feat(lsp): refactor

* Move configs into config subdirectory
 * Move LSP logic into classes
 * Make it possible to define mason package in lsp config,
   including nested dependency resolution and post install
   steps
 * replace jedi_language_server with pylsp
This commit is contained in:
2024-04-14 15:41:39 +02:00
parent 06898a5a31
commit 2bc21b248c
17 changed files with 671 additions and 376 deletions
+21
View File
@@ -0,0 +1,21 @@
return {
enable = true,
dependencies = {
"npm",
},
mason = {
name = "bash-language-server",
dependencies = {
{ name = "shellcheck", },
},
},
lspconfig = {
filetypes = {
"sh",
"bash",
"zsh",
},
cmd = { "bash-language-server", "start", },
single_file_support = true,
},
}
+23
View File
@@ -0,0 +1,23 @@
return {
enable = true,
mason = {
name = "clangd",
-- version = "",
},
lspconfig = {
filetypes = {
"c",
"cpp",
"objc",
"objcpp",
"cuda",
"proto",
},
cmd = {
"clangd",
"--clang-tidy",
"--enable-config",
},
single_file_support = true,
},
}
+23
View File
@@ -0,0 +1,23 @@
return {
enable = true,
dependencies = {
"python3",
},
py_module_deps = {
"venv",
},
mason = {
name = "cmake-language-server",
-- version = "",
},
lspconfig = {
filetypes = {
"cmake",
},
cmd = { "cmake-language-server", },
single_file_support = true,
init_options = {
buildDirectory = "build",
},
},
}
+206
View File
@@ -0,0 +1,206 @@
-- For more info see:
-- https://github.com/iamcco/diagnostic-languageserver
-- More examples at:
-- https://github.com/iamcco/coc-diagnostic/blob/master/src/config.ts
return {
enable = true,
dependencies = {
"npm",
},
mason = {
-- TODO: figure out if possible to install required formatters/linters
-- in this language server automatically through mason
name = "diagnostic-languageserver",
-- version = "",
},
lspconfig = {
filetypes = {
-- "python",
"sh",
"bash",
"zsh",
"php",
},
cmd = { "diagnostic-languageserver", "--stdio", },
single_file_support = true,
init_options = {
filetypes = {
-- python = "flake8",
php = "phpcs",
},
linters = {
-- some help from this:
-- https://github.com/creativenull/diagnosticls-configs-nvim/blob/main/lua/diagnosticls-configs/linters/flake8.lua
flake8 = {
command = "flake8",
args = {
"--max-line-length=100",
"--max-doc-length=100",
"--format",
"%(row)d,%(col)d,%(code).1s,%(code)s: %(text)s",
"-",
},
rootPatterns = { "Pipfile", ".git", "tox.ini", },
isStdout = true,
isStderr = false,
debounce = 100,
offsetLine = 0,
offsetColumn = 0,
sourceName = "flake8",
formatLines = 1,
formatPattern = {
[[^(\d+),(\d+),([A-Z]),(.*): (.*)]],
{ line = 1, column = 2, security = 3, message = { 5, }, },
},
securities = {
-- Available securities are { 'error', 'warning', 'hin', 'info' }
E = "error",
W = "warning",
B = "hint",
F = "hint",
D = "info",
},
},
phpcs = {
command = "./vendor/bin/phpcs",
args = {
"--report=json",
"-s",
"-",
},
rootPatterns = {
"composer.json",
"composer.lock",
"vendor",
".git",
},
isStdout = true,
isStderr = false,
debounce = 100,
offsetLine = 0,
offsetColumn = 0,
sourceName = "phpcs",
-- Alternative to JSON parsing,
-- requires --report=emacs
-- formatLines = 1,
-- formatPattern = {
-- [[^.*:(\d+):(\d+): (.*) [-] (.*)$]],
-- {
-- line = 1,
-- column = 2,
-- security = 3,
-- message = { 4, },
-- },
-- },
-- securities = {
-- error = "error",
-- warning = "warning",
-- },
parseJson = {
errorsRoot = "files.STDIN.messages",
line = "line",
column = "column",
security = "type",
message = "${message} (${source})",
},
securities = {
ERROR = "error",
WARNING = "warning",
},
},
},
formatFiletypes = {
-- python = { "black", "isort", },
sh = { "shfmt", },
bash = { "shfmt", },
zsh = { "shfmt", },
-- php = { "php_cs_fixer", },
},
formatters = {
autopep8 = {
command = "autopep8",
args = {
"--aggressive",
"-",
},
rootPatterns = { "Pipfile", "tox.ini", ".git", },
isStdout = true,
isStderr = false,
ignoreExitCode = false,
},
black = {
command = "black",
args = {
"--line-length", "100",
"--stdin-filename",
"%filename",
"--quiet",
"-code",
"%text",
},
rootPatterns = { "Pipfile", ".git", "tox.ini", },
isStdout = true,
isStderr = false,
ignoreExitCode = false,
},
isort = {
command = "isort",
args = { "--quiet", "-", },
rootPatterns = { "Pipfile", ".git", "tox.ini", },
isStdout = true,
isStderr = false,
ignoreExitCode = false,
},
shfmt = {
command = "shfmt",
args = { "-s", "-i", "4", "-ci", },
rootPatterns = { "Pipfile", ".git", "tox.ini", },
isStdout = true,
isStderr = false,
ignoreExitCode = false,
},
phpcbf = {
command = "./vendor/bin/phpcbf",
args = {
"--standard=PSR12",
"-",
},
rootPatterns = {
"composer.json",
"composer.lock",
"vendor",
".git",
},
isStdout = true,
isStderr = false,
ignoreExitCode = true,
},
php_cs_fixer = {
command = "./vendor/bin/php-cs-fixer",
args = {
"fix",
"--no-ansi",
"--using-cache=no",
"--quiet",
"--no-interaction",
"%file",
},
isStdout = false,
isStderr = false,
doesWriteToFile = true,
ignoreExitCode = true,
rootPatterns = {
"composer.json",
"composer.lock",
"vendor",
".git",
},
},
},
},
},
}
+28
View File
@@ -0,0 +1,28 @@
-- spec: https://rust-analyzer.github.io/manual.html#configuration
return {
enable = true,
mason = {
name = "gopls",
-- version = "",
},
lspconfig = {
filetypes = {
"go",
"gomod",
"gowork",
"gotmpl",
},
cmd = { "gopls", },
single_file_support = true,
settings = {
gopls = {
analyses = {
unusedparams = true,
},
staticcheck = true,
gofumpt = true,
},
},
},
}
+35
View File
@@ -0,0 +1,35 @@
--[[
Copyright 2023 Oscar Wallberg
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
]]
return {
enable = false,
dependencies = {
"java",
},
mason = {
name = "groovy-language-server",
-- version = "",
},
lspconfig = {
filetypes = {
"groovy",
},
cmd = {
"groovy-language-server",
},
single_file_support = true,
},
}
+18
View File
@@ -0,0 +1,18 @@
return {
enable = true,
mason = {
name = "haskell-language-server",
-- version = "",
},
lspconfig = {
filetypes = { "haskell", "lhaskell", "cabal", },
cmd = { "haskell-language-server-wrapper", "--lsp", },
single_file_support = true,
settings = {
haskell = {
cabalFormattingProvider = "cabalfmt",
formattingProvider = "ormolu",
},
},
},
}
+36
View File
@@ -0,0 +1,36 @@
-- spec:
-- https://github.com/bmewburn/intelephense-docs/blob/master/installation.md
-- https://github.com/bmewburn/vscode-intelephense/blob/master/package.json
return {
enable = true,
dependencies = {
"npm",
},
root_pattern = {
"composer.json",
"composer.lock",
"vendor",
},
mason = {
name = "intelephense",
-- version = "",
},
lspconfig = {
filetypes = {
"php",
},
cmd = { "intelephense", "--stdio", },
single_file_support = true,
settings = {
intelephense = {
environment = {
phpVersion = "7.4",
},
format = {
enable = true,
},
},
},
},
}
+55
View File
@@ -0,0 +1,55 @@
return {
enable = false,
dependencies = {
"python3",
},
py_module_deps = {
"venv",
},
mason = {
name = "jedi-language-server",
-- version = "",
},
lspconfig = {
filetypes = {
"python",
},
cmd = { "jedi-language-server", },
single_file_support = true,
-- For more info see:
-- - https://github.com/pappasam/jedi-language-server#configuration
-- - https://github.com/pappasam/coc-jedi#configuration (good descriptions)
init_options = {
-- Built-in diagnostics seem to be very basic,
-- to the point where you are wondering if it's even active.
-- Will use flake8 together with diagnosticls for added linting
diagnostics = {
-- Enables (or disables) diagnostics provided by Jedi
-- type: boolean
-- default: true
enable = true,
},
-- The preferred MarkupKind for all jedi-language-server messages that take MarkupContent.
-- type: string
-- accepted values: "markdown", "plaintext"
-- If omitted, jedi-language-server defaults to the client-preferred configuration.
-- If there is no client-preferred configuration, jedi language server users "plaintext".
-- markupKindPreferred = "markdown",
workspace = {
symbols = {
-- Performance optimization that sets names of folders that are ignored for workspace/symbols.
-- type: string[]
-- default: { ".nox", ".tox", ".venv", "__pycache__", "venv" }
-- If you manually set this option, it overrides the default.
-- Setting it to an empty array will result in no ignored folders.
ignoreFolders = {
".nox", ".tox", ".venv", "__pycache__", "venv",
"artifacts", "config", ".vscode", ".pytest_cache",
"build", "scripts", "incoax_tests.egg-info",
"node_modules",
},
},
},
},
},
}
+40
View File
@@ -0,0 +1,40 @@
-- spec: https://github.com/eclipse/lemminx/blob/main/docs/Configuration.md
return {
enable = true,
mason = {
name = "lemminx",
-- version = "",
},
lspconfig = {
filetypes = {
"xml",
"xsd",
"xsl",
"xslt",
"svg",
},
cmd = { "lemminx", },
single_file_support = true,
init_options = {
settings = {
xml = {
format = {
enabled = true, -- is able to format document
splitAttributes = true, -- each attribute is formatted onto new line
joinCDATALines = false, -- normalize content inside CDATA
joinCommentLines = false, -- normalize content inside comments
formatComments = true, -- keep comment in relative position
joinContentLines = false, -- normalize content inside elements
spaceBeforeEmptyCloseLine = true, -- insert whitespace before self closing tag end bracket
},
validation = {
noGrammar = "ignore",
enabled = true,
schema = true,
}
},
},
},
},
}
+54
View File
@@ -0,0 +1,54 @@
-- spec: https://luals.github.io/wiki/settings/
---@type ServerConfig
return {
enable = true,
mason = {
name = "lua-language-server",
-- version = "",
},
lspconfig = {
filetypes = {
"lua",
},
cmd = { "lua-language-server", },
single_file_support = true,
settings = {
Lua = {
completion = {
showWord = "Disable",
},
diagnostics = {
disable = { "missing-fields", },
},
runtime = {
version = "LuaJIT",
path = {
"lua/?.lua",
"lua/?/init.lua",
"?/lua/?.lua",
"?/lua/?/init.lua",
},
},
workspace = {
library = {
vim.env.VIMRUNTIME,
"/usr/share/lua/5.3",
vim.fn.stdpath("data") .. "/lazy",
},
checkThirdParty = false,
},
hint = {
enable = false,
arrayIndex = "Disable",
await = true,
paramName = "All",
paramType = true,
semicolon = "Disable",
setType = true,
},
telemetry = { enable = false, },
},
},
},
}
+85
View File
@@ -0,0 +1,85 @@
--- @type ServerConfig
return {
enable = true,
dependencies = {
"python3",
},
py_module_deps = {
"venv",
},
mason = {
name = "python-lsp-server",
post_install = {
{
command = "./venv/bin/pip",
args = {
"install",
"python-lsp-black",
"python-lsp-isort",
},
},
-- {
-- command = "./venv/bin/pip",
-- args = { "alsdkfjhaklsdfjhl", },
-- },
},
},
lspconfig = {
filetypes = {
"python",
},
cmd = { "pylsp", },
single_file_support = true,
settings = {
pylsp = {
configurationSources = { "flake8", },
plugins = {
autopep8 = {
enabled = false,
},
black = {
enabled = true,
line_length = 100,
},
flake8 = {
enabled = true,
exclude = { ".venv", "build/", },
filename = { "*.py", },
-- B - flake8-bugbear https://github.com/PyCQA/flake8-bugbear
-- C - only one violation, C901. mccabe https://github.com/PyCQA/mccabe
-- D - flake8-docstrings (pydocstyle) http://www.pydocstyle.org/en/stable/error_codes.html
-- E - pycodestyle https://pycodestyle.pycqa.org/en/latest/intro.html#error-codes
-- F - flake8 https://flake8.pycqa.org/en/latest/user/error-codes.html
-- W - pycodestyle https://pycodestyle.pycqa.org/en/latest/intro.html#error-codes
select = {
"B", "B902", "B903", "B904", "C", "E", "E999", "E501", "F", "W",
},
ignore = {
"B950", "D201", "D203", "D205", "D301", "D400", "E133", "E203", "W503",
},
max_line_length = 100,
max_doc_length = 100,
},
isort = {
enabled = true,
},
mccabe = {
enabled = false,
},
pycodestyle = {
enabled = false,
},
pydocstyle = {
enabled = false,
},
pyflakes = {
enabled = false,
},
yapf = {
enabled = false,
},
},
},
},
},
}
+191
View File
@@ -0,0 +1,191 @@
-- spec: https://rust-analyzer.github.io/manual.html#configuration
return {
enable = true,
mason = {
name = "rust-analyzer",
-- version = "",
},
lspconfig = {
filetypes = {
"rust",
},
cmd = { "rust-analyzer", },
single_file_support = true,
settings = {
["rust-analyzer"] = {
inlayHints = {
chainingHints = {
enable = false,
},
parameterHints = {
enable = false,
},
typeHints = {
enable = false,
},
},
--[[ assist = {
emitMustUse = false,
expressionFillDefault = false,
},
cachePriming = {
enable = false,
},
cargo = {
autoreload = false,
buildScripts = {
enable = false,
},
},
checkOnSave = false,
completion = {
autoimport = {
enable = false,
},
autoself = {
enable = false,
},
callable = {
snippets = false,
},
fullFunctionSignatures = {
enable = false,
},
postfix = {
enable = false,
},
privateEditable = {
enable = false,
},
},
diagnostics = {
enable = false,
},
highlightRelated = {
breakPoints = {
enable = false,
},
closureCaptures = {
enable = false,
},
exitPoints = {
enable = false,
},
references = {
enable = false,
},
yieldPoints = {
enable = false,
},
},
hover = {
actions = {
enable = false,
},
documentation = {
enable = true,
},
links = {
enable = false,
},
memoryLayout = {
enable = false,
},
},
imports = {
group = {
enable = false,
},
},
inlayHints = {
bindingModeHints = {
enable = false,
},
chainingHints = {
enable = false,
},
closingBraceHints = {
enable = false,
},
closureCaptureHints = {
enable = false,
},
closureReturnTypeHints = {
enable = false,
},
discriminantHints = {
enable = false,
},
expressionAdjustmentHints = {
enable = false,
},
lifetimeElisionHints = {
enable = false,
},
parameterHints = {
enable = false,
},
reborrowHints = {
enable = false,
},
typeHints = {
enable = false,
},
},
joinLines = {
joinAssignments = false,
joinElseIf = false,
removeTrailingComma = false,
unwrapTrivialBlock = false,
},
lens = {
enable = false,
},
notifications = {
cargoTomlNotFound = false,
},
procMacro = {
enable = false,
},
references = {
excludeImports = false,
},
rustfmt = {
rangeFormatting = {
enable = false,
},
},
semanticHighlighting = {
doc = {
comment = {
inject = {
enable = false,
},
},
},
nonStandardTokens = false,
operator = {
enable = false,
},
punctuation = {
enable = false,
},
strings = {
enable = false,
},
},
signatureInfo = {
documentation = {
enable = true,
},
},
typing = {
autoClosingAngleBrackets = {
enable = false,
},
}, ]]
},
},
},
}
+29
View File
@@ -0,0 +1,29 @@
-- spec: https://github.com/zigtools/zls#configuration-options
return {
enable = true,
dependencies = {
"zig",
},
-- mason = {
-- name = "zls",
-- -- version = "",
-- },
lspconfig = {
filetypes = {
"zig",
"zir",
},
cmd = { "zls", },
single_file_support = true,
settings = {
zls = {
enable_autofix = false,
enable_inlay_hints = false,
enable_build_on_save = true,
warn_style = true,
highlight_global_var_declarations = true,
},
},
},
}