12 Commits 4587a0d6a0 ... 182d61894f

Author SHA1 Message Date
  Thomas Dy 182d61894f nixpkgs/neovim: enable dprint lsp 3 months ago
  Thomas Dy e3f72c0eb2 nixpkgs/neovim: set shell to /bin/sh 3 months ago
  Thomas Dy da668b8588 git: add local git config 3 months ago
  Thomas Dy 1295de2f1a nixpkgs/neovim: use better go to definition for typescript 3 months ago
  Thomas Dy f63d50d661 nixpkgs/neovim: replace fidget with mini.notify 3 months ago
  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
  Thomas Dy 749866faf6 nixpkgs/neovim: replace fidget with mini.notify 3 months ago
  Thomas Dy 9c8b6814d4 nixpkgs/neovim: add format-on-save 3 months ago

+ 10 - 0
.config/nixpkgs/neovim/autocmd.lua

@@ -32,6 +32,16 @@ vim.api.nvim_create_autocmd('BufLeave', {
   command = 'stopinsert',
 })
 
+-- strip trailing whitespace
+vim.api.nvim_create_autocmd('BufWritePre', {
+  callback = function(opts)
+    if vim.bo.filetype == 'diff' then
+      return
+    end
+    vim.cmd('%s/\\s\\+$//e')
+  end,
+})
+
 -- filetype specific options
 vim.api.nvim_create_autocmd('FileType', {
   pattern = 'markdown',

+ 29 - 0
.config/nixpkgs/neovim/lsp.lua

@@ -37,6 +37,12 @@ if vim.fn.executable("node_modules/.bin/eslint") == 1 then
   })
 end
 
+if vim.fn.executable("dprint") == 1 then
+  local version = vim.version.parse(vim.fn.system("dprint --version"))
+  if vim.version.cmp(version, {0,45,0}) >= 0 then
+    nvim_lsp.dprint.setup({})
+  end
+end
 
 if vim.fn.executable("deno") == 1 then
   nvim_lsp.denols.setup({
@@ -103,6 +109,29 @@ if vim.fn.executable("nil") == 1 then
   });
 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)
+      end
+      vim.api.nvim_create_autocmd('BufWritePre', {
+        group = group,
+        buffer = bufnr,
+        callback = function()
+          vim.lsp.buf.format()
+        end,
+      })
+    end
+  end,
+})
+
 -- custom LSP servers
 local configs = require('lspconfig.configs')
 

+ 1 - 1
.config/nixpkgs/neovim/mappings.lua

@@ -61,7 +61,7 @@ vim.keymap.set('n', '<Leader>ut', '<cmd>UndotreeToggle<CR>', opts)
 
 -- opening terminals
 vim.keymap.set('n', '<Leader>tv', '<cmd>vsp term://$SHELL<CR>', opts)
-vim.keymap.set('n', '<Leader>to', '<cmd>term<CR>', opts)
+vim.keymap.set('n', '<Leader>to', '<cmd>term $SHELL<CR>', opts)
 
 -- delete buffer
 vim.keymap.set('n', '<Leader>q', '<cmd>lua MiniBufremove.delete()<CR>', opts)

+ 0 - 58
.config/nixpkgs/neovim/plugins.lua

@@ -272,63 +272,5 @@ cmp.setup({
   },
 })
 
--- format on save
-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 = {
-  lsp_formatter,
-  formatters.if_file_exists({
-    pattern = {
-      "dprint.json",
-      "dprint.jsonc",
-      ".dprint.json",
-      ".dprint.jsonc",
-    },
-    formatter = formatters.shell({ cmd = { "dprint", "fmt", "--stdin", "%:p" }}),
-  }),
-}
-
-format_on_save.setup({
-  error_notifier = vim_notify,
-
-  exclude_path_patterns = {
-    "/node_modules/",
-  },
-
-  formatter_by_ft = {
-    javascript = js,
-    typescript = js,
-    typescriptreact = js,
-
-    -- don't format diffs
-    diff = {},
-  },
-
-  fallback_formatter = {
-    whitespace_formatter,
-    lsp_formatter,
-  },
-})
-
 -- typescript-vim compiler options
 vim.g.typescript_compiler_options = '--incremental --noEmit'

+ 2 - 6
.config/nixpkgs/neovim/plugins/sources.json

@@ -44,8 +44,8 @@
     "sha256": "0n1pdil0di93sfmlxnw80xvwxgz36m3hllhzg16bmlcjwgagwclp"
   },
   "neovim/nvim-lspconfig": {
-    "rev": "9099871a7c7e1c16122e00d70208a2cd02078d80",
-    "sha256": "0w9f87zniyzz3hk3jqavj02d4lafp8aamfgv5j7nb5aa0c1hjd61"
+    "rev": "1759ea68fbbb1303192020d3e59936189359e0ed",
+    "sha256": "025kamvrx8j362kszkqa028xm4d2gjxsb45rwzcp0jvx2ay74zxj"
   },
   "nvim-treesitter/nvim-treesitter-textobjects": {
     "rev": "ec1c5bdb3d87ac971749fa6c7dbc2b14884f1f6a",
@@ -100,9 +100,5 @@
     "optional": true,
     "rev": "3ba0c02c378503739f1fdb95cff3ea2aad48db3e",
     "sha256": "0pvb25bdmx4hxs3g7pkdqfjg3qpnr9p5szzbqqwaw3lbdnbyykzy"
-  },
-  "elentok/format-on-save.nvim": {
-    "rev": "b7ea8d72391281d14ea1fa10324606c1684180da",
-    "sha256": "0z1ifp9ycn9fh3ckcdx2vx0pda7rp45gq8wix8hh28ci3djw176b"
   }
 }

+ 2 - 0
.config/nixpkgs/neovim/settings.lua

@@ -51,3 +51,5 @@ vim.o.mouse = false
 vim.o.foldmethod = 'expr'
 vim.o.foldexpr = 'nvim_treesitter#foldexpr()'
 vim.o.foldenable = false
+
+vim.o.shell = '/bin/sh'