Fix buffer-specific binds

This commit is contained in:
Smaug123
2024-03-24 23:30:52 +00:00
parent 75cebeaa7a
commit 4554ea1a90
4 changed files with 138 additions and 113 deletions

View File

@@ -166,19 +166,35 @@ if status then
local mappings = {}
local commands = {} -- Store commands keyed by the display string
require("which-key.keys").get_tree("n").tree:walk(function(node)
function accumulate(tree)
tree:walk(function(node)
-- Note: we could (if desired) view all groups, because the `node.mapping` table looks like this:
-- { prefix = "g", group = true, keys = {...}}
if node.mapping then
local mapping = node.mapping
if not mapping.group then
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.
if description then
local displayString = description .. " | " .. mapping.prefix
commands[displayString] = mapping.prefix
mappings[#mappings + 1] = displayString
else
for k, v in pairs(mapping) do
print("Nothing: " .. k .. " : " .. tostring(v) .. " (type: " .. type(v) .. ")")
end
print("-----")
end
end
-- TODO: If a command is a prefix of an existing command, prepend its description to those commands' descriptions, and append a '...' to the parent's description.
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({}, {
@@ -208,8 +224,12 @@ if status then
vim.cmd("setlocal spell!")
end
vim.api.nvim_set_keymap("n", "<localleader><localleader>", ":lua DisplayAllMappingsWithTelescope()<CR>", {})
whichkey.register({
-- TODO: this isn't working for the FSI ones - maybe we've moved to a different buffer by the time we ask for the keymap?
[vim.api.nvim_get_var("maplocalleader")] = {
DisplayAllMappingsWithTelescope,
"View all mappings",
},
["mp"] = {
MarkdownPreview,
"Preview Markdown in Lynx",
@@ -226,11 +246,6 @@ if status then
ChangeToCurrentDirectory,
"Switch CWD to the directory of the open buffer",
},
-- For some reason the command doesn't work at all if I map it in here,
-- whereas if we map it separately and *document* it in here then only the documentation doesn't work.
[vim.api.nvim_get_var("maplocalleader")] = {
"View all mappings",
},
["ss"] = {
ToggleSpell,
"Toggle spell-checker on or off",

View File

@@ -2,8 +2,6 @@ vim.g["fsharp#fsautocomplete_command"] = { "fsautocomplete" }
vim.g["fsharp#show_signature_on_cursor_move"] = 1
vim.g["fsharp#fsi_keymap"] = "none"
vim.api.nvim_create_augroup("FSharpGroup", {})
-- MASSIVE HACK - raised https://github.com/ionide/Ionide-vim/pull/78
local function captureLoadedProjects()
vim.fn.execute("redir => g:massive_hack_patrick_capture")
@@ -236,16 +234,18 @@ vim.api.nvim_create_user_command("BuildFSharpProject", function(opts)
end
end, { nargs = "?", complete = "file" })
local function SetupFSharpKeyBindings()
vim.api.nvim_create_autocmd("FileType", {
pattern = "fsharp",
callback = function()
local status, whichkey = pcall(require, "which-key")
if status then
whichkey.register({
["f"] = {
f = {
t = { ":call fsharp#showTooltip()<CR>", "Show F# Tooltip" },
["si"] = { ":call fsharp#toggleFsi()<CR>", "Toggle FSI (F# Interactive)" },
["sl"] = { ":call fsharp#sendLineToFsi()<cr>", "Send line to FSI (F# Interactive)" },
},
["b"] = {
b = {
p = {
a = { BuildFSharpProjects, "Build all projects" },
s = { ":BuildFSharpProject", "Build specified project" },
@@ -259,10 +259,5 @@ local function SetupFSharpKeyBindings()
vim.api.nvim_set_keymap("n", "<localleader>bpa", BuildFSharpProjects, { noremap = true })
vim.api.nvim_set_keymap("n", "<localleader>bps", ":BuildFSharpProject", { noremap = true })
end
end
vim.api.nvim_create_autocmd("FileType", {
group = "FSharpGroup",
pattern = "fsharp",
callback = SetupFSharpKeyBindings,
end,
})

View File

@@ -67,6 +67,7 @@ function ToggleLocList()
end
end
do
local whichkey_status, whichkey = pcall(require, "which-key")
if whichkey_status then
whichkey.register({
@@ -83,12 +84,14 @@ else
vim.keymap.set("n", "<localleader>ll", ToggleLocList)
vim.keymap.set("n", "<localleader>lf", vim.diagnostic.open_float)
end
end
-- Use LspAttach autocommand to only map the following keys
-- after the language server attaches to the current buffer
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
callback = function(ev)
local whichkey_status, whichkey = pcall(require, "which-key")
-- Enable completion triggered by <c-x><c-o>
vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc"

View File

@@ -17,6 +17,7 @@ dap.configurations.fsharp = {
},
}
do
local status, whichkey = pcall(require, "which-key")
if status then
whichkey.register({
@@ -55,9 +56,19 @@ else
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>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>dvv",
":lua require('dap.ui.widgets').hover()<CR>",
{ noremap = true }
)
vim.api.nvim_set_keymap(
"n",
"<localleader>dvs",
@@ -72,3 +83,4 @@ else
)
vim.api.nvim_set_keymap("n", "<localleader>dt", ":lua require('dap').terminate()<CR>", { noremap = true })
end
end