Closed bushblade closed 3 years ago
Does your example have a typo? I'm guessing app.js
should say console.log(test())
, right?
The debug output you're seeing is from ESLint, not from :TSLspImportAll
. It doesn't rely on a root marker, but it does rely on tsserver
, which (if you're using nvim-lspconfig) will only start up in a directory that contains a package.json
or a tsconfig.json
/ jsconfig.json
file. Do you see tsserver
under clients attached to this buffer
when you run :LspInfo
?
If the client is attached, then the issue may be with your project configuration. I just put together this repo, which contains the minimal configuration required to get this feature to work on JavaScript files. Running :TSLspImportAll
in app.js
should work – could you let me know if it does for you?
Toggling diagnostics is definitely possible, and I could add a config flag to suppress ESLint errors (detecting whether the current directory has a valid configuration isn't that easy, unfortunately, since the configuration could be embedded in a package.json
file). Please open another issue for those if you're interested.
Oh sorry I pasted in the wrong code. Yeah it should be test, I used foo in my .ts tests and test() in my .js tests. I also tested this in a couple of React and Gatsby projects and get the same results - no import.
Do you see tsserver under clients attached to this buffer when you run :LspInfo?
Yes I do...
And here is the output from :LspInfo in a React project...
I can confirm that cloning your repository and running :TSLspImportAll
does indeed import the function but imports it as a common JS module.
In that case, it most likely has to do with your project configuration. Could you verify whether replicating the scenario in an existing project, moving the cursor to the missing import, and calling :lua vim.lsp.buf.code_action()
shows a code action prompting you to add the missing import?
This happens in any React or Gatsby project I try.
Could you verify whether replicating the scenario in an existing project, moving the cursor to the missing import, and calling :lua > vim.lsp.buf.code_action() shows a code action prompting you to add the missing import?
Thanks for verifying! What :TSLspImportAll
does is aggregate code actions and run them all at once. If the code actions aren't available, it won't do anything, so I think you need to look at your project's configuration and make sure that tsserver
is properly scanning your files and providing code actions / diagnostics.
I don't really know about JavaScript, but I think you need a jsconfig.json file (or a tsconfig.json
file with allowJs
set to true
, as in the repo I linked) at the project's root.
Ok so I just tried pasting in the same tsconfig.json from your repo into the React project, but I still get the same output from :lua vim.lsp.buf.code_action()
and still no import.
Also in your example repo it imports as a common JS module, not ES module, is that correct?
I think the format of the imports has to do with the tsconfig.json
settings, but again, I don't work with JavaScript, so I can't say for sure.
Your config seems fine, and your screenshots show that tsserver
itself is working (plus the sample repo worked), so this is fundamentally an issue with your project configuration. I wish I could help more, but I really don't know anything about tsserver
+ JavaScript, and as long as you don't have access to code actions, there's nothing we can do on the plugin side.
Thanks that does make sense. I don't suppose you have a example repo where it is working correctly? Typescript project is fine. Just so I can test that?
create-react-app has an option to generate a project with TypeScript, and Gatsby has an example repo. I recommend getting started there.
Hi, first off thanks for creating this plugin. Prior to discovering your tutorial and plugin no linting in JS files was the one thing that held be back from moving away from COC to Nvim LSP.
I am not able to get the :TSLspImportAll command to work. I set
debug = true,
and I seecommand git exited with 0
when I try to use the command. To test I created a module.js file withAnd a app.js file with
And ran :TSLspImportAll, and I don't get any import. I also tried in .ts files but see the same result. I thought perhaps that the plugin looks for a .git directory to determine project root so initialized a repo in the test project but that did not work either. Am I doing something wrong or is this a bug? I would also like to put forward a feature request to make available a command to toggle the linting on or off, I can create a new issue if that would be more appropriate? Or perhaps an option to only have the linting output if there is a .eslintrc in the project root, if that is possible.