|
| 1 | +local M = {} |
| 2 | +M.lsp = require'lsp' |
| 3 | + |
1 | 4 | require'hop'.setup() |
2 | 5 |
|
3 | 6 | require('telescope').setup{ |
@@ -82,7 +85,11 @@ local on_attach = function(client, bufnr) |
82 | 85 | end |
83 | 86 | options = vim.tbl_extend('force', options, opts) |
84 | 87 | end |
85 | | - vim.api.nvim_buf_set_keymap(bufnr, mode, lhs, rhs, options) |
| 88 | + if type(opts) == 'string' then |
| 89 | + vim.api.nvim_buf_set_keymap(bufnr, mode, lhs, rhs, options) |
| 90 | + else |
| 91 | + vim.keymap.set(mode, lhs, rhs, {buffer=true}) |
| 92 | + end |
86 | 93 | end |
87 | 94 | local function nmap(lhs, rhs, opts) |
88 | 95 | map('n', lhs, rhs, opts) |
@@ -125,23 +132,33 @@ local on_attach = function(client, bufnr) |
125 | 132 | nmap('xd', '<cmd>CclsDerived<cr>') |
126 | 133 | nmap('xi', '<cmd>lua vim.lsp.buf.implementation()<cr>', 'Implementation') |
127 | 134 | nmap('xm', '<cmd>CclsMember<cr>', 'member') |
| 135 | + nmap('xn', function() M.lsp.words.jump(vim.v.count1) end, 'Next reference') |
| 136 | + nmap('xp', function() M.lsp.words.jump(-vim.v.count1) end, 'Prev reference') |
128 | 137 | nmap('xt', '<cmd>lua vim.lsp.buf.type_definition()<cr>', 'Type definition') |
129 | 138 | nmap('xv', '<cmd>CclsVars<cr>', 'vars') |
130 | 139 |
|
131 | | - if client.supports_method 'textDocument/documentHighlight' then |
132 | | - vim.api.nvim_create_augroup('lsp_document_highlight', {clear = true}) |
133 | | - vim.api.nvim_clear_autocmds {buffer = bufnr, group = 'lsp_document_highlight'} |
134 | | - vim.api.nvim_create_autocmd('CursorHold', { |
135 | | - callback = vim.lsp.buf.document_highlight, |
| 140 | + if client.supports_method 'textDocument/codeLens' then |
| 141 | + vim.api.nvim_create_autocmd({'BufEnter'}, { |
| 142 | + group = vim.api.nvim_create_augroup('lsp_buf_' .. bufnr, {clear = true}), |
136 | 143 | buffer = bufnr, |
137 | | - group = 'lsp_document_highlight', |
138 | | - desc = 'Document Highlight', |
| 144 | + callback = function(ev) |
| 145 | + vim.lsp.codelens.refresh({ bufnr = 0 }) |
| 146 | + end, |
139 | 147 | }) |
140 | | - vim.api.nvim_create_autocmd('CursorMoved', { |
141 | | - callback = vim.lsp.buf.clear_references, |
| 148 | + end |
| 149 | + |
| 150 | + if client.supports_method 'textDocument/documentHighlight' then |
| 151 | + vim.api.nvim_create_autocmd({'CursorHold', 'CursorHoldI', 'CursorMoved', 'CursorMovedI'}, { |
| 152 | + group = vim.api.nvim_create_augroup('lsp_word_' .. bufnr, {clear = true}), |
142 | 153 | buffer = bufnr, |
143 | | - group = 'lsp_document_highlight', |
144 | | - desc = 'Clear All the References', |
| 154 | + callback = function(ev) |
| 155 | + if ev.event:find('CursorMoved') then |
| 156 | + vim.lsp.buf.clear_references() |
| 157 | + else |
| 158 | + vim.lsp.buf.document_highlight() |
| 159 | + end |
| 160 | + end, |
| 161 | + desc = 'Document Highlight', |
145 | 162 | }) |
146 | 163 | end |
147 | 164 |
|
@@ -301,6 +318,8 @@ require('gitsigns').setup() |
301 | 318 | local neogit = require('neogit') |
302 | 319 | neogit.setup {} |
303 | 320 |
|
304 | | -require('octo').setup() |
| 321 | +-- require('octo').setup() |
305 | 322 |
|
306 | 323 | require('which-key').setup() |
| 324 | + |
| 325 | +return M |
0 commit comments