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: arguments in Callable not highlighted as types #6203

Open
MithicSpirit opened this issue Feb 27, 2024 · 3 comments
Open

python: arguments in Callable not highlighted as types #6203

MithicSpirit opened this issue Feb 27, 2024 · 3 comments
Assignees
Labels
highlights Issues or PRs about highlighting queries

Comments

@MithicSpirit
Copy link

MithicSpirit commented Feb 27, 2024

Describe the highlighting problem

In python, the arguments in a Callable are highlighted as variables/constants rather than as types.

Example snippet that causes the problem

f: Callable[[t], u]

Tree-sitter parsing result

(expression_statement) ; [1:1 - 19]
 (assignment) ; [1:1 - 19]
  left: (identifier) ; [1:1 - 1]
  type: (type) ; [1:4 - 19]
   (generic_type) ; [1:4 - 19]
    (identifier) ; [1:4 - 11]
    (type_parameter) ; [1:12 - 19]
     (type) ; [1:13 - 15]
      (list) ; [1:13 - 15]
       (identifier) ; [1:14 - 14]
     (type) ; [1:18 - 18]
      (identifier) ; [1:18 - 18]

Example screenshot

Using the catppuccin colorscheme. :Inspect was called with the cursor on the t.
image

Expected behavior

The t should be a @type, but it is a @variable instead. If it is changed to T, then it is both a @variable and a @constant. Note that the u is correctly identified as an @type. I suspect that the issue is the type node does not "propagate into" the list node for syntax highlighting.

Output of :checkhealth nvim-treesitter

==============================================================================
nvim-treesitter: require("nvim-treesitter.health").check()

Installation ~
- OK `tree-sitter` found 0.21.0 (1c55abb5308fe3891da545662e5df7ba28ade275) (parser generator, only needed for :TSInstallFromGrammar)
- OK `node` found v18.18.2 (only needed for :TSInstallFromGrammar)
- OK `git` executable found.
- OK `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
  Version: cc (GCC) 13.2.1 20230801
- OK Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI.

OS Info:
{
  machine = "x86_64",
  release = "6.7.6-2-cachyos-lto",
  sysname = "Linux",
  version = "#1 SMP PREEMPT_DYNAMIC Sat, 24 Feb 2024 08:43:40 +0000"
} ~

Parser/Features         H L F I J
  - agda                ✓ . ✓ . .
  - awk                 ✓ . . . ✓
  - bash                ✓ ✓ ✓ . ✓
  - c                   ✓ ✓ ✓ ✓ ✓
  - commonlisp          ✓ ✓ ✓ . .
  - cpp                 ✓ ✓ ✓ ✓ ✓
  - css                 ✓ . ✓ ✓ ✓
  - diff                ✓ . . . .
  - dot                 ✓ . . . ✓
  - fennel              ✓ ✓ ✓ . ✓
  - git_config          ✓ . ✓ . ✓
  - git_rebase          ✓ . . . ✓
  - gitcommit           ✓ . . . ✓
  - gitignore           ✓ . . . .
  - go                  ✓ ✓ ✓ ✓ ✓
  - groovy              ✓ ✓ ✓ ✓ ✓
  - haskell             ✓ . ✓ . ✓
  - html                ✓ ✓ ✓ ✓ ✓
  - ini                 ✓ . ✓ . .
  - java                ✓ ✓ ✓ ✓ ✓
  - javascript          ✓ ✓ ✓ ✓ ✓
  - json                ✓ ✓ ✓ ✓ .
  - jsonc               ✓ ✓ ✓ ✓ ✓
  - latex               ✓ . ✓ . ✓
  - lua                 ✓ ✓ ✓ ✓ ✓
  - make                ✓ . ✓ . ✓
  - markdown            ✓ . ✓ ✓ ✓
  - markdown_inline     ✓ . . . ✓
  - meson               ✓ . ✓ ✓ ✓
  - org                 . . . . .
  - passwd              ✓ . . . .
  - perl                ✓ . ✓ . ✓
  - properties          ✓ ✓ . . ✓
  - proto               ✓ . ✓ . .
  - python              ✓ ✓ ✓ ✓ ✓
  - query               ✓ ✓ ✓ ✓ ✓
  - rust                ✓ ✓ ✓ ✓ ✓
  - scss                ✓ . ✓ ✓ .
  - strace              ✓ . . . ✓
  - toml                ✓ ✓ ✓ ✓ ✓
  - vim                 ✓ ✓ ✓ . ✓
  - vimdoc              ✓ . . . ✓
  - yaml                ✓ ✓ ✓ ✓ ✓
  - zig                 ✓ ✓ ✓ ✓ ✓

  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.9.5
Build type: Release
LuaJIT 2.1.1702233742

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

Run :checkhealth for more info

Additional context

Also reported (erroneously) at tree-sitter/tree-sitter-python#258.

@MithicSpirit MithicSpirit added the highlights Issues or PRs about highlighting queries label Feb 27, 2024
@lucario387
Copy link
Member

Don't think this can be handled gracefully without bloating up the parser/slowing down parsing (#has-ancestor? shenanigan)

@MithicSpirit
Copy link
Author

Don't think this can be handled gracefully without bloating up the parser/slowing down parsing (#has-ancestor? shenanigan)

Been thinking about this. I'm not too familiar with treesitter queries, but maybe it could only look up a few nodes rather than all the way up the tree? If it only has to look back one or two nodes, I don't think that it'll have as significant a performance impact. No clue whether there's a query for this, though.

@clason
Copy link
Contributor

clason commented Mar 17, 2024

There is one for direct parents, but that's it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
highlights Issues or PRs about highlighting queries
Projects
None yet
Development

No branches or pull requests

4 participants