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

Highlight definition can be slow and blocks cursor movement #151

Closed
theHamsta opened this issue Jul 6, 2020 · 8 comments
Closed

Highlight definition can be slow and blocks cursor movement #151

theHamsta opened this issue Jul 6, 2020 · 8 comments
Labels
bug Something isn't working

Comments

@theHamsta
Copy link
Member

theHamsta commented Jul 6, 2020

Describe the bug
highlight_definitions can be really slow if it does not find the definition in current scope but in one of the parent levels.
This can be annoying since it blocks cursor movement while it is running.

To Reproduce
Open a big Python or C++ file with a lot of variable definitions (like this one https://i10git.cs.fau.de/pycodegen/pystencils/-/raw/master/pystencils/field.py)

Try to move over the individual letters of @staticmethod. It will not find a definition but quite a few usages. Cursor movement is blocked during the search of the definitions.

Expected behavior
Cursor movement is smooth. Search for definitions is non-blocking

** Output of :checkhealth nvim_treesitter **

```

health#nvim_treesitter#check

Installation

  • OK: git executable found.
  • OK: cc executable found.

html parser healthcheck

typescript parser healthcheck

  • OK: typescript parser found.
  • OK: locals.scm found.
  • OK: highlights.scm found.

clojure parser healthcheck

lisp parser healthcheck

regex parser healthcheck

c parser healthcheck

  • OK: c parser found.
  • OK: locals.scm found.
  • OK: highlights.scm found.

nix parser healthcheck

swift parser healthcheck

java parser healthcheck

  • OK: java parser found.
  • OK: locals.scm found.
  • OK: highlights.scm found.

python parser healthcheck

  • OK: python parser found.
  • OK: locals.scm found.
  • OK: highlights.scm found.

yaml parser healthcheck

elm parser healthcheck

vue parser healthcheck

cpp parser healthcheck

  • OK: cpp parser found.
  • OK: locals.scm found.
  • OK: highlights.scm found.

toml parser healthcheck

lua parser healthcheck

  • OK: lua parser found.
  • OK: locals.scm found.
  • OK: highlights.scm found.

ruby parser healthcheck

  • OK: ruby parser found.
  • OK: locals.scm found.
  • OK: highlights.scm found.

ocaml parser healthcheck

go parser healthcheck

  • OK: go parser found.
  • OK: locals.scm found.
  • OK: highlights.scm found.

scala parser healthcheck

haskell parser healthcheck

rust parser healthcheck

json parser healthcheck

markdown parser healthcheck

javascript parser healthcheck

  • OK: javascript parser found.
  • OK: locals.scm found.
  • OK: highlights.scm found.

css parser healthcheck

julia parser healthcheck

php parser healthcheck

c_sharp parser healthcheck

bash parser healthcheck

tsx parser healthcheck

  • OK: tsx parser found.
  • OK: locals.scm found.
  • OK: highlights.scm found.

Output of nvim --version

➜ nvim --version
NVIM v0.5.0-bd5f0e969
Build type: Release
LuaJIT 2.0.5
Compilation: /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/shims/linux/super/gcc-10 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNDEBUG -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/tmp/neovim-20200704-130349-1xlbcrp/build/config -I/tmp/neovim-20200704-130349-1xlbcrp/src -I/home/linuxbrew/.linuxbrew/include -I/tmp/neovim-20200704-130349-1xlbcrp/deps-build/include -I/usr/include -I/tmp/neovim-20200704-130349-1xlbcrp/build/src/nvim/auto -I/tmp/neovim-20200704-130349-1xlbcrp/build/include
Compiled by stephan@stephan-Z87-DS3H

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

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "
/home/linuxbrew/.linuxbrew/Cellar/neovim/HEAD-bd5f0e9_1/share/nvim"

Run :checkhealth for more info

Additional context
Add any other context about the problem here.

@theHamsta theHamsta added the bug Something isn't working label Jul 6, 2020
@vigoux
Copy link
Member

vigoux commented Jul 6, 2020

Oh we can move that as an async method, to avoid blocking, maybe...
It will need to be cancellable though

@steelsojka
Copy link
Contributor

@vigoux What's the nvim/lua api for making this async? I can take a look at this.

@vigoux
Copy link
Member

vigoux commented Jul 7, 2020

@steelsojka, I never used it personnally, but I think that the help page is located at :h lua-loop.

@theHamsta
Copy link
Member Author

I think we just wait for lua support for jobs. There is a PR for it in Neovim. I think it was called vim_wrap or something like that. Can give you hints tomorrow.

You would start the async job with a counter and only perform the highlighting when its finished when the counter was not incremented in the mean time. This is easier to implement that directly using vim.loop.

@steelsojka
Copy link
Contributor

Most of the performance issue is coming from checking if the node is a reference when recursing over the tree.

  M.recurse_tree(scope_node, function(iter_node, _, next)
    if vim.tbl_contains(references, iter_node) and M.get_node_text(iter_node)[1] == node_text then
      table.insert(usages, iter_node)
    end
    next()
  end)

I'll find a better way to check if it's a reference

@steelsojka
Copy link
Contributor

I'll also make it async as well 👍

@steelsojka
Copy link
Contributor

#154 This fixes a lot of the slowness when I was testing. I will explore making the api async as well, but this is probably a good solution for now.

@vigoux
Copy link
Member

vigoux commented Jul 8, 2020

Is the issue still happening with latest master? If not, we will close this.

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

No branches or pull requests

3 participants