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

Rename provider not found #344

Closed
hejops opened this issue Feb 25, 2021 · 23 comments
Closed

Rename provider not found #344

hejops opened this issue Feb 25, 2021 · 23 comments

Comments

@hejops
Copy link

hejops commented Feb 25, 2021

I'm having a similar issue as mentioned here: #51 (comment)

Completion, diagnostics and formatting work normally.

versions

vim version: VIM - Vi IMproved 8.2 8022489
node version: v15.8.0
coc.nvim version: 0.0.80-8e7635b6a0
coc.nvim directory: /home/user/.vim/plugged/coc.nvim
term: dumb
platform: linux

Log of coc.nvim

CocInfo
2021-02-25T11:05:26.404 INFO (pid:846565) [services] - registered service "diagnostic-languageserver"
2021-02-25T11:05:26.469 INFO (pid:846565) [services] - registered service "pyright"
2021-02-25T11:05:26.469 INFO (pid:846565) [services] - Pyright Server state change: stopped => starting
2021-02-25T11:05:26.515 INFO (pid:846565) [plugin] - coc.nvim 0.0.80-8e7635b6a0 initialized with node: v15.8.0 after 216ms
2021-02-25T11:05:26.523 INFO (pid:846565) [language-client-index] - pyright started with 846599
2021-02-25T11:05:26.767 INFO (pid:846565) [services] - Pyright Server state change: starting => running
2021-02-25T11:05:26.774 INFO (pid:846565) [services] - service pyright started
2021-02-25T11:05:28.808 INFO (pid:846565) [attach] - receive notification: highlight []
2021-02-25T11:05:29.686 INFO (pid:846565) [attach] - receive notification: highlight []
2021-02-25T11:05:31.478 INFO (pid:846565) [attach] - receive notification: runCommand [ 'document.renameCurrentWord' ]
2021-02-25T11:05:31.784 INFO (pid:846565) [attach] - receive notification: highlight []
2021-02-25T11:05:34.419 INFO (pid:846565) [attach] - receive notification: showInfo []

CocOpenLog
2021-02-25T11:05:26.404 INFO (pid:846565) [services] - registered service "diagnostic-languageserver"
2021-02-25T11:05:26.469 INFO (pid:846565) [services] - registered service "pyright"
2021-02-25T11:05:26.469 INFO (pid:846565) [services] - Pyright Server state change: stopped => starting
2021-02-25T11:05:26.515 INFO (pid:846565) [plugin] - coc.nvim 0.0.80-8e7635b6a0 initialized with node: v15.8.0 after 216ms
2021-02-25T11:05:26.523 INFO (pid:846565) [language-client-index] - pyright started with 846599
2021-02-25T11:05:26.767 INFO (pid:846565) [services] - Pyright Server state change: starting => running
2021-02-25T11:05:26.774 INFO (pid:846565) [services] - service pyright started
2021-02-25T11:05:28.808 INFO (pid:846565) [attach] - receive notification: highlight []
2021-02-25T11:05:29.686 INFO (pid:846565) [attach] - receive notification: highlight []
2021-02-25T11:05:31.478 INFO (pid:846565) [attach] - receive notification: runCommand [ 'document.renameCurrentWord' ]
2021-02-25T11:05:31.784 INFO (pid:846565) [attach] - receive notification: highlight []
2021-02-25T11:05:34.419 INFO (pid:846565) [attach] - receive notification: showInfo []
2021-02-25T11:05:34.444 INFO (pid:846565) [attach] - receive request: CocAutocmd [ 'BufReadCmd', 'output', 'output:///info' ]
2021-02-25T11:05:34.875 INFO (pid:846565) [attach] - receive notification: highlight []
2021-02-25T11:05:41.086 INFO (pid:846565) [attach] - receive notification: highlight []
2021-02-25T11:05:42.221 INFO (pid:846565) [attach] - receive notification: highlight []
2021-02-25T11:06:00.897 INFO (pid:846565) [attach] - receive notification: highlight []
2021-02-25T11:06:03.514 INFO (pid:846565) [attach] - receive notification: openLog []
@fannheyward
Copy link
Owner

What does :CocList services output when you came this error?

@hejops
Copy link
Author

hejops commented Feb 25, 2021

* pyright [running] python
  diagnostic-languageserver [init] sh

(by the way, is there a way to get the output of that command non-interactively?)

@yaegassy
Copy link
Contributor

yaegassy commented Feb 25, 2021

@hejops Are you setting "pyright.disableLanguageServices": true in coc-settings.json?

This setting has been "deprecated" in coc-pyright, but if it is set, it may have a bad effect.

If you have it set, please delete the setting and try again.

@hejops
Copy link
Author

hejops commented Feb 25, 2021

The only settings I have set in coc-settings.json are sh related.

@yaegassy
Copy link
Contributor

In my environment, "Rename" works fine in both Vim8 and Neovim. I can't reproduce it.

@hejops
Copy link
Author

hejops commented Feb 25, 2021

I remember rename working on my other machine; I'll try to figure out what's different over there. Could I be missing a dependency (I installed rope via pip to be sure), or could it be conflicting with coc-diagnostic perhaps?

For posterity, here are the contents of package.json and coc-settings.json:

Packages:
coc-diagnostic
coc-json
coc-pyright
coc-sh
coc-vimtex

Settings:
{
  "coc.preferences.extensionUpdateCheck": "weekly",
  "diagnostic-languageserver.filetypes": {
    "sh": "shellcheck",
    "python": "pylint",
    "vim": "vint"
  },
  "diagnostic-languageserver.formatFiletypes": {
    "sh": "shfmt"
  },
  "diagnostic-languageserver.formatters": {
    "shfmt": {
      "command": "shfmt"
    },
    "args": [
      "-i",
      "2",
      "-bn",
      "-ci",
      "-sr"
    ]
  }
}

And rope (according to pip) is located in /usr/lib/python3.9/site-packages.

@yaegassy
Copy link
Contributor

yaegassy commented Feb 26, 2021

I remember rename working on my other machine; I'll try to figure out what's different over there. Could I be missing a dependency (I installed rope via pip to be sure), or could it be conflicting with coc-diagnostic perhaps?

In coc-pyright, rope is not required for the "rename" feature. This is required if you want to use some of the "code action" features.

To check if there is a conflict with coc-diagnostic, you can uninstall coc-diagnostic temporarily. :CocUninstall coc-diagnostic

If the "workspace folder" is not resolved correctly, "rename" may not work. Check this wiki page to make sure your "workspace folder" (project root) is set up properly. https://github.com/neoclide/coc.nvim/wiki/Using-workspaceFolders

@hejops
Copy link
Author

hejops commented Feb 26, 2021

I managed to trace my git history and pinpoint the cause of the error. Turns out it was due to some issues between using nmap and nnoremap, as well as the specific command called for rename. To be clear, here is what worked for me, and what didn't:

Works:
nmap R <Plug>(coc-rename)

Does not work:
nnoremap R <Plug>(coc-rename)				Nothing executed
nmap R :CocCommand document.renameCurrentWord<CR>	Rename provider not found
nnoremap R :CocCommand document.renameCurrentWord<CR>	Rename provider not found

Hopefully this is of use to anyone with the same issue in future.

@hejops hejops closed this as completed Feb 26, 2021
@gitschneider
Copy link

For me it helped to install rope manually in my virtualenv. Weird, but ok.

@liquiddandruff
Copy link

liquiddandruff commented Mar 10, 2021

This seems to happen intermittently for me on coc-pyright, but a :CocRestart fixes it. Completion, gotos, etc all still work when this happens.

vim version: NVIM v0.4.3
node version: v15.11.0
coc.nvim version: 0.0.80-9184dcccc4

@hejops
Copy link
Author

hejops commented Mar 14, 2021

This seems to happen intermittently for me on coc-pyright, but a :CocRestart fixes it. Completion, gotos, etc all still work when this happens.

Indeed, I recently encountered an "Invalid position for rename" error, and :CocRestart fixed it. I assume these are issues with coc itself then, not this extension.

@dcordb
Copy link

dcordb commented Mar 25, 2021

I can confirm that rename doesn't work. I get the following message when trying to rename: [coc.nvim] Invalid position for rename.

Here is my coc-settings.json:

{
  "languageserver": {
    "ccls": {
      "command": "ccls",
      "filetypes": ["c", "cpp", "cuda", "objc", "objcpp"],
      "rootPatterns": [".ccls-root", "compile_commands.json"],
      "initializationOptions": {
        "cache": {
          "directory": ".ccls-cache"
        },
        "client": {
          "snippetSupport": true
        },
        "highlight": {
          "lsRanges": true
        }
      }
    }
  },
  "diagnostic.refreshOnInsertMode": true
}

This is happening with coc-pyright 1.1.122 (the only language server I have with python is pyright). Also I checked for C++ (I have ccls language server) and it works just fine with coc. I think this is an issue of coc-pyright.

@dcordb
Copy link

dcordb commented Mar 25, 2021

@fannheyward Could you consider reopening this?

@fannheyward
Copy link
Owner

fannheyward commented Mar 25, 2021

Invalid position for rename

@dcordb Can't reproduce this, please checkout :CocList services when you came the rename error.

@dcordb
Copy link

dcordb commented Mar 25, 2021

@fannheyward

I checked this with a minimal init.vim file, is the following:

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

nmap <silent> <F2> <Plug>(coc-rename)

Rename still won't work, from :CocList services I get that pyright is running. My pyright version is pyright 1.1.124, and coc-pyright version is 1.1.122. I'm using neovim v0.5.0-dev.

Could it be that something has changed in the last update of pyright that affects coc-pyright renaming?

@liquiddandruff
Copy link

@dcordb

When the rename doesn't work for you, does goto definitions and other coc-pyright features still work? Asking since if so, and if doing :CocRestart causes rename functionality to work, then I had the exact same issue as you.

It feels like initial setup causes this rename bug to show up, then afterwards if the coc server is restarted at least once, it never happens again.

@dcordb
Copy link

dcordb commented Mar 26, 2021

@liquiddandruff yes, while rename doesn't work everything else does (go to definition, auto completion, etc). Well everything except refactor that I get [coc.nvim] Empty workspaceEdit from language server (but maybe I need to configure something, although I couldn't find any setting with this name in coc help).

Restarting coc doesn't solve it for me. Also the renaming is working with C++ and ccls language server (all of this using coc also).

@yaegassy
Copy link
Contributor

@dcordb

If the workspace folder (project root) is not detected correctly, you may not be able to "Rename" it.

It may work correctly if you put pyrightconfig.json in the "project root", or check this wiki and take the necessary actions. Ref: https://github.com/neoclide/coc.nvim/wiki/Using-workspaceFolders

@yaegassy
Copy link
Contributor

@dcordb

Supplement: pyrightconfig.json should be in valid json format, This is the minimum content.

{}

@yaegassy
Copy link
Contributor

This is an example of a case where Rename is not possible.

Directory example

tmp$ pwd
/tmp
tmp$ tree coc-pyright-issue344/
coc-pyright-issue344/
└── check.py

[NG] Edit files with "absolute" paths.

1_coc-pyright-issue344_ng

[OK] Edit files with "relative" paths

2_coc-pyright-issue344_ok


In order to make "Rename" work with absolute paths, I think you still need to configure the workspace folder related settings. Ref: https://github.com/neoclide/coc.nvim/wiki/Using-workspaceFolders

@dcordb
Copy link

dcordb commented Mar 26, 2021

@yaegassy thanks for your explanation, yes this now works for me. I didn't know that in order to perform a rename I should be inside of a workspace.

In fact, as you said, in the case when the rename fails I ran CocList folders and it couldn't find it, so it fails. Maybe this should be specified in the error message.

Also I just tested this for C++ and it works with either absolute or relative paths (it seems that it doesn't matter if it's inside a workspace or not). It's worth noting that for C++ I'm not using a coc extension, just the language server directly.

So I'm assuming that being in a workspace is a requirement for coc-pyright, but not for other extensions. Is this so?

@yaegassy
Copy link
Contributor

yaegassy commented Mar 26, 2021

@dcordb I think each language server behaves differently.

I also think the situation is different depending on the project structure.

For example, in the case of a "monorepo" structure, it is common for the .git of the parent directory to be detected and the wrong workspace folder to be set, causing definition jumps and more... to not work properly.

@g15ecb
Copy link

g15ecb commented Apr 20, 2021

I experienced the same issue with 'rename'. I changed in my init.vim the binding nmap <silent>rn <Plug>(coc-rename) to nmap rn <Plug>(coc-rename) and all seems well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants