-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlua_init.lua
More file actions
280 lines (242 loc) · 8.58 KB
/
lua_init.lua
File metadata and controls
280 lines (242 loc) · 8.58 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
-- nvim-tree.lua
-- disable netrw at the very start of your init.lua
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
-- set termguicolors to enable highlight groups
vim.opt.termguicolors = true
-- OR setup with some options
require("nvim-tree").setup({
sort_by = "case_sensitive",
view = {
width = 30,
},
renderer = {
group_empty = true,
},
filters = {
dotfiles = true,
},
})
-- Set up nvim-cmp.
local cmp = require'cmp'
vim.lsp.handlers['textDocument/hover'] = vim.lsp.with(
vim.lsp.handlers.hover,
{ border = 'rounded' }
)
vim.lsp.handlers['textDocument/signatureHelp'] = vim.lsp.with(
vim.lsp.handlers.signature_help,
{ border = 'rounded' }
)
local map = function(type, key, value)
vim.api.nvim_buf_set_keymap(0,type,key,value,{noremap = true, silent = true});
end
-- NOTE: I could and maybe should gate each of these behind
-- something like if client.supports_method('textDocument/hover') then
-- but I'm not going to for now
vim.api.nvim_create_autocmd('LspAttach', {
callback = function(client)
-- NOTE: also the neovim lsp documentation claims that
-- some of these are set by default but they don't seem
-- to be for me, and I couldn't figure out why
map('n','K','<cmd>lua vim.lsp.buf.hover()<CR>')
map('n','gD','<cmd>lua vim.lsp.buf.declaration()<CR>')
map('n','gd','<cmd>lua vim.lsp.buf.definition()<CR>')
map('n','gr','<cmd>lua vim.lsp.buf.references()<CR>')
map('n','gs','<cmd>lua vim.lsp.buf.signature_help()<CR>')
map('n','gi','<cmd>lua vim.lsp.buf.implementation()<CR>')
map('n','gt','<cmd>lua vim.lsp.buf.type_definition()<CR>')
-- map('n','<leader>gw','<cmd>lua vim.lsp.buf.document_symbol()<CR>')
-- map('n','<leader>gW','<cmd>lua vim.lsp.buf.workspace_symbol()<CR>')
map('n','<leader>ah','<cmd>lua vim.lsp.buf.hover()<CR>')
-- map('n','<leader>af','<cmd>lua vim.lsp.buf.code_action()<CR>')
map('n','<leader>ee','<cmd>lua vim.diagnostic.open_float()<CR>')
-- map('n','<leader>ar','<cmd>lua vim.lsp.buf.rename()<CR>')
map('n','<leader>=', '<cmd>lua vim.lsp.buf.formatting()<CR>')
-- map('n','<leader>ai','<cmd>lua vim.lsp.buf.incoming_calls()<CR>')
-- map('n','<leader>ao','<cmd>lua vim.lsp.buf.outgoing_calls()<CR>')
end
})
cmp.setup({
snippet = {
-- REQUIRED - you must specify a snippet engine
expand = function(args)
vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
-- require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
-- require('snippy').expand_snippet(args.body) -- For `snippy` users.
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
-- vim.snippet.expand(args.body) -- For native neovim snippets (Neovim v0.10+)
end,
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
-- Set `select` to `false` to only confirm explicitly selected items.
-- i.e. not just accept the first suggestion.
['<CR>'] = cmp.mapping.confirm({ select = true }),
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'vsnip' },
}, {
{ name = 'buffer' },
})
})
-- To use git you need to install the plugin petertriho/cmp-git and uncomment lines below
-- Set configuration for specific filetype.
--[[ cmp.setup.filetype('gitcommit', {
sources = cmp.config.sources({
{ name = 'git' },
}, {
{ name = 'buffer' },
})
})
require("cmp_git").setup() ]]--
-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline({ '/', '?' }, {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = 'buffer' }
}
})
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
}),
matching = { disallow_symbol_nonprefix_matching = false }
})
-- Set up lspconfig.
local lspconfig = require('lspconfig')
local capabilities = require('cmp_nvim_lsp').default_capabilities()
-- Set default client capabilities so I don't have to add
-- `capabilities = capabilities` to each server config.
lspconfig.util.default_config = vim.tbl_extend(
'force',
lspconfig.util.default_config,
{
capabilities = capabilities,
}
)
lspconfig.zls.setup {
-- Server-specific settings. See `:help lspconfig-setup`
-- omit the following line if `zls` is in your PATH
-- cmd = { '/path/to/zls_executable' },
-- There are two ways to set config options:
-- - edit your `zls.json` that applies to any editor that uses ZLS
-- - set in-editor config options with the `settings` field below.
-- Further information on how to configure ZLS:
-- https://zigtools.org/zls/configure/
settings = {
zls = {
-- Whether to enable build-on-save diagnostics
-- Further information about build-on save:
-- https://zigtools.org/zls/guides/build-on-save/
-- enable_build_on_save = true,
-- omit the following line if `zig` is in your PATH
-- zig_exe_path = '/path/to/zig_executable'
}
}
}
lspconfig.svelte.setup {
-- Server-specific settings. See `:help lspconfig-setup`
settings = {
svelte = {
plugin = {
html = { completions = { enable = true } },
svelte = { completions = { enable = true } },
}
}
}
}
-- Helper function to get command with fallback
local function get_cmd_with_fallback(local_cmd, global_cmd)
-- First try to find the local version
local local_exists = vim.fn.executable(vim.fn.getcwd() .. '/node_modules/.bin/' .. local_cmd) == 1
if local_exists then
return { "pnpm", "exec", local_cmd, "--stdio" }
end
-- Fallback to global version if it exists
local global_exists = vim.fn.executable(global_cmd) == 1
if global_exists then
return { global_cmd, "--stdio" }
end
-- Default back to trying local with pnpm exec
return { "pnpm", "exec", local_cmd, "--stdio" }
end
-- Set higher max listeners for Node processes
local function setup_node_process(client)
if client.config.cmd and client.config.cmd[1] == "node" then
table.insert(client.config.cmd, 2, "--max-old-space-size=8192")
table.insert(client.config.cmd, 2, "--max-listeners=20")
end
end
lspconfig.ts_ls.setup {
-- this seems dumb, why are we falling back to the same command? TODO
cmd = get_cmd_with_fallback("typescript-language-server", "typescript-language-server"),
on_init = setup_node_process,
before_init = function(params)
params.processId = vim.NIL
end,
settings = {
javascript = {
inlayHints = {
includeInlayParameterNameHints = 'all',
includeInlayParameterNameHintsWhenArgumentMatchesName = false,
includeInlayFunctionParameterTypeHints = true,
includeInlayVariableTypeHints = true,
includeInlayPropertyDeclarationTypeHints = true,
includeInlayFunctionLikeReturnTypeHints = true,
includeInlayEnumMemberValueHints = true,
}
},
typescript = {
inlayHints = {
includeInlayParameterNameHints = 'all',
includeInlayParameterNameHintsWhenArgumentMatchesName = false,
includeInlayFunctionParameterTypeHints = true,
includeInlayVariableTypeHints = true,
includeInlayPropertyDeclarationTypeHints = true,
includeInlayFunctionLikeReturnTypeHints = true,
includeInlayEnumMemberValueHints = true,
}
}
}
}
-- ESLint LSP setup matching your working ts_ls configuration
lspconfig.eslint.setup {
-- Match the command format that's working for ts_ls in your setup
cmd = { "pnpm", "exec", "vscode-eslint-language-server", "--stdio" },
-- Use the same root_dir logic that ts_ls is successfully using
root_dir = lspconfig.util.find_package_json_ancestor,
settings = {
workingDirectory = { mode = "auto" },
format = true,
quiet = false,
onIgnoredFiles = "off",
rulesCustomizations = {},
run = "onType",
workingDirectories = { mode = "auto" }
},
handlers = {
-- Add handlers to debug attachment issues
["window/showMessageRequest"] = function(_, result, params)
vim.notify("ESLint message: " .. vim.inspect(params), vim.log.levels.INFO)
end,
["textDocument/publishDiagnostics"] = function(_, result, ctx, config)
vim.notify("Got ESLint diagnostics", vim.log.levels.INFO)
vim.lsp.handlers["textDocument/publishDiagnostics"](_, result, ctx, config)
end,
},
on_attach = function(client, bufnr)
vim.notify("ESLint attached to buffer: " .. bufnr)
end
}