|
1 | 1 | local M = {} |
2 | 2 |
|
| 3 | +-- NOTE: encoding is hard-coded here. It's apparently usually utf-16. But |
| 4 | +-- perhaps it should be calculated dynamically? |
| 5 | +local POSITION_ENCODING = 'utf-16' |
| 6 | + |
3 | 7 | ---@alias RefjumpReferencePosition { character: integer, line: integer } |
4 | 8 | ---@alias RefjumpReferenceRange { start: RefjumpReferencePosition, end: RefjumpReferencePosition } |
5 | 9 | ---@alias RefjumpReference { range: RefjumpReferenceRange, uri: string } |
@@ -52,11 +56,8 @@ local function jump_to(next_reference) |
52 | 56 | local bufnr = vim.api.nvim_get_current_buf() |
53 | 57 | local uri = vim.uri_from_bufnr(bufnr) |
54 | 58 | local next_location = { uri = uri, range = next_reference.range } |
55 | | - -- NOTE: encoding is hard-coded here. It's apparently usually utf-16. But |
56 | | - -- perhaps it should be calculated dynamically? |
57 | | - local encoding = 'utf-16' |
58 | 59 |
|
59 | | - vim.lsp.util.jump_to_location(next_location, encoding) |
| 60 | + vim.lsp.util.show_document(next_location, POSITION_ENCODING) |
60 | 61 |
|
61 | 62 | -- Open folds if the reference is inside a fold |
62 | 63 | vim.cmd('normal! zv') |
@@ -111,13 +112,13 @@ function M.reference_jump_from(current_position, opts, count, references, with_r |
111 | 112 | return |
112 | 113 | end |
113 | 114 |
|
114 | | - local params = vim.lsp.util.make_position_params() |
115 | | - |
116 | | - -- We call `textDocument/documentHighlight` here instead of |
| 115 | + -- NOTE: We call `textDocument/documentHighlight` here instead of |
117 | 116 | -- `textDocument/references` for performance reasons. The latter searches the |
118 | 117 | -- entire workspace, but `textDocument/documentHighlight` only searches the |
119 | 118 | -- current buffer, which is what we want. |
120 | | - vim.lsp.buf_request(0, 'textDocument/documentHighlight', params, function(err, refs, _, _) |
| 119 | + local document_highlight = 'textDocument/documentHighlight' |
| 120 | + local params = vim.lsp.util.make_position_params(0, POSITION_ENCODING) |
| 121 | + vim.lsp.buf_request(0, document_highlight, params, function(err, refs, _, _) |
121 | 122 | if err then |
122 | 123 | vim.notify('refjump.nvim: LSP Error: ' .. err.message, vim.log.levels.ERROR) |
123 | 124 | return |
|
152 | 153 | ---@param references? RefjumpReference[] |
153 | 154 | ---@param with_references? function(RefjumpReference[]) Called if `references` is `nil` with LSP references for item at `current_position` |
154 | 155 | function M.reference_jump(opts, references, with_references) |
155 | | - local compatible_lsp_clients = vim.lsp.get_clients({ |
156 | | - method = 'textDocument/documentHighlight', |
157 | | - }) |
158 | | - |
159 | 156 | local current_position = vim.api.nvim_win_get_cursor(0) |
160 | 157 | local count = vim.v.count1 |
161 | 158 | M.reference_jump_from(current_position, opts, count, references, with_references) |
|
0 commit comments