Skip to content

Commit

Permalink
nvim: Back to gopls formatting
Browse files Browse the repository at this point in the history
gopls is still "the future", despite how slow it can be at $WORK. Switch
to disabling it within conform, and then only hooking up the custom LSP
formatting for gopls clients (other LSPs will fallback to conform's
custom LSP formatting code).
  • Loading branch information
stefanvanburen committed Sep 4, 2024
1 parent 94f2fa0 commit eae37d3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
15 changes: 13 additions & 2 deletions .config/nvim/init.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@
;; https://github.com/stevearc/conform.nvim?tab=readme-ov-file#formatters
(conform.setup {:formatters_by_ft {:fennel [:fnlfmt]
:fish [:fish_indent]
:go [:goimports]
;; Go has a custom setup in the LSP section that enables goimports-like functionality.
:go {:lsp_fallback :never}
:just [:just]
:proto [:buf]}
:format_on_save {:timeout_ms 5000 :lsp_format :fallback}}))
Expand Down Expand Up @@ -452,6 +453,17 @@

(fn lsp-attach [{: buf :data {: client_id}}]
(local client (vim.lsp.get_client_by_id client_id))

(fn goimports []
;; https://github.com/golang/tools/blob/master/gopls/doc/vim.md#imports-and-formatting
(vim.lsp.buf.code_action {:context {:only [:source.organizeImports]}
:apply true})
(vim.lsp.buf.format))

;; Only enable formatting for gopls.
(when (and client.server_capabilities.documentFormattingProvider
(= client.name :gopls))
(vim.api.nvim_create_autocmd :BufWritePre {:buffer buf :callback goimports}))
(when (and client.server_capabilities.inlayHintProvider vim.lsp.inlay_hint)
(vim.lsp.inlay_hint.enable true {:bufnr buf}))
(when client.server_capabilities.documentHighlightProvider
Expand Down Expand Up @@ -555,4 +567,3 @@

(each [server settings (pairs server-settings)]
(server.setup settings))

10 changes: 9 additions & 1 deletion .config/nvim/init.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit eae37d3

Please sign in to comment.