A new top-level ide/: install.sh places a hash-checked Neovim release, five third-party plugins each at one pinned commit, the LLeMbas plugin from nvim/, a generated colourscheme and a launcher, for one user and under its own NVIM_APPNAME. Built in a staging directory, started there once, then swapped in. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
223 lines
13 KiB
Lua
223 lines
13 KiB
Lua
-- Every key the IDE adds, in one table: the mappings, the hints that appear after <Space>, the
|
|
-- cheat sheet (:LLeMbasIdeKeys) and the table in the README are all made from it.
|
|
-- The leader is <Space>. Neovim's own keys are unchanged unless listed here.
|
|
local M = {}
|
|
|
|
local function pick(name, opts) return function() require("mini.pick").builtin[name](opts) end end
|
|
local function extra(name, opts) return function() require("mini.extra").pickers[name](opts) end end
|
|
local function ll(command) return require("llembas_ide.llembas").cmd(command) end
|
|
local function problem(count)
|
|
return function()
|
|
if vim.diagnostic.jump then return vim.diagnostic.jump({ count = count, float = true }) end
|
|
if count > 0 then vim.diagnostic.goto_next() else vim.diagnostic.goto_prev() end -- Neovim 0.10
|
|
end
|
|
end
|
|
local function mod(module, fn) return function(...) return require(module)[fn](...) end end
|
|
|
|
M.groups = {
|
|
{ "<Leader>f", "find" },
|
|
{ "<Leader>b", "buffer" },
|
|
{ "<Leader>c", "code" },
|
|
{ "<Leader>g", "git" },
|
|
{ "<Leader>l", "LLeMbas" },
|
|
{ "<Leader>s", "session" },
|
|
{ "<Leader>t", "terminal" },
|
|
{ "<Leader>u", "look" },
|
|
{ "<Leader>x", "problems" },
|
|
{ "<Leader>i", "IDE" },
|
|
}
|
|
|
|
-- { modes, keys, action, what it does, section }
|
|
M.map = {
|
|
-- Files and search
|
|
{ "n", "<Leader><Space>", pick("files"), "Find a file", "Find" },
|
|
{ "n", "<Leader>/", pick("grep_live"), "Search in files (needs rg)", "Find" },
|
|
{ "n", "<Leader>,", pick("buffers"), "Switch buffer", "Find" },
|
|
{ "n", "<Leader>e", function() require("mini.files").open(vim.api.nvim_buf_get_name(0)) end, "File explorer at this file", "Find" },
|
|
{ "n", "<Leader>E", function() require("mini.files").open(vim.fn.getcwd()) end, "File explorer at the working directory", "Find" },
|
|
{ "n", "<Leader>ff", pick("files"), "Find a file", "Find" },
|
|
{ "n", "<Leader>fg", pick("grep_live"), "Search in files (needs rg)", "Find" },
|
|
{ "n", "<Leader>fw", function() require("mini.pick").builtin.grep({ pattern = vim.fn.expand("<cword>") }) end, "Search the word under the cursor", "Find" },
|
|
{ "n", "<Leader>fb", pick("buffers"), "Open buffers", "Find" },
|
|
{ "n", "<Leader>fr", extra("oldfiles"), "Recent files", "Find" },
|
|
{ "n", "<Leader>fs", extra("lsp", { scope = "document_symbol" }), "Symbols in this file", "Find" },
|
|
{ "n", "<Leader>fS", extra("lsp", { scope = "workspace_symbol" }), "Symbols in the project", "Find" },
|
|
{ "n", "<Leader>fR", extra("lsp", { scope = "references" }), "References to the symbol under the cursor", "Find" },
|
|
{ "n", "<Leader>fd", extra("diagnostic", { scope = "all" }), "Problems in the project", "Find" },
|
|
{ "n", "<Leader>fh", pick("help"), "Help pages", "Find" },
|
|
{ "n", "<Leader>fk", extra("keymaps"), "All key mappings", "Find" },
|
|
{ "n", "<Leader>f.", pick("resume"), "The last search again", "Find" },
|
|
-- Buffers and windows
|
|
{ "n", "<Leader>bd", function() require("mini.bufremove").delete() end, "Close the buffer, keep the window", "Buffers" },
|
|
{ "n", "<Leader>bn", "<Cmd>bnext<CR>", "Next buffer", "Buffers" },
|
|
{ "n", "<Leader>bp", "<Cmd>bprevious<CR>", "Previous buffer", "Buffers" },
|
|
{ "n", "<S-l>", "<Cmd>bnext<CR>", "Next buffer", "Buffers" },
|
|
{ "n", "<S-h>", "<Cmd>bprevious<CR>", "Previous buffer", "Buffers" },
|
|
{ "n", "<Leader>w", "<Cmd>write<CR>", "Save", "Buffers" },
|
|
{ "n", "<Leader>q", "<Cmd>quit<CR>", "Close the window", "Buffers" },
|
|
{ "n", "<Esc>", "<Cmd>nohlsearch<CR>", "Clear the search highlight", "Buffers" },
|
|
-- Code
|
|
{ "n", "<Leader>ca", function() vim.lsp.buf.code_action() end, "Code action", "Code" },
|
|
{ "n", "<Leader>cr", function() vim.lsp.buf.rename() end, "Rename the symbol", "Code" },
|
|
{ { "n", "x" }, "<Leader>cf", mod("llembas_ide.plugins", "format"), "Format the file or the selection", "Code" },
|
|
{ "n", "<Leader>cd", function() vim.diagnostic.open_float() end, "The problem on this line", "Code" },
|
|
{ "n", "<Leader>cl", mod("llembas_ide.lsp", "guide"), "Language servers: found, missing, how to install", "Code" },
|
|
-- Problems
|
|
{ "n", "<Leader>xx", function() vim.diagnostic.setloclist() end, "Problems in this file, as a list", "Problems" },
|
|
{ "n", "<Leader>xw", function() vim.diagnostic.setqflist() end, "Problems in the project, as a list", "Problems" },
|
|
{ "n", "<Leader>xn", problem(1), "Next problem", "Problems" },
|
|
{ "n", "<Leader>xp", problem(-1), "Previous problem", "Problems" },
|
|
-- Git
|
|
{ "n", "<Leader>gs", extra("git_files", { scope = "modified" }), "Changed files", "Git" },
|
|
{ "n", "<Leader>gh", extra("git_hunks"), "Changes, hunk by hunk", "Git" },
|
|
{ "n", "<Leader>gd", mod("llembas_ide.git", "diff_head"), "This file beside its committed version", "Git" },
|
|
{ "n", "<Leader>go", function() require("mini.diff").toggle_overlay(0) end, "Show changes inline, on and off", "Git" },
|
|
{ "n", "<Leader>ga", mod("llembas_ide.git", "stage_hunk"), "Stage the change under the cursor", "Git" },
|
|
{ "n", "<Leader>gr", mod("llembas_ide.git", "reset_hunk"), "Undo the change under the cursor", "Git" },
|
|
{ "n", "<Leader>gb", function() require("mini.git").show_at_cursor() end, "Who changed this line, and the commit", "Git" },
|
|
-- LLeMbas
|
|
{ "n", "<Leader>ll", ll("LLeMbas"), "Chat panel, open and close", "LLeMbas" },
|
|
{ { "n", "x" }, "<Leader>la", ":LLeMbasAsk ", "Ask about the line or the selection (type the question)", "LLeMbas" },
|
|
{ { "n", "x" }, "<Leader>le", ":LLeMbasEdit ", "Have the line or the selection rewritten (type how)", "LLeMbas" },
|
|
{ { "n", "x" }, "<Leader>lx", ":LLeMbasExplain<CR>", "Explain the line or the selection", "LLeMbas" },
|
|
{ "n", "<Leader>lg", ":LLeMbasGenerate ", "Generate code at the cursor (type what)", "LLeMbas" },
|
|
{ "n", "<Leader>lf", ll("LLeMbasFix"), "Fix this file's problems", "LLeMbas" },
|
|
{ "n", "<Leader>lt", mod("llembas_ide.llembas", "toggle_autocomplete"), "Suggestions as you type, on and off", "LLeMbas" },
|
|
{ "n", "<Leader>lm", ll("LLeMbasMode"), "Change the mode", "LLeMbas" },
|
|
{ "n", "<Leader>lM", ll("LLeMbasModel"), "Change the model", "LLeMbas" },
|
|
{ "n", "<Leader>ls", ll("LLeMbasSessions"), "Earlier conversations", "LLeMbas" },
|
|
{ "n", "<Leader>ln", ll("LLeMbasNew"), "New conversation", "LLeMbas" },
|
|
{ "n", "<Leader>lc", ll("LLeMbasCommands"), "Commands and skills", "LLeMbas" },
|
|
{ "n", "<Leader>lS", ll("LLeMbasStatus"), "Status", "LLeMbas" },
|
|
{ "n", "<Leader>l.", ll("LLeMbasStop"), "Stop the running turn", "LLeMbas" },
|
|
{ "n", "<Leader>li", mod("llembas_ide.llembas", "sign_in"), "Sign in", "LLeMbas" },
|
|
{ "n", "<Leader>l?", ll("LLeMbasHelp"), "The plugin's commands and keys", "LLeMbas" },
|
|
-- Sessions
|
|
{ "n", "<Leader>sr", mod("llembas_ide.sessions", "restore"), "Restore this directory's session", "Session" },
|
|
{ "n", "<Leader>sw", mod("llembas_ide.sessions", "save"), "Save the session now", "Session" },
|
|
{ "n", "<Leader>sd", mod("llembas_ide.sessions", "delete"), "Forget this directory's session", "Session" },
|
|
-- Terminal
|
|
{ "n", "<Leader>tt", mod("llembas_ide.terminal", "toggle"), "Terminal, open and close", "Terminal" },
|
|
{ { "n", "t" }, "<C-/>", mod("llembas_ide.terminal", "toggle"), "Terminal, open and close", "Terminal" },
|
|
{ { "n", "t" }, "<C-_>", mod("llembas_ide.terminal", "toggle"), "The same, as some terminals send it", "Terminal" },
|
|
{ "t", "<Esc><Esc>", "<C-\\><C-n>", "Leave the terminal's typing mode", "Terminal" },
|
|
-- Look
|
|
{ "n", "<Leader>ut", function() vim.o.background = vim.o.background == "dark" and "light" or "dark" end, "Dark and light theme", "Look" },
|
|
{ "n", "<Leader>uw", function() vim.wo.wrap = not vim.wo.wrap end, "Wrap long lines, on and off", "Look" },
|
|
{ "n", "<Leader>un", function() vim.wo.relativenumber = not vim.wo.relativenumber end, "Relative line numbers, on and off", "Look" },
|
|
-- The IDE itself
|
|
{ "n", "<Leader>ih", mod("llembas_ide.dashboard", "open"), "Start screen", "IDE" },
|
|
{ "n", "<Leader>ik", function() M.show() end, "This list of keys", "IDE" },
|
|
{ "n", "<Leader>id", "<Cmd>LLeMbasIdeDoctor<CR>", "Check the installation", "IDE" },
|
|
{ "n", "<Leader>iu", "<Cmd>LLeMbasIdeConfig<CR>", "Open your own settings file", "IDE" },
|
|
{ "n", "<Leader>iv", "<Cmd>LLeMbasIdeVersion<CR>", "Versions", "IDE" },
|
|
}
|
|
|
|
-- Added to a buffer when a language server attaches to it.
|
|
M.lsp = {
|
|
{ "n", "gd", function() vim.lsp.buf.definition() end, "Go to the definition" },
|
|
{ "n", "gD", function() vim.lsp.buf.declaration() end, "Go to the declaration" },
|
|
{ "n", "gI", function() vim.lsp.buf.implementation() end, "Go to the implementation" },
|
|
{ "n", "gy", function() vim.lsp.buf.type_definition() end, "Go to the type's definition" },
|
|
}
|
|
|
|
-- Keys that are not the IDE's mappings but belong on the cheat sheet: plugins' and Neovim's own.
|
|
M.also = {
|
|
{ "i", "<Tab>", "Accept LLeMbas's suggestion (the grey text)", "Typing" },
|
|
{ "i", "<M-Right>", "Accept one word of it", "Typing" },
|
|
{ "i", "<M-\\>", "Ask for a suggestion now", "Typing" },
|
|
{ "i", "<C-n> <C-p>", "Move in the completion menu (also <Down> <Up>)", "Typing" },
|
|
{ "i", "<CR>", "Take the menu entry you moved to; otherwise a new line", "Typing" },
|
|
{ "i", "<C-y>", "Take the menu's first entry", "Typing" },
|
|
{ "i", "<C-e>", "Close the menu", "Typing" },
|
|
{ "i", "<C-Space>", "Open the menu, or the entry's documentation", "Typing" },
|
|
{ "n", "gcc", "Comment the line, on and off (gc with a motion or a selection)", "Editing" },
|
|
{ "n", "sa sd sr", "Surround: add (saiw\"), delete (sd\"), replace (sr\"')", "Editing" },
|
|
{ "n", "K", "Documentation of the symbol under the cursor", "Editing" },
|
|
{ "n", "gd gD gI gy", "Definition, declaration, implementation, type (with a language server)", "Editing" },
|
|
{ "n", "]g [g", "Next and previous git change (]G [G: last and first)", "Git" },
|
|
{ "n", "ga gr", "Accept or reject LLeMbas's proposed change (gA gR: all; ]h [h: move)", "LLeMbas" },
|
|
}
|
|
|
|
local function modes(m) return type(m) == "table" and m or { m } end
|
|
|
|
--- Bindings given more than once (the same mode and keys), as text. Empty when the map is sound.
|
|
function M.duplicates()
|
|
local seen, dup = {}, {}
|
|
for _, list in ipairs({ M.map, M.lsp }) do
|
|
for _, k in ipairs(list) do
|
|
for _, mode in ipairs(modes(k[1])) do
|
|
local id = mode .. " " .. vim.api.nvim_replace_termcodes(k[2], true, true, true)
|
|
if seen[id] then table.insert(dup, mode .. " " .. k[2]) end
|
|
seen[id] = true
|
|
end
|
|
end
|
|
end
|
|
return dup
|
|
end
|
|
|
|
function M.setup()
|
|
for _, k in ipairs(M.map) do
|
|
vim.keymap.set(k[1], k[2], k[3], { desc = k[4], silent = type(k[3]) ~= "string" or k[3]:sub(1, 1) ~= ":" })
|
|
end
|
|
end
|
|
|
|
local function shown(lhs) return (lhs:gsub("<Leader>", "<Space>")) end
|
|
local mode_names = { n = "normal", x = "visual", i = "insert", t = "terminal" }
|
|
local function mode_text(m)
|
|
local out = {}
|
|
for _, mode in ipairs(modes(m)) do table.insert(out, mode_names[mode] or mode) end
|
|
return table.concat(out, ", ")
|
|
end
|
|
|
|
--- The sections of the cheat sheet in order: { name, { {keys, modes, text}, … } }.
|
|
function M.sections()
|
|
local order, by = {}, {}
|
|
local function add(section, keys, mode, text)
|
|
if not by[section] then
|
|
by[section] = {}
|
|
table.insert(order, section)
|
|
end
|
|
table.insert(by[section], { shown(keys), mode_text(mode), text })
|
|
end
|
|
for _, k in ipairs(M.also) do if k[4] == "Typing" or k[4] == "Editing" then add(k[4], k[2], k[1], k[3]) end end
|
|
for _, k in ipairs(M.map) do add(k[5], k[2], k[1], k[4]) end
|
|
for _, k in ipairs(M.also) do if k[4] ~= "Typing" and k[4] ~= "Editing" then add(k[4], k[2], k[1], k[3]) end end
|
|
local out = {}
|
|
for _, name in ipairs(order) do table.insert(out, { name, by[name] }) end
|
|
return out
|
|
end
|
|
|
|
--- The cheat sheet as the README has it.
|
|
function M.markdown()
|
|
local out = {}
|
|
for _, s in ipairs(M.sections()) do
|
|
vim.list_extend(out, { "**" .. s[1] .. "**", "", "| Keys | In | What it does |", "|---|---|---|" })
|
|
for _, r in ipairs(s[2]) do
|
|
table.insert(out, ("| `%s` | %s | %s |"):format(r[1]:gsub("|", "\\|"), r[2], (r[3]:gsub("|", "\\|"))))
|
|
end
|
|
table.insert(out, "")
|
|
end
|
|
return out
|
|
end
|
|
|
|
--- :LLeMbasIdeKeys
|
|
function M.show()
|
|
local lines, titles = { "The leader key is <Space>. Press it and wait: the next keys are shown.", "" }, {}
|
|
for _, s in ipairs(M.sections()) do
|
|
table.insert(lines, s[1])
|
|
table.insert(titles, #lines - 1)
|
|
for _, r in ipairs(s[2]) do
|
|
table.insert(lines, (" %-16s %-16s %s"):format(r[1], r[2], r[3]))
|
|
end
|
|
table.insert(lines, "")
|
|
end
|
|
local buf = require("llembas_ide.ui").page("LLeMbas IDE: keys", lines)
|
|
for _, l in ipairs(titles) do vim.api.nvim_buf_add_highlight(buf, -1, "Title", l, 0, -1) end
|
|
for i = 2, #lines - 1 do
|
|
if lines[i + 1]:sub(1, 2) == " " then vim.api.nvim_buf_add_highlight(buf, -1, "LLeMbasIdeKey", i, 2, 18) end
|
|
end
|
|
end
|
|
|
|
return M
|