More languages, clean up keybinds (#44)

This commit is contained in:
Patrick Stevens
2024-03-27 23:41:43 +00:00
committed by GitHub
parent b69b9248f9
commit 77d7d402c3
8 changed files with 281 additions and 259 deletions

View File

@@ -166,6 +166,16 @@
in { in {
enable = true; enable = true;
plugins = [ plugins = [
{
plugin = nixpkgs.vimPlugins.nvim-lightbulb;
type = "lua";
config = builtins.readFile ./nvim/nvim-lightbulb.lua;
}
{
plugin = nixpkgs.vimPlugins.lean-nvim;
type = "lua";
config = builtins.readFile ./nvim/lean.lua;
}
{ {
plugin = nixpkgs.vimPlugins.which-key-nvim; plugin = nixpkgs.vimPlugins.which-key-nvim;
type = "lua"; type = "lua";
@@ -284,7 +294,12 @@
}; };
home.packages = [ home.packages = [
nixpkgs.nodePackages_latest.dockerfile-language-server-nodejs
nixpkgs.nodePackages_latest.bash-language-server
nixpkgs.nodePackages_latest.vscode-json-languageserver nixpkgs.nodePackages_latest.vscode-json-languageserver
nixpkgs.nodePackages_latest.vscode-langservers-extracted
nixpkgs.hadolint
nixpkgs.ltex-ls
nixpkgs.yaml-language-server nixpkgs.yaml-language-server
nixpkgs.csharp-ls nixpkgs.csharp-ls
nixpkgs.netcoredbg nixpkgs.netcoredbg

View File

@@ -72,18 +72,14 @@ function RegisterSolution(sln_path)
vim.o.statusline = vim.o.statusline .. " %{v:lua.CurrentSlnOrEmpty()}" vim.o.statusline = vim.o.statusline .. " %{v:lua.CurrentSlnOrEmpty()}"
end end
local status, whichkey = pcall(require, "which-key") local whichkey = require("which-key")
if status then whichkey.register({
whichkey.register({ s = {
s = { name = ".NET solution",
name = ".NET solution", b = { BuildDotNetSolution, "Build .NET solution" },
b = { BuildDotNetSolution, "Build .NET solution" }, t = { TestDotNetSolution, "Test .NET solution" },
t = { TestDotNetSolution, "Test .NET solution" }, },
}, }, { prefix = vim.api.nvim_get_var("maplocalleader"), buffer = vim.api.nvim_get_current_buf() })
}, { prefix = vim.api.nvim_get_var("maplocalleader"), buffer = vim.api.nvim_get_current_buf() })
else
vim.api.nvim_set_keymap("n", "<localleader>sb", ":call BuildDotNetSolution", { noremap = true })
end
end end
local function find_nearest_slns() local function find_nearest_slns()
@@ -100,7 +96,11 @@ local function find_nearest_slns()
return {} return {}
end end
local function FindAndRegisterSolution() local function FindAndRegisterSolution(should_override)
if not should_override and GetCurrentSln() ~= nil then
RegisterSolution(GetCurrentSln())
end
local solutions = find_nearest_slns() local solutions = find_nearest_slns()
if not solutions or #solutions == 0 then if not solutions or #solutions == 0 then
print("No .sln file found in any parent directory.") print("No .sln file found in any parent directory.")
@@ -146,13 +146,15 @@ end
vim.api.nvim_create_autocmd({ "BufReadPost", "BufNewFile" }, { vim.api.nvim_create_autocmd({ "BufReadPost", "BufNewFile" }, {
pattern = "*.sln", pattern = "*.sln",
callback = function() callback = function()
RegisterSolution(vim.fn.expand("%:p")) if GetCurrentSln() == nil then
RegisterSolution(vim.fn.expand("%:p"))
end
end, end,
}) })
vim.api.nvim_create_autocmd("FileType", { vim.api.nvim_create_autocmd("FileType", {
pattern = { "fsharp", "cs" }, pattern = { "fsharp", "cs" },
callback = function() callback = function()
FindAndRegisterSolution() FindAndRegisterSolution(false)
end, end,
}) })

View File

@@ -105,6 +105,7 @@ vim.o.statusline = vim.o.statusline .. "%{v:lua.HasPaste()}%F%m%r%h %w Line: %l
vim.api.nvim_set_keymap("n", ";", "<Nop>", { noremap = true }) vim.api.nvim_set_keymap("n", ";", "<Nop>", { noremap = true })
vim.api.nvim_set_var("maplocalleader", ";") vim.api.nvim_set_var("maplocalleader", ";")
vim.api.nvim_set_var("mapleader", " ")
function MarkdownPreview() function MarkdownPreview()
local temp_file = vim.fn.tempname() .. ".md" local temp_file = vim.fn.tempname() .. ".md"
@@ -154,101 +155,134 @@ vim.api.nvim_create_autocmd("WinClosed", {
callback = close_loclist_if_orphaned, callback = close_loclist_if_orphaned,
}) })
local status, whichkey = pcall(require, "which-key") local whichkey = require("which-key")
if status then local pickers = require("telescope.pickers")
local pickers = require("telescope.pickers") local action_state = require("telescope.actions.state")
local action_state = require("telescope.actions.state") local actions = require("telescope.actions")
local actions = require("telescope.actions") local finders = require("telescope.finders")
local finders = require("telescope.finders") local conf = require("telescope.config").values
local conf = require("telescope.config").values
function DisplayAllMappingsWithTelescope() function DisplayAllMappingsWithTelescope()
local mappings = {} local mappings = {}
local commands = {} -- Store commands keyed by the display string local commands = {} -- Store commands keyed by the display string
local function accumulate(tree) local function accumulate(tree)
tree:walk(function(node) tree:walk(function(node)
-- Note: we could (if desired) view all groups, because the `node.mapping` table looks like this: -- Note: we could (if desired) view all groups, because the `node.mapping` table looks like this:
-- { prefix = "g", group = true, keys = {...}} -- { prefix = "g", group = true, keys = {...}}
if node.mapping then if node.mapping then
local mapping = node.mapping local mapping = node.mapping
if not mapping.group then if not mapping.group then
local description = mapping.desc or mapping.label or mapping.cmd local description = mapping.desc or mapping.label or mapping.cmd
-- Some actions are just there for which-key to hook into to display prefixes; they don't have a description. -- Some actions are just there for which-key to hook into to display prefixes; they don't have a description.
if description then if description then
local displayString = description .. " | " .. mapping.prefix local displayString = description .. " | " .. mapping.prefix
commands[displayString] = mapping.prefix commands[displayString] = mapping.prefix
mappings[#mappings + 1] = displayString mappings[#mappings + 1] = displayString
else else
for k, v in pairs(mapping) do for k, v in pairs(mapping) do
print("Nothing: " .. k .. " : " .. tostring(v) .. " (type: " .. type(v) .. ")") print("Nothing: " .. k .. " : " .. tostring(v) .. " (type: " .. type(v) .. ")")
end
print("-----")
end end
print("-----")
end end
end end
end) end
end end)
local cur_buf = vim.api.nvim_win_get_buf(0)
accumulate(require("which-key.keys").get_tree("n").tree)
accumulate(require("which-key.keys").get_tree("n", cur_buf).tree)
pickers
.new({}, {
prompt_title = "Actions",
finder = finders.new_table({
results = mappings,
}),
sorter = conf.generic_sorter({}),
attach_mappings = function(_, map)
map("i", "<CR>", function(bufnr)
local selection = action_state.get_selected_entry()
actions.close(bufnr)
local cmd = commands[selection.value]
if cmd then
vim.api.nvim_command(":normal " .. vim.api.nvim_replace_termcodes(cmd, true, true, true))
else
print("no command found")
end
end)
return true
end,
})
:find()
end end
function ToggleSpell() local cur_buf = vim.api.nvim_win_get_buf(0)
vim.cmd("setlocal spell!")
end
whichkey.register({ accumulate(require("which-key.keys").get_tree("n").tree)
[vim.api.nvim_get_var("maplocalleader")] = { accumulate(require("which-key.keys").get_tree("n", cur_buf).tree)
DisplayAllMappingsWithTelescope,
"View all mappings", pickers
}, .new({}, {
m = { prompt_title = "Actions",
p = { MarkdownPreview, "Preview Markdown in Lynx" }, finder = finders.new_table({
d = { RemoveCarriageReturn, "Delete carriage returns from file" }, results = mappings,
}, }),
["j"] = { sorter = conf.generic_sorter({}),
FormatJson, attach_mappings = function(_, map)
"Auto-format JSON", map("i", "<CR>", function(bufnr)
}, local selection = action_state.get_selected_entry()
["cd"] = { actions.close(bufnr)
ChangeToCurrentDirectory, local cmd = commands[selection.value]
"Switch CWD to the directory of the open buffer", if cmd then
}, vim.api.nvim_command(":normal " .. vim.api.nvim_replace_termcodes(cmd, true, true, true))
["ss"] = { else
ToggleSpell, print("no command found")
"Toggle spell-checker on or off", end
}, end)
}, { prefix = vim.api.nvim_get_var("maplocalleader") }) return true
else end,
vim.api.nvim_set_keymap("n", "<localleader>mp", ":lua MarkdownPreview()<CR>", { noremap = true, silent = true }) })
-- Remove the Windows ^M - when the encodings gets messed up :find()
vim.api.nvim_set_keymap("n", "<localleader>md", ":lua RemoveCarriageReturn()<CR>", { noremap = true })
vim.api.nvim_set_keymap("n", "<localleader>j", ":lua FormatJson()<CR>", { noremap = true })
vim.api.nvim_set_keymap("n", "<localleader>cd", ":lua ChangeToCurrentDirectory()<CR>", { noremap = true })
end end
function ToggleSpell()
vim.cmd("setlocal spell!")
end
whichkey.register({
[vim.api.nvim_get_var("maplocalleader")] = {
DisplayAllMappingsWithTelescope,
"View all mappings",
},
m = {
p = { MarkdownPreview, "Preview Markdown in Lynx" },
d = { RemoveCarriageReturn, "Delete carriage returns from file" },
},
["j"] = {
FormatJson,
"Auto-format JSON",
},
}, { prefix = vim.api.nvim_get_var("maplocalleader") })
whichkey.register({
g = {
function()
require("telescope.builtin").grep_string()
end,
"Find instances of text under cursor",
},
h = {
name = "Find historical...",
f = {
function()
require("telescope.builtin").oldfiles()
end,
"List previously open files",
},
c = {
function()
require("telescope.builtin").command_history()
end,
"List previously run commands",
},
s = {
function()
require("telescope.builtin").search_history()
end,
"List previously run searches",
},
},
m = {
function()
require("telescope.builtin").marks()
end,
"List marks",
},
["cd"] = {
ChangeToCurrentDirectory,
"Switch CWD to the directory of the open buffer",
},
["ss"] = {
ToggleSpell,
"Toggle spell-checker on or off",
},
[vim.api.nvim_get_var("mapleader")] = {
function()
require("telescope.builtin").find_files()
end,
"Find files by name",
},
}, { prefix = vim.api.nvim_get_var("mapleader") })

View File

@@ -0,0 +1,17 @@
require("lspconfig")["leanls"].setup({})
require("lean").setup({})
require("which-key").register({
l = {
i = { "<Cmd>LeanInfoviewToggle<CR>", "Toggle Lean info view" },
p = { "<Cmd>LeanInfoviewPinTogglePause<CR>", "Pause Lean info view" },
s = { "<Cmd>LeanSorryFill<CR>", "Fill open goals with sorry" },
w = { "<Cmd>LeanInfoviewEnableWidgets<CR>", "Enable Lean widgets" },
W = { "<Cmd>LeanInfoviewDisableWidgets<CR>", "Disable Lean widgets" },
["?"] = {
"<Cmd>LeanAbbreviationsReverseLookup<CR>",
"Show what Lean abbreviation produces the symbol under the cursor",
},
},
}, { prefix = vim.api.nvim_get_var("maplocalleader") })

View File

@@ -41,6 +41,13 @@ require("lspconfig")["jsonls"].setup({
}, },
}) })
require("lspconfig")["bashls"].setup({})
require("lspconfig")["dockerls"].setup({})
require("lspconfig")["html"].setup({
capabilities = capabilities,
})
require("lspconfig")["ltex"].setup({})
require("lspconfig")["lua_ls"].setup({ require("lspconfig")["lua_ls"].setup({
on_init = function(client) on_init = function(client)
local path = client.workspace_folders[1].name local path = client.workspace_folders[1].name
@@ -117,12 +124,12 @@ do
l = { ToggleLocList, "Toggle loclist" }, l = { ToggleLocList, "Toggle loclist" },
f = { vim.diagnostic.open_float, "Open current loclist entry in floating window" }, f = { vim.diagnostic.open_float, "Open current loclist entry in floating window" },
}, },
}, { prefix = vim.api.nvim_get_var("maplocalleader") }) }, { prefix = vim.api.nvim_get_var("mapleader") })
else else
vim.keymap.set("n", "<localleader>lp", vim.diagnostic.goto_prev) vim.keymap.set("n", "<leader>lp", vim.diagnostic.goto_prev)
vim.keymap.set("n", "<localleader>ln", vim.diagnostic.goto_next) vim.keymap.set("n", "<leader>ln", vim.diagnostic.goto_next)
vim.keymap.set("n", "<localleader>ll", ToggleLocList) vim.keymap.set("n", "<leader>ll", ToggleLocList)
vim.keymap.set("n", "<localleader>lf", vim.diagnostic.open_float) vim.keymap.set("n", "<leader>lf", vim.diagnostic.open_float)
end end
end end
@@ -131,77 +138,54 @@ end
vim.api.nvim_create_autocmd("LspAttach", { vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("UserLspConfig", {}), group = vim.api.nvim_create_augroup("UserLspConfig", {}),
callback = function(ev) callback = function(ev)
local whichkey_status, whichkey = pcall(require, "which-key") local whichkey = require("which-key")
-- Enable completion triggered by <c-x><c-o> -- Enable completion triggered by <c-x><c-o>
vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc" vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc"
-- Buffer local mappings. -- Buffer local mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions -- See `:help vim.lsp.*` for documentation on any of the below functions
local opts = { buffer = ev.buf } whichkey.register({
if whichkey_status then g = {
whichkey.register({ name = "Go-to related commands",
g = { D = { vim.lsp.buf.declaration, "Go to declaration" },
name = "Go-to related commands", d = { vim.lsp.buf.definition, "Go to definition" },
D = { vim.lsp.buf.declaration, "Go to declaration" }, i = { vim.lsp.buf.implementation, "Go to implementation" },
d = { vim.lsp.buf.definition, "Go to definition" },
i = { vim.lsp.buf.implementation, "Go to implementation" },
r = {
function()
require("telescope.builtin").lsp_references()
end,
"Find references",
},
},
K = { vim.lsp.buf.hover, "Display information about symbol under cursor" },
})
whichkey.register({
["<C-k>"] = { vim.lsp.buf.signature_help, "Display signature information about symbol under cursor" },
})
whichkey.register({
w = {
a = { vim.lsp.buf.add_workspace_folder, "Add a path to the workspace folders list" },
r = { vim.lsp.buf.add_workspace_folder, "Remove a path from the workspace folders list" },
l = {
function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end,
"Show the workspace folders list",
},
},
f = {
function()
vim.lsp.buf.format({ async = true })
end,
"Autoformat",
},
c = {
a = { vim.lsp.buf.code_action, "Select a code action" },
},
r = { r = {
n = { vim.lsp.buf.rename, "Rename variable" }, function()
require("telescope.builtin").lsp_references()
end,
"Find references",
}, },
D = { vim.lsp.buf.type_definition, "Go to type definition" }, },
}, { prefix = "<space>" }) K = { vim.lsp.buf.hover, "Display information about symbol under cursor" },
else })
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts) whichkey.register({
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) ["<C-k>"] = { vim.lsp.buf.signature_help, "Display signature information about symbol under cursor" },
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) })
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts) whichkey.register({
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, opts) w = {
vim.keymap.set("n", "<space>wa", vim.lsp.buf.add_workspace_folder, opts) a = { vim.lsp.buf.add_workspace_folder, "Add a path to the workspace folders list" },
vim.keymap.set("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, opts) r = { vim.lsp.buf.add_workspace_folder, "Remove a path from the workspace folders list" },
vim.keymap.set("n", "<space>wl", function() l = {
print(vim.inspect(vim.lsp.buf.list_workspace_folders())) function()
end, opts) print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
vim.keymap.set("n", "<space>D", vim.lsp.buf.type_definition, opts) end,
vim.keymap.set("n", "<space>rn", vim.lsp.buf.rename, opts) "Show the workspace folders list",
vim.keymap.set({ "n", "v" }, "<space>ca", vim.lsp.buf.code_action, opts) },
vim.keymap.set("n", "gr", function() },
require("telescope.builtin").lsp_references() f = {
end, opts) function()
vim.keymap.set("n", "<space>f", function() vim.lsp.buf.format({ async = true })
vim.lsp.buf.format({ async = true }) end,
end, opts) "Autoformat",
end },
c = {
a = { vim.lsp.buf.code_action, "Select a code action" },
},
r = {
n = { vim.lsp.buf.rename, "Rename variable" },
},
D = { vim.lsp.buf.type_definition, "Go to type definition" },
}, { prefix = vim.api.nvim_get_var("mapleader") })
end, end,
}) })

View File

@@ -29,71 +29,38 @@ dap.configurations.cs = {
} }
do do
local status, whichkey = pcall(require, "which-key") local whichkey = require("which-key")
if status then whichkey.register({
whichkey.register({ d = {
d = { name = "Debugger-related commands",
name = "Debugger-related commands", o = { dap.step_over, "Step over" },
o = { dap.step_over, "Step over" }, i = { dap.step_into, "Step into" },
i = { dap.step_into, "Step into" }, c = { dap.continue, "Continue" },
c = { dap.continue, "Continue" }, C = { dap.run_last, "Run with last debug configuration" },
C = { dap.run_last, "Run with last debug configuration" }, b = { dap.toggle_breakpoint, "Toggle breakpoint" },
b = { dap.toggle_breakpoint, "Toggle breakpoint" }, r = { dap.repl.open, "Open debug repl" },
r = { dap.repl.open, "Open debug repl" }, v = {
name = "Commands to view debugger state",
v = { v = {
name = "Commands to view debugger state", function()
v = { dap_ui.hover()
function() end,
dap_ui.hover() "View value of expression under cursor",
end, },
"View value of expression under cursor", s = {
}, function()
s = { dap_ui.sidebar(dap_ui.scopes).open()
function() end,
dap_ui.sidebar(dap_ui.scopes).open() "View values of all variables in all scopes",
end, },
"View values of all variables in all scopes", f = {
}, function()
f = { dap_ui.sidebar(dap_ui.frames).open()
function() end,
dap_ui.sidebar(dap_ui.frames).open() "View stack frames",
end,
"View stack frames",
},
}, },
t = { dap.terminate, "Terminate/stop/end debug session" },
}, },
}, { prefix = vim.api.nvim_get_var("maplocalleader") }) t = { dap.terminate, "Terminate/stop/end debug session" },
else },
vim.api.nvim_set_keymap("n", "<localleader>do", ":lua require('dap').step_over()<CR>", { noremap = true }) }, { prefix = vim.api.nvim_get_var("maplocalleader") })
vim.api.nvim_set_keymap("n", "<localleader>di", ":lua require('dap').step_into()<CR>", { noremap = true })
vim.api.nvim_set_keymap("n", "<localleader>dc", ":lua require('dap').continue()<CR>", { noremap = true })
vim.api.nvim_set_keymap("n", "<localleader>dC", ":lua require('dap').run_last()<CR>", { noremap = true })
vim.api.nvim_set_keymap(
"n",
"<localleader>db",
":lua require('dap').toggle_breakpoint()<CR>",
{ noremap = true }
)
vim.api.nvim_set_keymap("n", "<localleader>dr", ":lua require('dap').repl.open()<CR>", { noremap = true })
vim.api.nvim_set_keymap(
"n",
"<localleader>dvv",
":lua require('dap.ui.widgets').hover()<CR>",
{ noremap = true }
)
vim.api.nvim_set_keymap(
"n",
"<localleader>dvs",
":lua require('dap.ui.widgets').sidebar(require('dap.ui.widgets').scopes).open()<CR>",
{ noremap = true }
)
vim.api.nvim_set_keymap(
"n",
"<localleader>dvf",
":lua require('dap.ui.widgets').sidebar(require('dap.ui.widgets').frames).open()<CR>",
{ noremap = true }
)
vim.api.nvim_set_keymap("n", "<localleader>dt", ":lua require('dap').terminate()<CR>", { noremap = true })
end
end end

View File

@@ -0,0 +1,9 @@
require("nvim-lightbulb").setup({
autocmd = { enabled = true },
ignore = {
clients = {
-- This one is really noisy
"lua_ls",
},
},
})

View File

@@ -82,27 +82,21 @@ function CreateVenv()
end end
do do
local status, whichkey = pcall(require, "which-key") local whichkey = require("which-key")
if status then whichkey.register({
whichkey.register({ p = {
p = { name = "Python-related commands",
name = "Python-related commands", v = {
v = { name = "Virtual environment-related commands",
name = "Virtual environment-related commands", c = { CreateVenv, "Create virtual environment" },
c = { CreateVenv, "Create virtual environment" }, l = { SelectVenv, "Load virtual environment" },
l = { SelectVenv, "Load virtual environment" }, o = {
o = { function()
function() vim.cmd("VenvSelect")
vim.cmd("VenvSelect") end,
end, "Choose (override) new virtual environment",
"Choose (override) new virtual environment",
},
}, },
}, },
}, { prefix = vim.api.nvim_get_var("maplocalleader"), buffer = vim.api.nvim_get_current_buf() }) },
else }, { prefix = vim.api.nvim_get_var("maplocalleader") })
vim.api.nvim_set_keymap("n", "<localleader>pvc", ":lua CreateVenv()<CR>", { noremap = true })
vim.api.nvim_set_keymap("n", "<localleader>pvl", ":lua SelectVenv()<CR>", { noremap = true })
vim.api.nvim_set_keymap("n", "<localleader>pvo", ":VenvSelect<CR>", { noremap = true })
end
end end