5 次代码提交 fbcfd476eb ... acf3cddb9a

作者 SHA1 备注 提交日期
  Thomas Dy acf3cddb9a nixpkgs/neovim: add missing LSP capabilities 8 月之前
  Thomas Dy 4acb34602e nixpkgs/neovim: use LSPAttach autocmd for mappings 8 月之前
  Thomas Dy fae1dd6ab6 nixpkgs/neovim: redo formatting again 8 月之前
  Thomas Dy 28207159b2 nixpkgs/neovim: add support for java 8 月之前
  Thomas Dy 8628f5bb71 nixpkgs/elvish: update flake.lock 9 月之前

+ 6 - 6
.config/nixpkgs/elvish/flake.lock

@@ -5,11 +5,11 @@
         "systems": "systems"
       },
       "locked": {
-        "lastModified": 1701680307,
-        "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
+        "lastModified": 1709126324,
+        "narHash": "sha256-q6EQdSeUZOG26WelxqkmR7kArjgWCdw5sfJVHPH/7j8=",
         "owner": "numtide",
         "repo": "flake-utils",
-        "rev": "4022d587cbbfd70fe950c1e2083a02621806a725",
+        "rev": "d465f4819400de7c8d874d50b982301f28a84605",
         "type": "github"
       },
       "original": {
@@ -20,11 +20,11 @@
     },
     "nixpkgs": {
       "locked": {
-        "lastModified": 1703134684,
-        "narHash": "sha256-SQmng1EnBFLzS7WSRyPM9HgmZP2kLJcPAz+Ug/nug6o=",
+        "lastModified": 1709780214,
+        "narHash": "sha256-p4iDKdveHMhfGAlpxmkCtfQO3WRzmlD11aIcThwPqhk=",
         "owner": "NixOS",
         "repo": "nixpkgs",
-        "rev": "d6863cbcbbb80e71cecfc03356db1cda38919523",
+        "rev": "f945939fd679284d736112d3d5410eb867f3b31c",
         "type": "github"
       },
       "original": {

+ 3 - 3
.config/nixpkgs/elvish/flake.nix

@@ -11,13 +11,13 @@
       with nixpkgs.legacyPackages.${system}; {
         packages.carapace-bin = buildGoModule rec {
           pname = "carapace-bin";
-          version = "0.28.5";
+          version = "0.30.2";
 
           src = fetchFromGitHub {
             owner = "rsteube";
             repo = "carapace-bin";
             rev = "v${version}";
-            hash = "sha256-mprwDx1SvvT96MR1YgLwIJaEHCknCkbJ9zq0HfNJy/Y=";
+            hash = "sha256-gYYNwDUL00b9orq1suxa9VtHBLUgRgntQcYw24vgncg=";
           };
 
           ldflags = [ "-s" "-w" ];
@@ -30,7 +30,7 @@
             go generate ./...
           '';
 
-          vendorHash = "sha256-rR0mLO8jjhTPySQ/BTegNe9kd2DudULOuYBBB/P9K1s=";
+          vendorHash = "sha256-RML1al1XlONzeCCkz34Ij1I/WDQSTVrm3P6RaOdyWKI=";
         };
 
         packages.elvish =

+ 14 - 1
.config/nixpkgs/neovim/autocmd.lua

@@ -32,12 +32,25 @@ vim.api.nvim_create_autocmd('BufLeave', {
   command = 'stopinsert',
 })
 
--- strip trailing whitespace
+-- formatting
 vim.api.nvim_create_autocmd('BufWritePre', {
   callback = function(opts)
     if vim.bo.filetype == 'diff' then
       return
     end
+
+    if not vim.g.no_lsp_format then
+      -- check if can LSP format
+      local clients = vim.lsp.get_active_clients({ bufnr = opts.buf })
+      for _, client in ipairs(clients) do
+        if client.server_capabilities.documentFormattingProvider then
+          vim.lsp.buf.format()
+          return
+        end
+      end
+    end
+
+    -- otherwise strip trailing whitespace
     vim.cmd('%s/\\s\\+$//e')
   end,
 })

+ 20 - 43
.config/nixpkgs/neovim/lsp.lua

@@ -9,7 +9,6 @@ local nvim_lsp = require('lspconfig')
 
 nvim_lsp.bashls.setup({
   capabilities = capabilities,
-  on_attach = on_attach,
 });
 
 if vim.fn.executable("node_modules/.bin/eslint") == 1 then
@@ -24,15 +23,18 @@ if vim.fn.executable("node_modules/.bin/eslint") == 1 then
     settings = {
       options = options,
     },
-    on_attach = function(client, bufnr)
+    handlers = {
+      ["client/registerCapability"] = function(err, result, ctx, config)
+        -- ignore as we can't handle any of this and it just spams the logs
+        return vim.NIL
+      end
+    },
+    on_init = function(client)
       -- add formatting capability, the language server registers this
       -- dynamically but neovim does not support that yet
       -- https://github.com/microsoft/vscode-eslint/pull/1307
       client.server_capabilities.documentFormattingProvider = true
       client.server_capabilities.documentRangeFormattingProvider = true
-
-      -- mappings should have been attached by typescript and re-attaching can
-      -- overwrite the typescript specific overrides
     end,
   })
 end
@@ -47,7 +49,6 @@ end
 if vim.fn.executable("deno") == 1 then
   nvim_lsp.denols.setup({
     capabilities = capabilities,
-    on_attach = on_attach,
   });
 else
   require('typescript').setup({
@@ -67,21 +68,12 @@ else
       flags = {
         debounce_text_changes = 150,
       },
-      on_attach = function(client, bufnr)
+      on_init = function(client)
         -- mark tsserver as not having formatting available as we rely on
-        -- eslint for that
+        -- eslint and dprint for that
         client.server_capabilities.documentFormattingProvider = false
         client.server_capabilities.documentRangeFormattingProvider = false
-
-        on_attach(client, bufnr)
-
-        -- override mappings for typescript
-        local opts = { silent = true, buffer = bufnr }
-        -- exclude import statements from reference search (may have false positives)
-        vim.keymap.set('n', 'gr', '<cmd>Telescope lsp_references default_text=!import\\ <CR>', opts)
-        vim.keymap.set('n', 'gD', '<cmd>Telescope lsp_definitions<CR>', opts)
-        vim.keymap.set('n', 'gd', '<cmd>TypescriptGoToSourceDefinition<CR>', opts)
-      end
+      end,
     }
   })
 end
@@ -89,14 +81,12 @@ end
 if vim.fn.executable("gopls") == 1 then
   nvim_lsp.gopls.setup({
     capabilities = capabilities,
-    on_attach = on_attach,
   });
 end
 
 if vim.fn.executable("solargraph") == 1 then
   nvim_lsp.solargraph.setup({
     capabilities = capabilities,
-    on_attach = on_attach,
     init_options = {
       formatting = false,
     }
@@ -105,32 +95,20 @@ end
 
 if vim.fn.executable("nil") == 1 then
   nvim_lsp.nil_ls.setup({
-    on_attach = on_attach,
+    capabilities = capabilities,
   });
 end
 
--- format on save
-local group = vim.api.nvim_create_augroup('LspFormatting', { clear = false })
-
-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 client.server_capabilities.documentFormattingProvider then
-      for key, cmd in pairs(vim.api.nvim_get_autocmds({ group = group, buffer = bufnr })) do
-        vim.api.nvim_del_autocmd(cmd.id)
+if vim.fn.executable("jdtls") == 1 then
+  nvim_lsp.jdtls.setup({
+    capabilities = capabilities,
+    handlers = {
+      ["$/progress"] = function()
+        -- this is quite noisy so just disable it
       end
-      vim.api.nvim_create_autocmd('BufWritePre', {
-        group = group,
-        buffer = bufnr,
-        callback = function()
-          vim.lsp.buf.format()
-        end,
-      })
-    end
-  end,
-})
+    },
+  });
+end
 
 -- custom LSP servers
 local configs = require('lspconfig.configs')
@@ -148,5 +126,4 @@ end
 
 nvim_lsp.elvish.setup({
   capabilities = capabilities,
-  on_attach = on_attach,
 })

+ 32 - 16
.config/nixpkgs/neovim/mappings.lua

@@ -79,19 +79,35 @@ vim.keymap.set('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts)
 vim.keymap.set('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts)
 vim.keymap.set('n', '<space>q', '<cmd>lua vim.diagnostic.setqflist({ severity = { min = vim.diagnostic.severity.WARN } })<CR>', opts)
 
-function on_attach(client, bufnr)
-  local opts = { silent = true, buffer = bufnr }
-
-  -- LSP-specific mappings
-  vim.keymap.set('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
-  vim.keymap.set('n', 'gd', '<cmd>Telescope lsp_definitions<CR>', opts)
-  vim.keymap.set('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
-  vim.keymap.set('n', 'gi', '<cmd>Telescope lsp_implementations<CR>', opts)
-  vim.keymap.set({'n', 'i'}, '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
-  vim.keymap.set('n', '<space>D', '<cmd>Telescope lsp_type_definitions<CR>', opts)
-  vim.keymap.set('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
-  vim.keymap.set('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
-  vim.keymap.set('v', '<space>ca', '<cmd>lua vim.lsp.buf.range_code_action()<CR>', opts)
-  vim.keymap.set('n', 'gr', '<cmd>Telescope lsp_references<CR>', opts)
-  vim.keymap.set('n', '<Leader>fs', '<cmd>Telescope lsp_document_symbols<CR>', opts)
-end
+-- LSP-specific
+vim.api.nvim_create_autocmd('LspAttach', {
+  callback = function(args)
+    local client = vim.lsp.get_client_by_id(args.data.client_id)
+
+    if client.name == 'dprint' or client.name == 'eslint' then
+      -- mappings should have been attached by typescript and re-attaching can
+      -- overwrite the typescript specific overrides
+    end
+
+    local opts = { silent = true, buffer = args.buf }
+
+    vim.keymap.set('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
+    vim.keymap.set('n', 'gd', '<cmd>Telescope lsp_definitions<CR>', opts)
+    vim.keymap.set('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
+    vim.keymap.set('n', 'gi', '<cmd>Telescope lsp_implementations<CR>', opts)
+    vim.keymap.set({'n', 'i'}, '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
+    vim.keymap.set('n', '<space>D', '<cmd>Telescope lsp_type_definitions<CR>', opts)
+    vim.keymap.set('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
+    vim.keymap.set('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
+    vim.keymap.set('v', '<space>ca', '<cmd>lua vim.lsp.buf.range_code_action()<CR>', opts)
+    vim.keymap.set('n', 'gr', '<cmd>Telescope lsp_references<CR>', opts)
+    vim.keymap.set('n', '<Leader>fs', '<cmd>Telescope lsp_document_symbols<CR>', opts)
+
+    if client.name == 'tsserver' then
+      -- exclude import statements from reference search (may have false positives)
+      vim.keymap.set('n', 'gr', '<cmd>Telescope lsp_references default_text=!import\\ <CR>', opts)
+      vim.keymap.set('n', 'gD', '<cmd>Telescope lsp_definitions<CR>', opts)
+      vim.keymap.set('n', 'gd', '<cmd>TypescriptGoToSourceDefinition<CR>', opts)
+    end
+  end,
+})

+ 4 - 0
.config/nixpkgs/neovim/treesitter/grammars.json

@@ -68,5 +68,9 @@
     "repo": "neovim/tree-sitter-vimdoc",
     "rev": "016ad75faa854e4e13bc40c517015183b795eed9",
     "sha256": "1gia88qfyzfxaypv75vcqs2p3k1mn4kq0a3zqj52sw58zqim5s5z"
+  },
+  "java": {
+    "rev": "99b29f1ed957b3b424b6e21f57bd21a9732a622a",
+    "sha256": "1i776ikfdg70fnsg5sih3bf3pxgjyqwyhd122b3cxp4dxxfds3fq"
   }
 }