-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nvim: fix horrible performance on windows
All lsp servers were being registered w/ lspconfig on CmdEnter or FileType. On windows, some were taking hundreds of ms, adding up to nearly 5 seconds. Fixed by making lsp registration / installation happen on FileType event.
- Loading branch information
Showing
13 changed files
with
478 additions
and
343 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
dotfiles/private_dot_config/nvim/lua/chris468/config/lang/init.lua
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,71 @@ | ||
local util = require("chris468.util") | ||
local config = require("chris468.config") | ||
|
||
--- @class chris468.config.lang.Tools | ||
--- @field lint string[]? | ||
--- @field format string[]? | ||
|
||
--- @class (exact) chris468.config.lang.Lsp | ||
--- @field config? (table | fun():table?) | ||
--- @field register_server? table | fun():table? | ||
--- @field package_name? string | ||
|
||
--- @class (exact) chris468.config.lang.Config | ||
--- @field lsp { [string]: false | chris468.config.lang.Lsp } | ||
--- @field tools chris468.config.lang.Tools | ||
local M = {} | ||
|
||
M.lsp = { | ||
angularls = {}, | ||
ansiblels = {}, | ||
autotools_ls = {}, | ||
bashls = {}, | ||
clangd = {}, | ||
cmake = {}, | ||
cssls = {}, | ||
docker_compose_language_service = {}, | ||
dockerls = {}, | ||
elixirls = {}, | ||
erlangls = {}, | ||
gopls = {}, | ||
helm_ls = {}, | ||
html = {}, | ||
java_language_server = {}, | ||
jsonls = {}, | ||
lemminx = {}, -- xml | ||
lua_ls = {}, | ||
mesonlsp = {}, | ||
nil_ls = {}, -- nix | ||
omnisharp = require("chris468.config.lang.omnisharp"), | ||
powershell_es = {}, | ||
pyright = require("chris468.config.lang.pyright"), | ||
roslyn_lsp = require("chris468.config.lang.roslyn"), | ||
rust_analyzer = {}, | ||
ruff = {}, -- python | ||
spectral = {}, -- OpenAPI | ||
taplo = {}, -- toml | ||
terraformls = {}, | ||
tflint = {}, | ||
tsserver = {}, | ||
vimls = {}, | ||
yamlls = {}, | ||
codeqlls = {}, | ||
} | ||
|
||
--- @type { [string]: chris468.config.lang.Tools } | ||
M.tools = { | ||
markdown = { | ||
lint = { "markdownlint" }, | ||
}, | ||
lua = { | ||
format = { "stylua" }, | ||
}, | ||
python = { | ||
format = { "black" }, | ||
}, | ||
javascript = { | ||
format = { "prettierd", "prettier" }, | ||
}, | ||
} | ||
|
||
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
41 changes: 41 additions & 0 deletions
41
dotfiles/private_dot_config/nvim/lua/chris468/config/lang/pyright.lua
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,41 @@ | ||
local function detect_venv(root_dir) | ||
local Job = require("plenary.job") | ||
local python = vim.loop.os_uname().sysname == "Windows_NT" and "python.exe" or "python" | ||
local dot_venv_python = root_dir .. "/.venv/bin/" .. python | ||
if vim.fn.filereadable(dot_venv_python) == 1 then | ||
return dot_venv_python | ||
end | ||
|
||
local pyproject = root_dir .. "/pyproject.toml" | ||
if vim.fn.executable("poetry") == 1 and vim.fn.filereadable(pyproject) == 1 then | ||
local ok, venv = pcall(function() | ||
return Job:new({ | ||
command = "poetry", | ||
cwd = root_dir, | ||
args = { "env", "info", "-p" }, | ||
}) | ||
:sync()[1] | ||
end) | ||
if ok then | ||
return venv .. "/bin/" .. python | ||
end | ||
end | ||
|
||
return false | ||
end | ||
|
||
return { | ||
config = { | ||
on_new_config = function(new_config, new_root_dir) | ||
local defaults = require("lspconfig.server_configurations.pyright") | ||
if defaults.on_new_config then | ||
defaults.on_new_config(new_config, new_root_dir) | ||
end | ||
|
||
local venv_python = detect_venv(new_root_dir) | ||
if venv_python then | ||
new_config.settings.python.pythonPath = venv_python | ||
end | ||
end, | ||
}, | ||
} |
104 changes: 104 additions & 0 deletions
104
dotfiles/private_dot_config/nvim/lua/chris468/config/lang/roslyn.lua
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,104 @@ | ||
local util = require("chris468.util") | ||
local config = require("chris468.config") | ||
|
||
if not util.contains(config.csharp_lsp, "roslyn") then | ||
return false | ||
end | ||
|
||
local function configure_client_commands() | ||
vim.lsp.commands["roslyn.client.peekReferences"] = function(command, context) | ||
local window = vim.fn.bufwinid(context.bufnr) | ||
local pos = { command.arguments[2].line + 1, command.arguments[2].character } | ||
|
||
vim.api.nvim_win_set_cursor(window, pos) | ||
|
||
require("telescope.builtin").lsp_references() | ||
end | ||
end | ||
|
||
local function open_solution(client, sln) | ||
vim.notify("Opening " .. sln .. "...") | ||
client.notify("solution/open", { solution = vim.uri_from_fname(sln) }) | ||
end | ||
|
||
local function get_solutions(client) | ||
local root = client.config.root_dir | ||
local slns = vim.fn.glob(root .. "/*.sln", nil, true) | ||
return slns | ||
end | ||
|
||
local function find_and_open_solution(client) | ||
local slns = get_solutions(client) | ||
vim.notify(tostring(#slns) .. " solution found.") | ||
if #slns == 0 then | ||
return | ||
end | ||
open_solution(client, slns[1]) | ||
end | ||
|
||
local function prompt_for_solution(client) | ||
local slns = get_solutions(client) | ||
vim.ui.select(slns, { prompt = "Choose solution" }, function(selected) | ||
if selected then | ||
open_solution(client, selected) | ||
end | ||
end) | ||
end | ||
|
||
local function register_user_commands(client, bufnr) | ||
vim.api.nvim_buf_set_keymap(bufnr, "n", "gos", "", { | ||
callback = function() | ||
prompt_for_solution(client) | ||
end, | ||
desc = "Open solution", | ||
}) | ||
end | ||
|
||
--- @type chris468.config.lang.Lsp | ||
return { | ||
config = {}, | ||
register_server = function() | ||
local root_pattern = require("lspconfig.util").root_pattern | ||
|
||
return { | ||
default_config = { | ||
cmd = { | ||
"roslyn_lsp", | ||
"--logLevel", | ||
"Information", | ||
"--extensionLogDirectory", | ||
vim.fn.stdpath("state"), | ||
}, | ||
filetypes = { "cs" }, | ||
handlers = { | ||
["workspace/projectInitializationComplete"] = function() | ||
vim.notify("Project initialization complete.") | ||
end, | ||
}, | ||
on_attach = function(client, bufnr) | ||
register_user_commands(client, bufnr) | ||
end, | ||
on_init = function(client) | ||
find_and_open_solution(client) | ||
|
||
-- Ideally this would just set up the command in the comands table, but in lspconfig | ||
-- that currently sets up autocmds. see neovim/nvim-lspconfig/issues/2632. | ||
configure_client_commands() | ||
end, | ||
on_new_config = function(new_config, _) | ||
if vim.g.debug_roslyn_lsp == 1 then | ||
new_config.cmd = { | ||
"lsp-devtools", | ||
"agent", | ||
"--", | ||
unpack(new_config.cmd), | ||
} | ||
end | ||
end, | ||
root_dir = root_pattern({ "*.sln", "*.csproj" }), | ||
settings = {}, | ||
}, | ||
} | ||
end, | ||
package_name = "chris468_roslyn_lsp", | ||
} |
93 changes: 0 additions & 93 deletions
93
dotfiles/private_dot_config/nvim/lua/chris468/plugins/config/lsp/roslyn.lua
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.