diff --git a/nvim/.editorconfig b/nvim/.editorconfig index 29ac6fa..1b922a7 100644 --- a/nvim/.editorconfig +++ b/nvim/.editorconfig @@ -1,8 +1,7 @@ root = true -# Unix-style newlines with a newline ending every file -[*] +[*.lua] end_of_line = lf insert_final_newline = true indent_style = space -indent_size = 4 +indent_size = 2 diff --git a/nvim/after/ftplugin/lua.lua b/nvim/after/ftplugin/lua.lua new file mode 100644 index 0000000..e69de29 diff --git a/nvim/init.lua b/nvim/init.lua index abe3a63..9483407 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -1,17 +1,3 @@ - - - --- vim.cmd.colorscheme("gruvbox") --- vim.lsp.enable('lua_ls') --- --- require("mason").setup() --- require("mason-lspconfig").setup { --- ensure_installed = { "lua_ls" } --- } --- local ls = require("luasnip") --- ls.setup({ --- enable_autosnippets = true --- }) require("kanopo.options") require("kanopo.autocmds") require("kanopo.plugins") diff --git a/nvim/lua/kanopo/autocmds.lua b/nvim/lua/kanopo/autocmds.lua index 2eddef4..3425945 100644 --- a/nvim/lua/kanopo/autocmds.lua +++ b/nvim/lua/kanopo/autocmds.lua @@ -33,3 +33,21 @@ vim.api.nvim_create_autocmd("BufReadPost", { end end, }) + +vim.api.nvim_create_autocmd('LspAttach', { + group = vim.api.nvim_create_augroup('my.lsp', {}), + callback = function(args) + local client = assert(vim.lsp.get_client_by_id(args.data.client_id)) + -- Usually not needed if server supports "textDocument/willSaveWaitUntil". + if not client:supports_method('textDocument/willSaveWaitUntil') + and client:supports_method('textDocument/formatting') then + vim.api.nvim_create_autocmd('BufWritePre', { + group = vim.api.nvim_create_augroup('my.lsp', { clear = false }), + buffer = args.buf, + callback = function() + vim.lsp.buf.format({ bufnr = args.buf, id = client.id, timeout_ms = 1000 }) + end, + }) + end + end, +}) diff --git a/nvim/lua/kanopo/plugins/cmp.lua b/nvim/lua/kanopo/plugins/cmp.lua new file mode 100644 index 0000000..6857053 --- /dev/null +++ b/nvim/lua/kanopo/plugins/cmp.lua @@ -0,0 +1,28 @@ +vim.pack.add({ + { src = "https://github.com/saghen/blink.cmp", version = "1.*" }, + { src = "https://github.com/rafamadriz/friendly-snippets" } +}) + +-- Load packs on startup (guard for nightlies without load) +vim.api.nvim_create_autocmd("VimEnter", { + once = true, + callback = function() + if vim.pack and vim.pack.load then pcall(vim.pack.load) end + + -- Preload neogit module if available (optional) + pcall(function() + require("blink").setup({ + -- 'default' (recommended) for mappings similar to built-in completions (C-y to accept): + -- 'super-tab' for mappings similar to vscode (tab to accept) + -- 'enter' for enter to accept + -- 'none' for no mappings + -- All presets have the following mappings: + -- C-space: Open menu or open docs if already open + -- C-n/C-p or Up/Down: Select next/previous item + -- C-e: Hide menu + -- C-k: Toggle signature help (if signature.enabled = true) + keymap = { preset = 'default' }, + }) + end) + end, +}) diff --git a/nvim/lua/kanopo/plugins/git.lua b/nvim/lua/kanopo/plugins/git.lua index c2674d6..48151bf 100644 --- a/nvim/lua/kanopo/plugins/git.lua +++ b/nvim/lua/kanopo/plugins/git.lua @@ -1,37 +1,37 @@ -- Declare plugins vim.pack.add({ - { src = "https://github.com/NeogitOrg/neogit" }, - { src = "https://github.com/lewis6991/gitsigns.nvim" }, + { src = "https://github.com/NeogitOrg/neogit" }, + { src = "https://github.com/lewis6991/gitsigns.nvim" }, }) -- Load packs on startup (guard for nightlies without load) vim.api.nvim_create_autocmd("VimEnter", { - once = true, - callback = function() - if vim.pack and vim.pack.load then pcall(vim.pack.load) end + once = true, + callback = function() + if vim.pack and vim.pack.load then pcall(vim.pack.load) end - -- Configure gitsigns (safe pcall) - pcall(function() - require("gitsigns").setup() - end) + -- Configure gitsigns (safe pcall) + pcall(function() + require("gitsigns").setup() + end) - -- Preload neogit module if available (optional) - pcall(function() - require("neogit") - end) - end, + -- Preload neogit module if available (optional) + pcall(function() + require("neogit") + end) + end, }) -- Keymap: open Neogit (on-demand load if needed) vim.keymap.set("n", "gg", function() - local ok, neogit = pcall(require, "neogit") - if not ok then - if vim.pack and vim.pack.load then pcall(vim.pack.load) end - ok, neogit = pcall(require, "neogit") - end - if ok then - neogit.open({}) - else - vim.notify("neogit not available yet", vim.log.levels.WARN) - end + local ok, neogit = pcall(require, "neogit") + if not ok then + if vim.pack and vim.pack.load then pcall(vim.pack.load) end + ok, neogit = pcall(require, "neogit") + end + if ok then + neogit.open({}) + else + vim.notify("neogit not available yet", vim.log.levels.WARN) + end end, { desc = "Open Neogit" }) diff --git a/nvim/lua/kanopo/plugins/init.lua b/nvim/lua/kanopo/plugins/init.lua index f7a00e2..4856413 100644 --- a/nvim/lua/kanopo/plugins/init.lua +++ b/nvim/lua/kanopo/plugins/init.lua @@ -1,8 +1,9 @@ --- require("kanopo.plugins.lazydev") +require("kanopo.plugins.lazydev") require("kanopo.plugins.oil") require("kanopo.plugins.theme") require("kanopo.plugins.treesitter") require("kanopo.plugins.telescope") +require("kanopo.plugins.cmp") require("kanopo.plugins.lsp") require("kanopo.plugins.which-key") require("kanopo.plugins.git") diff --git a/nvim/lua/kanopo/plugins/lsp.lua b/nvim/lua/kanopo/plugins/lsp.lua index a659aa4..51677b0 100644 --- a/nvim/lua/kanopo/plugins/lsp.lua +++ b/nvim/lua/kanopo/plugins/lsp.lua @@ -1,190 +1,192 @@ vim.pack.add({ - { src = "https://github.com/neovim/nvim-lspconfig" }, - { src = "https://github.com/mason-org/mason.nvim" }, - { src = "https://github.com/mason-org/mason-lspconfig.nvim" }, - { src = "https://github.com/WhoIsSethDaniel/mason-tool-installer.nvim" }, -- optional for tools later - { src = "https://github.com/L3MON4D3/LuaSnip" }, - { src = "https://github.com/rafamadriz/friendly-snippets" }, + { src = "https://github.com/neovim/nvim-lspconfig" }, + { src = "https://github.com/mason-org/mason.nvim" }, + { src = "https://github.com/mason-org/mason-lspconfig.nvim" }, + { src = "https://github.com/WhoIsSethDaniel/mason-tool-installer.nvim" }, -- optional for tools later + + { src = "https://github.com/saghen/blink.cmp", version = "1.*" }, + -- { src = "https://github.com/L3MON4D3/LuaSnip" }, + -- { src = "https://github.com/rafamadriz/friendly-snippets" }, }) -- Load packs early (guard API) vim.api.nvim_create_autocmd("VimEnter", { - once = true, - callback = function() - if vim.pack and vim.pack.load then pcall(vim.pack.load) end - end, + once = true, + callback = function() + if vim.pack and vim.pack.load then pcall(vim.pack.load) end + end, }) -- Servers you want local lsp_servers = { - "lua_ls", - "ts_ls", - "texlab", - "marksman", - "docker_compose_language_service", - "dockerls", - "tailwindcss", - "cssls", - "clangd", - "rust_analyzer", - "gopls", + "lua_ls", + "ts_ls", + "texlab", + "marksman", + "docker_compose_language_service", + "dockerls", + "tailwindcss", + "cssls", + "clangd", + "rust_analyzer", + "gopls", } -- Optional: tools you might install later (kept, but not used for formatting here) local tools = { - "luacheck", - "latexindent", - "prettierd", + "luacheck", + "latexindent", + "prettierd", } -- Mason + mason-lspconfig do - local ok, mason = pcall(require, "mason") - if ok then mason.setup() end + local ok, mason = pcall(require, "mason") + if ok then mason.setup() end - local ok_mlsp, mlsp = pcall(require, "mason-lspconfig") - if ok_mlsp then - mlsp.setup({ - ensure_installed = lsp_servers, - automatic_enable = true, -- v2 - }) - end + local ok_mlsp, mlsp = pcall(require, "mason-lspconfig") + if ok_mlsp then + mlsp.setup({ + ensure_installed = lsp_servers, + automatic_enable = true, -- v2 + }) + end - -- If you want mason-tool-installer to fetch tools only (no config in this file): - local ok_mti, mti = pcall(require, "mason-tool-installer") - if ok_mti then - mti.setup({ - ensure_installed = tools, -- harmless to keep; you can remove if you prefer - automatic_installation = true, - }) - end + -- If you want mason-tool-installer to fetch tools only (no config in this file): + local ok_mti, mti = pcall(require, "mason-tool-installer") + if ok_mti then + mti.setup({ + ensure_installed = tools, -- harmless to keep; you can remove if you prefer + automatic_installation = true, + }) + end + local ok_ls, ls = pcall(require, "luasnip") + if ok_ls then + ls.config.set_config({ + history = true, + enable_autosnippets = false, + }) + + -- Load VSCode-style snippets from friendly-snippets (and any other VSCode snippet dirs on rtp) + -- pcall(function() + -- require("luasnip.loaders.from_vscode").lazy_load() + -- end) + + -- Your Tab/Shift-Tab mappings... + end end -- Shared on_attach: native omni + Telescope pickers local function on_attach(_, bufnr) - vim.api.nvim_set_option_value("omnifunc", "v:lua.vim.lsp.omnifunc", { buf = bufnr }) - vim.api.nvim_set_option_value("tagfunc", "v:lua.vim.lsp.tagfunc", { buf = bufnr }) + vim.api.nvim_set_option_value("omnifunc", "v:lua.vim.lsp.omnifunc", { buf = bufnr }) + vim.api.nvim_set_option_value("tagfunc", "v:lua.vim.lsp.tagfunc", { buf = bufnr }) - local function map(mode, lhs, rhs, desc) - vim.keymap.set(mode, lhs, rhs, { buffer = bufnr, noremap = true, silent = true, desc = desc }) + local function map(mode, lhs, rhs, desc) + vim.keymap.set(mode, lhs, rhs, { buffer = bufnr, noremap = true, silent = true, desc = desc }) + end + + -- Telescope-powered LSP navigation (loads telescope.builtin on demand) + local function tb(fn) + return function() + local ok, builtin = pcall(require, "telescope.builtin") + if not ok then + if vim.pack and vim.pack.load then pcall(vim.pack.load) end + ok, builtin = pcall(require, "telescope.builtin") + end + if ok and builtin[fn] then + builtin[fn]() + else + vim.notify("Telescope not available", vim.log.levels.WARN) + end end + end - local group = vim.api.nvim_create_augroup("LspFormatOnSave_" .. bufnr, { clear = true }) - vim.api.nvim_create_autocmd("BufWritePre", { - group = group, - buffer = bufnr, - callback = function() - -- Prefer synchronous formatting with timeout to avoid blocking too long - if vim.lsp.buf.format then - vim.lsp.buf.format({ - async = false, - timeout_ms = 1500, - }) - end - end, - desc = "LSP format before save", - }) + map("n", "gd", tb("lsp_definitions"), "Goto Definition (Telescope)") + map("n", "gr", tb("lsp_references"), "Goto References (Telescope)") + map("n", "gI", tb("lsp_implementations"), "Goto Implementations (Telescope)") + map("n", "gt", tb("lsp_type_definitions"), "Goto Type Definitions (Telescope)") - -- Telescope-powered LSP navigation (loads telescope.builtin on demand) - local function tb(fn) - return function() - local ok, builtin = pcall(require, "telescope.builtin") - if not ok then - if vim.pack and vim.pack.load then pcall(vim.pack.load) end - ok, builtin = pcall(require, "telescope.builtin") - end - if ok and builtin[fn] then - builtin[fn]() - else - vim.notify("Telescope not available", vim.log.levels.WARN) - end - end - end + -- LSP basics + map("n", "K", vim.lsp.buf.hover, "Hover") + map("n", "rn", vim.lsp.buf.rename, "Rename") + map({ "n", "v" }, "ca", vim.lsp.buf.code_action, "Code Action") + map("n", "[d", vim.diagnostic.goto_prev, "Prev Diagnostic") + map("n", "]d", vim.diagnostic.goto_next, "Next Diagnostic") + map("n", "e", vim.diagnostic.open_float, "Line Diagnostics") - map("n", "gd", tb("lsp_definitions"), "Goto Definition (Telescope)") - map("n", "gr", tb("lsp_references"), "Goto References (Telescope)") - map("n", "gI", tb("lsp_implementations"), "Goto Implementations (Telescope)") - map("n", "gt", tb("lsp_type_definitions"), "Goto Type Definitions (Telescope)") - - -- LSP basics - map("n", "K", vim.lsp.buf.hover, "Hover") - map("n", "rn", vim.lsp.buf.rename, "Rename") - map({ "n", "v" }, "ca", vim.lsp.buf.code_action, "Code Action") - map("n", "[d", vim.diagnostic.goto_prev, "Prev Diagnostic") - map("n", "]d", vim.diagnostic.goto_next, "Next Diagnostic") - map("n", "e", vim.diagnostic.open_float, "Line Diagnostics") - - pcall(vim.lsp.inlay_hint.enable, true, { bufnr = bufnr }) + pcall(vim.lsp.inlay_hint.enable, true, { bufnr = bufnr }) end + -- Global LSP defaults vim.lsp.config("*", { - on_attach = on_attach, - capabilities = (function() - local caps = vim.lsp.protocol.make_client_capabilities() - caps.textDocument = caps.textDocument or {} - caps.textDocument.foldingRange = { dynamicRegistration = false, lineFoldingOnly = true } - return caps - end)(), + on_attach = on_attach, + capabilities = require('blink.cmp').get_lsp_capabilities() + -- capabilities = (function() + -- local caps = vim.lsp.protocol.make_client_capabilities() + -- caps.textDocument = caps.textDocument or {} + -- caps.textDocument.foldingRange = { dynamicRegistration = false, lineFoldingOnly = true } + -- return caps + -- end)(), }) --- Server-specific tweaks -vim.lsp.config("lua_ls", { - settings = { - Lua = { - diagnostics = { globals = { "vim", "require" } }, - completion = { callSnippet = "Replace" }, - workspace = { checkThirdParty = false }, - }, - }, -}) +-- -- Server-specific tweaks +-- vim.lsp.config("lua_ls", { +-- settings = { +-- Lua = { +-- diagnostics = { globals = { "vim", "require" } }, +-- completion = { callSnippet = "Replace" }, +-- workspace = { checkThirdParty = false }, +-- }, +-- }, +-- }) -- Enable servers (Neovim 0.11+) vim.lsp.enable(lsp_servers) --- Trigger omni (like cmp.complete) -vim.keymap.set("i", "", function() - if vim.bo.omnifunc == "v:lua.vim.lsp.omnifunc" then - return vim.api.nvim_replace_termcodes("", true, true, true) - end - return "" -end, { expr = true, silent = true, desc = "Trigger omni-completion" }) - --- Navigate popup menu -vim.keymap.set("i", "", "", { silent = true, desc = "Omni next item" }) -vim.keymap.set("i", "", "", { silent = true, desc = "Omni prev item" }) - --- Enter to confirm when pum is visible, otherwise newline -vim.keymap.set("i", "", function() - if vim.fn.pumvisible() == 1 then - -- Confirm current selection; if none selected, accept first - return vim.api.nvim_replace_termcodes("", true, true, true) - end - return vim.api.nvim_replace_termcodes("", true, true, true) -end, { expr = true, silent = true, desc = "Confirm completion or newline" }) - --- Requires your existing LuaSnip setup and mappings -local ok_ls, ls = pcall(require, "luasnip") -if ok_ls then - -- Tab: if menu visible, next item; else snippet expand/jump; else literal Tab - vim.keymap.set({ "i", "s" }, "", function() - if vim.fn.pumvisible() == 1 then - return vim.api.nvim_replace_termcodes("", true, true, true) - elseif ls.expand_or_jumpable() then - return "luasnip-expand-or-jump" - else - return "" - end - end, { expr = true, silent = true, desc = "Next item / Snippet jump / Tab" }) - - -- Shift-Tab: if menu visible, prev item; else snippet jump back; else literal - vim.keymap.set({ "i", "s" }, "", function() - if vim.fn.pumvisible() == 1 then - return vim.api.nvim_replace_termcodes("", true, true, true) - elseif ls.jumpable(-1) then - return "luasnip-jump-prev" - else - return "" - end - end, { expr = true, silent = true, desc = "Prev item / Snippet back / Shift-Tab" }) -end +-- -- Trigger omni (like cmp.complete) +-- vim.keymap.set("i", "", function() +-- if vim.bo.omnifunc == "v:lua.vim.lsp.omnifunc" then +-- return vim.api.nvim_replace_termcodes("", true, true, true) +-- end +-- return "" +-- end, { expr = true, silent = true, desc = "Trigger omni-completion" }) +-- +-- -- Navigate popup menu +-- vim.keymap.set("i", "", "", { silent = true, desc = "Omni next item" }) +-- vim.keymap.set("i", "", "", { silent = true, desc = "Omni prev item" }) +-- +-- -- Enter to confirm when pum is visible, otherwise newline +-- vim.keymap.set("i", "", function() +-- if vim.fn.pumvisible() == 1 then +-- -- Confirm current selection; if none selected, accept first +-- return vim.api.nvim_replace_termcodes("", true, true, true) +-- end +-- return vim.api.nvim_replace_termcodes("", true, true, true) +-- end, { expr = true, silent = true, desc = "Confirm completion or newline" }) +-- +-- -- Requires your existing LuaSnip setup and mappings +-- local ok_ls, ls = pcall(require, "luasnip") +-- if ok_ls then +-- -- Tab: if menu visible, next item; else snippet expand/jump; else literal Tab +-- vim.keymap.set({ "i", "s" }, "", function() +-- if vim.fn.pumvisible() == 1 then +-- return vim.api.nvim_replace_termcodes("", true, true, true) +-- elseif ls.expand_or_jumpable() then +-- return "luasnip-expand-or-jump" +-- else +-- return "" +-- end +-- end, { expr = true, silent = true, desc = "Next item / Snippet jump / Tab" }) +-- +-- -- Shift-Tab: if menu visible, prev item; else snippet jump back; else literal +-- vim.keymap.set({ "i", "s" }, "", function() +-- if vim.fn.pumvisible() == 1 then +-- return vim.api.nvim_replace_termcodes("", true, true, true) +-- elseif ls.jumpable(-1) then +-- return "luasnip-jump-prev" +-- else +-- return "" +-- end +-- end, { expr = true, silent = true, desc = "Prev item / Snippet back / Shift-Tab" }) +-- end diff --git a/nvim/lua/kanopo/plugins/telescope.lua b/nvim/lua/kanopo/plugins/telescope.lua index 1c1c356..e8a8645 100644 --- a/nvim/lua/kanopo/plugins/telescope.lua +++ b/nvim/lua/kanopo/plugins/telescope.lua @@ -1,9 +1,9 @@ -- Ensure packs are added vim.pack.add({ - { src = "https://github.com/nvim-lua/plenary.nvim", version = "master" }, - { src = "https://github.com/nvim-telescope/telescope.nvim", version = "master" }, + { src = "https://github.com/nvim-lua/plenary.nvim", version = "master" }, + { src = "https://github.com/nvim-telescope/telescope.nvim", version = "master" }, -- Optional native sorter (requires a C toolchain) - { src = "https://github.com/nvim-telescope/telescope-fzf-native.nvim", version = "main", build = "make" }, + { src = "https://github.com/nvim-telescope/telescope-fzf-native.nvim", version = "main", build = "make" }, }) -- Helper: find fzf-native root and build/lib path if installed @@ -42,10 +42,12 @@ local function telescope_setup() telescope.setup({ pickers = { find_files = { + theme = "ivy", hidden = true, prompt_prefix = "🔍 ", }, live_grep = { + theme = "ivy", hidden = true, prompt_prefix = "🔍 ", }, diff --git a/nvim/main.ts b/nvim/main.ts index a4fc83b..e69de29 100644 --- a/nvim/main.ts +++ b/nvim/main.ts @@ -1,6 +0,0 @@ - -const ciao = () => { - console.log("ciao") -} - -ciao()