Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: export workspace markers #2237

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
8 changes: 5 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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',
Expand All @@ -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 = {
Expand All @@ -101,6 +102,7 @@ https://github.com/microsoft/pyright

`pyright`, a static type checker and language server for python
]],
workspace_markers = workspace_markers,
},
}
```
Expand Down
6 changes: 4 additions & 2 deletions lua/lspconfig/server_configurations/als.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [[
Expand All @@ -31,7 +33,7 @@ require('lspconfig').als.setup{
```
]],
default_config = {
root_dir = [[util.root_pattern("Makefile", ".git", "*.gpr", "*.adc")]],
workspace_markers = workspace_markers,
},
},
}
19 changes: 9 additions & 10 deletions lua/lspconfig/server_configurations/anakin_language_server.lua
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -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,
},
}
6 changes: 4 additions & 2 deletions lua/lspconfig/server_configurations/angularls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ 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,
filetypes = { 'typescript', 'html', 'typescriptreact', 'typescript.tsx' },
-- 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)
Expand Down Expand Up @@ -69,7 +71,7 @@ require'lspconfig'.angularls.setup{
```
]],
default_config = {
root_dir = [[root_pattern("angular.json")]],
workspace_markers = workspace_markers,
},
},
}
4 changes: 3 additions & 1 deletion lua/lspconfig/server_configurations/ansiblels.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 = {
Expand Down
4 changes: 3 additions & 1 deletion lua/lspconfig/server_configurations/antlersls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [[
Expand Down
6 changes: 4 additions & 2 deletions lua/lspconfig/server_configurations/apex_ls.lua
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -40,7 +42,7 @@ require'lspconfig'.apex_ls.setup {
```
]],
default_config = {
root_dir = [[root_pattern('sfdx-project.json')]],
workspace_markers = workspace_markers,
},
},
}
Original file line number Diff line number Diff line change
@@ -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 = [[
Expand Down
4 changes: 3 additions & 1 deletion lua/lspconfig/server_configurations/asm_lsp.lua
Original file line number Diff line number Diff line change
@@ -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 = [[
Expand Down
6 changes: 4 additions & 2 deletions lua/lspconfig/server_configurations/astro.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '',
Expand All @@ -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,
},
},
}
6 changes: 4 additions & 2 deletions lua/lspconfig/server_configurations/bashls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 = {
Expand All @@ -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,
},
},
}
6 changes: 4 additions & 2 deletions lua/lspconfig/server_configurations/beancount.lua
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
},
},
}
6 changes: 4 additions & 2 deletions lua/lspconfig/server_configurations/bicep.lua
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -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,
},
},
}
6 changes: 4 additions & 2 deletions lua/lspconfig/server_configurations/blueprint_ls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 = {
Expand All @@ -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,
},
},
}
6 changes: 4 additions & 2 deletions lua/lspconfig/server_configurations/bsl_ls.lua
Original file line number Diff line number Diff line change
@@ -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 = [[
Expand All @@ -13,7 +15,7 @@ return {

]],
default_config = {
root_dir = [[root_pattern(".git")]],
workspace_markers = workspace_markers,
},
},
}
8 changes: 4 additions & 4 deletions lua/lspconfig/server_configurations/bufls.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [[
Expand All @@ -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,
},
},
}