-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
431 lines (396 loc) · 13.9 KB
/
init.lua
File metadata and controls
431 lines (396 loc) · 13.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
-- lazy.nvim
require("config.lazy")
local cmd = vim.cmd
local g = vim.g
-- fzf
vim.keymap.set('n', '<C-p>', ':GFiles<CR>')
vim.keymap.set('n', '<leader>p', ':Files<CR>')
vim.keymap.set('n', '<C-g>', ':Rg<CR>')
vim.keymap.set('n', '<leader>l', ':Buffers<CR>')
g.fzf_colors = {
fg = {'fg', 'Normal'},
bg = {'bg', 'Normal'},
hl = {'fg', 'Comment'},
info = {'fg', 'PreProc'},
border = {'fg', 'Class'},
prompt = {'fg', 'Conditional'},
pointer = {'fg', 'Exception'},
marker = {'fg', 'Keyword'},
spinner = {'fg', 'Label'},
header = {'fg', 'Comment'}
}
g.fzf_colors["fg+"] = {'fg', 'Exception', 'CursorLine', 'CursorColumn', 'Normal'}
g.fzf_colors["bg+"] = {'fg', 'CursorLine', 'CursorColumn'}
g.fzf_colors["hl+"] = {'fg', 'Statement'}
-- =============================================================================
-- LSP Configuration
-- =============================================================================
-- Add capabilities from cmp_nvim_lsp for better completion support
local capabilities = require('cmp_nvim_lsp').default_capabilities()
-- -----------------------------------------------------------------------------
-- Python: Pyright (global) + Ruff (project-local via uv)
-- -----------------------------------------------------------------------------
vim.lsp.config.pyright = {
cmd = { "pyright-langserver", "--stdio" },
filetypes = { "python" },
capabilities = capabilities,
before_init = function(_, config)
local venv = vim.fn.getcwd() .. "/.venv"
if vim.fn.isdirectory(venv) == 1 then
config.settings.python.pythonPath = venv .. "/bin/python"
end
end,
settings = {
pyright = {
disableOrganizeImports = true,
},
python = {
analysis = {
typeCheckingMode = "basic",
autoImportCompletions = true,
diagnosticSeverityOverrides = {
reportUnusedImport = "none",
reportUnusedVariable = "none",
},
},
},
},
}
vim.lsp.config.ruff = {
cmd = { "ruff", "server" },
filetypes = { "python" },
capabilities = capabilities,
before_init = function(_, config)
local venv = vim.fn.getcwd() .. "/.venv"
if vim.fn.isdirectory(venv) == 1 then
local ruff_path = venv .. "/bin/ruff"
if vim.fn.executable(ruff_path) == 1 then
config.cmd = { ruff_path, "server" }
else
vim.notify("No ruff in .venv, using global", vim.log.levels.WARN)
end
end
end,
init_options = {
settings = {
lineLength = 88,
lint = {
select = { "E", "F", "UP", "B", "SIM", "I" },
},
},
},
}
-- -----------------------------------------------------------------------------
-- Rust: rust-analyzer with clippy
-- -----------------------------------------------------------------------------
vim.lsp.config.rust_analyzer = {
cmd = { "rust-analyzer" },
filetypes = { "rust" },
root_markers = { "Cargo.toml", "rust-project.json" },
capabilities = capabilities,
settings = {
["rust-analyzer"] = {
cargo = {
allFeatures = true,
loadOutDirsFromCheck = true,
},
check = {
command = "clippy",
extraArgs = {
"--",
"-W", "clippy::pedantic",
"-W", "clippy::nursery",
"-A", "clippy::module_name_repetitions",
"-A", "clippy::too_many_lines",
},
},
procMacro = {
enable = true,
},
imports = {
granularity = { group = "module" },
prefix = "self",
},
completion = {
postfix = { enable = true },
},
inlayHints = {
bindingModeHints = { enable = true },
closureCaptureHints = { enable = true },
closureReturnTypeHints = { enable = "with_block" },
lifetimeElisionHints = { enable = "skip_trivial" },
},
},
},
}
-- -----------------------------------------------------------------------------
-- C/C++: clangd
-- -----------------------------------------------------------------------------
vim.lsp.config.clangd = {
capabilities = capabilities,
filetypes = { "c", "cpp", "objc", "objcpp", "cuda", "proto" },
cmd = {
"clangd",
"--background-index",
"--clang-tidy",
"--header-insertion=iwyu",
"--completion-style=detailed",
"--function-arg-placeholders",
},
}
-- -----------------------------------------------------------------------------
-- MLIR / TableGen
-- -----------------------------------------------------------------------------
vim.lsp.config.mlir_lsp_server = { capabilities = capabilities }
vim.lsp.config.tblgen_lsp_server = { capabilities = capabilities }
-- -----------------------------------------------------------------------------
-- Enable servers
-- -----------------------------------------------------------------------------
local servers = {
"pyright", "ruff", "rust_analyzer",
"clangd", "mlir_lsp_server", "tblgen_lsp_server",
}
for _, server in ipairs(servers) do
vim.lsp.enable(server)
end
-- -----------------------------------------------------------------------------
-- Inlay hints (enabled by default)
-- -----------------------------------------------------------------------------
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("UserLspInlayHints", {}),
callback = function(args)
local client = vim.lsp.get_client_by_id(args.data.client_id)
-- Only enable inlay hints for buffers with valid file paths
local bufname = vim.api.nvim_buf_get_name(args.buf)
if client and client.supports_method("textDocument/inlayHint") and bufname ~= "" then
vim.lsp.inlay_hint.enable(true, { bufnr = args.buf })
end
end,
})
-- -----------------------------------------------------------------------------
-- Diagnostics keymaps (global)
-- -----------------------------------------------------------------------------
vim.keymap.set("n", "<space>e", vim.diagnostic.open_float, { desc = "Show diagnostic float" })
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, { desc = "Previous diagnostic" })
vim.keymap.set("n", "]d", vim.diagnostic.goto_next, { desc = "Next diagnostic" })
vim.keymap.set("n", "<space>q", vim.diagnostic.setloclist, { desc = "Diagnostics to loclist" })
-- -----------------------------------------------------------------------------
-- LSP keymaps (buffer-local on attach)
-- -----------------------------------------------------------------------------
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
callback = function(ev)
vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc"
local function map(mode, lhs, rhs, desc)
vim.keymap.set(mode, lhs, rhs, { buffer = ev.buf, desc = desc })
end
-- Navigation
map("n", "gD", vim.lsp.buf.declaration, "Go to declaration")
map("n", "gd", vim.lsp.buf.definition, "Go to definition")
map("n", "gi", vim.lsp.buf.implementation, "Go to implementation")
map("n", "gr", vim.lsp.buf.references, "Find references")
map("n", "<space>D", vim.lsp.buf.type_definition, "Type definition")
-- Documentation
map("n", "K", vim.lsp.buf.hover, "Hover documentation")
map("n", "<C-k>", vim.lsp.buf.signature_help, "Signature help")
-- Refactoring
map("n", "<space>rn", vim.lsp.buf.rename, "Rename symbol")
map({ "n", "v" }, "<space>ca", vim.lsp.buf.code_action, "Code action")
map("n", "<space>f", function()
vim.lsp.buf.format({ async = true })
end, "Format buffer")
-- Workspace
map("n", "<space>wa", vim.lsp.buf.add_workspace_folder, "Add workspace folder")
map("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, "Remove workspace folder")
map("n", "<space>wl", function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, "List workspace folders")
-- Toggle inlay hints
map("n", "<space>th", function()
vim.lsp.inlay_hint.enable(
not vim.lsp.inlay_hint.is_enabled({ bufnr = ev.buf }),
{ bufnr = ev.buf }
)
end, "Toggle inlay hints")
end,
})
-- GitHub Copilot mappings.
vim.g.copilot_no_tab_map = true
vim.api.nvim_set_keymap('i', '<C-l>', 'copilot#Accept("")', { expr = true, silent = true })
-- Next suggestion
vim.keymap.set('i', '<M-]>', '<Cmd>call copilot#Next()<CR>', { silent = true })
-- Previous suggestion
vim.keymap.set('i', '<M-[>', '<Cmd>call copilot#Previous()<CR>', { silent = true })
-- Dismiss current suggestion
vim.keymap.set('i', '<M-x>', '<Cmd>call copilot#Dismiss()<CR>', { silent = true })
-- Global Copilot toggle function
local function toggle_copilot_global()
if vim.g.copilot_enabled == false then
vim.cmd('Copilot enable')
vim.g.copilot_enabled = true
print('Copilot enabled globally')
else
vim.cmd('Copilot disable')
vim.g.copilot_enabled = false
print('Copilot disabled globally')
end
end
-- Toggle Copilot on/off (global) - normal mode
vim.keymap.set('n', '<leader>cg', toggle_copilot_global, { silent = false, desc = 'Toggle Copilot globally' })
-- Show Copilot suggestions panel
vim.keymap.set('i', '<M-p>', '<Cmd>Copilot panel<CR>', { silent = true })
-- Buffer-specific Copilot toggle function
local function toggle_copilot_buffer()
local buf = vim.api.nvim_get_current_buf()
if vim.b[buf].copilot_enabled == false then
vim.cmd('Copilot enable')
vim.b[buf].copilot_enabled = true
print('Copilot enabled for this buffer')
else
vim.cmd('Copilot disable')
vim.b[buf].copilot_enabled = false
print('Copilot disabled for this buffer')
end
end
-- Toggle Copilot for current buffer - normal mode
vim.keymap.set('n', '<leader>ct', toggle_copilot_buffer, { silent = false, desc = 'Toggle Copilot for buffer' })
-- luasnip setup
local luasnip = require 'luasnip'
-- nvim-cmp setup
local cmp = require 'cmp'
cmp.setup {
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
['<C-u>'] = cmp.mapping.scroll_docs(-4), -- Up
['<C-d>'] = cmp.mapping.scroll_docs(4), -- Down
-- C-b (back) C-f (forward) for snippet placeholder navigation.
['<C-Space>'] = cmp.mapping.complete(),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
else
fallback()
end
end, { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { 'i', 's' }),
}),
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
},
}
-- Colorschemes
-- Catppuccin
require("catppuccin").setup({
-- flavour = "auto", -- latte, frappe, macchiato, mocha
flavour = "macchiato", -- latte, frappe, macchiato, mocha
background = { -- :h background
light = "latte",
dark = "mocha",
},
transparent_background = true, -- disables setting the background color.
show_end_of_buffer = false, -- shows the '~' characters after the end of buffers
term_colors = false, -- sets terminal colors (e.g. `g:terminal_color_0`)
dim_inactive = {
enabled = false, -- dims the background color of inactive window
shade = "dark",
percentage = 0.15, -- percentage of the shade to apply to the inactive window
},
no_italic = false, -- Force no italic
no_bold = false, -- Force no bold
no_underline = false, -- Force no underline
styles = { -- Handles the styles of general hi groups (see `:h highlight-args`):
comments = { "italic" }, -- Change the style of comments
conditionals = { "italic" },
loops = {},
functions = {},
keywords = {},
strings = {},
variables = {},
numbers = {},
booleans = {},
properties = {},
types = {},
operators = {},
-- miscs = {}, -- Uncomment to turn off hard-coded styles
},
color_overrides = {},
custom_highlights = function(colors)
return {
Comment = { fg = colors.flamingo },
-- TabLineSel = { bg = colors.pink },
-- CmpBorder = { fg = colors.surface2 },
-- Pmenu = { bg = colors.none },
}
end,
-- custom_highlights = {},
default_integrations = true,
integrations = {
cmp = true,
gitsigns = false,
nvimtree = false,
treesitter = true,
notify = false,
mini = {
enabled = false,
indentscope_color = "",
},
native_lsp = {
enabled = true,
virtual_text = {
errors = { "italic" },
hints = { "italic" },
warnings = { "italic" },
information = { "italic" },
},
underlines = {
errors = { "underline" },
hints = { "underline" },
warnings = { "underline" },
information = { "underline" },
},
inlay_hints = {
background = true,
},
},
-- For more plugins integrations please scroll down (https://github.com/catppuccin/nvim#integrations)
},
})
-- setup must be called before loading
cmd[[colorscheme catppuccin]]
cmd [[hi VertSplit cterm=NONE guibg=NONE]]
-- Support for MDX files with nvim-treesitter
vim.filetype.add({
extension = {
mdx = "markdown"
}
})
-- Leader+d to delete/cut to system clipboard
vim.keymap.set({'n', 'v'}, '<leader>d', '"+d')
vim.keymap.set('n', '<leader>dd', '"+dd')
-- Leader+y to yank/copy to system clipboard
vim.keymap.set({'n', 'v'}, '<leader>y', '"+y')
vim.keymap.set('n', '<leader>yy', '"+yy')
-- Leader+v / Leader+V to paste from system clipboard (after / before cursor)
vim.keymap.set({'n', 'v'}, '<leader>v', '"+p')
vim.keymap.set({'n', 'v'}, '<leader>V', '"+P')
-- Optional: Leader+p in insert mode
vim.keymap.set('i', '<leader>p', '<C-r>+')