3 ms·
What kind of support do we have editor-side for swapping between "LSP contexts" automatically? If I'm editing a .cs file and my editor is using the C# LSP, then
by ComputerGuru 3y ago
What kind of support do we have editor-side for swapping between "LSP contexts" automatically? If I'm editing a .cs file and my editor is using the C# LSP, then start something that a plugin <somehow> recognizes as entering into an SQL mode as I type `foo("SELECT ..` can that somehow trigger the pgsql LSP too?
(I'm a vim user but I'll accept a VS Code answer since that's basically "state of the art" when it comes to LSP and where most others get their inspiration from.)
- swader999 3y agoNeovim does this. For example, if you have two lsp configured in nvm-lspconfig.lua as follows, it will use a specific lsp tailored to either SQL or ruby: -- Initialization of Neovim's LSP client local nvim_lsp = require('lspconfig') -- Setup for the Ruby LSP nvim_lsp.solargraph.setup {} -- Setup for an SQL LSP (assuming one exists with the name 'sql_lsp' in this example) nvim_lsp.sql_lsp.setup {}
- petrzjunior 3y agoJetBrains's IntelliJ and friends do that with language plugins. They detect the language according to keywords and patterns and are able to do highlighting and intellisense for multiple languages in a single file. I have not tried this with LSP though, because LSP support landed just in the last version.
- scns 3y agoIn Intellij you can connect to the DB and get autocomplete in SQL strings.
- ComputerGuru 3y agoYeah, (neo)vim can do that for non-lsp with a filetype like html.css or similar whichbloads both syntax rules possibly with customizations to determine when it switches into which of the two modes. But again, I don’t know how that works with lsp.
- marcelarie 3y agoI don't know if this exists but it could be done using Treesitter. This is already done for syntax highlighting, nvim could check the syntax from a string after a specific pattern, like gql`` in Typescript. This should be configured by the user, idk if a default implementation could work correctly in all cases.
- phil294 3y agoTo add to the correct IntelliJ answer: VSCode, on the other hand, does not allow for multiple language services or servers to handle the same file at the same time. Instead, any language support (always by means of extension, either built-in or external) has to individually add support for embedded languages, either using language services or request forwarding [1]. For example, the built-in HTML plugin includes JS support inside <script/> tags by simply spinning up its own tsserver [2]. This seems to have been a design decision from the very start, but I have a hard time understanding why. It seems like a conceptual mistake to me. It also eats up system resources like crazy, but that's a lost cause anyway. Instead of harnessing the capabilities of existing implementations, every "wrapper" kind of language needs to build its own solution, which leads to these solutions often not being great. For example, said HTML/JS solution has issues with external dependencies [3]. Or, I've been trying to enable support for CoffeeScript or Elm inside Vue Single File Component files, but I couldn't so far, even though I'm the author of the CoffeeScript extension. [4][5] Any source file always has exactly one language type assigned to it (possibly auto-detected), so no, dynamically "switching" is not possible without manually changing it for the entire file. For things like SQL inside PHP, Jetbrains products really are superior. [1] https://code.visualstudio.com/api/language-extensions/embedded-languages https://code.visualstudio.com/api/language-extensions/embedd... [2] https://github.com/microsoft/vscode/blob/7fd6f1b1d46bd2223a902406fccd20cc7a539825/extensions/html-language-features/server/src/modes/javascriptMode.ts https://github.com/microsoft/vscode/blob/7fd6f1b1d46bd2223a9... [3] https://github.com/microsoft/vscode/issues/26338 https://github.com/microsoft/vscode/issues/26338 [4] https://github.com/vuejs/language-tools/issues/3200 https://github.com/vuejs/language-tools/issues/3200 [5] https://github.com/vuejs/vetur/issues/1184 https://github.com/vuejs/vetur/issues/1184
- ComputerGuru 3y agoI just want to say thanks for taking the time out to answer with technical attention and thoroughness!
- deleted 3y ago[deleted]
- e12e 3y agoI'm using Helix these days, but I seem to recall neovim handling markdown with code blocks fine. Less sure about "minor" dsl-like support, like online css/html/js in php etc? (Or SQL strings in c# etc).