Skip to content

Commit

Permalink
feat: custom build for sumneko schema to include language translation…
Browse files Browse the repository at this point in the history
…s for descriptions
  • Loading branch information
folke committed Sep 9, 2022
1 parent 16d8f90 commit 045585e
Show file tree
Hide file tree
Showing 43 changed files with 70 additions and 62 deletions.
21 changes: 3 additions & 18 deletions lua/settings/build.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local M = {}

---@param schema LspSchema
function M.get_schema(schema)
local json = util.json_decode(util.fetch(schema.settings_url or schema.package_url)) or {}
local json = util.json_decode(util.fetch(schema.package_url)) or {}
local config = json.contributes and json.contributes.configuration or json.properties and json

local properties = {}
Expand All @@ -18,23 +18,8 @@ function M.get_schema(schema)
properties = config.properties
end

if schema.settings_prefix then
local props = {}
for key, value in pairs(properties) do
props[schema.settings_prefix .. key] = value
end
local function fixref(node)
if type(node) == "table" then
for k, v in pairs(node) do
if k == "$ref" then
node[k] = v:gsub("#/properties/", "#/properties/" .. schema.settings_prefix)
end
fixref(v)
end
end
return node
end
properties = fixref(props)
if schema.build then
schema.build(properties)
end

return {
Expand Down
28 changes: 26 additions & 2 deletions lua/settings/schema/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,32 @@ local M = {}
--- @type table<string, LspSchema>
M.overrides = {
sumneko_lua = {
settings_url = "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
settings_prefix = "Lua.",
build = function(props)
local lns = Util.json_decode(
Util.fetch("https://raw.githubusercontent.com/sumneko/vscode-lua/master/package.nls.json")
) or {}

local function translate(desc)
return lns[desc:gsub("%%", "")] or desc
end

local function fixdoc(node)
if type(node) == "table" then
for k, v in pairs(node) do
if k == "description" or k == "markdownDescription" then
node[k] = translate(v)
end
if k == "markdownEnumDescriptions" then
for i, d in ipairs(v) do
v[i] = translate(d)
end
end
fixdoc(v)
end
end
end
fixdoc(props)
end,
},
}

Expand Down
3 changes: 1 addition & 2 deletions lua/settings/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@

---@class LspSchema
---@field package_url string url of the package.json of the LSP server
---@field settings_url string url of the settings json schema of the LSP server
---@field settings_file string file of the settings json schema of the LSP server
---@field settings_prefix string|nil
---@field build fun(props: table)
2 changes: 1 addition & 1 deletion schemas/astro.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"properties": {"astro.typescript.rename.enabled": {"description": "Enable rename functionality for JS/TS variables inside Astro files", "type": "boolean", "default": true, "title": "TypeScript: Rename"}, "astro.format.indentFrontmatter": {"deprecationMessage": "The `astro.format` settings are deprecated. Formatting is now powered by Prettier and can be configured through a Prettier configuration file.", "description": "Indent the formatter by one level of indentation", "type": "boolean", "default": false, "title": "Formatting: Indent frontmatter"}, "astro.typescript.hover.enabled": {"description": "Enable hover info for TypeScript", "type": "boolean", "default": true, "title": "TypeScript: Hover Info"}, "astro.html.enabled": {"description": "Enable HTML features", "type": "boolean", "default": true, "title": "HTML"}, "astro.trace.server": {"description": "Traces the communication between VS Code and the language server.", "enum": ["off", "messages", "verbose"], "scope": "window", "type": "string", "default": "off"}, "astro.html.completions.enabled": {"description": "Enable completions for HTML", "type": "boolean", "default": true, "title": "HTML: Completions"}, "astro.css.enabled": {"description": "Enable CSS features", "type": "boolean", "default": true, "title": "CSS"}, "astro.typescript.definitions.enabled": {"description": "Enable go to definition for TypeScript", "type": "boolean", "default": true, "title": "TypeScript: Go to Definition"}, "astro.typescript.signatureHelp.enabled": {"description": "Enable signature help (parameter hints) for TypeScript", "type": "boolean", "default": true, "title": "TypeScript: Signature Help"}, "astro.css.completions.emmet": {"description": "Enable Emmet completions for CSS", "type": "boolean", "default": true, "title": "CSS: Emmet Completions"}, "astro.css.documentSymbols.enabled": {"description": "Enable document symbols for CSS", "type": "boolean", "default": true, "title": "CSS: Symbols in Outline"}, "astro.css.hover.enabled": {"description": "Enable hover info for CSS", "type": "boolean", "default": true, "title": "CSS: Hover Info"}, "astro.html.hover.enabled": {"description": "Enable hover info for HTML", "type": "boolean", "default": true, "title": "HTML: Hover Info"}, "astro.typescript.codeActions.enabled": {"description": "Enable code actions for TypeScript", "type": "boolean", "default": true, "title": "TypeScript: Code Actions"}, "astro.typescript.enabled": {"description": "Enable TypeScript features", "type": "boolean", "default": true, "title": "TypeScript"}, "astro.typescript.diagnostics.enabled": {"description": "Enable diagnostic messages for TypeScript", "type": "boolean", "default": true, "title": "TypeScript: Diagnostics"}, "astro.typescript.completions.enabled": {"description": "Enable completions for TypeScript", "type": "boolean", "default": true, "title": "TypeScript: Completions"}, "astro.typescript.allowArbitraryAttributes": {"description": "Enable the usage of non-standard HTML attributes, such as the ones added by AlpineJS or petite-vue", "type": "boolean", "default": false, "title": "TypeScript: Allow arbitrary attributes on HTML elements"}, "astro.html.tagComplete.enabled": {"description": "Enable tag completion for HTML", "type": "boolean", "default": true, "title": "HTML: Tag Completion"}, "astro.typescript.semanticTokens.enabled": {"description": "Enable semantic tokens (used for semantic highlighting) for TypeScript.", "type": "boolean", "default": true, "title": "TypeScript: Semantic Tokens"}, "astro.language-server.ls-path": {"description": "Path to the language server executable. You won't need this in most cases, set this only when needing a specific version of the language server", "scope": "application", "type": "string", "title": "Language Server: Path"}, "astro.html.completions.emmet": {"description": "Enable Emmet completions for HTML", "type": "boolean", "default": true, "title": "HTML: Emmet Completions"}, "astro.css.documentColors.enabled": {"description": "Enable color picker for CSS", "type": "boolean", "default": true, "title": "CSS: Document Colors"}, "astro.format.newLineAfterFrontmatter": {"deprecationMessage": "The `astro.format` settings are deprecated. Formatting is now powered by Prettier and can be configured through a Prettier configuration file.", "description": "Add a line return between the frontmatter and the template", "type": "boolean", "default": true, "title": "Formatting: Add line return after the frontmatter"}, "astro.html.documentSymbols.enabled": {"description": "Enable document symbols for CSS", "type": "boolean", "default": true, "title": "HTML: Symbols in Outline"}, "astro.css.completions.enabled": {"description": "Enable completions for CSS", "type": "boolean", "default": true, "title": "CSS: Completions"}, "astro.language-server.runtime": {"description": "Path to the node executable used to execute the language server. You won't need this in most cases", "scope": "application", "type": "string", "title": "Language Server: Runtime"}, "astro.typescript.documentSymbols.enabled": {"description": "Enable document symbols for TypeScript", "type": "boolean", "default": true, "title": "TypeScript: Symbols in Outline"}}, "description": "Language support for Astro", "$schema": "http://json-schema.org/draft-07/schema#"}
{"properties": {"astro.typescript.rename.enabled": {"description": "Enable rename functionality for JS/TS variables inside Astro files", "type": "boolean", "default": true, "title": "TypeScript: Rename"}, "astro.typescript.semanticTokens.enabled": {"description": "Enable semantic tokens (used for semantic highlighting) for TypeScript.", "type": "boolean", "default": true, "title": "TypeScript: Semantic Tokens"}, "astro.format.indentFrontmatter": {"deprecationMessage": "The `astro.format` settings are deprecated. Formatting is now powered by Prettier and can be configured through a Prettier configuration file.", "description": "Indent the formatter by one level of indentation", "type": "boolean", "default": false, "title": "Formatting: Indent frontmatter"}, "astro.typescript.hover.enabled": {"description": "Enable hover info for TypeScript", "type": "boolean", "default": true, "title": "TypeScript: Hover Info"}, "astro.typescript.documentSymbols.enabled": {"description": "Enable document symbols for TypeScript", "type": "boolean", "default": true, "title": "TypeScript: Symbols in Outline"}, "astro.html.enabled": {"description": "Enable HTML features", "type": "boolean", "default": true, "title": "HTML"}, "astro.trace.server": {"description": "Traces the communication between VS Code and the language server.", "enum": ["off", "messages", "verbose"], "scope": "window", "type": "string", "default": "off"}, "astro.html.completions.enabled": {"description": "Enable completions for HTML", "type": "boolean", "default": true, "title": "HTML: Completions"}, "astro.css.enabled": {"description": "Enable CSS features", "type": "boolean", "default": true, "title": "CSS"}, "astro.typescript.signatureHelp.enabled": {"description": "Enable signature help (parameter hints) for TypeScript", "type": "boolean", "default": true, "title": "TypeScript: Signature Help"}, "astro.css.completions.emmet": {"description": "Enable Emmet completions for CSS", "type": "boolean", "default": true, "title": "CSS: Emmet Completions"}, "astro.css.documentSymbols.enabled": {"description": "Enable document symbols for CSS", "type": "boolean", "default": true, "title": "CSS: Symbols in Outline"}, "astro.css.hover.enabled": {"description": "Enable hover info for CSS", "type": "boolean", "default": true, "title": "CSS: Hover Info"}, "astro.typescript.codeActions.enabled": {"description": "Enable code actions for TypeScript", "type": "boolean", "default": true, "title": "TypeScript: Code Actions"}, "astro.typescript.enabled": {"description": "Enable TypeScript features", "type": "boolean", "default": true, "title": "TypeScript"}, "astro.html.tagComplete.enabled": {"description": "Enable tag completion for HTML", "type": "boolean", "default": true, "title": "HTML: Tag Completion"}, "astro.typescript.diagnostics.enabled": {"description": "Enable diagnostic messages for TypeScript", "type": "boolean", "default": true, "title": "TypeScript: Diagnostics"}, "astro.typescript.completions.enabled": {"description": "Enable completions for TypeScript", "type": "boolean", "default": true, "title": "TypeScript: Completions"}, "astro.typescript.allowArbitraryAttributes": {"description": "Enable the usage of non-standard HTML attributes, such as the ones added by AlpineJS or petite-vue", "type": "boolean", "default": false, "title": "TypeScript: Allow arbitrary attributes on HTML elements"}, "astro.format.newLineAfterFrontmatter": {"deprecationMessage": "The `astro.format` settings are deprecated. Formatting is now powered by Prettier and can be configured through a Prettier configuration file.", "description": "Add a line return between the frontmatter and the template", "type": "boolean", "default": true, "title": "Formatting: Add line return after the frontmatter"}, "astro.html.completions.emmet": {"description": "Enable Emmet completions for HTML", "type": "boolean", "default": true, "title": "HTML: Emmet Completions"}, "astro.language-server.ls-path": {"description": "Path to the language server executable. You won't need this in most cases, set this only when needing a specific version of the language server", "scope": "application", "type": "string", "title": "Language Server: Path"}, "astro.css.documentColors.enabled": {"description": "Enable color picker for CSS", "type": "boolean", "default": true, "title": "CSS: Document Colors"}, "astro.typescript.definitions.enabled": {"description": "Enable go to definition for TypeScript", "type": "boolean", "default": true, "title": "TypeScript: Go to Definition"}, "astro.html.documentSymbols.enabled": {"description": "Enable document symbols for CSS", "type": "boolean", "default": true, "title": "HTML: Symbols in Outline"}, "astro.css.completions.enabled": {"description": "Enable completions for CSS", "type": "boolean", "default": true, "title": "CSS: Completions"}, "astro.language-server.runtime": {"description": "Path to the node executable used to execute the language server. You won't need this in most cases", "scope": "application", "type": "string", "title": "Language Server: Runtime"}, "astro.html.hover.enabled": {"description": "Enable hover info for HTML", "type": "boolean", "default": true, "title": "HTML: Hover Info"}}, "description": "Language support for Astro", "$schema": "http://json-schema.org/draft-07/schema#"}
Loading

0 comments on commit 045585e

Please sign in to comment.