Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hover/completions do not work when using mdx_analyzer from Neovim #474

Closed
4 tasks done
b0o opened this issue Aug 31, 2024 · 7 comments
Closed
4 tasks done

Hover/completions do not work when using mdx_analyzer from Neovim #474

b0o opened this issue Aug 31, 2024 · 7 comments
Labels
🙋 no/question This does not need any changes 👎 phase/no Post cannot or will not be acted on

Comments

@b0o
Copy link

b0o commented Aug 31, 2024

Initial checklist

Affected packages and versions

@mdx-js/[email protected]

Link to runnable example

No response

Steps to reproduce

I'm trying to use the MDX language server from Neovim.

The server starts and attaches to MDX files, and it reports diagnostics for structural issues like unclosed tags, but hover and completion do not work, and TypeScript errors are not reported.

I'm using the default config from lspconfig:

require'lspconfig'.mdx_analyzer.setup{}

I've tested in my own project (which is private), as well as this repo. MDX works as expected in both of them in VSCode, but not Neovim.

Other Neovim users seem to be having trouble as well: https://www.reddit.com/r/neovim/comments/1ewwtok/has_anyone_figured_out_intellisense_in_mdx_files/

Expected behavior

  • Hovering over a variable/function should display type information
  • Completions should be suggested, as they would in a .ts/tsx file

Actual behavior

  • Hovering reports "No information available"
  • No completions are shown

Runtime

Node v20

Package manager

pnpm

OS

Linux

Build and bundle tools

Next.js

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Aug 31, 2024
@remcohaszing
Copy link
Member

Hey @b0o, thanks for letting us know, and also for linking to the Reddit post.

MDX language server can run either with or without TypeScript enabled. This can be configured using the typescript.enabled initialize option. This is false by default.

If you enable TypeScript support via the MDX language server, it needs to perform things that the TypeScript language server does as well. It needs to create the same project, process the same files, etc. This option exists for editors that don’t support TypeScript plugins. I don’t know if this is the case for Neovim.

The recommended option is to use @mdx-js/typescript-plugin instead. This adds TypeScript support for MDX based on the TypeScript language server you probably already use. This means less memory usage, and compatibility with other plugins that work the same way, such as the Vue TypeScript plugin.


Since this is documented, but you and other Neovim users didn’t find it, do you have suggestions how to improve this? Are there other places that should document these options?

@remcohaszing remcohaszing closed this as not planned Won't fix, can't repro, duplicate, stale Aug 31, 2024
@remcohaszing remcohaszing added 🙋 no/question This does not need any changes 👎 phase/no Post cannot or will not be acted on labels Aug 31, 2024
@github-actions github-actions bot removed the 🤞 phase/open Post is being triaged manually label Aug 31, 2024
@remcohaszing remcohaszing added 👀 no/external This makes more sense somewhere else 🤞 phase/open Post is being triaged manually labels Aug 31, 2024
@github-actions github-actions bot added 👎 phase/no Post cannot or will not be acted on and removed 👎 phase/no Post cannot or will not be acted on 🙋 no/question This does not need any changes 👀 no/external This makes more sense somewhere else 🤞 phase/open Post is being triaged manually labels Aug 31, 2024

This comment was marked as resolved.

@remcohaszing remcohaszing added the 🙋 no/question This does not need any changes label Aug 31, 2024

This comment was marked as resolved.

@b0o
Copy link
Author

b0o commented Aug 31, 2024

Hi, thanks for getting back to me!

Since this is documented, but you and other Neovim users didn’t find it, do you have suggestions how to improve this?

I did see the documentation about this, but I couldn't get it to work, and it's difficult to debug. Personally, I don't care about using more CPU/memory, I would prefer to just add mdx_analyzer to my LSP config and have it just work.

@wooorm
Copy link
Member

wooorm commented Sep 1, 2024

AFAIK none of us are Neovim users so it’s an unknown for us, what to do

@haxibami
Copy link

haxibami commented Sep 4, 2024

Hi, I noticed something weird:

I'm using vtsls (a TS language server on Neovim). I installed and setup @mdx-js/typescript-plugin like this:

setup.lua
require('lspconfig').vtsls.setup({
  settings = {
    vtsls = {
      autoUseWorkspaceTsdk = true,
      tsserver = {
        globalPlugins = {
          {
            name = '@mdx-js/typescript-plugin',
            enableForWorkspaceTypeScriptVersions = true,
            languages = {
              'mdx',
            }
          },
        }
      }
    },
  },
  filetypes = {
    'javascript',
    'javascriptreact',
    'javascript.jsx',
    'typescript',
    'typescriptreact',
    'typescript.tsx',
    'mdx', -- <- Start TS server when you open a .mdx file
  },
  ...
})

In my minimum sample project, I created a tsconfig.json file to enable TS support for .mdx files.

tsconfig.json
{
  "compilerOptions": {
    "target": "es2016",
    "module": "commonjs",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true,
    "plugins": [
      {
        "name": "@mdx-js/typescript-plugin"
      }
    ]
  },
  "mdx": {
    "checkMdx": true,
    "plugins": [["remark-frontmatter", ["toml", "yaml"]], "remark-gfm"]
  }
}

And I have a test.mdx file with the following content. When I open this file, I get a lot of errors and hover doesn't work.

test.mdx
---
date: 2024-09-05
---

{/**
  * @typedef Props
  * @property {string} name
  *   Who to greet.
  */}

# Hello {props.name}
errors

image

So I tried another way: instead of the original .cjs script from @mdx-js/typescript-plugin (which resolves to node_modules/@mdx-js/typescript-plugin/index.cjs), I used the bundled .js script from the VSCode extension (<vscode_extensions_dir>/unifiedjs.vscode-mdx-<version>/node_modules/@mdx-js/typescript-plugin.js). I just removed the .cjs with package.json, and copied the .js to the same dir.

rm node_modules/@mdx-js/typescript-plugin/index.cjs node_modules/@mdx-js/typescript-plugin/package.json
cp <vscode_extensions_dir>/unifiedjs.vscode-mdx-1.8.10/node_modules/@mdx-js/typescript-plugin.js node_modules/@mdx-js/typescript-plugin/index.js

Now everything works like a charm. I can see the hover and the errors are gone.

hover, with no errors

image

I tested this in another project (which uses ESM) and the result was the same.

@haxibami
Copy link

haxibami commented Sep 5, 2024

No copying was necessary, just changing this line to "main": "./index.cjs" (or adding) worked.

"exports": "./index.cjs",

remcohaszing added a commit that referenced this issue Sep 19, 2024
Although the `exports` field should be sufficient, some TypeScript
integrations still rely on the `main` field.

See #474 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙋 no/question This does not need any changes 👎 phase/no Post cannot or will not be acted on
Development

No branches or pull requests

4 participants