diff options
Diffstat (limited to 'lua')
-rw-r--r-- | lua/completions.lua | 16 | ||||
-rw-r--r-- | lua/leap-ast.lua | 51 | ||||
-rw-r--r-- | lua/leap.lua | 10 | ||||
-rw-r--r-- | lua/lsp.lua | 71 | ||||
-rw-r--r-- | lua/treesitter.lua | 2 |
5 files changed, 115 insertions, 35 deletions
diff --git a/lua/completions.lua b/lua/completions.lua index f7598a6..bd90178 100644 --- a/lua/completions.lua +++ b/lua/completions.lua | |||
@@ -14,6 +14,22 @@ cmp.setup({ | |||
14 | c = cmp.mapping.close(), | 14 | c = cmp.mapping.close(), |
15 | }), | 15 | }), |
16 | ['<CR>'] = cmp.mapping.confirm({ select = true }), | 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' }), | ||
17 | }, | 33 | }, |
18 | sources = cmp.config.sources({ | 34 | sources = cmp.config.sources({ |
19 | { name = 'nvim_lsp' }, | 35 | { name = 'nvim_lsp' }, |
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 index 7509593..349c719 100644 --- a/lua/lsp.lua +++ b/lua/lsp.lua | |||
@@ -6,53 +6,51 @@ local on_attach = function(client, bufnr) | |||
6 | buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') | 6 | buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') |
7 | 7 | ||
8 | -- Mappings. | 8 | -- Mappings. |
9 | local opts = { noremap=true, silent=true } | 9 | local bufopts = { noremap=true, silent=true, buffer=bufnr } |
10 | buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts) | 10 | vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts) |
11 | buf_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts) | 11 | vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts) |
12 | buf_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts) | 12 | vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts) |
13 | buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts) | 13 | vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts) |
14 | buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts) | 14 | vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts) |
15 | buf_set_keymap('n', '<leader>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts) | ||
16 | buf_set_keymap('n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts) | ||
17 | buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts) | ||
18 | buf_set_keymap('n', '<leader>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts) | ||
19 | buf_set_keymap('n', '[g', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts) | ||
20 | buf_set_keymap('n', ']g', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts) | ||
21 | buf_set_keymap('n', '<leader>q', '<cmd>lua vim.diagnostic.set_qflist()<CR>', opts) | ||
22 | 15 | ||
23 | -- Set some keybinds conditional on server capabilities | 16 | local opts = { noremap=true, silent=true } |
24 | if client.server_capabilities.document_formatting then | 17 | vim.keymap.set('n', '<space>d', vim.diagnostic.open_float, opts) |
25 | buf_set_keymap("n", "<leader>f", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts) | 18 | vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts) |
26 | elseif client.server_capabilities.document_range_formatting then | 19 | vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts) |
27 | buf_set_keymap("n", "<leader>f", "<cmd>lua vim.lsp.buf.range_formatting()<CR>", opts) | 20 | vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts) |
28 | end | 21 | vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts) |
29 | end | 22 | end |
30 | 23 | ||
31 | local servers = { "hls", "rnix", "bashls" } | 24 | local servers = { "hls", "bashls" } |
32 | for _, lsp in ipairs(servers) do | 25 | for _, lsp in ipairs(servers) do |
33 | nvim_lsp[lsp].setup { | 26 | nvim_lsp[lsp].setup { |
34 | on_attach = on_attach, | 27 | on_attach = on_attach, |
35 | } | 28 | } |
36 | end | 29 | end |
37 | 30 | ||
38 | local capabilities = vim.lsp.protocol.make_client_capabilities() | 31 | local capabilities = require('cmp_nvim_lsp') |
32 | .default_capabilities(vim.lsp.protocol.make_client_capabilities()) | ||
33 | |||
39 | capabilities.textDocument.completion.completionItem.snippetSupport = true | 34 | capabilities.textDocument.completion.completionItem.snippetSupport = true |
40 | 35 | ||
41 | nvim_lsp.rust_analyzer.setup { | 36 | -- nvim_lsp.rust_analyzer.setup { |
42 | capabilities = capabilities, | 37 | -- on_attach = on_attach, |
43 | settings = { | 38 | -- settings = { |
44 | ["rust-analyzer"] = { | 39 | -- ["rust-analyzer"] = { |
45 | procMacro = { | 40 | -- procMacro = { |
46 | enable = true | 41 | -- enable = true |
47 | }, | 42 | -- }, |
48 | cargo = { | 43 | -- cargo = { |
49 | allFeatures = true, | 44 | -- allFeatures = false, |
50 | }, | 45 | -- }, |
51 | }, | 46 | -- checkOnSave = false, |
52 | }, | 47 | -- }, |
53 | } | 48 | -- }, |
49 | -- } | ||
54 | 50 | ||
55 | nvim_lsp.ccls.setup { | 51 | nvim_lsp.ccls.setup { |
52 | capabilities = capabilities, | ||
53 | on_attach = on_attach, | ||
56 | init_options = { | 54 | init_options = { |
57 | index = { | 55 | index = { |
58 | threads = 0; | 56 | threads = 0; |
@@ -63,3 +61,8 @@ nvim_lsp.ccls.setup { | |||
63 | }; | 61 | }; |
64 | } | 62 | } |
65 | } | 63 | } |
64 | |||
65 | nvim_lsp.jdtls.setup{ | ||
66 | cmd = {"jdtls"}; | ||
67 | } | ||
68 | |||
diff --git a/lua/treesitter.lua b/lua/treesitter.lua index 344abf0..f63cb3b 100644 --- a/lua/treesitter.lua +++ b/lua/treesitter.lua | |||
@@ -1,6 +1,6 @@ | |||
1 | require'nvim-treesitter.configs'.setup { | 1 | require'nvim-treesitter.configs'.setup { |
2 | highlight = { | 2 | highlight = { |
3 | enable = true, | 3 | enable = false, |
4 | -- disable = { "c"}, | 4 | -- disable = { "c"}, |
5 | }, | 5 | }, |
6 | incremental_selection = { | 6 | incremental_selection = { |