-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
362 lines (315 loc) · 13 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
local current_file_name = vim.api.nvim_eval('expand("<sfile>:p")')
local system_name = 'unknown'
if vim.fn.has("mac") == 1 then
system_name = "macOS"
elseif vim.fn.has("unix") == 1 then
system_name = "Linux"
elseif vim.fn.has('win32') == 1 then
system_name = "Windows"
end
-- Mapleader
vim.g.mapleader = " " -- space
-- Windows compatable commands for Ctrl+C and Ctrl+V
vim.cmd("source $VIMRUNTIME/mswin.vim")
-- Quick settings open and reload
-- vim.cmd([[
-- augroup vimrc
-- autocmd!
-- exec "autocmd BufWritePost " . expand("<sfile>:t") . " source $MYVIMRC"
-- augroup end
-- ]])
vim.cmd('nnoremap <leader>` :e ' .. current_file_name .. '<CR>')
-- Sensible Bindings
-- Unmap Q
vim.cmd("nmap Q <Nop>")
-- ESC to leave terminal
vim.cmd("tnoremap <ESC> <C-\\><C-n>")
-- Opening files and directories from current path
vim.cmd('nnoremap <leader>e :e <C-R>=expand("%:p:h")."/"<cr>')
vim.cmd('nnoremap <leader>cd :cd <C-R>=expand("%:p:h")."/"<cr>')
-- Settings
-- Default Shell (for terminal)
vim.o.shell = 'pwsh' -- Powershell
-- Display line numberse
vim.o.number = true
-- Display signs (debugging, etc) shared in the number column
vim.o.signcolumn = 'number' -- TODO: Look into why lsp overwrites this to auto?
-- Case settings
vim.o.ignorecase = true
vim.o.smartcase = true
-- Incremental search
vim.incsearch = true
-- Completion options
-- menuone: popup even when there's only one match
-- noinsert: Do not insert text until a selection is made
-- noselect: Do not select, force user to select one from the menu
vim.o.completeopt = 'menuone,noinsert,noselect'
-- Expand all tabs by default
vim.o.expandtab = true
-- Allow mouse to be used in all modes
vim.o.mouse = 'a'
-- Trigger CursorHold event in normal mode after no keys are pressed
vim.o.updatetime = 550
-- Set Vim to automatically read in modified files
vim.o.autoread = true
vim.cmd([[
augroup neovimrc
" Remove all neovimrc autocmds (useful when resourcing)
autocmd!
" Remove line numbers from terminal buffers
autocmd TermOpen * setlocal nonumber
autocmd TermOpen * setlocal norelativenumber
" Update any changed files in buffers
autocmd BufLeave * if &buftype ==# 'terminal' | checktime | endif
augroup END
]])
-- Plugins
vim.cmd [[packadd packer.nvim]]
require('packer').startup(function()
-- Packer can manage itself
use 'wbthomason/packer.nvim'
-- Colourscheme
use 'marko-cerovac/material.nvim'
-- F3 to toggle current window to max size and back
use 'szw/vim-maximizer'
-- gc to comment out lines
use 'tpope/vim-commentary'
-- cs to change surrounding text
use 'tpope/vim-surround'
-- Autocompletion
-- Neovim Language Server Protocol Configuations using builtin LSP
use 'neovim/nvim-lspconfig'
-- Autoformatting?
-- Use sbdchd/neoformat?
-- Better syntax highlighting
use { 'nvim-treesitter/nvim-treesitter', branch = '0.5-compat', run = ':TSUpdate' }
-- Add configuration for better text objects (in function, in class, etc) ?
-- use { 'nvim-treesitter/nvim-treesitter-textobjects', branch = '0.5-compat', run = ':TSUpdate' }
-- Fuzzy Finding (files, buffers, etc)
use { 'nvim-telescope/telescope.nvim', requires = { {'nvim-lua/plenary.nvim'} } }
-- Debug Adapter Protocol
-- TODO: Configure for various languages (.e.g lldb)
use 'mfussenegger/nvim-dap'
-- Telescope prompt for debugging information (dap => commands configurations list_breakboints variables frames)
use { 'nvim-telescope/telescope-dap.nvim', requires = { {'nvim-telescope/telescope.nvim'} } }
-- Add font-based icons (from supported fonts re: nerdfonts.com)
use 'kyazdani42/nvim-web-devicons'
-- Popup completion engine
use {
"hrsh7th/nvim-cmp", -- base engine
requires = {
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
-- "hrsh7th/vim-vsnip", snippets?
}
}
-- Status line
use {
'hoob3rt/lualine.nvim',
requires = {'kyazdani42/nvim-web-devicons', opt = true}
}
end)
-- Auto-recompile plugins after upting this file
-- TODO: Verify this works
vim.cmd([[
augroup packer_user_config
autocmd!
autocmd BufWritePost init.lua source <afile> | PackerCompile
augroup end
]])
-- Set Colourscheme
vim.g.material_style = "darker"
vim.cmd('colorscheme material')
-- Setup Treesitter
require('nvim-treesitter.configs').setup({
ensure_installed = "maintained", -- one of "all", "maintained" (parsers with maintainers), or a list of languages
-- ignore_install = { "javascript" }, -- List of parsers to ignore installing
highlight = {
enable = true, -- false will disable the whole extension
-- disable = { "c", "rust" }, -- list of language that will be disabled
-- Setting this to true will run `:h syntax` and tree-sitter at the same time.
-- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
-- Using this option may slow down your editor, and you may see some duplicate highlights.
-- Instead of true it can also be a list of languages
additional_vim_regex_highlighting = false,
},
})
-- Startup status line
require('lualine').setup({
options = {
theme = "material"
},
-- NB: Putting nvim_treesitter:#statusline in results in sometimes text that is too large to fit
})
-- Telescope settings and bindings
vim.cmd('nnoremap <leader>ff <cmd>Telescope find_files<cr>')
vim.cmd('nnoremap <leader>fo <cmd>Telescope file_browser<cr>')
vim.cmd('nnoremap <leader>fg <cmd>Telescope live_grep<cr>')
vim.cmd('nnoremap <leader>fb <cmd>Telescope buffers<cr>')
vim.cmd('nnoremap <leader>fh <cmd>Telescope help_tags<cr>')
-- Langauge Server settings and bindings
local nvim_lsp = require('lspconfig')
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
-- *Must* put the on_attach callback in each setup() call for each LSP server for these to take effect
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
-- Enable completion triggered by <c-x><c-o>
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
-- Mappings.
local opts = { noremap=true, silent=true }
-- vim.cmd('nnoremap gt <cmd>Telescope lsp_type_definitions<cr>') -- type definitions?
buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
buf_set_keymap('n', '<F2>', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
buf_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
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>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
--- Telescope lsp
buf_set_keymap('n', '<leader>fs', '<cmd>Telescope lsp_document_symbols<CR>', opts)
buf_set_keymap('n', 'gd', '<cmd>Telescope lsp_definitions<CR>', opts)
buf_set_keymap('n', 'gr', '<cmd>Telescope lsp_references<CR>', opts)
buf_set_keymap('n', '<leader>ca', '<cmd>Telescope lsp_code_actions<CR>', opts)
-- See `:help vim.lsp.*` for documentation on any of the below functions
-- buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
-- buf_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
-- 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', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
-- buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
-- buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
-- buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
-- buf_set_keymap('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
-- buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
-- buf_set_keymap('n', '<space>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
-- 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', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
-- buf_set_keymap('n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
end
-- Rust
nvim_lsp.rust_analyzer.setup({
on_attach = on_attach,
settings = {
["rust-analyzer"] = {
assist = {
importGranularity = "module",
importPrefix = "by_self",
},
cargo = {
loadOutDirsFromCheck = true
},
procMacro = {
enable = true
},
}
}
})
-- Lua
-- TODO/NB: This might only make sense if this lua configuration file is where
-- it's supposed to be with the rest of the lua configurations for neovim
-- Maybe symlink?
--
-- local sumneko_root_path = 'C:/Projects/lua-language-server'
-- local sumneko_binary = sumneko_root_path .. "/bin/" .. system_name .. "/lua-language-server"
-- local runtime_path = vim.split(package.path, ';')
-- table.insert(runtime_path, "lua/?.lua")
-- table.insert(runtime_path, "lua/?/init.lua")
-- nvim_lsp.sumneko_lua.setup {
-- cmd = {sumneko_binary, "-E", sumneko_root_path .. "/main.lua"};
-- settings = {
-- Lua = {
-- runtime = {
-- -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
-- version = 'LuaJIT',
-- -- Setup your lua path
-- path = runtime_path,
-- },
-- diagnostics = {
-- -- Get the language server to recognize the `vim` global
-- globals = {'vim'},
-- },
-- workspace = {
-- -- Make the server aware of Neovim runtime files
-- library = vim.api.nvim_get_runtime_file("", true),
-- },
-- -- Do not send telemetry data containing a randomized but unique identifier
-- telemetry = {
-- enable = false,
-- },
-- },
-- },
-- }
-- Debug Adapter Settings
local dap = require('dap')
vim.fn.sign_define('DapBreakpoint', {text='', texthl='DapBreakpoint', linehl='', numhl=''}) -- TODO: Fix this
vim.fn.sign_define('DapBreakpointRejected', {text='', texthl='DapBreakpointRejected', linehl='', numhl=''})
vim.fn.sign_define('DapStopped', {text='⭐️', texthl='Cursor', linehl='', numhl=''})
vim.cmd('nnoremap <F5> <cmd>lua require("dap").continue()<CR>')
vim.cmd('nnoremap <F9> <cmd>lua require("dap").toggle_breakpoint()<CR>')
vim.cmd('nnoremap <silent> <F10> :lua require("dap").step_over()<CR>')
vim.cmd('nnoremap <silent> <F11> :lua require("dap").step_into()<CR>')
vim.cmd('nnoremap <silent> <F12> :lua require("dap").step_out()<CR>')
vim.cmd('nnoremap <silent> <leader>B :lua require("dap").set_breakpoint(vim.fn.input("Breakpoint condition: "))<CR>')
vim.cmd('nnoremap <silent> <leader>lp :lua require("dap").set_breakpoint(nil, nil, vim.fn.input("Log point message: "))<CR>')
vim.cmd('nnoremap <silent> <leader>dr :lua require("dap").repl.open()<CR>')
vim.cmd('nnoremap <silent> <leader>dl :lua require("dap").run_last()<CR>')
--- Telescope Debug Extension (DAP)
require('telescope').load_extension('dap')
-- TODO: Disable this when things are fixed
dap.set_log_level('TRACE')
local lldb_executable = 'C:/Program Files/LLVM/bin/lldb-vscode.exe'
-- TODO: Set :help dap.set-log-level
dap.adapters.lldb = {
type = 'executable',
command = lldb_executable,
name = "lldb",
}
-- Simple rust debugging configuration
-- TODO: Expand out configurations into separate/project-related files?
dap.configurations.rust = {
{
name = "Launch Rust",
type = "lldb",
request = "launch",
-- program = "C:/Projects/rust/rlox/target/debug/rlox.exe",
program = function()
return vim.fn.input('Path to executable: ', vim.fn.getcwd() .. '/', 'file')
end,
cwd = '${workspaceFolder}',
-- cwd = vim.fn.getcwd(),
-- stopOnEntry = false,
stopOnEntry = true,
args = {},
-- if you change `runInTerminal` to true, you might need to change the yama/ptrace_scope setting:
--
-- echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
--
-- Otherwise you might get the following error:
--
-- Error on launch: Failed to attach to the target process
--
-- But you should be aware of the implications:
-- https://www.kernel.org/doc/html/latest/admin-guide/LSM/Yama.html
runInTerminal = false,
},
}
-- Completion Engine Settings
local cmp = require('cmp')
cmp.setup {
mapping = {
['<S-Tab>'] = cmp.mapping.select_prev_item(),
['<Tab>'] = cmp.mapping.select_next_item(),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Insert,
})
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'buffer' },
},
}