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

feat(lsp): support using new language server implementations #162

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

jokeyrhyme
Copy link

@jokeyrhyme jokeyrhyme commented Oct 17, 2023

  • relates to Standalone LSP Server in Rust #117
  • adds a new "implementation" setting: extension, nu --lsp, or lsp
    • "extension" is the default, and uses the existing TypeScript->nu --ide-... implementation embedded in this extension
    • nu --lsp will use this implementation (if available): Integrated Language Server nushell#10723
      • uses the "nushellExecutablePath" setting
    • nuls will use the implementation in this repository (if available): https://github.com/jokeyrhyme/nuls
    • language server selection is live, i.e. changing "implementation" causes the selected language server to start (and all others to stop)

@jokeyrhyme
Copy link
Author

@fdncred
Copy link
Collaborator

fdncred commented Oct 17, 2023

Let's make this draft while it is still WIP.

@jokeyrhyme jokeyrhyme changed the title WORK-IN-PROGRESS: feat(lsp): use standalone language server implementation feat(lsp): use standalone language server implementation Oct 19, 2023
"enum": ["extension", "nu --lsp", "nuls"],
"default": "extension",
"description": "Switch between different language server implementations (requires restarting Visual Studio Code to take effect)."
},
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bah, this is the only deliberate change here

The rest is auto-prettier, which I can revert if necessary

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're using vscode to edit these files, one thing that I've just learned is you can do ctrl/cmd-shift-p and choose File:Save without formatting and it stops things like prettier or other formatters from running on save.

@jokeyrhyme jokeyrhyme marked this pull request as ready for review October 19, 2023 04:44
@fdncred
Copy link
Collaborator

fdncred commented Oct 19, 2023

ok, I'm seeing a few things:

  1. I figured out that you have to quit out and restart to use a different lsp.

  2. It looks like hover help isn't rendered correctly.
    image

I'm guessing this is some markdown formatting issues with backticks and such. I remember JT fighting this originally.

  1. We also already know that goto-definition doesn't quite work right yet.

  2. It looks like the include-path isn't being sent correctly, at least it looks different in the logging window.
    image
    This is how those u{1e} separators are rendered like using the extension lsp
    image

  3. Hovers seem to be getting the right information.

It's generally a pretty good experience considering where it's at in the development cycle. Good job!

@jokeyrhyme
Copy link
Author

@fdncred I assume those are notes on nuls and not this PR on the extension? Anything further to be done in this PR?

@fdncred
Copy link
Collaborator

fdncred commented Oct 19, 2023

Yes, those are notes on nuls when I tried it out in this PR.

I think there should be some type of restart on this PR when the lsp changes.

@jokeyrhyme
Copy link
Author

Okay, I've made "implementation" a live setting

It's working suspiciously well, haha

@jokeyrhyme jokeyrhyme changed the title feat(lsp): use standalone language server implementation feat(lsp): support using new language server implementations Oct 20, 2023
@fdncred
Copy link
Collaborator

fdncred commented Oct 20, 2023

My test of this produced some errors. Not sure what any of this really means.
image

@fdncred
Copy link
Collaborator

fdncred commented Oct 20, 2023

Something weird is going on. If I delete the node_modules folders from the root, server, and client folders. Then do a npm install and start debugging with F5 in vscode. I get all these errors seen above in the vscode where i have the source code and these popups in vscode that was launched with F5.
image

@fdncred
Copy link
Collaborator

fdncred commented Oct 20, 2023

I will say though, the switching between nuls and extension is working well. We just need to narrow down on what's giving these other errors.

@jokeyrhyme
Copy link
Author

The current behaviour tries to stop all the servers and then start the desired one, and maybe those errors are from trying to stop a server that was never running

Just a theory, but I'll play with it and see

Thanks for checking!

@jokeyrhyme
Copy link
Author

I'm handling the Promises from client.start() and client.stop() more thoroughly to try to address those error messages

That said, I believe them to be pretty harmless, and you probably won't encounter them at all unless you try to use an implementation that cannot be started, i.e. you don't have nuls installed, or you don't have the nu --lsp branch installed

@fdncred
Copy link
Collaborator

fdncred commented Oct 22, 2023

Thanks! I'll give this a try later this afternoon. Just so you know, I had nuls and (obviously) extension installed when I got those errors. I did not have the PR with nu --lsp installed, but I never configured my system to use it. Hopefully we don't see these errors anymore so we can land this PR.

@fdncred
Copy link
Collaborator

fdncred commented Oct 22, 2023

Sorry - Ran out of time today. I hope to look at this tomorrow.

@jokeyrhyme
Copy link
Author

No worries

Not urgent

And I've had less time to work in this area in the last week, too :)

@fdncred
Copy link
Collaborator

fdncred commented Oct 23, 2023

ok, finally got to this. This looks better but I'm not sure we can ship with this. People will be filing issues because they think something isn't working. I wonder if there's a better way to handle this like if whatever the configured lsp is, like extension, don't try and stop the configured one on startup. Just stop the other ones maybe?
image

There's also 3 language server log menu items now. Not sure what that's about. They all have similarly formatted information. Looks like they're all coming from the "extension" lsp. And they all update as you mouse over things.
image

@schrieveslaach
Copy link

@fdncred, thanks for the feedback and great to see that it is also working in Vscode (I'm using Neovim).

I'm not sure how to get completions to work. What I was doing was typing str . Not sure the right voodoo to get them to work here.

I observed similar behavior in my editor of choice and that it seems to work only in certain conditions. Here is an example of my setup. I type something into the command line, start Nushell's open in editor feature, then my Neovim starts and start the LSP automatically, I can use some completions and then I quit the editor:

output

However, when the document changed completions stop working unless I was the document. And here the textDocument/didChange implementation is required. I'll start working on it in the next days.

@schrieveslaach
Copy link

@fdncred, speaking of “to show”: if you want I could provide some GIF recording of Nushell in Neovim if you want to include it in the release blog post.

@fdncred
Copy link
Collaborator

fdncred commented Nov 3, 2023

@fdncred, speaking of “to show”: if you want I could provide some GIF recording of Nushell in Neovim if you want to include it in the release blog post.

ya, definitely. Feel free to put them in this PR nushell/nushell.github.io#1114 with a write up like "We've started building a nushell Language Server". What most people are looking for at this point is (1) how to configure it in helix, vim, nvim and (2) which features are currently supported.

@amtoine
Copy link
Member

amtoine commented Nov 3, 2023

@schrieveslaach
i know this is not really the place for this, but could you share your Neovim setup?
i cannot get the completions to work 😕

@schrieveslaach
Copy link

@schrieveslaach i know this is not really the place for this, but could you share your Neovim setup? i cannot get the completions to work 😕

@amtoine, at the moment it is very simple. I start an LSP for the current buffer when file type nu.

function StartNuLS()
lua << EOF
local id = vim.lsp.start({
   name = "Nushell's LSP",
   cmd = {
      "/pat/to/nushell-repo/target/debug/nu",
      "--lsp"
   },
   on_attach = M.on_attach
})
vim.lsp.buf_attach_client(0, id)
EOF
endfunction

augroup NuSetup
   autocmd!
   autocmd FileType nu call StartNuLS()
augroup end

I was thinking of providing a PR to lspconfig after Nushell's next release which does it then for you. Maybe I'll also try to add file type nu to Neovim directly.

@amtoine
Copy link
Member

amtoine commented Nov 4, 2023

@schrieveslaach
that would be great, i don't know how to plug that snippet into my config, i get errors all over the place 😢

@AucaCoyan
Copy link
Contributor

Just to get some directions, after this release of nu is done, and #11284 + 11320 are merged: what is missing to this PR?

I would like a list of things that --lsp must be capable of before landing it 🏁

@fdncred
Copy link
Collaborator

fdncred commented Dec 14, 2023

This PR only needs to support 2 lsps now. nu --lsp and nu --ide-* and not nuls. So, it needs to be refactored to only do those 2. You should also read these threads to see what I mentioned was missing or not working right before. Some of it has to do with logging.

@jokeyrhyme
Copy link
Author

We probably want to determine what the destiny of this PR is

I agree we should remove the nuls code path

But is it desirable to ship/merge this PR otherwise (assuming other rough areas are polished)?

Or, should we keep this as a PR until nu --lsp has eclipsed nu --ide-..., at which point we can delete that code path from the PR, too?

@fdncred
Copy link
Collaborator

fdncred commented Dec 14, 2023

I'd like to have the functionality of switching between the two lsps until nu-lsp overtakes nu --ide-* in functionality and stability. This PR isn't far from landing. We just need to work on the things mentioned, logging, making sure to default to nu --ide-*, etc.

@AucaCoyan
Copy link
Contributor

@fdncred Oh, my bad, sorry if I was disrespectful. I lost something in the translation 😅

My understanding is that the problems mentioned in this PR are solved in other PRs (either merged, or ready to merge when the moment comes)

and, the remaining issues:

It looks like the include-path isn't being sent correctly, at least it looks different in the logging window.

I don't know how to reproduce the problem, can you give me a little script or sample to follow? 💯 . That is a note for nuls, is --lsp working properly?

red error-sy logs here

I had some of those errors too, but it was something of VS Code playing badly with the extension. I decided to try the extension host with all the extensions disabled and it didn't failure once. Still have that weird bug that sometimes the LSP has more than one instance running

And that's about it. I see nothing else to be missing. That's why I asked before for "what could be done to land this PR?" (in a poor manner)
Again, sorry for the rudeness! 😇

@schrieveslaach
Copy link

I think input for @AucaCoyan last comment would be also input for me on what I could work next in the LSP area. I'm a bit lost there at the moment because I just using it to edit my Nushell REPL input and don't often work with a lot of scripts.

@fdncred
Copy link
Collaborator

fdncred commented Dec 15, 2023

Looking at this PR, there are a few things that might need to change before landing. I've tried to re-read everything and add a checkbox for it below just to make sure we've covered everything. Some of these items may be done and we can just check them off. Others will need some work prior to landing this PR.

    • I'd like it to support nu --ide-* and nu --lsp as the two options for LSPs.
    • I don't want to have to quit out to get switching LSPs to work.
    • When running from VSCode server (debug mode) it shouldn't have any errors.
    • Test deleting node_modules and then npm install to see if odd errors in vscode happen.
    • When switching LSPs, maybe it would be nice to show a popup that we switched.
    • When switching LSPs, we shouldn't get "nushell language server error".
    • We should have 1 "Nushell Language Server" log shared between LSPs, not multiple. As a fallback, I could also live with separate "Nushell Language Server (extension)" and "Nushell Language Server (nu-lsp)" logs.
    • We should initially have pretty verbose logging so we can make sure things are launching and running correctly. So, start with logging most everything in typescript so that we can see what's happening in the log window as it happens.
    • Make sure functionality works on each LSP if implemented.
      • Extension
        • Hover built-ins
        • Hover custom commands
        • Hover variables
        • Hover rendered correctly
        • GoTo Def
        • Completions
        • Diagnostics (errors/red squigglies)
        • Inlays
        • Configuration is accepted when changed (including include paths)
      • nu --lsp ( we know some of these are not implemented yet. that won't stop this pr from landing)
        • Hover built-ins
        • Hover custom commands
        • Hover variables
        • Hover rendered correctly
        • GoTo Def
        • Completions
        • Diagnostics (errors/red squigglies)
        • Inlays
        • Configuration is accepted when changed (including include paths)

@AucaCoyan
Copy link
Contributor

Thank you very much for creating a list with everything! 🙏🏼

I'm wondering on how to tackle the list. I think we should resolve changing servers and debugging + errors first. But since this is a PR, only jokeyrhyme and maintainers of this repo can make changes. Is it ok to you to make PRs into your repo jokeyrhyme/vscode-nushell-lang jokeyrhyme? Another possible way is to close this pr and make a meta issue.
Both ways are good for me 💻

@fdncred
Copy link
Collaborator

fdncred commented Dec 15, 2023

or @AucaCoyan we can close this PR and you can copy the code out of it and make a new PR with you being the owner. i'm not sure if there's a way to give you permissions to change this PR without going through jokeyrhyme's repo.

@jokeyrhyme
Copy link
Author

I've invited everyone here to collaborate on my fork, but have no ill feelings if you wish to fork my fork into another repository :)

@fdncred
Copy link
Collaborator

fdncred commented Dec 16, 2023

Thanks @jokeyrhyme, we appreciate your help!

@AucaCoyan
Copy link
Contributor

Thank you jokey! I tested it and updated main of your repo successfully 😄

We'll be seeing around each other here and in the fork 💪🏼

@fdncred fdncred marked this pull request as draft March 25, 2024 01:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants