nvim-treesitter / completion-treesitter

Treesitter source for completion-nvim and more
161 stars 5 forks source link

How to add support for new parsers #3

Closed pwntester closed 4 years ago

pwntester commented 4 years ago

Im trying to add support for https://github.com/tree-sitter/tree-sitter-ql

so far added a ql.vim file to after/ftplugin with:

" This query Extracts context definitions (like functions, of for example, Rust bracketed contexts)
let b:completion_context_query = ['classlessPredicate', 'class', 'exists', 'predicate']

" This is the name of an identifier node (as shown in treesitter playground), it will be used
let b:completion_ident_type_name = "simpleId"

" This is the query that will be used to search for the definition of
" a given identifier, it is mandatory to have an @def in it to tag the identifier of the declaration.
" The other @-tag will be used to name the completion item during completion
let b:completion_def_query = ['(varDecl varName: (simpleId) @def @v)']

Im not really familiar with tree-sitter, but looking at tree-sitter web-ui, it seems correct to me:

image

BTW, how can I run the query on the query window?

Thanks!

pwntester commented 4 years ago

Im getting this error:

Error executing vim.schedule lua callback: ...m/HEAD-05fd647/share/nvim/runtime/lua/vim/treesitter.lua:128: query: invalid field at position 10

Where query is ((varDecl varName: (simpleId) @def @v) @declaration), so it seems there is a problem with varName field. According to parser grammar, varName is a SYMBOL:

    "varDecl": {
      "type": "SEQ",
      "members": [
        {
          "type": "SYMBOL",
          "name": "typeExpr"
        },
        {
          "type": "SYMBOL",
          "name": "varName"
        }
      ]
    },

I rewrote the query as ((varDecl (simpleId) @def @v) @declaration) and Im not getting the error anymore, but I dont get the var declaration highlighted neither

pwntester commented 4 years ago

finally got it working, the problem was sillier than that, I was not adding ql file type to the CursorHold autocommand in completion-treesitter.vim