Skip to content

Commit

Permalink
Integrated Language Server (nushell#10723)
Browse files Browse the repository at this point in the history
# 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.
-->
  • Loading branch information
schrieveslaach authored and dmatos2012 committed Feb 20, 2024
1 parent de7bf3d commit f40b4c1
Show file tree
Hide file tree
Showing 13 changed files with 1,102 additions and 3 deletions.
75 changes: 75 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ members = [
"crates/nu-cmd-lang",
"crates/nu-cmd-dataframe",
"crates/nu-command",
"crates/nu-lsp",
"crates/nu-protocol",
"crates/nu-plugin",
"crates/nu_plugin_inc",
Expand All @@ -56,6 +57,7 @@ nu-command = { path = "./crates/nu-command", version = "0.86.1" }
nu-engine = { path = "./crates/nu-engine", version = "0.86.1" }
nu-explore = { path = "./crates/nu-explore", version = "0.86.1" }
nu-json = { path = "./crates/nu-json", version = "0.86.1" }
nu-lsp = { path = "./crates/nu-lsp/", version = "0.86.1" }
nu-parser = { path = "./crates/nu-parser", version = "0.86.1" }
nu-path = { path = "./crates/nu-path", version = "0.86.1" }
nu-plugin = { path = "./crates/nu-plugin", optional = true, version = "0.86.1" }
Expand Down
29 changes: 29 additions & 0 deletions crates/nu-lsp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
authors = ["The Nushell Project Developers"]
description = "Nushell's integrated LSP server"
repository = "https://github.com/nushell/nushell/tree/main/crates/nu-lsp"
name = "nu-lsp"
version = "0.86.1"
edition = "2021"
license = "MIT"

[dependencies]
nu-cli = { path = "../nu-cli", version = "0.86.1" }
nu-parser = { path = "../nu-parser", version = "0.86.1" }
nu-protocol = { path = "../nu-protocol", version = "0.86.1" }
reedline = { version = "0.25" }

lsp-types = "0.94.1"
lsp-server = "0.7.4"
miette = "5.10"
ropey = "1.6.1"
serde = "1.0"
serde_json = "1.0"

[dev-dependencies]
nu-cmd-lang = { path = "../nu-cmd-lang", version = "0.86.1" }
nu-command = { path = "../nu-command", version = "0.86.1" }
nu-test-support = { path = "../nu-test-support", version = "0.86.1" }

assert-json-diff = "2.0"
tempfile = "3.2"
28 changes: 28 additions & 0 deletions crates/nu-lsp/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
The MIT License (MIT)

Copyright (c) 2014 The Rust Project Developers
Copyright (c) 2020-2023 The Nushell Project Developers

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Loading

0 comments on commit f40b4c1

Please # to comment.