mirror of
https://github.com/Smaug123/nix-dotfiles
synced 2025-10-06 15:08:41 +00:00
Fix buffer-specific binds
This commit is contained in:
@@ -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)
|
||||
if node.mapping then
|
||||
local mapping = node.mapping
|
||||
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
|
||||
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
|
||||
-- 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)
|
||||
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",
|
||||
|
@@ -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,33 +234,30 @@ vim.api.nvim_create_user_command("BuildFSharpProject", function(opts)
|
||||
end
|
||||
end, { nargs = "?", complete = "file" })
|
||||
|
||||
local function SetupFSharpKeyBindings()
|
||||
local status, whichkey = pcall(require, "which-key")
|
||||
if status then
|
||||
whichkey.register({
|
||||
["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"] = {
|
||||
p = {
|
||||
a = { BuildFSharpProjects, "Build all projects" },
|
||||
s = { ":BuildFSharpProject", "Build specified project" },
|
||||
},
|
||||
},
|
||||
}, { prefix = vim.api.nvim_get_var("maplocalleader"), buffer = vim.api.nvim_get_current_buf() })
|
||||
else
|
||||
vim.api.nvim_set_keymap("n", "<localleader>ft", ":call fsharp#showTooltip()<CR>", { noremap = true })
|
||||
vim.api.nvim_set_keymap("n", "<localleader>fsi", ":call fsharp#toggleFsi()<CR>", { noremap = true })
|
||||
vim.api.nvim_set_keymap("n", "<localleader>fsl", ":call fsharp#sendLineToFsi()<CR>", { noremap = true })
|
||||
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,
|
||||
callback = function()
|
||||
local status, whichkey = pcall(require, "which-key")
|
||||
if status then
|
||||
whichkey.register({
|
||||
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 = {
|
||||
p = {
|
||||
a = { BuildFSharpProjects, "Build all projects" },
|
||||
s = { ":BuildFSharpProject", "Build specified project" },
|
||||
},
|
||||
},
|
||||
}, { prefix = vim.api.nvim_get_var("maplocalleader"), buffer = vim.api.nvim_get_current_buf() })
|
||||
else
|
||||
vim.api.nvim_set_keymap("n", "<localleader>ft", ":call fsharp#showTooltip()<CR>", { noremap = true })
|
||||
vim.api.nvim_set_keymap("n", "<localleader>fsi", ":call fsharp#toggleFsi()<CR>", { noremap = true })
|
||||
vim.api.nvim_set_keymap("n", "<localleader>fsl", ":call fsharp#sendLineToFsi()<CR>", { noremap = true })
|
||||
vim.api.nvim_set_keymap("n", "<localleader>bpa", BuildFSharpProjects, { noremap = true })
|
||||
vim.api.nvim_set_keymap("n", "<localleader>bps", ":BuildFSharpProject", { noremap = true })
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
@@ -67,21 +67,23 @@ function ToggleLocList()
|
||||
end
|
||||
end
|
||||
|
||||
local whichkey_status, whichkey = pcall(require, "which-key")
|
||||
if whichkey_status then
|
||||
whichkey.register({
|
||||
l = {
|
||||
p = { vim.diagnostic.goto_prev, "Go to previous entry in loclist" },
|
||||
n = { vim.diagnostic.goto_next, "Go to next entry in loclist" },
|
||||
l = { ToggleLocList, "Toggle loclist" },
|
||||
f = { vim.diagnostic.open_float, "Open current loclist entry in floating window" },
|
||||
},
|
||||
}, { prefix = vim.api.nvim_get_var("maplocalleader") })
|
||||
else
|
||||
vim.keymap.set("n", "<localleader>lp", vim.diagnostic.goto_prev)
|
||||
vim.keymap.set("n", "<localleader>ln", vim.diagnostic.goto_next)
|
||||
vim.keymap.set("n", "<localleader>ll", ToggleLocList)
|
||||
vim.keymap.set("n", "<localleader>lf", vim.diagnostic.open_float)
|
||||
do
|
||||
local whichkey_status, whichkey = pcall(require, "which-key")
|
||||
if whichkey_status then
|
||||
whichkey.register({
|
||||
l = {
|
||||
p = { vim.diagnostic.goto_prev, "Go to previous entry in loclist" },
|
||||
n = { vim.diagnostic.goto_next, "Go to next entry in loclist" },
|
||||
l = { ToggleLocList, "Toggle loclist" },
|
||||
f = { vim.diagnostic.open_float, "Open current loclist entry in floating window" },
|
||||
},
|
||||
}, { prefix = vim.api.nvim_get_var("maplocalleader") })
|
||||
else
|
||||
vim.keymap.set("n", "<localleader>lp", vim.diagnostic.goto_prev)
|
||||
vim.keymap.set("n", "<localleader>ln", vim.diagnostic.goto_next)
|
||||
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
|
||||
@@ -89,6 +91,7 @@ end
|
||||
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"
|
||||
|
||||
|
@@ -17,58 +17,70 @@ dap.configurations.fsharp = {
|
||||
},
|
||||
}
|
||||
|
||||
local status, whichkey = pcall(require, "which-key")
|
||||
if status then
|
||||
whichkey.register({
|
||||
d = {
|
||||
o = { dap.step_over, "Step over" },
|
||||
i = { dap.step_into, "Step into" },
|
||||
c = { dap.continue, "Continue" },
|
||||
C = { dap.run_last, "Run with last debug configuration" },
|
||||
b = { dap.toggle_breakpoint, "Toggle breakpoint" },
|
||||
r = { dap.repl.open, "Open debug repl" },
|
||||
v = {
|
||||
do
|
||||
local status, whichkey = pcall(require, "which-key")
|
||||
if status then
|
||||
whichkey.register({
|
||||
d = {
|
||||
o = { dap.step_over, "Step over" },
|
||||
i = { dap.step_into, "Step into" },
|
||||
c = { dap.continue, "Continue" },
|
||||
C = { dap.run_last, "Run with last debug configuration" },
|
||||
b = { dap.toggle_breakpoint, "Toggle breakpoint" },
|
||||
r = { dap.repl.open, "Open debug repl" },
|
||||
v = {
|
||||
function()
|
||||
dap_ui.hover()
|
||||
end,
|
||||
"View value of expression under cursor",
|
||||
},
|
||||
s = {
|
||||
function()
|
||||
dap_ui.sidebar(dap_ui.scopes).open()
|
||||
end,
|
||||
"View values of all variables in all scopes",
|
||||
},
|
||||
f = {
|
||||
function()
|
||||
dap_ui.sidebar(dap_ui.frames).open()
|
||||
end,
|
||||
"View stack frames",
|
||||
v = {
|
||||
function()
|
||||
dap_ui.hover()
|
||||
end,
|
||||
"View value of expression under cursor",
|
||||
},
|
||||
s = {
|
||||
function()
|
||||
dap_ui.sidebar(dap_ui.scopes).open()
|
||||
end,
|
||||
"View values of all variables in all scopes",
|
||||
},
|
||||
f = {
|
||||
function()
|
||||
dap_ui.sidebar(dap_ui.frames).open()
|
||||
end,
|
||||
"View stack frames",
|
||||
},
|
||||
},
|
||||
t = { dap.terminate, "Terminate/stop/end debug session" },
|
||||
},
|
||||
t = { dap.terminate, "Terminate/stop/end debug session" },
|
||||
},
|
||||
}, { prefix = vim.api.nvim_get_var("maplocalleader") })
|
||||
else
|
||||
vim.api.nvim_set_keymap("n", "<localleader>do", ":lua require('dap').step_over()<CR>", { noremap = true })
|
||||
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 })
|
||||
}, { prefix = vim.api.nvim_get_var("maplocalleader") })
|
||||
else
|
||||
vim.api.nvim_set_keymap("n", "<localleader>do", ":lua require('dap').step_over()<CR>", { noremap = true })
|
||||
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
|
||||
|
Reference in New Issue
Block a user