Skip to content

Integrated Language Server Protocol #10794

Open

Description

@schrieveslaach

Related problem

As described in nushell/vscode-nushell-lang#117 there is a demand to integrate support for the language server protocol (LSP) into Nushell itself instead of creating an additional command line interface (CLI) protocol (that is the current approach with --ide-* CLI options.

Describe the solution you'd like

Based on the initial draft PR #10723 at least following LSP methods should be supported by Nushell:

Describe alternatives you've considered

The alternative would be to keep using the --ide-* in the long run and build an external LSP server.

Additional context and details

No response

Activity

  1. added
    category:enhancement
    status:needs-triage
    on Oct 21, 2023
  2. fdncred commented on Oct 21, 2023

    @fdncred
    Contributor

    Thanks @schrieveslaach.

    The one other thing that I'd like to see added, which I think has to be added on the vscode side is semantic highlighting. Just logging it here to remember.

  3. amtoine commented on Oct 21, 2023

    @amtoine
    Member

    just to be sure, will #10723 close this issue? 😋

  4. fdncred commented on Oct 21, 2023

    @fdncred
    Contributor

    just to be sure, will #10723 close this issue? 😋

    Not necessarily. This is the tracking issue. We could land #10723 without everything being completed and then have follow-up PRs to complete the remaining tasks.

  5. added
    category:meta-issue
    and removed
    status:needs-triage
    on Oct 23, 2023
  6. schrieveslaach commented on Oct 24, 2023

    @schrieveslaach
    ContributorAuthor

    @fdncred, textDocument/semanticTokens is now in the list. I put an asterisks at the end because there are multiple requests.

  7. fdncred commented on Oct 24, 2023

    @fdncred
    Contributor

    @fdncred, textDocument/semanticTokens is now in the list. I put an asterisks at the end because there are multiple requests.

    I'm excited about this!!!!

  8. fdncred commented on Nov 2, 2023

    @fdncred
    Contributor

    @schrieveslaach When you get a moment, can you update the tracking items above?

  9. fdncred commented on Nov 28, 2023

    @fdncred
    Contributor

    @schrieveslaach I just heard that the work you've done here has already been added to helix and to zed. Here's a screenshot of zed that was posted on discord.
    image

  10. AucaCoyan commented on Dec 1, 2023

    @AucaCoyan
    Contributor

    Hi! I did a lot of work on nufmt. I checked out the code for the LSP but sadly I understand very little. I do want to help! LSP give life to my everyday code. Is there any help I can give for you? (particulary for @schrieveslaach ) ❤️

  11. schrieveslaach commented on Dec 3, 2023

    @schrieveslaach
    ContributorAuthor

    @AucaCoyan, thanks for offering help. In the recent weeks hadn't had much time for working on LSP in Nushell and I wasn't sure what to tackle next. Maybe, on workspace/configuration but I'm uncertain how a workspace should behave for a Nushell project.

    But what do you think about integrating nufmt as a Document Formatting Request into Nushell? When Nushell's LSP receives the request, it could look for nufmt binary in the PATH variable and then it could format the content kept in memory and sends back the the text edits that the client has to do as well.

  12. AucaCoyan commented on Dec 3, 2023

    @AucaCoyan
    Contributor

    Great!
    Just for confimation: do you see a better approach to have a different binary called nufmt or do you prefer having a library in nu-lsp that formats code?
    nufmt it's not close to be ready as a beta yet, it doesn't format a thing. Just checking if you want this or you prefer having everything in one repo for the lsp 👍🏼

  13. fdncred commented on Dec 3, 2023

    @fdncred
    Contributor

    we should not integrate nufmt yet. it's not very useful in its current state.

  14. added a commit that references this issue on Mar 25, 2024
  15. fdncred commented on Mar 31, 2024

    @fdncred
    Contributor

    @schrieveslaach one thing I think we need to be able to have is the -I include dirs functionality. For vscode, I think that will be a configuration point, but it could also just utilize whatever is in your env.nu NU_LIB_DIRS folders as a starting point.

  16. schrieveslaach commented on Apr 6, 2024

    @schrieveslaach
    ContributorAuthor

    @fdncred, I'm not so sure if I can follow you. The -I option is evaluated and set put into the engine_state before starting the LSP (in the same fashion as for the IDE command line options). If you are talking about this, I'm lost what is not yet working.

    Or are you talking about the rootUri LSP init parameter? Here I'm unsure how a rootUri should be treated be nu's LSP.

  17. fdncred commented on Apr 7, 2024

    @fdncred
    Contributor

    @schrieveslaach Sorry, this is what I'm talking about. It may not be exactly as I've stated but this is the symptom.

    This is my config.nu loaded in nvim. Note that the lsp is failing to find some files.
    image

    The reason for this is

    1. I am not specifying any -I parameter to the nu lsp invocation. I'm kind of a nvim noob and I barely got the lsp working.
    2. I'm thinking that the lsp should probably look at NU_LIB_DIRS and apply that automatically. If this were to happen, then I wouldn't have any errors when looking at my config.nu.

    In the vscode extension, I get around this by having a config point to manually add Include Dirs.
    image

    I'm not saying we should have a config or not. I'm not sure but I am saying that whatever is in NU_LIB_DIRS should be used. This may also assume that a persons env.nu is parsed when launching with nu --lsp which I'm not confident of.

  18. schrieveslaach commented on Apr 8, 2024

    @schrieveslaach
    ContributorAuthor

    If you are testing with nvim-lspconfig changing the CLI parameters is easy:

    local lspconfig = require('lspconfig')
    lspconfig.nushell.setup({
       cmd = { "nu", "--lsp", "-I", "… your path …", "-I", "… another path" },
       -- … more options …
    })

    This may also assume that a persons env.nu is parsed when launching with nu --lsp which I'm not confident of.

    It doesn't parse standard config files. Seems to me that it should in certain cases. Maybe, if there is no rootUri present. Let me check something.

  19. schrieveslaach commented on Apr 8, 2024

    @schrieveslaach
    ContributorAuthor

    @fdncred, have a look at #12454 if that solves your issue.

  20. fdncred commented on Apr 8, 2024

    @fdncred
    Contributor

    If you are testing with nvim-lspconfig changing the CLI parameters is easy:

    This may work but I'm not confident with it because the -I parameter was never meant to be used multiple times when launching nushell. It's meant to be one string with separate folders separated by \x1e, iirc.

    I'll test #12454 soon.

  21. schrieveslaach commented on Apr 9, 2024

    @schrieveslaach
    ContributorAuthor

    Providing -I multiple time was just a guess. Following should do the trick then.

    local lspconfig = require('lspconfig')
    lspconfig.nushell.setup({
       cmd = { "nu", "--lsp", "-I", "… your path …\x1e… another path" },
       -- … more options …
    })
  22. added a commit that references this issue on Apr 14, 2024
  23. tombh commented on Nov 21, 2024

    @tombh

    Regarding nufmt, the relevant part of the spec would be:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    category:enhancementcategory:meta-issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions