-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: in-progress implementation of lsp without lspconfig
- Loading branch information
1 parent
4c2440e
commit 4d2cf5f
Showing
20 changed files
with
350 additions
and
2 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require("konrad.lsp.borders") | ||
require("konrad.lsp.commands") | ||
|
||
require("konrad.lsp").init_efm() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
local lsp = require("konrad.lsp") | ||
|
||
local config = require("konrad.lsp.configs.omnisharp").config() | ||
lsp.start_and_attach(config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
local lsp = require("konrad.lsp") | ||
|
||
local config = require("konrad.lsp.configs.gopls").config() | ||
lsp.start_and_attach(config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
local lsp = require("konrad.lsp") | ||
|
||
local config = require("konrad.lsp.configs.gopls").config() | ||
lsp.start_and_attach(config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
local lsp = require("konrad.lsp") | ||
|
||
local config = require("konrad.lsp.configs.gopls").config() | ||
lsp.start_and_attach(config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
local lsp = require("konrad.lsp") | ||
|
||
local config = require("konrad.lsp.configs.gopls").config() | ||
lsp.start_and_attach(config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
local lsp = require("konrad.lsp") | ||
local efm = require("konrad.lsp.efm") | ||
|
||
lsp.start_and_attach(efm.build_config("stylua", { "stylua" })) | ||
lsp.start_and_attach(require("konrad.lsp.configs.lua_ls").config()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
local lsp = require("konrad.lsp") | ||
lsp.start_and_attach(require("konrad.lsp.configs.nil_ls").config()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
local lsp = require("konrad.lsp") | ||
|
||
local config = require("konrad.lsp.configs.rust_analyzer").config() | ||
lsp.start_and_attach(config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
vim.api.nvim_create_user_command("LspClients", function() | ||
local data = {} | ||
for _, client in ipairs(vim.lsp.get_clients()) do | ||
data[tostring(client.id)] = { | ||
name = client.name, | ||
cmd = client.config.cmd, | ||
buffers = vim.tbl_keys(client.attached_buffers), | ||
root_dir = client.config.root_dir, | ||
} | ||
end | ||
|
||
vim.print(vim.inspect(data)) | ||
end, { | ||
desc = "List LSP clients with their details", | ||
}) | ||
|
||
vim.api.nvim_create_user_command("LspStopClient", function(info) | ||
local server_id | ||
local arguments = vim.split(info.args, "%s") | ||
for _, v in pairs(arguments) do | ||
if v:find("^[0-9]+$") then | ||
server_id = tonumber(v) | ||
end | ||
end | ||
if server_id then | ||
vim.notify("stoping server with id: " .. server_id) | ||
vim.lsp.stop_client(server_id) | ||
else | ||
vim.notify("stoping all lsp servers") | ||
vim.lsp.stop_client(vim.lsp.get_clients()) | ||
end | ||
end, { | ||
desc = "Stops specified LSP by id", | ||
nargs = 1, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
-- https://github.com/golang/tools/tree/master/gopls | ||
|
||
local binaries = require("konrad.binaries") | ||
local configs = require("konrad.lsp.configs") | ||
return { | ||
config = function() | ||
return { | ||
cmd = { binaries.gopls() }, | ||
-- https://github.com/golang/tools/blob/master/gopls/doc/settings.md | ||
settings = { | ||
gopls = { | ||
allExperiments = true, | ||
}, | ||
}, | ||
root_dir = configs.root_dir({ "go.work", "go.mod", ".git" }), | ||
} | ||
end, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
local M = {} | ||
|
||
---@param config table | ||
---@return table | ||
M.make_config = function(config) | ||
local base = { | ||
capabilities = require("konrad.lsp.capabilities"), | ||
} | ||
|
||
return vim.tbl_deep_extend("force", base, config) | ||
end | ||
|
||
---@param names string[]|string | ||
---@return string|nil | ||
M.root_dir = function(names) | ||
local found = vim.fs.find(names, { | ||
upward = true, | ||
stop = vim.uv.os_homedir(), | ||
path = vim.fs.dirname(vim.api.nvim_buf_get_name(0)), | ||
}) | ||
return vim.fs.dirname(found[1]) | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
-- https://github.com/sumneko/lua-language-server | ||
vim.cmd("packadd neodev.nvim") | ||
require("neodev").setup({ | ||
lspconfig = false, | ||
}) | ||
local before_init = require("neodev.lsp").before_init | ||
local binaries = require("konrad.binaries") | ||
local configs = require("konrad.lsp.configs") | ||
|
||
return { | ||
config = function() | ||
return { | ||
name = "lua_ls", | ||
cmd = { binaries.lua_ls() }, | ||
before_init = before_init, | ||
init_options = { | ||
documentFormatting = false, | ||
documentRangeFormatting = false, | ||
}, | ||
on_init = function(client) | ||
-- use stylua via efm, this formatter is not great and it cleares diagnostic text on save | ||
client.server_capabilities.documentFormattingProvider = nil | ||
client.server_capabilities.documentRangeFormattingProvider = nil | ||
end, | ||
settings = { | ||
Lua = { | ||
addonManager = { enable = false }, | ||
telemetry = { enable = false }, | ||
hint = { enable = true }, | ||
-- use stylua via efm, this formatter is not great and it cleares diagnostic text on save | ||
format = { enable = false }, | ||
}, | ||
}, | ||
root_dir = configs.root_dir({ ".luarc.json", "lua", ".git" }), | ||
} | ||
end, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
-- https://github.com/oxalica/nil | ||
local binaries = require("konrad.binaries") | ||
local configs = require("konrad.lsp.configs") | ||
return { | ||
config = function() | ||
return { | ||
cmd = { binaries.nil_ls() }, | ||
settings = { | ||
["nil"] = { | ||
formatting = { | ||
command = { binaries.nixpkgs_fmt() }, | ||
}, | ||
}, | ||
}, | ||
root_dir = configs.root_dir({ "flake.nix", ".git" }), | ||
} | ||
end, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
-- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#omnisharp | ||
|
||
-- https://github.com/Hoffs/omnisharp-extended-lsp.nvim | ||
vim.cmd("packadd omnisharp-extended-lsp.nvim") | ||
|
||
local binaries = require("konrad.binaries") | ||
local configs = require("konrad.lsp.configs") | ||
local function register_cap() | ||
local capabilities = vim.lsp.protocol.make_client_capabilities() | ||
capabilities.workspace.workspaceFolders = false -- https://github.com/OmniSharp/omnisharp-roslyn/issues/909 | ||
return capabilities | ||
end | ||
|
||
local M = {} | ||
|
||
M.options = { | ||
-- Only run analyzers against open files when 'enableRoslynAnalyzers' is | ||
-- true | ||
analyze_open_documents_only = true, | ||
-- decompilation support via omnisharp-extended-lsp | ||
enableDecompilationSupport = true, | ||
-- Enables support for reading code style, naming convention and analyzer | ||
-- settings from .editorconfig. | ||
enable_editorconfig_support = true, | ||
-- Enables support for roslyn analyzers, code fixes and rulesets. | ||
enable_roslyn_analyzers = true, | ||
-- Specifies whether 'using' directives should be grouped and sorted during | ||
-- document formatting. | ||
organize_imports_on_format = true, | ||
-- Enables support for showing unimported types and unimported extension | ||
-- methods in completion lists. When committed, the appropriate using | ||
-- directive will be added at the top of the current file. This option can | ||
-- have a negative impact on initial completion responsiveness, | ||
-- particularly for the first few completion sessions after opening a | ||
-- solution. | ||
enable_import_completion = true, | ||
} | ||
|
||
M.config = function() | ||
local cmd = { binaries.omnisharp() } | ||
-- Append hard-coded command arguments | ||
table.insert(cmd, "-z") -- https://github.com/OmniSharp/omnisharp-vscode/pull/4300 | ||
vim.list_extend(cmd, { "--hostPID", tostring(vim.fn.getpid()) }) | ||
table.insert(cmd, "DotNet:enablePackageRestore=false") | ||
vim.list_extend(cmd, { "--encoding", "utf-8" }) | ||
table.insert(cmd, "--languageserver") | ||
|
||
-- Append configuration-dependent command arguments | ||
if M.options.enable_editorconfig_support then | ||
table.insert(cmd, "FormattingOptions:EnableEditorConfigSupport=true") | ||
end | ||
|
||
if M.options.organize_imports_on_format then | ||
table.insert(cmd, "FormattingOptions:OrganizeImports=true") | ||
end | ||
|
||
if M.options.enable_ms_build_load_projects_on_demand then | ||
table.insert(cmd, "MsBuild:LoadProjectsOnDemand=true") | ||
end | ||
|
||
if M.options.enable_roslyn_analyzers then | ||
table.insert(cmd, "RoslynExtensionsOptions:EnableAnalyzersSupport=true") | ||
end | ||
|
||
if M.options.enable_import_completion then | ||
table.insert(cmd, "RoslynExtensionsOptions:EnableImportCompletion=true") | ||
end | ||
|
||
if M.options.sdk_include_prereleases then | ||
table.insert(cmd, "Sdk:IncludePrereleases=true") | ||
end | ||
|
||
if M.options.analyze_open_documents_only then | ||
table.insert(cmd, "RoslynExtensionsOptions:AnalyzeOpenDocumentsOnly=true") | ||
end | ||
|
||
return { | ||
cmd = cmd, | ||
on_init = function(client, initialize_result) | ||
-- disable codelens for omnisharp because it makes it extremely slow | ||
client.server_capabilities.codeLensProvider = nil | ||
-- inlayHints are broken as well as of 1.39.10 | ||
client.server_capabilities.inlayHintProvider = nil | ||
client.notify("workspace/didChangeConfiguration", { settings = client.config.settings }) | ||
end, | ||
capabilities = register_cap(), | ||
handlers = { | ||
["textDocument/definition"] = require("omnisharp_extended").handler, | ||
}, | ||
root_dir = configs.root_dir(".sln") or configs.root_dir(".csproj"), | ||
} | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
local binaries = require("konrad.binaries") | ||
local configs = require("konrad.lsp.configs") | ||
|
||
local function register_cap() | ||
local capabilities = vim.lsp.protocol.make_client_capabilities() | ||
capabilities.experimental = { | ||
serverStatusNotification = true, | ||
} | ||
return capabilities | ||
end | ||
|
||
return { | ||
config = function() | ||
return { | ||
cmd = { binaries.rust_analyzer() }, | ||
capabilities = register_cap(), | ||
settings = { | ||
["rust-analyzer"] = { | ||
rustfmt = { | ||
overrideCommand = { binaries.rustfmt(), "--" }, | ||
}, | ||
files = { | ||
excludeDirs = { | ||
"./.direnv/", | ||
"./.git/", | ||
"./.github/", | ||
"./.gitlab/", | ||
"./node_modules/", | ||
"./ci/", | ||
"./docs/", | ||
}, | ||
}, | ||
checkOnSave = { | ||
enable = true, | ||
}, | ||
diagnostics = { | ||
enable = true, | ||
experimental = { | ||
enable = true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
root_dir = configs.root_dir({ "Cargo.toml", "rust-project.json" }), | ||
} | ||
end, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters