Skip to content

Commit

Permalink
fix: CocTagFunc jumps to wrong position if using tabs for indentation (
Browse files Browse the repository at this point in the history
…#4810)

From LSP specification, Position.character indicates the character
offset on a line in a document (zero-based) [1]. However, `|` in vim
will jump to screen column [2]. If the file (e.g., linux kernel source
code) uses tabs for indentation, then CocTagFunc will jump to a wrong
position. We can fix it by changing to use `cursor()`, whose col
argument means the byte-count column.

1. https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#position
2. https://vimdoc.sourceforge.net/htmldoc/motion.html#bar

Signed-off-by: Adam Tao <[email protected]>
  • Loading branch information
tcx4c70 authored Nov 14, 2023
1 parent e3f91b5 commit 9c3723a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/__tests__/handler/locations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,10 @@ describe('locations', () => {
expect(res).toEqual([
{
name: 'foo',
cmd: 'silent keepjumps 3 | normal 1|',
cmd: 'silent keepjumps call cursor(3, 1)',
filename: 'test://bar'
},
{ name: 'foo', cmd: 'silent keepjumps 2 | normal 1|', filename: '/foo' }
{ name: 'foo', cmd: 'silent keepjumps call cursor(2, 1)', filename: '/foo' }
])
})
})
Expand Down
2 changes: 1 addition & 1 deletion src/handler/locations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export default class LocationsHandler {
const filename = parsedURI.scheme == 'file' ? parsedURI.fsPath : parsedURI.toString()
return {
name: word,
cmd: `silent keepjumps ${location.range.start.line + 1} | normal ${location.range.start.character + 1}|`,
cmd: `silent keepjumps call cursor(${location.range.start.line + 1}, ${location.range.start.character + 1})`,
filename,
}
})
Expand Down

0 comments on commit 9c3723a

Please sign in to comment.