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

Python: base type inside a multi level type square bracket is detected as variable #1899

Open
3 tasks done
Terseus opened this issue Oct 2, 2021 · 0 comments
Open
3 tasks done
Labels
bug Something isn't working

Comments

@Terseus
Copy link

Terseus commented Oct 2, 2021

Before reporting

  • I have updated my neovim version to latest master
  • I have updated my plugin to the latest version
  • I have run :TSUpdate

Describe the bug

Any base type (str, int, etc) used inside a multi-level type declaration is detected as a variable, not as a type.

To Reproduce

Given the following code snippet:

from typing import Sequence, Dict, Any


def test(
    param_1: Dict[str, Any],
    param_2: Sequence[int],
    param_3: Sequence[Dict[str, Any]],
    param_4: Sequence[Sequence[Sequence[int]]]
):
    pass

The str at param_1 and int at param_2 are highlighted as types, but the str at param_3 and int at param_4 aren't.

Expected behavior

I would expect all the occurrences of a base type inside a type definition to have the same highlight group.

Output of :checkhealth nvim_treesitter

health#nvim_treesitter#check
========================================================================
## Installation
  - WARNING: `tree-sitter` executable not found (parser generator, only needed for :TSInstallFromGrammar, not required for :TSInstall)
  - OK: `node` found v16.10.0 (only needed for :TSInstallFromGrammar)
  - OK: `git` executable found.
  - OK: `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl" }
  - OK: Neovim was compiled with tree-sitter runtime ABI version 13 (required >=13). Parsers must be compatible with runtime ABI.

## Parser/Features H L F I J
  - c              ✓ ✓ ✓ ✓ ✓ 
  - cpp            ✓ ✓ ✓ ✓ ✓ 
  - javascript     ✓ ✓ ✓ ✓ ✓ 
  - lua            ✓ ✓ ✓ ✓ ✓ 
  - css            ✓ . ✓ ✓ ✓ 
  - dockerfile     ✓ . . . ✓ 
  - yaml           ✓ ✓ ✓ ✓ ✓ 
  - fish           ✓ ✓ ✓ ✓ ✓ 
  - comment        ✓ . . . . 
  - jsonc          ✓ ✓ ✓ ✓ ✓ 
  - rst            ✓ ✓ . . ✓ 
  - html           ✓ ✓ ✓ ✓ ✓ 
  - python         ✓ ✓ ✓ ✓ ✓ 
  - php            ✓ ✓ ✓ ✓ ✓ 
  - json           ✓ ✓ ✓ ✓ . 
  - java           ✓ ✓ . ✓ ✓ 
  - typescript     ✓ ✓ ✓ ✓ ✓ 
  - rust           ✓ ✓ ✓ ✓ ✓ 
  - bash           ✓ ✓ ✓ . ✓ 
  - toml           ✓ ✓ ✓ ✓ ✓ 
  - vim            ✓ ✓ . . ✓ 
  - go             ✓ ✓ ✓ ✓ ✓ 

 Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
         +) multiple parsers found, only one will be used
         x) errors found in the query, try to run :TSUpdate {lang}

Output of nvim --version

NVIM v0.6.0-dev+84-gac5139eae
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/gcc-11 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/home/runner/work/neovim/neovim/build/config -I/home/runner/work/neovim/neovim/src -I/home/runner/work/neovim/neovim/.deps/usr/include -I/usr/include -I/home/runner/work/neovim/neovim/build/src/nvim/auto -I/home/runner/work/neovim/neovim/build/include
Compilado por runner@fv-az68-473

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

     archivo "vimrc" del sistema: "$VIM/sysinit.vim"
            predefinido para $VIM: "/share/nvim"

Run :checkhealth for more info

Additional context

Using the :TSHighlightCapturesUnderCursor command I got:

  • In the str from param_1:
# Treesitter

* **@variable** -> pythonTSVariable -> **TSVariable**
* **@type** -> pythonTSType -> **TSType**
  • In the str from param_2 the same:
# Treesitter

* **@variable** -> pythonTSVariable -> **TSVariable**
* **@type** -> pythonTSType -> **TSType**
  • However in the str from param_3 we see it's missing @type:
# Treesitter

* **@variable** -> pythonTSVariable -> **TSVariable**
  • Same result in the str from param_4:
# Treesitter

* **@variable** -> pythonTSVariable -> **TSVariable**

This issue was originally created at tree-sitter/tree-sitter-python#110 and moved here as suggested by @stsewd

@Terseus Terseus added the bug Something isn't working label Oct 2, 2021
stsewd added a commit to stsewd/nvim-treesitter that referenced this issue Oct 13, 2021
Fixes nvim-treesitter#1899

Think this was considered slow? I'll test this change for a while and
check the performance (but probably I won't notice any change on my
computer)
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

Successfully merging a pull request may close this issue.

1 participant