From 336cf3083232e824c8990834b56c6a1068b5a631 Mon Sep 17 00:00:00 2001 From: Michiel van den Heuvel Date: Sat, 24 Jun 2023 19:46:03 +0200 Subject: Make formatting options sort of configurable This should be wired up to code that's in a pull request in the vis repository for the default options. This PR does not yet expose `expandtab`. Referenced PR: https://github.com/martanne/vis/pull/717 --- README.md | 2 ++ init.lua | 7 ++++++- supported-servers.lua | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b9d6cae..ffd98d6 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,7 @@ Additional fields are: * `settings` - a table of arbitrary possibly nested data. It is sent in a `workspace/didChangeConfiguration` to the language server after initialization. It is also used to lookup configuration for the `workspace/configuratio` method call. * `init_options` - table of arbitrary possibly nested data. It is send to the server as `initializationOptions` in the parameters of the `initialize` method call. +* `formatting_options` - table of configuration data as found in [the LSP specification](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_formatting). `tabSize` and `insertSpaces` are required. **Example:** The language server configuration entry in the `ls_map` for lua-language-server @@ -163,6 +164,7 @@ ls_map.lua = { settings = { Lua = {diagnostics = {globals = {'vis'}}, telemetry = {enable = false}}, }, + formatting_options = {tabSize = 2, insertSpaces = true}, }, ``` diff --git a/init.lua b/init.lua index 48f7b97..843bfdc 100644 --- a/init.lua +++ b/init.lua @@ -1109,6 +1109,7 @@ local function ls_start_server(syntax) local ls = { name = ls_conf.name, settings = ls_conf.settings, + formatting_options = ls_conf.formatting_options, initialized = false, id = 0, inflight = {}, @@ -1345,8 +1346,12 @@ vis:command_register('lspc-format', function(_, _, win) local params = { textDocument = {uri = path_to_uri(win.file.path)}, - options = {tabSize = 2, insertSpaces = true}, + options = ls.formatting_options, } + if params.options == nil then + -- probably a safe default, but this should be hooked up to the vis options + params.options = {tabSize = 4, insertSpaces = true} + end ls_call_text_document_method(ls, 'formatting', params, win) end) diff --git a/supported-servers.lua b/supported-servers.lua index 62583b9..eaaa855 100644 --- a/supported-servers.lua +++ b/supported-servers.lua @@ -40,6 +40,7 @@ return { settings = { Lua = {diagnostics = {globals = {'vis'}}, telemetry = {enable = false}}, }, + formatting_options = {tabSize = 2, insertSpaces = true}, }, -- typescript (typescript-language-server) language server configuration -- https://github.com/typescript-language-server/typescript-language-server -- cgit v1.2.3