5 Commits 749866faf6 ... 4587a0d6a0

Author SHA1 Message Date
  Thomas Dy 4587a0d6a0 git: add local git config 3 months ago
  Thomas Dy 231ae19f35 nixpkgs/neovim: pass full path to dprint formatter 3 months ago
  Thomas Dy 7be27c6b5a nixpkgs/neovim: fix strip trailing whitespace formatter 3 months ago
  Thomas Dy 357e17b02d nixpkgs/neovim: only use LSP format if a client is attached 3 months ago
  Thomas Dy 3c24ea4b72 nixpkgs/neovim: use better go to definition for typescript 3 months ago
4 changed files with 34 additions and 5 deletions
  1. 4 0
      .config/git/config
  2. 4 1
      .config/nixpkgs/neovim/lsp.lua
  3. 25 4
      .config/nixpkgs/neovim/plugins.lua
  4. 1 0
      .gitignore

+ 4 - 0
.config/git/config

@@ -53,3 +53,7 @@
 	reset-head = remote set-head origin -a
 	head = for-each-ref --format="%(symref:lstrip=-1)" refs/remotes/origin/HEAD
 	sh = "!git switch $(git head)"
+
+[include]
+	path = ./config.local
+	path = ./config.nonexistent

+ 4 - 1
.config/nixpkgs/neovim/lsp.lua

@@ -31,7 +31,8 @@ if vim.fn.executable("node_modules/.bin/eslint") == 1 then
       client.server_capabilities.documentFormattingProvider = true
       client.server_capabilities.documentRangeFormattingProvider = true
 
-      on_attach(client, bufnr)
+      -- mappings should have been attached by typescript and re-attaching can
+      -- overwrite the typescript specific overrides
     end,
   })
 end
@@ -72,6 +73,8 @@ else
         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>TypescriptGoToSourceDefinition<CR>', opts)
+        vim.keymap.set('n', 'gD', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
       end
     }
   })

+ 25 - 4
.config/nixpkgs/neovim/plugins.lua

@@ -277,8 +277,26 @@ local format_on_save = require("format-on-save")
 local formatters = require("format-on-save.formatters")
 local vim_notify = require("format-on-save.error-notifiers.vim-notify")
 
+-- only format with LSP if there are clients attached
+local lsp_formatter = formatters.custom({
+  format = function()
+    local bufnr = vim.api.nvim_get_current_buf()
+    local clients = vim.lsp.get_active_clients({ bufnr = bufnr })
+    if #clients > 0 then
+      vim.lsp.buf.format({ timeout_ms = 4000, bufnr = bufnr })
+    end
+  end
+})
+
+-- the built-in formatter was not playing well with folds
+local whitespace_formatter = formatters.custom({
+  format = function()
+    vim.cmd('%s/\\s\\+$//e')
+  end
+})
+
 local js = {
-  formatters.lsp,
+  lsp_formatter,
   formatters.if_file_exists({
     pattern = {
       "dprint.json",
@@ -286,7 +304,7 @@ local js = {
       ".dprint.json",
       ".dprint.jsonc",
     },
-    formatter = formatters.shell({ cmd = { "dprint", "fmt", "--stdin", "%" }}),
+    formatter = formatters.shell({ cmd = { "dprint", "fmt", "--stdin", "%:p" }}),
   }),
 }
 
@@ -301,11 +319,14 @@ format_on_save.setup({
     javascript = js,
     typescript = js,
     typescriptreact = js,
+
+    -- don't format diffs
+    diff = {},
   },
 
   fallback_formatter = {
-    formatters.remove_trailing_whitespace,
-    formatters.lsp,
+    whitespace_formatter,
+    lsp_formatter,
   },
 })
 

+ 1 - 0
.gitignore

@@ -5,6 +5,7 @@
 !.config
 !.config/git
 !.config/git/**
+.config/git/config.local
 !.config/nixpkgs
 !.config/nixpkgs/**
 !.local