-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
184 lines (158 loc) · 5.59 KB
/
init.lua
File metadata and controls
184 lines (158 loc) · 5.59 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
local plugins = require('plugins')
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
vim.fn.system({
"git", "clone", "--filter=blob:none", "--branch=stable",
"https://github.com/folke/lazy.nvim.git", lazypath,
})
end
vim.opt.runtimepath:prepend(lazypath)
-- LOAD PLUGINS
require("lazy").setup(plugins, {
termguicolors = true,
disable_netrw = true,
})
-- MASON
require("mason").setup()
require("mason-lspconfig").setup({
ensure_installed = {
"lua_ls", "pyright", "gopls", "dockerls", "yamlls", "bashls",
"eslint", "ts_ls", "solargraph", "rubocop", "clangd", "graphql", "terraformls"
},
})
-- Common capabilities for nvim-cmp
local capabilities = require('cmp_nvim_lsp').default_capabilities()
-- LSP CONFIGURATION (0.11 API)
local servers = {
"pyright", "gopls", "dockerls", "yamlls", "bashls",
"ts_ls", "clangd", "graphql", "solargraph", "terraformls", "lua_ls"
}
-- Godot stuff
-- paths to check for project.godot file
vim.lsp.config('gdscript', {})
vim.lsp.enable('gdscript')
local paths_to_check = {'/', '/../'}
local is_godot_project = false
local godot_project_path = ''
local cwd = vim.fn.getcwd()
-- iterate over paths and check
for key, value in pairs(paths_to_check) do
if vim.uv.fs_stat(cwd .. value .. 'project.godot') then
is_godot_project = true
godot_project_path = cwd .. value
break
end
end
-- check if server is already running in godot project path
local is_server_running = vim.uv.fs_stat(godot_project_path .. '/server.pipe')
-- start server, if not already running
if is_godot_project and not is_server_running then
vim.fn.serverstart(godot_project_path .. '/server.pipe')
end
--
for _, lsp in ipairs(servers) do
-- Fetch the default configuration from nvim-lspconfig data
local config = vim.lsp.config[lsp]
if config then
-- Merge your custom capabilities and flags into the default config
config = vim.tbl_deep_extend("force", config, {
capabilities = capabilities,
flags = { debounce_text_changes = 300 },
})
-- Server-Specific Logic (Clangd)
if lsp == "clangd" then
config.cmd = {
'clangd', '--background-index', '--clang-tidy', '--log=verbose',
'--header-insertion=iwyu', '--completion-style=detailed', '-j=4'
}
config.init_options = { fallbackFlags = { '-std=c++17' } }
end
-- Server-Specific Logic (Lua)
if lsp == "lua_ls" then
config.on_init = function(client)
local path = client.workspace_folders[1].name
if not (vim.uv or vim.loop).fs_stat(path..'/.luarc.json') and not (vim.uv or vim.loop).fs_stat(path..'/.luarc.jsonc') then
client.config.settings.Lua = {
runtime = { version = 'LuaJIT' },
workspace = { checkThirdParty = false, library = { vim.env.VIMRUNTIME } },
}
end
return true
end
end
-- Register the modified config
vim.lsp.config(lsp, config)
end
end
-- Enable all servers (This replaces lspconfig setup loops)
vim.lsp.enable(servers)
-- Diagnostics Setup
vim.diagnostic.config({
virtual_text = true,
update_in_insert = false,
severity_sort = true,
})
-- Keybindings
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
callback = function(ev)
local opts = { buffer = ev.buf, silent = true }
-- Navigation
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
-- Actions
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
vim.keymap.set({ 'n', 'v' }, '<space>ca', vim.lsp.buf.code_action, opts)
vim.keymap.set('n', '<space>f', function() vim.lsp.buf.format { async = true } end, opts)
end,
})
-- Rubocop
vim.api.nvim_create_autocmd("FileType", {
pattern = "ruby",
callback = function()
vim.lsp.start({ name = "rubocop", cmd = { "bundle", "exec", "rubocop", "--lsp" } })
end,
})
-- General
vim.cmd[[colorscheme everforest]]
vim.o.background = "dark"
vim.opt.hidden = true
vim.wo.number = true
vim.opt.shiftwidth = 2
vim.opt.tabstop = 2
vim.opt.expandtab = true
vim.opt.smartindent = true
vim.opt.autoindent = true
vim.opt.termguicolors = true
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
vim.opt.signcolumn = "yes"
-- Keymaps
local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>ff', builtin.find_files, {})
vim.keymap.set('n', '<leader>fg', builtin.live_grep, {})
vim.keymap.set('n', '<leader>fb', builtin.buffers, {})
vim.keymap.set('n', '<leader>fr', builtin.lsp_references, {desc="Find References"})
vim.keymap.set('n', '<leader>ft', function()
local function_name = vim.fn.expand("<cword>")
require('telescope.builtin').live_grep({
default_text = "def test_" .. function_name,
})
end, { desc = 'Find tests for function under cursor' })
-- Substitute Plugin
vim.keymap.set("n", "s", require('substitute').operator, { noremap = true })
vim.keymap.set("n", "ss", require('substitute').line, { noremap = true })
-- Nvim-tree
require("nvim-tree").setup { filters = { dotfiles = true } }
vim.api.nvim_set_keymap("n", "<F2>", ":NvimTreeToggle<CR>", { noremap = true, silent = true })
-- Formatter Autocmd
vim.api.nvim_create_autocmd("BufWritePre", {
pattern = { "*.ts", "*.js", "*.tsx", "*.jsx" },
callback = function()
vim.lsp.buf.format({ async = false })
end,
})