Giter Club home page Giter Club logo

cmp-treesitter's Introduction

cmp-treesitter

nvim-cmp source for treesitter nodes. Using all treesitter highlight nodes as completion candicates. LRU cache is used to improve performance.

Setup

require'cmp'.setup {
  sources = {
    { name = 'treesitter' }
  }
}

Screenshot

treesitter_cmp

Screen Shot 2021-10-24 at 1 00 29 pm

cmp-treesitter's People

Contributors

3rd avatar amarakon avatar delphinus avatar imcaizheng avatar ray-x avatar uga-rosa avatar zeroknight avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cmp-treesitter's Issues

Poor performance

Using treesitter completions with this plugins makes the whole insert mode quite laggy. Can anything be done about that or is it unavoidable?

bad argument #1 to ipairs

Hi,
I keep getting this error:

E5108: Error executing lua .../packer/start/cmp-treesitter/lua/cmp_treesitter/init.lua:51: bad argument #1 to 'ipairs' (table expected, got nil)```

Thank you for looking into it.
Regards,
Omar

how to use highlight groups?

i want to set the highlight groups in cmp but im not getting how to, i tried
vim.api.nvim_set_hl(0, "CmpItemKindVariable", { fg = "green", bg = "NONE" })
but it is not applying to treesitter variable, it applied to lsp variable idk why
image
image
image
image
image

Examples?

Maybe add examples on how this is useful. Between all the sources that cmp can have, I can't legitimately tell what this does for me. I love both cmp and treesitter, so I'd love to see if I get benefit from this.

Strange error causing massive performance degradation

stack traceback:
        ...rapped-bad218c/share/nvim/runtime/lua/vim/treesitter.lua:28: in function '__index'                                            
        ...s/start/cmp-treesitter/lua/cmp_treesitter/treesitter.lua:43: in function <...s/start/cmp-treesitter/lua/cmp_treesitter/treesitter.lua:31
>

This appears briefly upon typing in insert mode and typing... I'm not sure how to get more context for what's happening here.

Error executing vim.schedule lua callback: vim/shared.lua:0: after the second argument: expected table, got nil

I occasionally will get this error. I've not really found it to be reproducible though:

Error executing vim.schedule lua callback: vim/shared.lua:0: after the second argument: expected table, got nil
stack traceback:
        [C]: in function 'error'
        vim/shared.lua: in function 'validate'
        vim/shared.lua: in function 'tbl_deep_extend'
        .../packer/start/cmp-treesitter/lua/cmp_treesitter/init.lua:19: in function 'get_keyword_pattern'
        .../nvim/site/pack/packer/start/nvim-cmp/lua/cmp/source.lua:163: in function 'callback'
        .../site/pack/packer/start/nvim-cmp/lua/cmp/utils/cache.lua:36: in function 'get_default_replace_range'
        ...e/nvim/site/pack/packer/start/nvim-cmp/lua/cmp/entry.lua:45: in function 'new'
        .../nvim/site/pack/packer/start/nvim-cmp/lua/cmp/source.lua:316: in function ''
        vim.lua: in function <vim.lua:0>

Maybe it makes sense to you?

Broken completions with quotes and comments

Hi there!

I'm experiencing some strange issue with cmp-treesitter with [quotes] autopairing:

  1. when I trying to complete some substring inside quotes (and it finds corresponding node for completion, and it is also inside quotes), cmp-treesitter suggest that quoted node as completion (dunno why TS doesn't cut quotes when collecting nodes ๐Ÿคท).
    This causes situation that completed string have two closing quotes (which causes syntax errors).

This is demonstration:

asciicast

Is it possible to maybe somehow ask cmp-treesitter to cut quotes before passing node to cmp?
Or, maybe, it is possible to somehow ask cmp (or cmp-treesitter?) to take closing quote into account (like it does with middle-word/fuzzy completions)?

  1. something similar happens when I trying to comple some "common" comments (like luacheck (linter) directives).

a. I start comment block
b. I type lua as start of word-to-be-completed
c. I see -- luacheck: ... as treesitter completion
d. I select it and I see it inserted one more -- (so there is double commented string, which, by the way, doesn't count as valid luacheck directive).

Here is a demonstration:

asciicast

So, it seems, in that situation it doesn't even count "left" part of completeion...

Can that things be fixed?

Or it is all on cmp itself behalf, and cmp-treesitter have nothing to do here?

Example Rust and collaboration with https://github.com/nvim-treesitter

async fn run(options: Opt) -> Result<()> {
    let (certs, key) = if let (Some(key_path), Some(cert_path)) = (&options.key, &options.cert) {
      key_log
        let key = fs::read(key_path).context("failed to read private key")?;
        let key = if key_path.extension().map_or(false, |x| x == "der") {
            rustls::PrivateKey(key)
        } else {
            let pkcs8 = rustls_pemfile::pkcs8_private_keys(&mut &*key)
                .context("malformed PKCS #8 private key")?;

is sample Rust code from quinn (server.rs in examples).

You see that Some(key_path) defines a var you want to complete.

That Some(key_path) get's understood as identifier (See HERE)

    let_declaration [62, 4] - [121, 6]
      pattern: tuple_pattern [62, 8] - [62, 20]
        identifier [62, 9] - [62, 14]
        identifier [62, 16] - [62, 19]
      value: if_expression [62, 23] - [121, 5]
        condition: let_condition [62, 26] - [62, 95]
          pattern: tuple_pattern [62, 30] - [62, 63]
            tuple_struct_pattern [62, 31] - [62, 45]
              type: identifier [62, 31] - [62, 35] << HERE
              identifier [62, 36] - [62, 44]
            tuple_struct_pattern [62, 47] - [62, 62]
              type: identifier [62, 47] - [62, 51]
              identifier [62, 52] - [62, 61]

Not all identifiers are declarations.

https://github.com/ms-jpq/coq_nvim also has a treesitter based completion implementation. So there might be yet another trace for joint efforts ?

What I am exactly interested in is

  1. preserve order (above cursor, closest first) because I am most likely to be using them again and it means least typing effort
    You seem to have implemented caching, and tell that treesitter is slow. The playground indicated might be fast ?

I have uploaded my code here so that you get a feeling how it behaves and how much it saves.
https://github.com/MarcWeber/nvim-cmp-local-identifiers-by-regex-completion-quick-and-dirty

Font used in screenshots?

Could you please share what font is being used in the screenshots, especially for those gorgeous italics?

Error when opening non-ascii filenames

Error detected while processing /home/llyyr/.local/share/nvim/site/pack/packer/start/cmp-treesitter/after/plugin/cmp_treesitter.lua:
E5113: Error while calling lua chunk: /usr/share/nvim/runtime/lua/vim/uri.lua:43: attempt to call upvalue 'tohex' (a nil value)
stack traceback:
        /usr/share/nvim/runtime/lua/vim/uri.lua:43: in function </usr/share/nvim/runtime/lua/vim/uri.lua:42>
        [C]: in function 'uri_encode'
        /usr/share/nvim/runtime/lua/vim/uri.lua:67: in function 'uri_from_fname'
        ...r/start/cmp-treesitter/lua/cmp_treesitter/treesitter.lua:7: in function <...r/start/cmp-treesitter/lua/cmp_treesitter/treesitter.lua:5>
        [C]: in function 'require'
        .../packer/start/cmp-treesitter/lua/cmp_treesitter/init.lua:1: in main chunk
        [C]: in function 'require'
        ...ker/start/cmp-treesitter/after/plugin/cmp_treesitter.lua:1: in main chunk

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.