]> localhost Git - nvim.git/commitdiff
feat: lsp setup
authorJansen <[email protected]>
Mon, 7 Oct 2024 20:13:57 +0000 (16:13 -0400)
committerJansen <[email protected]>
Mon, 7 Oct 2024 20:13:57 +0000 (16:13 -0400)
init.lua
lazy-lock.json

index 1958ce373db1a021f5106fea71574258461fcdb4..a3ae8f27775938f35994ae4fab71d1bcd6fa0e2a 100644 (file)
--- a/init.lua
+++ b/init.lua
@@ -15,16 +15,20 @@ vim.opt.foldenable = true
 
 vim.opt.cursorline = true
 
+local tab_next = true
+
 -- Neovide =====================================================================
 if vim.g.neovide then
   vim.g.neovide_hide_mouse_when_typing = true
 
-  vim.o.guifont = "Iosevka NF:h12"
+  vim.o.guifont = "Iosevka NF:h18"
   vim.opt.linespace = 0
+  vim.cmd [[cd ~]]
 end
 
 -- Lazy NVIM ===================================================================
 local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
+---@diagnostic disable-next-line: undefined-field
 if not (vim.uv or vim.loop).fs_stat(lazypath) then
   vim.fn.system({
     "git",
@@ -49,7 +53,16 @@ require("lazy").setup({
     },
     config = true
   },
-  { 
+  {
+    'sainnhe/sonokai',
+    lazy = false,
+    priority = 1000,
+    config = function()
+      vim.g.sonokai_enable_italic = true
+      vim.cmd.colorscheme('sonokai')
+    end
+  },
+  {
     "nvim-treesitter/nvim-treesitter",
     config = function()
       require("nvim-treesitter.configs").setup({
@@ -76,18 +89,75 @@ require("lazy").setup({
     end
   },
   {
-    'sainnhe/sonokai',
+    "williamboman/mason.nvim",
     lazy = false,
-    priority = 1000,
     config = function()
-      vim.g.sonokai_enable_italic = true
-      vim.cmd.colorscheme('sonokai')
+      require("mason").setup({ max_concurrent_installers = 10 })
+    end
+  },
+  {
+    "neovim/nvim-lspconfig",
+    dependencies = { "williamboman/mason-lspconfig.nvim", },
+    config = function()
+      local manual = {
+        "lua_ls",
+      }
+      local automatic = {
+        "ts_ls",
+      }
+
+      -- Install LSPs
+      local ensure_installed = {}
+      for k,v in pairs(manual)    do ensure_installed[k] = v end
+      for k,v in pairs(automatic) do ensure_installed[k] = v end
+      require('mason-lspconfig').setup({ ensure_installed = ensure_installed })
+
+      -- LSP
+      local function lsp_keymaps_on_attach(_, bufnr)
+        local bufopts = { noremap = true, silent = true, buffer = bufnr }
+
+        -- Open in a new tab
+        local function nt(cmd)
+          tab_next = true
+          return "<cmd>tab split | lua " .. cmd .. "()<CR>"
+        end
+        vim.keymap.set('n', 'gD', nt("vim.lsp.buf.declaration"),     bufopts)
+        vim.keymap.set('n', 'gd', nt("vim.lsp.buf.definition"),      bufopts)
+        vim.keymap.set('n', 'gi', nt("vim.lsp.buf.implementation"),  bufopts)
+        vim.keymap.set('n', 'gf', nt("vim.lsp.buf.type_definition"), bufopts)
+        vim.keymap.set('n', 'gr', nt("vim.lsp.buf.references"),      bufopts)
+
+        vim.keymap.set('n', '<leader>kd', vim.diagnostic.open_float,   bufopts)
+        vim.keymap.set('n', '<leader>kk', vim.lsp.buf.signature_help,  bufopts)
+        vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename,          bufopts)
+        vim.keymap.set('n', '<leader>ka', vim.lsp.buf.code_action,     bufopts)
+      end
+
+      local lspconfig = require("lspconfig")
+      -- Automatic setup
+      for i in pairs(automatic) do
+        lspconfig[automatic[i]].setup { on_attach = lsp_keymaps_on_attach }
+      end
+
+      -- Manual setup
+      lspconfig.lua_ls.setup {
+        on_attach = lsp_keymaps_on_attach,
+        settings = {
+          Lua = {
+            diagnostics = {
+              globals = { 'vim', 'require' },
+            },
+            workspace = { library = vim.api.nvim_get_runtime_file("", true) },
+            telemetry = { enable = false, },
+          },
+        },
+      }
     end
   },
 })
 
 -- CustomCommands ==============================================================
-function edit_config()
+local function edit_config()
   vim.cmd [[cd ~/.config/nvim]]
   vim.cmd [[e ~/.config/nvim/init.lua]]
 end
@@ -102,13 +172,13 @@ vim.keymap.set('n', '<leader>g', function() vim.cmd [[Neogit]] end)
 
 -- Find (fzf)
 vim.keymap.set('n', '<leader>ff',  function() vim.cmd [[FzfLua files]] end)
-vim.keymap.set('n', '<leader>ft',  function() 
-  vim.cmd [[FzfLua grep_visual]] 
+vim.keymap.set('n', '<leader>ft',  function()
+  vim.cmd [[FzfLua grep_visual]]
 end)
 vim.keymap.set('n', '<leader>fm',  function() vim.cmd [[FzfLua marks]] end)
 
 -- Buffers/Windows (inplace)
-function open_term()
+local function open_term()
   vim.cmd [[term]]
   vim.cmd [[startinsert]]
 end
@@ -116,49 +186,45 @@ end
 vim.keymap.set('n', '<leader>e',  function() vim.cmd [[Explore]] end)
 vim.keymap.set('n', '<leader>c',  function() vim.cmd [[confirm quit]] end)
 vim.keymap.set('n', '<leader>T',  open_term)
-vim.keymap.set('n', '<leader>q',  function()
-  local win_count = #vim.api.nvim_list_wins()
-  vim.cmd [[confirm qa]]
-end)
+vim.keymap.set('n', '<leader>q',  function() vim.cmd [[confirm qa]] end)
 
 -- Buffers/Windows (horizontal)
 vim.keymap.set('n', '<leader>se', function() vim.cmd [[Hexplore]] end)
-vim.keymap.set('n', '<leader>ss', function() 
-  vim.cmd [[split]]  
-  vim.cmd [[wincmd j]]  
+vim.keymap.set('n', '<leader>ss', function()
+  vim.cmd [[split]]
+  vim.cmd [[wincmd j]]
 end)
 
 -- Buffers/Windows (vertical)
 vim.keymap.set('n', '<leader>ve', function() vim.cmd [[Vexplore!]] end)
-vim.keymap.set('n', '<leader>vs', function() 
-  vim.cmd [[vsplit]]  
-  vim.cmd [[wincmd l]]  
+vim.keymap.set('n', '<leader>vs', function()
+  vim.cmd [[vsplit]]
+  vim.cmd [[wincmd l]]
 end)
 
 -- Tabs
-tab_next = true
-function open_texplore()
+local function open_texplore()
   tab_next = true
   vim.cmd [[Texplore]]
 end
-function open_tterm()
+local function open_tterm()
   tab_next = true
   vim.cmd [[tabnew]]
   vim.cmd [[term]]
   vim.cmd [[startinsert]]
 end
-function next_tab()
+local function next_tab()
   tab_next = true
   vim.cmd [[tabn]]
 end
-function prev_tab()
+local function prev_tab()
   tab_next = false
   vim.cmd [[tabp]]
 end
 
-function last_tab() if tab_next then prev_tab() else next_tab() end end 
+local function last_tab() if tab_next then prev_tab() else next_tab() end end
 
-function close_tab()
+local function close_tab()
   local total_tabs = #vim.api.nvim_list_tabpages()
   if total_tabs > 1 then
     tab_next = true
@@ -173,8 +239,8 @@ vim.keymap.set('n', '<leader>tT', open_tterm)
 vim.keymap.set('n', '<leader>tc', close_tab)
 
 -- Code
-function compile_rust() vim.cmd [[!cargo check]] end
-function run_rust() 
+local function compile_rust() vim.cmd [[!cargo check]] end
+local function run_rust()
   tab_next = true
   vim.cmd [[tabnew]]
   vim.cmd [[term cargo run]]
@@ -188,11 +254,11 @@ local code = {
   }
 }
 
-vim.keymap.set('n', '<leader>xc', function() 
+vim.keymap.set('n', '<leader>xc', function()
   local c = code[vim.bo.filetype]
   if(c) then c.compile() end
 end)
-vim.keymap.set('n', '<leader>xr', function() 
+vim.keymap.set('n', '<leader>xr', function()
   local c = code[vim.bo.filetype]
   if(c) then c.run() end
 end)
index 98376e480ebbf1aee9282c35a5b8bb3b152dfe02..dc2694a9dfb3b66a6689c6d191aec2dae90ee25d 100644 (file)
@@ -1,10 +1,14 @@
 {
   "diffview.nvim": { "branch": "main", "commit": "4516612fe98ff56ae0415a259ff6361a89419b0a" },
-  "fzf-lua": { "branch": "main", "commit": "a1f834b37506ca77c47fa99cd3f5e9ed3f4102d2" },
-  "lazy.nvim": { "branch": "main", "commit": "460e1cd8f24e364d54543a4b0e83f6f4ec1f65fb" },
-  "neogit": { "branch": "master", "commit": "950d6f91529573dfd89b32c5fc55c52f72dee603" },
-  "nvim-treesitter": { "branch": "master", "commit": "da61d31a3d51f38a78a739392aabf79e7b2f523f" },
+  "fzf-lua": { "branch": "main", "commit": "1e03541de4d8a169defe83bb4d7abfba450c63a1" },
+  "lazy.nvim": { "branch": "main", "commit": "1159bdccd8910a0fd0914b24d6c3d186689023d9" },
+  "lazydev.nvim": { "branch": "main", "commit": "491452cf1ca6f029e90ad0d0368848fac717c6d2" },
+  "mason-lspconfig.nvim": { "branch": "main", "commit": "25c11854aa25558ee6c03432edfa0df0217324be" },
+  "mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" },
+  "neogit": { "branch": "master", "commit": "d55bf6114c6cfba013e4c0e817e29e7752554ab7" },
+  "nvim-lspconfig": { "branch": "master", "commit": "04680101ff79e99b4e33a4386ec27cbd0d360c75" },
+  "nvim-treesitter": { "branch": "master", "commit": "45e0d66246f31306d890b91301993fa1623e79f1" },
   "plenary.nvim": { "branch": "master", "commit": "2d9b06177a975543726ce5c73fca176cedbffe9d" },
-  "render-markdown.nvim": { "branch": "main", "commit": "e91b042b3865d2d040a0e21e0a3b13fb57f24094" },
+  "render-markdown.nvim": { "branch": "main", "commit": "06e6134e840da8be25f1053ba3be64ea33edd07b" },
   "sonokai": { "branch": "master", "commit": "3dcd97c0c5e4118bc171df6ba33800dfd9524a00" }
 }