Skip to content

Commit 553935a

Browse files
committed
attempt to fix lsp
1 parent 1127226 commit 553935a

File tree

6 files changed

+150
-32
lines changed

6 files changed

+150
-32
lines changed

lua/core/keymaps.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ vim.keymap.set('n', '<leader>h', '<C-w>s', opts) -- split window horizontally
5959
vim.keymap.set('n', '<leader>se', '<C-w>=', opts) -- make split windows equal width & height
6060
vim.keymap.set('n', '<leader>xs', ':close<CR>', opts) -- close current split window
6161

62-
-- Navigate between splits
63-
vim.keymap.set('n', '<C-k>', ':wincmd k<CR>', opts)
64-
vim.keymap.set('n', '<C-j>', ':wincmd j<CR>', opts)
65-
vim.keymap.set('n', '<C-h>', ':wincmd h<CR>', opts)
66-
vim.keymap.set('n', '<C-l>', ':wincmd l<CR>', opts)
62+
-- Navigate between splits - DISABLED: Using Zellij navigation
63+
-- vim.keymap.set('n', '<C-k>', ':wincmd k<CR>', opts)
64+
-- vim.keymap.set('n', '<C-j>', ':wincmd j<CR>', opts)
65+
-- vim.keymap.set('n', '<C-h>', ':wincmd h<CR>', opts)
66+
-- vim.keymap.set('n', '<C-l>', ':wincmd l<CR>', opts)
6767

6868
-- Tabs
6969
vim.keymap.set('n', '<leader>to', ':tabnew<CR>', opts) -- open new tab

lua/core/options.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,13 @@ vim.api.nvim_create_autocmd("FileType", {
6969
vim.bo.expandtab = true
7070
end,
7171
})
72+
73+
vim.api.nvim_create_autocmd("FileType", {
74+
pattern = { "typescript", "typescriptreact", "javascript", "javascriptreact" },
75+
callback = function()
76+
vim.bo.tabstop = 2
77+
vim.bo.shiftwidth = 2
78+
vim.bo.softtabstop = 2
79+
vim.bo.expandtab = true
80+
end,
81+
})

lua/plugins/conform.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ return {
2222
args = { "fmt", "-stdin-filepath", "$FILENAME", "-stdout" },
2323
stdin = true,
2424
},
25+
goimports = {
26+
command = "goimports",
27+
args = {},
28+
stdin = true,
29+
},
2530
},
2631
formatters_by_ft = {
2732
templ = { "templ_fmt" }, -- ✅ only templ fmt for .templ
@@ -35,7 +40,7 @@ return {
3540
html = { "prettier" },
3641
css = { "prettier" },
3742
lua = { "stylua" },
38-
go = { "gofmt" },
43+
go = { "goimports", "gofmt" },
3944
},
4045
format_on_save = function(bufnr)
4146
if vim.bo[bufnr].filetype == "templ" then

lua/plugins/lsp.lua

Lines changed: 112 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,52 @@ return {
1111
extension = { templ = "templ" },
1212
})
1313

14-
-- Example setup for Go, TS, etc.
15-
lspconfig.gopls.setup({})
14+
-- Go LSP with import organization
15+
lspconfig.gopls.setup({
16+
root_dir = function(fname)
17+
return util.root_pattern("go.work", "go.mod", ".git")(fname)
18+
or util.path.dirname(fname)
19+
end,
20+
settings = {
21+
gopls = {
22+
gofumpt = true,
23+
codelenses = {
24+
gc_details = false,
25+
generate = true,
26+
regenerate_cgo = true,
27+
run_govulncheck = true,
28+
test = true,
29+
tidy = true,
30+
upgrade_dependency = true,
31+
vendor = true,
32+
},
33+
hints = {
34+
assignVariableTypes = true,
35+
compositeLiteralFields = true,
36+
compositeLiteralTypes = true,
37+
constantValues = true,
38+
functionTypeParameters = true,
39+
parameterNames = true,
40+
rangeVariableTypes = true,
41+
},
42+
analyses = {
43+
fieldalignment = true,
44+
nilness = true,
45+
unusedparams = true,
46+
unusedwrite = true,
47+
useany = true,
48+
},
49+
usePlaceholders = true,
50+
completeUnimported = true,
51+
staticcheck = true,
52+
directoryFilters = { "-.git", "-.vscode", "-.idea", "-.vscode-test", "-node_modules", "-dist", "-build", "-out", "-coverage", "-tmp", "-.cache" },
53+
semanticTokens = true,
54+
-- Performance optimizations for large repositories
55+
memoryMode = "DegradeClosed",
56+
symbolMatcher = "FastFuzzy",
57+
},
58+
},
59+
})
1660

1761
-- TypeScript (make sure you don't also set this up elsewhere to avoid duplicates)
1862
lspconfig.ts_ls.setup({})
@@ -25,6 +69,64 @@ return {
2569
single_file_support = true,
2670
})
2771

72+
-- LSP client monitoring helper
73+
vim.api.nvim_create_user_command('LspClients', function()
74+
local clients = vim.lsp.get_clients()
75+
local client_counts = {}
76+
77+
for _, client in ipairs(clients) do
78+
client_counts[client.name] = (client_counts[client.name] or 0) + 1
79+
end
80+
81+
print("=== Active LSP Clients ===")
82+
for name, count in pairs(client_counts) do
83+
local status = count > 1 and " ⚠️ DUPLICATE" or ""
84+
print(string.format("%s: %d client(s)%s", name, count, status))
85+
end
86+
87+
if next(client_counts) == nil then
88+
print("No active LSP clients")
89+
end
90+
end, { desc = "Show active LSP clients and detect duplicates" })
91+
92+
-- Command to kill duplicate gopls clients (keep only the one with settings)
93+
vim.api.nvim_create_user_command('LspKillDuplicates', function()
94+
local gopls_clients = vim.lsp.get_clients({ name = "gopls" })
95+
if #gopls_clients <= 1 then
96+
print("No duplicate gopls clients found")
97+
return
98+
end
99+
100+
local client_to_keep = nil
101+
local clients_to_kill = {}
102+
103+
-- Find the client with the most settings (should be our configured one)
104+
for _, client in ipairs(gopls_clients) do
105+
local settings_count = 0
106+
if client.config.settings and client.config.settings.gopls then
107+
for _ in pairs(client.config.settings.gopls) do
108+
settings_count = settings_count + 1
109+
end
110+
end
111+
112+
if settings_count > 0 and not client_to_keep then
113+
client_to_keep = client
114+
else
115+
table.insert(clients_to_kill, client)
116+
end
117+
end
118+
119+
-- Kill the duplicates
120+
for _, client in ipairs(clients_to_kill) do
121+
print(string.format("Killing duplicate gopls client (id: %d)", client.id))
122+
client.stop(true)
123+
end
124+
125+
if client_to_keep then
126+
print(string.format("Kept gopls client (id: %d) with settings", client_to_keep.id))
127+
end
128+
end, { desc = "Kill duplicate gopls clients" })
129+
28130
-- Safe hover helper
29131
local function has_hover(bufnr)
30132
for _, c in pairs(vim.lsp.get_active_clients({ bufnr = bufnr })) do
@@ -35,15 +137,20 @@ return {
35137
return false
36138
end
37139

38-
-- Keymaps
140+
-- LSP keymaps are handled in lsp-keymaps.lua
39141
vim.api.nvim_create_autocmd("LspAttach", {
40142
callback = function(args)
41143
local bufnr = args.buf
144+
145+
-- Use the centralized keymap system
146+
local lsp_keymaps = require('plugins.lsp-keymaps')
147+
lsp_keymaps.on_attach(nil, bufnr)
148+
149+
-- Safe hover (keeping this custom logic)
42150
local function buf_map(mode, lhs, rhs, desc)
43151
vim.keymap.set(mode, lhs, rhs, { buffer = bufnr, desc = desc })
44152
end
45-
46-
-- SAFE Hover
153+
47154
buf_map("n", "K", function()
48155
if not has_hover(bufnr) then
49156
return
@@ -55,12 +162,6 @@ return {
55162
pcall(vim.lsp.buf.hover)
56163
end
57164
end, "LSP: Hover (safe)")
58-
59-
-- Usual LSP keymaps
60-
buf_map("n", "gd", vim.lsp.buf.definition, "Goto Definition")
61-
buf_map("n", "gr", vim.lsp.buf.references, "Goto References")
62-
buf_map("n", "gi", vim.lsp.buf.implementation, "Goto Implementation")
63-
buf_map("n", "<leader>rn", vim.lsp.buf.rename, "Rename Symbol")
64165
end,
65166
})
66167
end,

lua/plugins/none-ls.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ return {
3232
formatting.shfmt.with { args = { '-i', '4' } },
3333
require('none-ls.formatting.ruff').with { extra_args = { '--extend-select', 'I' } },
3434
require 'none-ls.formatting.ruff_format',
35+
formatting.goimports, -- Add goimports for Go files
3536
}
3637

3738
local augroup = vim.api.nvim_create_augroup('LspFormatting', {})

lua/plugins/vim-tmux-navigator.lua

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
-- Copied config from https://github.com/christoomey/vim-tmux-navigator
2+
-- DISABLED: Using Zellij navigation instead
23
return {
3-
'christoomey/vim-tmux-navigator',
4-
cmd = {
5-
'TmuxNavigateLeft',
6-
'TmuxNavigateDown',
7-
'TmuxNavigateUp',
8-
'TmuxNavigateRight',
9-
'TmuxNavigatePrevious',
10-
},
11-
keys = {
12-
{ '<c-h>', '<cmd><C-U>TmuxNavigateLeft<cr>' },
13-
{ '<c-j>', '<cmd><C-U>TmuxNavigateDown<cr>' },
14-
{ '<c-k>', '<cmd><C-U>TmuxNavigateUp<cr>' },
15-
{ '<c-l>', '<cmd><C-U>TmuxNavigateRight<cr>' },
16-
{ '<c-\\>', '<cmd><C-U>TmuxNavigatePrevious<cr>' },
17-
},
4+
-- 'christoomey/vim-tmux-navigator',
5+
-- cmd = {
6+
-- 'TmuxNavigateLeft',
7+
-- 'TmuxNavigateDown',
8+
-- 'TmuxNavigateUp',
9+
-- 'TmuxNavigateRight',
10+
-- 'TmuxNavigatePrevious',
11+
-- },
12+
-- keys = {
13+
-- { '<c-h>', '<cmd><C-U>TmuxNavigateLeft<cr>' },
14+
-- { '<c-j>', '<cmd><C-U>TmuxNavigateDown<cr>' },
15+
-- { '<c-k>', '<cmd><C-U>TmuxNavigateUp<cr>' },
16+
-- { '<c-l>', '<cmd><C-U>TmuxNavigateRight<cr>' },
17+
-- { '<c-\\>', '<cmd><C-U>TmuxNavigatePrevious<cr>' },
18+
-- },
1819
}

0 commit comments

Comments
 (0)