From a7233c94e095959683b003499d27759e620af5ae Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Mon, 17 Oct 2022 17:08:05 +0200 Subject: [PATCH 01/11] feat: export workspace markers --- .../server_configurations/clangd.lua | 19 ++++--------------- .../server_configurations/sumneko_lua.lua | 18 +++++------------- .../server_configurations/tsserver.lua | 10 +++------- lua/lspconfig/util.lua | 2 +- 4 files changed, 13 insertions(+), 36 deletions(-) diff --git a/lua/lspconfig/server_configurations/clangd.lua b/lua/lspconfig/server_configurations/clangd.lua index 732f556c19..39bdbcbd59 100644 --- a/lua/lspconfig/server_configurations/clangd.lua +++ b/lua/lspconfig/server_configurations/clangd.lua @@ -21,12 +21,13 @@ local function switch_source_header(bufnr) end end -local root_files = { +local workspace_markers = { '.clangd', '.clang-tidy', '.clang-format', 'compile_commands.json', 'compile_flags.txt', + '.git', 'configure.ac', -- AutoTools } @@ -43,9 +44,7 @@ return { default_config = { cmd = { 'clangd' }, filetypes = { 'c', 'cpp', 'objc', 'objcpp', 'cuda', 'proto' }, - root_dir = function(fname) - return util.root_pattern(unpack(root_files))(fname) or util.find_git_ancestor(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, capabilities = default_capabilities, }, @@ -71,17 +70,7 @@ https://clangd.llvm.org/installation.html specified as compile_commands.json, see https://clangd.llvm.org/installation#compile_commandsjson ]], default_config = { - root_dir = [[ - root_pattern( - '.clangd', - '.clang-tidy', - '.clang-format', - 'compile_commands.json', - 'compile_flags.txt', - 'configure.ac', - '.git' - ) - ]], + workspace_markers = workspace_markers, capabilities = [[default capabilities, with offsetEncoding utf-8]], }, }, diff --git a/lua/lspconfig/server_configurations/sumneko_lua.lua b/lua/lspconfig/server_configurations/sumneko_lua.lua index 0f89bbd630..6e6aab73fd 100644 --- a/lua/lspconfig/server_configurations/sumneko_lua.lua +++ b/lua/lspconfig/server_configurations/sumneko_lua.lua @@ -1,6 +1,6 @@ local util = require 'lspconfig.util' -local root_files = { +local workspace_markers = { '.luarc.json', '.luarc.jsonc', '.luacheckrc', @@ -8,6 +8,8 @@ local root_files = { 'stylua.toml', 'selene.toml', 'selene.yml', + 'lua/', + '.git', } local bin_name = 'lua-language-server' @@ -21,17 +23,7 @@ return { default_config = { cmd = cmd, filetypes = { 'lua' }, - root_dir = function(fname) - local root = util.root_pattern(unpack(root_files))(fname) - if root and root ~= vim.env.HOME then - return root - end - root = util.root_pattern 'lua/'(fname) - if root then - return root .. '/lua/' - end - return util.find_git_ancestor(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, log_level = vim.lsp.protocol.MessageType.Warning, settings = { Lua = { telemetry = { enable = false } } }, @@ -85,7 +77,7 @@ See `lua-language-server`'s [documentation](https://github.com/sumneko/lua-langu ]], default_config = { - root_dir = [[root_pattern(".luarc.json", ".luarc.jsonc", ".luacheckrc", ".stylua.toml", "stylua.toml", "selene.toml", "selene.yml", ".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/tsserver.lua b/lua/lspconfig/server_configurations/tsserver.lua index efbb544b6d..4bbda43ea0 100644 --- a/lua/lspconfig/server_configurations/tsserver.lua +++ b/lua/lspconfig/server_configurations/tsserver.lua @@ -1,3 +1,4 @@ +local workspace_markers = { 'tsconfig.json', 'package.json', 'jsconfig.json', '.git' } local util = require 'lspconfig.util' local bin_name = 'typescript-language-server' @@ -19,10 +20,7 @@ return { 'typescriptreact', 'typescript.tsx', }, - root_dir = function(fname) - return util.root_pattern 'tsconfig.json'(fname) - or util.root_pattern('package.json', 'jsconfig.json', '.git')(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -53,8 +51,6 @@ Here's an example that disables type checking in JavaScript files. } ``` ]], - default_config = { - root_dir = [[root_pattern("package.json", "tsconfig.json", "jsconfig.json", ".git")]], - }, + workspace_markers = workspace_markers, }, } diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua index 119c1caf16..578dcfc4bf 100644 --- a/lua/lspconfig/util.lua +++ b/lua/lspconfig/util.lua @@ -340,7 +340,7 @@ function M.root_pattern(...) local function matcher(path) for _, pattern in ipairs(patterns) do for _, p in ipairs(vim.fn.glob(M.path.join(M.path.escape_wildcards(path), pattern), true, true)) do - if M.path.exists(p) then + if M.path.exists(p) and p ~= vim.env.HOME then return path end end From 650c5b7c3760076967d4ad46d78f1273cefa99d0 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Wed, 9 Nov 2022 18:27:39 +0100 Subject: [PATCH 02/11] refactor: export ws markers - 1 --- lua/lspconfig/server_configurations/als.lua | 6 ++++-- lua/lspconfig/server_configurations/ansiblels.lua | 4 +++- lua/lspconfig/server_configurations/astro.lua | 6 ++++-- lua/lspconfig/server_configurations/clojure_lsp.lua | 6 ++++-- lua/lspconfig/server_configurations/csharp_ls.lua | 4 +++- lua/lspconfig/server_configurations/cssls.lua | 6 ++++-- lua/lspconfig/server_configurations/denols.lua | 7 +++++-- lua/lspconfig/server_configurations/ember.lua | 6 ++++-- lua/lspconfig/server_configurations/erlangls.lua | 6 ++++-- lua/lspconfig/server_configurations/fsautocomplete.lua | 4 +++- .../server_configurations/fsharp_language_server.lua | 4 +++- lua/lspconfig/server_configurations/gdscript.lua | 6 ++++-- lua/lspconfig/server_configurations/ghcide.lua | 6 ++++-- lua/lspconfig/server_configurations/graphql.lua | 6 ++++-- lua/lspconfig/server_configurations/hie.lua | 6 ++++-- lua/lspconfig/server_configurations/html.lua | 4 +++- .../server_configurations/java_language_server.lua | 4 +++- lua/lspconfig/server_configurations/m68k.lua | 4 +++- lua/lspconfig/server_configurations/metals.lua | 6 ++++-- lua/lspconfig/server_configurations/nil_ls.lua | 7 +++++-- lua/lspconfig/server_configurations/nxls.lua | 6 ++++-- lua/lspconfig/server_configurations/ocamlls.lua | 6 ++++-- lua/lspconfig/server_configurations/ocamllsp.lua | 6 ++++-- lua/lspconfig/server_configurations/ols.lua | 6 ++++-- lua/lspconfig/server_configurations/pasls.lua | 4 +++- lua/lspconfig/server_configurations/prismals.lua | 7 +++++-- lua/lspconfig/server_configurations/psalm.lua | 6 ++++-- lua/lspconfig/server_configurations/purescriptls.lua | 6 ++++-- lua/lspconfig/server_configurations/quick_lint_js.lua | 4 +++- lua/lspconfig/server_configurations/reason_ls.lua | 4 +++- lua/lspconfig/server_configurations/relay_lsp.lua | 7 +++++-- lua/lspconfig/server_configurations/rescriptls.lua | 4 +++- lua/lspconfig/server_configurations/ruby_ls.lua | 6 ++++-- lua/lspconfig/server_configurations/serve_d.lua | 6 ++++-- lua/lspconfig/server_configurations/solargraph.lua | 6 ++++-- lua/lspconfig/server_configurations/solc.lua | 6 ++++-- lua/lspconfig/server_configurations/solidity.lua | 6 ++++-- lua/lspconfig/server_configurations/solidity_ls.lua | 6 ++++-- lua/lspconfig/server_configurations/sorbet.lua | 6 ++++-- lua/lspconfig/server_configurations/sourcekit.lua | 6 ++++-- lua/lspconfig/server_configurations/spectral.lua | 4 +++- lua/lspconfig/server_configurations/steep.lua | 6 ++++-- lua/lspconfig/server_configurations/stylelint_lsp.lua | 7 +++++-- lua/lspconfig/server_configurations/svelte.lua | 6 ++++-- lua/lspconfig/server_configurations/teal_ls.lua | 7 +++++-- lua/lspconfig/server_configurations/terraform_lsp.lua | 6 ++++-- lua/lspconfig/server_configurations/terraformls.lua | 6 ++++-- lua/lspconfig/server_configurations/tflint.lua | 6 ++++-- lua/lspconfig/server_configurations/typeprof.lua | 6 ++++-- lua/lspconfig/server_configurations/vls.lua | 6 ++++-- lua/lspconfig/server_configurations/vuels.lua | 6 ++++-- lua/lspconfig/server_configurations/zls.lua | 6 ++++-- 52 files changed, 202 insertions(+), 92 deletions(-) diff --git a/lua/lspconfig/server_configurations/als.lua b/lua/lspconfig/server_configurations/als.lua index 7d916adf6c..48a5833ba8 100644 --- a/lua/lspconfig/server_configurations/als.lua +++ b/lua/lspconfig/server_configurations/als.lua @@ -5,11 +5,13 @@ if vim.fn.has 'win32' == 1 then bin_name = 'ada_language_server.exe' end +local workspace_markers = { 'Makefile', '.git', '*.gpr', '*.adc' } + return { default_config = { cmd = { bin_name }, filetypes = { 'ada' }, - root_dir = util.root_pattern('Makefile', '.git', '*.gpr', '*.adc'), + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -31,7 +33,7 @@ require('lspconfig').als.setup{ ``` ]], default_config = { - root_dir = [[util.root_pattern("Makefile", ".git", "*.gpr", "*.adc")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/ansiblels.lua b/lua/lspconfig/server_configurations/ansiblels.lua index b4bb32422c..7fcf457120 100644 --- a/lua/lspconfig/server_configurations/ansiblels.lua +++ b/lua/lspconfig/server_configurations/ansiblels.lua @@ -7,6 +7,8 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, '--stdio' } end +local workspace_markers = { 'ansible.cfg', '.ansible-lint' } + return { default_config = { cmd = cmd, @@ -28,7 +30,7 @@ return { }, }, filetypes = { 'yaml.ansible' }, - root_dir = util.root_pattern('ansible.cfg', '.ansible-lint'), + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { diff --git a/lua/lspconfig/server_configurations/astro.lua b/lua/lspconfig/server_configurations/astro.lua index b643e16dc6..cc0f92e25f 100644 --- a/lua/lspconfig/server_configurations/astro.lua +++ b/lua/lspconfig/server_configurations/astro.lua @@ -13,11 +13,13 @@ local function get_typescript_server_path(root_dir) or '' end +local workspace_markers = { 'package.json', 'tsconfig.json', 'jsconfig.json', '.git' } + return { default_config = { cmd = cmd, filetypes = { 'astro' }, - root_dir = util.root_pattern('package.json', 'tsconfig.json', 'jsconfig.json', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), init_options = { typescript = { serverPath = '', @@ -44,7 +46,7 @@ npm install -g @astrojs/language-server ``` ]], default_config = { - root_dir = [[root_pattern("package.json", "tsconfig.json", "jsconfig.json", ".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/clojure_lsp.lua b/lua/lspconfig/server_configurations/clojure_lsp.lua index 8bef32df44..3d109d062e 100644 --- a/lua/lspconfig/server_configurations/clojure_lsp.lua +++ b/lua/lspconfig/server_configurations/clojure_lsp.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'project.clj', 'deps.edn', 'build.boot', 'shadow-cljs.edn', '.git' } + return { default_config = { cmd = { 'clojure-lsp' }, filetypes = { 'clojure', 'edn' }, - root_dir = util.root_pattern('project.clj', 'deps.edn', 'build.boot', 'shadow-cljs.edn', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -13,7 +15,7 @@ https://github.com/clojure-lsp/clojure-lsp Clojure Language Server ]], default_config = { - root_dir = [[root_pattern("project.clj", "deps.edn", "build.boot", "shadow-cljs.edn", ".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/csharp_ls.lua b/lua/lspconfig/server_configurations/csharp_ls.lua index 0952457b44..20bfccdda9 100644 --- a/lua/lspconfig/server_configurations/csharp_ls.lua +++ b/lua/lspconfig/server_configurations/csharp_ls.lua @@ -1,9 +1,11 @@ local util = require 'lspconfig.util' +local workspace_markers = { '*.sln', '*.csproj', '*.fsproj', '.git' } + return { default_config = { cmd = { 'csharp-ls' }, - root_dir = util.root_pattern('*.sln', '*.csproj', '*.fsproj', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), filetypes = { 'cs' }, init_options = { AutomaticWorkspaceInit = true, diff --git a/lua/lspconfig/server_configurations/cssls.lua b/lua/lspconfig/server_configurations/cssls.lua index 41c38e6afe..3ca6482688 100644 --- a/lua/lspconfig/server_configurations/cssls.lua +++ b/lua/lspconfig/server_configurations/cssls.lua @@ -7,11 +7,13 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, '--stdio' } end +local workspace_markers = { 'package.json', '.git' } + return { default_config = { cmd = cmd, filetypes = { 'css', 'scss', 'less' }, - root_dir = util.root_pattern('package.json', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, settings = { css = { validate = true }, @@ -43,7 +45,7 @@ require'lspconfig'.cssls.setup { ``` ]], default_config = { - root_dir = [[root_pattern("package.json", ".git") or bufdir]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/denols.lua b/lua/lspconfig/server_configurations/denols.lua index 1986a3ec65..34cea80abb 100644 --- a/lua/lspconfig/server_configurations/denols.lua +++ b/lua/lspconfig/server_configurations/denols.lua @@ -56,10 +56,13 @@ local function denols_handler(err, result, ctx) lsp.handlers[ctx.method](err, result, ctx) end +local workspace_markers = { 'deno.json', 'deno.jsonc', '.git' } + return { default_config = { cmd = { 'deno', 'lsp' }, filetypes = { + workspace_markers = workspace_markers, 'javascript', 'javascriptreact', 'javascript.jsx', @@ -67,7 +70,7 @@ return { 'typescriptreact', 'typescript.tsx', }, - root_dir = util.root_pattern('deno.json', 'deno.jsonc', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), init_options = { enable = true, unstable = false, @@ -115,7 +118,7 @@ vim.g.markdown_fenced_languages = { ]], default_config = { - root_dir = [[root_pattern("deno.json", "deno.jsonc", ".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/ember.lua b/lua/lspconfig/server_configurations/ember.lua index e6ce1eae76..8b73ddb6c8 100644 --- a/lua/lspconfig/server_configurations/ember.lua +++ b/lua/lspconfig/server_configurations/ember.lua @@ -7,11 +7,13 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, '--stdio' } end +local workspace_markers = { 'ember-cli-build.js', '.git' } + return { default_config = { cmd = cmd, filetypes = { 'handlebars', 'typescript', 'javascript' }, - root_dir = util.root_pattern('ember-cli-build.js', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -24,7 +26,7 @@ npm install -g @lifeart/ember-language-server ``` ]], default_config = { - root_dir = [[root_pattern("ember-cli-build.js", ".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/erlangls.lua b/lua/lspconfig/server_configurations/erlangls.lua index cec192845f..ef8875968e 100644 --- a/lua/lspconfig/server_configurations/erlangls.lua +++ b/lua/lspconfig/server_configurations/erlangls.lua @@ -5,11 +5,13 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', 'erlang_ls.cmd' } end +local workspace_markers = { 'rebar.config', 'erlang.mk', '.git' } + return { default_config = { cmd = cmd, filetypes = { 'erlang' }, - root_dir = util.root_pattern('rebar.config', 'erlang.mk', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { @@ -28,7 +30,7 @@ Installation requirements: - [rebar3 3.9.1+](https://github.com/erlang/rebar3) ]], default_config = { - root_dir = [[root_pattern('rebar.config', 'erlang.mk', '.git')]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/fsautocomplete.lua b/lua/lspconfig/server_configurations/fsautocomplete.lua index 4858c044e6..6927702d50 100644 --- a/lua/lspconfig/server_configurations/fsautocomplete.lua +++ b/lua/lspconfig/server_configurations/fsautocomplete.lua @@ -1,9 +1,11 @@ local util = require 'lspconfig.util' +local workspace_markers = { '*.sln', '*.fsproj', '.git' } + return { default_config = { cmd = { 'fsautocomplete', '--adaptive-lsp-server-enabled' }, - root_dir = util.root_pattern('*.sln', '*.fsproj', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), filetypes = { 'fsharp' }, init_options = { AutomaticWorkspaceInit = true, diff --git a/lua/lspconfig/server_configurations/fsharp_language_server.lua b/lua/lspconfig/server_configurations/fsharp_language_server.lua index 1abc60686b..4d3d81f4ce 100644 --- a/lua/lspconfig/server_configurations/fsharp_language_server.lua +++ b/lua/lspconfig/server_configurations/fsharp_language_server.lua @@ -1,9 +1,11 @@ local util = require 'lspconfig.util' +local workspace_markers = { '*.sln', '*.fsproj', '.git' } + return { default_config = { cmd = { 'dotnet', 'FSharpLanguageServer.dll' }, - root_dir = util.root_pattern('*.sln', '*.fsproj', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), filetypes = { 'fsharp' }, init_options = { AutomaticWorkspaceInit = true, diff --git a/lua/lspconfig/server_configurations/gdscript.lua b/lua/lspconfig/server_configurations/gdscript.lua index 1491212a96..43de882418 100644 --- a/lua/lspconfig/server_configurations/gdscript.lua +++ b/lua/lspconfig/server_configurations/gdscript.lua @@ -6,11 +6,13 @@ if vim.fn.has 'nvim-0.8' == 1 then cmd = vim.lsp.rpc.connect('127.0.0.1', '6008') end +local workspace_markers = { 'project.godot', '.git' } + return { default_config = { cmd = cmd, filetypes = { 'gd', 'gdscript', 'gdscript3' }, - root_dir = util.root_pattern('project.godot', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -19,7 +21,7 @@ https://github.com/godotengine/godot Language server for GDScript, used by Godot Engine. ]], default_config = { - root_dir = [[util.root_pattern("project.godot", ".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/ghcide.lua b/lua/lspconfig/server_configurations/ghcide.lua index 7f9307b1e2..e8df4a4861 100644 --- a/lua/lspconfig/server_configurations/ghcide.lua +++ b/lua/lspconfig/server_configurations/ghcide.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'stack.yaml', 'hie-bios', 'BUILD.bazel', 'cabal.config', 'package.yaml' } + return { default_config = { cmd = { 'ghcide', '--lsp' }, filetypes = { 'haskell', 'lhaskell' }, - root_dir = util.root_pattern('stack.yaml', 'hie-bios', 'BUILD.bazel', 'cabal.config', 'package.yaml'), + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { @@ -15,7 +17,7 @@ A library for building Haskell IDE tooling. "ghcide" isn't for end users now. Use "haskell-language-server" instead of "ghcide". ]], default_config = { - root_dir = [[root_pattern("stack.yaml", "hie-bios", "BUILD.bazel", "cabal.config", "package.yaml")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/graphql.lua b/lua/lspconfig/server_configurations/graphql.lua index 2d586c9eaa..2989f4e9a0 100644 --- a/lua/lspconfig/server_configurations/graphql.lua +++ b/lua/lspconfig/server_configurations/graphql.lua @@ -7,11 +7,13 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, 'server', '-m', 'stream' } end +local workspace_markers = { '.git', '.graphqlrc*', '.graphql.config.*', 'graphql.config.*' } + return { default_config = { cmd = cmd, filetypes = { 'graphql', 'typescriptreact', 'javascriptreact' }, - root_dir = util.root_pattern('.git', '.graphqlrc*', '.graphql.config.*', 'graphql.config.*'), + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { @@ -27,7 +29,7 @@ npm install -g graphql-language-service-cli Note that you must also have [the graphql package](https://github.com/graphql/graphql-js) installed and create a [GraphQL config file](https://www.graphql-config.com/docs/user/user-introduction). ]], default_config = { - root_dir = [[util.root_pattern('.git', '.graphqlrc*', '.graphql.config.*', 'graphql.config.*')]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/hie.lua b/lua/lspconfig/server_configurations/hie.lua index 96148ad1c1..0330ed60cc 100644 --- a/lua/lspconfig/server_configurations/hie.lua +++ b/lua/lspconfig/server_configurations/hie.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'stack.yaml', 'package.yaml', '.git' } + return { default_config = { cmd = { 'hie-wrapper', '--lsp' }, filetypes = { 'haskell' }, - root_dir = util.root_pattern('stack.yaml', 'package.yaml', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { @@ -28,7 +30,7 @@ init_options = { ]], default_config = { - root_dir = [[root_pattern("stack.yaml", "package.yaml", ".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/html.lua b/lua/lspconfig/server_configurations/html.lua index 2f8214f486..4e61089828 100644 --- a/lua/lspconfig/server_configurations/html.lua +++ b/lua/lspconfig/server_configurations/html.lua @@ -7,11 +7,13 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, '--stdio' } end +local workspace_markers = { 'package.json', '.git' } + return { default_config = { cmd = cmd, filetypes = { 'html' }, - root_dir = util.root_pattern('package.json', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, settings = {}, init_options = { diff --git a/lua/lspconfig/server_configurations/java_language_server.lua b/lua/lspconfig/server_configurations/java_language_server.lua index 3ddf4b1b4c..bf5703d61c 100644 --- a/lua/lspconfig/server_configurations/java_language_server.lua +++ b/lua/lspconfig/server_configurations/java_language_server.lua @@ -1,9 +1,11 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'build.gradle', 'pom.xml', '.git' } + return { default_config = { filetypes = { 'java' }, - root_dir = util.root_pattern('build.gradle', 'pom.xml', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), settings = {}, }, docs = { diff --git a/lua/lspconfig/server_configurations/m68k.lua b/lua/lspconfig/server_configurations/m68k.lua index 9e96d84754..28bcba69a2 100644 --- a/lua/lspconfig/server_configurations/m68k.lua +++ b/lua/lspconfig/server_configurations/m68k.lua @@ -7,11 +7,13 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, '--stdio' } end +local workspace_markers = { 'Makefile', '.git' } + return { default_config = { cmd = cmd, filetypes = { 'asm68k' }, - root_dir = util.root_pattern('Makefile', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { diff --git a/lua/lspconfig/server_configurations/metals.lua b/lua/lspconfig/server_configurations/metals.lua index 1242f51b7a..ec971a0458 100644 --- a/lua/lspconfig/server_configurations/metals.lua +++ b/lua/lspconfig/server_configurations/metals.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'build.sbt', 'build.sc', 'build.gradle', 'pom.xml' } + return { default_config = { cmd = { 'metals' }, filetypes = { 'scala' }, - root_dir = util.root_pattern('build.sbt', 'build.sc', 'build.gradle', 'pom.xml'), + root_dir = util.root_pattern(unpack(workspace_markers)), message_level = vim.lsp.protocol.MessageType.Log, init_options = { statusBarProvider = 'show-message', @@ -34,7 +36,7 @@ Note: that if you're using [nvim-metals](https://github.com/scalameta/nvim-metal To install Metals, make sure to have [coursier](https://get-coursier.io/docs/cli-installation) installed, and once you do you can install the latest Metals with `cs install metals`. ]], default_config = { - root_dir = [[util.root_pattern("build.sbt", "build.sc", "build.gradle", "pom.xml")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/nil_ls.lua b/lua/lspconfig/server_configurations/nil_ls.lua index ff7ebba208..eb3f2d8505 100644 --- a/lua/lspconfig/server_configurations/nil_ls.lua +++ b/lua/lspconfig/server_configurations/nil_ls.lua @@ -1,11 +1,14 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'flake.nix', '.git' } + return { default_config = { cmd = { 'nil' }, filetypes = { 'nix' }, + workspace_markers = workspace_markers, single_file_support = true, - root_dir = util.root_pattern('flake.nix', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -17,7 +20,7 @@ If you are using Nix with Flakes support, run `nix profile install github:oxalic Check the repository README for more information. ]], default_config = { - root_dir = [[root_pattern("flake.nix", ".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/nxls.lua b/lua/lspconfig/server_configurations/nxls.lua index 7c4517edd9..336c5a4497 100644 --- a/lua/lspconfig/server_configurations/nxls.lua +++ b/lua/lspconfig/server_configurations/nxls.lua @@ -7,11 +7,13 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, '--stdio' } end +local workspace_markers = { 'nx.json', '.git' } + return { default_config = { cmd = cmd, filetypes = { 'json', 'jsonc' }, - root_dir = util.root_pattern('nx.json', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -25,7 +27,7 @@ npm i -g nxls ``` ]], default_config = { - root_dir = [[util.root_pattern]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/ocamlls.lua b/lua/lspconfig/server_configurations/ocamlls.lua index fcc25dbc51..6832761959 100644 --- a/lua/lspconfig/server_configurations/ocamlls.lua +++ b/lua/lspconfig/server_configurations/ocamlls.lua @@ -6,11 +6,13 @@ local cmd = { bin_name, '--stdio' } if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, '--stdio' } end +local workspace_markers = { '*.opam', 'esy.json', 'package.json' } + return { default_config = { cmd = cmd, filetypes = { 'ocaml', 'reason' }, - root_dir = util.root_pattern('*.opam', 'esy.json', 'package.json'), + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -22,7 +24,7 @@ npm install -g ocaml-language-server ``` ]], default_config = { - root_dir = [[root_pattern("*.opam", "esy.json", "package.json")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/ocamllsp.lua b/lua/lspconfig/server_configurations/ocamllsp.lua index 71db1f5b73..749c68787e 100644 --- a/lua/lspconfig/server_configurations/ocamllsp.lua +++ b/lua/lspconfig/server_configurations/ocamllsp.lua @@ -13,11 +13,13 @@ local get_language_id = function(_, ftype) return language_id_of[ftype] end +local workspace_markers = { '*.opam', 'esy.json', 'package.json', '.git', 'dune-project', 'dune-workspace' } + return { default_config = { cmd = { 'ocamllsp' }, filetypes = { 'ocaml', 'ocaml.menhir', 'ocaml.interface', 'ocaml.ocamllex', 'reason', 'dune' }, - root_dir = util.root_pattern('*.opam', 'esy.json', 'package.json', '.git', 'dune-project', 'dune-workspace'), + root_dir = util.root_pattern(unpack(workspace_markers)), get_language_id = get_language_id, }, docs = { @@ -32,7 +34,7 @@ opam install ocaml-lsp-server ``` ]], default_config = { - root_dir = [[root_pattern("*.opam", "esy.json", "package.json", ".git", "dune-project", "dune-workspace")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/ols.lua b/lua/lspconfig/server_configurations/ols.lua index 65dd085c7e..d01ccdc9bb 100644 --- a/lua/lspconfig/server_configurations/ols.lua +++ b/lua/lspconfig/server_configurations/ols.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'ols.json', '.git' } + return { default_config = { cmd = { 'ols' }, filetypes = { 'odin' }, - root_dir = util.root_pattern('ols.json', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { @@ -14,7 +16,7 @@ return { `Odin Language Server`. ]], default_config = { - root_dir = [[util.root_pattern("ols.json", ".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/pasls.lua b/lua/lspconfig/server_configurations/pasls.lua index 19ef8486f1..04019366b6 100644 --- a/lua/lspconfig/server_configurations/pasls.lua +++ b/lua/lspconfig/server_configurations/pasls.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '*.lpi', '*.lpk', '.git' } + return { default_config = { cmd = { 'pasls' }, filetypes = { 'pascal' }, - root_dir = util.root_pattern('*.lpi', '*.lpk', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { diff --git a/lua/lspconfig/server_configurations/prismals.lua b/lua/lspconfig/server_configurations/prismals.lua index f330e25390..74d5e5684d 100644 --- a/lua/lspconfig/server_configurations/prismals.lua +++ b/lua/lspconfig/server_configurations/prismals.lua @@ -7,16 +7,19 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, '--stdio' } end +local workspace_markers = { '.git', 'package.json' } + return { default_config = { cmd = cmd, filetypes = { 'prisma' }, + workspace_markers = workspace_markers, settings = { prisma = { prismaFmtBinPath = '', }, }, - root_dir = util.root_pattern('.git', 'package.json'), + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -28,7 +31,7 @@ npm install -g @prisma/language-server ``` ]], default_config = { - root_dir = [[root_pattern(".git", "package.json")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/psalm.lua b/lua/lspconfig/server_configurations/psalm.lua index 01f7581924..ad98d4a511 100644 --- a/lua/lspconfig/server_configurations/psalm.lua +++ b/lua/lspconfig/server_configurations/psalm.lua @@ -6,11 +6,13 @@ if vim.fn.has 'win32' == 1 then bin_name = bin_name .. '.bat' end +local workspace_markers = { 'psalm.xml', 'psalm.xml.dist' } + return { default_config = { cmd = { bin_name }, filetypes = { 'php' }, - root_dir = util.root_pattern('psalm.xml', 'psalm.xml.dist'), + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -23,7 +25,7 @@ composer global require vimeo/psalm ]], default_config = { cmd = { 'psalm-language-server' }, - root_dir = [[root_pattern("psalm.xml", "psalm.xml.dist")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/purescriptls.lua b/lua/lspconfig/server_configurations/purescriptls.lua index 7010d57dfe..aaf0461f18 100644 --- a/lua/lspconfig/server_configurations/purescriptls.lua +++ b/lua/lspconfig/server_configurations/purescriptls.lua @@ -7,11 +7,13 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, '--stdio' } end +local workspace_markers = { 'bower.json', 'psc-package.json', 'spago.dhall', 'flake.nix', 'shell.nix' } + return { default_config = { cmd = cmd, filetypes = { 'purescript' }, - root_dir = util.root_pattern('bower.json', 'psc-package.json', 'spago.dhall', 'flake.nix', 'shell.nix'), + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -23,7 +25,7 @@ The `purescript-language-server` can be added to your project and `$PATH` via * Nix under the `nodePackages` and `nodePackages_latest` package sets ]], default_config = { - root_dir = [[root_pattern('spago.dhall', 'psc-package.json', 'bower.json', 'flake.nix', 'shell.nix'),]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/quick_lint_js.lua b/lua/lspconfig/server_configurations/quick_lint_js.lua index 29daa966ed..807506b017 100644 --- a/lua/lspconfig/server_configurations/quick_lint_js.lua +++ b/lua/lspconfig/server_configurations/quick_lint_js.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'package.json', 'jsconfig.json', '.git' } + return { default_config = { cmd = { 'quick-lint-js', '--lsp-server' }, filetypes = { 'javascript' }, - root_dir = util.root_pattern('package.json', 'jsconfig.json', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { diff --git a/lua/lspconfig/server_configurations/reason_ls.lua b/lua/lspconfig/server_configurations/reason_ls.lua index 75028c7c81..b9573ad699 100644 --- a/lua/lspconfig/server_configurations/reason_ls.lua +++ b/lua/lspconfig/server_configurations/reason_ls.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'bsconfig.json', '.git' } + return { default_config = { cmd = { 'reason-language-server' }, filetypes = { 'reason' }, - root_dir = util.root_pattern('bsconfig.json', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ diff --git a/lua/lspconfig/server_configurations/relay_lsp.lua b/lua/lspconfig/server_configurations/relay_lsp.lua index 7b84929324..e8b7b025a2 100644 --- a/lua/lspconfig/server_configurations/relay_lsp.lua +++ b/lua/lspconfig/server_configurations/relay_lsp.lua @@ -8,6 +8,8 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, 'lsp' } end +local workspace_markers = { 'relay.config.*', 'package.json' } + return { default_config = { -- (default: false) Whether or not we should automatically start the @@ -21,6 +23,7 @@ return { cmd = cmd, filetypes = { + workspace_markers = workspace_markers, 'javascript', 'javascriptreact', 'javascript.jsx', @@ -28,7 +31,7 @@ return { 'typescriptreact', 'typescript.tsx', }, - root_dir = util.root_pattern('relay.config.*', 'package.json'), + root_dir = util.root_pattern(unpack(workspace_markers)), on_new_config = function(config, root_dir) local project_root = util.find_node_modules_ancestor(root_dir) local node_bin_path = util.path.join(project_root, 'node_modules', '.bin') @@ -109,7 +112,7 @@ return { ``` ]], default_config = { - root_dir = [[root_pattern("relay.config.*", "package.json")]], + workspace_markers = workspace_markers, auto_start_compiler = false, path_to_config = nil, }, diff --git a/lua/lspconfig/server_configurations/rescriptls.lua b/lua/lspconfig/server_configurations/rescriptls.lua index 1c80ada14d..ae4dc59084 100644 --- a/lua/lspconfig/server_configurations/rescriptls.lua +++ b/lua/lspconfig/server_configurations/rescriptls.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'bsconfig.json', '.git' } + return { default_config = { cmd = {}, filetypes = { 'rescript' }, - root_dir = util.root_pattern('bsconfig.json', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), settings = {}, }, docs = { diff --git a/lua/lspconfig/server_configurations/ruby_ls.lua b/lua/lspconfig/server_configurations/ruby_ls.lua index ef4902564c..f3f04be454 100644 --- a/lua/lspconfig/server_configurations/ruby_ls.lua +++ b/lua/lspconfig/server_configurations/ruby_ls.lua @@ -9,11 +9,13 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name } end +local workspace_markers = { 'Gemfile', '.git' } + return { default_config = { cmd = cmd, filetypes = { 'ruby' }, - root_dir = util.root_pattern('Gemfile', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), init_options = { enabledFeatures = { 'codeActions', @@ -42,7 +44,7 @@ end ``` ]], default_config = { - root_dir = [[root_pattern("Gemfile", ".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/serve_d.lua b/lua/lspconfig/server_configurations/serve_d.lua index 09d1b108c3..f45a1c4a55 100644 --- a/lua/lspconfig/server_configurations/serve_d.lua +++ b/lua/lspconfig/server_configurations/serve_d.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'dub.json', 'dub.sdl', '.git' } + return { default_config = { cmd = { 'serve-d' }, filetypes = { 'd' }, - root_dir = util.root_pattern('dub.json', 'dub.sdl', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -14,7 +16,7 @@ return { Download a binary from https://github.com/Pure-D/serve-d/releases and put it in your $PATH. ]], default_config = { - root_dir = [[util.root_pattern("dub.json", "dub.sdl", ".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/solargraph.lua b/lua/lspconfig/server_configurations/solargraph.lua index 4fba4009c3..361a69884e 100644 --- a/lua/lspconfig/server_configurations/solargraph.lua +++ b/lua/lspconfig/server_configurations/solargraph.lua @@ -7,6 +7,8 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, 'stdio' } end +local workspace_markers = { 'Gemfile', '.git' } + return { default_config = { cmd = cmd, @@ -17,7 +19,7 @@ return { }, init_options = { formatting = true }, filetypes = { 'ruby' }, - root_dir = util.root_pattern('Gemfile', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -32,7 +34,7 @@ gem install --user-install solargraph ``` ]], default_config = { - root_dir = [[root_pattern("Gemfile", ".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/solc.lua b/lua/lspconfig/server_configurations/solc.lua index 9ae3948d28..956d622480 100644 --- a/lua/lspconfig/server_configurations/solc.lua +++ b/lua/lspconfig/server_configurations/solc.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'hardhat.config.*', '.git' } + return { default_config = { cmd = { 'solc', '--lsp' }, filetypes = { 'solidity' }, - root_dir = util.root_pattern('hardhat.config.*', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -13,7 +15,7 @@ https://docs.soliditylang.org/en/latest/installing-solidity.html solc is the native language server for the Solidity language. ]], default_config = { - root_dir = [[root_pattern('hardhat.config.*', '.git')]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/solidity.lua b/lua/lspconfig/server_configurations/solidity.lua index 4e254bd942..59ef213dbf 100644 --- a/lua/lspconfig/server_configurations/solidity.lua +++ b/lua/lspconfig/server_configurations/solidity.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git', 'package.json' } + return { default_config = { cmd = { 'solidity-ls', '--stdio' }, filetypes = { 'solidity' }, - root_dir = util.root_pattern('.git', 'package.json'), + root_dir = util.root_pattern(unpack(workspace_markers)), settings = { solidity = { includePath = '', remapping = {} } }, }, docs = { @@ -43,7 +45,7 @@ After installing with package.json, just create a `remappings.txt` with: You can omit the node_modules as well. ]], default_config = { - root_dir = [[root_pattern("package.json", ".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/solidity_ls.lua b/lua/lspconfig/server_configurations/solidity_ls.lua index 4d4c4902d5..9ca37752ca 100644 --- a/lua/lspconfig/server_configurations/solidity_ls.lua +++ b/lua/lspconfig/server_configurations/solidity_ls.lua @@ -5,11 +5,13 @@ if vim.fn.has 'win32' == 1 then bin_name = bin_name .. '.cmd' end +local workspace_markers = { '.git', 'package.json' } + return { default_config = { cmd = { bin_name, '--stdio' }, filetypes = { 'solidity' }, - root_dir = util.root_pattern('.git', 'package.json'), + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -18,7 +20,7 @@ npm install -g solidity-language-server solidity-language-server is a language server for the solidity language ported from the vscode solidity extension ]], default_config = { - root_dir = [[root_pattern(".git", "package.json")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/sorbet.lua b/lua/lspconfig/server_configurations/sorbet.lua index 86d3443607..91d86c7489 100644 --- a/lua/lspconfig/server_configurations/sorbet.lua +++ b/lua/lspconfig/server_configurations/sorbet.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'Gemfile', '.git' } + return { default_config = { cmd = { 'srb', 'tc', '--lsp' }, filetypes = { 'ruby' }, - root_dir = util.root_pattern('Gemfile', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -20,7 +22,7 @@ gem install sorbet ``` ]], default_config = { - root_dir = [[root_pattern("Gemfile", ".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/sourcekit.lua b/lua/lspconfig/server_configurations/sourcekit.lua index d90b30aeb8..815463e638 100644 --- a/lua/lspconfig/server_configurations/sourcekit.lua +++ b/lua/lspconfig/server_configurations/sourcekit.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'Package.swift', '.git' } + return { default_config = { cmd = { 'sourcekit-lsp' }, filetypes = { 'swift', 'c', 'cpp', 'objective-c', 'objective-cpp' }, - root_dir = util.root_pattern('Package.swift', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -13,7 +15,7 @@ https://github.com/apple/sourcekit-lsp Language server for Swift and C/C++/Objective-C. ]], default_config = { - root_dir = [[root_pattern("Package.swift", ".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/spectral.lua b/lua/lspconfig/server_configurations/spectral.lua index e21b6cb5b1..834bdf3851 100644 --- a/lua/lspconfig/server_configurations/spectral.lua +++ b/lua/lspconfig/server_configurations/spectral.lua @@ -2,11 +2,13 @@ local util = require 'lspconfig.util' local bin_name = 'spectral-language-server' +local workspace_markers = { '.spectral.yaml', '.spectral.yml', '.spectral.json', '.spectral.js' } + return { default_config = { cmd = { bin_name, '--stdio' }, filetypes = { 'yaml', 'json', 'yml' }, - root_dir = util.root_pattern('.spectral.yaml', '.spectral.yml', '.spectral.json', '.spectral.js'), + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, settings = { enable = true, diff --git a/lua/lspconfig/server_configurations/steep.lua b/lua/lspconfig/server_configurations/steep.lua index 367c780098..7a8e9959af 100644 --- a/lua/lspconfig/server_configurations/steep.lua +++ b/lua/lspconfig/server_configurations/steep.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'Steepfile', '.git' } + return { default_config = { cmd = { 'steep', 'langserver' }, filetypes = { 'ruby', 'eruby' }, - root_dir = util.root_pattern('Steepfile', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -15,7 +17,7 @@ https://github.com/soutaro/steep You need `Steepfile` to make it work. Generate it with `steep init`. ]], default_config = { - root_dir = [[root_pattern("Steepfile", ".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/stylelint_lsp.lua b/lua/lspconfig/server_configurations/stylelint_lsp.lua index d471d2673a..ef56d5ba79 100644 --- a/lua/lspconfig/server_configurations/stylelint_lsp.lua +++ b/lua/lspconfig/server_configurations/stylelint_lsp.lua @@ -7,10 +7,13 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, '--stdio' } end +local workspace_markers = { '.stylelintrc', 'package.json' } + return { default_config = { cmd = cmd, filetypes = { + workspace_markers = workspace_markers, 'css', 'less', 'scss', @@ -22,7 +25,7 @@ return { 'typescript', 'typescriptreact', }, - root_dir = util.root_pattern('.stylelintrc', 'package.json'), + root_dir = util.root_pattern(unpack(workspace_markers)), settings = {}, }, docs = { @@ -48,7 +51,7 @@ require'lspconfig'.stylelint_lsp.setup{ ``` ]], default_config = { - root_dir = [[ root_pattern('.stylelintrc', 'package.json') ]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/svelte.lua b/lua/lspconfig/server_configurations/svelte.lua index 64ed468f41..b495935454 100644 --- a/lua/lspconfig/server_configurations/svelte.lua +++ b/lua/lspconfig/server_configurations/svelte.lua @@ -7,11 +7,13 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, '--stdio' } end +local workspace_markers = { 'package.json', '.git' } + return { default_config = { cmd = cmd, filetypes = { 'svelte' }, - root_dir = util.root_pattern('package.json', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -25,7 +27,7 @@ npm install -g svelte-language-server ``` ]], default_config = { - root_dir = [[root_pattern("package.json", ".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/teal_ls.lua b/lua/lspconfig/server_configurations/teal_ls.lua index b554addab5..c69c88f53d 100644 --- a/lua/lspconfig/server_configurations/teal_ls.lua +++ b/lua/lspconfig/server_configurations/teal_ls.lua @@ -1,5 +1,7 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'tlconfig.lua', '.git' } + return { default_config = { cmd = { @@ -8,10 +10,11 @@ return { -- "logging=on", }, filetypes = { + workspace_markers = workspace_markers, 'teal', -- "lua", -- Also works for lua, but you may get type errors that cannot be resolved within lua itself }, - root_dir = util.root_pattern('tlconfig.lua', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -23,7 +26,7 @@ luarocks install --dev teal-language-server ``` ]], default_config = { - root_dir = [[root_pattern("tlconfig.lua", ".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/terraform_lsp.lua b/lua/lspconfig/server_configurations/terraform_lsp.lua index 48a6fc5870..9170bf1865 100644 --- a/lua/lspconfig/server_configurations/terraform_lsp.lua +++ b/lua/lspconfig/server_configurations/terraform_lsp.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.terraform', '.git' } + return { default_config = { cmd = { 'terraform-lsp' }, filetypes = { 'terraform', 'hcl' }, - root_dir = util.root_pattern('.terraform', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -37,7 +39,7 @@ choice: - less stability (due to reliance on Terraform's own internal packages) ]], default_config = { - root_dir = [[root_pattern(".terraform", ".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/terraformls.lua b/lua/lspconfig/server_configurations/terraformls.lua index 3eb4a1c8be..aa2257e8f5 100644 --- a/lua/lspconfig/server_configurations/terraformls.lua +++ b/lua/lspconfig/server_configurations/terraformls.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.terraform', '.git' } + return { default_config = { cmd = { 'terraform-ls', 'serve' }, filetypes = { 'terraform' }, - root_dir = util.root_pattern('.terraform', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -36,7 +38,7 @@ choice: - less stability (due to reliance on Terraform's own internal packages) ]], default_config = { - root_dir = [[root_pattern(".terraform", ".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/tflint.lua b/lua/lspconfig/server_configurations/tflint.lua index de2a1d8ce7..45c7945b70 100644 --- a/lua/lspconfig/server_configurations/tflint.lua +++ b/lua/lspconfig/server_configurations/tflint.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.terraform', '.git', '.tflint.hcl' } + return { default_config = { cmd = { 'tflint', '--langserver' }, filetypes = { 'terraform' }, - root_dir = util.root_pattern('.terraform', '.git', '.tflint.hcl'), + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -14,7 +16,7 @@ A pluggable Terraform linter that can act as lsp server. Installation instructions can be found in https://github.com/terraform-linters/tflint#installation. ]], default_config = { - root_dir = [[root_pattern(".terraform", ".git", ".tflint.hcl")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/typeprof.lua b/lua/lspconfig/server_configurations/typeprof.lua index ab9dc8ef9f..f495b6d8b8 100644 --- a/lua/lspconfig/server_configurations/typeprof.lua +++ b/lua/lspconfig/server_configurations/typeprof.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'Gemfile', '.git' } + return { default_config = { cmd = { 'typeprof', '--lsp', '--stdio' }, filetypes = { 'ruby', 'eruby' }, - root_dir = util.root_pattern('Gemfile', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -13,7 +15,7 @@ https://github.com/ruby/typeprof `typeprof` is the built-in analysis and LSP tool for Ruby 3.1+. ]], default_config = { - root_dir = [[root_pattern("Gemfile", ".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/vls.lua b/lua/lspconfig/server_configurations/vls.lua index 9400648cb8..6174bbcad6 100644 --- a/lua/lspconfig/server_configurations/vls.lua +++ b/lua/lspconfig/server_configurations/vls.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'v.mod', '.git' } + return { default_config = { cmd = { 'v', 'ls' }, filetypes = { 'vlang' }, - root_dir = util.root_pattern('v.mod', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -16,7 +18,7 @@ V language server. ``` ]], default_config = { - root_dir = [[root_pattern("v.mod", ".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/vuels.lua b/lua/lspconfig/server_configurations/vuels.lua index d3d2d92e66..be1c8cc229 100644 --- a/lua/lspconfig/server_configurations/vuels.lua +++ b/lua/lspconfig/server_configurations/vuels.lua @@ -7,11 +7,13 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name } end +local workspace_markers = { 'package.json', 'vue.config.js' } + return { default_config = { cmd = cmd, filetypes = { 'vue' }, - root_dir = util.root_pattern('package.json', 'vue.config.js'), + root_dir = util.root_pattern(unpack(workspace_markers)), init_options = { config = { vetur = { @@ -62,7 +64,7 @@ npm install -g vls ``` ]], default_config = { - root_dir = [[root_pattern("package.json", "vue.config.js")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/zls.lua b/lua/lspconfig/server_configurations/zls.lua index d890fb63a4..93451ea218 100644 --- a/lua/lspconfig/server_configurations/zls.lua +++ b/lua/lspconfig/server_configurations/zls.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'zls.json', '.git' } + return { default_config = { cmd = { 'zls' }, filetypes = { 'zig', 'zir' }, - root_dir = util.root_pattern('zls.json', '.git'), + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { @@ -14,7 +16,7 @@ https://github.com/zigtools/zls Zig LSP implementation + Zig Language Server ]], default_config = { - root_dir = [[util.root_pattern("zls.json", ".git")]], + workspace_markers = workspace_markers, }, }, } From e8c53e710b750f713f185825fb20e8000255b569 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Wed, 9 Nov 2022 18:27:39 +0100 Subject: [PATCH 03/11] refactor: export ws markers - 2 --- lua/lspconfig/server_configurations/angularls.lua | 6 ++++-- lua/lspconfig/server_configurations/antlersls.lua | 4 +++- lua/lspconfig/server_configurations/apex_ls.lua | 6 ++++-- .../server_configurations/arduino_language_server.lua | 4 +++- lua/lspconfig/server_configurations/clarity_lsp.lua | 6 ++++-- lua/lspconfig/server_configurations/codeqlls.lua | 4 +++- lua/lspconfig/server_configurations/crystalline.lua | 6 ++++-- lua/lspconfig/server_configurations/dartls.lua | 6 ++++-- lua/lspconfig/server_configurations/dockerls.lua | 6 ++++-- lua/lspconfig/server_configurations/flow.lua | 6 ++++-- .../server_configurations/haxe_language_server.lua | 6 ++++-- lua/lspconfig/server_configurations/hhvm.lua | 6 ++++-- lua/lspconfig/server_configurations/idris2_lsp.lua | 4 +++- lua/lspconfig/server_configurations/please.lua | 4 +++- lua/lspconfig/server_configurations/pyre.lua | 4 +++- lua/lspconfig/server_configurations/qml_lsp.lua | 4 +++- lua/lspconfig/server_configurations/rls.lua | 6 ++++-- lua/lspconfig/server_configurations/sqlls.lua | 4 +++- lua/lspconfig/server_configurations/sqls.lua | 4 +++- lua/lspconfig/server_configurations/theme_check.lua | 4 +++- lua/lspconfig/server_configurations/visualforce_ls.lua | 6 ++++-- lua/lspconfig/server_configurations/volar.lua | 4 +++- lua/lspconfig/server_configurations/wgsl_analyzer.lua | 6 ++++-- lua/lspconfig/server_configurations/zk.lua | 6 ++++-- 24 files changed, 85 insertions(+), 37 deletions(-) diff --git a/lua/lspconfig/server_configurations/angularls.lua b/lua/lspconfig/server_configurations/angularls.lua index 3250735045..a850752fc0 100644 --- a/lua/lspconfig/server_configurations/angularls.lua +++ b/lua/lspconfig/server_configurations/angularls.lua @@ -26,6 +26,8 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, unpack(args) } end +local workspace_markers = { 'angular.json' } + return { default_config = { cmd = cmd, @@ -33,7 +35,7 @@ return { -- Check for angular.json since that is the root of the project. -- Don't check for tsconfig.json or package.json since there are multiple of these -- in an angular monorepo setup. - root_dir = util.root_pattern 'angular.json', + root_dir = util.root_pattern(unpack(workspace_markers)), }, on_new_config = function(new_config, new_root_dir) local new_probe_dir = get_probe_dir(new_root_dir) @@ -69,7 +71,7 @@ require'lspconfig'.angularls.setup{ ``` ]], default_config = { - root_dir = [[root_pattern("angular.json")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/antlersls.lua b/lua/lspconfig/server_configurations/antlersls.lua index 28fa0d0cc0..798de302d2 100644 --- a/lua/lspconfig/server_configurations/antlersls.lua +++ b/lua/lspconfig/server_configurations/antlersls.lua @@ -7,11 +7,13 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, '--stdio' } end +local workspace_markers = { 'composer.json' } + return { default_config = { cmd = cmd, filetypes = { 'html', 'antlers' }, - root_dir = util.root_pattern 'composer.json', + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ diff --git a/lua/lspconfig/server_configurations/apex_ls.lua b/lua/lspconfig/server_configurations/apex_ls.lua index 76fff90f1c..15f35315da 100644 --- a/lua/lspconfig/server_configurations/apex_ls.lua +++ b/lua/lspconfig/server_configurations/apex_ls.lua @@ -1,9 +1,11 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'sfdx-project.json' } + return { default_config = { filetypes = { 'apexcode' }, - root_dir = util.root_pattern 'sfdx-project.json', + root_dir = util.root_pattern(unpack(workspace_markers)), on_new_config = function(config) if not config.cmd and config.apex_jar_path then config.cmd = { @@ -40,7 +42,7 @@ require'lspconfig'.apex_ls.setup { ``` ]], default_config = { - root_dir = [[root_pattern('sfdx-project.json')]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/arduino_language_server.lua b/lua/lspconfig/server_configurations/arduino_language_server.lua index b7f529fffa..5d6b498825 100644 --- a/lua/lspconfig/server_configurations/arduino_language_server.lua +++ b/lua/lspconfig/server_configurations/arduino_language_server.lua @@ -1,9 +1,11 @@ local util = require 'lspconfig.util' +local workspace_markers = { '*.ino' } + return { default_config = { filetypes = { 'arduino' }, - root_dir = util.root_pattern '*.ino', + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ diff --git a/lua/lspconfig/server_configurations/clarity_lsp.lua b/lua/lspconfig/server_configurations/clarity_lsp.lua index 72a6197218..f807b29393 100644 --- a/lua/lspconfig/server_configurations/clarity_lsp.lua +++ b/lua/lspconfig/server_configurations/clarity_lsp.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } + return { default_config = { cmd = { 'clarity-lsp' }, filetypes = { 'clar', 'clarity' }, - root_dir = util.root_pattern '.git', + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -13,7 +15,7 @@ return { To learn how to configure the clarity language server, see the [clarity-lsp documentation](https://github.com/hirosystems/clarity-lsp). ]], default_config = { - root_dir = [[root_pattern(".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/codeqlls.lua b/lua/lspconfig/server_configurations/codeqlls.lua index 695041e44b..c89008e5f8 100644 --- a/lua/lspconfig/server_configurations/codeqlls.lua +++ b/lua/lspconfig/server_configurations/codeqlls.lua @@ -2,11 +2,13 @@ local util = require 'lspconfig.util' local workspace_folders = {} +local workspace_markers = { 'qlpack.yml' } + return { default_config = { cmd = { 'codeql', 'execute', 'language-server', '--check-errors', 'ON_CHANGE', '-q' }, filetypes = { 'ql' }, - root_dir = util.root_pattern 'qlpack.yml', + root_dir = util.root_pattern(unpack(workspace_markers)), log_level = vim.lsp.protocol.MessageType.Warning, before_init = function(initialize_params) table.insert(workspace_folders, { name = 'workspace', uri = initialize_params['rootUri'] }) diff --git a/lua/lspconfig/server_configurations/crystalline.lua b/lua/lspconfig/server_configurations/crystalline.lua index ef4d6bca13..c425d34627 100644 --- a/lua/lspconfig/server_configurations/crystalline.lua +++ b/lua/lspconfig/server_configurations/crystalline.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'shard.yml', '.git' } + return { default_config = { cmd = { 'crystalline' }, filetypes = { 'crystal' }, - root_dir = util.root_pattern 'shard.yml' or util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { @@ -14,7 +16,7 @@ https://github.com/elbywan/crystalline Crystal language server. ]], default_config = { - root_dir = [[root_pattern('shard.yml', '.git')]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/dartls.lua b/lua/lspconfig/server_configurations/dartls.lua index c6facdedae..5f0e756aa3 100644 --- a/lua/lspconfig/server_configurations/dartls.lua +++ b/lua/lspconfig/server_configurations/dartls.lua @@ -5,11 +5,13 @@ local cmd = ( or { 'dart', 'language-server', '--protocol=lsp' } ) +local workspace_markers = { 'pubspec.yaml' } + return { default_config = { cmd = cmd, filetypes = { 'dart' }, - root_dir = util.root_pattern 'pubspec.yaml', + root_dir = util.root_pattern(unpack(workspace_markers)), init_options = { onlyAnalyzeProjectsWithOpenFiles = true, suggestFromUnimportedLibraries = true, @@ -31,7 +33,7 @@ https://github.com/dart-lang/sdk/tree/master/pkg/analysis_server/tool/lsp_spec Language server for dart. ]], default_config = { - root_dir = [[root_pattern("pubspec.yaml")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/dockerls.lua b/lua/lspconfig/server_configurations/dockerls.lua index 6d1cfc7d2f..4f82aaa49b 100644 --- a/lua/lspconfig/server_configurations/dockerls.lua +++ b/lua/lspconfig/server_configurations/dockerls.lua @@ -7,11 +7,13 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, '--stdio' } end +local workspace_markers = { 'Dockerfile' } + return { default_config = { cmd = cmd, filetypes = { 'dockerfile' }, - root_dir = util.root_pattern 'Dockerfile', + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { @@ -24,7 +26,7 @@ npm install -g dockerfile-language-server-nodejs ``` ]], default_config = { - root_dir = [[root_pattern("Dockerfile")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/flow.lua b/lua/lspconfig/server_configurations/flow.lua index 3ac59aaa2d..861e2123e3 100644 --- a/lua/lspconfig/server_configurations/flow.lua +++ b/lua/lspconfig/server_configurations/flow.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.flowconfig' } + return { default_config = { cmd = { 'npx', '--no-install', 'flow', 'lsp' }, filetypes = { 'javascript', 'javascriptreact', 'javascript.jsx' }, - root_dir = util.root_pattern '.flowconfig', + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -21,7 +23,7 @@ npx flow lsp --help ``` ]], default_config = { - root_dir = [[root_pattern(".flowconfig")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/haxe_language_server.lua b/lua/lspconfig/server_configurations/haxe_language_server.lua index 1589c7b047..221bd7aaca 100644 --- a/lua/lspconfig/server_configurations/haxe_language_server.lua +++ b/lua/lspconfig/server_configurations/haxe_language_server.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '*.hxml' } + return { default_config = { cmd = { 'haxe-language-server' }, filetypes = { 'haxe' }, - root_dir = util.root_pattern '*.hxml', + root_dir = util.root_pattern(unpack(workspace_markers)), settings = { haxe = { executable = 'haxe', @@ -41,7 +43,7 @@ your project's root directory. If your file is named something different, specify it using the `init_options.displayArguments` setting. ]], default_config = { - root_dir = [[root_pattern("*.hxml")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/hhvm.lua b/lua/lspconfig/server_configurations/hhvm.lua index 0e8ac5c5bb..6755a9342a 100644 --- a/lua/lspconfig/server_configurations/hhvm.lua +++ b/lua/lspconfig/server_configurations/hhvm.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.hhconfig' } + return { default_config = { cmd = { 'hh_client', 'lsp' }, filetypes = { 'php', 'hack' }, - root_dir = util.root_pattern '.hhconfig', + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -15,7 +17,7 @@ See below for how to setup HHVM & typechecker: https://docs.hhvm.com/hhvm/getting-started/getting-started ]], default_config = { - root_dir = [[root_pattern(".hhconfig")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/idris2_lsp.lua b/lua/lspconfig/server_configurations/idris2_lsp.lua index acb906e634..a2c3ae7fdf 100644 --- a/lua/lspconfig/server_configurations/idris2_lsp.lua +++ b/lua/lspconfig/server_configurations/idris2_lsp.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '*.ipkg' } + return { default_config = { cmd = { 'idris2-lsp' }, filetypes = { 'idris2' }, - root_dir = util.root_pattern '*.ipkg', + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ diff --git a/lua/lspconfig/server_configurations/please.lua b/lua/lspconfig/server_configurations/please.lua index 085d1e700c..428de261e8 100644 --- a/lua/lspconfig/server_configurations/please.lua +++ b/lua/lspconfig/server_configurations/please.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.plzconfig' } + return { default_config = { cmd = { 'plz', 'tool', 'lps' }, filetypes = { 'bzl' }, - root_dir = util.root_pattern '.plzconfig', + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { diff --git a/lua/lspconfig/server_configurations/pyre.lua b/lua/lspconfig/server_configurations/pyre.lua index 5c2f8fb73c..0611dff95a 100644 --- a/lua/lspconfig/server_configurations/pyre.lua +++ b/lua/lspconfig/server_configurations/pyre.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.pyre_configuration' } + return { default_config = { cmd = { 'pyre', 'persistent' }, filetypes = { 'python' }, - root_dir = util.root_pattern '.pyre_configuration', + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ diff --git a/lua/lspconfig/server_configurations/qml_lsp.lua b/lua/lspconfig/server_configurations/qml_lsp.lua index 0f334a3216..d8f5128595 100644 --- a/lua/lspconfig/server_configurations/qml_lsp.lua +++ b/lua/lspconfig/server_configurations/qml_lsp.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '*.qml' } + return { default_config = { cmd = { 'qml-lsp' }, filetypes = { 'qmljs' }, - root_dir = util.root_pattern '*.qml', + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ diff --git a/lua/lspconfig/server_configurations/rls.lua b/lua/lspconfig/server_configurations/rls.lua index 363b81d2a8..c512acdcbb 100644 --- a/lua/lspconfig/server_configurations/rls.lua +++ b/lua/lspconfig/server_configurations/rls.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'Cargo.toml' } + return { default_config = { cmd = { 'rls' }, filetypes = { 'rust' }, - root_dir = util.root_pattern 'Cargo.toml', + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -36,7 +38,7 @@ cmd = {"rustup", "run", "nightly", "rls"} ``` ]], default_config = { - root_dir = [[root_pattern("Cargo.toml")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/sqlls.lua b/lua/lspconfig/server_configurations/sqlls.lua index 434a7ce8fe..66648868ab 100644 --- a/lua/lspconfig/server_configurations/sqlls.lua +++ b/lua/lspconfig/server_configurations/sqlls.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.sqllsrc.json' } + return { default_config = { cmd = { 'sql-language-server', 'up', '--method', 'stdio' }, filetypes = { 'sql', 'mysql' }, - root_dir = util.root_pattern '.sqllsrc.json', + root_dir = util.root_pattern(unpack(workspace_markers)), settings = {}, }, docs = { diff --git a/lua/lspconfig/server_configurations/sqls.lua b/lua/lspconfig/server_configurations/sqls.lua index 2680253923..a1c0cb2e7a 100644 --- a/lua/lspconfig/server_configurations/sqls.lua +++ b/lua/lspconfig/server_configurations/sqls.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'config.yml' } + return { default_config = { cmd = { 'sqls' }, filetypes = { 'sql', 'mysql' }, - root_dir = util.root_pattern 'config.yml', + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, settings = {}, }, diff --git a/lua/lspconfig/server_configurations/theme_check.lua b/lua/lspconfig/server_configurations/theme_check.lua index 94d677408b..e0a3ff5819 100644 --- a/lua/lspconfig/server_configurations/theme_check.lua +++ b/lua/lspconfig/server_configurations/theme_check.lua @@ -2,11 +2,13 @@ local util = require 'lspconfig.util' local bin_name = 'theme-check-language-server' +local workspace_markers = { '.theme-check.yml' } + return { default_config = { cmd = { bin_name, '--stdio' }, filetypes = { 'liquid' }, - root_dir = util.root_pattern '.theme-check.yml', + root_dir = util.root_pattern(unpack(workspace_markers)), settings = {}, }, docs = { diff --git a/lua/lspconfig/server_configurations/visualforce_ls.lua b/lua/lspconfig/server_configurations/visualforce_ls.lua index c48bcaa2d6..bbd9964864 100644 --- a/lua/lspconfig/server_configurations/visualforce_ls.lua +++ b/lua/lspconfig/server_configurations/visualforce_ls.lua @@ -1,9 +1,11 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'sfdx-project.json' } + return { default_config = { filetypes = { 'visualforce' }, - root_dir = util.root_pattern 'sfdx-project.json', + root_dir = util.root_pattern(unpack(workspace_markers)), init_options = { embeddedLanguages = { css = true, @@ -32,7 +34,7 @@ require'lspconfig'.visualforce_ls.setup { ``` ]], default_config = { - root_dir = [[root_pattern('sfdx-project.json')]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/volar.lua b/lua/lspconfig/server_configurations/volar.lua index a7f38ade88..5df6e2f800 100644 --- a/lua/lspconfig/server_configurations/volar.lua +++ b/lua/lspconfig/server_configurations/volar.lua @@ -52,11 +52,13 @@ local cmd = { bin_name, '--stdio' } if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, '--stdio' } end +local workspace_markers = { 'package.json' } + return { default_config = { cmd = cmd, filetypes = { 'vue' }, - root_dir = util.root_pattern 'package.json', + root_dir = util.root_pattern(unpack(workspace_markers)), init_options = volar_init_options, on_new_config = function(new_config, new_root_dir) if diff --git a/lua/lspconfig/server_configurations/wgsl_analyzer.lua b/lua/lspconfig/server_configurations/wgsl_analyzer.lua index 859373eae9..e12f0203f1 100644 --- a/lua/lspconfig/server_configurations/wgsl_analyzer.lua +++ b/lua/lspconfig/server_configurations/wgsl_analyzer.lua @@ -7,11 +7,13 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name } end +local workspace_markers = { '.git' } + return { default_config = { cmd = cmd, filetypes = { 'wgsl' }, - root_dir = util.root_pattern '.git', + root_dir = util.root_pattern(unpack(workspace_markers)), settings = {}, }, docs = { @@ -24,7 +26,7 @@ cargo install --git https://github.com/wgsl-analyzer/wgsl-analyzer wgsl_analyzer ``` ]], default_config = { - root_dir = [[root_pattern(".git"]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/zk.lua b/lua/lspconfig/server_configurations/zk.lua index e670f83406..234ddaa9d5 100644 --- a/lua/lspconfig/server_configurations/zk.lua +++ b/lua/lspconfig/server_configurations/zk.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.zk' } + return { default_config = { cmd = { 'zk', 'lsp' }, filetypes = { 'markdown' }, - root_dir = util.root_pattern '.zk', + root_dir = util.root_pattern(unpack(workspace_markers)), }, commands = { ZkIndex = { @@ -42,7 +44,7 @@ https://github.com/mickael-menu/zk A plain text note-taking assistant ]], default_config = { - root_dir = [[root_pattern(".zk")]], + workspace_markers = workspace_markers, }, }, } From 04830916fd503b926fd35cd455db943fad787473 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Wed, 9 Nov 2022 18:27:39 +0100 Subject: [PATCH 04/11] refactor: export ws markers - 3 --- lua/lspconfig/server_configurations/asm_lsp.lua | 4 +++- lua/lspconfig/server_configurations/bashls.lua | 6 ++++-- lua/lspconfig/server_configurations/beancount.lua | 6 ++++-- lua/lspconfig/server_configurations/bicep.lua | 6 ++++-- lua/lspconfig/server_configurations/blueprint_ls.lua | 6 ++++-- lua/lspconfig/server_configurations/bsl_ls.lua | 6 ++++-- .../server_configurations/cucumber_language_server.lua | 6 ++++-- lua/lspconfig/server_configurations/dhall_lsp_server.lua | 6 ++++-- lua/lspconfig/server_configurations/diagnosticls.lua | 4 +++- lua/lspconfig/server_configurations/dotls.lua | 4 +++- lua/lspconfig/server_configurations/efm.lua | 7 +++++-- lua/lspconfig/server_configurations/emmet_ls.lua | 4 +++- lua/lspconfig/server_configurations/esbonio.lua | 4 +++- lua/lspconfig/server_configurations/flux_lsp.lua | 6 ++++-- lua/lspconfig/server_configurations/fstar.lua | 6 ++++-- lua/lspconfig/server_configurations/glslls.lua | 4 +++- lua/lspconfig/server_configurations/grammarly.lua | 6 ++++-- lua/lspconfig/server_configurations/hdl_checker.lua | 6 ++++-- lua/lspconfig/server_configurations/hoon_ls.lua | 4 +++- lua/lspconfig/server_configurations/jsonls.lua | 7 +++++-- lua/lspconfig/server_configurations/lelwel_ls.lua | 4 +++- lua/lspconfig/server_configurations/lemminx.lua | 6 ++++-- lua/lspconfig/server_configurations/ltex.lua | 4 +++- lua/lspconfig/server_configurations/luau_lsp.lua | 6 ++++-- lua/lspconfig/server_configurations/mlir_lsp_server.lua | 4 +++- lua/lspconfig/server_configurations/mm0_ls.lua | 4 +++- lua/lspconfig/server_configurations/nickel_ls.lua | 4 +++- lua/lspconfig/server_configurations/opencl_ls.lua | 6 ++++-- lua/lspconfig/server_configurations/openscad_ls.lua | 4 +++- lua/lspconfig/server_configurations/perlls.lua | 4 +++- lua/lspconfig/server_configurations/perlnavigator.lua | 4 +++- lua/lspconfig/server_configurations/perlpls.lua | 6 ++++-- lua/lspconfig/server_configurations/powershell_es.lua | 4 +++- lua/lspconfig/server_configurations/prosemd_lsp.lua | 4 +++- lua/lspconfig/server_configurations/racket_langserver.lua | 4 +++- lua/lspconfig/server_configurations/remark_ls.lua | 4 +++- lua/lspconfig/server_configurations/salt_ls.lua | 6 ++++-- lua/lspconfig/server_configurations/solang.lua | 6 ++++-- lua/lspconfig/server_configurations/svls.lua | 6 ++++-- lua/lspconfig/server_configurations/tilt_ls.lua | 6 ++++-- lua/lspconfig/server_configurations/verible.lua | 4 +++- lua/lspconfig/server_configurations/veridian.lua | 4 +++- lua/lspconfig/server_configurations/vimls.lua | 4 +++- lua/lspconfig/server_configurations/yamlls.lua | 6 ++++-- 44 files changed, 156 insertions(+), 66 deletions(-) diff --git a/lua/lspconfig/server_configurations/asm_lsp.lua b/lua/lspconfig/server_configurations/asm_lsp.lua index 102bcbab16..0e4067f93e 100644 --- a/lua/lspconfig/server_configurations/asm_lsp.lua +++ b/lua/lspconfig/server_configurations/asm_lsp.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } + return { default_config = { cmd = { 'asm-lsp' }, filetypes = { 'asm', 'vmasm' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ diff --git a/lua/lspconfig/server_configurations/bashls.lua b/lua/lspconfig/server_configurations/bashls.lua index 3f25c76f49..5911d4895f 100644 --- a/lua/lspconfig/server_configurations/bashls.lua +++ b/lua/lspconfig/server_configurations/bashls.lua @@ -7,6 +7,8 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, 'start' } end +local workspace_markers = { '.git' } + return { default_config = { cmd = cmd, @@ -18,7 +20,7 @@ return { GLOB_PATTERN = vim.env.GLOB_PATTERN or '*@(.sh|.inc|.bash|.command)', }, filetypes = { 'sh' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { @@ -33,7 +35,7 @@ npm i -g bash-language-server Language server for bash, written using tree sitter in typescript. ]], default_config = { - root_dir = [[util.find_git_ancestor]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/beancount.lua b/lua/lspconfig/server_configurations/beancount.lua index 5258456c00..5189736d53 100644 --- a/lua/lspconfig/server_configurations/beancount.lua +++ b/lua/lspconfig/server_configurations/beancount.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } + return { default_config = { cmd = { 'beancount-language-server', '--stdio' }, filetypes = { 'beancount', 'bean' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, init_options = { -- this is the path to the beancout journal file @@ -18,7 +20,7 @@ https://github.com/polarmutex/beancount-language-server#installation See https://github.com/polarmutex/beancount-language-server#configuration for configuration options ]], default_config = { - root_dir = [[root_pattern(".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/bicep.lua b/lua/lspconfig/server_configurations/bicep.lua index 1ec703238a..76e8898ba3 100644 --- a/lua/lspconfig/server_configurations/bicep.lua +++ b/lua/lspconfig/server_configurations/bicep.lua @@ -1,9 +1,11 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } + return { default_config = { filetypes = { 'bicep' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), init_options = {}, }, docs = { @@ -41,7 +43,7 @@ To download the latest release and place in /usr/local/bin/bicep-langserver: ``` ]=], default_config = { - root_dir = [[util.find_git_ancestor]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/blueprint_ls.lua b/lua/lspconfig/server_configurations/blueprint_ls.lua index d8d36ebb86..2e17856eaf 100644 --- a/lua/lspconfig/server_configurations/blueprint_ls.lua +++ b/lua/lspconfig/server_configurations/blueprint_ls.lua @@ -7,6 +7,8 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, 'start' } end +local workspace_markers = { '.git' } + return { default_config = { cmd = cmd, @@ -18,7 +20,7 @@ return { GLOB_PATTERN = vim.env.GLOB_PATTERN or '*@(.blp)', }, filetypes = { 'blueprint' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { @@ -31,7 +33,7 @@ Language server for the blurprint markup language, written in python and part of the blueprint-compiler. ]], default_config = { - root_dir = [[util.find_git_ancestor]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/bsl_ls.lua b/lua/lspconfig/server_configurations/bsl_ls.lua index fef15f9270..448a5eaa46 100644 --- a/lua/lspconfig/server_configurations/bsl_ls.lua +++ b/lua/lspconfig/server_configurations/bsl_ls.lua @@ -1,9 +1,11 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } + return { default_config = { filetypes = { 'bsl', 'os' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -13,7 +15,7 @@ return { ]], default_config = { - root_dir = [[root_pattern(".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/cucumber_language_server.lua b/lua/lspconfig/server_configurations/cucumber_language_server.lua index 07832061fe..7a44880ed8 100644 --- a/lua/lspconfig/server_configurations/cucumber_language_server.lua +++ b/lua/lspconfig/server_configurations/cucumber_language_server.lua @@ -7,11 +7,13 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, '--stdio' } end +local workspace_markers = { '.git' } + return { default_config = { cmd = cmd, filetypes = { 'cucumber' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -27,7 +29,7 @@ npm install -g @cucumber/language-server ``` ]], default_config = { - root_dir = [[util.find_git_ancestor]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/dhall_lsp_server.lua b/lua/lspconfig/server_configurations/dhall_lsp_server.lua index af910f3658..2e5b3ef0ec 100644 --- a/lua/lspconfig/server_configurations/dhall_lsp_server.lua +++ b/lua/lspconfig/server_configurations/dhall_lsp_server.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } + return { default_config = { cmd = { 'dhall-lsp-server' }, filetypes = { 'dhall' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { @@ -20,7 +22,7 @@ cabal install dhall-lsp-server prebuilt binaries can be found [here](https://github.com/dhall-lang/dhall-haskell/releases). ]], default_config = { - root_dir = [[root_pattern(".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/diagnosticls.lua b/lua/lspconfig/server_configurations/diagnosticls.lua index 8f0476b614..bc94f45acf 100644 --- a/lua/lspconfig/server_configurations/diagnosticls.lua +++ b/lua/lspconfig/server_configurations/diagnosticls.lua @@ -7,10 +7,12 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, '--stdio' } end +local workspace_markers = { '.git' } + return { default_config = { cmd = cmd, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, filetypes = {}, }, diff --git a/lua/lspconfig/server_configurations/dotls.lua b/lua/lspconfig/server_configurations/dotls.lua index dff14b9cd5..0017b27ed8 100644 --- a/lua/lspconfig/server_configurations/dotls.lua +++ b/lua/lspconfig/server_configurations/dotls.lua @@ -7,11 +7,13 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, '--stdio' } end +local workspace_markers = { '.git' } + return { default_config = { cmd = cmd, filetypes = { 'dot' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { diff --git a/lua/lspconfig/server_configurations/efm.lua b/lua/lspconfig/server_configurations/efm.lua index f5f74edc50..259dec631a 100644 --- a/lua/lspconfig/server_configurations/efm.lua +++ b/lua/lspconfig/server_configurations/efm.lua @@ -1,9 +1,11 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } + return { default_config = { cmd = { 'efm-langserver' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, @@ -20,6 +22,7 @@ launching the language server on single files. If on an older version of EFM, di require('lspconfig')['efm'].setup{ settings = ..., -- You must populate this according to the EFM readme filetypes = ..., -- Populate this according to the note below + workspace_markers = workspace_markers, single_file_support = false, -- This is the important line for supporting older version of EFM } ``` @@ -37,7 +40,7 @@ require('lspconfig')['efm'].setup{ ]], default_config = { - root_dir = [[util.root_pattern(".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/emmet_ls.lua b/lua/lspconfig/server_configurations/emmet_ls.lua index aa04f794ae..627e21a40a 100644 --- a/lua/lspconfig/server_configurations/emmet_ls.lua +++ b/lua/lspconfig/server_configurations/emmet_ls.lua @@ -7,11 +7,13 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, '--stdio' } end +local workspace_markers = { '.git' } + return { default_config = { cmd = cmd, filetypes = { 'html', 'typescriptreact', 'javascriptreact', 'css', 'sass', 'scss', 'less' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { diff --git a/lua/lspconfig/server_configurations/esbonio.lua b/lua/lspconfig/server_configurations/esbonio.lua index ca681d406a..5e6794c764 100644 --- a/lua/lspconfig/server_configurations/esbonio.lua +++ b/lua/lspconfig/server_configurations/esbonio.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } + return { default_config = { cmd = { 'python3', '-m', 'esbonio' }, filetypes = { 'rst' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ diff --git a/lua/lspconfig/server_configurations/flux_lsp.lua b/lua/lspconfig/server_configurations/flux_lsp.lua index 3be9a1b113..10b3e615fa 100644 --- a/lua/lspconfig/server_configurations/flux_lsp.lua +++ b/lua/lspconfig/server_configurations/flux_lsp.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } + return { default_config = { cmd = { 'flux-lsp' }, filetypes = { 'flux' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { @@ -16,7 +18,7 @@ cargo install --git https://github.com/influxdata/flux-lsp ``` ]], default_config = { - root_dir = [[util.find_git_ancestor]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/fstar.lua b/lua/lspconfig/server_configurations/fstar.lua index d866c544b9..8e62ae513f 100644 --- a/lua/lspconfig/server_configurations/fstar.lua +++ b/lua/lspconfig/server_configurations/fstar.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } + return { default_config = { cmd = { 'fstar.exe', '--lsp' }, filetypes = { 'fstar' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -13,7 +15,7 @@ https://github.com/FStarLang/FStar LSP support is included in FStar. Make sure `fstar.exe` is in your PATH. ]], default_config = { - root_dir = [[util.find_git_ancestor]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/glslls.lua b/lua/lspconfig/server_configurations/glslls.lua index fd6de7f882..f6d6c94a97 100644 --- a/lua/lspconfig/server_configurations/glslls.lua +++ b/lua/lspconfig/server_configurations/glslls.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } + return { default_config = { cmd = { 'glslls', '--stdin' }, filetypes = { 'glsl' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, capabilities = { textDocument = { diff --git a/lua/lspconfig/server_configurations/grammarly.lua b/lua/lspconfig/server_configurations/grammarly.lua index 2ab47e188f..b947caac1a 100644 --- a/lua/lspconfig/server_configurations/grammarly.lua +++ b/lua/lspconfig/server_configurations/grammarly.lua @@ -7,11 +7,13 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, '--stdio' } end +local workspace_markers = { '.git' } + return { default_config = { cmd = cmd, filetypes = { 'markdown' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, handlers = { ['$/updateDocumentState'] = function() @@ -35,7 +37,7 @@ npm i -g grammarly-languageserver WARNING: Since this language server uses Grammarly's API, any document you open with it running is shared with them. Please evaluate their [privacy policy](https://www.grammarly.com/privacy-policy) before using this. ]], default_config = { - root_dir = [[util.find_git_ancestor]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/hdl_checker.lua b/lua/lspconfig/server_configurations/hdl_checker.lua index 5cf2941497..616f40d230 100644 --- a/lua/lspconfig/server_configurations/hdl_checker.lua +++ b/lua/lspconfig/server_configurations/hdl_checker.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } + return { default_config = { cmd = { 'hdl_checker', '--lsp' }, filetypes = { 'vhdl', 'verilog', 'systemverilog' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { @@ -14,7 +16,7 @@ Language server for hdl-checker. Install using: `pip install hdl-checker --upgrade` ]], default_config = { - root_dir = [[util.find_git_ancestor]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/hoon_ls.lua b/lua/lspconfig/server_configurations/hoon_ls.lua index 80092db19b..4013b36a81 100644 --- a/lua/lspconfig/server_configurations/hoon_ls.lua +++ b/lua/lspconfig/server_configurations/hoon_ls.lua @@ -7,11 +7,13 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name } end +local workspace_markers = { '.git' } + return { default_config = { cmd = cmd, filetypes = { 'hoon' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { diff --git a/lua/lspconfig/server_configurations/jsonls.lua b/lua/lspconfig/server_configurations/jsonls.lua index a62a715d0c..b1085bdf71 100644 --- a/lua/lspconfig/server_configurations/jsonls.lua +++ b/lua/lspconfig/server_configurations/jsonls.lua @@ -7,14 +7,17 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, '--stdio' } end +local workspace_markers = { '.git' } + return { default_config = { cmd = cmd, filetypes = { 'json', 'jsonc' }, + workspace_markers = workspace_markers, init_options = { provideFormatter = true, }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { @@ -42,7 +45,7 @@ require'lspconfig'.jsonls.setup { ``` ]], default_config = { - root_dir = [[util.find_git_ancestor]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/lelwel_ls.lua b/lua/lspconfig/server_configurations/lelwel_ls.lua index ac8c456054..53797df3af 100644 --- a/lua/lspconfig/server_configurations/lelwel_ls.lua +++ b/lua/lspconfig/server_configurations/lelwel_ls.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } + return { default_config = { cmd = { 'lelwel-ls' }, filetypes = { 'llw' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ diff --git a/lua/lspconfig/server_configurations/lemminx.lua b/lua/lspconfig/server_configurations/lemminx.lua index eb1ccaa8bb..ea223129a7 100644 --- a/lua/lspconfig/server_configurations/lemminx.lua +++ b/lua/lspconfig/server_configurations/lemminx.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } + return { default_config = { cmd = { 'lemminx' }, filetypes = { 'xml', 'xsd', 'xsl', 'xslt', 'svg' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { @@ -17,7 +19,7 @@ NOTE to macOS users: Binaries from unidentified developers are blocked by defaul ]], default_config = { - root_dir = [[util.find_git_ancestor]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/ltex.lua b/lua/lspconfig/server_configurations/ltex.lua index 0aeb387420..f9ae96ca65 100644 --- a/lua/lspconfig/server_configurations/ltex.lua +++ b/lua/lspconfig/server_configurations/ltex.lua @@ -14,11 +14,13 @@ if vim.fn.has 'win32' == 1 then bin_name = bin_name .. '.bat' end +local workspace_markers = { '.git' } + return { default_config = { cmd = { bin_name }, filetypes = { 'bib', 'gitcommit', 'markdown', 'org', 'plaintex', 'rst', 'rnoweb', 'tex' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, get_language_id = function(_, filetype) local language_id = language_id_mapping[filetype] diff --git a/lua/lspconfig/server_configurations/luau_lsp.lua b/lua/lspconfig/server_configurations/luau_lsp.lua index c916114a05..90ea134241 100644 --- a/lua/lspconfig/server_configurations/luau_lsp.lua +++ b/lua/lspconfig/server_configurations/luau_lsp.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } + return { default_config = { cmd = { 'luau-lsp', 'lsp' }, filetypes = { 'luau' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { [[ @@ -21,7 +23,7 @@ autocmd BufRead,BufNewFile *.luau setf luau ``` ]], default_config = { - root_dir = [[root_pattern(".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/mlir_lsp_server.lua b/lua/lspconfig/server_configurations/mlir_lsp_server.lua index 22a712688a..61266cdc0d 100644 --- a/lua/lspconfig/server_configurations/mlir_lsp_server.lua +++ b/lua/lspconfig/server_configurations/mlir_lsp_server.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } + return { default_config = { cmd = { 'mlir-lsp-server' }, filetypes = { 'mlir' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { diff --git a/lua/lspconfig/server_configurations/mm0_ls.lua b/lua/lspconfig/server_configurations/mm0_ls.lua index 513bbeb957..bff24effc9 100644 --- a/lua/lspconfig/server_configurations/mm0_ls.lua +++ b/lua/lspconfig/server_configurations/mm0_ls.lua @@ -1,9 +1,11 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } + return { default_config = { cmd = { 'mm0-rs', 'server' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), filetypes = { 'metamath-zero' }, single_file_support = true, }, diff --git a/lua/lspconfig/server_configurations/nickel_ls.lua b/lua/lspconfig/server_configurations/nickel_ls.lua index 391abfee6e..34f235109d 100644 --- a/lua/lspconfig/server_configurations/nickel_ls.lua +++ b/lua/lspconfig/server_configurations/nickel_ls.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } + return { default_config = { cmd = { 'nls' }, filetypes = { 'ncl', 'nickel' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { diff --git a/lua/lspconfig/server_configurations/opencl_ls.lua b/lua/lspconfig/server_configurations/opencl_ls.lua index dc88d24c4d..b6905de94c 100644 --- a/lua/lspconfig/server_configurations/opencl_ls.lua +++ b/lua/lspconfig/server_configurations/opencl_ls.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } + return { default_config = { cmd = { 'opencl-language-server' }, filetypes = { 'opencl' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -15,7 +17,7 @@ Build instructions can be found [here](https://github.com/Galarius/opencl-langua Prebuilt binaries are available for Linux, macOS and Windows [here](https://github.com/Galarius/opencl-language-server/releases). ]], default_config = { - root_dir = [[util.root_pattern(".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/openscad_ls.lua b/lua/lspconfig/server_configurations/openscad_ls.lua index e5ca9cac50..3473aeee1d 100644 --- a/lua/lspconfig/server_configurations/openscad_ls.lua +++ b/lua/lspconfig/server_configurations/openscad_ls.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } + return { default_config = { cmd = { 'openscad-language-server' }, filetypes = { 'openscad' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { diff --git a/lua/lspconfig/server_configurations/perlls.lua b/lua/lspconfig/server_configurations/perlls.lua index 5d241a5d69..a90a0a829c 100644 --- a/lua/lspconfig/server_configurations/perlls.lua +++ b/lua/lspconfig/server_configurations/perlls.lua @@ -1,5 +1,7 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } + return { default_config = { cmd = { @@ -21,7 +23,7 @@ return { }, }, filetypes = { 'perl' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { diff --git a/lua/lspconfig/server_configurations/perlnavigator.lua b/lua/lspconfig/server_configurations/perlnavigator.lua index 7ba389552c..966c506da1 100644 --- a/lua/lspconfig/server_configurations/perlnavigator.lua +++ b/lua/lspconfig/server_configurations/perlnavigator.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } + return { default_config = { cmd = {}, filetypes = { 'perl' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { diff --git a/lua/lspconfig/server_configurations/perlpls.lua b/lua/lspconfig/server_configurations/perlpls.lua index 3326028129..f21219f644 100644 --- a/lua/lspconfig/server_configurations/perlpls.lua +++ b/lua/lspconfig/server_configurations/perlpls.lua @@ -1,5 +1,7 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } + return { default_config = { cmd = { 'pls' }, @@ -10,7 +12,7 @@ return { }, }, filetypes = { 'perl' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { @@ -23,7 +25,7 @@ https://metacpan.org/pod/PLS To use the language server, ensure that you have PLS installed and that it is in your path ]], default_config = { - root_dir = [[util.find_git_ancestor]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/powershell_es.lua b/lua/lspconfig/server_configurations/powershell_es.lua index ac723f4360..482a4ea9bd 100644 --- a/lua/lspconfig/server_configurations/powershell_es.lua +++ b/lua/lspconfig/server_configurations/powershell_es.lua @@ -11,6 +11,8 @@ local function make_cmd(new_config) end end +local workspace_markers = { '.git' } + return { default_config = { shell = 'pwsh', @@ -22,7 +24,7 @@ return { end, filetypes = { 'ps1' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { diff --git a/lua/lspconfig/server_configurations/prosemd_lsp.lua b/lua/lspconfig/server_configurations/prosemd_lsp.lua index 048e4b4941..d6b12474ba 100644 --- a/lua/lspconfig/server_configurations/prosemd_lsp.lua +++ b/lua/lspconfig/server_configurations/prosemd_lsp.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } + return { default_config = { cmd = { 'prosemd-lsp', '--stdio' }, filetypes = { 'markdown' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { diff --git a/lua/lspconfig/server_configurations/racket_langserver.lua b/lua/lspconfig/server_configurations/racket_langserver.lua index 25bd0ab1f4..342a9cb053 100644 --- a/lua/lspconfig/server_configurations/racket_langserver.lua +++ b/lua/lspconfig/server_configurations/racket_langserver.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } + return { default_config = { cmd = { 'racket', '--lib', 'racket-langserver' }, filetypes = { 'racket', 'scheme' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { diff --git a/lua/lspconfig/server_configurations/remark_ls.lua b/lua/lspconfig/server_configurations/remark_ls.lua index 4ef37177c1..69100aec63 100644 --- a/lua/lspconfig/server_configurations/remark_ls.lua +++ b/lua/lspconfig/server_configurations/remark_ls.lua @@ -7,11 +7,13 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, '--stdio' } end +local workspace_markers = { '.git' } + return { default_config = { cmd = cmd, filetypes = { 'markdown' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { diff --git a/lua/lspconfig/server_configurations/salt_ls.lua b/lua/lspconfig/server_configurations/salt_ls.lua index 65d1d3223e..5e7fd5f42c 100644 --- a/lua/lspconfig/server_configurations/salt_ls.lua +++ b/lua/lspconfig/server_configurations/salt_ls.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } + return { default_config = { cmd = { 'salt_lsp_server' }, filetypes = { 'sls' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { @@ -18,7 +20,7 @@ pip install salt-lsp ``` ]], default_config = { - root_dir = [[root_pattern('.git')]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/solang.lua b/lua/lspconfig/server_configurations/solang.lua index be1d1ecabc..7dd5178bf8 100644 --- a/lua/lspconfig/server_configurations/solang.lua +++ b/lua/lspconfig/server_configurations/solang.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } + return { default_config = { cmd = { 'solang', '--language-server', '--target', 'ewasm' }, filetypes = { 'solidity' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -21,7 +23,7 @@ There is currently no support for completion, goto definition, references, or ot ]], default_config = { - root_dir = [[util.find_git_ancestor]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/svls.lua b/lua/lspconfig/server_configurations/svls.lua index ff4d8102ee..94846b08a4 100644 --- a/lua/lspconfig/server_configurations/svls.lua +++ b/lua/lspconfig/server_configurations/svls.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } + return { default_config = { cmd = { 'svls' }, filetypes = { 'verilog', 'systemverilog' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -18,7 +20,7 @@ Language server for verilog and SystemVerilog ``` ]], default_config = { - root_dir = [[util.find_git_ancestor]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/tilt_ls.lua b/lua/lspconfig/server_configurations/tilt_ls.lua index c6656513ed..a0bbe53373 100644 --- a/lua/lspconfig/server_configurations/tilt_ls.lua +++ b/lua/lspconfig/server_configurations/tilt_ls.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } + return { default_config = { cmd = { 'tilt', 'lsp', 'start' }, filetypes = { 'tiltfile' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { @@ -20,7 +22,7 @@ autocmd BufRead Tiltfile setf=tiltfile ``` ]], default_config = { - root_dir = [[root_pattern(".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/verible.lua b/lua/lspconfig/server_configurations/verible.lua index 3c4823a876..04d7530bfe 100644 --- a/lua/lspconfig/server_configurations/verible.lua +++ b/lua/lspconfig/server_configurations/verible.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } + return { default_config = { cmd = { 'verible-verilog-ls' }, filetypes = { 'systemverilog', 'verilog' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ diff --git a/lua/lspconfig/server_configurations/veridian.lua b/lua/lspconfig/server_configurations/veridian.lua index 231d0c056a..d1411d3200 100644 --- a/lua/lspconfig/server_configurations/veridian.lua +++ b/lua/lspconfig/server_configurations/veridian.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } + return { default_config = { cmd = { 'veridian' }, filetypes = { 'systemverilog', 'verilog' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ diff --git a/lua/lspconfig/server_configurations/vimls.lua b/lua/lspconfig/server_configurations/vimls.lua index 9b33d3a642..9db9f93ec8 100644 --- a/lua/lspconfig/server_configurations/vimls.lua +++ b/lua/lspconfig/server_configurations/vimls.lua @@ -7,11 +7,13 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, '--stdio' } end +local workspace_markers = { '.git' } + return { default_config = { cmd = cmd, filetypes = { 'vim' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, init_options = { isNeovim = true, diff --git a/lua/lspconfig/server_configurations/yamlls.lua b/lua/lspconfig/server_configurations/yamlls.lua index 52d8e6f6d8..85bcaaa705 100644 --- a/lua/lspconfig/server_configurations/yamlls.lua +++ b/lua/lspconfig/server_configurations/yamlls.lua @@ -7,11 +7,13 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, '--stdio' } end +local workspace_markers = { '.git' } + return { default_config = { cmd = cmd, filetypes = { 'yaml', 'yaml.docker-compose' }, - root_dir = util.find_git_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, settings = { -- https://github.com/redhat-developer/vscode-redhat-telemetry#how-to-disable-telemetry-reporting @@ -81,7 +83,7 @@ require('lspconfig').yamlls.setup { ]], default_config = { - root_dir = [[util.find_git_ancestor]], + workspace_markers = workspace_markers, }, }, } From b71542216986ab28f592588c7a4c80a0c2dde425 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Wed, 9 Nov 2022 18:27:39 +0100 Subject: [PATCH 05/11] refactor: export ws markers - 4 --- lua/lspconfig/server_configurations/ccls.lua | 9 ++++----- .../erg_language_server.lua | 8 ++++---- .../server_configurations/fortls.lua | 8 ++++---- .../server_configurations/ghdl_ls.lua | 6 +++--- .../server_configurations/groovyls.lua | 7 ++++--- .../server_configurations/jsonnet_ls.lua | 8 ++++---- .../server_configurations/julials.lua | 7 ++++--- .../server_configurations/marksman.lua | 9 ++++----- lua/lspconfig/server_configurations/mint.lua | 7 ++++--- .../mlir_pdll_lsp_server.lua | 7 ++++--- lua/lspconfig/server_configurations/nimls.lua | 7 ++++--- lua/lspconfig/server_configurations/pylsp.lua | 20 +++++++++---------- .../robotframework_ls.lua | 8 ++++---- lua/lspconfig/server_configurations/scry.lua | 8 ++++---- .../server_configurations/sourcery.lua | 9 +++++---- .../server_configurations/svlangserver.lua | 8 ++++---- lua/lspconfig/server_configurations/taplo.lua | 8 ++++---- .../tblgen_lsp_server.lua | 7 ++++--- .../server_configurations/texlab.lua | 7 ++++--- 19 files changed, 82 insertions(+), 76 deletions(-) diff --git a/lua/lspconfig/server_configurations/ccls.lua b/lua/lspconfig/server_configurations/ccls.lua index 3009a64155..331d47d23e 100644 --- a/lua/lspconfig/server_configurations/ccls.lua +++ b/lua/lspconfig/server_configurations/ccls.lua @@ -1,17 +1,16 @@ local util = require 'lspconfig.util' -local root_files = { +local workspace_markers = { 'compile_commands.json', '.ccls', + '.git', } return { default_config = { cmd = { 'ccls' }, filetypes = { 'c', 'cpp', 'objc', 'objcpp' }, - root_dir = function(fname) - return util.root_pattern(unpack(root_files))(fname) or util.find_git_ancestor(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), offset_encoding = 'utf-32', -- ccls does not support sending a null root directory single_file_support = false, @@ -44,7 +43,7 @@ lspconfig.ccls.setup { ]], default_config = { - root_dir = [[root_pattern('compile_commands.json', '.ccls', '.git')]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/erg_language_server.lua b/lua/lspconfig/server_configurations/erg_language_server.lua index 7f2daf700a..e6ab713e37 100644 --- a/lua/lspconfig/server_configurations/erg_language_server.lua +++ b/lua/lspconfig/server_configurations/erg_language_server.lua @@ -1,12 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'package.er', '.git' } + return { default_config = { cmd = { 'els' }, filetypes = { 'erg' }, - root_dir = function(fname) - return util.root_pattern 'package.er'(fname) or util.find_git_ancestor(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -20,7 +20,7 @@ ELS (erg-language-server) is a language server for the Erg programming language. ``` ]], default_config = { - root_dir = [[root_pattern("package.er") or find_git_ancestor]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/fortls.lua b/lua/lspconfig/server_configurations/fortls.lua index 41a000515e..ca44d65e28 100644 --- a/lua/lspconfig/server_configurations/fortls.lua +++ b/lua/lspconfig/server_configurations/fortls.lua @@ -1,5 +1,7 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.fortls', '.git' } + return { default_config = { cmd = { @@ -10,9 +12,7 @@ return { '--use_signature_help', }, filetypes = { 'fortran' }, - root_dir = function(fname) - return util.root_pattern '.fortls'(fname) or util.find_git_ancestor(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), settings = {}, }, docs = { @@ -30,7 +30,7 @@ a local configuration file e.g. `.fortls`. For more information see the `fortls` [documentation](https://gnikit.github.io/fortls/options.html). ]], default_config = { - root_dir = [[root_pattern(".fortls")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/ghdl_ls.lua b/lua/lspconfig/server_configurations/ghdl_ls.lua index 0f9e118689..f48d0be794 100644 --- a/lua/lspconfig/server_configurations/ghdl_ls.lua +++ b/lua/lspconfig/server_configurations/ghdl_ls.lua @@ -1,12 +1,11 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'hdl-prj.json', '.git' } return { default_config = { cmd = { 'ghdl-ls' }, filetypes = { 'vhdl' }, - root_dir = function(fname) - return util.root_pattern 'hdl-prj.json'(fname) or util.find_git_ancestor(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { @@ -18,5 +17,6 @@ A language server for VHDL, using ghdl as its backend. `ghdl-ls` is part of pyghdl, for installation instructions see [the upstream README](https://github.com/ghdl/ghdl/tree/master/pyGHDL/lsp). ]], + workspace_markers = workspace_markers, }, } diff --git a/lua/lspconfig/server_configurations/groovyls.lua b/lua/lspconfig/server_configurations/groovyls.lua index b4182f4a3f..1ac67ca0d4 100644 --- a/lua/lspconfig/server_configurations/groovyls.lua +++ b/lua/lspconfig/server_configurations/groovyls.lua @@ -1,5 +1,7 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'Jenkinsfile', '.git' } + return { default_config = { cmd = { @@ -8,9 +10,7 @@ return { 'groovy-language-server-all.jar', }, filetypes = { 'groovy' }, - root_dir = function(fname) - return util.root_pattern 'Jenkinsfile'(fname) or util.find_git_ancestor(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -32,5 +32,6 @@ require'lspconfig'.groovyls.setup{ } ``` ]], + workspace_markers = workspace_markers, }, } diff --git a/lua/lspconfig/server_configurations/jsonnet_ls.lua b/lua/lspconfig/server_configurations/jsonnet_ls.lua index 64e86cbd9c..3a73b70fc2 100644 --- a/lua/lspconfig/server_configurations/jsonnet_ls.lua +++ b/lua/lspconfig/server_configurations/jsonnet_ls.lua @@ -9,13 +9,13 @@ local function jsonnet_path(root_dir) return table.concat(paths, ':') end +local workspace_markers = { 'jsonnetfile.json', '.git' } + return { default_config = { cmd = { 'jsonnet-language-server' }, filetypes = { 'jsonnet', 'libsonnet' }, - root_dir = function(fname) - return util.root_pattern 'jsonnetfile.json'(fname) or util.find_git_ancestor(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), on_new_config = function(new_config, root_dir) if not new_config.cmd_env then new_config.cmd_env = {} @@ -37,7 +37,7 @@ go install github.com/grafana/jsonnet-language-server@latest ``` ]], default_config = { - root_dir = [[root_pattern("jsonnetfile.json")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/julials.lua b/lua/lspconfig/server_configurations/julials.lua index 44360c71ac..2a82c49a6c 100644 --- a/lua/lspconfig/server_configurations/julials.lua +++ b/lua/lspconfig/server_configurations/julials.lua @@ -40,13 +40,13 @@ local cmd = { ]], } +local workspace_markers = { 'Project.toml', '.git' } + return { default_config = { cmd = cmd, filetypes = { 'julia' }, - root_dir = function(fname) - return util.root_pattern 'Project.toml'(fname) or util.find_git_ancestor(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { @@ -71,5 +71,6 @@ Julia project, you must make sure that the project is instantiated: julia --project=/path/to/my/project -e 'using Pkg; Pkg.instantiate()' ``` ]], + workspace_markers = workspace_markers, }, } diff --git a/lua/lspconfig/server_configurations/marksman.lua b/lua/lspconfig/server_configurations/marksman.lua index 113cb1e39f..fa3222ea5c 100644 --- a/lua/lspconfig/server_configurations/marksman.lua +++ b/lua/lspconfig/server_configurations/marksman.lua @@ -3,14 +3,13 @@ local util = require 'lspconfig.util' local bin_name = 'marksman' local cmd = { bin_name, 'server' } +local workspace_markers = { '.marksman.toml', '.git' } + return { default_config = { cmd = cmd, filetypes = { 'markdown' }, - root_dir = function(fname) - local root_files = { '.marksman.toml' } - return util.root_pattern(unpack(root_files))(fname) or util.find_git_ancestor(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { @@ -24,7 +23,7 @@ Marksman works on MacOS, Linux, and Windows and is distributed as a self-contain Pre-built binaries can be downloaded from https://github.com/artempyanykh/marksman/releases ]], default_config = { - root_dir = [[root_pattern(".git", ".marksman.toml")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/mint.lua b/lua/lspconfig/server_configurations/mint.lua index 7fde1c406e..2b7f708395 100644 --- a/lua/lspconfig/server_configurations/mint.lua +++ b/lua/lspconfig/server_configurations/mint.lua @@ -1,15 +1,16 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'mint.json', '.git' } + return { default_config = { cmd = { 'mint', 'ls' }, filetypes = { 'mint' }, - root_dir = function(fname) - return util.root_pattern 'mint.json'(fname) or util.find_git_ancestor(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { + workspace_markers = workspace_markers, description = [[ https://www.mint-lang.com diff --git a/lua/lspconfig/server_configurations/mlir_pdll_lsp_server.lua b/lua/lspconfig/server_configurations/mlir_pdll_lsp_server.lua index e24d634fb2..1ab4e700ff 100644 --- a/lua/lspconfig/server_configurations/mlir_pdll_lsp_server.lua +++ b/lua/lspconfig/server_configurations/mlir_pdll_lsp_server.lua @@ -1,12 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'pdll_compile_commands.yml', '.git' } + return { default_config = { cmd = { 'mlir-pdll-lsp-server' }, filetypes = { 'pdll' }, - root_dir = function(fname) - return util.root_pattern 'pdll_compile_commands.yml'(fname) or util.find_git_ancestor(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -16,5 +16,6 @@ The Language Server for the LLVM PDLL language `mlir-pdll-lsp-server` can be installed at the llvm-project repository (https://github.com/llvm/llvm-project) ]], + workspace_markers = workspace_markers, }, } diff --git a/lua/lspconfig/server_configurations/nimls.lua b/lua/lspconfig/server_configurations/nimls.lua index 3c1aeb2bed..a56da0e8fe 100644 --- a/lua/lspconfig/server_configurations/nimls.lua +++ b/lua/lspconfig/server_configurations/nimls.lua @@ -1,12 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '*.nimble', '.git' } + return { default_config = { cmd = { 'nimlsp' }, filetypes = { 'nim' }, - root_dir = function(fname) - return util.root_pattern '*.nimble'(fname) or util.find_git_ancestor(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { @@ -19,5 +19,6 @@ https://github.com/PMunch/nimlsp nimble install nimlsp ``` ]], + workspace_markers = workspace_markers, }, } diff --git a/lua/lspconfig/server_configurations/pylsp.lua b/lua/lspconfig/server_configurations/pylsp.lua index d76b2ea331..2117913864 100644 --- a/lua/lspconfig/server_configurations/pylsp.lua +++ b/lua/lspconfig/server_configurations/pylsp.lua @@ -1,19 +1,18 @@ local util = require 'lspconfig.util' +local workspace_markers = { + 'pyproject.toml', + 'setup.py', + 'setup.cfg', + 'requirements.txt', + 'Pipfile', + '.git', +} return { default_config = { cmd = { 'pylsp' }, filetypes = { 'python' }, - root_dir = function(fname) - local root_files = { - 'pyproject.toml', - 'setup.py', - 'setup.cfg', - 'requirements.txt', - 'Pipfile', - } - return util.root_pattern(unpack(root_files))(fname) or util.find_git_ancestor(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { @@ -44,5 +43,6 @@ require'lspconfig'.pylsp.setup{ Note: This is a community fork of `pyls`. ]], + workspace_markers = workspace_markers, }, } diff --git a/lua/lspconfig/server_configurations/robotframework_ls.lua b/lua/lspconfig/server_configurations/robotframework_ls.lua index 7cb772b723..699f1f7376 100644 --- a/lua/lspconfig/server_configurations/robotframework_ls.lua +++ b/lua/lspconfig/server_configurations/robotframework_ls.lua @@ -1,12 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'robotidy.toml', 'pyproject.toml', '.git' } + return { default_config = { cmd = { 'robotframework_ls' }, filetypes = { 'robot' }, - root_dir = function(fname) - return util.root_pattern('robotidy.toml', 'pyproject.toml')(fname) or util.find_git_ancestor(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -15,7 +15,7 @@ https://github.com/robocorp/robotframework-lsp Language Server Protocol implementation for Robot Framework. ]], default_config = { - root_dir = "util.root_pattern('robotidy.toml', 'pyproject.toml')(fname) or util.find_git_ancestor(fname)", + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/scry.lua b/lua/lspconfig/server_configurations/scry.lua index 8350a439b9..6729149bcc 100644 --- a/lua/lspconfig/server_configurations/scry.lua +++ b/lua/lspconfig/server_configurations/scry.lua @@ -1,12 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'shard.yml', '.git' } + return { default_config = { cmd = { 'scry' }, filetypes = { 'crystal' }, - root_dir = function(fname) - return util.root_pattern 'shard.yml'(fname) or util.find_git_ancestor(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { @@ -16,7 +16,7 @@ https://github.com/crystal-lang-tools/scry Crystal language server. ]], default_config = { - root_dir = [[root_pattern('shard.yml', '.git')]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/sourcery.lua b/lua/lspconfig/server_configurations/sourcery.lua index bde18a15d9..5f6d465995 100644 --- a/lua/lspconfig/server_configurations/sourcery.lua +++ b/lua/lspconfig/server_configurations/sourcery.lua @@ -1,12 +1,13 @@ local util = require 'lspconfig.util' -local root_files = { +local workspace_markers = { 'pyproject.toml', 'setup.py', 'setup.cfg', 'requirements.txt', 'Pipfile', 'pyrightconfig.json', + '.git', } local token_in_auth_file = function() @@ -32,14 +33,13 @@ return { default_config = { cmd = { 'sourcery', 'lsp' }, filetypes = { 'python' }, + workspace_markers = workspace_markers, init_options = { editor_version = 'vim', extension_version = 'vim.lsp', token = nil, }, - root_dir = function(fname) - return util.root_pattern(unpack(root_files))(fname) or util.find_git_ancestor(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, on_new_config = function(new_config, _) @@ -79,5 +79,6 @@ require'lspconfig'.sourcery.setup { Alternatively, you can login to sourcery by running `sourcery login` with sourcery-cli. ]], + workspace_markers = workspace_markers, }, } diff --git a/lua/lspconfig/server_configurations/svlangserver.lua b/lua/lspconfig/server_configurations/svlangserver.lua index 72eef65bec..87665e17b1 100644 --- a/lua/lspconfig/server_configurations/svlangserver.lua +++ b/lua/lspconfig/server_configurations/svlangserver.lua @@ -22,13 +22,13 @@ local function report_hierarchy() vim.lsp.buf.execute_command(params) end +local workspace_markers = { '.svlangserver', '.git' } + return { default_config = { cmd = cmd, filetypes = { 'verilog', 'systemverilog' }, - root_dir = function(fname) - return util.root_pattern '.svlangserver'(fname) or util.find_git_ancestor(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, settings = { systemverilog = { @@ -59,7 +59,7 @@ $ npm install -g @imc-trading/svlangserver ``` ]], default_config = { - root_dir = [[root_pattern(".svlangserver", ".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/taplo.lua b/lua/lspconfig/server_configurations/taplo.lua index e1a9353046..0abf3332b4 100644 --- a/lua/lspconfig/server_configurations/taplo.lua +++ b/lua/lspconfig/server_configurations/taplo.lua @@ -1,12 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { '*.toml', '.git' } + return { default_config = { cmd = { 'taplo', 'lsp', 'stdio' }, filetypes = { 'toml' }, - root_dir = function(fname) - return util.root_pattern '*.toml'(fname) or util.find_git_ancestor(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { @@ -21,7 +21,7 @@ cargo install --features lsp --locked taplo-cli ``` ]], default_config = { - root_dir = [[root_pattern("*.toml", ".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/tblgen_lsp_server.lua b/lua/lspconfig/server_configurations/tblgen_lsp_server.lua index 73022d4a28..73fc111e95 100644 --- a/lua/lspconfig/server_configurations/tblgen_lsp_server.lua +++ b/lua/lspconfig/server_configurations/tblgen_lsp_server.lua @@ -1,12 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'tablegen_compile_commands.yml', '.git' } + return { default_config = { cmd = { 'tblgen-lsp-server' }, filetypes = { 'tablegen' }, - root_dir = function(fname) - return util.root_pattern 'tablegen_compile_commands.yml'(fname) or util.find_git_ancestor(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -16,5 +16,6 @@ The Language Server for the LLVM TableGen language `tblgen-lsp-server` can be installed at the llvm-project repository (https://github.com/llvm/llvm-project) ]], + workspace_markers = workspace_markers, }, } diff --git a/lua/lspconfig/server_configurations/texlab.lua b/lua/lspconfig/server_configurations/texlab.lua index 6eb9d99a7d..d306df0537 100644 --- a/lua/lspconfig/server_configurations/texlab.lua +++ b/lua/lspconfig/server_configurations/texlab.lua @@ -63,13 +63,13 @@ end -- end) -- end +local workspace_markers = { '.latexmkrc', '.git' } + return { default_config = { cmd = { 'texlab' }, filetypes = { 'tex', 'plaintex', 'bib' }, - root_dir = function(fname) - return util.root_pattern '.latexmkrc'(fname) or util.find_git_ancestor(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, settings = { texlab = { @@ -122,5 +122,6 @@ A completion engine built from scratch for (La)TeX. See https://github.com/latex-lsp/texlab/wiki/Configuration for configuration options. ]], + workspace_markers = workspace_markers, }, } From 7e2984e8a409094c4a9bf40b5a2f3ac8cced35ad Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Thu, 10 Nov 2022 14:46:43 +0100 Subject: [PATCH 06/11] refactor: export ws markers - 5 --- .../anakin_language_server.lua | 19 +++++++++--------- lua/lspconfig/server_configurations/bufls.lua | 8 ++++---- lua/lspconfig/server_configurations/cmake.lua | 9 ++++----- .../server_configurations/cssmodules_ls.lua | 6 ++++-- lua/lspconfig/server_configurations/dafny.lua | 7 ++++--- .../server_configurations/dagger.lua | 8 ++++---- .../golangci_lint_ls.lua | 9 +++++---- lua/lspconfig/server_configurations/gopls.lua | 8 ++++---- .../server_configurations/intelephense.lua | 6 ++++-- .../jedi_language_server.lua | 6 +++--- .../server_configurations/lean3ls.lua | 10 +++++----- .../server_configurations/leanls.lua | 8 ++++---- .../server_configurations/millet.lua | 5 ++++- .../server_configurations/move_analyzer.lua | 9 ++++----- .../server_configurations/neocmake.lua | 8 +++----- .../server_configurations/omnisharp.lua | 8 ++++---- lua/lspconfig/server_configurations/phan.lua | 7 +++++-- .../server_configurations/phpactor.lua | 6 ++++-- .../server_configurations/puppet.lua | 6 +++--- .../server_configurations/pyright.lua | 5 +++-- lua/lspconfig/server_configurations/qmlls.lua | 6 +++--- lua/lspconfig/server_configurations/rome.lua | 10 ++++------ .../server_configurations/syntax_tree.lua | 8 ++++---- .../server_configurations/tailwindcss.lua | 20 +++++++++++-------- .../server_configurations/vala_ls.lua | 9 ++++----- 25 files changed, 111 insertions(+), 100 deletions(-) diff --git a/lua/lspconfig/server_configurations/anakin_language_server.lua b/lua/lspconfig/server_configurations/anakin_language_server.lua index f0c281cc56..d2c638b643 100644 --- a/lua/lspconfig/server_configurations/anakin_language_server.lua +++ b/lua/lspconfig/server_configurations/anakin_language_server.lua @@ -1,19 +1,17 @@ local util = require 'lspconfig.util' +local workspace_markers = { + 'pyproject.toml', + 'setup.py', + 'setup.cfg', + 'requirements.txt', + 'Pipfile', +} return { default_config = { cmd = { 'anakinls' }, filetypes = { 'python' }, - root_dir = function(fname) - local root_files = { - 'pyproject.toml', - 'setup.py', - 'setup.cfg', - 'requirements.txt', - 'Pipfile', - } - return util.root_pattern(unpack(root_files))(fname) or util.find_git_ancestor(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, settings = { anakinls = { @@ -74,5 +72,6 @@ Available options: * Initialization: https://github.com/muffinmad/anakin-language-server#initialization-option * Configuration: https://github.com/muffinmad/anakin-language-server#configuration-options ]], + workspace_markers = workspace_markers, }, } diff --git a/lua/lspconfig/server_configurations/bufls.lua b/lua/lspconfig/server_configurations/bufls.lua index aa25b4c0e5..a63a8cd394 100644 --- a/lua/lspconfig/server_configurations/bufls.lua +++ b/lua/lspconfig/server_configurations/bufls.lua @@ -7,13 +7,13 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, 'start' } end +local workspace_markers = { 'buf.work.yaml', '.git' } + return { default_config = { cmd = cmd, filetypes = { 'proto' }, - root_dir = function(fname) - return util.root_pattern('buf.work.yaml', '.git')(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -27,7 +27,7 @@ go install github.com/bufbuild/buf-language-server/cmd/bufls@latest bufls is a Protobuf language server compatible with Buf modules and workspaces ]], default_config = { - root_dir = [[root_pattern("buf.work.yaml", ".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/cmake.lua b/lua/lspconfig/server_configurations/cmake.lua index 7f27fea0b1..a9224cae05 100644 --- a/lua/lspconfig/server_configurations/cmake.lua +++ b/lua/lspconfig/server_configurations/cmake.lua @@ -1,13 +1,12 @@ local util = require 'lspconfig.util' -local root_files = { 'CMakePresets.json', 'CTestConfig.cmake', '.git', 'build', 'cmake' } +local workspace_markers = { 'CMakePresets.json', 'CTestConfig.cmake', '.git', 'build', 'cmake' } + return { default_config = { cmd = { 'cmake-language-server' }, filetypes = { 'cmake' }, - root_dir = function(fname) - return util.root_pattern(unpack(root_files))(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, init_options = { buildDirectory = 'build', @@ -20,7 +19,7 @@ https://github.com/regen100/cmake-language-server CMake LSP Implementation ]], default_config = { - root_dir = [[root_pattern('CMakePresets.json', 'CTestConfig.cmake', '.git', 'build', 'cmake')]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/cssmodules_ls.lua b/lua/lspconfig/server_configurations/cssmodules_ls.lua index 3107b75d3b..83a4fdf8d8 100644 --- a/lua/lspconfig/server_configurations/cssmodules_ls.lua +++ b/lua/lspconfig/server_configurations/cssmodules_ls.lua @@ -7,11 +7,13 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name } end +local workspace_markers = { 'package.json' } + return { default_config = { cmd = cmd, filetypes = { 'javascript', 'javascriptreact', 'typescript', 'typescriptreact' }, - root_dir = util.find_package_json_ancestor, + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -25,7 +27,7 @@ npm install -g cssmodules-language-server ``` ]], default_config = { - root_dir = [[root_pattern("package.json")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/dafny.lua b/lua/lspconfig/server_configurations/dafny.lua index cbd4bbed49..0f5787d332 100644 --- a/lua/lspconfig/server_configurations/dafny.lua +++ b/lua/lspconfig/server_configurations/dafny.lua @@ -1,11 +1,11 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } + return { default_config = { filetypes = { 'dfy', 'dafny' }, - root_dir = function(fname) - util.find_git_ancestor(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { @@ -16,5 +16,6 @@ return { Note that there is no default cmd set. You must set it yourself. The recommended way is to use `{"dotnet", ""}`. ]], + workspace_markers = workspace_markers, }, } diff --git a/lua/lspconfig/server_configurations/dagger.lua b/lua/lspconfig/server_configurations/dagger.lua index 734249fa85..539258cce1 100644 --- a/lua/lspconfig/server_configurations/dagger.lua +++ b/lua/lspconfig/server_configurations/dagger.lua @@ -1,12 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'cue.mod', '.git' } + return { default_config = { cmd = { 'cuelsp' }, filetypes = { 'cue' }, - root_dir = function(fname) - return util.root_pattern('cue.mod', '.git')(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { @@ -16,7 +16,7 @@ https://github.com/dagger/cuelsp Dagger's lsp server for cuelang. ]], default_config = { - root_dir = [[root_pattern("cue.mod", ".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/golangci_lint_ls.lua b/lua/lspconfig/server_configurations/golangci_lint_ls.lua index 21ed58f387..4f42a3c9b4 100644 --- a/lua/lspconfig/server_configurations/golangci_lint_ls.lua +++ b/lua/lspconfig/server_configurations/golangci_lint_ls.lua @@ -1,15 +1,16 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'go.work', 'go.mod', '.golangci.yaml', '.git' } + return { default_config = { cmd = { 'golangci-lint-langserver' }, filetypes = { 'go', 'gomod' }, + workspace_markers = workspace_markers, init_options = { command = { 'golangci-lint', 'run', '--out-format', 'json' }, }, - root_dir = function(fname) - return util.root_pattern 'go.work'(fname) or util.root_pattern('go.mod', '.golangci.yaml', '.git')(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -28,7 +29,7 @@ go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest ]], default_config = { - root_dir = [[root_pattern('go.work') or root_pattern('go.mod', '.golangci.yaml', '.git')]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/gopls.lua b/lua/lspconfig/server_configurations/gopls.lua index 8e899d4372..3aa0fac343 100644 --- a/lua/lspconfig/server_configurations/gopls.lua +++ b/lua/lspconfig/server_configurations/gopls.lua @@ -1,12 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'go.work', 'go.mod', '.git' } + return { default_config = { cmd = { 'gopls' }, filetypes = { 'go', 'gomod', 'gowork', 'gotmpl' }, - root_dir = function(fname) - return util.root_pattern 'go.work'(fname) or util.root_pattern('go.mod', '.git')(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { @@ -16,7 +16,7 @@ https://github.com/golang/tools/tree/master/gopls Google's lsp server for golang. ]], default_config = { - root_dir = [[root_pattern("go.mod", ".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/intelephense.lua b/lua/lspconfig/server_configurations/intelephense.lua index c9e35b9ddc..cb60dd815a 100644 --- a/lua/lspconfig/server_configurations/intelephense.lua +++ b/lua/lspconfig/server_configurations/intelephense.lua @@ -7,13 +7,15 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, '--stdio' } end +local workspace_markers = { 'composer.json', '.git' } + return { default_config = { cmd = cmd, filetypes = { 'php' }, root_dir = function(pattern) local cwd = vim.loop.cwd() - local root = util.root_pattern('composer.json', '.git')(pattern) + local root = util.root_pattern(unpack(workspace_markers))(pattern) -- prefer cwd if root is a descendant return util.path.is_descendant(cwd, root) and cwd or root @@ -29,7 +31,7 @@ npm install -g intelephense ``` ]], default_config = { - root_dir = [[root_pattern("composer.json", ".git")]], + workspace_markers = workspace_markers, init_options = [[{ storagePath = Optional absolute path to storage dir. Defaults to os.tmpdir(). globalStoragePath = Optional absolute path to a global storage dir. Defaults to os.homedir(). diff --git a/lua/lspconfig/server_configurations/jedi_language_server.lua b/lua/lspconfig/server_configurations/jedi_language_server.lua index 30cf8f506b..16d321c93b 100644 --- a/lua/lspconfig/server_configurations/jedi_language_server.lua +++ b/lua/lspconfig/server_configurations/jedi_language_server.lua @@ -1,6 +1,6 @@ local util = require 'lspconfig.util' -local root_files = { +local workspace_markers = { 'pyproject.toml', 'setup.py', 'setup.cfg', @@ -12,7 +12,7 @@ return { default_config = { cmd = { 'jedi-language-server' }, filetypes = { 'python' }, - root_dir = util.root_pattern(unpack(root_files)), + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { @@ -22,7 +22,7 @@ https://github.com/pappasam/jedi-language-server `jedi-language-server`, a language server for Python, built on top of jedi ]], default_config = { - root_dir = "vim's starting directory", + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/lean3ls.lua b/lua/lspconfig/server_configurations/lean3ls.lua index b35a6932bc..bbb3a1ec00 100644 --- a/lua/lspconfig/server_configurations/lean3ls.lua +++ b/lua/lspconfig/server_configurations/lean3ls.lua @@ -8,10 +8,13 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, unpack(args) } end +local workspace_markers = { 'leanpkg.toml', 'leanpkg.path' } + return { default_config = { cmd = cmd, filetypes = { 'lean3' }, + workspace_markers = workspace_markers, offset_encoding = 'utf-32', root_dir = function(fname) fname = util.path.sanitize(fname) @@ -24,10 +27,7 @@ return { end end - return util.root_pattern 'leanpkg.toml'(fname) - or util.root_pattern 'leanpkg.path'(fname) - or stdlib_dir - or util.find_git_ancestor(fname) + return util.root_pattern(unpack(workspace_markers))(fname) or stdlib_dir or util.find_git_ancestor(fname) end, single_file_support = true, }, @@ -48,7 +48,7 @@ that plugin fully handles the setup of the Lean language server, and you shouldn't set up `lean3ls` both with it and `lspconfig`. ]], default_config = { - root_dir = [[root_pattern("leanpkg.toml") or root_pattern(".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/leanls.lua b/lua/lspconfig/server_configurations/leanls.lua index 208598af95..4fd0ac23d2 100644 --- a/lua/lspconfig/server_configurations/leanls.lua +++ b/lua/lspconfig/server_configurations/leanls.lua @@ -1,5 +1,7 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'lakefile.lean', 'lean-toolchain', 'leanpkg.toml' } + return { default_config = { cmd = { 'lake', 'serve', '--' }, @@ -21,9 +23,7 @@ return { end end - return util.root_pattern('lakefile.lean', 'lean-toolchain', 'leanpkg.toml')(fname) - or stdlib_dir - or util.find_git_ancestor(fname) + return util.root_pattern(unpack(workspace_markers))(fname) or stdlib_dir or util.find_git_ancestor(fname) end, options = { -- Only Lake 3.0+ supports lake serve, so for old enough Lean 4, @@ -71,7 +71,7 @@ that plugin fully handles the setup of the Lean language server, and you shouldn't set up `leanls` both with it and `lspconfig`. ]], default_config = { - root_dir = [[root_pattern("lakefile.lean", "lean-toolchain", "leanpkg.toml", ".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/millet.lua b/lua/lspconfig/server_configurations/millet.lua index 0b7d29949f..ff4cba5535 100644 --- a/lua/lspconfig/server_configurations/millet.lua +++ b/lua/lspconfig/server_configurations/millet.lua @@ -1,10 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'millet.toml' } + return { default_config = { cmd = { 'millet' }, filetypes = { 'sml' }, - root_dir = util.root_pattern 'millet.toml', + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -19,5 +21,6 @@ To use with nvim: 3. Run `cargo build --release --bin lang-srv` 4. Move `target/release/lang-srv` to somewhere on your $PATH as `millet` ]], + workspace_markers = workspace_markers, }, } diff --git a/lua/lspconfig/server_configurations/move_analyzer.lua b/lua/lspconfig/server_configurations/move_analyzer.lua index ab9774577c..8fb78dc569 100644 --- a/lua/lspconfig/server_configurations/move_analyzer.lua +++ b/lua/lspconfig/server_configurations/move_analyzer.lua @@ -1,13 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'Move.toml' } + return { default_config = { cmd = { 'move-analyzer' }, filetypes = { 'move' }, - root_dir = function(fname) - local move_package_dir = util.root_pattern 'Move.toml'(fname) - return move_package_dir - end, + root_dir = util.root_pattern(unpack(workspace_markers)), }, commands = {}, docs = { @@ -25,7 +24,7 @@ cargo install --git https://github.com/move-language/move move-analyzer See [`move-analyzer`'s doc](https://github.com/move-language/move/blob/1b258a06e3c7d2bc9174578aac92cca3ac19de71/language/move-analyzer/editors/code/README.md#how-to-install) for details. ]], default_config = { - root_dir = [[root_pattern("Move.toml")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/neocmake.lua b/lua/lspconfig/server_configurations/neocmake.lua index 3839bdbbc3..7e60a8b6c2 100644 --- a/lua/lspconfig/server_configurations/neocmake.lua +++ b/lua/lspconfig/server_configurations/neocmake.lua @@ -1,13 +1,11 @@ local util = require 'lspconfig.util' -local root_files = { '.git', 'build', 'cmake' } +local workspace_markers = { '.git', 'build', 'cmake' } return { default_config = { cmd = { 'neocmakelsp', '--stdio' }, filetypes = { 'cmake' }, - root_dir = function(fname) - return util.root_pattern(unpack(root_files))(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { @@ -17,7 +15,7 @@ https://github.com/Decodetalkers/neocmakelsp CMake LSP Implementation ]], default_config = { - root_dir = [[root_pattern('.git', 'cmake')]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/omnisharp.lua b/lua/lspconfig/server_configurations/omnisharp.lua index 0ad8b6a190..685dd49676 100644 --- a/lua/lspconfig/server_configurations/omnisharp.lua +++ b/lua/lspconfig/server_configurations/omnisharp.lua @@ -1,5 +1,7 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.sln', '.csproj' } + return { default_config = { -- Enables support for reading code style, naming convention and analyzer @@ -38,9 +40,7 @@ return { analyze_open_documents_only = false, filetypes = { 'cs', 'vb' }, - root_dir = function(fname) - return util.root_pattern '*.sln'(fname) or util.root_pattern '*.csproj'(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), on_new_config = function(new_config, new_root_dir) table.insert(new_config.cmd, '-z') -- https://github.com/OmniSharp/omnisharp-vscode/pull/4300 vim.list_extend(new_config.cmd, { '-s', new_root_dir }) @@ -133,7 +133,7 @@ require'lspconfig'.omnisharp.setup { ``` ]], default_config = { - root_dir = [[root_pattern(".sln") or root_pattern(".csproj")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/phan.lua b/lua/lspconfig/server_configurations/phan.lua index bb5242e62e..d2d17e59c2 100644 --- a/lua/lspconfig/server_configurations/phan.lua +++ b/lua/lspconfig/server_configurations/phan.lua @@ -13,14 +13,17 @@ local cmd = { '--allow-polyfill-parser', } +local workspace_markers = { 'composer.json', '.git' } + return { default_config = { cmd = cmd, filetypes = { 'php' }, + workspace_markers = workspace_markers, single_file_support = true, root_dir = function(pattern) local cwd = vim.loop.cwd() - local root = util.root_pattern('composer.json', '.git')(pattern) + local root = util.root_pattern(unpack(workspace_markers))(pattern) -- prefer cwd if root is a descendant return util.path.is_descendant(cwd, root) and cwd or root @@ -34,7 +37,7 @@ Installation: https://github.com/phan/phan#getting-started ]], default_config = { cmd = cmd, - root_dir = [[root_pattern("composer.json", ".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/phpactor.lua b/lua/lspconfig/server_configurations/phpactor.lua index 5a1f0d10eb..679bd0eba8 100644 --- a/lua/lspconfig/server_configurations/phpactor.lua +++ b/lua/lspconfig/server_configurations/phpactor.lua @@ -1,12 +1,14 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'composer.json', '.git' } + return { default_config = { cmd = { 'phpactor', 'language-server' }, filetypes = { 'php' }, root_dir = function(pattern) local cwd = vim.loop.cwd() - local root = util.root_pattern('composer.json', '.git')(pattern) + local root = util.root_pattern(unpack(workspace_markers))(pattern) -- prefer cwd if root is a descendant return util.path.is_descendant(cwd, root) and cwd or root @@ -20,7 +22,7 @@ Installation: https://phpactor.readthedocs.io/en/master/usage/standalone.html#gl ]], default_config = { cmd = { 'phpactor', 'language-server' }, - root_dir = [[root_pattern("composer.json", ".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/puppet.lua b/lua/lspconfig/server_configurations/puppet.lua index 18a1532cca..42a8664a45 100644 --- a/lua/lspconfig/server_configurations/puppet.lua +++ b/lua/lspconfig/server_configurations/puppet.lua @@ -1,6 +1,6 @@ local util = require 'lspconfig.util' -local root_files = { +local workspace_markers = { 'manifests', '.puppet-lint.rc', 'hiera.yaml', @@ -11,7 +11,7 @@ return { default_config = { cmd = { 'puppet-languageserver', '--stdio' }, filetypes = { 'puppet' }, - root_dir = util.root_pattern(unpack(root_files)), + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { @@ -32,7 +32,7 @@ Installation: - Ensure you can run `puppet-languageserver` from outside the editor-services directory. ]], default_config = { - root_dir = [[root_pattern("manifests", ".puppet-lint.rc", "hiera.yaml", ".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/pyright.lua b/lua/lspconfig/server_configurations/pyright.lua index a198477f4c..5046abe6c8 100644 --- a/lua/lspconfig/server_configurations/pyright.lua +++ b/lua/lspconfig/server_configurations/pyright.lua @@ -7,7 +7,7 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, '--stdio' } end -local root_files = { +local workspace_markers = { 'pyproject.toml', 'setup.py', 'setup.cfg', @@ -28,7 +28,7 @@ return { default_config = { cmd = cmd, filetypes = { 'python' }, - root_dir = util.root_pattern(unpack(root_files)), + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, settings = { python = { @@ -52,5 +52,6 @@ https://github.com/microsoft/pyright `pyright`, a static type checker and language server for python ]], + workspace_markers = workspace_markers, }, } diff --git a/lua/lspconfig/server_configurations/qmlls.lua b/lua/lspconfig/server_configurations/qmlls.lua index e5a9006589..fcd72d8c7a 100644 --- a/lua/lspconfig/server_configurations/qmlls.lua +++ b/lua/lspconfig/server_configurations/qmlls.lua @@ -1,12 +1,11 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } return { default_config = { cmd = { 'qmlls' }, filetypes = { 'qmljs' }, - root_dir = function(fname) - return util.find_git_ancestor(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { @@ -15,5 +14,6 @@ https://github.com/qt/qtdeclarative LSP implementation for QML (autocompletion, live linting, etc. in editors), ]], + workspace_markers = workspace_markers, }, } diff --git a/lua/lspconfig/server_configurations/rome.lua b/lua/lspconfig/server_configurations/rome.lua index 1e426a7fea..fb0cc250bf 100644 --- a/lua/lspconfig/server_configurations/rome.lua +++ b/lua/lspconfig/server_configurations/rome.lua @@ -7,6 +7,8 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, 'lsp-proxy' } end +local workspace_markers = { 'package.json', 'node_modules', '.git' } + return { default_config = { cmd = cmd, @@ -18,11 +20,7 @@ return { 'typescript.tsx', 'typescriptreact', }, - root_dir = function(fname) - return util.find_package_json_ancestor(fname) - or util.find_node_modules_ancestor(fname) - or util.find_git_ancestor(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { @@ -36,7 +34,7 @@ npm install [-g] rome ``` ]], default_config = { - root_dir = [[root_pattern('package.json', 'node_modules', '.git')]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/syntax_tree.lua b/lua/lspconfig/server_configurations/syntax_tree.lua index 13f8df8995..fe76164983 100644 --- a/lua/lspconfig/server_configurations/syntax_tree.lua +++ b/lua/lspconfig/server_configurations/syntax_tree.lua @@ -7,13 +7,13 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, 'lsp' } end +local workspace_markers = { '.streerc', 'Gemfile', '.git' } + return { default_config = { cmd = cmd, filetypes = { 'ruby' }, - root_dir = function(fname) - return util.root_pattern '.streerc'(fname) or util.root_pattern('Gemfile', '.git')(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -31,7 +31,7 @@ gem install syntax_tree ``` ]], default_config = { - root_dir = [[root_pattern(".streerc", "Gemfile", ".git")]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/tailwindcss.lua b/lua/lspconfig/server_configurations/tailwindcss.lua index 9247a1fdb7..64f4e61dd3 100644 --- a/lua/lspconfig/server_configurations/tailwindcss.lua +++ b/lua/lspconfig/server_configurations/tailwindcss.lua @@ -7,6 +7,16 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, '--stdio' } end +local workspace_markers = { + 'tailwind.config.js', + 'tailwind.config.ts', + 'postcss.config.js', + 'postcss.config.ts', + 'package.json', + 'node_modules', + '.git', +} + return { default_config = { cmd = cmd, @@ -103,13 +113,7 @@ return { new_config.settings.editor.tabSize = vim.lsp.util.get_effective_tabstop() end end, - root_dir = function(fname) - return util.root_pattern('tailwind.config.js', 'tailwind.config.ts')(fname) - or util.root_pattern('postcss.config.js', 'postcss.config.ts')(fname) - or util.find_package_json_ancestor(fname) - or util.find_node_modules_ancestor(fname) - or util.find_git_ancestor(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), }, docs = { description = [[ @@ -121,7 +125,7 @@ npm install -g @tailwindcss/language-server ``` ]], default_config = { - root_dir = [[root_pattern('tailwind.config.js', 'tailwind.config.ts', 'postcss.config.js', 'postcss.config.ts', 'package.json', 'node_modules', '.git')]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/vala_ls.lua b/lua/lspconfig/server_configurations/vala_ls.lua index 842c561d41..931bd58127 100644 --- a/lua/lspconfig/server_configurations/vala_ls.lua +++ b/lua/lspconfig/server_configurations/vala_ls.lua @@ -21,20 +21,19 @@ local meson_matcher = function(path) end end +local workspace_markers = { 'meson.build', '.git' } + return { default_config = { cmd = { 'vala-language-server' }, filetypes = { 'vala', 'genie' }, - root_dir = function(fname) - local root = util.search_ancestors(fname, meson_matcher) - return root or util.find_git_ancestor(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, }, docs = { description = 'https://github.com/Prince781/vala-language-server', default_config = { - root_dir = [[root_pattern("meson.build", ".git")]], + workspace_markers = workspace_markers, }, }, } From 2408a5cf6643a1820d7b371d91a88290828a7e3c Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Thu, 10 Nov 2022 14:46:43 +0100 Subject: [PATCH 07/11] refactor: export ws markers - 6 --- lua/lspconfig/server_configurations/elixirls.lua | 7 +++++-- lua/lspconfig/server_configurations/r_language_server.lua | 7 +++++-- lua/lspconfig/server_configurations/rnix.lua | 6 ++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lua/lspconfig/server_configurations/elixirls.lua b/lua/lspconfig/server_configurations/elixirls.lua index 1450b3e4af..631ab056d7 100644 --- a/lua/lspconfig/server_configurations/elixirls.lua +++ b/lua/lspconfig/server_configurations/elixirls.lua @@ -1,10 +1,13 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'mix.exs', '.git' } + return { default_config = { filetypes = { 'elixir', 'eelixir', 'heex', 'surface' }, root_dir = function(fname) - return util.root_pattern('mix.exs', '.git')(fname) or vim.loop.os_homedir() + -- FIXME(kylo252): why does this use homedir? + return util.root_pattern(unpack(workspace_markers))(fname) or vim.loop.os_homedir() end, }, docs = { @@ -33,7 +36,7 @@ require'lspconfig'.elixirls.setup{ ``` ]], default_config = { - root_dir = [[root_pattern("mix.exs", ".git") or vim.loop.os_homedir()]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/r_language_server.lua b/lua/lspconfig/server_configurations/r_language_server.lua index 7e1e3f38a2..6a3dfadcd1 100644 --- a/lua/lspconfig/server_configurations/r_language_server.lua +++ b/lua/lspconfig/server_configurations/r_language_server.lua @@ -1,11 +1,14 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } + return { default_config = { cmd = { 'R', '--slave', '-e', 'languageserver::run()' }, filetypes = { 'r', 'rmd' }, root_dir = function(fname) - return util.find_git_ancestor(fname) or vim.loop.os_homedir() + -- FIXME(kylo252): why does this use homedir? + return util.root_pattern(unpack(workspace_markers))(fname) or vim.loop.os_homedir() end, log_level = vim.lsp.protocol.MessageType.Warning, }, @@ -22,7 +25,7 @@ install.packages("languageserver") ``` ]], default_config = { - root_dir = [[root_pattern(".git") or os_homedir]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/rnix.lua b/lua/lspconfig/server_configurations/rnix.lua index aa7f00ed14..da64adc96b 100644 --- a/lua/lspconfig/server_configurations/rnix.lua +++ b/lua/lspconfig/server_configurations/rnix.lua @@ -1,11 +1,13 @@ local util = require 'lspconfig.util' +local workspace_markers = { '.git' } return { default_config = { cmd = { 'rnix-lsp' }, filetypes = { 'nix' }, root_dir = function(fname) - return util.find_git_ancestor(fname) or vim.loop.os_homedir() + -- FIXME(kylo252): why does this use homedir? + return util.root_pattern(unpack(workspace_markers))(fname) or vim.loop.os_homedir() end, settings = {}, init_options = {}, @@ -22,7 +24,7 @@ This server accepts configuration via the `settings` key. ]], default_config = { - root_dir = "vim's starting directory", + workspace_markers = workspace_markers, }, }, } From 84a043e124b43fb06fadcc039ec631af2cd062d1 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Thu, 10 Nov 2022 14:46:43 +0100 Subject: [PATCH 08/11] refactor: export ws markers - 7 --- lua/lspconfig/server_configurations/eslint.lua | 7 ++++--- .../server_configurations/gradle_ls.lua | 13 ++++--------- lua/lspconfig/server_configurations/hls.lua | 18 ++++-------------- .../kotlin_language_server.lua | 15 +++++---------- 4 files changed, 17 insertions(+), 36 deletions(-) diff --git a/lua/lspconfig/server_configurations/eslint.lua b/lua/lspconfig/server_configurations/eslint.lua index 92a44ac46c..f08d262328 100644 --- a/lua/lspconfig/server_configurations/eslint.lua +++ b/lua/lspconfig/server_configurations/eslint.lua @@ -40,7 +40,7 @@ if is_windows then cmd = { 'cmd.exe', '/C', bin_name, '--stdio' } end -local root_file = { +local workspace_markers = { '.eslintrc', '.eslintrc.js', '.eslintrc.cjs', @@ -57,7 +57,7 @@ if root_with_package then local path_sep = is_windows and '\\' or '/' for line in io.lines(root_with_package .. path_sep .. 'package.json') do if line:find 'eslintConfig' then - table.insert(root_file, 'package.json') + table.insert(workspace_markers, 'package.json') break end end @@ -78,7 +78,7 @@ return { 'astro', }, -- https://eslint.org/docs/user-guide/configuring/configuration-files#configuration-file-formats - root_dir = util.root_pattern(unpack(root_file)), + root_dir = util.root_pattern(unpack(workspace_markers)), -- Refer to https://github.com/Microsoft/vscode-eslint#settings-options for documentation. settings = { validate = 'on', @@ -191,5 +191,6 @@ Messages handled in lspconfig: `eslint/openDoc`, `eslint/confirmESLintExecution` Additional messages you can handle: `eslint/noConfig` ]], + workspace_markers = workspace_markers, }, } diff --git a/lua/lspconfig/server_configurations/gradle_ls.lua b/lua/lspconfig/server_configurations/gradle_ls.lua index 47091b2db4..ea62c3037c 100644 --- a/lua/lspconfig/server_configurations/gradle_ls.lua +++ b/lua/lspconfig/server_configurations/gradle_ls.lua @@ -5,20 +5,15 @@ if vim.fn.has 'win32' == 1 then bin_name = bin_name .. '.bat' end -local root_files = { +local workspace_markers = { 'settings.gradle', -- Gradle (multi-project) -} - -local fallback_root_files = { - 'build.gradle', -- Gradle + 'build.gradle', -- Gradle (fallback) } return { default_config = { filetypes = { 'groovy' }, - root_dir = function(fname) - return util.root_pattern(unpack(root_files))(fname) or util.root_pattern(unpack(fallback_root_files))(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), cmd = { bin_name }, -- gradle-language-server expects init_options.settings to be defined init_options = { @@ -36,7 +31,7 @@ Microsoft's lsp server for gradle files If you're setting this up manually, build vscode-gradle using `./gradlew installDist` and point `cmd` to the `gradle-language-server` generated in the build directory ]], default_config = { - root_dir = [[root_pattern("settings.gradle")]], + workspace_markers = workspace_markers, cmd = { 'gradle-language-server' }, init_options = { settings = { diff --git a/lua/lspconfig/server_configurations/hls.lua b/lua/lspconfig/server_configurations/hls.lua index 54b45e9892..85c370fa3c 100644 --- a/lua/lspconfig/server_configurations/hls.lua +++ b/lua/lspconfig/server_configurations/hls.lua @@ -1,15 +1,12 @@ local util = require 'lspconfig.util' +local workspace_markers = { 'hie.yaml', 'stack.yaml', 'cabal.project', '*.cabal', 'package.yaml' } + return { default_config = { cmd = { 'haskell-language-server-wrapper', '--lsp' }, filetypes = { 'haskell', 'lhaskell' }, - root_dir = function(filepath) - return ( - util.root_pattern('hie.yaml', 'stack.yaml', 'cabal.project')(filepath) - or util.root_pattern('*.cabal', 'package.yaml')(filepath) - ) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, settings = { haskell = { @@ -42,14 +39,7 @@ Haskell Language Server ]], default_config = { - root_dir = [[ -function (filepath) - return ( - util.root_pattern('hie.yaml', 'stack.yaml', 'cabal.project')(filepath) - or util.root_pattern('*.cabal', 'package.yaml')(filepath) - ) -end - ]], + workspace_markers = workspace_markers, }, }, } diff --git a/lua/lspconfig/server_configurations/kotlin_language_server.lua b/lua/lspconfig/server_configurations/kotlin_language_server.lua index a955fe6372..8cd54e4a9a 100644 --- a/lua/lspconfig/server_configurations/kotlin_language_server.lua +++ b/lua/lspconfig/server_configurations/kotlin_language_server.lua @@ -10,24 +10,19 @@ end -- These are configuration files for the various build systems supported by -- Kotlin. I am not sure whether the language server supports Ant projects, -- but I'm keeping it here as well since Ant does support Kotlin. -local root_files = { +local workspace_markers = { 'settings.gradle', -- Gradle (multi-project) 'settings.gradle.kts', -- Gradle (multi-project) 'build.xml', -- Ant 'pom.xml', -- Maven -} - -local fallback_root_files = { - 'build.gradle', -- Gradle - 'build.gradle.kts', -- Gradle + 'build.gradle', -- Gradle (fallback) + 'build.gradle.kts', -- Gradle (fallback) } return { default_config = { filetypes = { 'kotlin' }, - root_dir = function(fname) - return util.root_pattern(unpack(root_files))(fname) or util.root_pattern(unpack(fallback_root_files))(fname) - end, + root_dir = util.root_pattern(unpack(workspace_markers)), cmd = { bin_name }, }, docs = { @@ -46,7 +41,7 @@ return { Note that there is no LICENSE specified yet. ]], default_config = { - root_dir = [[root_pattern("settings.gradle")]], + workspace_markers = workspace_markers, cmd = { 'kotlin-language-server' }, capabilities = [[ smart code completion, From 7ff94f5607f8b15e8754205ebb61b74c0e871c40 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Thu, 10 Nov 2022 15:46:55 +0100 Subject: [PATCH 09/11] revert: restore meson matcher for vala_ls --- lua/lspconfig/server_configurations/vala_ls.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lua/lspconfig/server_configurations/vala_ls.lua b/lua/lspconfig/server_configurations/vala_ls.lua index 931bd58127..b5c9b56d3a 100644 --- a/lua/lspconfig/server_configurations/vala_ls.lua +++ b/lua/lspconfig/server_configurations/vala_ls.lua @@ -27,7 +27,11 @@ return { default_config = { cmd = { 'vala-language-server' }, filetypes = { 'vala', 'genie' }, - root_dir = util.root_pattern(unpack(workspace_markers)), + root_dir = function(fname) + -- TODO(kylo252): can't we just use 'meson_options.txt' instead? + local root = util.search_ancestors(fname, meson_matcher) + return root or util.find_git_ancestor(fname) + end, single_file_support = true, }, docs = { From 28a973708d2c9c9d1a51110ebf94af71bd691c0d Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Wed, 9 Nov 2022 19:27:22 +0100 Subject: [PATCH 10/11] fix: restore workspace markers to docgen --- scripts/docgen.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/docgen.lua b/scripts/docgen.lua index 93d57eb0ff..171c984c5a 100644 --- a/scripts/docgen.lua +++ b/scripts/docgen.lua @@ -132,7 +132,7 @@ local function make_lsp_sections() if description and type(description) ~= 'string' then description = inspect(description) elseif not description and type(v) == 'function' then - description = 'see source file' + return end return string.format('- `%s` : \n```lua\n%s\n```', k, description or inspect(v)) end), From 4817ec94cb6a697c2cb7a7a1ade43288dbc03d44 Mon Sep 17 00:00:00 2001 From: kylo252 <59826753+kylo252@users.noreply.github.com> Date: Wed, 16 Nov 2022 14:14:03 +0100 Subject: [PATCH 11/11] docs: update contributing --- CONTRIBUTING.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e97d6591bc..d8c220193f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -36,7 +36,8 @@ if vim.fn.has 'win32' == 1 then end ``` -* `filetypes`: a list for filetypes a +* `filetypes`: a list for filetypes that server supports. +* `workspace_markers`: a list for file patterns that determines the root of the workspace folder that will be passed to the language server. * `root_dir`: a function (or function handle) which returns the root of the project used to determine if lspconfig should launch a new language server, or attach a previously launched server when you open a new buffer matching the filetype of the server. Note, lspconfig does not offer a dedicated single file mode (this is not codified in the spec). Do not add `vim.fn.cwd` or `util.path.dirname` in `root_dir`. A future version of lspconfig will provide emulation of a single file mode until this is formally codified in the specification. A good fallback is `util.find_git_ancestor`, see other configurations for examples. Additionally, the following options are often added: @@ -56,7 +57,7 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, '--stdio' } end -local root_files = { +local workspace_markers = { 'pyproject.toml', 'setup.py', 'setup.cfg', @@ -77,7 +78,7 @@ return { default_config = { cmd = cmd, filetypes = { 'python' }, - root_dir = util.root_pattern(unpack(root_files)), + root_dir = util.root_pattern(unpack(workspace_markers)), single_file_support = true, settings = { python = { @@ -101,6 +102,7 @@ https://github.com/microsoft/pyright `pyright`, a static type checker and language server for python ]], + workspace_markers = workspace_markers, }, } ```