fannheyward / coc-pyright

Pyright extension for coc.nvim
MIT License
1.28k stars 47 forks source link

Syntax highlighting doesn't go away when problem fixed #659

Closed Paul-Aime closed 2 years ago

Paul-Aime commented 2 years ago

Parts of the code where there is a problem to be fixed are underlined, and variables that are unused are shadowed. This goes away when the problem is fixed, but NOT if there is still other problems to be fixed in the file.

For example, let's take the following file with 2 problems:

import os           # [Pyright] [H] "os" is not accessed
a = "foo"
b = 2
c = a + b           # [Pyright reportGeneralTypeIssues] [E] ...

The os variable is shadowed, and a+b is underlined.

If I fix the error [E] by modifying b = 2 into b = "bar", then the error [E] goes away but a + b is style underlined.

Highlighting becomes OK only if I also fix the [H] problem, or if I reload the file.

Any idea on what's wrong here ?

I also noticed that if only fixing the [E] and writing (:w), then reloading (:e) will correctly remove the underlined a + b, but undoing (u) will redo the underlining of a + b (and not any other modificaition).

Edit: Screenshots:

There is 2 problems One problem fixed, but underlining remains All problems fixed, underlining goes away
pyright-highligth-bug-01 pyright-highligth-bug-02 pyright-highligth-bug-03

What's the output of :CocCommand pyright.version

[coc.nvim] coc-pyright 1.1.181 with Pyright 1.1.184

What's the output of :CocCommand workspace.showOutput Pyright

Workspace: /home/p20aime
Using python from /home/p20aime/miniconda3/bin/python

[Warn  - 9:08:12 AM] Ignored rootPath /home/p20aime of client "pyright"
[Info  - 9:08:12 AM] Pyright language server 1.1.184 starting
[Info  - 9:08:12 AM] Server root directory: /home/p20aime/.config/coc/extensions/node_modules/coc-pyright/node_modules/pyright/dist/
[Info  - 9:08:12 AM] No pyproject.toml file found.
[Info  - 9:08:12 AM] Setting pythonPath for service "<default>": "/home/p20aime/miniconda3/bin/python"
[Warn  - 9:08:12 AM] stubPath typings is not a valid directory.
[Info  - 9:08:12 AM] Assuming Python version 3.9
[Info  - 9:08:12 AM] Assuming Python platform Linux
[Warn  - 9:08:12 AM] Exception received when installing file system watcher: TypeError [ERR_FEATURE_UNAVAILABLE_ON_PLATFORM]: The feature watch recursively is unavailable on the current platform, which is being used to run Node.js
[Warn  - 9:08:12 AM] Exception received when installing file system watcher: TypeError [ERR_FEATURE_UNAVAILABLE_ON_PLATFORM]: The feature watch recursively is unavailable on the current platform, which is being used to run Node.js
[Warn  - 9:08:12 AM] Exception received when installing file system watcher: TypeError [ERR_FEATURE_UNAVAILABLE_ON_PLATFORM]: The feature watch recursively is unavailable on the current platform, which is being used to run Node.js
[Warn  - 9:08:12 AM] Exception received when installing file system watcher: TypeError [ERR_FEATURE_UNAVAILABLE_ON_PLATFORM]: The feature watch recursively is unavailable on the current platform, which is being used to run Node.js
[Info  - 9:08:12 AM] Searching for source files
[Info  - 9:08:12 AM] No source files found.
fannheyward commented 2 years ago

Can't reproduce.

Workspace: /home/p20aime

Try this in a folder, not $HOME, this will make Pyright to scan the whole $HOME to analyze.

Paul-Aime commented 2 years ago

I tried in a custom folder and it is the same. The issue doesn't seem to be related to the analyze, since the problem is recognized as fixed but only the underline remains.

I don't know if it is particular to my installation, I tried with no other plugins than coc and it is the same:

Plug 'neoclide/coc.nvim', {'branch': 'release'}
let g:coc_global_extensions = ['coc-pyright', 'coc-json']

Is there a way do deactivate the underline / shadowing ... as a quick fix?

fannheyward commented 2 years ago
截屏2021-11-08 下午9 32 41 截屏2021-11-08 下午9 33 03

Your installation is OK, but I still can't reproduce this.

fannheyward commented 2 years ago

My tests:

  1. mkdir /tmp/test
  2. cd /tmp/test
  3. python3 -m venv .venv
  4. source .venv/bin/activate
  5. touch bug.py and vim open it
  6. input the test code
Paul-Aime commented 2 years ago

I can reproduce it on a second machine with same installation. I can't reproduce it on a third machine (Android tablet with termux), where there is no underlining for some reason, but when I fix the unused import problem (and not the type error), then the shadowing correctly goes away, although it sometimes goes away for all unused variables, even if still unused (see screenshots).

No underlining fixing unused os, but re highlighting also goes away retyping line 6, re shadowed again
termux_01 termux_02 termux_03
yaegassy commented 2 years ago

@Paul-Aime What colorscheme are you using? Does the same problem recur if you change the colorscheme? If you are using nvim-treesitter, please try disabling nvim-treesitter as well.

Paul-Aime commented 2 years ago

@yaegassy I am using morhetz/gruvbox as a plugin, but it seems to have nothing to do with the issue, since if my .vimrc is strictly reduced to the following, the issue persists:

call plug#begin('~/.vim/plugged')
Plug 'neoclide/coc.nvim', {'branch': 'release'}
let g:coc_global_extensions = ['coc-pyright', 'coc-json']
call plug#end()

image

yaegassy commented 2 years ago

@Paul-Aime I've tried it in my environment, but I can't reproduce the problem. I tried it with both Vim8 and Neovim. :(

fannheyward commented 2 years ago

@yaegassy thank you for your tests. @Paul-Aime what's the output of :CocList extensions and CocList services?

Paul-Aime commented 2 years ago

I use vim-gtk3 (Ubuntu focal repo). I updated coc-pyright but still have the same issue.

:CocCommand pyright.version
[coc.nvim] coc-pyright 1.1.185 with Pyright 1.1.186
:CocList extensions
  * coc-pyright 1.1.185 ~/.config/coc/extensions/node_modules/coc-pyright
  + coc-json 1.3.6 ~/.config/coc/extensions/node_modules/coc-json
:CocList services
  * pyright [running] python
fannheyward commented 2 years ago

What's your vim version?

Paul-Aime commented 2 years ago
$ vim --version
VIM - Vi IMproved 8.1 (2018 May 18, compiled Sep 20 2021 11:42:42)
Included patches: 1-2269
Modified by team+vim@tracker.debian.org
Compiled by team+vim@tracker.debian.org
Huge version with GTK3 GUI.  Features included (+) or not (-):
+acl               -farsi             -mouse_sysmouse    -tag_any_white
+arabic            +file_in_path      +mouse_urxvt       +tcl
+autocmd           +find_in_path      +mouse_xterm       +termguicolors
+autochdir         +float             +multi_byte        +terminal
-autoservername    +folding           +multi_lang        +terminfo
+balloon_eval      -footer            -mzscheme          +termresponse
+balloon_eval_term +fork()            +netbeans_intg     +textobjects
+browse            +gettext           +num64             +textprop
++builtin_terms    -hangul_input      +packages          +timers
+byte_offset       +iconv             +path_extra        +title
+channel           +insert_expand     +perl              +toolbar
+cindent           +job               +persistent_undo   +user_commands
+clientserver      +jumplist          +postscript        +vartabs
+clipboard         +keymap            +printer           +vertsplit
+cmdline_compl     +lambda            +profile           +virtualedit
+cmdline_hist      +langmap           -python            +visual
+cmdline_info      +libcall           +python3           +visualextra
+comments          +linebreak         +quickfix          +viminfo
+conceal           +lispindent        +reltime           +vreplace
+cryptv            +listcmds          +rightleft         +wildignore
+cscope            +localmap          -ruby              +wildmenu
+cursorbind        +lua               +scrollbind        +windows
+cursorshape       +menu              +signs             +writebackup
+dialog_con_gui    +mksession         +smartindent       +X11
+diff              +modify_fname      +sound             -xfontset
+digraphs          +mouse             +spell             +xim
+dnd               +mouseshape        +startuptime       +xpm
-ebcdic            +mouse_dec         +statusline        +xsmp_interact
+emacs_tags        +mouse_gpm         -sun_workshop      +xterm_clipboard
+eval              -mouse_jsbterm     +syntax            -xterm_save
+ex_extra          +mouse_netterm     +tag_binary        
+extra_search      +mouse_sgr         -tag_old_static    
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK  -pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/fribidi -I/usr/include/harfbuzz -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -Wdate-time  -g -O2 -fdebug-prefix-map=/build/vim-RjZCd2/vim-8.1.2269=. -fstack-protector-strong -Wformat -Werror=format-security -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1       
Linking: gcc   -Wl,-E  -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -o vim   -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE  -lm -ltinfo -lnsl  -lselinux  -lcanberra -lacl -lattr -lgpm -ldl  -L/usr/lib -llua5.2 -Wl,-E  -fstack-protector-strong -L/usr/local/lib  -L/usr/lib/x86_64-linux-gnu/perl/5.30/CORE -lperl -ldl -lm -lpthread -lcrypt  -L/usr/lib/python3.8/config-3.8-x86_64-linux-gnu -lpython3.8 -lcrypt -lpthread -ldl -lutil -lm -lm -L/usr/lib/x86_64-linux-gnu -ltcl8.6 -ldl -lz -lpthread -lm     
fannheyward commented 2 years ago

I've tested with Vim 8.2, can't reproduce.

Paul-Aime commented 2 years ago

So I removed all vim installations and installed vim 8.2 from ppa:jonathonf/vim and there is no issue anymore