From bdc2558eac9f052984cec22c61bb902c6e65eefa Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Thu, 15 Feb 2024 22:01:49 +0200 Subject: [PATCH] Add default language server settings to display inlay hints for Go and TypeScript (#7854) Hints are still disabled by default in Zed, but when those get enabled, the language server settings allow to display those instantly without further server configuration, which might be not obvious. Also add the documentation enties for those settings and their defaults in Zed. Closes https://github.com/zed-industries/zed/issues/7821 Release Notes: - Added default settings for TypeScript and Go LSP servers to enable inlay hints when those are turned on in Zed ([7821](https://github.com/zed-industries/zed/issues/7821)) --- crates/zed/src/languages/go.rs | 9 +++++++ crates/zed/src/languages/typescript.rs | 10 ++++++++ docs/src/languages/go.md | 34 +++++++++++++++++++++++++ docs/src/languages/typescript.md | 35 ++++++++++++++++++++++++++ 4 files changed, 88 insertions(+) diff --git a/crates/zed/src/languages/go.rs b/crates/zed/src/languages/go.rs index cb171d5bd30fe22f7844d9d69be2e36895258ab6..83adf45d4b2c12ab2226c9c4d1def16d7abfc878 100644 --- a/crates/zed/src/languages/go.rs +++ b/crates/zed/src/languages/go.rs @@ -174,6 +174,15 @@ impl super::LspAdapter for GoLspAdapter { fn initialization_options(&self) -> Option { Some(json!({ "usePlaceholders": true, + "hints": { + "assignVariableTypes": true, + "compositeLiteralFields": true, + "compositeLiteralTypes": true, + "constantValues": true, + "functionTypeParameters": true, + "parameterNames": true, + "rangeVariableTypes": true + } })) } diff --git a/crates/zed/src/languages/typescript.rs b/crates/zed/src/languages/typescript.rs index 6ee8e34bfd3ad63f0c55b8ae1733a88b2d3339c6..34640d0ed396e2e3a96c82416e03470a5acd2142 100644 --- a/crates/zed/src/languages/typescript.rs +++ b/crates/zed/src/languages/typescript.rs @@ -160,6 +160,16 @@ impl LspAdapter for TypeScriptLspAdapter { "tsserver": { "path": "node_modules/typescript/lib", }, + "preferences": { + "includeInlayParameterNameHints": "all", + "includeInlayParameterNameHintsWhenArgumentMatchesName": true, + "includeInlayFunctionParameterTypeHints": true, + "includeInlayVariableTypeHints": true, + "includeInlayVariableTypeHintsWhenTypeMatchesName": true, + "includeInlayPropertyDeclarationTypeHints": true, + "includeInlayFunctionLikeReturnTypeHints": true, + "includeInlayEnumMemberValueHints": true, + } })) } diff --git a/docs/src/languages/go.md b/docs/src/languages/go.md index 29924aa74637d901ddded94cbb5d78ea2847a39e..79ab5610fb520c68f2af77bcf00bfa645dfa108c 100644 --- a/docs/src/languages/go.md +++ b/docs/src/languages/go.md @@ -3,6 +3,40 @@ - Tree Sitter: [tree-sitter-go](https://github.com/tree-sitter/tree-sitter-go) - Language Server: [gopls](https://github.com/golang/tools/tree/master/gopls) +## Inlay Hints + +Zed sets the following initialization options for inlay hints: + +```json +"hints": { + "assignVariableTypes": true, + "compositeLiteralFields": true, + "compositeLiteralTypes": true, + "constantValues": true, + "functionTypeParameters": true, + "parameterNames": true, + "rangeVariableTypes": true +} +``` + +to make the language server send back inlay hints when Zed has them enabled in the settings. + +Use +```json +"lsp": { + "$LANGUAGE_SERVER_NAME": { + "initialization_options": { + "hints": { + .... + } + } + } +} +``` +to override these settings. + +See https://github.com/golang/tools/blob/master/gopls/doc/inlayHints.md for more information. + # Go Mod - Tree Sitter: [tree-sitter-gomod](https://github.com/camdencheek/tree-sitter-go-mod) diff --git a/docs/src/languages/typescript.md b/docs/src/languages/typescript.md index 91b72115feb63348803eb42702b580496b4e94b4..4bfd15dc160a0555fb673a13f269c0c93c2fc211 100644 --- a/docs/src/languages/typescript.md +++ b/docs/src/languages/typescript.md @@ -2,3 +2,38 @@ - Tree Sitter: [tree-sitter-typescript](https://github.com/tree-sitter/tree-sitter-typescript) - Language Server: [typescript-language-server](https://github.com/typescript-language-server/typescript-language-server) + +## Inlay Hints + +Zed sets the following initialization options for inlay hints: + +```json +"preferences": { + "includeInlayParameterNameHints": "all", + "includeInlayParameterNameHintsWhenArgumentMatchesName": true, + "includeInlayFunctionParameterTypeHints": true, + "includeInlayVariableTypeHints": true, + "includeInlayVariableTypeHintsWhenTypeMatchesName": true, + "includeInlayPropertyDeclarationTypeHints": true, + "includeInlayFunctionLikeReturnTypeHints": true, + "includeInlayEnumMemberValueHints": true, +} +``` + +to make the language server send back inlay hints when Zed has them enabled in the settings. + +Use +```json +"lsp": { + "$LANGUAGE_SERVER_NAME": { + "initialization_options": { + "preferences": { + .... + } + } + } +} +``` +to override these settings. + +See https://github.com/typescript-language-server/typescript-language-server?tab=readme-ov-file#inlay-hints-textdocumentinlayhint for more information.