Skip to content

Integrated Language Server - #10723

Merged
fdncred merged 2 commits into
nushell:mainfrom
schrieveslaach:lsp
Nov 2, 2023
Merged

fdncred merged 2 commits into
nushell:mainfrom
schrieveslaach:lsp

Conversation

@schrieveslaach

@schrieveslaach schrieveslaach commented Oct 15, 2023 •

Copy link
Copy Markdown
Contributor

Description

This commit integrates a language server into nushell so that IDEs don't have to convert CLI option back and forth.

Tracking tasks

User-Facing Changes

The command line options --lsp will start a LSP server.

Tests + Formatting

After Submitting

@schrieveslaach
schrieveslaach marked this pull request as draft October 15, 2023 11:11
@schrieveslaach

Copy link
Copy Markdown
Contributor Author

@fdncred, @jokeyrhyme I tested something in nushell and integrated lsp-server. What do you think?

@fdncred

fdncred commented Oct 15, 2023 •

Copy link
Copy Markdown
Contributor

@schrieveslaach This seems like a good start to integrating nuls into nushell more closely. Thanks!

What I'd like to see here is both the --start-lsp and all the --ide-blah parameters coexist. I think this will make things easier. This prevents us to having to do a coordinated cutover to --start-lsp with the vscode extension. We can just get this PR in working order, bring nuls into our repo, integrate nuls, etc., and meanwhile the vscode extension still works like it does today and when we're comfortable with the "new stuff" we can make changes to the extension. How's that sound?

I haven't really used lsp-server so if there are better ways to integrate nuls in, I think we're open to other ideas too.

@jokeyrhyme

Copy link
Copy Markdown
Contributor

I'm on my phone but will check this out a bit later

I did use tower-lsp for my implementation, I haven't looked into how it compares to lsp-server, but then I did also see a few comments questioning the health of the tower-lsp project (may or may not have improved since those comments were made)

@jokeyrhyme

Copy link
Copy Markdown
Contributor

Thanks for getting a start on this! <3

I think there was a previous suggestion about having a plain --lsp flag

Having "start" in there makes me think a background daemon will be created and then the command will terminate, which might be what we want, but then we'll probably want an accompanying --stop-lsp

Otherwise, if the command is intended to stay alive and serve LSP requests, then maybe drop the "start"?

🤷

@jokeyrhyme

Copy link
Copy Markdown
Contributor

Is it worth using the nuls roadmap as a checklist to see what is implemented by this PR? No software is ever complete, so it's totally fine for this PR to implement something nuls does not and vice versa, but would be good to have something of a status report for where this PR is up to: https://github.com/jokeyrhyme/nuls#roadmap

@jokeyrhyme

Copy link
Copy Markdown
Contributor

Related: nushell/vscode-nushell-lang#162

@schrieveslaach
schrieveslaach force-pushed the lsp branch 2 times, most recently from c723f35 to 9bc05d4 Compare October 17, 2023 21:36
@schrieveslaach

Copy link
Copy Markdown
Contributor Author

@fdncred, @jokeyrhyme, I updated the PR to keep the previous behavior and to provide a command line option --lsp instead of --start-lsp. I'll add the roadmap later this week.

Comment thread Cargo.toml Resolved
@jokeyrhyme

Copy link
Copy Markdown
Contributor

Thanks for the roadmap/checklist :)

I wonder if there's a way we can collaborate a little more closely? Should I raise PRs against your branch?

There's great work here that effectively covers jokeyrhyme/nuls#7 , but then the rest of nuls has more comprehensive coverage of the features that are in the TypeScript implementation

There might be a way we can avoid duplication of effort, although some duplication is probably unavoidable

@jokeyrhyme

Copy link
Copy Markdown
Contributor

Oh, also, I'm not sure if you've checked it out, but there's a room dedicated to editor support in the official Discord:

https://discord.com/channels/601130461678272522/1066353495638278194

@jokeyrhyme

Copy link
Copy Markdown
Contributor

I've updated the draft PR for the Visual Studio Code extension, so that there's now a setting to point it at nu --lsp: nushell/vscode-nushell-lang#162

@fdncred

fdncred commented Oct 19, 2023 •

Copy link
Copy Markdown
Contributor

From a nushell core-team perspective, we'd definitely like to see these two approaches to a language server converge into one excellent approach. We appreciate all the effort from @schrieveslaach and @jokeyrhyme. Thanks @jokeyrhyme for getting the vscode extension setup to use extension, nuls and nu --lsp!

We definitely like this PR's approach of just calling the nushell functions instead of shelling out. We also like that it's using lsp-types and lsp-server instead of the (sometimes) heafty tower-lsp found in nusl. We also like that this PR is all inside of nushell itself and not a separate executable that people will have to download.

So, if we can just merge our efforts here, I think we can get to the goal of having a lsp pretty quickly. No need to have it perfect on the first merge, now that we have the extension setup to handle it, it should be pretty easy to switch back and forth between lsps for testing.

Really great work so far y'all!

@schrieveslaach

Copy link
Copy Markdown
Contributor Author

@fdncred, I'm very happy to read your appreciation statement and I'm glad to help here.

We also like that it's using lsp-types and lsp-server instead of the (sometimes) heafty tower-lsp found in nusl.

I specifically chose lsp-server instead of tower due to minimal set of dependencies. 😉

No need to have it perfect on the first merge, now that we have the extension setup to handle it, it should be pretty easy to switch back and forth between lsps for testing.

What about then making this PR into the initial PR that adds the corresponding LSP responses for --ide-* CLI args and then we can create follow up PRs for adding workspace/* and textDocument/did* functionality? @jokeyrhyme, I think it is a good way of sharing the contributions work. I would continue with textDocument/inlayHint and
textDocument/publishDiagnostics in this PR and then merge this as soon as possible so that we then can start working on the next items.

Shall we create a tracking issue then?

@schrieveslaach

Copy link
Copy Markdown
Contributor Author

Oh, also, I'm not sure if you've checked it out, but there's a room dedicated to editor support in the official Discord:

https://discord.com/channels/601130461678272522/1066353495638278194

No, I didn't because I'm into Discord. Is that something you think is really required?

@jokeyrhyme

Copy link
Copy Markdown
Contributor

Oh, also, I'm not sure if you've checked it out, but there's a room dedicated to editor support in the official Discord:
https://discord.com/channels/601130461678272522/1066353495638278194

No, I didn't because I'm into Discord. Is that something you think is really required?

Not especially (and I'm usually on the Matrix room rather than the Discord server, as a preference), I was just thinking out loud

@jokeyrhyme

Copy link
Copy Markdown
Contributor

Shall we create a tracking issue then?

The nushell team is not opposed to an incremental approach

The Code extension will have a switch in it, so there's no expectation for a completed LSP server here as part of this PR

Once this PR is ready, we can raise issues for any follow-up items

That way we can use issue assignments, etc

@fdncred

fdncred commented Oct 20, 2023

Copy link
Copy Markdown
Contributor

@schrieveslaach Yes, please create a tracking issue with the tasks as markdown checkboxes. Yes, we can land this when the first pieces are ready, but the entirety isn't complete.

Since this PR is really entirely separate from nushell (but built in) we should feel free to merge it whenever we think the first step is ready. And then followup PRs documented a little bit in the tracking issue could follow on behind this one. One thing we need to make sure of though is that we do not break the existing lsp functionality. So, all the --ide-* commands need to continue to work while we're going through this process. I see changes in ide.rs right now that concern me because I think they'll break the current implementation. I'm fine with additions but when we change things like find_id(), goto_def(), hover(), complete(), etc. I think this will break things. So, I'd recommend leaving those type of functions in place, working as they do now, and add find_id_lsp(), goto_def_lsp(), hover_lsp(), complete_lsp(), etc. Does that sound ok?

Ping me when the tracking issue is created and we're ready to merge this PR.

Comment thread src/main.rs Resolved
@schrieveslaach

Copy link
Copy Markdown
Contributor Author

@fdncred, #10794 is the tracking issue I created.

Regarding your other comment I was wondering if I should revert the changes and create a new module (not an additional crate within the repository at the moment) and add all the LSP support separate from the existing IDE options. What do you think?

@fdncred

fdncred commented Oct 21, 2023 •

Copy link
Copy Markdown
Contributor

@schrieveslaach I think we were wanting it as a separate crate before we merge, but if it's easier to start as a mod, then that's fine. I kind of think what you're suggesting is better, adding all the lsp support stuff separate to the ide commands, because it should easily allow us to have both coexist, which is what we want at this point.

@schrieveslaach

Copy link
Copy Markdown
Contributor Author

FYI, I started from scratch where I build the LSP support in a separate crate. I also started with test driven development so that the LSP support has some proper tests.

@fdncred

fdncred commented Oct 24, 2023

Copy link
Copy Markdown
Contributor

FYI, I started from scratch where I build the LSP support in a separate crate. I also started with test driven development so that the LSP support has some proper tests.

oh, nice. TDD should provide ample tests then. Good idea. I guess we can close this PR when you open your new one. Thanks!

@101313

101313 commented Oct 24, 2023

Copy link
Copy Markdown

Exciting stuff @schrieveslaach, thanks for the effort!
Very interesting, especially if considering the longing for such functionality on big names like zsh for quite some time now

@schrieveslaach

Copy link
Copy Markdown
Contributor Author

FYI, I started from scratch where I build the LSP support in a separate crate. I also started with test driven development so that the LSP support has some proper tests.

oh, nice. TDD should provide ample tests then. Good idea. I guess we can close this PR when you open your new one. Thanks!

@fdncred, I wanted to update this PR. Do you want me to create a new one instead? I was thinking that updating this one is better because it has been referenced by other issues and PRs.

@fdncred

fdncred commented Oct 25, 2023

Copy link
Copy Markdown
Contributor

@schrieveslaach I'm fine with using this PR still. I just thought you meant you were going to close it when you said you started from scratch.

@jokeyrhyme

Copy link
Copy Markdown
Contributor

Yep, but nushell itself could have declared that anything other than UNIX line endings is invalid and not a valid nushell script, refusing to execute anything else

That would mean nobody would have Windows line endings anywhere for us to deal with here (unless they wanted to curate their own collection of scripts that nushell cannot execute, for some reason)

This is a hypothetical lament, of course, seeing as the ship has sailed :)

@fdncred

fdncred commented Nov 1, 2023

Copy link
Copy Markdown
Contributor

Ah, a LineIterator. That's an interesting approach. Hopefully it work better with some tweaking.

@fdncred

fdncred commented Nov 1, 2023 •

Copy link
Copy Markdown
Contributor

I could be way off here, but after looking at this a little bit, I'm wondering if span_to_range() is right. I say that because, so far in my debugging, offset is always 0.

In our ide.rs code, offset is initialized to working_set.next_span_start(). So, if this is the nushell Span, the offset might should initially start like that.

In nushell, if you do view files you'll see what the next span start will be by looking at the the last end.

I could be way off too. I've just looked at a few sections of your code so far.

I'm leaning towards me being wrong after trying to consume more code. It's like we're trying to convert a span to a position, which is a little different since position has line and character and span is just an index range in an array.

@fdncred

fdncred commented Nov 1, 2023

Copy link
Copy Markdown
Contributor

The vscode extension also converts spans to positions but it goes about it a little different. Just posting this here in case you haven't seen it. Not sure how helpful it is.

function convertSpan(utf8_offset: number, lineBreaks: Array<number>): Position {
  const lineBreakIndex = lowerBoundBinarySearch(lineBreaks, utf8_offset);

  const start_of_line_offset =
    lineBreakIndex == -1 ? 0 : lineBreaks[lineBreakIndex] + 1;
  const character = Math.max(0, utf8_offset - start_of_line_offset);

  return { line: lineBreakIndex + 1, character };
}

function lowerBoundBinarySearch(arr: number[], num: number): number {
  let low = 0;
  let mid = 0;
  let high = arr.length - 1;

  if (num >= arr[high]) return high;

  while (low < high) {
    // Bitshift to avoid floating point division
    mid = (low + high) >> 1;

    if (arr[mid] < num) {
      low = mid + 1;
    } else {
      high = mid;
    }
  }

  return low - 1;
}

and it uses this to find the linebreaks

function findLineBreaks(utf16_text: string): Array<number> {
  const utf8_text = new TextEncoder().encode(utf16_text);
  const lineBreaks: Array<number> = [];

  for (let i = 0; i < utf8_text.length; ++i) {
    if (utf8_text[i] == 0x0a) {
      lineBreaks.push(i);
    }
  }

  return lineBreaks;
}

@fdncred

fdncred commented Nov 1, 2023 •

Copy link
Copy Markdown
Contributor

In goto_definition_of_command(), I really don't get why this part is returning None.

        let resp = goto_definition(script.clone(), 4, 1);
        eprintln!("response: {:?}", resp);
response: Response(Response { id: RequestId(I32(2)), result: None, error: None })

I've changed the goto_definition() command a bit but it's still difficult for me to unravel what's going on, under the hood.

    fn goto_definition(uri: Url, line: u32, character: u32) -> Message {
        let (client_connection, _recv) = initialize_language_server();

        let method_name = GotoDefinition::METHOD.to_string();
        eprintln!("method_name: {}", method_name);
        let method_params = serde_json::to_value(GotoDefinitionParams {
            text_document_position_params: TextDocumentPositionParams {
                text_document: TextDocumentIdentifier { uri },
                position: lsp_types::Position { line, character },
            },
            work_done_progress_params: Default::default(),
            partial_result_params: Default::default(),
        })
        .unwrap();
        eprintln!("method_params: {:?}", method_params);
        let mess_req = Message::Request(lsp_server::Request {
            id: 2.into(),
            method: method_name,
            params: method_params,
        });
        eprintln!("goto_def_mess_req: {:?}", mess_req);
        client_connection.sender.send(mess_req).unwrap();

        client_connection
            .receiver
            .recv_timeout(std::time::Duration::from_secs(5))
            .unwrap()
    }
method_name: textDocument/definition
method_params: Object {"position": Object {"character": Number(1), "line": Number(4)}, "textDocument": Object {"uri": String("file:///D:/nushell/tests/fixtures/lsp/goto/command.nu")}}
goto_def_mess_req: Request(Request { id: RequestId(I32(2)), method: "textDocument/definition", params: Object {"position": Object {"character": Number(1), "line": Number(4)}, "textDocument": Object {"uri": String("file:///D:/nushell/tests/fixtures/lsp/goto/command.nu")}} })

What makes it even more confusing is goto_definition_of_variable, which uses the same goto_definition works fine.

@fdncred

fdncred commented Nov 1, 2023

Copy link
Copy Markdown
Contributor

Sorry for all the debug spam here @schrieveslaach. I think I may be on to something here. I changed lsp_position_to_location() to this.

    fn lsp_position_to_location(position: &lsp_types::Position, file: &[u8]) -> usize {
        let content = String::from_utf8_lossy(file);
        eprintln!("content: {:?}", content);
        for (p, char_index) in LineIterator::from_file(&content) {
            let ch = match content.chars().nth(char_index) {
                Some('\n') => "LF".to_string(),
                Some('\r') => "CR".to_string(),
                Some(v) => v.to_string(),
                _ => "err".to_string(),
            };
            eprintln!("p: {:?}, char_index: {}, char: {}", p, char_index, ch);
            if p == *position {
                eprintln!("found match: p: {:?} char_index: {}", p, char_index);
                return char_index;
            }
        }
        eprintln!("not found");
        content.len() - 1
    }

So I could see how it was checking the data. It looks to me that the LineIterator isn't quite working right because of this output.

content: "def greet [name] {\r\n  $\"hello ($name)\"\r\n}\r\n\r\ngreet nushell\r\n"
p: Position { line: 0, character: 0 }, char_index: 0, char: d
p: Position { line: 0, character: 1 }, char_index: 1, char: e
p: Position { line: 0, character: 2 }, char_index: 2, char: f
p: Position { line: 0, character: 3 }, char_index: 3, char:
p: Position { line: 0, character: 4 }, char_index: 4, char: g
p: Position { line: 0, character: 5 }, char_index: 5, char: r
p: Position { line: 0, character: 6 }, char_index: 6, char: e
p: Position { line: 0, character: 7 }, char_index: 7, char: e
p: Position { line: 0, character: 8 }, char_index: 8, char: t
p: Position { line: 0, character: 9 }, char_index: 9, char:
p: Position { line: 0, character: 10 }, char_index: 10, char: [
p: Position { line: 0, character: 11 }, char_index: 11, char: n
p: Position { line: 0, character: 12 }, char_index: 12, char: a
p: Position { line: 0, character: 13 }, char_index: 13, char: m
p: Position { line: 0, character: 14 }, char_index: 14, char: e
p: Position { line: 0, character: 15 }, char_index: 15, char: ]
p: Position { line: 0, character: 16 }, char_index: 16, char:
p: Position { line: 0, character: 17 }, char_index: 17, char: {
p: Position { line: 1, character: 0 }, char_index: 19, char: LF
p: Position { line: 1, character: 1 }, char_index: 20, char:
p: Position { line: 1, character: 2 }, char_index: 21, char:
p: Position { line: 1, character: 3 }, char_index: 22, char: $
p: Position { line: 1, character: 4 }, char_index: 23, char: "
p: Position { line: 1, character: 5 }, char_index: 24, char: h
p: Position { line: 1, character: 6 }, char_index: 25, char: e
p: Position { line: 1, character: 7 }, char_index: 26, char: l
p: Position { line: 1, character: 8 }, char_index: 27, char: l
p: Position { line: 1, character: 9 }, char_index: 28, char: o
p: Position { line: 1, character: 10 }, char_index: 29, char:
p: Position { line: 1, character: 11 }, char_index: 30, char: (
p: Position { line: 1, character: 12 }, char_index: 31, char: $
p: Position { line: 1, character: 13 }, char_index: 32, char: n
p: Position { line: 1, character: 14 }, char_index: 33, char: a
p: Position { line: 1, character: 15 }, char_index: 34, char: m
p: Position { line: 1, character: 16 }, char_index: 35, char: e
p: Position { line: 1, character: 17 }, char_index: 36, char: )
p: Position { line: 2, character: 0 }, char_index: 38, char: CR
p: Position { line: 3, character: 0 }, char_index: 40, char: }
p: Position { line: 4, character: 0 }, char_index: 41, char: CR
p: Position { line: 4, character: 1 }, char_index: 42, char: LF
p: Position { line: 4, character: 2 }, char_index: 43, char: CR
p: Position { line: 4, character: 3 }, char_index: 44, char: LF
p: Position { line: 4, character: 4 }, char_index: 45, char: g
p: Position { line: 4, character: 5 }, char_index: 46, char: r
found match: p: Position { line: 4, character: 5 } char_index: 46

Notice that I changed "4, 1" to "4, 5" in goto_definition_of_command() and now it's finding something.

        let resp = goto_definition(script.clone(), 4, 5);
        eprintln!("response: {:?}", resp);
response: Response(Response { id: RequestId(I32(2)), result: Some(Object {"range": Object {"end": Object {"character": Number(0), "line": Number(4)}, "start": Object {"character": Number(17), "line": Number(0)}}, "uri": String("file:///D:/nushell/tests/fixtures/lsp/goto/command.nu")}), error: None })

Which means that if I change the assert to this

        assert_json_eq!(
            result,
            serde_json::json!({
               "uri": script,
               "range": {
                  "start": { "line": 0, "character": 17 },
                  "end": { "line": 4, "character": 0 }
               }
            })
        );

it passes on Windows. That's probably a good thing but I'm also guessing that it would fail on Linux. So, I'm still thinking these errors are all about line endings. I can't really mess with this anymore for now. Hope something here helps!

@schrieveslaach
schrieveslaach force-pushed the lsp branch 3 times, most recently from 59d0019 to 5769fe2 Compare November 1, 2023 20:35
This commit integrates a language server into nushell so that IDEs don't
have to convert CLI option back and forth.
@schrieveslaach

Copy link
Copy Markdown
Contributor Author

@fdncred, thank you very much for looking into this.

During the day I came to the conclusion that maybe a rope would be a good data structure for the rescue because a) it provides indexing and conversion out of the box and b) when start working on messages of textDocument/did* it is probably required anyway to efficiently update the in memory file content (compare content_changes of LSP types and insert of ropey). And voila ropey fixed the bugs on Windows and I also found a bug in my unit tests. 😍

Maybe, it is also worthwhile to use this structure at the core of Nushell but that is out of scope of this PR. I just wanted to start a conversation on it.

I'll go ahead and mark this PR as ready.

@schrieveslaach
schrieveslaach marked this pull request as ready for review November 1, 2023 20:53

@fdncred fdncred left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wow! Looking at 8ff2ba7, it seems like ropey significantly cleaned up the code. I like not seeing all that manual span/position calculation. I think this looks good to me.

@fdncred
fdncred merged commit 0ca8fcf into nushell:main Nov 2, 2023
@fdncred

fdncred commented Nov 2, 2023

Copy link
Copy Markdown
Contributor

Let's go!

@jokeyrhyme

Copy link
Copy Markdown
Contributor

Amazing, great work! <3

@schrieveslaach

Copy link
Copy Markdown
Contributor Author

Thanks a lot for accepting my contribution.

@fdncred

fdncred commented Nov 3, 2023

Copy link
Copy Markdown
Contributor

@schrieveslaach People are already testing it and trying to integrate it into nvim and helix. If you waant to participate in these chats, please come to our #editor-support on Discord.

@JosephTLyons

Copy link
Copy Markdown
Contributor

Very cool! This might make it easier for us (Zed) to integrate the language server!

@fdncred

fdncred commented Nov 3, 2023 •

Copy link
Copy Markdown
Contributor

Very cool! This might make it easier for us (Zed) to integrate the language server!

@JosephTLyons Hopefully so, this is very early and things don't work right yet. I didn't have any problems with goto definition but the other 2 things that are enabled are still a little buggy.

@schrieveslaach
schrieveslaach deleted the lsp branch November 3, 2023 22:21
hardfau1t pushed a commit to hardfau1t/nushell that referenced this pull request Dec 14, 2023
# Description

This commit integrates a language server into nushell so that IDEs don't
have to convert CLI option back and forth.

- fixes nushell/vscode-nushell-lang#117
- fixes jokeyrhyme/nuls#8

Tracking tasks


- [x]
[textDocument/hover](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_hover)
-> `nu --ide-hover`
- [x]
[textDocument/completion](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_completion)
-> `nu --ide-complete`
- [x]
[textDocument/definition](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_definition)
-> `nu --ide-goto-def`
- ~~[ ]
[textDocument/didChange](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_didChange),
[textDocument/didClose](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_didClose),
and
[textDocument/didOpen](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_didOpen)~~
(will be done in a follow-up PR)
- ~~[ ]
[textDocument/inlayHint](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_inlayHint)
-> `nu --ide-check`~~ (will be done in a follow-up PR)
- ~~[ ]
[textDocument/publishDiagnostics](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_publishDiagnostics)
-> `nu --ide-check`~~ (will be done in a follow-up PR)
- ~~[ ]
[workspace/configuration](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_configuration)~~
(will be done in a follow-up PR)
- ~~[ ]
[workspace/didChangeConfiguration](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_didChangeConfiguration)~~
(will be done in a follow-up PR)


# User-Facing Changes

The command line options `--lsp` will start a LSP server.

# Tests + Formatting
<!--
Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```
-->

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
dmatos2012 pushed a commit to dmatos2012/nushell that referenced this pull request Feb 20, 2024
# Description

This commit integrates a language server into nushell so that IDEs don't
have to convert CLI option back and forth.

- fixes nushell/vscode-nushell-lang#117
- fixes jokeyrhyme/nuls#8

Tracking tasks


- [x]
[textDocument/hover](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_hover)
-> `nu --ide-hover`
- [x]
[textDocument/completion](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_completion)
-> `nu --ide-complete`
- [x]
[textDocument/definition](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_definition)
-> `nu --ide-goto-def`
- ~~[ ]
[textDocument/didChange](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_didChange),
[textDocument/didClose](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_didClose),
and
[textDocument/didOpen](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_didOpen)~~
(will be done in a follow-up PR)
- ~~[ ]
[textDocument/inlayHint](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_inlayHint)
-> `nu --ide-check`~~ (will be done in a follow-up PR)
- ~~[ ]
[textDocument/publishDiagnostics](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_publishDiagnostics)
-> `nu --ide-check`~~ (will be done in a follow-up PR)
- ~~[ ]
[workspace/configuration](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_configuration)~~
(will be done in a follow-up PR)
- ~~[ ]
[workspace/didChangeConfiguration](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_didChangeConfiguration)~~
(will be done in a follow-up PR)


# User-Facing Changes

The command line options `--lsp` will start a LSP server.

# Tests + Formatting
<!--
Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to
check that you're using the standard code style
- `cargo test --workspace` to check that all tests pass (on Windows make
sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```
-->

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
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.

incorporate language server directly in the upstream nu executable Standalone LSP Server in Rust

5 participants