From 61b04b384cd43be984d3f4236c96ea2fdf819317 Mon Sep 17 00:00:00 2001 From: Tamika Nomara Date: Mon, 4 Aug 2025 11:49:04 +0400 Subject: [PATCH] Add annotations for exporting VSCode settings --- .../resources/schema.json | 139 ++++++++++++------ .../src/config/configs/code_action.rs | 3 +- .../src/config/configs/codelen.rs | 7 +- .../src/config/configs/completion.rs | 19 ++- .../src/config/configs/diagnostics.rs | 3 +- .../src/config/configs/document_color.rs | 3 +- .../src/config/configs/hover.rs | 3 +- .../src/config/configs/inlayhint.rs | 49 +++++- .../src/config/configs/inline_values.rs | 3 +- .../src/config/configs/mod.rs | 2 +- .../src/config/configs/references.rs | 10 +- .../src/config/configs/semantictoken.rs | 3 +- .../src/config/configs/workspace.rs | 7 +- .../emmylua_code_analysis/src/config/mod.rs | 4 +- 14 files changed, 176 insertions(+), 79 deletions(-) diff --git a/crates/emmylua_code_analysis/resources/schema.json b/crates/emmylua_code_analysis/resources/schema.json index 4980072cf..12d10aab4 100644 --- a/crates/emmylua_code_analysis/resources/schema.json +++ b/crates/emmylua_code_analysis/resources/schema.json @@ -16,7 +16,7 @@ } }, "codeLens": { - "$ref": "#/$defs/EmmyrcCodeLen", + "$ref": "#/$defs/EmmyrcCodeLens", "default": { "enable": true } @@ -438,19 +438,21 @@ "type": "object", "properties": { "insertSpace": { - "description": "Whether to insert space after '---'", + "description": "Add space after `---` comments when inserting `@diagnostic disable-next-line`.", "type": "boolean", - "default": false + "default": false, + "x-vscode-setting": true } } }, - "EmmyrcCodeLen": { + "EmmyrcCodeLens": { "type": "object", "properties": { "enable": { - "description": "Whether to enable code lens.", + "description": "Enable code lens.", "type": "boolean", - "default": true + "default": true, + "x-vscode-setting": true } } }, @@ -459,9 +461,10 @@ "type": "object", "properties": { "autoRequire": { - "description": "Whether to automatically require modules.", + "description": "Automatically insert call to `require` when autocompletion\ninserts objects from other modules.", "type": "boolean", - "default": true + "default": true, + "x-vscode-setting": true }, "autoRequireFunction": { "description": "The function used for auto-requiring modules.", @@ -479,9 +482,10 @@ "default": "." }, "baseFunctionIncludesName": { - "description": "Whether to include the name in the base function completion. effect: `function () end` -> `function name() end`.", + "description": "Whether to include the name in the base function completion. Effect: `function () end` -> `function name() end`.", "type": "boolean", - "default": true + "default": true, + "x-vscode-setting": true }, "callSnippet": { "description": "Whether to use call snippets in completions.", @@ -489,14 +493,34 @@ "default": false }, "enable": { - "description": "Whether to enable code completion.", + "description": "Enable autocompletion.", "type": "boolean", - "default": true + "default": true, + "x-vscode-setting": true }, "postfix": { - "description": "The postfix trigger used in completions.", - "type": "string", - "default": "@" + "description": "Symbol that's used to trigger postfix autocompletion.", + "type": "string", + "default": "@", + "x-vscode-setting": { + "default": null, + "enum": [ + null, + "@", + ".", + ":" + ], + "enumItemLabels": [ + "Default" + ], + "markdownEnumDescriptions": [ + "%config.common.enum.default.description%" + ], + "type": [ + "string", + "null" + ] + } } } }, @@ -505,13 +529,14 @@ "type": "object", "properties": { "diagnosticInterval": { - "description": "The interval in milliseconds to perform diagnostics.", + "description": "Delay between opening/changing a file and scanning it for errors, in milliseconds.", "type": [ "integer", "null" ], "format": "uint64", - "minimum": 0 + "minimum": 0, + "x-vscode-setting": true }, "disable": { "description": "A list of diagnostic codes that are disabled.", @@ -585,9 +610,10 @@ "type": "object", "properties": { "enable": { - "description": "Whether to enable document color.", + "description": "Enable parsing strings for color tags and showing a color picker next to them.", "type": "boolean", - "default": true + "default": true, + "x-vscode-setting": true } } }, @@ -624,9 +650,10 @@ "type": "object", "properties": { "enable": { - "description": "Whether to enable hover.", + "description": "Enable showing documentation on hover.", "type": "boolean", - "default": true + "default": true, + "x-vscode-setting": true } } }, @@ -634,39 +661,46 @@ "type": "object", "properties": { "enable": { - "description": "Whether to enable inlay hints.", + "description": "Enable inlay hints.", "type": "boolean", - "default": true + "default": true, + "x-vscode-setting": true }, "enumParamHint": { - "description": "Whether to enable enum parameter hints.", + "description": "Show name of enumerator when passing a literal value to a function\nthat expects an enum.\n\nExample:\n\n```lua\n--- @enum Level\nlocal Foo = {\n Info = 1,\n Error = 2,\n}\n\n--- @param l Level\nfunction print_level(l) end\n\nprint_level(1 --[[ Hint: Level.Info ]])\n```", "type": "boolean", - "default": false + "default": false, + "x-vscode-setting": true }, "indexHint": { - "description": "Whether to enable index hints.", + "description": "Show named array indexes.\n\nExample:\n\n```lua\nlocal array = {\n [1] = 1, -- [name]\n}\n\nprint(array[1] --[[ Hint: name ]])\n```", "type": "boolean", - "default": true + "default": true, + "x-vscode-setting": true }, "localHint": { - "description": "Whether to enable local hints.\nWhether to enable override hints.", + "description": "Show types of local variables.", "type": "boolean", - "default": true + "default": true, + "x-vscode-setting": true }, "metaCallHint": { - "description": "Whether to enable meta __call operator hints.", + "description": "Show hint when calling an object results in a call to\nits meta table's `__call` function.", "type": "boolean", - "default": true + "default": true, + "x-vscode-setting": true }, "overrideHint": { - "description": "Whether to enable override hints.", + "description": "Show methods that override functions from base class.", "type": "boolean", - "default": true + "default": true, + "x-vscode-setting": true }, "paramHint": { - "description": "Whether to enable parameter hints.", + "description": "Show parameter names in function calls and parameter types in function definitions.", "type": "boolean", - "default": true + "default": true, + "x-vscode-setting": true } } }, @@ -674,9 +708,10 @@ "type": "object", "properties": { "enable": { - "description": "Whether to enable inline values.", + "description": "Show inline values during debug.", "type": "boolean", - "default": true + "default": true, + "x-vscode-setting": true } } }, @@ -723,19 +758,22 @@ "type": "object", "properties": { "enable": { - "description": "Whether to enable reference search.", + "description": "Enable searching for symbol usages.", "type": "boolean", - "default": true + "default": true, + "x-vscode-setting": true }, "fuzzySearch": { - "description": "Determines whether to enable fuzzy searching for fields where references cannot be found.", + "description": "Use fuzzy search when searching for symbol usages\nand normal search didn't find anything.", "type": "boolean", - "default": true + "default": true, + "x-vscode-setting": true }, "shortStringSearch": { - "description": "Cache Short string for search", + "description": "Also search for usages in strings.", "type": "boolean", - "default": false + "default": false, + "x-vscode-setting": true } } }, @@ -806,9 +844,10 @@ "type": "object", "properties": { "enable": { - "description": "Whether to enable semantic token.", + "description": "Enable semantic tokens.", "type": "boolean", - "default": true + "default": true, + "x-vscode-setting": true } } }, @@ -855,9 +894,10 @@ "type": "object", "properties": { "enableReindex": { - "description": "Enable reindex.", + "description": "Enable full project reindex after changing a file.", "type": "boolean", - "default": false + "default": false, + "x-vscode-setting": true }, "encoding": { "description": "Encoding. eg: \"utf-8\"", @@ -902,11 +942,12 @@ "default": 0 }, "reindexDuration": { - "description": "when save a file, ls will reindex the workspace after reindex_duration milliseconds.", + "description": "Delay between changing a file and full project reindex, in milliseconds.", "type": "integer", "format": "uint64", "default": 5000, - "minimum": 0 + "minimum": 0, + "x-vscode-setting": true }, "workspaceRoots": { "description": "Workspace roots. eg: [\"src\", \"test\"]", diff --git a/crates/emmylua_code_analysis/src/config/configs/code_action.rs b/crates/emmylua_code_analysis/src/config/configs/code_action.rs index 619c06cab..317414e58 100644 --- a/crates/emmylua_code_analysis/src/config/configs/code_action.rs +++ b/crates/emmylua_code_analysis/src/config/configs/code_action.rs @@ -4,8 +4,9 @@ use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug, JsonSchema, Clone)] #[serde(rename_all = "camelCase")] pub struct EmmyrcCodeAction { - /// Whether to insert space after '---' + /// Add space after `---` comments when inserting `@diagnostic disable-next-line`. #[serde(default = "default_false")] + #[schemars(extend("x-vscode-setting" = true))] pub insert_space: bool, } diff --git a/crates/emmylua_code_analysis/src/config/configs/codelen.rs b/crates/emmylua_code_analysis/src/config/configs/codelen.rs index f059eaf15..1ed9128c5 100644 --- a/crates/emmylua_code_analysis/src/config/configs/codelen.rs +++ b/crates/emmylua_code_analysis/src/config/configs/codelen.rs @@ -3,13 +3,14 @@ use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug, JsonSchema, Clone)] #[serde(rename_all = "camelCase")] -pub struct EmmyrcCodeLen { - /// Whether to enable code lens. +pub struct EmmyrcCodeLens { + /// Enable code lens. #[serde(default = "default_true")] + #[schemars(extend("x-vscode-setting" = true))] pub enable: bool, } -impl Default for EmmyrcCodeLen { +impl Default for EmmyrcCodeLens { fn default() -> Self { Self { enable: default_true(), diff --git a/crates/emmylua_code_analysis/src/config/configs/completion.rs b/crates/emmylua_code_analysis/src/config/configs/completion.rs index 91838b3b1..4484c1b46 100644 --- a/crates/emmylua_code_analysis/src/config/configs/completion.rs +++ b/crates/emmylua_code_analysis/src/config/configs/completion.rs @@ -7,11 +7,14 @@ use serde_with::{DefaultOnError, serde_as}; #[serde(rename_all = "camelCase")] /// Configuration for EmmyLua code completion. pub struct EmmyrcCompletion { - /// Whether to enable code completion. + /// Enable autocompletion. #[serde(default = "default_true")] + #[schemars(extend("x-vscode-setting" = true))] pub enable: bool, - /// Whether to automatically require modules. + /// Automatically insert call to `require` when autocompletion + /// inserts objects from other modules. #[serde(default = "default_true")] + #[schemars(extend("x-vscode-setting" = true))] pub auto_require: bool, /// The function used for auto-requiring modules. #[serde(default = "default_require_function")] @@ -26,11 +29,19 @@ pub struct EmmyrcCompletion { #[serde(default)] #[serde_as(deserialize_as = "DefaultOnError")] pub call_snippet: bool, - /// The postfix trigger used in completions. + /// Symbol that's used to trigger postfix autocompletion. #[serde(default = "default_postfix")] + #[schemars(extend("x-vscode-setting" = { + "type": ["string", "null"], + "default": null, + "enum": [null, "@", ".", ":"], + "enumItemLabels": ["Default"], + "markdownEnumDescriptions": ["%config.common.enum.default.description%"], + }))] pub postfix: String, - /// Whether to include the name in the base function completion. effect: `function () end` -> `function name() end`. + /// Whether to include the name in the base function completion. Effect: `function () end` -> `function name() end`. #[serde(default = "default_true")] + #[schemars(extend("x-vscode-setting" = true))] pub base_function_includes_name: bool, } diff --git a/crates/emmylua_code_analysis/src/config/configs/diagnostics.rs b/crates/emmylua_code_analysis/src/config/configs/diagnostics.rs index d8f7036f3..7d173348d 100644 --- a/crates/emmylua_code_analysis/src/config/configs/diagnostics.rs +++ b/crates/emmylua_code_analysis/src/config/configs/diagnostics.rs @@ -28,7 +28,8 @@ pub struct EmmyrcDiagnostic { /// A list of diagnostic codes that are enabled. #[serde(default)] pub enables: Vec, - /// The interval in milliseconds to perform diagnostics. + /// Delay between opening/changing a file and scanning it for errors, in milliseconds. + #[schemars(extend("x-vscode-setting" = true))] pub diagnostic_interval: Option, } diff --git a/crates/emmylua_code_analysis/src/config/configs/document_color.rs b/crates/emmylua_code_analysis/src/config/configs/document_color.rs index 6b19ab6a0..06926b3e7 100644 --- a/crates/emmylua_code_analysis/src/config/configs/document_color.rs +++ b/crates/emmylua_code_analysis/src/config/configs/document_color.rs @@ -4,8 +4,9 @@ use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug, JsonSchema, Clone)] #[serde(rename_all = "camelCase")] pub struct EmmyrcDocumentColor { - /// Whether to enable document color. + /// Enable parsing strings for color tags and showing a color picker next to them. #[serde(default = "default_true")] + #[schemars(extend("x-vscode-setting" = true))] pub enable: bool, } diff --git a/crates/emmylua_code_analysis/src/config/configs/hover.rs b/crates/emmylua_code_analysis/src/config/configs/hover.rs index 96c426e08..3a7508c32 100644 --- a/crates/emmylua_code_analysis/src/config/configs/hover.rs +++ b/crates/emmylua_code_analysis/src/config/configs/hover.rs @@ -4,8 +4,9 @@ use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug, JsonSchema, Clone)] #[serde(rename_all = "camelCase")] pub struct EmmyrcHover { - /// Whether to enable hover. + /// Enable showing documentation on hover. #[serde(default = "default_true")] + #[schemars(extend("x-vscode-setting" = true))] pub enable: bool, } diff --git a/crates/emmylua_code_analysis/src/config/configs/inlayhint.rs b/crates/emmylua_code_analysis/src/config/configs/inlayhint.rs index d110590e2..49c8d63cc 100644 --- a/crates/emmylua_code_analysis/src/config/configs/inlayhint.rs +++ b/crates/emmylua_code_analysis/src/config/configs/inlayhint.rs @@ -4,27 +4,60 @@ use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug, JsonSchema, Clone)] #[serde(rename_all = "camelCase")] pub struct EmmyrcInlayHint { - /// Whether to enable inlay hints. + /// Enable inlay hints. #[serde(default = "default_true")] + #[schemars(extend("x-vscode-setting" = true))] pub enable: bool, - /// Whether to enable parameter hints. + /// Show parameter names in function calls and parameter types in function definitions. #[serde(default = "default_true")] + #[schemars(extend("x-vscode-setting" = true))] pub param_hint: bool, - /// Whether to enable index hints. + /// Show named array indexes. + /// + /// Example: + /// + /// ```lua + /// local array = { + /// [1] = 1, -- [name] + /// } + /// + /// print(array[1] --[[ Hint: name ]]) + /// ``` #[serde(default = "default_true")] + #[schemars(extend("x-vscode-setting" = true))] pub index_hint: bool, - /// Whether to enable local hints. + /// Show types of local variables. #[serde(default = "default_true")] - /// Whether to enable override hints. + #[schemars(extend("x-vscode-setting" = true))] pub local_hint: bool, - /// Whether to enable override hints. + /// Show methods that override functions from base class. #[serde(default = "default_true")] + #[schemars(extend("x-vscode-setting" = true))] pub override_hint: bool, - /// Whether to enable meta __call operator hints. + /// Show hint when calling an object results in a call to + /// its meta table's `__call` function. #[serde(default = "default_true")] + #[schemars(extend("x-vscode-setting" = true))] pub meta_call_hint: bool, - /// Whether to enable enum parameter hints. + /// Show name of enumerator when passing a literal value to a function + /// that expects an enum. + /// + /// Example: + /// + /// ```lua + /// --- @enum Level + /// local Foo = { + /// Info = 1, + /// Error = 2, + /// } + /// + /// --- @param l Level + /// function print_level(l) end + /// + /// print_level(1 --[[ Hint: Level.Info ]]) + /// ``` #[serde(default = "default_false")] + #[schemars(extend("x-vscode-setting" = true))] pub enum_param_hint: bool, } diff --git a/crates/emmylua_code_analysis/src/config/configs/inline_values.rs b/crates/emmylua_code_analysis/src/config/configs/inline_values.rs index f46cefb75..b5b607cda 100644 --- a/crates/emmylua_code_analysis/src/config/configs/inline_values.rs +++ b/crates/emmylua_code_analysis/src/config/configs/inline_values.rs @@ -4,8 +4,9 @@ use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug, JsonSchema, Clone)] #[serde(rename_all = "camelCase")] pub struct EmmyrcInlineValues { - /// Whether to enable inline values. + /// Show inline values during debug. #[serde(default = "default_true")] + #[schemars(extend("x-vscode-setting" = true))] pub enable: bool, } diff --git a/crates/emmylua_code_analysis/src/config/configs/mod.rs b/crates/emmylua_code_analysis/src/config/configs/mod.rs index 973084028..363002e11 100644 --- a/crates/emmylua_code_analysis/src/config/configs/mod.rs +++ b/crates/emmylua_code_analysis/src/config/configs/mod.rs @@ -16,7 +16,7 @@ mod strict; mod workspace; pub use code_action::EmmyrcCodeAction; -pub use codelen::EmmyrcCodeLen; +pub use codelen::EmmyrcCodeLens; pub use completion::{EmmyrcCompletion, EmmyrcFilenameConvention}; pub use diagnostics::EmmyrcDiagnostic; pub use doc::EmmyrcDoc; diff --git a/crates/emmylua_code_analysis/src/config/configs/references.rs b/crates/emmylua_code_analysis/src/config/configs/references.rs index 87bb1ef81..df5cf1c8c 100644 --- a/crates/emmylua_code_analysis/src/config/configs/references.rs +++ b/crates/emmylua_code_analysis/src/config/configs/references.rs @@ -4,14 +4,18 @@ use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug, JsonSchema, Clone)] #[serde(rename_all = "camelCase")] pub struct EmmyrcReference { - /// Whether to enable reference search. + /// Enable searching for symbol usages. #[serde(default = "default_true")] + #[schemars(extend("x-vscode-setting" = true))] pub enable: bool, - /// Determines whether to enable fuzzy searching for fields where references cannot be found. + /// Use fuzzy search when searching for symbol usages + /// and normal search didn't find anything. #[serde(default = "default_true")] + #[schemars(extend("x-vscode-setting" = true))] pub fuzzy_search: bool, - /// Cache Short string for search + /// Also search for usages in strings. #[serde(default = "default_false")] + #[schemars(extend("x-vscode-setting" = true))] pub short_string_search: bool, } diff --git a/crates/emmylua_code_analysis/src/config/configs/semantictoken.rs b/crates/emmylua_code_analysis/src/config/configs/semantictoken.rs index 9cda9ba62..96ca16dbf 100644 --- a/crates/emmylua_code_analysis/src/config/configs/semantictoken.rs +++ b/crates/emmylua_code_analysis/src/config/configs/semantictoken.rs @@ -4,8 +4,9 @@ use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug, JsonSchema, Clone)] #[serde(rename_all = "camelCase")] pub struct EmmyrcSemanticToken { - /// Whether to enable semantic token. + /// Enable semantic tokens. #[serde(default = "default_true")] + #[schemars(extend("x-vscode-setting" = true))] pub enable: bool, } diff --git a/crates/emmylua_code_analysis/src/config/configs/workspace.rs b/crates/emmylua_code_analysis/src/config/configs/workspace.rs index e887a4bf3..3ef90c6b1 100644 --- a/crates/emmylua_code_analysis/src/config/configs/workspace.rs +++ b/crates/emmylua_code_analysis/src/config/configs/workspace.rs @@ -29,12 +29,13 @@ pub struct EmmyrcWorkspace { /// } #[serde(default)] pub module_map: Vec, - - /// when save a file, ls will reindex the workspace after reindex_duration milliseconds. + /// Delay between changing a file and full project reindex, in milliseconds. #[serde(default = "reindex_duration_default")] + #[schemars(extend("x-vscode-setting" = true))] pub reindex_duration: u64, - /// Enable reindex. + /// Enable full project reindex after changing a file. #[serde(default = "enable_reindex_default")] + #[schemars(extend("x-vscode-setting" = true))] pub enable_reindex: bool, } diff --git a/crates/emmylua_code_analysis/src/config/mod.rs b/crates/emmylua_code_analysis/src/config/mod.rs index 042339c64..844b6fc00 100644 --- a/crates/emmylua_code_analysis/src/config/mod.rs +++ b/crates/emmylua_code_analysis/src/config/mod.rs @@ -9,7 +9,7 @@ use std::{ pub use config_loader::{load_configs, load_configs_raw}; use configs::{ - EmmyrcCodeAction, EmmyrcCodeLen, EmmyrcCompletion, EmmyrcDiagnostic, EmmyrcDoc, + EmmyrcCodeAction, EmmyrcCodeLens, EmmyrcCompletion, EmmyrcDiagnostic, EmmyrcDoc, EmmyrcDocumentColor, EmmyrcHover, EmmyrcInlayHint, EmmyrcInlineValues, EmmyrcReference, EmmyrcResource, EmmyrcRuntime, EmmyrcSemanticToken, EmmyrcSignature, EmmyrcStrict, EmmyrcWorkspace, @@ -42,7 +42,7 @@ pub struct Emmyrc { #[serde(default)] pub resource: EmmyrcResource, #[serde(default)] - pub code_lens: EmmyrcCodeLen, + pub code_lens: EmmyrcCodeLens, #[serde(default)] pub strict: EmmyrcStrict, #[serde(default)]