forked from nvim-lua/kickstart.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
1434 lines (1284 loc) · 53 KB
/
Copy pathinit.lua
File metadata and controls
1434 lines (1284 loc) · 53 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
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- Neovim config (kshksdrt)
-- init.lua holds options, base keymaps and the lazy.nvim bootstrap.
-- Everything else lives under lua/{plugins,keymaps,commands,utils}/.
-- Leader keys. Must be set before plugins load, or they bind the old leader.
vim.g.mapleader = ' '
vim.g.maplocalleader = ' '
-- Gates nerd-font glyphs throughout the config.
vim.g.have_nerd_font = true
local platform_utils = require 'utils.platform'
if platform_utils.is_windows() then
vim.opt.shell = 'pwsh'
vim.opt.shellcmdflag = '-NoLogo -NoProfile -NonInteractive -ExecutionPolicy RemoteSigned -Command'
vim.opt.shellquote = ''
vim.opt.shellxquote = ''
else
vim.opt.shell = 'fish'
end
if vim.g.neovide then
vim.opt.title = true
vim.opt.titlestring = vim.fn.fnamemodify(vim.fn.getcwd(), ':t') .. ' - Neovide'
vim.opt.linespace = 2
-- Skia's defaults (0.0/0.5) thicken glyph stems; these sit just shy of Alacritty's rendering
-- Lower gamma / higher contrast = thicker stems for light-on-dark text
-- vim.g.neovide_text_gamma = 0.7
-- vim.g.neovide_text_contrast = 0.25
vim.g.neovide_progress_bar_enabled = true
vim.g.neovide_progress_bar_height = 5.0
vim.g.neovide_progress_bar_animation_speed = 200.0
vim.g.neovide_progress_bar_hide_delay = 0.2
-- vim.g.neovide_scroll_animation_length = 0.2 -- Default is good enough
vim.g.neovide_cursor_animation_length = 0 -- Cursor position animation
vim.g.neovide_position_animation_length = 0 -- Window position animation
vim.g.neovide_refresh_rate = 144
vim.g.neovide_cursor_animate_command_line = false
vim.g.neovide_cursor_antialiasing = false
vim.g.neovide_cursor_animate_command_line = false
vim.g.neovide_cursor_animate_in_insert_mode = false
vim.g.neovide_hide_mouse_when_typing = true
vim.g.neovide_floating_blur_amount_x = 0
vim.g.neovide_floating_blur_amount_y = 0
vim.g.neovide_floating_shadow = false
vim.g.neovide_floating_z_height = 10
vim.g.neovide_light_angle_degrees = 45
vim.g.neovide_light_radius = 0
vim.g.neovide_opacity = 1
vim.g.neovide_normal_opacity = 1
end
-- Options. See `:help option-list`.
vim.o.number = true
vim.o.relativenumber = false
vim.opt.wrap = false
vim.keymap.set('n', 'gz', ':set wrap!<CR>', { noremap = true, silent = true, desc = 'Toggle line wrapping' })
-- Keep 10 lines of context above and below the cursor.
vim.opt.scrolloff = 10
vim.o.mouse = 'a'
-- The mode already shows in the statusline.
vim.o.showmode = false
-- Overridden further down: mini.tabline forces showtabline=2 and renders the
-- breadcrumb there. Left at 0 as the fallback if that block ever goes away.
vim.o.showtabline = 0
-- One global statusline instead of one per split. mini.statusline handles this
-- and always renders the focused window's section.
vim.o.laststatus = 3
-- Share the OS clipboard. Deferred, because setting it costs startup time.
vim.schedule(function()
vim.o.clipboard = 'unnamedplus'
end)
vim.o.breakindent = true
vim.o.undofile = true
-- Case-insensitive search, unless the pattern has a capital or \C.
vim.o.ignorecase = true
vim.o.smartcase = true
vim.o.signcolumn = 'yes'
vim.o.updatetime = 250
vim.o.timeoutlen = 300
-- Don't redraw while executing macros.
vim.opt.lazyredraw = true
vim.o.splitright = true
vim.o.splitbelow = true
-- Show whitespace.
vim.o.list = true
vim.opt.listchars = {
tab = '· ',
trail = '·',
nbsp = '␣',
}
-- Live preview of :s substitutions in a split.
vim.o.inccommand = 'split'
vim.o.cursorline = true
-- Disable netrw; snacks.explorer replaces it (lua/plugins/snacks.lua).
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
-- Opening a directory would leave an empty directory buffer behind. Close it.
vim.api.nvim_create_autocmd('VimEnter', {
callback = function()
if vim.fn.isdirectory(vim.fn.expand '%') == 1 then
vim.cmd 'bd'
end
end,
})
-- Prompt to save instead of failing, on `:q` with unsaved changes.
vim.o.confirm = true
-- Base keymaps. The rest live under lua/keymaps/.
-- Clear search highlight.
vim.keymap.set('n', '<Esc>', '<cmd>nohlsearch<CR>')
vim.keymap.set('n', '<leader>dq', vim.diagnostic.setloclist, { desc = 'Open [D]iagnostic [Q]uickfix list' })
-- Easier to reach than the built-in <C-\><C-n>. Some terminals swallow it.
vim.keymap.set('t', '<Esc><Esc>', '<C-\\><C-n>', { desc = 'Exit terminal mode' })
vim.opt.expandtab = false
vim.opt.tabstop = 4
vim.opt.shiftwidth = 4
-- Quickfix list navigation
vim.keymap.set('n', '<C-j>', '<cmd>cnext<CR>zz', { desc = 'Go to the next quickfix item' })
vim.keymap.set('n', '<C-k>', '<cmd>cprev<CR>zz', { desc = 'Go to the previous quickfix item' })
-- Shell tools
vim.keymap.set('n', '<leader>x', ':exe "!" . getline(".")<CR>', { noremap = true, silent = false, desc = 'Execute current line in shell' })
vim.keymap.set('n', '<leader>cd', function()
vim.fn.setreg('+', vim.fn.getcwd())
print 'Current directory copied to clipboard'
end, { noremap = true, silent = true, desc = 'Copy workspace directory' })
vim.keymap.set('v', '<leader>y', function()
local start_line, end_line = vim.fn.line "'<", vim.fn.line "'>"
local lines = vim.api.nvim_buf_get_lines(0, start_line - 1, end_line, false)
vim.api.nvim_buf_set_lines(0, start_line - 1, end_line, false, {})
local executed, errors = 0, 0
for i, line in ipairs(lines) do
if line:match '%S' then -- Check if line is not just whitespace
local success, error_msg = pcall(vim.cmd, line)
if success then
executed = executed + 1
else
errors = errors + 1
print(string.format('Error on line %d: %s', start_line + i - 1, error_msg))
end
end
end
print(string.format('Executed %d command(s), encountered %d error(s)', executed, errors))
end, { noremap = true, silent = true, desc = 'Execute selected lines as commands' })
-- Off: many terminals either collide with these or can't send them distinctly.
-- vim.keymap.set("n", "<C-S-h>", "<C-w>H", { desc = "Move window to the left" })
-- vim.keymap.set("n", "<C-S-l>", "<C-w>L", { desc = "Move window to the right" })
-- vim.keymap.set("n", "<C-S-j>", "<C-w>J", { desc = "Move window to the lower" })
-- vim.keymap.set("n", "<C-S-k>", "<C-w>K", { desc = "Move window to the upper" })
-- Briefly highlight yanked text.
vim.api.nvim_create_autocmd('TextYankPost', {
desc = 'Highlight when yanking (copying) text',
group = vim.api.nvim_create_augroup('yank-highlight', { clear = true }),
callback = function()
vim.hl.on_yank()
end,
})
-- Bootstrap lazy.nvim. See https://github.com/folke/lazy.nvim
local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim'
if not (vim.uv or vim.loop).fs_stat(lazypath) then
local lazyrepo = 'https://github.com/folke/lazy.nvim.git'
local out = vim.fn.system { 'git', 'clone', '--filter=blob:none', '--branch=stable', lazyrepo, lazypath }
if vim.v.shell_error ~= 0 then
error('Error cloning lazy.nvim:\n' .. out)
end
end
---@type vim.Option
local rtp = vim.opt.rtp
rtp:prepend(lazypath)
-- Plugins. `:Lazy` for status, `:Lazy update` to update.
require('lazy').setup({
'NMAC427/guess-indent.nvim', -- Detect tabstop and shiftwidth automatically
{ -- Popup listing the keybinds that can follow what you've typed.
'folke/which-key.nvim',
event = 'VimEnter',
opts = {
-- Milliseconds before the popup opens. Independent of 'timeoutlen'.
delay = 500,
preset = 'helix',
icons = {
mappings = vim.g.have_nerd_font,
separator = '',
-- Empty table = which-key's own nerd-font icons. The fallback spells the keys out.
keys = vim.g.have_nerd_font and {} or {
Up = '<Up> ',
Down = '<Down> ',
Left = '<Left> ',
Right = '<Right> ',
C = '<C-…> ',
M = '<M-…> ',
D = '<D-…> ',
S = '<S-…> ',
CR = '<CR> ',
Esc = '<Esc> ',
ScrollWheelDown = '<ScrollWheelDown> ',
ScrollWheelUp = '<ScrollWheelUp> ',
NL = '<NL> ',
BS = '<BS> ',
Space = '<Space> ',
Tab = '<Tab> ',
F1 = '<F1>',
F2 = '<F2>',
F3 = '<F3>',
F4 = '<F4>',
F5 = '<F5>',
F6 = '<F6>',
F7 = '<F7>',
F8 = '<F8>',
F9 = '<F9>',
F10 = '<F10>',
F11 = '<F11>',
F12 = '<F12>',
},
},
-- Document existing key chains
spec = {
{ '<leader>s', group = '[S]earch' },
{ '<leader>t', group = '[T]oggle' },
{ '<leader>h', group = 'Git [H]unk', mode = { 'n', 'v' } },
},
},
},
-- LSP
{
-- Teaches lua_ls about the Neovim API, runtime and installed plugins.
'folke/lazydev.nvim',
ft = 'lua',
opts = {
library = {
-- Load luvit types when the `vim.uv` word is found
{ path = '${3rd}/luv/library', words = { 'vim%.uv' } },
},
},
},
{
-- Main LSP configuration
'neovim/nvim-lspconfig',
dependencies = {
-- Installs servers and tools. Must load before anything that depends on it.
{
'mason-org/mason.nvim',
version = '^1.0.0',
opts = {
registries = {
'github:mason-org/mason-registry',
'github:Crashdummyy/mason-registry',
},
},
},
-- No `mason-lspconfig` on purpose. Servers are enabled through `vim.lsp` at
-- the end of this block, and mason-tool-installer gets real Mason package
-- names, so its lspconfig-name <-> package-name table is not needed.
'WhoIsSethDaniel/mason-tool-installer.nvim',
{
'saghen/blink.cmp',
branch = 'v1',
lazy = false,
dependencies = {
'rafamadriz/friendly-snippets', -- optional: provides snippets for the snippet source
'xzbdmw/colorful-menu.nvim',
},
---@module 'blink.cmp'
---@type blink.cmp.Config
opts = {
keymap = {
-- Other presets: 'super-tab', 'enter'. See `:h blink-cmp-config-keymap`.
preset = 'default',
},
completion = {
menu = {
auto_show = true,
draw = {
-- No label_description column: colorful-menu folds it into label.
columns = { { 'kind_icon' }, { 'label', gap = 1 } },
components = {
label = {
text = function(ctx)
return require('colorful-menu').blink_components_text(ctx)
end,
highlight = function(ctx)
return require('colorful-menu').blink_components_highlight(ctx)
end,
},
},
},
},
documentation = {
auto_show = true,
auto_show_delay_ms = 500,
window = {
border = 'single',
},
},
},
sources = {
-- `snippets` reads friendly-snippets plus every `<filetype>.json`
-- under this config's `snippets/` directory -- no path to declare.
default = { 'snippets', 'lsp', 'path', 'buffer' },
providers = {
cmdline = {
min_keyword_length = function(ctx)
-- Only complete a bare command name once 3 characters are typed.
if ctx.mode == 'cmdline' and string.find(ctx.line, ' ') == nil then
return 3
end
return 0
end,
},
},
},
cmdline = {
keymap = {
preset = 'inherit',
},
completion = {
menu = {
auto_show = true,
min_keyword_length = 3,
},
},
},
appearance = {
-- 'mono' for Nerd Font Mono, 'normal' for Nerd Font. Aligns icon spacing.
nerd_font_variant = 'mono',
},
signature = {
enabled = true,
window = {
border = 'single',
},
},
},
-- Lets other specs append to enabled_providers instead of redefining it.
opts_extend = {
'sources.completion.enabled_providers',
},
},
-- LSP progress notifications.
{ 'j-hui/fidget.nvim', opts = {} },
'saghen/blink.cmp',
},
config = function(_, opts)
-- Runs once per client, every time a server attaches to a buffer.
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('lsp-attach', { clear = true }),
callback = function(event)
-- Buffer-local mapping helper: sets mode, buffer and description for us.
local map = function(keys, func, desc, mode)
mode = mode or 'n'
vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc })
end
-- Wrap an LSP "locations" method so its results land in a named quickfix
-- list. The symbol is captured before the async request returns and baked
-- into the title, so `:chistory` and the Snacks history picker read
-- "References: my_function" rather than a bare "References".
--
-- needs_context = true -> references(context, opts)
-- needs_context = false -> definition/implementation/type_definition(opts)
local function lsp_qf(label, fn, needs_context)
return function()
local symbol = vim.fn.expand '<cword>'
-- Show a statusline indicator while the request is in flight; the
-- LSP-activity section of mini.statusline's content() renders it.
-- The token guards against a request that never completes: it can
-- neither linger nor clear a newer request's indicator.
_G.LspActivityToken = (_G.LspActivityToken or 0) + 1
local token = _G.LspActivityToken
_G.LspActivity = label
vim.cmd 'redrawstatus'
local function clear_activity()
if _G.LspActivityToken == token then
_G.LspActivity = nil
vim.cmd 'redrawstatus'
end
end
vim.defer_fn(clear_activity, 15000) -- safety net if the server never responds
local opts = {
on_list = function(t)
clear_activity()
-- ' ' (space) action pushes a NEW list onto the stack -> history.
vim.fn.setqflist({}, ' ', {
title = ('%s: %s'):format(label, symbol),
items = t.items,
context = { time = os.time(), lsp = t.context },
})
if #t.items == 1 then
vim.cmd.cfirst() -- jump straight to a lone result
else
vim.cmd 'botright copen'
end
end,
}
if needs_context then
fn(nil, opts)
else
fn(opts)
end
end
end
local client = vim.lsp.get_client_by_id(event.data.client_id)
local Methods = vim.lsp.protocol.Methods
-- Bind only if the attaching client implements the method. LspAttach fires
-- once per client, so the real server still installs these when it arrives.
-- Without the guard, copilot.lua's client (started on InsertEnter, often
-- first in a large TS project) claimed `gd` and warned that definition was
-- unsupported until the TS server caught up.
local function map_if(method, keys, func, desc, mode)
if client and client:supports_method(method, event.buf) then
map(keys, func, desc, mode)
end
end
-- Goto navigation, overriding the built-in gr* defaults with versions
-- that produce titled quickfix lists.
map_if(Methods.textDocument_definition, 'gd', lsp_qf('Definitions', vim.lsp.buf.definition, false), '[G]oto [D]efinition')
map_if(Methods.textDocument_references, 'grr', lsp_qf('References', vim.lsp.buf.references, true), '[G]oto [R]eferences')
map_if(Methods.textDocument_implementation, 'gri', lsp_qf('Implementations', vim.lsp.buf.implementation, false), '[G]oto [I]mplementation')
map_if(Methods.textDocument_typeDefinition, 'grt', lsp_qf('Type Definitions', vim.lsp.buf.type_definition, false), '[G]oto [T]ype Definition')
-- Rename the symbol under your cursor (most servers do this across files).
map_if(Methods.textDocument_rename, '<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame Symbol')
map_if(Methods.textDocument_rename, '<F2>', vim.lsp.buf.rename, 'Rename Symbol')
-- Code action. Cursor usually needs to be on an error/suggestion.
map_if(Methods.textDocument_codeAction, '<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction', { 'n', 'x' })
-- Declaration, not definition. In C this lands in the header.
map_if(Methods.textDocument_declaration, 'gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
-- Disabled: highlight other references to the word under the cursor once
-- it rests there, and clear them when it moves. See `:help CursorHold`.
-- if client and client:supports_method(vim.lsp.protocol.Methods.textDocument_documentHighlight, event.buf) then
-- local highlight_augroup = vim.api.nvim_create_augroup('lsp-highlight', { clear = false })
-- vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
-- buffer = event.buf,
-- group = highlight_augroup,
-- callback = vim.lsp.buf.document_highlight,
-- })
--
-- vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, {
-- buffer = event.buf,
-- group = highlight_augroup,
-- callback = vim.lsp.buf.clear_references,
-- })
--
-- vim.api.nvim_create_autocmd('LspDetach', {
-- group = vim.api.nvim_create_augroup('lsp-detach', { clear = true }),
-- callback = function(event2)
-- vim.lsp.buf.clear_references()
-- vim.api.nvim_clear_autocmds { group = 'lsp-highlight', buffer = event2.buf }
-- end,
-- })
-- end
-- Toggle inlay hints where the server supports them.
if client and client:supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint, event.buf) then
map('<leader>th', function()
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf })
end, '[T]oggle Inlay [H]ints')
end
end,
})
-- Signature
vim.keymap.set('i', '<C-s>', function()
vim.lsp.buf.signature_help {
border = 'single',
max_height = 25,
max_width = 120,
}
end, {
desc = 'Show signature help',
})
-- Define a highlight group for the border color
vim.api.nvim_set_hl(0, 'FloatBorderCustom', { fg = '#404040' })
local border = {
{ '┌', 'FloatBorderCustom' },
{ '─', 'FloatBorderCustom' },
{ '┐', 'FloatBorderCustom' },
{ '│', 'FloatBorderCustom' },
{ '┘', 'FloatBorderCustom' },
{ '─', 'FloatBorderCustom' },
{ '└', 'FloatBorderCustom' },
{ '│', 'FloatBorderCustom' },
}
-- General diagnostic config
vim.diagnostic.config {
update_in_insert = false,
signs = true,
virtual_text = false,
-- virtual_text = {
-- source = 'if_many',
-- spacing = 2,
-- format = function(diagnostic)
-- local diagnostic_message = {
-- [vim.diagnostic.severity.ERROR] = diagnostic.message,
-- [vim.diagnostic.severity.WARN] = diagnostic.message,
-- [vim.diagnostic.severity.INFO] = diagnostic.message,
-- [vim.diagnostic.severity.HINT] = diagnostic.message,
-- }
-- return diagnostic_message[diagnostic.severity]
-- end,
-- },
underline = false,
severity_sort = true,
float = {
border = border,
style = 'minimal',
source = 'always',
},
}
vim.keymap.set('n', 'K', function()
vim.lsp.buf.hover {
border = 'single',
max_height = 25,
max_width = 120,
}
end, {
desc = 'Hover documentation',
})
-- Change diagnostic symbols in the sign column (gutter)
if vim.g.have_nerd_font then
local signs = { ERROR = '', WARN = '', INFO = '', HINT = '' }
local diagnostic_signs = {}
for type, icon in pairs(signs) do
diagnostic_signs[vim.diagnostic.severity[type]] = icon
end
vim.diagnostic.config { signs = { text = diagnostic_signs } }
end
-- Also exports `$MASON`, which the vue plugin path below relies on.
require('mason').setup()
-- Ships inside the `vue-language-server` Mason package. Loaded into `ts_ls`
-- below as a tsserver plugin, so `vue_ls` can run in hybrid mode.
local vue_plugin = {
name = '@vue/typescript-plugin',
location = vim.fn.expand '$MASON/packages/vue-language-server/node_modules/@vue/language-server',
languages = { 'vue' },
configNamespace = 'typescript',
}
-- Filetypes owned by whichever JS/TS server is selected. `vue` is absent on
-- purpose: it always belongs to `ts_ls`, never `tsgo`. The `:TsServer` toggle
-- at the end of this block reassigns this list, so keep it the only copy.
local ts_filetypes = { 'javascript', 'javascriptreact', 'typescript', 'typescriptreact' }
-- Keys are lspconfig server names (`:help lspconfig-all`). Everything listed
-- here is configured and enabled at the bottom of this block. Mason package
-- names are a separate namespace, handled by mason-tool-installer below --
-- formatters and linters belong there, not here.
local servers = {
-- C/C++/ObjC/CUDA, using the *system* clangd rather than a Mason copy so it
-- shares the resource dir and GCC headers the local compiler uses. A Mason
-- clangd on an older LLVM drifts from those and invents errors in system
-- headers. Hence no `clangd` under mason-tool-installer below.
-- Root markers, utf-8 offset negotiation and the `:LspClangd*` commands all
-- come from nvim-lspconfig's `lsp/clangd.lua`.
clangd = {
-- The only flag that differs from clangd 22's defaults. Background indexing,
-- clang-tidy, iwyu header insertion, detailed completion and `.clangd`
-- reading are already on; repeating them here would only rot.
-- `memory` trades RAM for faster reparses; drop it if a big C++ tree gets heavy.
cmd = { 'clangd', '--pch-storage=memory' },
init_options = {
-- Only for files with no `compile_commands.json` entry: scratch files,
-- single-file programs, headers outside the build. Language-neutral,
-- since this server also owns C++ and a `-std=` would break one of the
-- two. Per-project flags belong in `.clangd` / `compile_flags.txt`.
fallbackFlags = { '-Wall', '-Wextra' },
},
},
gopls = {
cmd = { 'gopls' },
},
-- pyright = {},
-- rust_analyzer = {},
-- TypeScript 7 (`typescript-go`), the Go port of tsserver, and the default
-- owner of `ts_filetypes`. Coverage is still partial and it cannot load
-- tsserver plugins, which is why `ts_ls` below stays around for Vue.
-- Defaults come from nvim-lspconfig's `lsp/tsgo.lua`.
tsgo = { filetypes = ts_filetypes },
-- Always owns Vue, as the carrier of `@vue/typescript-plugin`. `vue_ls` runs
-- in hybrid mode: it owns the template/style blocks and forwards
-- `tsserver/request` to the attached TS client, and only `ts_ls` can load
-- that plugin. The forwarding handler ships with nvim-lspconfig, so no
-- `on_init` here. Also takes `ts_filetypes` when `:TsServer` picks it.
-- See https://github.com/vuejs/language-tools/wiki/Neovim
ts_ls = {
filetypes = { 'vue' },
init_options = {
plugins = { vue_plugin },
},
on_attach = function(client, bufnr)
-- vue_ls supplies semantic tokens for .vue files, so let it win there and
-- keep them elsewhere. Read the filetype from `bufnr`, not the current
-- buffer: `:TsServer` re-attaches buffers that may not be focused.
local caps = client.server_capabilities
if caps.semanticTokensProvider then
caps.semanticTokensProvider.full = vim.bo[bufnr].filetype ~= 'vue'
end
-- Formatting and highlighting come from conform.nvim (prettier) and treesitter.
caps.documentFormattingProvider = nil
caps.documentHighlightProvider = nil
end,
},
vue_ls = {},
lua_ls = {
settings = {
Lua = {
completion = {
callSnippet = 'Replace',
},
-- Uncomment to silence lua_ls's noisy `missing-fields` warnings.
-- diagnostics = { disable = { 'missing-fields' } },
},
},
},
-- Configured and enabled by roslyn.nvim itself; this only layers on settings.
-- NOTE: duplicated by the `opts` in lua/plugins/lsps.lua. Change both, or drop one.
roslyn = {
['csharp|formatting'] = {
csharp_enable_inlay_hints_for_implicit_object_creation = true,
csharp_enable_inlay_hints_for_implicit_variable_types = true,
indent_style = 'space',
indent_size = 4,
tab_width = 4,
},
['csharp|code_style'] = {
formatting = {
indent_style = 'space',
indent_size = 4,
},
},
['csharp|code_lens'] = {
dotnet_enable_references_code_lens = false,
},
},
markdown_oxide = {},
rust_analyzer = {
settings = {
checkOnSave = true,
check = {
command = 'check',
extraArgs = { '--jobs=2' },
},
cargo = {
buildScripts = {
enable = false,
},
},
procMacro = {
enable = true,
},
},
},
tinymist = {
settings = {
formatterMode = 'typstyle',
exportPdf = 'never',
},
},
}
-- Mason package names; browse them with `:Mason`. Spelled out rather than
-- derived from `servers`, because the two namespaces don't line up: `ts_ls`
-- ships as `typescript-language-server`, and formatters have no server entry
-- at all. A translation table goes stale; real package names cannot.
require('mason-tool-installer').setup {
ensure_installed = {
-- Language servers. `clangd` is absent on purpose -- it comes from the
-- system clang install; see its entry in `servers` above.
'gopls',
'lua-language-server',
'markdown-oxide',
'roslyn',
'rust-analyzer',
'tinymist',
'tsgo', -- TypeScript 7 / @typescript/native-preview
'typescript-language-server', -- `ts_ls`, Vue only
'vue-language-server',
-- Formatters
'csharpier',
'prettier',
'prettierd',
'stylua',
},
}
-- `servers` is the single source of truth for what runs: exactly what is listed
-- there gets enabled, nothing else. The old mason-lspconfig handler instead
-- started whatever happened to be installed in Mason.
for name, server in pairs(servers) do
server.capabilities = require('blink.cmp').get_lsp_capabilities(server.capabilities)
vim.lsp.config(name, server)
end
vim.lsp.enable(vim.tbl_keys(servers))
-- `:TsServer [tsgo|ts_ls]` picks the server for `ts_filetypes`. No argument
-- toggles; naming the current one restarts it. Vue always stays with `ts_ls`.
local ts_selected = 'tsgo' -- owner of `ts_filetypes` right now
local function select_ts_server(name)
ts_selected = name
-- Stop both servers' clients, remembering where they were so we can re-attach.
local buffers, stopping = {}, {}
for _, client in ipairs(vim.lsp.get_clients()) do
if client.name == 'tsgo' or client.name == 'ts_ls' then
for buf in pairs(client.attached_buffers) do
buffers[buf] = true
end
client:stop()
stopping[#stopping + 1] = client
end
end
if name == 'tsgo' then
vim.lsp.config('ts_ls', { filetypes = { 'vue' } })
vim.lsp.enable 'tsgo'
else
vim.lsp.enable('tsgo', false)
vim.lsp.config('ts_ls', { filetypes = vim.list_extend({ 'vue' }, ts_filetypes) })
end
-- Re-attach only once the old clients are fully down. Firing FileType while
-- one is still shutting down hands the buffer back to the dying client.
local timer = assert(vim.uv.new_timer())
timer:start(
100,
100,
vim.schedule_wrap(function()
for _, client in ipairs(stopping) do
if not client:is_stopped() then
return
end
end
timer:close()
for buf in pairs(buffers) do
if vim.api.nvim_buf_is_loaded(buf) then
vim.api.nvim_exec_autocmds('FileType', { buffer = buf, modeline = false })
end
end
vim.notify('JS/TS language server: ' .. name)
end)
)
end
vim.api.nvim_create_user_command('TsServer', function(opts)
select_ts_server(opts.args ~= '' and opts.args or (ts_selected == 'tsgo' and 'ts_ls' or 'tsgo'))
end, {
nargs = '?',
desc = 'Switch the JS/TS language server between tsgo and ts_ls (restarts if already selected)',
complete = function()
return { 'tsgo', 'ts_ls' }
end,
})
end,
},
{ -- Autoformat
'stevearc/conform.nvim',
event = { 'BufWritePre' },
cmd = { 'ConformInfo' },
keys = {
{
'<leader>tF',
function()
if vim.g.disable_autoformat then
vim.cmd 'FormatEnable'
vim.notify 'Enabled autoformat globally'
else
vim.cmd 'FormatDisable'
vim.notify 'Disabled autoformat globally'
end
end,
desc = '[T]oggle [F]ormatting globally',
},
{
'<leader>tf',
function()
if vim.b.disable_autoformat then
vim.cmd 'FormatEnable'
vim.notify 'Enabled autoformat for current buffer'
else
vim.cmd 'FormatDisable!'
vim.notify 'Disabled autoformat for current buffer'
end
end,
desc = '[T]oggle [F]ormatting for current buffer',
},
{
'<leader>f',
function()
require('conform').format { async = true, lsp_format = 'fallback' }
end,
mode = '',
desc = '[F]ormat buffer',
},
},
opts = {
notify_on_error = false,
format_after_save = function(bufnr)
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
return
end
-- Skip format-on-save for languages with no well-standardized style. `c` is
-- deliberately not in this list: clangd formats it with its embedded
-- clang-format, honouring the project's `.clang-format` and falling back to
-- LLVM style. Nothing in `formatters_by_ft` claims `c`, so it goes through
-- the `lsp_format = 'fallback'` below.
local disable_filetypes = { cpp = true }
if disable_filetypes[vim.bo[bufnr].filetype] then
return nil
else
return {
timeout_ms = 500,
lsp_format = 'fallback',
}
end
end,
formatters_by_ft = {
lua = { 'stylua' },
typescript = { 'prettierd', 'prettier', stop_after_first = true },
javascript = { 'prettierd', 'prettier', stop_after_first = true },
ts = { 'prettierd', 'prettier', stop_after_first = true },
js = { 'prettierd', 'prettier', stop_after_first = true },
tsx = { 'prettierd', 'prettier', stop_after_first = true },
jsx = { 'prettierd', 'prettier', stop_after_first = true },
vue = { 'prettierd', 'prettier', stop_after_first = true },
html = { 'prettierd', 'prettier', stop_after_first = true },
css = { 'prettierd', 'prettier', stop_after_first = true },
json = { 'prettierd', 'prettier', stop_after_first = true },
yaml = { 'prettierd', 'prettier', stop_after_first = true },
markdown = { 'prettierd', 'prettier', stop_after_first = true },
},
},
config = function(_, opts)
require('conform').setup(opts)
vim.api.nvim_create_user_command('FormatDisable', function(args)
if args.bang then
vim.b.disable_autoformat = true -- `:FormatDisable!` -- this buffer only
else
vim.g.disable_autoformat = true -- `:FormatDisable` -- globally
end
end, {
desc = 'Disable autoformat-on-save',
bang = true,
})
vim.api.nvim_create_user_command('FormatEnable', function()
vim.b.disable_autoformat = false
vim.g.disable_autoformat = false
end, {
desc = 'Re-enable autoformat-on-save',
})
end,
},
{ -- Colorscheme. Loads first (priority), then kanagawa in lua/plugins/theme.lua
-- loads later and wins; this is the fallback if that spec ever goes away.
'folke/tokyonight.nvim',
priority = 1000,
config = function()
---@diagnostic disable-next-line: missing-fields
require('tokyonight').setup {
styles = {
comments = { italic = false },
},
}
-- Other styles: tokyonight-storm, -moon, -day.
vim.cmd.colorscheme 'tokyonight-night'
end,
},
{ -- Collection of various small independent plugins/modules
'nvim-mini/mini.nvim',
version = '*',
dependencies = {
'kshksdrt/mini-tabline-colorizer',
},
config = function()
local hipatterns = require 'mini.hipatterns'
hipatterns.setup {
highlighters = {
-- Highlight standalone 'FIXME', 'HACK', 'TODO', 'NOTE'
fixme = { pattern = '%f[%w]()FIXME()%f[%W]', group = 'MiniHipatternsFixme' },
hack = { pattern = '%f[%w]()HACK()%f[%W]', group = 'MiniHipatternsHack' },
todo = { pattern = '%f[%w]()TODO()%f[%W]', group = 'MiniHipatternsTodo' },
note = { pattern = '%f[%w]()NOTE()%f[%W]', group = 'MiniHipatternsNote' },
-- Highlight hex color strings (`#rrggbb`) using that color
hex_color = hipatterns.gen_highlighter.hex_color(),
},
}
-- Around/inside textobjects: `va)`, `yinq`, `ci'`.
require('mini.ai').setup { n_lines = 500 }
-- Every mapping is cleared: nvim-surround (lua/plugins/init.lua) owns the
-- surround keys instead.
require('mini.surround').setup {
mappings = {
add = '',
delete = '',
find = '',
find_left = '',
highlight = '',
replace = '',
update_n_lines = '',
},
}
-- Statusline. Sections are assembled in the content function further down.
local statusline = require 'mini.statusline'
-- Shared bg for every MiniStatuslineBreadcrumb* group.
local BREADCRUMB_BG = '#2d2d2d'
-- fg source per breadcrumb kind: treesitter capture first, else base syntax group.
--stylua: ignore
local BREADCRUMB_KIND_HL_SOURCES = {
Function = { '@function', 'Function' },
Method = { '@function.method', 'Function' },
Constructor = { '@constructor', 'Special' },