Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openLink uses incorrect document position #3010

Closed
mickael-menu opened this issue Apr 2, 2021 · 2 comments
Closed

openLink uses incorrect document position #3010

mickael-menu opened this issue Apr 2, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@mickael-menu
Copy link

mickael-menu commented Apr 2, 2021

Result from CocInfo

## versions

vim version: NVIM v0.4.4
node version: v15.1.0
coc.nvim version: 0.0.80-6b4dd38af2
coc.nvim directory: /Users/mickael/.vim/plugged/coc.nvim
term: iTerm.app
platform: darwin

## Log of coc.nvim

2021-04-02T17:11:30.310 INFO (pid:84652) [services] - registered service "languageserver.zk"
2021-04-02T17:11:30.314 INFO (pid:84652) [services] - zk state change: stopped => starting
2021-04-02T17:11:30.317 INFO (pid:84652) [plugin] - coc.nvim 0.0.80-6b4dd38af2 initialized with node: v15.1.0 after 60ms
2021-04-02T17:11:30.321 INFO (pid:84652) [language-client-index] - Language server "languageserver.zk" started with 84657
2021-04-02T17:11:30.689 INFO (pid:84652) [services] - zk state change: starting => running
2021-04-02T17:11:30.693 INFO (pid:84652) [services] - service languageserver.zk started
2021-04-02T17:11:31.306 INFO (pid:84652) [attach] - receive notification: highlight []
2021-04-02T17:11:31.948 INFO (pid:84652) [attach] - receive notification: openLink []
2021-04-02T17:11:32.303 INFO (pid:84652) [attach] - receive notification: highlight []
2021-04-02T17:11:33.383 INFO (pid:84652) [attach] - receive notification: highlight []
2021-04-02T17:11:34.960 INFO (pid:84652) [attach] - receive notification: openLink []
2021-04-02T17:11:35.507 INFO (pid:84652) [attach] - receive notification: highlight []
2021-04-02T17:11:38.163 INFO (pid:84652) [attach] - receive notification: showInfo []

Describe the bug

I'm currently building a language server for a Markdown flavor and found a weird bug when implementing documentLink.

Given the following Markdown document containing a few links:

# Index

* [Note 1](note1.md)
* [Note 2](note2.md)
* [Note 3](note3.md)

When I try to open one linked document with CocAction('openLink'), the LSP communication with my server seems correct:

--> request #1: textDocument/documentLink: {"textDocument":{"uri":"file:///private/tmp/test/index.md"}}

<-- result #1: textDocument/documentLink: [
    {"range":{"start":{"line":2,"character":2},"end":{"line":2,"character":20}},"target":"file:///private/tmp/test/note1.md","tooltip":"Note 1"},
    {"range":{"start":{"line":3,"character":2},"end":{"line":3,"character":20}},"target":"file:///private/tmp/test/note2.md","tooltip":"Note 2"},
    {"range":{"start":{"line":4,"character":2},"end":{"line":4,"character":20}},"target":"file:///private/tmp/test/note3.md","tooltip":"Note 3"}
]

However, coc.nvim opens the wrong document:

  • If the cursor is on [Note 1](note1.md), it will open note2.md.
  • If it is anywhere else (even when not on a link), it will open note1.md.

When checking the links with :CocList links, they seem correct: [j]ump shows the proper range and [o]pen goes to the right document.

Test with documentLink/resolve

In a second attempt, I didn't set the target for the textDocument/documentLink request, to receive the documentLink/resolve and check the requested link. I noticed the same behavior:

  • If the cursor is on [Note 1](note1.md), the range is the one of the note2.md link.
  • If it is anywhere else (even when not on a link), the range is the one of the note1.md link.
--> request #1: textDocument/documentLink: {"textDocument":{"uri":"file:///private/tmp/test/index.md"}}
<-- result #1: textDocument/documentLink: [
    {"range":{"start":{"line":2,"character":2},"end":{"line":2,"character":20}},"tooltip":"Note 1"},
    {"range":{"start":{"line":3,"character":2},"end":{"line":3,"character":20}},"tooltip":"Note 2"},
    {"range":{"start":{"line":4,"character":2},"end":{"line":4,"character":20}},"tooltip":"Note 3"}
]

--> request #2: documentLink/resolve: {
    "range": {
        "start":{"line":3,"character":2},
        "end":{"line":3,"character":20}
    },
    "tooltip":"Note 2",
    "data":{"source":"71887081-200d-4c38-9a2a-03d46baded9b"}
}

Reproduce the bug

I can share the Language Server if needed to reproduce the issue. I could reproduce the problem with the following minimal vimrc:

call plug#begin('~/.vim/plugged')
Plug 'neoclide/coc.nvim', {'branch': 'release'}
call plug#end()

nmap <silent> <CR> <Plug>(coc-openlink)

I use this coc-settings.json to start my server:

{
  "languageserver": {
    "zk": {
      "command": "zk",
      "args": ["lsp"],
      "trace.server": "verbose",
      "filetypes": ["markdown"]
    }
  }
}

After opening a Markdown, I used my <CR> mapping to trigger openLink.

I could also reproduce the same problem with the official gopls language server, following these instructions, I have:

  "languageserver": {
    "golang": {
      "command": "gopls",
      "rootPatterns": ["go.mod", ".vim/", ".git/", ".hg/"],
      "filetypes": ["go"],
      "initializationOptions": {
        "usePlaceholders": true
      }
    }
  }

And with the following Go file:

package main

// http://google.com
// http://github.com

If I trigger openLink on http://google.com, it will open GitHub with my browser. But if I trigger it anywhere else, it opens Google.

Screenshots (optional)

I recorded two videos showing the problem:

@chemzqm chemzqm added the bug Something isn't working label Apr 3, 2021
chemzqm added a commit that referenced this issue Apr 3, 2021
@chemzqm
Copy link
Member

chemzqm commented Apr 3, 2021

Fixed on latest release branch of coc.nvim.

@chemzqm chemzqm closed this as completed Apr 3, 2021
@mickael-menu
Copy link
Author

@chemzqm It works great, thanks a lot for fixing this so quickly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants