-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
446 lines (398 loc) · 11.7 KB
/
init.lua
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
-- Set <space> as the leader key
-- See `:help mapleader`
vim.g.mapleader = " "
vim.g.maplocalleader = " "
-- [[ Settings options ]]
-- See `:help vim.opt`
-- Enable line numbers
vim.opt.number = true
-- Enable the mouse
vim.opt.mouse = "a"
-- Don't show the vim mode, since it's already in the status line
vim.opt.showmode = false
-- Make neovim use the system clipboard
vim.opt.clipboard = "unnamedplus"
-- Keep the signcolumn enabled
-- See `:help 'signcolumn'`
vim.opt.signcolumn = "yes"
-- Set the update time to a lower value
-- See `:help 'updatetime'`
vim.opt.updatetime = 300
-- Show the current line where the cursor is on
vim.opt.cursorline = true
-- [[ Basic keymaps ]]
-- See `:help vim.keymap`
-- Go to next diagnostic
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev)
-- Go to previous diagnostic
vim.keymap.set("n", "]d", vim.diagnostic.goto_next)
-- Show diagnostic under the cursor
vim.keymap.set("n", "<leader>e", vim.diagnostic.open_float)
-- Open diagnostic quickfix list
vim.keymap.set("n", "<leader>q", vim.diagnostic.setloclist)
local function rojo_project()
return vim.fs.root(0, function(name)
return name:match ".+%.project%.json$"
end)
end
-- [[ Luau filetype detection ]]
-- Automatically recognise .lua as luau files in a Roblox project
if rojo_project() then
vim.filetype.add {
extension = {
lua = function(path)
return path:match "%.nvim%.lua$" and "lua" or "luau"
end,
},
}
end
-- [[ Install `lazy.nvim` plugin manager ]]
-- See https://github.com/folke/lazy.nvim
local lazypath = vim.fn.stdpath "data" .. "/lazy/lazy.nvim"
if not vim.uv.fs_stat(lazypath) then
vim
.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable",
lazypath,
})
:wait()
end
vim.opt.runtimepath:prepend(lazypath)
local function get_capabilities()
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = vim.tbl_deep_extend("force", capabilities, require("cmp_nvim_lsp").default_capabilities())
-- Enable manually file watcher capability, so luau-lsp will be aware of sourcemap.json changes, this
-- is done internally in Neovim 0.10+, but only for non Linux systems
capabilities.workspace.didChangeWatchedFiles.dynamicRegistration = true
return capabilities
end
local function get_json_schemas()
local schemas = require("schemastore").json.schemas()
-- Add the rojo json schema for rojo project files
table.insert(schemas, {
fileMatch = { "*.project.json" },
url = "https://raw.githubusercontent.com/rojo-rbx/vscode-rojo/master/schemas/project.template.schema.json",
})
return schemas
end
-- [[ Configure and install plugins ]]
-- See https://github.com/folke/lazy.nvim
--
-- To check the current status of your plugins, run `:Lazy`
--
-- To update your plugins, run `:Lazy update`
--
-- Here is where you install your plugins
require("lazy").setup {
-- Tool manager for external tools like LSP's, linters, formatters, etc
--
-- To check the current status of your tools, run `:Mason`
{
"WhoIsSethDaniel/mason-tool-installer.nvim",
opts = {
ensure_installed = {
"lua-language-server",
"luau-lsp",
"stylua",
"vtsls",
"eslint-lsp",
"prettierd",
"json-lsp",
},
},
dependencies = {
{
"williamboman/mason.nvim",
build = ":MasonUpdate",
opts = {},
},
},
},
-- Git integration
{
"lewis6991/gitsigns.nvim",
opts = {},
},
-- LSP configuration
-- See https://microsoft.github.io/language-server-protocol/
--
-- LSP provides Neovim features like:
-- - Go to definition
-- - Find references
-- - Autocompletion
-- - and more!
{
"neovim/nvim-lspconfig",
config = function()
-- This function will run when an LSP attaches to a particular buffer
-- See `:help LspAttach`
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(event)
-- Create a helper function to set the buffer specific keymaps
local function map(mode, lhs, rhs)
vim.keymap.set(mode, lhs, rhs, { buffer = event.buf })
end
-- Go to definition
map("n", "gd", vim.lsp.buf.definition)
-- Go to declaration
map("n", "gD", vim.lsp.buf.declaration)
-- Find references
map("n", "gr", vim.lsp.buf.references)
-- Rename symbol
map("n", "<leader>rn", vim.lsp.buf.rename)
-- Code action
map("n", "<leader>ca", vim.lsp.buf.code_action)
-- Hover
map("n", "K", vim.lsp.buf.hover)
-- Signature help
map("i", "<c-s>", vim.lsp.buf.signature_help)
local client = vim.lsp.get_client_by_id(event.data.client_id)
if not client then
return
end
-- Highlight the current word under the cursor
if client.supports_method "textDocument/documentHighlight" then
vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, {
buffer = event.buf,
callback = vim.lsp.buf.document_highlight,
})
vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, {
buffer = event.buf,
callback = vim.lsp.buf.clear_references,
})
end
end,
})
-- Setup lua-ls for your neovim config
require("lspconfig").lua_ls.setup {
capabilities = get_capabilities(),
}
-- Setup eslint for `typescript` files
require("lspconfig").eslint.setup {
capabilities = get_capabilities(),
}
-- Setup jsonls for `json` files
require("lspconfig").jsonls.setup {
capabilities = get_capabilities(),
settings = {
json = {
-- Send custom json schemas to jsonls to provide its features when you open a json file
schemas = get_json_schemas(),
validate = { enable = true },
},
},
}
-- Setup vtsls for `typescript` files
require("lspconfig").vtsls.setup {
capabilities = get_capabilities(),
}
-- We don't need to call `require("lspconfig").luau_lsp.setup` because we are using luau-lsp.nvim
end,
dependencies = {
"hrsh7th/cmp-nvim-lsp",
"b0o/SchemaStore.nvim",
-- Configures Lua LS for your Neovim config, runtime and plugins
-- used for completion, annotations and signatures of Neovim apis
{
"folke/lazydev.nvim",
opts = {
library = {
-- Load luvit types when the `vim.uv` word is found
{ path = "luvit-meta/library", words = { "vim%.uv" } },
},
},
dependencies = {
"Bilal2453/luvit-meta", -- optional `vim.uv` typings
},
},
},
},
-- Luau support
{
"lopi-py/luau-lsp.nvim",
config = function()
-- We call `require("luau-lsp").setup` instead of `require("lspconfig").luau_lsp.setup` because luau-lsp.nvim will
-- add extra features to luau-lsp, so we don't need to call lspconfig's setup
--
-- See https://github.com/lopi-py/luau-lsp.nvim
require("luau-lsp").setup {
platform = {
type = rojo_project() and "roblox" or "standard",
},
plugin = {
enabled = true,
},
server = {
capabilities = get_capabilities(),
settings = {
["luau-lsp"] = {
ignoreGlobs = { "**/_Index/**", "node_modules/**" },
completion = {
imports = {
enabled = true,
ignoreGlobs = { "**/_Index/**", "node_modules/**" },
},
},
require = {
-- luau-lsp does not yet support .luaurc aliases, but we can use a helper function included in
-- luau-lsp.nvim
directoryAliases = require("luau-lsp").aliases(),
},
},
},
},
}
end,
dependencies = {
"nvim-lua/plenary.nvim",
},
},
-- Format code on save
{
"stevearc/conform.nvim",
event = { "BufWritePre" },
keys = {
-- Format code
{
"<leader>f",
function()
require("conform").format { async = true }
end,
},
},
opts = {
formatters_by_ft = {
lua = { "stylua" },
luau = { "stylua" },
typescript = { "prettierd" },
typescriptreact = { "prettierd" },
},
default_format_opts = {
lsp_format = "fallback",
},
format_on_save = {
timeout_ms = 500,
},
},
},
-- Autocompletion
{
"hrsh7th/nvim-cmp",
config = function()
local cmp = require "cmp"
cmp.setup {
mapping = {
-- Accept the completion
["<cr>"] = cmp.mapping.confirm { select = true },
["<tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
-- Select the next item if the completion menu is visible
cmp.select_next_item()
elseif vim.snippet.active { direction = 1 } then
-- Jump to the next snippet location if possible
vim.snippet.jump(1)
else
fallback()
end
end, { "i", "s" }),
["<s-tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
-- Select the previous item if the completion menu is visible
cmp.select_prev_item()
elseif vim.snippet.active { direction = -1 } then
-- Jump to the previous snippet location if possible
vim.snippet.jump(-1)
else
fallback()
end
end, { "i", "s" }),
},
sources = cmp.config.sources({
{ name = "lazydev" },
}, {
{ name = "nvim_lsp" },
{ name = "snippets" },
}),
}
end,
dependencies = {
"hrsh7th/cmp-nvim-lsp",
-- Snippet loader, by default it will load snippets in `NVIM_CONFIG/snippets/*.json`
-- See https://github.com/garymjr/nvim-snippets
{ "garymjr/nvim-snippets", opts = {} },
},
},
-- Fuzzy finder
{
"nvim-telescope/telescope.nvim",
keys = {
-- Search files
{ "<leader>sf", ":Telescope find_files<cr>" },
-- Search by grep
{ "<leader>sg", ":Telescope live_grep<cr>" },
-- Search buffers
{ "<leader><leader>", ":Telescope buffers<cr>" },
},
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-tree/nvim-web-devicons",
},
},
-- Autopair support
{
"windwp/nvim-autopairs",
opts = {},
},
-- Set tabstop and shifwidth when opening a file
-- See `:help 'tabstop'` and `:help 'shifwidth'`
{
"NMAC427/guess-indent.nvim",
opts = {},
},
-- Colorscheme
-- See https://dotfyle.com/neovim/colorscheme/top for a list of popular colorschemes!
{
"catppuccin/nvim",
name = "catppuccin",
opts = {},
},
-- Display LSP progress messages
{
"j-hui/fidget.nvim",
opts = {},
},
-- Highlight, edit, and navigate code
{
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
main = "nvim-treesitter.configs",
opts = {
ensure_installed = {
"lua",
"luau",
"typescript",
"tsx",
"toml",
"yaml",
"json",
"jsonc",
},
highlight = {
enable = true,
},
indent = {
enable = true,
},
},
},
-- Uncomment the following line and add your plugins to `lua/custom/plugins/*.lua` to get going
-- See https://lazy.folke.io/usage/structuring
--
-- { import = "custom.plugins" },
}
-- Set the colorscheme
vim.cmd.colorscheme "catppuccin-mocha"