diff options
author | Akshay <[email protected]> | 2024-07-23 20:26:43 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2024-07-23 20:26:43 +0100 |
commit | ddc6f72c5b1cf6916ef2705b226d0c53950b9386 (patch) | |
tree | 56b1d651dfe18a5e45b8cc6477ff8cb49991d98c /lua |
init
Diffstat (limited to 'lua')
-rw-r--r-- | lua/completions.lua | 53 | ||||
-rw-r--r-- | lua/leap-ast.lua | 51 | ||||
-rw-r--r-- | lua/leap.lua | 10 | ||||
-rw-r--r-- | lua/lsp.lua | 68 | ||||
-rw-r--r-- | lua/treesitter.lua | 41 |
5 files changed, 223 insertions, 0 deletions
diff --git a/lua/completions.lua b/lua/completions.lua new file mode 100644 index 0000000..bd90178 --- /dev/null +++ b/lua/completions.lua | |||
@@ -0,0 +1,53 @@ | |||
1 | local cmp = require 'cmp' | ||
2 | |||
3 | cmp.setup({ | ||
4 | snippet = { | ||
5 | expand = function(args) end, | ||
6 | }, | ||
7 | mapping = { | ||
8 | ['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }), | ||
9 | ['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }), | ||
10 | ['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }), | ||
11 | ['<C-y>'] = cmp.config.disable, | ||
12 | ['<C-e>'] = cmp.mapping({ | ||
13 | i = cmp.mapping.abort(), | ||
14 | c = cmp.mapping.close(), | ||
15 | }), | ||
16 | ['<CR>'] = cmp.mapping.confirm({ select = true }), | ||
17 | |||
18 | ['<C-n>'] = cmp.mapping(function(fallback) | ||
19 | if cmp.visible() then | ||
20 | cmp.select_next_item() | ||
21 | else | ||
22 | fallback() | ||
23 | end | ||
24 | end, { 'i', 's', 'c' }), | ||
25 | |||
26 | ['<C-p>'] = cmp.mapping(function(fallback) | ||
27 | if cmp.visible() then | ||
28 | cmp.select_prev_item() | ||
29 | else | ||
30 | fallback() | ||
31 | end | ||
32 | end, { 'i', 's', 'c' }), | ||
33 | }, | ||
34 | sources = cmp.config.sources({ | ||
35 | { name = 'nvim_lsp' }, | ||
36 | }, { | ||
37 | { name = 'buffer' }, | ||
38 | }) | ||
39 | }) | ||
40 | |||
41 | cmp.setup.cmdline('/', { | ||
42 | sources = { | ||
43 | { name = 'buffer' } | ||
44 | } | ||
45 | }) | ||
46 | |||
47 | cmp.setup.cmdline(':', { | ||
48 | sources = cmp.config.sources({ | ||
49 | { name = 'path' } | ||
50 | }, { | ||
51 | { name = 'cmdline' } | ||
52 | }) | ||
53 | }) | ||
diff --git a/lua/leap-ast.lua b/lua/leap-ast.lua new file mode 100644 index 0000000..22a5876 --- /dev/null +++ b/lua/leap-ast.lua | |||
@@ -0,0 +1,51 @@ | |||
1 | local api = vim.api | ||
2 | -- Note: The functions used here will be upstreamed eventually. | ||
3 | local ts_utils = require('nvim-treesitter.ts_utils') | ||
4 | |||
5 | local function get_ast_nodes() | ||
6 | local wininfo = vim.fn.getwininfo(api.nvim_get_current_win())[1] | ||
7 | -- Get current TS node. | ||
8 | local cur_node = ts_utils.get_node_at_cursor(0) | ||
9 | if not cur_node then return end | ||
10 | -- Get parent nodes recursively. | ||
11 | local nodes = { cur_node } | ||
12 | local parent = cur_node:parent() | ||
13 | while parent do | ||
14 | table.insert(nodes, parent) | ||
15 | parent = parent:parent() | ||
16 | end | ||
17 | -- Create Leap targets from TS nodes. | ||
18 | local targets = {} | ||
19 | local startline, startcol | ||
20 | for _, node in ipairs(nodes) do | ||
21 | startline, startcol, _, _ = node:range() -- (0,0) | ||
22 | if startline + 1 >= wininfo.topline then | ||
23 | local target = { node = node, pos = { startline + 1, startcol + 1 } } | ||
24 | table.insert(targets, target) | ||
25 | end | ||
26 | end | ||
27 | if #targets >= 1 then return targets end | ||
28 | end | ||
29 | |||
30 | local function select_range(target) | ||
31 | local mode = api.nvim_get_mode().mode | ||
32 | if not mode:match('n?o') then | ||
33 | -- Force going back to Normal (implies mode = v | V | ). | ||
34 | vim.cmd('normal! ' .. mode) | ||
35 | end | ||
36 | ts_utils.update_selection(0, target.node, | ||
37 | mode:match('V') and 'linewise' or | ||
38 | mode:match('') and 'blockwise' or | ||
39 | 'charwise' | ||
40 | ) | ||
41 | end | ||
42 | |||
43 | local function leap() | ||
44 | require('leap').leap { | ||
45 | targets = get_ast_nodes(), | ||
46 | action = api.nvim_get_mode().mode ~= 'n' and select_range, -- or jump | ||
47 | backward = true | ||
48 | } | ||
49 | end | ||
50 | |||
51 | return { leap = leap } | ||
diff --git a/lua/leap.lua b/lua/leap.lua new file mode 100644 index 0000000..14be3bd --- /dev/null +++ b/lua/leap.lua | |||
@@ -0,0 +1,10 @@ | |||
1 | local leap = require 'leap' | ||
2 | leap.opts.safe_labels = {} | ||
3 | leap.opts.labels = { | ||
4 | "a", "r", "s", "t", "n", "e", "i", "o", "d", "h", | ||
5 | "A", "R", "S", "T", "N", "E", "I", "O", "D", "H" | ||
6 | } | ||
7 | leap.opts.special_keys = { | ||
8 | next_target = '<c-n>', | ||
9 | prev_target = '<c-p>', | ||
10 | } | ||
diff --git a/lua/lsp.lua b/lua/lsp.lua new file mode 100644 index 0000000..349c719 --- /dev/null +++ b/lua/lsp.lua | |||
@@ -0,0 +1,68 @@ | |||
1 | local nvim_lsp = require('lspconfig') | ||
2 | local on_attach = function(client, bufnr) | ||
3 | local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end | ||
4 | local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end | ||
5 | |||
6 | buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') | ||
7 | |||
8 | -- Mappings. | ||
9 | local bufopts = { noremap=true, silent=true, buffer=bufnr } | ||
10 | vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) | ||
11 | vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) | ||
12 | vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) | ||
13 | vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) | ||
14 | vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts) | ||
15 | |||
16 | local opts = { noremap=true, silent=true } | ||
17 | vim.keymap.set('n', '<space>d', vim.diagnostic.open_float, opts) | ||
18 | vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts) | ||
19 | vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts) | ||
20 | vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts) | ||
21 | vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts) | ||
22 | end | ||
23 | |||
24 | local servers = { "hls", "bashls" } | ||
25 | for _, lsp in ipairs(servers) do | ||
26 | nvim_lsp[lsp].setup { | ||
27 | on_attach = on_attach, | ||
28 | } | ||
29 | end | ||
30 | |||
31 | local capabilities = require('cmp_nvim_lsp') | ||
32 | .default_capabilities(vim.lsp.protocol.make_client_capabilities()) | ||
33 | |||
34 | capabilities.textDocument.completion.completionItem.snippetSupport = true | ||
35 | |||
36 | -- nvim_lsp.rust_analyzer.setup { | ||
37 | -- on_attach = on_attach, | ||
38 | -- settings = { | ||
39 | -- ["rust-analyzer"] = { | ||
40 | -- procMacro = { | ||
41 | -- enable = true | ||
42 | -- }, | ||
43 | -- cargo = { | ||
44 | -- allFeatures = false, | ||
45 | -- }, | ||
46 | -- checkOnSave = false, | ||
47 | -- }, | ||
48 | -- }, | ||
49 | -- } | ||
50 | |||
51 | nvim_lsp.ccls.setup { | ||
52 | capabilities = capabilities, | ||
53 | on_attach = on_attach, | ||
54 | init_options = { | ||
55 | index = { | ||
56 | threads = 0; | ||
57 | }; | ||
58 | clang = { | ||
59 | extraArgs = { "-fopenmp" }; | ||
60 | excludeArgs = { "-frounding-math" } ; | ||
61 | }; | ||
62 | } | ||
63 | } | ||
64 | |||
65 | nvim_lsp.jdtls.setup{ | ||
66 | cmd = {"jdtls"}; | ||
67 | } | ||
68 | |||
diff --git a/lua/treesitter.lua b/lua/treesitter.lua new file mode 100644 index 0000000..f63cb3b --- /dev/null +++ b/lua/treesitter.lua | |||
@@ -0,0 +1,41 @@ | |||
1 | require'nvim-treesitter.configs'.setup { | ||
2 | highlight = { | ||
3 | enable = false, | ||
4 | -- disable = { "c"}, | ||
5 | }, | ||
6 | incremental_selection = { | ||
7 | enable = true, | ||
8 | keymaps = { | ||
9 | init_selection = "gnn", | ||
10 | node_incremental = "g}", | ||
11 | scope_incremental = "grc", | ||
12 | node_decremental = "g{", | ||
13 | }, | ||
14 | }, | ||
15 | indent = { | ||
16 | enable = false | ||
17 | }, | ||
18 | playground = { | ||
19 | enable = true, | ||
20 | disable = {}, | ||
21 | updatetime = 25, -- Debounced time for highlighting nodes in the playground from source code | ||
22 | persist_queries = false, -- Whether the query persists across vim sessions | ||
23 | keybindings = { | ||
24 | toggle_query_editor = 'o', | ||
25 | toggle_hl_groups = 'i', | ||
26 | toggle_injected_languages = 't', | ||
27 | toggle_anonymous_nodes = 'a', | ||
28 | toggle_language_display = 'I', | ||
29 | focus_language = 'f', | ||
30 | unfocus_language = 'F', | ||
31 | update = 'R', | ||
32 | goto_node = '<cr>', | ||
33 | show_help = '?', | ||
34 | }, | ||
35 | }, | ||
36 | query_linter = { | ||
37 | enable = true, | ||
38 | use_virtual_text = true, | ||
39 | lint_events = {"BufWrite", "CursorHold"}, | ||
40 | }, | ||
41 | } | ||