From f494b1840a2507e3f117d62321b42fee7b7f1ecd Mon Sep 17 00:00:00 2001 From: tracer Date: Tue, 31 Mar 2026 23:13:00 +0200 Subject: [PATCH] added LSP and treesitter --- karabiner/karabiner.json | 2 +- nvim/lua/tracer/options.lua | 2 + nvim/lua/tracer/plugins.lua | 49 +++++++++++++- nvim/lua/tracer/plugins/fugitive.lua | 90 ++++++++++++++++++++++++++ nvim/lua/tracer/plugins/lspconfig.lua | 34 ++++++++++ nvim/lua/tracer/plugins/treesitter.lua | 30 +++++++++ 6 files changed, 205 insertions(+), 2 deletions(-) create mode 100644 nvim/lua/tracer/plugins/fugitive.lua create mode 100644 nvim/lua/tracer/plugins/lspconfig.lua create mode 100644 nvim/lua/tracer/plugins/treesitter.lua diff --git a/karabiner/karabiner.json b/karabiner/karabiner.json index 162182a..2932e91 100644 --- a/karabiner/karabiner.json +++ b/karabiner/karabiner.json @@ -80,7 +80,7 @@ "key_code": "vk_none" }, { - "shell_command": "/Applications/kitty.app/Contents/MacOS/kitty --single-instance --directory ~" + "shell_command": "/usr/bin/osascript -e 'tell application \"kitty\" to activate' -e 'tell application \"System Events\" to keystroke return using command down'" } ], "type": "basic" diff --git a/nvim/lua/tracer/options.lua b/nvim/lua/tracer/options.lua index cca1497..b18b8ee 100644 --- a/nvim/lua/tracer/options.lua +++ b/nvim/lua/tracer/options.lua @@ -7,6 +7,7 @@ opt.laststatus = 2 opt.termguicolors = true opt.autoread = true opt.mouse = "a" +opt.clipboard:append("unnamedplus") opt.expandtab = true opt.shiftwidth = 4 opt.tabstop = 4 @@ -15,6 +16,7 @@ opt.smartindent = true opt.wrap = false opt.wildmode = "longest:full,full" opt.title = true +opt.signcolumn = 'yes:1' vim.cmd.colorscheme("slate") diff --git a/nvim/lua/tracer/plugins.lua b/nvim/lua/tracer/plugins.lua index cf26f3a..02dfef7 100644 --- a/nvim/lua/tracer/plugins.lua +++ b/nvim/lua/tracer/plugins.lua @@ -107,6 +107,53 @@ require("packer").startup(function(use) vim.g.pasta_disabled_filetypes = { "fugitive" } end, }) + -- Git integration. + use({ + "lewis6991/gitsigns.nvim", + config = function() + require("gitsigns").setup({ current_line_blame = true }) + + vim.keymap.set("n", "]h", ":Gitsigns next_hunk") + vim.keymap.set("n", "[h", ":Gitsigns prev_hunk") + vim.keymap.set("n", "gs", ":Gitsigns stage_hunk") + vim.keymap.set("n", "gS", ":Gitsigns undo_stage_hunk") + vim.keymap.set("n", "gp", ":Gitsigns preview_hunk") + vim.keymap.set("n", "gb", ":Gitsigns blame_line") + end, + }) + -- Git commands. + use({ + "tpope/vim-fugitive", + requires = "tpope/vim-rhubarb", + config = function() + require("tracer.plugins.fugitive").setup() + end, + }) + -- Improved syntax highlighting. + use({ + "nvim-treesitter/nvim-treesitter", + run = function() + require("nvim-treesitter.install").update({ with_sync = true }) + end, + requires = { + "JoosepAlviste/nvim-ts-context-commentstring", + "nvim-treesitter/nvim-treesitter-textobjects", + }, + config = function() + pcall(require, "tracer.plugins.treesitter") + end, + }) + -- Language Server Protocol. + use({ + "neovim/nvim-lspconfig", + requires = { + "williamboman/mason.nvim", + "williamboman/mason-lspconfig.nvim", + }, + config = function() + pcall(require, "tracer.plugins.lspconfig") + end, + }) -- Fuzzy finder use({ @@ -119,7 +166,7 @@ require("packer").startup(function(use) }, config = function() require("tracer.plugins.telescope") - end, +end, }) -- File tree sidebar for project-style navigation. diff --git a/nvim/lua/tracer/plugins/fugitive.lua b/nvim/lua/tracer/plugins/fugitive.lua new file mode 100644 index 0000000..a5bee02 --- /dev/null +++ b/nvim/lua/tracer/plugins/fugitive.lua @@ -0,0 +1,90 @@ +local M = {} + +local function homepage_for_remote(remote) + local patterns = { + "^gitea@([^:]+):(.+)%.git$", + "^git@([^:]+):(.+)%.git$", + "^ssh://git@([^/]+)/(.+)%.git$", + "^https?://([^/]+)/(.+)%.git$", + "^https?://([^/]+)/(.+)$", + } + + for _, pattern in ipairs(patterns) do + local host, repo = remote:match(pattern) + if host and repo then + return ("https://%s/%s"):format(host, repo) + end + end + + return nil +end + +local function url_escape(value) + return (value:gsub("#", "%%23"):gsub(" ", "%%20")) +end + +local function gitea_browse(opts) + local root = homepage_for_remote(opts.remote or "") + if not root then + return nil + end + + local path = (opts.path or ""):gsub("^/", "") + local ref = (opts.path or ""):match("^/?%.git/(refs/.*)") + + if ref and ref:match("^refs/heads/") then + local branch = ref:gsub("^refs/heads/", "") + return root .. "/commits/branch/" .. url_escape(branch) + end + + if ref and ref:match("^refs/tags/") then + local tag = ref:gsub("^refs/tags/", "") + return root .. "/releases/tag/" .. url_escape(tag) + end + + if ref and ref:match("^refs/remotes/[^/]+/.+") then + local branch = ref:match("^refs/remotes/[^/]+/(.+)$") + return root .. "/commits/branch/" .. url_escape(branch) + end + + if (opts.path or ""):match("^/?%.git") then + return root + end + + local commit = url_escape(opts.commit or "HEAD") + local url + + if opts.type == "tree" or path:match("/$") then + url = root .. "/src/commit/" .. commit + if path ~= "" then + url = url .. "/" .. url_escape(path):gsub("/$", "") + end + elseif opts.type == "blob" or path:match("[^/]$") then + url = root .. "/src/commit/" .. commit + if path ~= "" then + url = url .. "/" .. url_escape(path) + end + + if opts.line2 and opts.line1 and opts.line1 > 0 and opts.line1 == opts.line2 then + url = url .. "#L" .. opts.line1 + elseif opts.line1 and opts.line2 and opts.line1 > 0 and opts.line2 > 0 then + url = url .. "#L" .. opts.line1 .. "-L" .. opts.line2 + end + else + url = root .. "/commit/" .. commit + end + + return url +end + +function M.setup() + if vim.g.tracer_fugitive_gitea_handler_loaded then + return + end + + vim.g.tracer_fugitive_gitea_handler_loaded = true + vim.g.fugitive_browse_handlers = vim.g.fugitive_browse_handlers or {} + table.insert(vim.g.fugitive_browse_handlers, 1, gitea_browse) +end + +return M diff --git a/nvim/lua/tracer/plugins/lspconfig.lua b/nvim/lua/tracer/plugins/lspconfig.lua new file mode 100644 index 0000000..e51ad61 --- /dev/null +++ b/nvim/lua/tracer/plugins/lspconfig.lua @@ -0,0 +1,34 @@ +-- Setup Mason to automatically install LSP servers +require("mason").setup() + +require("mason-lspconfig").setup({ automatic_installation = true }) + +-- Keymaps +vim.keymap.set("n", "d", vim.diagnostic.open_float) +vim.keymap.set("n", "[d", vim.diagnostic.goto_prev) +vim.keymap.set("n", "]d", vim.diagnostic.goto_next) +vim.keymap.set("n", "gd", vim.lsp.buf.definition) +vim.keymap.set("n", "gi", "Telescope lsp_implementations") +vim.keymap.set("n", "gr", "Telescope lsp_references") +vim.keymap.set("n", "K", vim.lsp.buf.hover) +vim.keymap.set("n", "rn", vim.lsp.buf.rename) + +-- Emmet for HTML and JSX-style markup editing +vim.lsp.config("emmet_language_server", { + filetypes = { + "css", + "html", + "javascriptreact", + "less", + "sass", + "scss", + "typescriptreact", + }, +}) + +vim.lsp.enable("intelephense") +vim.lsp.enable("ts_ls") +vim.lsp.enable("eslint") +vim.lsp.enable("html") +vim.lsp.enable("cssls") +vim.lsp.enable("emmet_language_server") diff --git a/nvim/lua/tracer/plugins/treesitter.lua b/nvim/lua/tracer/plugins/treesitter.lua new file mode 100644 index 0000000..5bd3d95 --- /dev/null +++ b/nvim/lua/tracer/plugins/treesitter.lua @@ -0,0 +1,30 @@ +local ok, configs = pcall(require, "nvim-treesitter.configs") +if not ok then + return +end + +configs.setup({ + ensure_installed = "all", + highlight = { + enable = true, + additional_vim_regex_highlighting = true, + }, + context_commentstring = { + enable = true, + }, + indent = { + enable = true, + }, + textobjects = { + select = { + enable = true, + lookahead = true, + keymaps = { + ["if"] = "@function.inner", + ["af"] = "@function.outer", + ["ia"] = "@parameter.inner", + ["aa"] = "@parameter.outer", + }, + }, + }, +})