News for hackers. Stuff that matters.
Re:Show HN: Postgres Language Server by ComputerGuru on Sunday August 06, 2023 @12:54PM (#37023959)
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.)

Re:Show HN: Postgres Language Server by swader999 on Sunday August 06, 2023 @01:11PM (#37024197)
Neovim 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 {}

Re:Show HN: Postgres Language Server by NilsIRL on Sunday August 06, 2023 @04:05PM (#37026038)
I think what parent comment is asking for is the ability switch between languages withing a single file. I don't think this will work with the setup you described.
Re:Show HN: Postgres Language Server by swader999 on Sunday August 06, 2023 @06:15PM (#37027452)
No, it would not.
Re:Show HN: Postgres Language Server by petrzjunior on Sunday August 06, 2023 @01:53PM (#37024687)
JetBrains'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.
Re:Show HN: Postgres Language Server by ComputerGuru on Sunday August 06, 2023 @04:43PM (#37026470)
Yeah, (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.
Re:Show HN: Postgres Language Server by scns on Wednesday August 09, 2023 @11:45AM (#37064417)
In Intellij you can connect to the DB and get autocomplete in SQL strings.
Re:Show HN: Postgres Language Server by marcelarie on Sunday August 06, 2023 @06:36PM (#37027625)
I 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.

Re:Show HN: Postgres Language Server by phil294 on Sunday August 06, 2023 @07:11PM (#37027931)
To 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/embedd... [2] https://github.com/microsoft/vscode/blob/7fd6f1b1d46bd2223a9... [3] https://github.com/microsoft/vscode/issues/26338 [4] https://github.com/vuejs/language-tools/issues/3200 [5] https://github.com/vuejs/vetur/issues/1184

Re:Show HN: Postgres Language Server by ComputerGuru on Sunday August 06, 2023 @10:14PM (#37029223)
I just want to say thanks for taking the time out to answer with technical attention and thoroughness!
Re:Show HN: Postgres Language Server by e12e on Monday August 07, 2023 @10:04AM (#37034605)
I'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).