From b274ec19fdf67bb4e7ecc24c79638e7673880ba1 Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Sat, 20 Apr 2024 08:16:38 -0400 Subject: [PATCH] improve `nu --lsp` command tooltips (#12589) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description This PR improves the `nu --lsp` tooltips by using nu code blocks around the examples and a few other places. This is what it looks like in Zed. ![Screenshot 2024-04-19 at 8 20 53 PM](https://github.com/nushell/nushell/assets/343840/20d51dcc-f3b2-4f2b-9d43-5817dd3913df) Here it is in Helix. ![image](https://github.com/nushell/nushell/assets/343840/a9e7d6b9-cd21-4a5a-9c88-9af17a2b2363) This coloring is far from perfect, but it's what the tree-sitter-nu queries generate. # User-Facing Changes # Tests + Formatting # After Submitting --- crates/nu-lsp/src/lib.rs | 10 +++++----- crates/nu-lsp/src/notification.rs | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/nu-lsp/src/lib.rs b/crates/nu-lsp/src/lib.rs index adee58349a..939bb0e4e0 100644 --- a/crates/nu-lsp/src/lib.rs +++ b/crates/nu-lsp/src/lib.rs @@ -365,7 +365,7 @@ impl LanguageServer { } // Usage - description.push_str("### Usage \n```\n"); + description.push_str("### Usage \n```nu\n"); let signature = decl.signature(); description.push_str(&format!(" {}", signature.name)); if !signature.named.is_empty() { @@ -472,7 +472,7 @@ impl LanguageServer { // Input/output types if !signature.input_output_types.is_empty() { description.push_str("\n### Input/output types\n"); - description.push_str("\n```\n"); + description.push_str("\n```nu\n"); for input_output in &signature.input_output_types { description .push_str(&format!(" {} | {}\n", input_output.0, input_output.1)); @@ -485,7 +485,7 @@ impl LanguageServer { description.push_str("### Example(s)\n"); for example in decl.examples() { description.push_str(&format!( - " {}\n```\n {}\n```\n", + " {}\n```nu\n {}\n```\n", example.description, example.example )); } @@ -1003,7 +1003,7 @@ mod tests { serde_json::json!({ "contents": { "kind": "markdown", - "value": "Renders some greeting message\n### Usage \n```\n hello {flags}\n```\n\n### Flags\n\n `-h`, `--help` - Display the help message for this command\n\n" + "value": "Renders some greeting message\n### Usage \n```nu\n hello {flags}\n```\n\n### Flags\n\n `-h`, `--help` - Display the help message for this command\n\n" } }) ); @@ -1033,7 +1033,7 @@ mod tests { serde_json::json!({ "contents": { "kind": "markdown", - "value": "Concatenate multiple strings into a single string, with an optional separator between each.\n### Usage \n```\n str join {flags} \n```\n\n### Flags\n\n `-h`, `--help` - Display the help message for this command\n\n\n### Parameters\n\n `separator: string` - Optional separator to use when creating string.\n\n\n### Input/output types\n\n```\n list | string\n string | string\n\n```\n### Example(s)\n Create a string from input\n```\n ['nu', 'shell'] | str join\n```\n Create a string from input with a separator\n```\n ['nu', 'shell'] | str join '-'\n```\n" + "value": "Concatenate multiple strings into a single string, with an optional separator between each.\n### Usage \n```nu\n str join {flags} \n```\n\n### Flags\n\n `-h`, `--help` - Display the help message for this command\n\n\n### Parameters\n\n `separator: string` - Optional separator to use when creating string.\n\n\n### Input/output types\n\n```nu\n list | string\n string | string\n\n```\n### Example(s)\n Create a string from input\n```nu\n ['nu', 'shell'] | str join\n```\n Create a string from input with a separator\n```nu\n ['nu', 'shell'] | str join '-'\n```\n" } }) ); diff --git a/crates/nu-lsp/src/notification.rs b/crates/nu-lsp/src/notification.rs index 8bfab92664..a715a67d4f 100644 --- a/crates/nu-lsp/src/notification.rs +++ b/crates/nu-lsp/src/notification.rs @@ -121,7 +121,7 @@ mod tests { serde_json::json!({ "contents": { "kind": "markdown", - "value": "Create a variable and give it a value.\n\nThis command is a parser keyword. For details, check:\n https://www.nushell.sh/book/thinking_in_nu.html\n### Usage \n```\n let {flags} \n```\n\n### Flags\n\n `-h`, `--help` - Display the help message for this command\n\n\n### Parameters\n\n `var_name: any` - Variable name.\n\n `initial_value: any` - Equals sign followed by value.\n\n\n### Input/output types\n\n```\n any | nothing\n\n```\n### Example(s)\n Set a variable to a value\n```\n let x = 10\n```\n Set a variable to the result of an expression\n```\n let x = 10 + 100\n```\n Set a variable based on the condition\n```\n let x = if false { -1 } else { 1 }\n```\n" + "value": "Create a variable and give it a value.\n\nThis command is a parser keyword. For details, check:\n https://www.nushell.sh/book/thinking_in_nu.html\n### Usage \n```nu\n let {flags} \n```\n\n### Flags\n\n `-h`, `--help` - Display the help message for this command\n\n\n### Parameters\n\n `var_name: any` - Variable name.\n\n `initial_value: any` - Equals sign followed by value.\n\n\n### Input/output types\n\n```nu\n any | nothing\n\n```\n### Example(s)\n Set a variable to a value\n```nu\n let x = 10\n```\n Set a variable to the result of an expression\n```nu\n let x = 10 + 100\n```\n Set a variable based on the condition\n```nu\n let x = if false { -1 } else { 1 }\n```\n" } }) ); @@ -162,7 +162,7 @@ hello"#, serde_json::json!({ "contents": { "kind": "markdown", - "value": "Renders some updated greeting message\n### Usage \n```\n hello {flags}\n```\n\n### Flags\n\n `-h`, `--help` - Display the help message for this command\n\n" + "value": "Renders some updated greeting message\n### Usage \n```nu\n hello {flags}\n```\n\n### Flags\n\n `-h`, `--help` - Display the help message for this command\n\n" } }) ); @@ -207,7 +207,7 @@ hello"#, serde_json::json!({ "contents": { "kind": "markdown", - "value": "Renders some updated greeting message\n### Usage \n```\n hello {flags}\n```\n\n### Flags\n\n `-h`, `--help` - Display the help message for this command\n\n" + "value": "Renders some updated greeting message\n### Usage \n```nu\n hello {flags}\n```\n\n### Flags\n\n `-h`, `--help` - Display the help message for this command\n\n" } }) );