-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
413 lines (379 loc) · 12.2 KB
/
init.lua
File metadata and controls
413 lines (379 loc) · 12.2 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
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
-- map leader to <Space>
vim.keymap.set("n", " ", "<Nop>", { silent = true, remap = false })
vim.g.mapleader = " "
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
---@diagnostic disable-next-line: undefined-field
if not (vim.uv or vim.loop).fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
require("lazy").setup({
{
'nvim-telescope/telescope.nvim',
branch = '0.1.x',
dependencies = { 'nvim-lua/plenary.nvim' },
config = function()
local telescope = require('telescope')
local actions = require('telescope.actions')
telescope.setup {
defaults = {
layout_strategy = "horizontal",
layout_config = { width = 0.95 },
},
pickers = {
find_files = {
hidden = true
}
},
extensions = {
live_grep_args = {
mappings = {
i = {
['<C-n>'] = actions.cycle_history_next,
['<C-p>'] = actions.cycle_history_prev,
},
},
},
},
}
local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader><leader>', builtin.find_files, {})
vim.keymap.set('n', '<leader>ff', builtin.find_files, {})
vim.keymap.set('n', '<leader>fs', builtin.lsp_document_symbols, {})
vim.keymap.set('n', '<leader>fg', builtin.live_grep, {})
vim.keymap.set('n', '<leader>fb', function() builtin.buffers({ sort_mru = true }) end, {})
vim.keymap.set('n', '<leader>bb', function() builtin.buffers({ sort_mru = true }) end, {})
vim.keymap.set('n', '<leader>fh', builtin.help_tags, {})
vim.keymap.set('n', '<leader>f.',
':Telescope file_browser path=%:p:h select_buffer=true hidden=true<CR>', {})
vim.keymap.set('n', '<leader>.',
':Telescope file_browser path=%:p:h select_buffer=true hidden=true<CR>', {})
vim.keymap.set('n', '<leader>sb', ':Telescope current_buffer_fuzzy_find<CR>', {})
vim.keymap.set('n', '<leader>ss', ':Telescope current_buffer_fuzzy_find<CR>', {})
vim.keymap.set('n', '<leader>fbd',
function() builtin.find_files({ cwd = require('telescope.utils').buffer_dir() }) end,
{})
end
},
{
"nvim-telescope/telescope-file-browser.nvim",
dependencies = {
"nvim-telescope/telescope.nvim",
"nvim-lua/plenary.nvim"
},
config = function()
require("telescope").load_extension('file_browser')
end
},
{
'nvim-telescope/telescope-live-grep-args.nvim',
version = "^1.0.0",
dependencies = {
'nvim-telescope/telescope.nvim',
},
config = function()
require("telescope").load_extension("live_grep_args")
vim.keymap.set('n', '<leader>fG',
function() require("telescope").extensions.live_grep_args.live_grep_args() end, {})
end
},
{
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
config = function()
local configs = require("nvim-treesitter.configs")
---@diagnostic disable-next-line: missing-fields
configs.setup({
ensure_installed = { "fidl", "cpp", "rust", "markdown", "lua" },
highlight = {
enable = true,
-- 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,
},
})
end
},
'nvim-lua/plenary.nvim',
{
'williamboman/mason.nvim',
opts = {
PATH = "prepend", -- prepend | append | skip
}
},
{
'stevearc/overseer.nvim',
config = function()
require('overseer').setup()
vim.keymap.set('n', '<leader>pt', function() vim.cmd('OverseerRun') end, {})
end
},
{
'stevearc/oil.nvim',
opts = {},
config = function()
require("oil").setup({
skip_confirm_for_simple_edits = true,
view_options = {
show_hidden = true,
}
})
vim.keymap.set("n", "-", "<CMD>Oil<CR>", { desc = "Open parent directory" })
end
},
'airblade/vim-gitgutter',
'tpope/vim-fugitive',
{
'sindrets/diffview.nvim',
opts = {
use_icons = false,
file_panel = {
listing_style = 'list',
},
}
},
'raimondi/delimitmate',
{
'saghen/blink.cmp',
-- use a release tag to download pre-built binaries
version = '1.*',
-- AND/OR build from source, requires nightly: https://rust-lang.github.io/rustup/concepts/channels.html#working-with-nightly-rust
-- build = 'cargo build --release',
-- If you use nix, you can build from source using latest nightly rust with:
-- build = 'nix run .#build-plugin',
---@module 'blink.cmp'
---@type blink.cmp.Config
opts = {
-- 'default' (recommended) for mappings similar to built-in completions (C-y to accept)
-- 'super-tab' for mappings similar to vscode (tab to accept)
-- 'enter' for enter to accept
-- 'none' for no mappings
--
-- All presets have the following mappings:
-- C-space: Open menu or open docs if already open
-- C-n/C-p or Up/Down: Select next/previous item
-- C-e: Hide menu
-- C-k: Toggle signature help (if signature.enabled = true)
--
-- See :h blink-cmp-config-keymap for defining your own keymap
keymap = { preset = 'default' },
appearance = {
-- 'mono' (default) for 'Nerd Font Mono' or 'normal' for 'Nerd Font'
-- Adjusts spacing to ensure icons are aligned
nerd_font_variant = 'mono'
},
-- (Default) Only show the documentation popup when manually triggered
completion = { documentation = { auto_show = false } },
-- Default list of enabled providers defined so that you can extend it
-- elsewhere in your config, without redefining it, due to `opts_extend`
sources = {
default = { 'lsp', 'path', 'buffer' },
},
-- (Default) Rust fuzzy matcher for typo resistance and significantly better performance
-- You may use a lua implementation instead by using `implementation = "lua"` or fallback to the lua implementation,
-- when the Rust fuzzy matcher is not available, by using `implementation = "prefer_rust"`
--
-- See the fuzzy documentation for more information
fuzzy = { implementation = "prefer_rust_with_warning" }
},
opts_extend = { "sources.default" }
}
})
-- Large workspace scanning may freeze the UI; see https://github.com/neovim/neovim/issues/23291
-- capabilities.workspace.didChangeWatchedFiles.dynamicRegistration = false
local function stop_lsp_clients()
vim.lsp.stop_client(vim.lsp.get_clients())
end
vim.api.nvim_create_user_command('LspStop', stop_lsp_clients, {})
-- https://clangd.llvm.org/extensions.html#switch-between-sourceheader
local function switch_source_header(bufnr)
local method_name = 'textDocument/switchSourceHeader'
local client = vim.lsp.get_clients({ bufnr = bufnr })[1]
local params = vim.lsp.util.make_text_document_params(bufnr)
client.request(method_name, params, function(err, result)
if err then
error(tostring(err))
end
if not result then
vim.notify('corresponding file cannot be determined')
return
end
vim.cmd.edit(vim.uri_to_fname(result))
end, bufnr)
end
local clangd_cmd = {
"clangd",
"-header-insertion=never",
}
local is_pigweed = string.find(vim.loop.cwd() or "", "/pigweed")
if is_pigweed then
clangd_cmd = {
"/usr/local/google/home/benlawson/pigweed/.environment/cipd/packages/pigweed/bin/clangd",
"-header-insertion=never",
-- GN
--"--compile-commands-dir=/usr/local/google/home/benlawson/pigweed/.pw_ide/.stable",
-- Bazel
-- "--compile-commands-dir=/usr/local/google/home/benlawson/pigweed/.compile_commands/fuchsia",
-- Bazel (NEW!)
"--compile-commands-dir=/usr/local/google/home/benlawson/pigweed/.compile_commands/fuchsia_x64-fastbuild-ST-8479f6f5b9de",
"--query-driver=/usr/local/google/home/benlawson/pigweed/.environment/cipd/packages/pigweed/bin/*,/usr/local/google/home/benlawson/pigweed/.environment/cipd/packages/arm/bin/*",
"--background-index",
"--clang-tidy",
}
end
vim.lsp.config['clangd'] = {
cmd = clangd_cmd,
filetypes = { 'h', 'cc', 'cpp', 'cc.inc' },
root_markers = { '.gn' },
commands = {
ClangdSwitchSourceHeader = {
function()
-- 0 means current buffer
switch_source_header(0)
end,
description = 'Switch between source/header',
},
}
}
vim.lsp.enable('clangd')
vim.lsp.config['rust_analyzer'] = {
cmd = { '/usr/local/google/home/benlawson/fuchsia/prebuilt/third_party/rust-analyzer/rust-analyzer' },
filetypes = { 'rust' },
root_markers = { '.git' },
settings = {
['rust-analyzer'] = {
diagnostics = {
enable = true,
remapPrefix = {
["../../"] = "~/fuchsia",
},
experimental = {
enable = true,
}
},
check = {
-- overrideCommand = { "fx", "clippy", "--all", "--raw"}
overrideCommand = { "fx", "clippy", "-f", "$saved_file", "--raw" }
},
cachePriming = {
enable = false,
}
},
},
}
vim.lsp.enable('rust_analyzer')
vim.lsp.config['luals'] = {
cmd = { 'lua-language-server' },
filetypes = { 'lua' },
root_markers = { '.luarc.json', '.luarc.jsonc' },
settings = {
Lua = {
format = {
enable = true,
-- Put format options here
-- NOTE: the value should be STRING!!
defaultConfig = {
indent_style = "space",
indent_size = "2",
}
},
runtime = {
-- Tell the language server which version of Lua you're using
-- (most likely LuaJIT in the case of Neovim)
version = 'LuaJIT'
},
-- Make the server aware of Neovim runtime files
workspace = {
checkThirdParty = false,
-- library = {
-- vim.env.VIMRUNTIME
-- -- Depending on the usage, you might want to add additional paths here.
-- -- "${3rd}/luv/library"
-- -- "${3rd}/busted/library",
-- }
-- or pull in all of 'runtimepath'. NOTE: this is a lot slower
library = vim.api.nvim_get_runtime_file("", true)
}
}
}
}
vim.lsp.enable('luals')
-- Theme
vim.cmd [[colorscheme eink]]
-- Git
vim.keymap.set('n', '<leader>gg', function() vim.cmd('Git') end, {})
-- Enable line numbers
vim.wo.number = true
-- Don't wrap lines
vim.wo.wrap = false
-- Terminal
vim.keymap.set('t', '<C-space>', '<C-\\><C-n>', {}) -- exit terminal mode
-- window keymap
vim.keymap.set('n', '<leader>wh', '<C-w>h', {})
vim.keymap.set('n', '<leader>wj', '<C-w>j', {})
vim.keymap.set('n', '<leader>wk', '<C-w>k', {})
vim.keymap.set('n', '<leader>wl', '<C-w>l', {})
-- Global mappings.
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next)
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist)
-- Buffer local mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, {})
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, {})
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, {})
vim.keymap.set('n', 'gr', vim.lsp.buf.references, {})
vim.keymap.set('n', 'gh', vim.lsp.buf.hover, {})
vim.keymap.set('n', 'gk', vim.lsp.buf.signature_help, {})
vim.keymap.set('n', '<leader>D', vim.lsp.buf.type_definition, {})
vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, {})
-- vim.keymap.set('n', '<leader>o', function() vim.cmd('ClangdSwitchSourceHeader') end, {})
vim.keymap.set('n', '<leader>o', function() switch_source_header(0) end, {})
vim.keymap.set({ 'n', 'v' }, '<leader>ca', vim.lsp.buf.code_action, {})
vim.keymap.set('n', '<leader>bf', function()
vim.lsp.buf.format { async = true }
end, {})
vim.keymap.set('n', '<leader>G', ':DiffviewOpen HEAD~1<CR>', {})
-- LSP format on save
vim.api.nvim_create_autocmd({ "BufWritePre" }, {
callback = function()
vim.lsp.buf.format()
end,
})
-- misc keymaps
vim.keymap.set('n', '<leader>bp', '<C-^>', {})
-- FIDL
vim.filetype.add({ extension = { fidl = "fidl" } })
-- highlight whitespace
vim.opt.listchars = {
tab = "▏ ",
trail = "·",
nbsp = "·"
}
vim.opt.list = true
-- Copy to system clipboard: "+y
vim.g.clipboard = {
name = 'OSC 52',
copy = {
['+'] = require('vim.ui.clipboard.osc52').copy('+'),
['*'] = require('vim.ui.clipboard.osc52').copy('*'),
},
paste = {
['+'] = require('vim.ui.clipboard.osc52').paste('+'),
['*'] = require('vim.ui.clipboard.osc52').paste('*'),
},
}
vim.cmd [[set notermguicolors]]
vim.cmd [[set bg=light]]
vim.cmd [[let g:terminal_color_11 = 'black']]