Skip to content

Commit ded6bd7

Browse files
committed
Setup go formatting; configure diagnostics as telescope dropdown
1 parent d82930d commit ded6bd7

File tree

1 file changed

+94
-8
lines changed

1 file changed

+94
-8
lines changed

init.lua

Lines changed: 94 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,21 @@ require('lazy').setup({
363363
-- You can put your default mappings / updates / etc. in here
364364
-- All the info you're looking for is in `:help telescope.setup()`
365365
--
366-
-- defaults = {
367-
-- mappings = {
368-
-- i = { ['<c-enter>'] = 'to_fuzzy_refine' },
369-
-- },
370-
-- },
371-
-- pickers = {}
366+
defaults = {
367+
layout_config = {
368+
vertical = { width = 0.8, height = 0.8 },
369+
horizontal = { width = 0.8 },
370+
},
371+
},
372+
pickers = {
373+
diagnostics = {
374+
theme = 'dropdown',
375+
previewer = false,
376+
layout_config = {
377+
width = 0.9,
378+
},
379+
},
380+
},
372381
extensions = {
373382
['ui-select'] = {
374383
require('telescope.themes').get_dropdown(),
@@ -388,11 +397,16 @@ require('lazy').setup({
388397
vim.keymap.set('n', '<leader>ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' })
389398
vim.keymap.set('n', '<leader>sw', builtin.grep_string, { desc = '[S]earch current [W]ord' })
390399
vim.keymap.set('n', '<leader>sg', builtin.live_grep, { desc = '[S]earch by [G]rep' })
391-
vim.keymap.set('n', '<leader>sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' })
392400
vim.keymap.set('n', '<leader>sr', builtin.resume, { desc = '[S]earch [R]esume' })
393401
vim.keymap.set('n', '<leader>s.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' })
394402
vim.keymap.set('n', '<leader><leader>', builtin.buffers, { desc = '[ ] Find existing buffers' })
395403

404+
vim.keymap.set('n', '<leader>sd', function()
405+
builtin.diagnostics {
406+
bufnr = 0,
407+
}
408+
end, { desc = '[S]earch [D]iagnostics' })
409+
396410
-- Slightly advanced example of overriding default behavior and theme
397411
vim.keymap.set('n', '<leader>/', function()
398412
-- You can pass additional configuration to Telescope to change the theme, layout, etc.
@@ -527,6 +541,29 @@ require('lazy').setup({
527541
-- For example, in C this would take you to the header.
528542
map('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
529543

544+
vim.api.nvim_create_autocmd('BufWritePre', {
545+
pattern = '*.go',
546+
callback = function()
547+
local params = vim.lsp.util.make_range_params()
548+
params.context = { only = { 'source.organizeImports' } }
549+
-- buf_request_sync defaults to a 1000ms timeout. Depending on your
550+
-- machine and codebase, you may want longer. Add an additional
551+
-- argument after params if you find that you have to write the file
552+
-- twice for changes to be saved.
553+
-- E.g., vim.lsp.buf_request_sync(0, "textDocument/codeAction", params, 3000)
554+
local result = vim.lsp.buf_request_sync(0, 'textDocument/codeAction', params)
555+
for cid, res in pairs(result or {}) do
556+
for _, r in pairs(res.result or {}) do
557+
if r.edit then
558+
local enc = (vim.lsp.get_client_by_id(cid) or {}).offset_encoding or 'utf-16'
559+
vim.lsp.util.apply_workspace_edit(r.edit, enc)
560+
end
561+
end
562+
end
563+
vim.lsp.buf.format { async = false }
564+
end,
565+
})
566+
530567
-- The following two autocommands are used to highlight references of the
531568
-- word under your cursor when your cursor rests there for a little while.
532569
-- See `:help CursorHold` for information about when this is executed
@@ -587,7 +624,17 @@ require('lazy').setup({
587624
local servers = {
588625
ruby_lsp = {},
589626
-- clangd = {},
590-
gopls = {},
627+
gopls = {
628+
settings = {
629+
gopls = {
630+
analyses = {
631+
unusedparams = true,
632+
},
633+
staticcheck = true,
634+
usePlaceholders = true,
635+
},
636+
},
637+
},
591638
-- pyright = {},
592639
-- rust_analyzer = {},
593640
-- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs
@@ -646,6 +693,44 @@ require('lazy').setup({
646693
end,
647694
},
648695

696+
{ 'nvim-neotest/nvim-nio' },
697+
698+
{
699+
'nvim-neotest/neotest',
700+
dependencies = {
701+
'nvim-treesitter/nvim-treesitter',
702+
'nvim-neotest/neotest-go',
703+
},
704+
opts = {},
705+
config = function()
706+
local neotest = require 'neotest'
707+
708+
neotest.setup {
709+
adapters = {
710+
-- require 'neotest-rspec' {
711+
-- rspec_cmd = function()
712+
-- return vim.tbl_flatten {
713+
-- 'bundle',
714+
-- 'exec',
715+
-- 'rspec',
716+
-- }
717+
-- end,
718+
-- },
719+
require 'neotest-go',
720+
},
721+
output_panel = {
722+
enabled = true,
723+
open = 'botright split | resize 15',
724+
},
725+
quickfix = {
726+
open = false,
727+
},
728+
}
729+
730+
vim.keymap.set('n', '<leader>rt', "<cmd>lua require('neotest').run.run()<CR>", { desc = 'Run Test' })
731+
end,
732+
},
733+
649734
{ -- Autoformat
650735
'stevearc/conform.nvim',
651736
event = { 'BufWritePre' },
@@ -674,6 +759,7 @@ require('lazy').setup({
674759
end,
675760
formatters_by_ft = {
676761
lua = { 'stylua' },
762+
go = { 'gofmt' },
677763
-- Conform can also run multiple formatters sequentially
678764
-- python = { "isort", "black" },
679765
--

0 commit comments

Comments
 (0)