Initial commit

This commit is contained in:
2023-08-31 21:58:22 +02:00
parent 61336de4d2
commit 429a03c710
72 changed files with 5130 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
--[[
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.
]]
-- requires shellcheck also (for linting)
return {
cmd = { 'bash-language-server', 'start' },
cmd_env = { GLOB_PATTERN = '*@(.sh|.inc|.bash|.command)' },
single_file_support = true
}
+25
View File
@@ -0,0 +1,25 @@
--[[
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 {
cmd = {
'clangd',
'--clang-tidy',
'--enable-config',
'--log=verbose'
},
single_file_support = true,
}
+23
View File
@@ -0,0 +1,23 @@
--[[
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 {
cmd = { 'cmake-language-server' },
single_file_support = true,
init_options = {
buildDirectory = "build"
}
}
+176
View File
@@ -0,0 +1,176 @@
--[[
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 {
cmd = { 'diagnostic-languageserver', '--stdio' },
single_file_support = true,
-- For more info see https://github.com/iamcco/diagnostic-languageserver
init_options = {
filetypes = { python = 'flake8', lua = 'luaFormatter' },
linters = {
-- some help from this:
-- https://github.com/creativenull/diagnosticls-configs-nvim/blob/main/lua/diagnosticls-configs/linters/flake8.lua
flake8 = {
command = 'flake8',
args = {
'--config',
'tox.ini',
'--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]),(.*)(\r|\n)*$]],
{ line = 1, column = 2, security = 3, message = { 4 } }
},
securities = {
-- Available securities are { 'error', 'warning', 'hint', 'info' }
E = 'error',
W = 'warning',
B = 'hint',
F = 'error',
D = 'info'
}
}
},
formatFiletypes = {
python = { 'black', 'isort' },
lua = { 'luaFormatter' },
sh = { 'shfmt' }
},
formatters = {
black = {
sourceName = 'black',
command = 'black',
args = {
'--stdin-filename',
'%filename',
'-t',
'py39',
'--quiet',
'-'
},
rootPatterns = { 'Pipfile', '.git', 'tox.ini' },
isStdout = true,
isStderr = false,
ignoreExitCode = false
},
isort = {
sourceName = 'isort',
command = 'isort',
args = { '--quiet', '-' },
rootPatterns = { 'Pipfile', '.git', 'tox.ini' },
isStdout = true,
isStderr = false,
ignoreExitCode = false
},
luaFormatter = {
sourceName = 'luaFormatter',
command = 'lua-format',
isStdout = true,
isStderr = false,
ignoreExitCode = false,
args = {
'--column-limit',
'80', -- Column limit of one line
'--indent-width',
'4', -- Number of spaces used for indentation
-- '--use-tab', -- Use tab for indentation
'--no-use-tab', -- Do not use tab for indentation
'--tab-width',
'4', -- Number of spaces used per tab
'--continuation-indent-width',
'4', -- Indent width for continuations line
'--spaces-before-call',
'1', -- Space on function calls
'--keep-simple-control-block-one-line', -- Keep block in one line
-- '--no-keep-simple-control-block-one-line', -- Do not keep block in one line
'--keep-simple-function-one-line', -- Keep function in one line
-- '--no-keep-simple-function-one-line', -- Do not keep function in one line
'--align-args', -- Align the arguments
-- '--no-align-args', -- Do not align the arguments
'--break-after-functioncall-lp', -- Break after '(' of function call
-- '--no-break-after-functioncall-lp', -- Do not break after '(' of function call
'--break-before-functioncall-rp', -- Break before ')' of function call
-- '--no-break-before-functioncall-rp', -- Do not break before ')' of function call
-- '--spaces-inside-functioncall-parens', -- Put spaces on the inside of parens in function calls
'--no-spaces-inside-functioncall-parens', -- Do not put spaces on the inside of parens in function calls
-- '--spaces-inside-functiondef-parens', -- Put spaces on the inside of parens in function headers
'--no-spaces-inside-functiondef-parens', -- Do not put spaces on the inside of parens in function headers
'--align-parameter', -- Align the parameters
-- '--no-align-parameter', -- Do not align the parameters
'--chop-down-parameter', -- Chop down all parameters
-- '--no-chop-down-parameter', -- Do not chop down all parameters
'--break-after-functiondef-lp', -- Break after '(' of function def
-- '--no-break-after-functiondef-lp', -- Do not break after '(' of function def
'--break-before-functiondef-rp', -- Break before ')' of function def
-- '--no-break-before-functiondef-rp', -- Do not break before ')' of function def
'--align-table-field', -- Align fields of table
-- '--no-align-table-field', -- Do not align fields of table
'--break-after-table-lb', -- Break after '{' of table
-- '--no-break-after-table-lb', -- Do not break after '{' of table
'--break-before-table-rb', -- Break before '}' of table
-- '--no-break-before-table-rb', -- Do not break before '}' of table
'--chop-down-table', -- Chop down any table
-- '--no-chop-down-table', -- Do not chop down any table
'--chop-down-kv-table', -- Chop down table if table contains key
-- '--no-chop-down-kv-table', -- Do not chop down table if table contains key
'--table-sep',
',', -- Character to separate table fields
'--column-table-limit',
'80', -- Column limit of each line of a table
-- '--extra-sep-at-table-end', -- Add a extra field separator
'--no-extra-sep-at-table-end', -- Do not add a extra field separator
'--spaces-inside-table-braces', -- Put spaces on the inside of braces in table constructors
-- '--no-spaces-inside-table-braces', -- Do not put spaces on the inside of braces in table constructors
'--break-after-operator', -- Put break after operators
-- '--no-break-after-operator', -- Do not put break after operators
'--double-quote-to-single-quote', -- Transform string literals to use single quote
-- '--no-double-quote-to-single-quote', -- Do not transform string literals to use single quote
-- '--single-quote-to-double-quote', -- Transform string literals to use double
'--no-single-quote-to-double-quote', -- Do not transform string literals to use double
'--spaces-around-equals-in-field', -- Put spaces around the equal sign in key/value fields
-- '--no-spaces-around-equals-in-field', -- Do not put spaces around the equal sign in key/value fields
'--line-breaks-after-function-body',
'1', -- Line brakes after function body
'--line-separator',
'input' -- input(determined by the input content),
-- os(Use line ending of the current Operating system),
-- lf(Unix style "\n"),
-- crlf(Windows style "\r\n"),
-- cr(classic Max style "\r")
}
},
shfmt = {
sourceName = 'shfmt',
command = 'shfmt',
args = { '-s', '-i', '4', '-ci' },
rootPatterns = { 'Pipfile', '.git', 'tox.ini' },
isStdout = true,
isStderr = false,
ignoreExitCode = false
}
}
}
}
+22
View File
@@ -0,0 +1,22 @@
--[[
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 {
cmd = { "golangci-lint-langserver" },
init_options = {
command = { "golangci-lint", "run", "--out-format", "json" }
}
}
+84
View File
@@ -0,0 +1,84 @@
--[[
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 {
cmd = { "gopls", "serve" },
-- https://github.com/golang/tools/blob/master/gopls/doc/settings.md
settings = {
gopls = {
gofumpt = true,
codelenses = {
gc_details = true,
generate = true,
regenerate_cgo = true,
run_vulncheck_exp = true,
tidy = true,
upgrade_dependency = true,
vendor = true
},
usePlaceholders = true,
analyses = {
asmdecl = true,
assign = true,
atomic = true,
atomicalign = true,
bools = true,
buildtag = true,
cgocall = true,
composites = true,
copylocks = true,
deepequalerrors = true,
embed = true,
errorsas = true,
fieldalignment = true,
httpresponse = true,
ifaceassert = true,
infertypeargs = true,
loopclosure = true,
lostcancel = true,
nilfunc = true,
nilness = true,
printf = true,
shadow = true,
shift = true,
simplifycompositelit = true,
simplifyrange = true,
simplifyslice = true,
sortslice = true,
stdmethods = true,
stringintconv = true,
structtag = true,
testinggoroutine = true,
tests = true,
timeformat = true,
unmarshal = true,
unreachable = true,
unsafeptr = true,
unusedparams = true,
unusedresult = true,
unusedwrite = true,
useany = true,
fillreturns = true,
nonewvars = true,
noresultvalues = true,
undeclaredname = true,
unusedvariable = true,
fillstruct = true,
stubmethods = true
}
}
}
}
+23
View File
@@ -0,0 +1,23 @@
--[[
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 {
cmd = {
'java', '-jar',
'/usr/share/java/groovy-language-server/groovy-language-server-all.jar'
},
single_file_support = true
}
+171
View File
@@ -0,0 +1,171 @@
--[[
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 {
cmd = { 'jedi-language-server' },
single_file_support = true,
-- For more info see https://github.com/pappasam/jedi-language-server#configurationSources
-- and https://github.com/pappasam/coc-jedi#configuration (good descriptions)
init_options = {
completion = {
-- If your language client supports CompletionItem snippets but you don't like them,
-- disable them by setting this option to true.
-- type: boolean
-- default: false
disableSnippets = false,
-- Return all completion results in initial completion request.
-- Set to true if your language client does not support completionItem/resolve.
-- type: boolean
-- default: false
resolveEagerly = false,
-- A list of regular expressions.
-- If any regular expression in ignorePatterns matches a completion's name,
-- that completion item is not returned to the client.
-- type: string[]
-- default: []
-- In general, you should prefer the default value for this option.
-- Jedi is very good at filtering values for end users.
-- That said, there are situations where IDE developers,
-- or some programmers in some code bases, may want to filter some completions by name.
-- This flexible interface is provided to accommodate these advanced use cases.
ignorePatterns = {}
},
-- Built-in diagnostics seem to be very basic,
-- to the point where you are wondering if it's even active.
-- Will use iamcco/diagnostic-languageserver instead.
diagnostics = {
-- Enables (or disables) diagnostics provided by Jedi
-- type: boolean
-- default: true
enable = false,
-- When diagnostics are enabled, run on document open
-- type: boolean
-- default: true
didOpen = true,
-- When diagnostics are enabled, run on in-memory document change
-- (eg, while you're editing, without needing to save to disk)
-- type: boolean
-- default: true
didChange = true,
-- When diagnostics are enabled, run on document save (to disk)
-- type: boolean
-- default: true
didSave = true
},
hover = {
-- Enable (or disable) all hover text.
-- If set to false, will cause the hover method not to be registered to the language server.
-- type: boolean
-- default: true
enable = true,
-- disable.[jedi-type].all
-- Disable all hover text of jedi-type specified.
-- type: boolean
-- default: false
-- disable.[jedi-type].names
-- Disable hover text identified by name in list of jedi-type specified.
-- type: string[]
-- default: []
-- disable.[jedi-type].fullNames
-- Disable hover text identified by the fully qualified name in list of jedi-type specified.
-- If no fully qualified name can be found, jedi-language-server will default to
-- the name to prevent any unexpected behavior for users
-- (relevant for jedi types like keywords that don't have full names).
-- type: string[]
-- default: []
disable = {
class = { all = false, names = {}, fullNames = {} },
-- Need to escape lua keyword
['function'] = { all = false, names = {}, fullNames = {} },
instance = { all = false, names = {}, fullNames = {} },
keyword = { all = false, names = {}, fullNames = {} },
module = { all = false, names = {}, fullNames = {} },
param = { all = false, names = {}, fullNames = {} },
path = { all = false, names = {}, fullNames = {} },
property = { all = false, names = {}, fullNames = {} },
statement = { all = false, names = {}, fullNames = {} }
}
},
jediSettings = {
-- Modules that jedi will directly import without analyzing.
-- Improves autocompletion but loses goto definition.
-- type: string[]
-- default: []
-- If you're noticing that modules like numpy and pandas are taking a super long time to load
-- and you value completions / signatures over goto definition,
-- I recommend using this option like this:
-- autoImportModules = { "numpy", "pandas" },
autoImportModules = {},
-- Completions are by default case insensitive.
-- Set to false to make completions case sensitive.
-- type: boolean
-- default: true
caseInsensitiveCompletion = true,
-- Print jedi debugging messages to stderr.
-- type: boolean
-- default: false
debug = false
},
-- 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 = {
-- Add additional paths for Jedi's analysis.
-- Useful with vendor directories, packages in a non-standard location, etc.
-- You probably won't need to use this, but you'll be happy it's here when you need it!
-- type: string[]
-- default: []
-- Non-absolute paths are relative to your project root.
-- For example, let's say your Python project is structured like this:
-- ├── funky
-- │ └── haha.py
-- ├── poetry.lock
-- ├── pyproject.toml
-- └── test.py
-- Assume that funky/haha.py contains 1 line, x = 12,
-- and your build system does some wizardry that makes haha importable just like os or pathlib.
-- In this example, if you want to have this same non-standard behavior with jedi-language-server,
-- put the following:
-- extraPaths = { "funky" }
-- When editing test.py, you'll get completions, goto definition,
-- and all other lsp features for the line `from haha import ....`
-- Again, you probably don't need this.
extraPaths = {},
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'
},
-- Maximum number of symbols returned by a call to workspace/symbols.
-- type: number
-- default: 20
-- A value less than or equal to zero removes the maximum
-- and allows jedi-language-server to return all workplace symbols found by jedi.
maxSymbols = 20
}
}
}
}
+40
View File
@@ -0,0 +1,40 @@
--[[
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 {
cmd = { 'lemminx' },
single_file_support = true,
init_options = {
settings = {
xml = {
trace = { server = 'verbose' },
catalogs = {},
logs = {
client = false,
file = '/home/oscar/lsp4xml.log'
},
format = {
splitAttributes = true,
joinCDATALines = false,
joinContentLines = true,
joinCommentLines = false,
spaceBeforeEmptyCloseLine = false,
enabled = true
}
}
}
}
}
+47
View File
@@ -0,0 +1,47 @@
--[[
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.
]]
local runtime_path = vim.split(package.path, ';')
table.insert(runtime_path, 'lua/?.lua')
table.insert(runtime_path, 'lua/?/init.lua')
-- spec: https://luals.github.io/wiki/settings/
return {
cmd = { 'lua-language-server' },
single_file_support = true,
settings = {
Lua = {
runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = 'LuaJIT',
-- Setup your lua path
path = runtime_path
},
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = { 'vim' }
},
workspace = {
-- Make the server aware of Neovim runtime files
library = vim.api.nvim_get_runtime_file('', true),
checkThirdParty = false
},
-- Do not send telemetry data containing a randomized but unique identifier
telemetry = { enable = false }
}
}
}
+61
View File
@@ -0,0 +1,61 @@
--[[
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 {
cmd = { 'pylsp' },
single_file_support = true,
-- Reference: https://github.com/python-lsp/python-lsp-server/blob/develop/CONFIGURATION.md
settings = {
pylsp = {
-- configurationSources = { "flake8", "jedi_completion", "jedi_definition", "jedi_hover", "jedi_references", "jedi_signature_help", "jedi_symbols" },
plugins = {
flake8 = {
config = 'tox.ini',
enabled = true
-- executable = "flake8"
},
pyls_isort = { enabled = true },
jedi_completion = {
enabled = true,
include_params = false,
include_class_objects = true,
fuzzy = true,
eager = true,
resolve_at_most = 25,
cache_for = {
'pandas',
'numpy',
'tensorflow',
'matplotlib'
}
},
jedi_definition = {
enabled = true,
follow_imports = true,
follow_builtin_imports = true
},
jedi_hover = { enabled = true },
jedi_references = { enabled = true },
jedi_signature_help = { enabled = true },
jedi_symbols = {
enabled = true,
all_scopes = true,
include_import_symbols = true
}
}
}
}
}
+39
View File
@@ -0,0 +1,39 @@
--[[
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 {
cmd = { 'pyright-langserver', '--stdio' },
single_file_support = true,
-- see https://github.com/microsoft/pyright/blob/main/docs/configuration.md
-- and https://github.com/fannheyward/coc-pyright
settings = {
python = {
disableCompletion = false,
disableDiagnostics = false,
analysis = {
autoImportCompletions = true,
autoSearchPaths = true,
diagnosticMode = 'workspace',
stubPath = 'typings',
typeschedPaths = {},
diagnosticSeverityOverrides = {},
typeCheckingMode = 'off',
useLibraryCodeForTypes = true
},
completion = { importSupport = true, snippetSupport = true }
}
}
}
+38
View File
@@ -0,0 +1,38 @@
--[[
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 {
cmd = { 'rust-analyzer' },
settings = {
-- https://github.com/rust-lang/rust-analyzer/blob/master/docs/user/generated_config.adoc
['rust-analyzer'] = {
cargo = {
-- Extra environment variables that will be set when running cargo, rustc
-- or other commands within the workspace. Useful for setting RUSTFLAGS.
extraEnv = {
OPENSSL_INCLUDE_DIR = '/usr/include/openssl-1.0/',
OPENSSL_LIB_DIR = '/usr/lib/openssl-1.0/'
}
}
--[[ inlayHints = {
closingBraceHints = {
-- Whether to show inlay hints after a closing `}` to indicate what item it belongs to.
enable = false
},
} ]]
}
}
}
+287
View File
@@ -0,0 +1,287 @@
--[[
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.
]]
local P = {}
P._filetypes = nil
P._language_servers = nil
P.capabilities = {}
P.spec = require('lsp.spec')
function P._setup_diagnostic()
vim.diagnostic.config({
underline = true,
signs = true,
virtual_text = false,
-- virtual_text = {
-- format = function(diagnostic)
-- return string.format("%s: %s", diagnostic.user_data.lsp.code, diagnostic.message)
-- end
-- },
float = {
show_header = false,
source = 'if_many',
border = 'rounded',
focusable = false,
format = function(diagnostic)
return string.format('%s', diagnostic.message)
end
},
update_in_insert = false, -- default to false
severity_sort = true -- default to false
})
-- Change diagnostic icons
vim.fn.sign_define('DiagnosticSignError', {
text = 'E',
texthl = 'DiagnosticSignError',
-- culhl = 'DiagnosticSignError',
numhl = 'DiagnosticSignError'
-- linehl = 'LspDiagnosticsUnderlineError'
})
vim.fn.sign_define('DiagnosticSignWarn', {
text = 'W',
texthl = 'DiagnosticSignWarn',
-- culhl = 'DiagnosticSignWarn',
numhl = 'DiagnosticSignWarn'
-- linehl = 'LspDiagnosticsUnderlineWarning'
})
vim.fn.sign_define('DiagnosticSignHint', {
text = 'H',
texthl = 'DiagnosticSignHint',
-- culhl = 'DiagnosticSignHint',
numhl = 'DiagnosticSignHint'
-- linehl = 'LspDiagnosticsUnderlineHint'
})
vim.fn.sign_define('DiagnosticSignInfo', {
text = 'i',
texthl = 'DiagnosticSignInfo',
-- culhl = 'DiagnosticSignInfo',
numhl = 'DiagnosticSignInfo'
-- linehl = 'LspDiagnosticsUnderlineInfo'
})
-- Change some highlights
-- vim.cmd('highlight DiagnosticUnderlineError guifg=' .. utils.get_hl('DiagnosticError').foreground)
-- vim.cmd('highlight DiagnosticUnderlineWarn guifg=' .. utils.get_hl('DiagnosticWarn').foreground)
end
function P.on_attach(client, bufnr)
-- Enable completion triggered by <c-x><c-o>
-- Disabled in favor of nvim-cmp
-- vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
require('lsp_signature').on_attach({
debug = false, -- set to true to enable debug logging
log_path = vim.fn.stdpath('cache') .. '/lsp_signature.log', -- log dir when debug is on
-- default is ~/.cache/nvim/lsp_signature.log
verbose = false, -- show debug line number
bind = true, -- This is mandatory, otherwise border config won't get registered.
-- If you want to hook lspsaga or other signature handler, pls set to false
doc_lines = 20, -- will show two lines of comment/doc(if there are more than two lines in doc, will be truncated);
-- set to 0 if you DO NOT want any API comments be shown
-- This setting only take effect in insert mode, it does not affect signature help in normal
-- mode, 10 by default
max_height = 12, -- max height of signature floating_window
max_width = 80, -- max_width of signature floating_window
noice = false, -- set to true if you using noice to render markdown
wrap = true, -- allow doc/signature text wrap inside floating_window, useful if your lsp return doc/sig is too long
floating_window = true, -- show hint in a floating window, set to false for virtual text only mode
floating_window_above_cur_line = true, -- try to place the floating above the current line when possible Note:
-- will set to true when fully tested, set to false will use whichever side has more space
-- this setting will be helpful if you do not want the PUM and floating win overlap
floating_window_off_x = 1, -- adjust float windows x position.
floating_window_off_y = 0, -- adjust float windows y position. e.g -2 move window up 2 lines; 2 move down 2 lines
close_timeout = nil, -- close floating window after ms when laster parameter is entered
fix_pos = false, -- set to true, the floating window will not auto-close until finish all parameters
hint_enable = false, -- virtual hint enable
hint_prefix = '🐼 ', -- Panda for parameter, NOTE: for the terminal not support emoji, might crash
hint_scheme = 'String',
hi_parameter = 'IncSearch', -- default 'LspSignatureActiveParameter', -- how your parameter will be highlight
handler_opts = {
border = 'none' -- double, rounded, single, shadow, none
},
always_trigger = true, -- sometime show signature on new line or in middle of parameter can be confusing, set it to false for #58
auto_close_after = nil, -- autoclose signature float win after x sec, disabled if nil.
extra_trigger_chars = {}, -- Array of extra characters that will trigger signature completion, e.g., {"(", ","}
zindex = 200, -- by default it will be on top of all floating windows, set to <= 50 send it to bottom
padding = '', -- character to pad on left and right of signature can be ' ', or '|' etc
transparency = nil, -- disabled by default, allow floating win transparent value 1~100
shadow_blend = 36, -- if you using shadow as border use this set the opacity
shadow_guibg = 'Black', -- if you using shadow as border use this set the color e.g. 'Green' or '#121315'
timer_interval = 200, -- default timer check interval set to lower value if you want to reduce latency
toggle_key = '<C-e>', -- toggle signature on and off in insert mode, e.g. toggle_key = '<M-x>'
select_signature_key = nil, -- cycle to next signature, e.g. '<M-n>' function overloading
move_cursor_key = '<C-s>' -- imap, use nvim_set_current_win to move cursor between current win and floating
}, bufnr)
-- Mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local opts = { noremap = true, silent = true }
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'L',
'<cmd>lua vim.diagnostic.open_float()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '[d',
'<cmd>lua vim.diagnostic.goto_prev()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', ']d',
'<cmd>lua vim.diagnostic.goto_next()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>ll',
'<cmd>lua vim.diagnostic.setloclist()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD',
'<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd',
'<cmd>lua vim.lsp.buf.definition()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K',
'<cmd>lua vim.lsp.buf.hover()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi',
'<cmd>lua vim.lsp.buf.implementation()<CR>',
opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>s',
'<cmd>lua vim.lsp.buf.signature_help()<CR>',
opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>wa',
'<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>',
opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>wr',
'<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>',
opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>wl',
'<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>',
opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gt',
'<cmd>lua vim.lsp.buf.type_definition()<CR>',
opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>rn',
'<cmd>lua vim.lsp.buf.rename()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>ca',
'<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr',
'<cmd>lua vim.lsp.buf.references()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>lf',
'<cmd>lua vim.lsp.buf.format({async = true})<CR>',
opts)
-- if client.server_capabilities.document_range_formatting then
vim.api.nvim_buf_set_keymap(bufnr, 'v', '<leader>lf',
'<cmd>lua vim.lsp.buf.format({async = true})<CR>',
opts)
-- end
-- The below command will highlight the current variable and its usages in the buffer.
if client.server_capabilities.document_highlight then
vim.fn.execute('hi! link LspReferenceRead Visual')
vim.fn.execute('hi! link LspReferenceText Visual')
vim.fn.execute('hi! link LspReferenceWrite Visual')
vim.api.nvim_create_augroup('lsp_document_highlight', { clear = true })
vim.api.nvim_create_autocmd('CursorHold', {
buffer = bufnr,
callback = vim.lsp.buf.document_highlight
})
vim.api.nvim_create_autocmd('CursorMoved', {
buffer = bufnr,
callback = vim.lsp.buf.clear_references
})
end
-- Auto show current line diagnostics after 300 ms
-- vim.cmd('autocmd CursorHold <buffer> lua vim.diagnostic.open_float({ scope = "line" })')
-- vim.api.nvim_create_autocmd("CursorHold", {
-- buffer = bufnr,
-- callback = function()
-- vim.diagnostic.open_float({ scope = "line" })
-- end
-- })
vim.opt.updatetime = 100
end
function P.reload_server_buf(self, name)
local server_spec = self.spec[name]
local ft_map = {}
for _, ft in ipairs(server_spec.filetypes) do
ft_map[ft] = true
end
for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do
if vim.api.nvim_buf_is_loaded(bufnr) then
local buf_ft = vim.api.nvim_get_option_value('filetype', { buf = bufnr })
if ft_map[buf_ft] then
vim.api.nvim_buf_call(
bufnr,
function() vim.cmd('e') end
)
end
end
end
end
function P.filetypes(self)
if not self._filetypes then
self._filetypes = {}
local unique = {}
for _, server_spec in pairs(self.spec) do
for _, ft in ipairs(server_spec.filetypes) do
if not unique[ft] then
table.insert(self._filetypes, ft)
unique[ft] = true
end
end
end
end
return self._filetypes
end
function P.language_servers(self)
if not self._language_servers then
self._language_servers = {}
for server, _ in pairs(self.spec) do
table.insert(self._language_servers, server)
end
end
return self._language_servers
end
function P.setup_server(self, server)
local lspconfig = require('lspconfig')
local server_spec = self.spec[server]
local cfg = require('lsp.config.' .. server)
cfg.filetypes = server_spec.filetypes
cfg.root_dir = lspconfig.util.find_git_ancestor
cfg.capabilities = self.capabilities
cfg.on_attach = self.on_attach
lspconfig[server].setup(cfg)
end
function P.setup(self)
self._setup_diagnostic()
P.capabilities = require('cmp_nvim_lsp').default_capabilities()
require("mason-lspconfig").setup_handlers({
function(name)
self:setup_server(name)
self:reload_server_buf(name)
end
})
end
return P
+88
View File
@@ -0,0 +1,88 @@
--[[
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 {
clangd = {
filetypes = {
'c',
'cpp',
'objc',
'objcpp',
'cuda',
'proto',
}
},
cmake = {
filetypes = {
'cmake'
}
},
diagnosticls = {
filetypes = {
'python',
'lua',
'sh',
}
},
lua_ls = {
filetypes = {
'lua'
}
},
lemminx = {
filetypes = {
'xml',
'xsd',
'xsl',
'xslt',
'svg',
}
},
bashls = {
filetypes = {
'sh'
}
},
groovyls = {
filetypes = {
'groovy'
}
},
rust_analyzer = {
filetypes = {
'rust'
}
},
gopls = {
filetypes = {
"go",
"gomod"
}
},
golangci_lint_ls = {
filetypes = {
"go",
"gomod"
}
},
jedi_language_server = {
filetypes = {
'python'
}
},
-- pyright = { 'python' },
-- pylsp = { 'python' },
}