From 56663575aaf0af6724bcfdc0d4d1f94de42eaed6 Mon Sep 17 00:00:00 2001 From: Anthony Rodriguez Date: Mon, 22 Jul 2024 17:50:47 +0200 Subject: [PATCH] Update .gitmodules Update .config/nvim/init.lua Add .config/nvim/pack/plugins/start/coq_nvim Add .config/nvim/pack/plugins/start/lsp_signature Add .config/nvim/pack/plugins/start/plenary --- .gitmodules | 10 ++++++ dot_config/nvim/init.lua | 73 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/.gitmodules b/.gitmodules index 0808f9e..3a9b7ae 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,13 @@ [submodule "dot_config/nvim/pack/plugins/start/telescope"] path = dot_config/nvim/pack/plugins/start/telescope url = https://github.com/nvim-telescope/telescope.nvim + branch = 0.1.x +[submodule "dot_config/nvim/pack/plugins/start/plenary"] + path = dot_config/nvim/pack/plugins/start/plenary + url = https://github.com/nvim-lua/plenary.nvim +[submodule "dot_config/nvim/pack/plugins/start/coq_nvim"] + path = dot_config/nvim/pack/plugins/start/coq_nvim + url = https://github.com/ms-jpq/coq_nvim +[submodule "dot_config/nvim/pack/plugins/start/lsp_signature"] + path = dot_config/nvim/pack/plugins/start/lsp_signature + url = https://github.com/ray-x/lsp_signature.nvim diff --git a/dot_config/nvim/init.lua b/dot_config/nvim/init.lua index 7a1ab71..5ce7ec6 100644 --- a/dot_config/nvim/init.lua +++ b/dot_config/nvim/init.lua @@ -1 +1,74 @@ +-- general settings vim.cmd.colorscheme "catppuccin-frappe" +vim.g.mapleader = " " +vim.wo.relativenumber = true + +-- Telescope +local builtin = require('telescope.builtin') +vim.keymap.set('n', 'ff', builtin.find_files, {}) +vim.keymap.set('n', 'fg', builtin.live_grep, {}) +vim.keymap.set('n', 'fb', builtin.buffers, {}) +vim.keymap.set('n', 'fh', builtin.help_tags, {}) + +-- LSP settings +vim.g.coq_settings = { auto_start = 'shut-up' } +local coq = require "coq" + +-- Function to get root directory +local function get_root_dir(fname, patterns) + local dir = vim.fs.dirname(fname) + for _, pattern in ipairs(patterns) do + local match = vim.fn.globpath(dir, pattern) + if match ~= "" then + return dir + end + end + return nil +end + +-- Function to start LSP +local function start_lsp(server_name, cmd, patterns) + return function(args) + local root_dir = get_root_dir(vim.api.nvim_buf_get_name(args.buf), patterns) + if root_dir then + vim.lsp.start(coq.lsp_ensure_capabilities({ + name = server_name, + cmd = cmd, + root_dir = root_dir, + })) + end + end +end + +-- Create autocommands for different file types +vim.api.nvim_create_autocmd('FileType', { + pattern = 'python', + callback = start_lsp('pyright', {'pyright-langserver', '--stdio'}, {'setup.py', 'pyproject.toml'}) +}) + +vim.api.nvim_create_autocmd('FileType', { + pattern = {'javascript', 'typescript'}, + callback = start_lsp('tsserver', {'typescript-language-server', '--stdio'}, {'package.json', 'tsconfig.json'}) +}) + +vim.api.nvim_create_autocmd('FileType', { + pattern = 'go', + callback = start_lsp('gopls', {'gopls'}, {'go.mod'}) +}) + +-- Enable signature completion +vim.api.nvim_create_autocmd("LspAttach", { + callback = function(args) + local bufnr = args.buf + local client = vim.lsp.get_client_by_id(args.data.client_id) + if vim.tbl_contains({ 'null-ls' }, client.name) then -- blacklist lsp + return + end + require("lsp_signature").on_attach({ + -- ... setup options here ... + }, bufnr) + end, +}) + +-- Formatting +vim.api.nvim_set_keymap('n', 'qf', 'lua vim.lsp.buf.format()', { noremap = true, silent = true })