-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.vim
More file actions
193 lines (167 loc) · 7.18 KB
/
init.vim
File metadata and controls
193 lines (167 loc) · 7.18 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
set runtimepath^=~/.vim runtimepath+=~/.vim/after
let &packpath = &runtimepath
source ~/.vim/vimrc
if has('nvim-0.5')
lua << EOF
local status, nvim_lsp = pcall(require, 'lspconfig')
if status then
-- Run an LSP command using a Telescope picker if it's available, otherwise use the fallback.
function lsp_do(picker, fallback)
if picker == "lsp_code_actions" then
print('Getting code actions (this may take a while on first use)...')
end
vim.schedule(function()
local status, telescope = pcall(require, 'telescope.builtin')
if status then
telescope[picker]{}
else
fallback()
end
end)
end
function lsp_workspace_symbols(query)
local status, telescope = pcall(require, 'telescope.builtin')
if status then
telescope.lsp_workspace_symbols{query=query}
else
vim.lsp.buf.workspace_symbol(query)
end
end
local on_attach = function(client, bufnr)
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
-- Mappings.
local opts = { noremap=true, silent=true }
-- Inspired by https://github.com/neovim/nvim-lspconfig/#keybindings-and-completion,
-- but with <leader> instead of <space>
-- Navigation
buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
buf_set_keymap('n', 'gd', '<cmd>lua lsp_do("lsp_definitions", vim.lsp.buf.definition)<CR>', opts)
buf_set_keymap('n', '<Leader>D', '<cmd>lua lsp_do("lsp_type_definitions", vim.lsp.buf.type_definition)<CR>', opts)
-- Information
buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
buf_set_keymap('n', 'gr', '<cmd>lua lsp_do("lsp_references", vim.lsp.buf.references)<CR>', opts)
buf_set_keymap('n', '<Leader>ds', '<cmd>lua lsp_do("lsp_document_symbols", vim.lsp.buf.document_symbol)<CR>', opts)
-- Diagnostics
buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
buf_set_keymap('n', '<Leader>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
buf_set_keymap('n', '<Leader>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
-- Refactoring
buf_set_keymap('n', '<Leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
buf_set_keymap('n', '<Leader>ca', '<cmd>lua lsp_do("lsp_code_actions", vim.lsp.buf.code_action)<CR>', opts)
-- Workspaces
buf_set_keymap('n', '<Leader>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<Leader>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<Leader>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
-- Set some keybinds conditional on server capabilities
if client.resolved_capabilities.document_formatting then
buf_set_keymap("n", "<Leader>fd", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts)
elseif client.resolved_capabilities.document_range_formatting then
buf_set_keymap("n", "<Leader>fd", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts)
end
-- Set autocommands conditional on server_capabilities
if client.resolved_capabilities.document_highlight then
vim.api.nvim_exec([[
hi LspReferenceRead cterm=bold ctermbg=red guibg=LightYellow
hi LspReferenceText cterm=bold ctermbg=red guibg=LightYellow
hi LspReferenceWrite cterm=bold ctermbg=red guibg=LightYellow
augroup lsp_document_highlight
autocmd!
autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
augroup END
]], false)
end
end
local jdtls_bundles = {vim.env.HOME.."/language-servers/java/extensions/debug.jar"};
vim.list_extend(jdtls_bundles, vim.split(vim.fn.glob(vim.env.HOME.."/language-servers/java/extensions/test/extension/server/*.jar"), "\n"))
nvim_lsp.jdtls.setup{
cmd = { "java-language-server", "--heap-max", "8G" };
init_options = {
bundles = jdtls_bundles;
};
on_attach = on_attach;
}
nvim_lsp.gopls.setup{
on_attach = on_attach;
}
nvim_lsp.bashls.setup{
on_attach = on_attach;
}
end
local status, telescope = pcall(require, 'telescope')
if status then
telescope.setup{
pickers = {
['lsp_code_actions'] = {
timeout = 30000
}
}
}
end
local status, treesitter = pcall(require, 'nvim-treesitter.configs')
if status then
treesitter.setup{
-- List of supported languages can be found here: https://github.com/nvim-treesitter/nvim-treesitter#supported-languages
ensure_installed = {"bash", "c_sharp", "clojure", "comment", "css", "go", "graphql", "html", "java", "javascript", "json", "kotlin", "lua", "php", "python", "regex", "ruby", "rust", "scala", "toml", "typescript"},
highlight = {
enable = true
},
incremental_selection = {
enable = true,
keymaps = {
init_selection = "gnn",
node_incremental = "grn",
scope_incremental = "grc",
node_decremental = "grm",
},
},
indent = {
enable = true
},
}
vim.wo.foldmethod = 'expr'
vim.wo.foldexpr = 'nvim_treesitter#foldexpr()'
vim.o.foldlevelstart = 99
end
function notify_file_changed(buffer, change)
local log = require('vim.lsp.log')
local filepath = vim.fn.expand('#'..buffer..':p')
for _,client in pairs(vim.lsp.get_active_clients()) do
log.info('Notifying LSP server "'..client.name..'" of change to file "'..filepath..'"')
local result = client.notify('workspace/didChangeWatchedFiles', {
changes = {{ uri = 'file://'..filepath, type = change }},
})
if not result then
log.warn('File change notification failed!')
end
end
end
-- Add this right here to initialize CopilotChat
local status_copilot, copilot_chat = pcall(require, "CopilotChat")
if status_copilot then
copilot_chat.setup({
model = 'gpt-4o', -- Fallback model in case the API fetch is blocked
debug = true,
mappings = {
submit_prompt = {
insert = '<C-s>', -- Universal submit for WSL (Ctrl+s)
},
},
})
end
EOF
" LSP servers may not always pick up changes to relevant files, such as when
" changing a resource file in a Java project. To help ensure that the language
" server always has recent changes, send a notification to all active servers
" whenever a file is changed.
augroup buffer_updates
au!
au BufWritePost,FileWritePost * lua notify_file_changed(vim.fn.expand('<abuf>'), 2)
augroup END
command! -nargs=1 Symbols :lua lsp_workspace_symbols('<args>')
endif