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 in file from another path does not work #521

Closed
dsirov opened this issue Jun 10, 2021 · 13 comments
Closed

Rename in file from another path does not work #521

dsirov opened this issue Jun 10, 2021 · 13 comments

Comments

@dsirov
Copy link

dsirov commented Jun 10, 2021

Problem

When opening a file from another sub-root path and trying to rename a method/variable, the following error is received
[coc.nvim] Invalid position for rename

Seems exactly like in #474, but I do not have coc-python installed.

Minimal Environment

Fully-cleaning coc

rm -rvf ~/.config/coc

~/.config/nvim/init.vim

set nocompatible
call plug#begin('~/.config/nvim/plugged')
Plug 'neoclide/coc.nvim'
call plug#end()
 
let mapleader=","
nmap <leader>rn <Plug>(coc-rename)

installing coc-pyright

:PlugUpdate
:CocInstall coc-pyright

/tmp/test/test.py

import sys
   
def test( s: str ):
    print( s )
   
def main():
    test('1')

Opening the file

cd ~
nvim /tmp/test/test.py

Attempting to Rename

Attempt to rename the name of the function test when standing on any of its letters (,rn)

[coc.nvim] Invalid position for rename

Versioning

:CocCommand pyright.version

[coc.nvim] coc-pyright 1.1.146 with Pyright 1.1.148

:CocInfo

## versions

vim version: NVIM v0.4.4                                                                                    
node version: v14.16.1               
coc.nvim version: 0.0.80-b427b2ccfa  
coc.nvim directory: /home/david/.config/nvim/plugged/coc.nvim                                               
term: xterm-256color
platform: linux

## Log of coc.nvim

2021-06-10T11:50:29.340 INFO (pid:1247104) [services] - registered service "pyright"
2021-06-10T11:50:29.343 INFO (pid:1247104) [services] - Pyright Server state change: stopped => starting 
2021-06-10T11:50:29.349 INFO (pid:1247104) [plugin] - coc.nvim 0.0.80-b427b2ccfa initialized with node: v14.16.1 after 182ms
2021-06-10T11:50:29.356 INFO (pid:1247104) [language-client-index] - pyright started with 1247117
2021-06-10T11:50:29.646 INFO (pid:1247104) [services] - Pyright Server state change: starting => running 
2021-06-10T11:50:29.654 INFO (pid:1247104) [services] - service pyright started
2021-06-10T11:50:30.519 INFO (pid:1247104) [attach] - receive notification: rename []
2021-06-10T11:50:31.244 WARN (pid:1247104) [completion] - Document not attached, suggest disabled.
2021-06-10T11:50:34.792 INFO (pid:1247104) [attach] - receive notification: showInfo []

:version

:version                                                                                                                                                                                                   
NVIM v0.4.4
Build type: RelWithDebInfo
LuaJIT 2.0.5
Compilation: /usr/local/clang-7.0.0/bin/clang -O2 -g -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrou
gh -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/home/travis/build/neovim/bot-ci/build
/neovim/build/config -I/home/travis/build/neovim/bot-ci/build/neovim/src -I/home/travis/build/neovim/bot-ci/build/neovim/.deps/usr/include -I/usr/include -I/home/travis/build/neovim/bot-ci/build/neovim/build/src
/nvim/auto -I/home/travis/build/neovim/bot-ci/build/neovim/build/include
Compiled by travis@travis-job-d8a0d531-236d-4d4c-9703-9d6e27bee65f

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/share/nvim"

Debugging

:checkhealth

health#coc#check
========================================================================
  - OK: Environment check passed

  - OK: Javascript bundle build/index.js found
  - OK: Service started

health#nvim#check
========================================================================
## Configuration
  - OK: no issues found

## Performance
  - OK: Build type: RelWithDebInfo

## Remote Plugins
  - OK: Up to date

## terminal
  - INFO: key_backspace (kbs) terminfo entry: key_backspace=\177
  - INFO: key_dc (kdch1) terminfo entry: key_dc=\E[3~
  - INFO: $VTE_VERSION='6203'
  - INFO: $COLORTERM='truecolor'

health#provider#check
========================================================================
## Clipboard (optional)
  - OK: Clipboard tool found: xclip

## Python 2 provider (optional)
  - WARNING: No Python executable found that can `import neovim`. Using the first available executable for diagnostics.
  - ERROR: Python provider error:
    - ADVICE:
      - provider/pythonx: Could not load Python 2:
          /usr/bin/python2 does not have the "neovim" module. :help |provider-python|
          /usr/bin/python2.7 does not have the "neovim" module. :help |provider-python|
          python2.6 not found in search path or not executable.
          /usr/bin/python is Python 3.9 and cannot provide Python 2.
  - INFO: Executable: Not found

## Python 3 provider (optional)
  - INFO: `g:python3_host_prog` is not set.  Searching for python3 in the environment.
  - INFO: Executable: /usr/bin/python3
  - INFO: Python version: 3.9.5
  - INFO: pynvim version: 0.4.3
  - OK: Latest pynvim is installed.

## Ruby provider (optional)
  - INFO: Ruby: ruby 2.7.3p183 (2021-04-05 revision 6847ee089d) [x86_64-linux]
  - WARNING: `neovim-ruby-host` not found.
    - ADVICE:
      - Run `gem install neovim` to ensure the neovim RubyGem is installed.
      - Run `gem environment` to ensure the gem bin directory is in $PATH.
      - If you are using rvm/rbenv/chruby, try "rehashing".
      - See :help |g:ruby_host_prog| for non-standard gem installations.

## Node.js provider (optional)
  - INFO: Node.js: v14.16.1
  - WARNING: Missing "neovim" npm (or yarn) package.
    - ADVICE:
      - Run in shell: npm install -g neovim
      - Run in shell (if you use yarn): yarn global add neovim

@fannheyward
Copy link
Owner

Do you have some other Python linter or formatter set with coc-diagnostic?

@dsirov
Copy link
Author

dsirov commented Jun 10, 2021

Negative, no other linter or formatter set

coc-settings.json:

{
    "clangd.enabled": true,
    "clangd.semanticHighlighting": true,
    "clangd.path": "/home/david/.config/coc/extensions/coc-clangd-data/install/12.0.0/clangd_12.0.0/bin/clangd",

    "java.home": "/usr/lib/jvm/java-11",

    "java.configuration.runtimes": [
        {
            "name": "JavaSE-1.8",
            "path": "/usr/lib/jvm/java-1.8.0",
            "default": true
        },
        {
            "name": "JavaSE-11",
            "path": "/usr/lib/jvm/java-11"
        }
    ],

    "markdownlint.config": {
        "MD003": false,
        "MD034": false
    },

    "sh.enable": true,
    "sh.highlightParsingErrors": true,

    "diagnostic-languageserver.filetypes": {
        "vim": "vint"
    },

    "diagnostic.errorSign": "✖",
    "diagnostic.warningSign": "!",
    "diagnostic.hintSign": "▶",
    "diagnostic.virtualText": true,
    "diagnostic.locationlistUpdate": true
}

@dsirov
Copy link
Author

dsirov commented Jun 10, 2021

Uninstalling coc-diagnostic does not help

@fannheyward
Copy link
Owner

Tested coc-pyright with coc-diagnostic, can't reproduce.

@dsirov
Copy link
Author

dsirov commented Jun 10, 2021

Started with a fully clean slate for coc (manually removed the coc directory), installed coc-pyright as a single coc plugin, same result.

So it must be something external to coc (?).

:CocInstall coc-pyright
:CocList extensions
  * coc-pyright 1.1.146 ~/.config/coc/extensions/node_modules/coc-pyright 

:CocInfo
## versions

vim version: NVIM v0.4.4
node version: v14.16.1
coc.nvim version: 0.0.80-b427b2ccfa
coc.nvim directory: /media/work/dev/vim/nvim/plugged/coc.nvim
term: xterm-256color
platform: linux

## Log of coc.nvim

2021-06-10T10:39:12.795 WARN (pid:1223696) [attach] - Plugin not ready when received "registNotification" [ 'cquery', '$cquery/publishSemanticHighlighting' ]
2021-06-10T10:39:12.798 WARN (pid:1223696) [attach] - Plugin not ready when received "registNotification" [ 'cquery', '$cquery/setInactiveRegions' ]
2021-06-10T10:39:12.798 WARN (pid:1223696) [attach] - Plugin not ready when received "registNotification" [ 'ccls', '$ccls/publishSemanticHighlight' ]
2021-06-10T10:39:12.799 WARN (pid:1223696) [attach] - Plugin not ready when received "registNotification" [ 'ccls', '$ccls/publishSkippedRanges' ]
2021-06-10T10:39:12.988 INFO (pid:1223696) [services] - registered service "pyright"
2021-06-10T10:39:12.990 INFO (pid:1223696) [services] - Pyright Server state change: stopped => starting
2021-06-10T10:39:12.995 INFO (pid:1223696) [plugin] - coc.nvim 0.0.80-b427b2ccfa initialized with node: v14.16.1 after 182ms
2021-06-10T10:39:13.006 INFO (pid:1223696) [language-client-index] - pyright started with 1223711
2021-06-10T10:39:13.014 INFO (pid:1223696) [attach] - receive notification: registNotification [ 'cquery', '$cquery/publishSemanticHighlighting' ]
2021-06-10T10:39:13.014 INFO (pid:1223696) [attach] - receive notification: registNotification [ 'cquery', '$cquery/setInactiveRegions' ]
2021-06-10T10:39:13.014 INFO (pid:1223696) [attach] - receive notification: registNotification [ 'ccls', '$ccls/publishSemanticHighlight' ]
2021-06-10T10:39:13.015 INFO (pid:1223696) [attach] - receive notification: registNotification [ 'ccls', '$ccls/publishSkippedRanges' ]
2021-06-10T10:39:13.306 INFO (pid:1223696) [services] - Pyright Server state change: starting => running
2021-06-10T10:39:13.314 INFO (pid:1223696) [services] - service pyright started
2021-06-10T10:39:13.645 INFO (pid:1223696) [attach] - receive notification: rename []
2021-06-10T10:39:14.996 INFO (pid:1223696) [attach] - receive notification: highlight []
2021-06-10T10:39:20.918 INFO (pid:1223696) [attach] - receive notification: showInfo []

@fannheyward
Copy link
Owner

fannheyward commented Jun 10, 2021

Try minimal vimrc, with coc/coc-pyright only.

@dsirov
Copy link
Author

dsirov commented Jun 10, 2021

Issue description updated with minimal configuration

@fannheyward
Copy link
Owner

  1. Set "pyright.trace.server": "verbose" in your coc-settings.json and restart your nvim
  2. do your rename steps
  3. :CocCommand workspace.showOutput Pyright
  4. search textDocument/rename in logs, what's the output?

@dsirov
Copy link
Author

dsirov commented Jun 10, 2021

Excerpt (full file: pyright.log)

Trace - 1:40:48 PM] Sending request 'textDocument/rename - (1)'.
Params: {
    "textDocument": {
        "uri": "file:///tmp/test.py"
    },
    "position": {
        "line": 3,
        "character": 4
    },
    "newName": "test2"
}
                           
                           
[Trace - 1:40:48 PM] Received response 'textDocument/rename - (1)' in 9ms.
No result returned.

@dsirov
Copy link
Author

dsirov commented Jun 10, 2021

OK, reduced this further.

The problem appears if the file, for example, is opened from another sub-root directory:
Rename will fail here:

cd ~/
nvim /tmp/test/test.py

But wiill work if:

cd ~/tmp/test
nvim test.py

Also will work if:

cd ~/tmp
nvim test/test.py

However, there is something else as there are cases when this does not work even when opened from the same directory. Trying to figure this out...

@yaegassy
Copy link
Contributor

yaegassy commented Jun 10, 2021

@dsirov If pyright cannot detect the "project root" correctly, it may not work as you expect.

Try this. https://github.com/neoclide/coc.nvim/wiki/Using-workspaceFolders#resolve-workspace-folder

e.g:

autocmd FileType python let b:coc_root_patterns = ['.git', '.env', 'venv', '.venv', 'setup.cfg', 'setup.py', 'pyproject.toml', 'pyrightconfig.json']

Related issue:

@fannheyward
Copy link
Owner

Thank you @yaegassy, I just put this on README 272dbb6

@dsirov dsirov changed the title Rename does not work Rename in file from another path does not work Jun 10, 2021
@fannheyward
Copy link
Owner

There was an error in rootPatterns that won't work, fixed in 03b6703#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519R71

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

3 participants