@@ -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 ,
0 commit comments