From 37f9866f6685a3a62536f857348202b280e28dbe Mon Sep 17 00:00:00 2001 From: TravonteD Date: Sun, 7 Jun 2020 18:15:02 -0400 Subject: [PATCH 01/51] - #76 update the predicate syntax for ruby and css --- queries/css/highlights.scm | 4 ++-- queries/ruby/highlights.scm | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/queries/css/highlights.scm b/queries/css/highlights.scm index 3fc468ca3..72009e765 100644 --- a/queries/css/highlights.scm +++ b/queries/css/highlights.scm @@ -48,9 +48,9 @@ ((property_name) @type - (match? @type "^--")) + (#match? @type "^--")) ((plain_value) @type - (match? @type "^--")) + (#match? @type "^--")) (string_value) @string (color_value) @string diff --git a/queries/ruby/highlights.scm b/queries/ruby/highlights.scm index da4eac9b9..9e5852cdf 100644 --- a/queries/ruby/highlights.scm +++ b/queries/ruby/highlights.scm @@ -29,12 +29,12 @@ "yield" @keyword ((identifier) @keyword - (match? @keyword "^(private|protected|public)$")) + (#match? @keyword "^(private|protected|public)$")) ; Function calls ((identifier) @function - (eq? @function "require")) + (#eq? @function "require")) "defined?" @function @@ -67,10 +67,10 @@ (instance_variable) @label ((identifier) @constant.builtin - (match? @constant.builtin "^__(FILE|LINE|ENCODING)__$")) + (#match? @constant.builtin "^__(FILE|LINE|ENCODING)__$")) ((constant) @constant.macro - (match? @constant.macro "^[A-Z\\d_]+$")) + (#match? @constant.macro "^[A-Z\\d_]+$")) (constant) @constant @@ -87,8 +87,9 @@ (block_parameter (identifier) @parameter) (keyword_parameter (identifier) @parameter) -((identifier) @function - (is-not? local)) +; TODO: Re-enable this once it is supported +; ((identifier) @function +; (#is-not? local)) ; Literals From a06792450799f7cfe24cebac099cb47d640a2be3 Mon Sep 17 00:00:00 2001 From: Thomas Vigouroux <39092278+vigoux@users.noreply.github.com> Date: Sun, 14 Jun 2020 11:57:09 +0200 Subject: [PATCH 02/51] Update issue templates Add some issue templates --- .github/ISSUE_TEMPLATE/bug_report.md | 34 ++++++++++++++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 20 +++++++++++++ .github/ISSUE_TEMPLATE/language-request.md | 12 ++++++++ 3 files changed, 66 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/ISSUE_TEMPLATE/language-request.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 000000000..06596fe11 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,34 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: bug +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Output of `:checkhealth nvim_treesitter` *** +``` +Paste the output here +``` + +**Output of `nvim --version`** +``` +Paste your output here +``` + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 000000000..11fc491ef --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: enhancement +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/ISSUE_TEMPLATE/language-request.md b/.github/ISSUE_TEMPLATE/language-request.md new file mode 100644 index 000000000..b10287ea6 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/language-request.md @@ -0,0 +1,12 @@ +--- +name: Language request +about: Request for a new language to be supported +title: '' +labels: enhancement, good first issue, help wanted +assignees: '' + +--- + +**Language informations** + +Please paste any useful informations here ! From 44108fe03e5c2cb761090c4abf8e7164225bf62f Mon Sep 17 00:00:00 2001 From: Steven Sojka Date: Fri, 12 Jun 2020 14:11:37 -0500 Subject: [PATCH 03/51] feat(queries): allow for user overrides --- README.md | 7 +++++++ lua/nvim-treesitter/query.lua | 15 +++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c31ce8985..c19874593 100644 --- a/README.md +++ b/README.md @@ -181,6 +181,13 @@ List of currently supported languages: - [ ] nix - [ ] markdown +## User Query Extensions + +You can add your own query files by placing a query file in vim's runtime path after `nvim-treesitter` is sourced. +If the language has a built in query file, that file will be appended to or it will be used (useful for languages not yet supported). +For example, you can add files to `/after/queries/lua/highlights.scm` to add more queries to lua highlights. +You can also manually add query paths to the runtime path by adding this to your vim config `set rtp+='path/to/queries'`. + ## Troubleshooting Before doing anything run `:checkhealth nvim_treesitter`. This will help you find where the bug might come from. diff --git a/lua/nvim-treesitter/query.lua b/lua/nvim-treesitter/query.lua index 644c33933..b914e5d7d 100644 --- a/lua/nvim-treesitter/query.lua +++ b/lua/nvim-treesitter/query.lua @@ -3,14 +3,21 @@ local ts = vim.treesitter local M = {} -local function read_query_file(fname) - return table.concat(vim.fn.readfile(fname), '\n') +local function read_query_files(filenames) + local contents = {} + + for _,filename in ipairs(filenames) do + vim.list_extend(contents, vim.fn.readfile(filename)) + end + + return table.concat(contents, '\n') end function M.get_query(ft, query_name) - local query_files = api.nvim_get_runtime_file(string.format('queries/%s/%s.scm', ft, query_name), false) + local query_files = api.nvim_get_runtime_file(string.format('queries/%s/%s.scm', ft, query_name), true) + if #query_files > 0 then - return ts.parse_query(ft, read_query_file(query_files[1])) + return ts.parse_query(ft, read_query_files(query_files)) end end From 45ea0df21a8494c7a8258bbb98ebd510716148e9 Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Mon, 1 Jun 2020 00:22:59 +0200 Subject: [PATCH 04/51] Add tree-sitter-regex This might be interesting for injected highlighting --- README.md | 1 + lua/nvim-treesitter/configs.lua | 7 +++++++ queries/regex/highlights.scm | 29 +++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 queries/regex/highlights.scm diff --git a/README.md b/README.md index c31ce8985..233487d7d 100644 --- a/README.md +++ b/README.md @@ -180,6 +180,7 @@ List of currently supported languages: - [ ] yaml - [ ] nix - [ ] markdown +- [x] regex (maintained by @theHamsta) ## Troubleshooting Before doing anything run `:checkhealth nvim_treesitter`. This will help you find where the bug might come from. diff --git a/lua/nvim-treesitter/configs.lua b/lua/nvim-treesitter/configs.lua index f79fed00c..f7b5ff2cf 100644 --- a/lua/nvim-treesitter/configs.lua +++ b/lua/nvim-treesitter/configs.lua @@ -203,6 +203,13 @@ parsers.nix = { } } +parsers.regex = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-regex", + files = { "src/parser.c" } + } +} + -- @enable can be true or false -- @disable is a list of languages, only relevant if enable is true -- @keymaps list of user mappings for a given module if relevant diff --git a/queries/regex/highlights.scm b/queries/regex/highlights.scm new file mode 100644 index 000000000..48242543f --- /dev/null +++ b/queries/regex/highlights.scm @@ -0,0 +1,29 @@ +;; Forked from tree-sitter-regex +;; The MIT License (MIT) Copyright (c) 2014 Max Brunsfeld +[ + "(" + ")" + "(?" + "(?:" + "(?<" + ">" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +(group_name) @property + +[ + (identity_escape) + (control_letter_escape) + (character_class_escape) + (control_escape) + (start_assertion) + (end_assertion) + (boundary_assertion) + (non_boundary_assertion) +] @escape + +[ "*" "+" "|" "=" "<=" "!" " Date: Fri, 12 Jun 2020 07:41:20 -0500 Subject: [PATCH 05/51] feat(queries): add typescript and javascript queries --- README.md | 4 +- queries/javascript/highlights.scm | 190 ++++++++++++++++++++++++++ queries/javascript/locals.scm | 35 +++++ queries/typescript/highlights.scm | 215 ++++++++++++++++++++++++++++++ queries/typescript/locals.scm | 37 +++++ 5 files changed, 479 insertions(+), 2 deletions(-) create mode 100644 queries/javascript/highlights.scm create mode 100644 queries/javascript/locals.scm create mode 100644 queries/typescript/highlights.scm create mode 100644 queries/typescript/locals.scm diff --git a/README.md b/README.md index c31ce8985..0401128b8 100644 --- a/README.md +++ b/README.md @@ -159,8 +159,8 @@ List of currently supported languages: - [ ] cpp - [ ] rust - [x] python (maintained by @theHamsta) -- [ ] javascript -- [ ] typescript +- [x] javascript (maintained by @steelsojka) +- [x] typescript (maintained by @steelsojka) - [ ] tsx - [ ] json - [x] html (maintained by @TravonteD) diff --git a/queries/javascript/highlights.scm b/queries/javascript/highlights.scm new file mode 100644 index 000000000..da88d85d0 --- /dev/null +++ b/queries/javascript/highlights.scm @@ -0,0 +1,190 @@ +; Types + +; Javascript +; Special identifiers +;-------------------- + +((identifier) @constant + (#match? @constant "^[A-Z_][A-Z\\d_]+$")) + +((shorthand_property_identifier) @constant + (#match? @constant "^[A-Z_][A-Z\\d_]+$")) + +((identifier) @constructor + (#match? @constructor "^[A-Z]")) + +((identifier) @variable.builtin + (#match? @variable.builtin "^(arguments|module|console|window|document)$")) + +((identifier) @function.builtin + (#eq? @function.builtin "require")) + +; Function and method definitions +;-------------------------------- + +(function + name: (identifier) @function) +(function_declaration + name: (identifier) @function) +(method_definition + name: (property_identifier) @function.method) + +(pair + key: (property_identifier) @function.method + value: (function)) +(pair + key: (property_identifier) @function.method + value: (arrow_function)) + +(assignment_expression + left: (member_expression + property: (property_identifier) @function.method) + right: (arrow_function)) +(assignment_expression + left: (member_expression + property: (property_identifier) @function.method) + right: (function)) + +(variable_declarator + name: (identifier) @function + value: (arrow_function)) +(variable_declarator + name: (identifier) @function + value: (function)) + +(assignment_expression + left: (identifier) @function + right: (arrow_function)) +(assignment_expression + left: (identifier) @function + right: (function)) + +; Function and method calls +;-------------------------- + +(call_expression + function: (identifier) @function) + +(call_expression + function: (member_expression + property: (property_identifier) @function.method)) + +; Variables +;---------- + +(formal_parameters (identifier) @variable.parameter) + +(identifier) @variable + +; Properties +;----------- + +(property_identifier) @property + +; Literals +;--------- + +(this) @variable.builtin +(super) @variable.builtin + +(true) @constant.builtin +(false) @constant.builtin +(null) @constant.builtin +(comment) @comment +(string) @string +(regex) @string.special +(template_string) @string +(number) @number + +; Punctuation +;------------ + +(template_substitution + "${" @punctuation.special + "}" @punctuation.special) @embedded + +";" @punctuation.delimiter +"." @punctuation.delimiter +"," @punctuation.delimiter + +"--" @operator +"-" @operator +"-=" @operator +"&&" @operator +"+" @operator +"++" @operator +"+=" @operator +"<" @operator +"<<" @operator +"=" @operator +"==" @operator +"===" @operator +"=>" @operator +">" @operator +">>" @operator +"||" @operator +"??" @operator + +"(" @punctuation.bracket +")" @punctuation.bracket +"[" @punctuation.bracket +"]" @punctuation.bracket +"{" @punctuation.bracket +"}" @punctuation.bracket + +; Keywords +;---------- + +[ +"if" +"else" +"switch" +"case" +"default" +] @conditional + +[ +"import" +"from" +"as" +] @include + +[ +"for" +"of" +"do" +"while" +"continue" +] @repeat + +[ +"async" +"await" +"break" +"catch" +"class" +"const" +"debugger" +"delete" +"export" +"extends" +"finally" +"function" +"get" +"in" +"instanceof" +"let" +"new" +"return" +"set" +"static" +"switch" +"target" +"throw" +"try" +"typeof" +"var" +"void" +"with" +"yield" +] @keyword diff --git a/queries/javascript/locals.scm b/queries/javascript/locals.scm new file mode 100644 index 000000000..165adfed9 --- /dev/null +++ b/queries/javascript/locals.scm @@ -0,0 +1,35 @@ +; Scopes +;------- + +(statement_block) @scope +(function) @scope +(arrow_function) @scope +(function_declaration) @scope +(method_definition) @scope + +; Definitions +;------------ + +(formal_parameters + (identifier) @definition) + +(formal_parameters + (object_pattern + (identifier) @definition)) + +(formal_parameters + (object_pattern + (shorthand_property_identifier) @definition)) + +(formal_parameters + (array_pattern + (identifier) @definition)) + +(variable_declarator + name: (identifier) @definition) + +; References +;------------ + +(identifier) @reference + diff --git a/queries/typescript/highlights.scm b/queries/typescript/highlights.scm new file mode 100644 index 000000000..92820105b --- /dev/null +++ b/queries/typescript/highlights.scm @@ -0,0 +1,215 @@ +; Types + +; Javascript +; Special identifiers +;-------------------- + +((identifier) @constant + (#match? @constant "^[A-Z_][A-Z\\d_]+$")) + +((shorthand_property_identifier) @constant + (#match? @constant "^[A-Z_][A-Z\\d_]+$")) + +((identifier) @constructor + (#match? @constructor "^[A-Z]")) + +((identifier) @variable.builtin + (#match? @variable.builtin "^(arguments|module|console|window|document)$")) + +((identifier) @function.builtin + (#eq? @function.builtin "require")) + +; Function and method definitions +;-------------------------------- + +(function + name: (identifier) @function) +(function_declaration + name: (identifier) @function) +(method_definition + name: (property_identifier) @function.method) + +(pair + key: (property_identifier) @function.method + value: (function)) +(pair + key: (property_identifier) @function.method + value: (arrow_function)) + +(assignment_expression + left: (member_expression + property: (property_identifier) @function.method) + right: (arrow_function)) +(assignment_expression + left: (member_expression + property: (property_identifier) @function.method) + right: (function)) + +(variable_declarator + name: (identifier) @function + value: (arrow_function)) +(variable_declarator + name: (identifier) @function + value: (function)) + +(assignment_expression + left: (identifier) @function + right: (arrow_function)) +(assignment_expression + left: (identifier) @function + right: (function)) + +; Function and method calls +;-------------------------- + +(call_expression + function: (identifier) @function) + +(call_expression + function: (member_expression + property: (property_identifier) @function.method)) + +; Variables +;---------- + +(formal_parameters (identifier) @variable.parameter) + +(identifier) @variable + +; Properties +;----------- + +(property_identifier) @property + +; Literals +;--------- + +(this) @variable.builtin +(super) @variable.builtin + +(true) @constant.builtin +(false) @constant.builtin +(null) @constant.builtin +(comment) @comment +(string) @string +(regex) @string.special +(template_string) @string +(number) @number + +; Punctuation +;------------ + +(template_substitution + "${" @punctuation.special + "}" @punctuation.special) @embedded + +";" @punctuation.delimiter +"." @punctuation.delimiter +"," @punctuation.delimiter + +"--" @operator +"-" @operator +"-=" @operator +"&&" @operator +"+" @operator +"++" @operator +"+=" @operator +"<" @operator +"<<" @operator +"=" @operator +"==" @operator +"===" @operator +"=>" @operator +">" @operator +">>" @operator +"||" @operator +"??" @operator + +"(" @punctuation.bracket +")" @punctuation.bracket +"[" @punctuation.bracket +"]" @punctuation.bracket +"{" @punctuation.bracket +"}" @punctuation.bracket + +; Keywords +;---------- + +[ +"if" +"else" +"switch" +"case" +"default" +] @conditional + +[ +"import" +"from" +"as" +] @include + +[ +"for" +"of" +"do" +"while" +"continue" +] @repeat + +[ +"async" +"await" +"break" +"catch" +"class" +"const" +"debugger" +"delete" +"export" +"extends" +"finally" +"function" +"get" +"in" +"instanceof" +"let" +"new" +"return" +"set" +"static" +"switch" +"target" +"throw" +"try" +"typeof" +"var" +"void" +"with" +"yield" +"abstract" +"declare" +"enum" +"export" +"implements" +"interface" +"keyof" +"namespace" +"private" +"protected" +"public" +"type" +] @keyword + +(readonly) @keyword +(type_identifier) @type +(predefined_type) @type.builtin + +(type_arguments + "<" @punctuation.bracket + ">" @punctuation.bracket) + +; Variables + +(required_parameter (identifier) @variable.parameter) +(optional_parameter (identifier) @variable.parameter) diff --git a/queries/typescript/locals.scm b/queries/typescript/locals.scm new file mode 100644 index 000000000..d308e9873 --- /dev/null +++ b/queries/typescript/locals.scm @@ -0,0 +1,37 @@ +; Scopes +;------- + +(statement_block) @scope +(function) @scope +(arrow_function) @scope +(function_declaration) @scope +(method_definition) @scope + +; Definitions +;------------ + +(formal_parameters + (identifier) @definition) + +(formal_parameters + (object_pattern + (identifier) @definition)) + +(formal_parameters + (object_pattern + (shorthand_property_identifier) @definition)) + +(formal_parameters + (array_pattern + (identifier) @definition)) + +(variable_declarator + name: (identifier) @definition) + +; References +;------------ + +(identifier) @reference + +(required_parameter (identifier) @definition) +(optional_parameter (identifier) @definition) From df060261106a3570dbae04ae83879cdcbc9a9907 Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Sat, 23 May 2020 20:29:08 +0200 Subject: [PATCH 06/51] Introduce base languages for queries Some treesitter grammars just extend another treesitter grammar. This enables us to use the C queries also for C++. We only need to put additional queries in the C++ files. --- lua/nvim-treesitter/query.lua | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lua/nvim-treesitter/query.lua b/lua/nvim-treesitter/query.lua index b914e5d7d..788bfa126 100644 --- a/lua/nvim-treesitter/query.lua +++ b/lua/nvim-treesitter/query.lua @@ -13,11 +13,31 @@ local function read_query_files(filenames) return table.concat(contents, '\n') end +-- Some treesitter grammars extend others. +-- We can use that to import the queries of the base language +M.base_language_map = { + cpp = {'c'}, + typescript = {'javascript'}, + tsx = {'typescript', 'javascript'}, +} + function M.get_query(ft, query_name) local query_files = api.nvim_get_runtime_file(string.format('queries/%s/%s.scm', ft, query_name), true) + local query_string = '' if #query_files > 0 then - return ts.parse_query(ft, read_query_files(query_files)) + query_string = read_query_files(query_files)..query_string + end + + for _, base_lang in ipairs(M.base_language_map[ft] or {}) do + local base_files = api.nvim_get_runtime_file(string.format('queries/%s/%s.scm', base_lang, query_name), false) + if base_files and #base_files > 0 then + query_string = read_query_files(base_files)..query_string + end + end + + if #query_string > 0 then + return ts.parse_query(ft, query_string) end end From 167ce6339fb672af9bfd9b5e21a4d18b2f4fb253 Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Sat, 23 May 2020 21:02:43 +0200 Subject: [PATCH 07/51] Add C++ highlights.scm --- README.md | 2 +- queries/c/highlights.scm | 3 ++ queries/cpp/highlights.scm | 97 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 queries/cpp/highlights.scm diff --git a/README.md b/README.md index 1b4fe210d..95bb5ae91 100644 --- a/README.md +++ b/README.md @@ -156,7 +156,7 @@ List of currently supported languages: - [x] ruby (maintained by @TravonteD) - [x] c (maintained by @vigoux) - [x] go (maintained by @theHamsta) -- [ ] cpp +- [x] cpp (maintained by @theHamsta, extends C queries) - [ ] rust - [x] python (maintained by @theHamsta) - [ ] javascript diff --git a/queries/c/highlights.scm b/queries/c/highlights.scm index 4cfb042cc..80fb99749 100644 --- a/queries/c/highlights.scm +++ b/queries/c/highlights.scm @@ -71,6 +71,9 @@ (primitive_type) @type (sized_type_specifier) @type +((identifier) @type + (match? @type "^[A-Z]")) + ((identifier) @constant (match? @constant "^[A-Z][A-Z\\d_]+$")) diff --git a/queries/cpp/highlights.scm b/queries/cpp/highlights.scm new file mode 100644 index 000000000..e3bce91cb --- /dev/null +++ b/queries/cpp/highlights.scm @@ -0,0 +1,97 @@ +((identifier) @field + (match? @field "^_")) + +((identifier) @field + (match? @field "^m_")) + +((identifier) @field + (match? @field "_$")) + +;(field_expression) @parameter ;; How to highlight this? +(template_function + name: (identifier) @function) + +(template_method + name: (field_identifier) @method) + +(template_function + name: (scoped_identifier + name: (identifier) @function)) + +(namespace_identifier) @constant + +((namespace_identifier) @type + (match? @type "^[A-Z]")) +((namespace_identifier) @constant + (match? @constant "^[A-Z][A-Z_1-9]*$")) + +(destructor_name + name: (*) @function) + +(function_declarator + declarator: (scoped_identifier + name: (identifier) @function)) +((function_declarator + declarator: (scoped_identifier + name: (identifier) @constructor)) + (match? @constructor "^[A-Z]")) + +(call_expression + function: (scoped_identifier + name: (identifier) @function)) + +(call_expression + function: (field_expression + field: (field_identifier) @function)) + +((call_expression + function: (scoped_identifier + name: (identifier) @constructor)) +(match? @constructor "^[A-Z]")) + +((call_expression + function: (field_expression + field: (field_identifier) @function)) +(match? @function "^[A-Z]")) + +;; constructing a type in a intizializer list: Constructor (): **SuperType (1)** +((field_initializer + (field_identifier) @constructor + (argument_list)) + (match? @constructor "^[A-Z]")) + +(auto) @keyword +(class_specifier) + +; Constants + +;(this) @constant.builtin +(this) @keyword +(nullptr) @constant + +(true) @boolean +(false) @boolean + +; Keywords + +"catch" @exception +"class" @keyword +"constexpr" @keyword +"delete" @operator +"explicit" @keyword +"final" @exception +"friend" @keyword +"mutable" @keyword +"namespace" @keyword +"noexcept" @keyword +"new" @operator +"override" @keyword +"private" @keyword +"protected" @keyword +"public" @keyword +"template" @keyword +"throw" @keyword +"try" @exception +"typename" @keyword +"using" @keyword +"virtual" @keyword From b95e0af73b00dcba6e54e6f1ffa9b42e1aef5060 Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Sat, 23 May 2020 21:03:03 +0200 Subject: [PATCH 08/51] Add @error highlight to c/highlights.scm --- queries/c/highlights.scm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/queries/c/highlights.scm b/queries/c/highlights.scm index 80fb99749..e758b0ed4 100644 --- a/queries/c/highlights.scm +++ b/queries/c/highlights.scm @@ -78,3 +78,5 @@ (match? @constant "^[A-Z][A-Z\\d_]+$")) (comment) @comment + +(ERROR) @error From 1badceea813d321d0d58319d5fc5dde07e98f18f Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Sat, 23 May 2020 21:23:05 +0200 Subject: [PATCH 09/51] Add cpp/locals.scm --- queries/cpp/highlights.scm | 11 ++++++--- queries/cpp/locals.scm | 49 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 queries/cpp/locals.scm diff --git a/queries/cpp/highlights.scm b/queries/cpp/highlights.scm index e3bce91cb..be79098c9 100644 --- a/queries/cpp/highlights.scm +++ b/queries/cpp/highlights.scm @@ -61,7 +61,11 @@ (match? @constructor "^[A-Z]")) (auto) @keyword -(class_specifier) + +;; Parameters +; normals +(parameter_list + (parameter_declaration) @parameter) ; Constants @@ -77,14 +81,14 @@ "catch" @exception "class" @keyword "constexpr" @keyword -"delete" @operator +"delete" @keyword "explicit" @keyword "final" @exception "friend" @keyword "mutable" @keyword "namespace" @keyword "noexcept" @keyword -"new" @operator +"new" @keyword "override" @keyword "private" @keyword "protected" @keyword @@ -95,3 +99,4 @@ "typename" @keyword "using" @keyword "virtual" @keyword +"::" @operator diff --git a/queries/cpp/locals.scm b/queries/cpp/locals.scm new file mode 100644 index 000000000..00268442c --- /dev/null +++ b/queries/cpp/locals.scm @@ -0,0 +1,49 @@ + +;; Class / struct defintions +(class_specifier) @scope +(struct_specifier) @scope + + +(struct_specifier + name: (type_identifier) @definition.type) + +(struct_specifier + name: (scoped_type_identifier + name: (type_identifier) @definition.type) ) + +(class_specifier + name: (type_identifier) @definition.type) + +(class_specifier + name: (scoped_type_identifier + name: (type_identifier) @definition.type) ) + +;; Function defintions +(template_function + name: (identifier) @definition.function) @scope + +(template_method + name: (field_identifier) @definition.method) @scope + +(template_function + name: (scoped_identifier + name: (identifier) @definition.function)) @scope + +(function_declarator + declarator: (scoped_identifier + name: (type_identifier) @definition.function)) @scope + +(field_declaration + declarator: (function_declarator + (field_identifier) @definition.method)) + +(lambda_expression) @scope + +;; Control structures +(try_statement + body: (*) @scope) + +(catch_clause) @scope + +(destructor_name + name: (*) @constructor) From 148ad160e8be09b29a2e9547f4814b85147639a6 Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Sat, 23 May 2020 21:50:52 +0200 Subject: [PATCH 10/51] Make =,~,! operators in C highlights --- queries/c/highlights.scm | 10 ++++++++++ queries/cpp/highlights.scm | 5 ----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/queries/c/highlights.scm b/queries/c/highlights.scm index e758b0ed4..307feb751 100644 --- a/queries/c/highlights.scm +++ b/queries/c/highlights.scm @@ -35,14 +35,20 @@ "->" @operator "!=" @operator "*" @operator +"/" @operator "&" @operator "&&" @operator "+" @operator "++" @operator "+=" @operator "<" @operator +"<=" @operator "==" @operator +"=" @operator +"~" @operator ">" @operator +">=" @operator +"!" @operator "||" @operator "." @delimiter @@ -79,4 +85,8 @@ (comment) @comment +;; Parameters +(parameter_list + (parameter_declaration) @parameter) + (ERROR) @error diff --git a/queries/cpp/highlights.scm b/queries/cpp/highlights.scm index be79098c9..d98099185 100644 --- a/queries/cpp/highlights.scm +++ b/queries/cpp/highlights.scm @@ -62,11 +62,6 @@ (auto) @keyword -;; Parameters -; normals -(parameter_list - (parameter_declaration) @parameter) - ; Constants ;(this) @constant.builtin From a0b912ff8ace8f58ff74843ffcfd12c0aa9700c5 Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Sat, 23 May 2020 21:59:34 +0200 Subject: [PATCH 11/51] Add punctuation.bracket/punctuation.delimiter to C highlights --- queries/c/highlights.scm | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/queries/c/highlights.scm b/queries/c/highlights.scm index 307feb751..c0df45d48 100644 --- a/queries/c/highlights.scm +++ b/queries/c/highlights.scm @@ -51,8 +51,17 @@ "!" @operator "||" @operator -"." @delimiter -";" @delimiter +"." @punctuation.delimiter +";" @punctuation.delimiter +":" @punctuation.delimiter +"," @punctuation.delimiter + +"(" @punctuation.bracket +")" @punctuation.bracket +"[" @punctuation.bracket +"]" @punctuation.bracket +"{" @punctuation.bracket +"}" @punctuation.bracket (string_literal) @string (system_lib_string) @string From 95f4e10a62f8a90ba7f7db58cb6e8c360b0f61c9 Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Sat, 23 May 2020 22:10:14 +0200 Subject: [PATCH 12/51] Add compound_statement to c queries --- queries/c/locals.scm | 1 + 1 file changed, 1 insertion(+) diff --git a/queries/c/locals.scm b/queries/c/locals.scm index b08d706ee..f7a4b84d2 100644 --- a/queries/c/locals.scm +++ b/queries/c/locals.scm @@ -36,3 +36,4 @@ (while_statement) @scope (translation_unit) @scope (function_definition) @scope +(compound_statement) @scope ; a block in curly braces From d88db9d71805bf9d759d4e0b8d571e6c952c3b0c Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Sun, 24 May 2020 13:31:13 +0200 Subject: [PATCH 13/51] Add operators /=,*=,|=,&= to C highlights --- queries/c/highlights.scm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/queries/c/highlights.scm b/queries/c/highlights.scm index c0df45d48..d6e3a7a15 100644 --- a/queries/c/highlights.scm +++ b/queries/c/highlights.scm @@ -31,7 +31,6 @@ "--" @operator "-" @operator -"-=" @operator "->" @operator "!=" @operator "*" @operator @@ -40,7 +39,6 @@ "&&" @operator "+" @operator "++" @operator -"+=" @operator "<" @operator "<=" @operator "==" @operator @@ -51,6 +49,13 @@ "!" @operator "||" @operator +"-=" @operator +"+=" @operator +"*=" @operator +"/=" @operator +"|=" @operator +"&=" @operator + "." @punctuation.delimiter ";" @punctuation.delimiter ":" @punctuation.delimiter From e46baab8ca23855053900b8657a50e83ad76ba41 Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Sun, 24 May 2020 13:40:43 +0200 Subject: [PATCH 14/51] Add better highlighting for preprocessor functions in C highlights --- queries/c/highlights.scm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/queries/c/highlights.scm b/queries/c/highlights.scm index d6e3a7a15..3c2123383 100644 --- a/queries/c/highlights.scm +++ b/queries/c/highlights.scm @@ -84,6 +84,8 @@ declarator: (identifier) @function) (preproc_function_def name: (identifier) @function.macro) +(preproc_arg) @function.macro +; TODO (preproc_arg) @embedded (field_identifier) @property (statement_identifier) @label @@ -103,4 +105,7 @@ (parameter_list (parameter_declaration) @parameter) +(preproc_params + (identifier)) @parameter + (ERROR) @error From a5fc7b13ccfbc189deea031e692ba14b0e686279 Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Sun, 7 Jun 2020 13:13:24 +0200 Subject: [PATCH 15/51] Update C/C++ highlights to new query syntax --- queries/c/highlights.scm | 5 +++-- queries/c/locals.scm | 2 +- queries/cpp/highlights.scm | 22 +++++++++++----------- queries/cpp/locals.scm | 4 ++-- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/queries/c/highlights.scm b/queries/c/highlights.scm index 3c2123383..568ebaffa 100644 --- a/queries/c/highlights.scm +++ b/queries/c/highlights.scm @@ -94,10 +94,10 @@ (sized_type_specifier) @type ((identifier) @type - (match? @type "^[A-Z]")) + (#match? @type "^[A-Z]")) ((identifier) @constant - (match? @constant "^[A-Z][A-Z\\d_]+$")) + (#match? @constant "^[A-Z][A-Z\\d_]+$")) (comment) @comment @@ -109,3 +109,4 @@ (identifier)) @parameter (ERROR) @error + diff --git a/queries/c/locals.scm b/queries/c/locals.scm index f7a4b84d2..505db5b57 100644 --- a/queries/c/locals.scm +++ b/queries/c/locals.scm @@ -17,7 +17,7 @@ (declaration declarator: (identifier) @definition.var) (enum_specifier - name: (*) @definition.type + name: (_) @definition.type (enumerator_list (enumerator name: (identifier) @definition.var))) diff --git a/queries/cpp/highlights.scm b/queries/cpp/highlights.scm index d98099185..68e5047ab 100644 --- a/queries/cpp/highlights.scm +++ b/queries/cpp/highlights.scm @@ -1,11 +1,11 @@ ((identifier) @field - (match? @field "^_")) + (#match? @field "^_")) ((identifier) @field - (match? @field "^m_")) + (#match? @field "^m_")) ((identifier) @field - (match? @field "_$")) + (#match? @field "_$")) ;(field_expression) @parameter ;; How to highlight this? (template_function @@ -21,12 +21,12 @@ (namespace_identifier) @constant ((namespace_identifier) @type - (match? @type "^[A-Z]")) + (#match? @type "^[A-Z]")) ((namespace_identifier) @constant - (match? @constant "^[A-Z][A-Z_1-9]*$")) + (#match? @constant "^[A-Z][A-Z_1-9]*$")) (destructor_name - name: (*) @function) + name: (_) @function) (function_declarator declarator: (scoped_identifier @@ -34,7 +34,7 @@ ((function_declarator declarator: (scoped_identifier name: (identifier) @constructor)) - (match? @constructor "^[A-Z]")) + (#match? @constructor "^[A-Z]")) (call_expression function: (scoped_identifier @@ -47,18 +47,18 @@ ((call_expression function: (scoped_identifier name: (identifier) @constructor)) -(match? @constructor "^[A-Z]")) +(#match? @constructor "^[A-Z]")) ((call_expression function: (field_expression - field: (field_identifier) @function)) -(match? @function "^[A-Z]")) + field: (field_identifier) @constructor)) +(#match? @function "^[A-Z]")) ;; constructing a type in a intizializer list: Constructor (): **SuperType (1)** ((field_initializer (field_identifier) @constructor (argument_list)) - (match? @constructor "^[A-Z]")) + (#match? @constructor "^[A-Z]")) (auto) @keyword diff --git a/queries/cpp/locals.scm b/queries/cpp/locals.scm index 00268442c..061153c04 100644 --- a/queries/cpp/locals.scm +++ b/queries/cpp/locals.scm @@ -41,9 +41,9 @@ ;; Control structures (try_statement - body: (*) @scope) + body: (_) @scope) (catch_clause) @scope (destructor_name - name: (*) @constructor) + name: (_) @constructor) From 8bc00cf02a5bc73541ba76ad8ea70fd928fffce2 Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Sun, 14 Jun 2020 15:12:38 +0200 Subject: [PATCH 16/51] Change regexes in C/C++ highlights --- queries/c/highlights.scm | 2 +- queries/cpp/highlights.scm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/queries/c/highlights.scm b/queries/c/highlights.scm index 568ebaffa..0d718c223 100644 --- a/queries/c/highlights.scm +++ b/queries/c/highlights.scm @@ -97,7 +97,7 @@ (#match? @type "^[A-Z]")) ((identifier) @constant - (#match? @constant "^[A-Z][A-Z\\d_]+$")) + (#match? @constant "^[A-Z][A-Z0-9_]+$")) (comment) @comment diff --git a/queries/cpp/highlights.scm b/queries/cpp/highlights.scm index 68e5047ab..92909f4d9 100644 --- a/queries/cpp/highlights.scm +++ b/queries/cpp/highlights.scm @@ -23,7 +23,7 @@ ((namespace_identifier) @type (#match? @type "^[A-Z]")) ((namespace_identifier) @constant - (#match? @constant "^[A-Z][A-Z_1-9]*$")) + (#match? @constant "^[A-Z][A-Z_0-9]*$")) (destructor_name name: (_) @function) From 0671c0c6a28bc62e5467d744d72466817d8f30e7 Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Mon, 15 Jun 2020 12:07:50 +0200 Subject: [PATCH 17/51] Fixup: Introduce base languages for queries Use same argument for nvim_get_runtime_file for base language --- lua/nvim-treesitter/query.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/nvim-treesitter/query.lua b/lua/nvim-treesitter/query.lua index 788bfa126..bd0f4c542 100644 --- a/lua/nvim-treesitter/query.lua +++ b/lua/nvim-treesitter/query.lua @@ -30,7 +30,7 @@ function M.get_query(ft, query_name) end for _, base_lang in ipairs(M.base_language_map[ft] or {}) do - local base_files = api.nvim_get_runtime_file(string.format('queries/%s/%s.scm', base_lang, query_name), false) + local base_files = api.nvim_get_runtime_file(string.format('queries/%s/%s.scm', base_lang, query_name), true) if base_files and #base_files > 0 then query_string = read_query_files(base_files)..query_string end From a600be80b68803c949d43e384c847315f5ab4155 Mon Sep 17 00:00:00 2001 From: Steven Sojka Date: Mon, 15 Jun 2020 08:53:49 -0500 Subject: [PATCH 18/51] chore(queries): use inherited queries for ts/js --- queries/typescript/highlights.scm | 188 ------------------------------ queries/typescript/locals.scm | 35 ------ 2 files changed, 223 deletions(-) diff --git a/queries/typescript/highlights.scm b/queries/typescript/highlights.scm index 92820105b..dd0dd778f 100644 --- a/queries/typescript/highlights.scm +++ b/queries/typescript/highlights.scm @@ -1,192 +1,4 @@ -; Types - -; Javascript -; Special identifiers -;-------------------- - -((identifier) @constant - (#match? @constant "^[A-Z_][A-Z\\d_]+$")) - -((shorthand_property_identifier) @constant - (#match? @constant "^[A-Z_][A-Z\\d_]+$")) - -((identifier) @constructor - (#match? @constructor "^[A-Z]")) - -((identifier) @variable.builtin - (#match? @variable.builtin "^(arguments|module|console|window|document)$")) - -((identifier) @function.builtin - (#eq? @function.builtin "require")) - -; Function and method definitions -;-------------------------------- - -(function - name: (identifier) @function) -(function_declaration - name: (identifier) @function) -(method_definition - name: (property_identifier) @function.method) - -(pair - key: (property_identifier) @function.method - value: (function)) -(pair - key: (property_identifier) @function.method - value: (arrow_function)) - -(assignment_expression - left: (member_expression - property: (property_identifier) @function.method) - right: (arrow_function)) -(assignment_expression - left: (member_expression - property: (property_identifier) @function.method) - right: (function)) - -(variable_declarator - name: (identifier) @function - value: (arrow_function)) -(variable_declarator - name: (identifier) @function - value: (function)) - -(assignment_expression - left: (identifier) @function - right: (arrow_function)) -(assignment_expression - left: (identifier) @function - right: (function)) - -; Function and method calls -;-------------------------- - -(call_expression - function: (identifier) @function) - -(call_expression - function: (member_expression - property: (property_identifier) @function.method)) - -; Variables -;---------- - -(formal_parameters (identifier) @variable.parameter) - -(identifier) @variable - -; Properties -;----------- - -(property_identifier) @property - -; Literals -;--------- - -(this) @variable.builtin -(super) @variable.builtin - -(true) @constant.builtin -(false) @constant.builtin -(null) @constant.builtin -(comment) @comment -(string) @string -(regex) @string.special -(template_string) @string -(number) @number - -; Punctuation -;------------ - -(template_substitution - "${" @punctuation.special - "}" @punctuation.special) @embedded - -";" @punctuation.delimiter -"." @punctuation.delimiter -"," @punctuation.delimiter - -"--" @operator -"-" @operator -"-=" @operator -"&&" @operator -"+" @operator -"++" @operator -"+=" @operator -"<" @operator -"<<" @operator -"=" @operator -"==" @operator -"===" @operator -"=>" @operator -">" @operator -">>" @operator -"||" @operator -"??" @operator - -"(" @punctuation.bracket -")" @punctuation.bracket -"[" @punctuation.bracket -"]" @punctuation.bracket -"{" @punctuation.bracket -"}" @punctuation.bracket - -; Keywords -;---------- - [ -"if" -"else" -"switch" -"case" -"default" -] @conditional - -[ -"import" -"from" -"as" -] @include - -[ -"for" -"of" -"do" -"while" -"continue" -] @repeat - -[ -"async" -"await" -"break" -"catch" -"class" -"const" -"debugger" -"delete" -"export" -"extends" -"finally" -"function" -"get" -"in" -"instanceof" -"let" -"new" -"return" -"set" -"static" -"switch" -"target" -"throw" -"try" -"typeof" -"var" -"void" -"with" -"yield" "abstract" "declare" "enum" diff --git a/queries/typescript/locals.scm b/queries/typescript/locals.scm index d308e9873..cb064b823 100644 --- a/queries/typescript/locals.scm +++ b/queries/typescript/locals.scm @@ -1,37 +1,2 @@ -; Scopes -;------- - -(statement_block) @scope -(function) @scope -(arrow_function) @scope -(function_declaration) @scope -(method_definition) @scope - -; Definitions -;------------ - -(formal_parameters - (identifier) @definition) - -(formal_parameters - (object_pattern - (identifier) @definition)) - -(formal_parameters - (object_pattern - (shorthand_property_identifier) @definition)) - -(formal_parameters - (array_pattern - (identifier) @definition)) - -(variable_declarator - name: (identifier) @definition) - -; References -;------------ - -(identifier) @reference - (required_parameter (identifier) @definition) (optional_parameter (identifier) @definition) From a896f5579dfc8c1852b72d7698aa84c6705a46e0 Mon Sep 17 00:00:00 2001 From: Steven Sojka Date: Mon, 15 Jun 2020 15:11:07 -0500 Subject: [PATCH 19/51] fix(javascript): set booleans to boolean highlights --- queries/javascript/highlights.scm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/queries/javascript/highlights.scm b/queries/javascript/highlights.scm index da88d85d0..dfbabc977 100644 --- a/queries/javascript/highlights.scm +++ b/queries/javascript/highlights.scm @@ -87,8 +87,8 @@ (this) @variable.builtin (super) @variable.builtin -(true) @constant.builtin -(false) @constant.builtin +(true) @boolean +(false) @boolean (null) @constant.builtin (comment) @comment (string) @string From 7bc746f3f0f2e8195c39c3ff3029379ad39d9f33 Mon Sep 17 00:00:00 2001 From: Steven Sojka Date: Mon, 15 Jun 2020 13:13:26 -0500 Subject: [PATCH 20/51] feat(lang): add json highlights --- README.md | 2 +- queries/json/highlights.scm | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 queries/json/highlights.scm diff --git a/README.md b/README.md index 6a45ebee9..3df340334 100644 --- a/README.md +++ b/README.md @@ -162,7 +162,7 @@ List of currently supported languages: - [x] javascript (maintained by @steelsojka) - [x] typescript (maintained by @steelsojka) - [ ] tsx -- [ ] json +- [x] json (maintained by @steelsojka) - [x] html (maintained by @TravonteD) - [ ] csharp - [ ] swift diff --git a/queries/json/highlights.scm b/queries/json/highlights.scm new file mode 100644 index 000000000..bdc35ad98 --- /dev/null +++ b/queries/json/highlights.scm @@ -0,0 +1,13 @@ +(true) @boolean +(false) @boolean +(null) @constant.builtin +(number) @number +(pair key: (string) @label) +(pair value: (string) @string) +(string_content (escape_sequence) @string.escape) +(ERROR) @error +"," @punctuation.delimiter +"[" @punctuation.bracket +"]" @punctuation.bracket +"{" @punctuation.bracket +"}" @punctuation.bracket From 38af29a912a607d3d703f57b840bfc61671679cc Mon Sep 17 00:00:00 2001 From: kiyan42 Date: Fri, 19 Jun 2020 13:45:33 +0200 Subject: [PATCH 21/51] refacto: remove buf_state - remove buf_state and related code - add get_node_at_cursor() - better incremental selection (code is localized) --- lua/nvim-treesitter.lua | 21 +-- lua/nvim-treesitter/configs.lua | 76 +++++------ lua/nvim-treesitter/incremental_selection.lua | 76 ++++++----- lua/nvim-treesitter/install.lua | 3 +- lua/nvim-treesitter/locals.lua | 4 +- lua/nvim-treesitter/parsers.lua | 5 +- lua/nvim-treesitter/state.lua | 122 ------------------ lua/nvim-treesitter/ts_utils.lua | 7 + lua/nvim-treesitter/utils.lua | 19 --- 9 files changed, 100 insertions(+), 233 deletions(-) delete mode 100644 lua/nvim-treesitter/state.lua diff --git a/lua/nvim-treesitter.lua b/lua/nvim-treesitter.lua index 100324e36..d3c7fa75f 100644 --- a/lua/nvim-treesitter.lua +++ b/lua/nvim-treesitter.lua @@ -2,10 +2,9 @@ local api = vim.api local install = require'nvim-treesitter.install' local utils = require'nvim-treesitter.utils' +local ts_utils = require'nvim-treesitter.ts_utils' local info = require'nvim-treesitter.info' local configs = require'nvim-treesitter.configs' -local state = require'nvim-treesitter.state' -local ts_utils = require'nvim-treesitter.ts_utils' local M = {} @@ -21,20 +20,13 @@ function M.setup() api.nvim_command(string.format("autocmd NvimTreesitter FileType %s %s", ft, cmd)) end end - local cmd = string.format("lua require'nvim-treesitter.state'.attach_to_buffer(%s)", ft) - api.nvim_command(string.format('autocmd NvimTreesitter FileType %s %s', ft, cmd)) end - - state.run_update() end function M.statusline(indicator_size) local indicator_size = indicator_size or 100 - local bufnr = api.nvim_get_current_buf() - local buf_state = state.get_buf_state(bufnr) - if not buf_state then return "" end - local current_node = buf_state.current_node + local current_node = ts_utils.get_node_at_cursor() if not current_node then return "" end local expr = current_node:parent() @@ -56,13 +48,4 @@ function M.statusline(indicator_size) end end -function M.get_buf_state() - local bufnr = api.nvim_get_current_buf() - return state.exposed_state(bufnr) -end - -function M.get_node_api() - return ts_utils -end - return M diff --git a/lua/nvim-treesitter/configs.lua b/lua/nvim-treesitter/configs.lua index f7b5ff2cf..633f9d21c 100644 --- a/lua/nvim-treesitter/configs.lua +++ b/lua/nvim-treesitter/configs.lua @@ -1,137 +1,137 @@ local api = vim.api local queries = require'nvim-treesitter.query' -local utils = require'nvim-treesitter.utils' +local parsers = require'nvim-treesitter.parsers' -local parsers = {} +local parserlist = {} -parsers.javascript = { +parserlist.javascript = { install_info = { url = "https://github.com/tree-sitter/tree-sitter-javascript", files = { "src/parser.c", "src/scanner.c" }, } } -parsers.c = { +parserlist.c = { install_info = { url = "https://github.com/tree-sitter/tree-sitter-c", files = { "src/parser.c" } } } -parsers.cpp = { +parserlist.cpp = { install_info = { url = "https://github.com/tree-sitter/tree-sitter-cpp", files = { "src/parser.c", "src/scanner.cc" } } } -parsers.rust = { +parserlist.rust = { install_info = { url = "https://github.com/tree-sitter/tree-sitter-rust", files = { "src/parser.c", "src/scanner.c" }, } } -parsers.lua = { +parserlist.lua = { install_info = { url = "https://github.com/nvim-treesitter/tree-sitter-lua", files = { "src/parser.c", "src/scanner.cc" } } } -parsers.python = { +parserlist.python = { install_info = { url = "https://github.com/tree-sitter/tree-sitter-python", files = { "src/parser.c", "src/scanner.cc" }, } } -parsers.go = { +parserlist.go = { install_info = { url = "https://github.com/tree-sitter/tree-sitter-go", files = { "src/parser.c" }, } } -parsers.ruby = { +parserlist.ruby = { install_info = { url = "https://github.com/tree-sitter/tree-sitter-ruby", files = { "src/parser.c", "src/scanner.cc" }, } } -parsers.bash = { +parserlist.bash = { install_info = { url = "https://github.com/tree-sitter/tree-sitter-bash", files = { "src/parser.c", "src/scanner.cc" }, } } -parsers.php = { +parserlist.php = { install_info = { url = "https://github.com/tree-sitter/tree-sitter-php", files = { "src/parser.c", "src/scanner.cc" }, } } -parsers.java = { +parserlist.java = { install_info = { url = "https://github.com/tree-sitter/tree-sitter-java", files = { "src/parser.c" }, } } -parsers.html = { +parserlist.html = { install_info = { url = "https://github.com/tree-sitter/tree-sitter-html", files = { "src/parser.c", "src/scanner.cc" }, } } -parsers.julia = { +parserlist.julia = { install_info = { url = "https://github.com/tree-sitter/tree-sitter-julia", files = { "src/parser.c", "src/scanner.c" }, } } -parsers.json = { +parserlist.json = { install_info = { url = "https://github.com/tree-sitter/tree-sitter-json", files = { "src/parser.c" }, } } -parsers.css = { +parserlist.css = { install_info = { url = "https://github.com/tree-sitter/tree-sitter-css", files = { "src/parser.c", "src/scanner.c" }, } } -parsers.ocaml = { +parserlist.ocaml = { install_info = { url = "https://github.com/tree-sitter/tree-sitter-ocaml", files = { "src/parser.c", "src/scanner.cc" }, } } -parsers.swift = { +parserlist.swift = { install_info = { url = "https://github.com/tree-sitter/tree-sitter-swift", files = { "src/parser.c" }, } } -parsers.csharp = { +parserlist.csharp = { install_info = { url = "https://github.com/tree-sitter/tree-sitter-c-sharp", files = { "src/parser.c", "src/scanner.c" }, } } -parsers.typescript = { +parserlist.typescript = { install_info = { url = "https://github.com/tree-sitter/tree-sitter-typescript", files = { "src/parser.c", "src/scanner.c" }, @@ -139,7 +139,7 @@ parsers.typescript = { } } -parsers.tsx = { +parserlist.tsx = { install_info = { url = "https://github.com/tree-sitter/tree-sitter-typescript", files = { "src/parser.c", "src/scanner.c" }, @@ -147,63 +147,63 @@ parsers.tsx = { } } -parsers.scala = { +parserlist.scala = { install_info = { url = "https://github.com/tree-sitter/tree-sitter-scala", files = { "src/parser.c", "src/scanner.c" }, } } -parsers.haskell = { +parserlist.haskell = { install_info = { url = "https://github.com/tree-sitter/tree-sitter-haskell", files = { "src/parser.c", "src/scanner.cc" }, } } -parsers.markdown = { +parserlist.markdown = { install_info = { url = "https://github.com/ikatyang/tree-sitter-markdown", files = { "src/parser.c", "src/scanner.cc" }, } } -parsers.toml = { +parserlist.toml = { install_info = { url = "https://github.com/ikatyang/tree-sitter-toml", files = { "src/parser.c", "src/scanner.c" }, } } -parsers.vue = { +parserlist.vue = { install_info = { url = "https://github.com/ikatyang/tree-sitter-vue", files = { "src/parser.c", "src/scanner.cc" }, } } -parsers.elm = { +parserlist.elm = { install_info = { url = "https://github.com//razzeee/tree-sitter-elm", files = { "src/parser.c", "src/scanner.cc" }, } } -parsers.yaml = { +parserlist.yaml = { install_info = { url = "https://github.com/ikatyang/tree-sitter-yaml", files = { "src/parser.c", "src/scanner.cc" }, } } -parsers.nix = { +parserlist.nix = { install_info = { url = "https://github.com/cstrahan/tree-sitter-nix", files = { "src/parser.c", "src/scanner.cc" }, } } -parsers.regex = { +parserlist.regex = { install_info = { url = "https://github.com/tree-sitter/tree-sitter-regex", files = { "src/parser.c" } @@ -245,7 +245,7 @@ local M = {} local function enable_module(mod, bufnr, ft) local bufnr = bufnr or api.nvim_get_current_buf() local ft = ft or api.nvim_buf_get_option(bufnr, 'ft') - if not parsers[ft] or not config.modules[mod] then + if not parserlist[ft] or not config.modules[mod] then return end @@ -275,12 +275,12 @@ local function enable_all(mod, ft) end end if ft then - if utils.has_parser(ft) then + if parsers.has_parser(ft) then enable_mod_conf_autocmd(mod, ft) end else for _, ft in pairs(M.available_parsers()) do - if utils.has_parser(ft) then + if parsers.has_parser(ft) then enable_mod_conf_autocmd(mod, ft) end end @@ -291,7 +291,7 @@ end local function disable_module(mod, bufnr, ft) local bufnr = bufnr or api.nvim_get_current_buf() local ft = ft or api.nvim_buf_get_option(bufnr, 'ft') - if not parsers[ft] or not config.modules[mod] then + if not parserlist[ft] or not config.modules[mod] then return end @@ -360,7 +360,7 @@ M.commands = { -- @param mod: module (string) -- @param ft: filetype (string) function M.is_enabled(mod, ft) - if not M.get_parser_configs()[ft] or not utils.has_parser(ft) then + if not M.get_parser_configs()[ft] or not parsers.has_parser(ft) then return false end @@ -404,11 +404,11 @@ function M.setup(user_data) end function M.get_parser_configs() - return parsers + return parserlist end function M.available_parsers() - return vim.tbl_keys(parsers) + return vim.tbl_keys(parserlist) end function M.available_modules() diff --git a/lua/nvim-treesitter/incremental_selection.lua b/lua/nvim-treesitter/incremental_selection.lua index 9876f2e01..6a9999303 100644 --- a/lua/nvim-treesitter/incremental_selection.lua +++ b/lua/nvim-treesitter/incremental_selection.lua @@ -1,11 +1,13 @@ local api = vim.api -local state = require'nvim-treesitter.state' local configs = require'nvim-treesitter.configs' local ts_utils = require'nvim-treesitter.ts_utils' +local parsers = require'nvim-treesitter.parsers' local M = {} +local selections = {} + local function update_selection(buf, node) local start_row, start_col, end_row, end_col = node:range() @@ -18,32 +20,49 @@ local function update_selection(buf, node) vim.fn.setpos(".", { buf, end_row+1, end_col+1, 0 }) end +function M.init_selection() + local buf = api.nvim_get_current_buf() + local node = ts_utils.get_node_at_cursor() + selections[buf] = { [1] = node } + update_selection(buf, node) +end + +local function visual_selection_range() + local _, csrow, cscol, _ = unpack(vim.fn.getpos("'<")) + local _, cerow, cecol, _ = unpack(vim.fn.getpos("'>")) + if csrow < cerow then + return csrow-1, cscol-1, cerow-1, cecol-1 + else + return cerow-1, cecol-1, csrow-1, cscol-1 + end +end + +local function range_matches(node) + local csrow, cscol, cerow, cecol = visual_selection_range() + local srow, scol, erow, ecol = node:range() + return srow == csrow and scol == cscol and erow == cerow and ecol == cecol +end + local function select_incremental(get_parent) return function() local buf = api.nvim_get_current_buf() - local buf_state = state.get_buf_state(buf) + local nodes = selections[buf] - local node - -- initialize incremental selection with current range - if #buf_state.selection.nodes == 0 then - local cur_range = buf_state.selection.range - if not cur_range then - local _, cursor_row, cursor_col, _ = unpack(vim.fn.getpos(".")) - cur_range = { cursor_row, cursor_col, cursor_row, cursor_col + 1 } - end - - local root = buf_state.parser.tree:root() - if not root then return end - - node = root:named_descendant_for_range(cur_range[1]-1, cur_range[2]-1, cur_range[3]-1, cur_range[4]-1) - else - node = get_parent(buf_state.selection.nodes[#buf_state.selection.nodes]) + -- initialize incremental selection with current selection + if not nodes or #nodes == 0 or not range_matches(nodes[#nodes]) then + local csrow, cscol, cerow, cecol = visual_selection_range() + local root = parsers.get_parser().tree:root() + local node = root:named_descendant_for_range(csrow, cscol, cerow, cecol) + update_selection(buf, node) + selections[buf] = { [1] = node } + return end + node = get_parent(nodes[#nodes]) if not node then return end - if node ~= buf_state.selection.nodes[#buf_state.selection.nodes] then - state.insert_selection_node(buf, node) + if node ~= nodes[#nodes] then + table.insert(nodes, node) end update_selection(buf, node) @@ -60,13 +79,10 @@ end) function M.node_decremental() local buf = api.nvim_get_current_buf() - local buf_state = state.get_buf_state(buf) - - local nodes = buf_state.selection.nodes - if #nodes < 2 then return end - - state.pop_selection_node(buf) + local nodes = selections[buf] + if not nodes or #nodes < 2 then return end + table.remove(selections[buf]) local node = nodes[#nodes] update_selection(buf, node) end @@ -76,14 +92,14 @@ function M.attach(bufnr) local config = configs.get_module('incremental_selection') for funcname, mapping in pairs(config.keymaps) do - + local mode if funcname == "init_selection" then - local cmd = ":lua require'nvim-treesitter.incremental_selection'.node_incremental()" - api.nvim_buf_set_keymap(buf, 'n', mapping, cmd, { silent = true }) + mode = 'n' else - local cmd = string.format(":lua require'nvim-treesitter.incremental_selection'.%s()", funcname) - api.nvim_buf_set_keymap(buf, 'v', mapping, cmd, { silent = true }) + mode = 'v' end + local cmd = string.format(":lua require'nvim-treesitter.incremental_selection'.%s()", funcname) + api.nvim_buf_set_keymap(buf, mode, mapping, cmd, { silent = true }) end end diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua index 637f1dedb..381afaa4a 100644 --- a/lua/nvim-treesitter/install.lua +++ b/lua/nvim-treesitter/install.lua @@ -4,6 +4,7 @@ local luv = vim.loop local configs = require'nvim-treesitter.configs' local utils = require'nvim-treesitter.utils' +local parsers = require'nvim-treesitter.parsers' local M = {} @@ -128,7 +129,7 @@ M.ensure_installed = function(languages) end for _, ft in ipairs(languages) do - if not utils.has_parser(ft) then + if not parsers.has_parser(ft) then install(ft) end end diff --git a/lua/nvim-treesitter/locals.lua b/lua/nvim-treesitter/locals.lua index 313d7655d..cbea89108 100644 --- a/lua/nvim-treesitter/locals.lua +++ b/lua/nvim-treesitter/locals.lua @@ -5,7 +5,7 @@ local api = vim.api local ts = vim.treesitter local queries = require'nvim-treesitter.query' -local utils = require'nvim-treesitter.utils' +local parsers = require'nvim-treesitter.parsers' local M = { locals = {} @@ -18,7 +18,7 @@ function M.collect_locals(bufnr) local query = queries.get_query(ft, 'locals') if not query then return end - local parser = utils.get_parser(bufnr, ft) + local parser = parsers.get_parser(bufnr, ft) if not parser then return end local root = parser:parse():root() diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua index 07f3e9d34..3789b7afe 100644 --- a/lua/nvim-treesitter/parsers.lua +++ b/lua/nvim-treesitter/parsers.lua @@ -10,9 +10,10 @@ function M.has_parser(lang) end function M.get_parser(bufnr, lang) + local buf = bufnr or api.nvim_get_current_buf() + local lang = lang or api.nvim_buf_get_option(buf, 'ft') + if M.has_parser(lang) then - local buf = bufnr or api.nvim_get_current_buf() - local lang = lang or api.nvim_buf_get_option(buf, 'ft') if not M[buf] then M[buf] = {} end diff --git a/lua/nvim-treesitter/state.lua b/lua/nvim-treesitter/state.lua deleted file mode 100644 index adff7eeaf..000000000 --- a/lua/nvim-treesitter/state.lua +++ /dev/null @@ -1,122 +0,0 @@ -local api = vim.api - -local utils = require'nvim-treesitter.utils' - -local M = {} - -local buffers = {} - -local g_mode = api.nvim_get_mode().mode - -local function get_selection_range() - local _, vstart_row, vstart_col, _ = unpack(vim.fn.getpos("v")) - local _, cursor_row, cursor_col, _ = unpack(vim.fn.getpos(".")) - if vstart_row < cursor_row then - return vstart_row, vstart_col, cursor_row, cursor_col - else - return cursor_row, cursor_col, vstart_row, vstart_col - end -end - -function M.update() - local bufnr = api.nvim_get_current_buf() - local buf_config = buffers[bufnr] - if not buf_config then return end - - local mode = api.nvim_get_mode().mode - local cursor = api.nvim_win_get_cursor(0) - local row = cursor[1] - local col = cursor[2] - if row == buf_config.cursor_pos.row - and col == buf_config.cursor_pos.col - and mode == g_mode - then - return - end - - local root = buf_config.parser.tree:root() - if not root then return end - - local new_node = root:named_descendant_for_range(row - 1, col, row - 1, col) - - if new_node ~= buf_config.current_node then - buf_config.current_node = new_node - end - - -- We only want to update the range when the incremental selection has not started yet - if mode == "v" and #buf_config.selection.nodes == 0 then - local row_start, col_start, row_end, col_end = get_selection_range() - buf_config.selection.range = { row_start, col_start, row_end, col_end } - elseif mode ~= "v" then - buf_config.selection.nodes = {} - buf_config.selection.range = nil - end - - g_mode = mode - buf_config.cursor_pos.row = row - buf_config.cursor_pos.col = col -end - -function M.insert_selection_node(bufnr, range) - local buf_config = buffers[bufnr] - if not buf_config then return end - - table.insert(buffers[bufnr].selection.nodes, range) -end - -function M.pop_selection_node(bufnr) - local buf_config = buffers[bufnr] - if not buf_config then return end - - table.remove( - buffers[bufnr].selection.nodes, - #buffers[bufnr].selection.nodes - ) -end - -function M.run_update() - local cmd = "lua require'nvim-treesitter.state'.update()" - api.nvim_command('autocmd NvimTreesitter CursorMoved * '..cmd) -end - -function M.attach_to_buffer(ft) - local bufnr = api.nvim_get_current_buf() - local ft = ft or api.nvim_buf_get_option(bufnr, 'ft') - - if buffers[bufnr] then return end - - local parser = utils.get_parser(bufnr, ft) - if not parser then return end - - buffers[bufnr] = { - cursor_pos = {}, - current_node = nil, - selection = { - range = nil, - nodes = {} - }, - parser = parser, - } - - M.update() - api.nvim_buf_attach(bufnr, false, { - -- TODO(kyazdani): on lines should only parse the changed content - -- TODO(kyazdani): add a timer to avoid too frequent updates - on_lines = function(_, buf) buffers[buf].parser:parse() end, - on_detach = function(bufnr) buffers[bufnr] = nil end, - }) -end - -function M.get_buf_state(bufnr) - return buffers[bufnr] -end - -function M.exposed_state(bufnr) - local buf_state = buffers[bufnr] - return { - cursor_pos = buf_state.cursor_pos, - current_node = buf_state.current_node - } -end - -return M diff --git a/lua/nvim-treesitter/ts_utils.lua b/lua/nvim-treesitter/ts_utils.lua index 1445418e0..a85934c0b 100644 --- a/lua/nvim-treesitter/ts_utils.lua +++ b/lua/nvim-treesitter/ts_utils.lua @@ -1,6 +1,7 @@ local api = vim.api local locals = require'nvim-treesitter.locals' +local parsers = require'nvim-treesitter.parsers' local M = {} @@ -205,4 +206,10 @@ function M.previous_scope(node) end end +function M.get_node_at_cursor() + local cursor = api.nvim_win_get_cursor(0) + local root = parsers.get_parser().tree:root() + return root:named_descendant_for_range(cursor[1]-1,cursor[2],cursor[1]-1,cursor[2]) +end + return M diff --git a/lua/nvim-treesitter/utils.lua b/lua/nvim-treesitter/utils.lua index 9dc5d17bd..6fa159817 100644 --- a/lua/nvim-treesitter/utils.lua +++ b/lua/nvim-treesitter/utils.lua @@ -45,23 +45,4 @@ function M.get_cache_dir() return nil, 'Invalid cache rights, $XDG_CACHE_HOME or /tmp should be read/write' end -function M.has_parser(lang) - local lang = lang or api.nvim_buf_get_option(0, 'filetype') - return #api.nvim_get_runtime_file('parser/' .. lang .. '.so', false) > 0 -end - -function M.get_parser(bufnr, lang) - if M.has_parser() then - local buf = bufnr or api.nvim_get_current_buf() - local lang = lang or api.nvim_buf_get_option(buf, 'ft') - if not M[buf] then - M[buf] = {} - end - if not M[buf][lang] then - M[buf][lang] = ts.get_parser(buf, lang) - end - return M[buf][lang] - end -end - return M From cabe61ac19a2d0377a46ef48499eb292e12ae5fb Mon Sep 17 00:00:00 2001 From: kiyan42 Date: Fri, 19 Jun 2020 13:51:09 +0200 Subject: [PATCH 22/51] update docs --- README.md | 14 ++++--------- doc/nvim-treesitter.txt | 46 +++++++++++++++-------------------------- doc/tags | 23 +++++++++++---------- 3 files changed, 33 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index 33ce5d979..b2193103a 100644 --- a/README.md +++ b/README.md @@ -131,19 +131,13 @@ Some of these features are : You can find the roadmap [here](https://github.com/nvim-treesitter/nvim-treesitter/projects/1). The roadmap and all features of this plugin are open to change, and any suggestion will be highly appreciated! -## Api +## Utils -Nvim-treesitter exposes an api to extend node capabilites. You can retrieve the api like this: +you can get some utility functions with ```lua -local ts_node_api = require 'nvim-treesitter'.get_node_api() +local ts_utils = require 'nvim-treesitter.ts_utils' ``` - -You can also retrieve the current state of the current buffer with: -```lua -local buf_state = require'nvim-treesitter'.get_buf_state() -``` - -More information is available in neovim documentation (`:help nvim-treesitter-api`). +More information is available in neovim documentation (`:help nvim-treesitter-utils`). ## Supported Languages diff --git a/doc/nvim-treesitter.txt b/doc/nvim-treesitter.txt index f1c278427..27e4f0bb5 100644 --- a/doc/nvim-treesitter.txt +++ b/doc/nvim-treesitter.txt @@ -91,26 +91,28 @@ A list of languages can be found at |:TSInstallInfo| List modules state for the current session. ============================================================================== -API *nvim-treesitter-api* +UTILS *nvim-treesitter-utils* -Nvim treesitter exposes extended functions to use on nodes and scopes. -you can retrieve the api with: +Nvim treesitter has some wrapper functions that you can retrieve with: > - local ts_node_api = require 'nvim-treesitter'.get_node_api() + local ts_utils = require 'nvim-treesitter.ts_utils' < Methods -get_node_text(node, bufnr) *ts_api.get_node_text* +get_node_at_cursor() *ts_utils.get_node_at_cursor* + returns the node under the cursor + +get_node_text(node, bufnr) *ts_utils.get_node_text* return the text content of a node -is_parent(dest, source) *ts_api.is_parent* +is_parent(dest, source) *ts_utils.is_parent* determines wether `dest` is a parent of `source` return a boolean -get_named_children(node) *ts_api.get_named_children* +get_named_children(node) *ts_utils.get_named_children* return a table of named children of `node` -get_next_node(node, allow_switch_parent, allow_next_parent) *ts_api.get_next_node* +get_next_node(node, allow_switch_parent, allow_next_parent) *ts_utils.get_next_node* return the next node within the same parent. if no node is found, returns `nil`. if `allow_switch_parent` is true, it will allow switching parent @@ -118,42 +120,28 @@ get_next_node(node, allow_switch_parent, allow_next_parent) *ts_api.get_next_nod if `allow_next_parent` is true, it will allow next parent if the node is the last node and the next parent doesn't have children. -get_previous_node(node, allow_switch_parents, allow_prev_parent) *ts_api.get_previous_node* +get_previous_node(node, allow_switch_parents, allow_prev_parent) *ts_utils.get_previous_node* return the previous node within the same parent. `allow_switch_parent` and `allow_prev_parent` follow the same rule - as |ts_api.get_next_node| but if the node is the first node. + as |ts_utils.get_next_node| but if the node is the first node. -containing_scope(node) *ts_api.containing_scope* +containing_scope(node) *ts_utils.containing_scope* return the smallest scope containing the node -parent_scope(node, cursor_pos) *ts_api.parent_scope* +parent_scope(node, cursor_pos) *ts_utils.parent_scope* return the parent scope of the current scope that contains the node. `cursor_pos` should be `{ row = number, col = number }` - you can retrieve the cursor_pos with the buffer state -nested_scope(node, cursor_pos) *ts_api.nested_scope* +nested_scope(node, cursor_pos) *ts_utils.nested_scope* return the first scope within current scope that contains the node. `cursor_pos` should be `{ row = number, col = number }` - you can retrieve the cursor_pos with the buffer state -next_scope(node) *ts_api.next_scope* +next_scope(node) *ts_utils.next_scope* return the neighbour scope of the current node -previous_scope(node) *ts_api.previous_scope* +previous_scope(node) *ts_utils.previous_scope* return the previous neighbour scope of the current node -Nvim-treesitter also provides access to the state of the current buffer: -> - local cur_buf_state = require'nvim-treesitter'.get_buf_state() - print(vim.inspect(cur_buf_state)) - --[[ - { - cursor_pos = { row = number, col = number }, (current cursor pos in the buffer) - current_node = tsnode (smallest node the cursor is on) - } - ]]-- -< - ============================================================================== FUNCTIONS *nvim-treesitter-functions* diff --git a/doc/tags b/doc/tags index 0a12b18d5..df33c4d43 100644 --- a/doc/tags +++ b/doc/tags @@ -6,20 +6,21 @@ :TSInstallInfo nvim-treesitter.txt /*:TSInstallInfo* :TSModuleInfo nvim-treesitter.txt /*:TSModuleInfo* nvim-treesitter nvim-treesitter.txt /*nvim-treesitter* -nvim-treesitter-api nvim-treesitter.txt /*nvim-treesitter-api* nvim-treesitter-commands nvim-treesitter.txt /*nvim-treesitter-commands* nvim-treesitter-functions nvim-treesitter.txt /*nvim-treesitter-functions* nvim-treesitter-intro nvim-treesitter.txt /*nvim-treesitter-intro* nvim-treesitter-quickstart nvim-treesitter.txt /*nvim-treesitter-quickstart* +nvim-treesitter-utils nvim-treesitter.txt /*nvim-treesitter-utils* nvim_treesitter#foldexpr() nvim-treesitter.txt /*nvim_treesitter#foldexpr()* nvim_treesitter#statusline() nvim-treesitter.txt /*nvim_treesitter#statusline()* -ts_api.containing_scope nvim-treesitter.txt /*ts_api.containing_scope* -ts_api.get_named_children nvim-treesitter.txt /*ts_api.get_named_children* -ts_api.get_next_node nvim-treesitter.txt /*ts_api.get_next_node* -ts_api.get_node_text nvim-treesitter.txt /*ts_api.get_node_text* -ts_api.get_previous_node nvim-treesitter.txt /*ts_api.get_previous_node* -ts_api.is_parent nvim-treesitter.txt /*ts_api.is_parent* -ts_api.nested_scope nvim-treesitter.txt /*ts_api.nested_scope* -ts_api.next_scope nvim-treesitter.txt /*ts_api.next_scope* -ts_api.parent_scope nvim-treesitter.txt /*ts_api.parent_scope* -ts_api.previous_scope nvim-treesitter.txt /*ts_api.previous_scope* +ts_utils.containing_scope nvim-treesitter.txt /*ts_utils.containing_scope* +ts_utils.get_named_children nvim-treesitter.txt /*ts_utils.get_named_children* +ts_utils.get_next_node nvim-treesitter.txt /*ts_utils.get_next_node* +ts_utils.get_node_at_cursor nvim-treesitter.txt /*ts_utils.get_node_at_cursor* +ts_utils.get_node_text nvim-treesitter.txt /*ts_utils.get_node_text* +ts_utils.get_previous_node nvim-treesitter.txt /*ts_utils.get_previous_node* +ts_utils.is_parent nvim-treesitter.txt /*ts_utils.is_parent* +ts_utils.nested_scope nvim-treesitter.txt /*ts_utils.nested_scope* +ts_utils.next_scope nvim-treesitter.txt /*ts_utils.next_scope* +ts_utils.parent_scope nvim-treesitter.txt /*ts_utils.parent_scope* +ts_utils.previous_scope nvim-treesitter.txt /*ts_utils.previous_scope* From cf72524b2f7e3868ea74037004913af6f935f126 Mon Sep 17 00:00:00 2001 From: kiyan42 Date: Fri, 19 Jun 2020 14:13:23 +0200 Subject: [PATCH 23/51] add winnr to get_node_at_cursor --- README.md | 2 +- doc/nvim-treesitter.txt | 3 ++- lua/nvim-treesitter/ts_utils.lua | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b2193103a..787a2a200 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ you can get some utility functions with ```lua local ts_utils = require 'nvim-treesitter.ts_utils' ``` -More information is available in neovim documentation (`:help nvim-treesitter-utils`). +More information is available in the help file (`:help nvim-treesitter-utils`). ## Supported Languages diff --git a/doc/nvim-treesitter.txt b/doc/nvim-treesitter.txt index 27e4f0bb5..bb53e182e 100644 --- a/doc/nvim-treesitter.txt +++ b/doc/nvim-treesitter.txt @@ -99,7 +99,8 @@ Nvim treesitter has some wrapper functions that you can retrieve with: < Methods -get_node_at_cursor() *ts_utils.get_node_at_cursor* +get_node_at_cursor(winnr) *ts_utils.get_node_at_cursor* + winnr will be 0 if nil returns the node under the cursor get_node_text(node, bufnr) *ts_utils.get_node_text* diff --git a/lua/nvim-treesitter/ts_utils.lua b/lua/nvim-treesitter/ts_utils.lua index a85934c0b..687a3c539 100644 --- a/lua/nvim-treesitter/ts_utils.lua +++ b/lua/nvim-treesitter/ts_utils.lua @@ -206,8 +206,8 @@ function M.previous_scope(node) end end -function M.get_node_at_cursor() - local cursor = api.nvim_win_get_cursor(0) +function M.get_node_at_cursor(winnr) + local cursor = api.nvim_win_get_cursor(winnr or 0) local root = parsers.get_parser().tree:root() return root:named_descendant_for_range(cursor[1]-1,cursor[2],cursor[1]-1,cursor[2]) end From ad636f4f5306b7741bc55ad63e6b12f9379a2515 Mon Sep 17 00:00:00 2001 From: kiyan42 Date: Fri, 19 Jun 2020 14:22:43 +0200 Subject: [PATCH 24/51] fix: declare parse names as their appropriate filetype and change clone url --- lua/nvim-treesitter/configs.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lua/nvim-treesitter/configs.lua b/lua/nvim-treesitter/configs.lua index 633f9d21c..4942fac78 100644 --- a/lua/nvim-treesitter/configs.lua +++ b/lua/nvim-treesitter/configs.lua @@ -61,9 +61,9 @@ parserlist.ruby = { } } -parserlist.bash = { +parserlist.sh = { install_info = { - url = "https://github.com/tree-sitter/tree-sitter-bash", + url = "https://github.com/nvim-treesitter/tree-sitter-bash", files = { "src/parser.c", "src/scanner.cc" }, } } @@ -124,9 +124,9 @@ parserlist.swift = { } } -parserlist.csharp = { +parserlist.cs = { install_info = { - url = "https://github.com/tree-sitter/tree-sitter-c-sharp", + url = "https://github.com/nvim-treesitter/tree-sitter-c-sharp", files = { "src/parser.c", "src/scanner.c" }, } } @@ -139,9 +139,9 @@ parserlist.typescript = { } } -parserlist.tsx = { +parserlist.typescriptreact = { install_info = { - url = "https://github.com/tree-sitter/tree-sitter-typescript", + url = "https://github.com/nvim-treesitter/tree-sitter-typescript", files = { "src/parser.c", "src/scanner.c" }, location = "tree-sitter-tsx/tsx" } From df17a48c85b8e47bc4982b640dbb686e372cd81e Mon Sep 17 00:00:00 2001 From: kiyan42 Date: Sat, 20 Jun 2020 12:21:42 +0200 Subject: [PATCH 25/51] refactor: parser list and lang->ft/ft->lang - move parser list in `parsers.lua` - most `ft` variable where changed to `lang`, `ft` is only used on autocmd binding, and lang is used for everything else. Functions have been defined to make the switch between `ft` and `lang` --- lua/nvim-treesitter.lua | 6 +- lua/nvim-treesitter/configs.lua | 295 +++++------------------------- lua/nvim-treesitter/health.lua | 4 +- lua/nvim-treesitter/highlight.lua | 11 +- lua/nvim-treesitter/info.lua | 7 +- lua/nvim-treesitter/install.lua | 11 +- lua/nvim-treesitter/parsers.lua | 244 +++++++++++++++++++++++- lua/nvim-treesitter/query.lua | 8 +- plugin/nvim-treesitter.vim | 2 +- 9 files changed, 311 insertions(+), 277 deletions(-) diff --git a/lua/nvim-treesitter.lua b/lua/nvim-treesitter.lua index d3c7fa75f..dde4ac0fd 100644 --- a/lua/nvim-treesitter.lua +++ b/lua/nvim-treesitter.lua @@ -5,6 +5,7 @@ local utils = require'nvim-treesitter.utils' local ts_utils = require'nvim-treesitter.ts_utils' local info = require'nvim-treesitter.info' local configs = require'nvim-treesitter.configs' +local parsers = require'nvim-treesitter.parsers' local M = {} @@ -13,9 +14,10 @@ function M.setup() utils.setup_commands('info', info.commands) utils.setup_commands('configs', configs.commands) - for _, ft in pairs(configs.available_parsers()) do + for _, lang in pairs(parsers.available_parsers()) do for _, mod in pairs(configs.available_modules()) do - if configs.is_enabled(mod, ft) then + if configs.is_enabled(mod, lang) then + local ft = parsers.lang_to_ft(lang) local cmd = string.format("lua require'nvim-treesitter.%s'.attach()", mod) api.nvim_command(string.format("autocmd NvimTreesitter FileType %s %s", ft, cmd)) end diff --git a/lua/nvim-treesitter/configs.lua b/lua/nvim-treesitter/configs.lua index 4942fac78..ecad20136 100644 --- a/lua/nvim-treesitter/configs.lua +++ b/lua/nvim-treesitter/configs.lua @@ -3,213 +3,6 @@ local api = vim.api local queries = require'nvim-treesitter.query' local parsers = require'nvim-treesitter.parsers' -local parserlist = {} - -parserlist.javascript = { - install_info = { - url = "https://github.com/tree-sitter/tree-sitter-javascript", - files = { "src/parser.c", "src/scanner.c" }, - } -} - -parserlist.c = { - install_info = { - url = "https://github.com/tree-sitter/tree-sitter-c", - files = { "src/parser.c" } - } -} - -parserlist.cpp = { - install_info = { - url = "https://github.com/tree-sitter/tree-sitter-cpp", - files = { "src/parser.c", "src/scanner.cc" } - } -} - -parserlist.rust = { - install_info = { - url = "https://github.com/tree-sitter/tree-sitter-rust", - files = { "src/parser.c", "src/scanner.c" }, - } -} - -parserlist.lua = { - install_info = { - url = "https://github.com/nvim-treesitter/tree-sitter-lua", - files = { "src/parser.c", "src/scanner.cc" } - } -} - -parserlist.python = { - install_info = { - url = "https://github.com/tree-sitter/tree-sitter-python", - files = { "src/parser.c", "src/scanner.cc" }, - } -} - -parserlist.go = { - install_info = { - url = "https://github.com/tree-sitter/tree-sitter-go", - files = { "src/parser.c" }, - } -} - -parserlist.ruby = { - install_info = { - url = "https://github.com/tree-sitter/tree-sitter-ruby", - files = { "src/parser.c", "src/scanner.cc" }, - } -} - -parserlist.sh = { - install_info = { - url = "https://github.com/nvim-treesitter/tree-sitter-bash", - files = { "src/parser.c", "src/scanner.cc" }, - } -} - -parserlist.php = { - install_info = { - url = "https://github.com/tree-sitter/tree-sitter-php", - files = { "src/parser.c", "src/scanner.cc" }, - } -} - -parserlist.java = { - install_info = { - url = "https://github.com/tree-sitter/tree-sitter-java", - files = { "src/parser.c" }, - } -} - -parserlist.html = { - install_info = { - url = "https://github.com/tree-sitter/tree-sitter-html", - files = { "src/parser.c", "src/scanner.cc" }, - } -} - -parserlist.julia = { - install_info = { - url = "https://github.com/tree-sitter/tree-sitter-julia", - files = { "src/parser.c", "src/scanner.c" }, - } -} - -parserlist.json = { - install_info = { - url = "https://github.com/tree-sitter/tree-sitter-json", - files = { "src/parser.c" }, - } -} - -parserlist.css = { - install_info = { - url = "https://github.com/tree-sitter/tree-sitter-css", - files = { "src/parser.c", "src/scanner.c" }, - } -} - -parserlist.ocaml = { - install_info = { - url = "https://github.com/tree-sitter/tree-sitter-ocaml", - files = { "src/parser.c", "src/scanner.cc" }, - } -} - -parserlist.swift = { - install_info = { - url = "https://github.com/tree-sitter/tree-sitter-swift", - files = { "src/parser.c" }, - } -} - -parserlist.cs = { - install_info = { - url = "https://github.com/nvim-treesitter/tree-sitter-c-sharp", - files = { "src/parser.c", "src/scanner.c" }, - } -} - -parserlist.typescript = { - install_info = { - url = "https://github.com/tree-sitter/tree-sitter-typescript", - files = { "src/parser.c", "src/scanner.c" }, - location = "tree-sitter-typescript/typescript" - } -} - -parserlist.typescriptreact = { - install_info = { - url = "https://github.com/nvim-treesitter/tree-sitter-typescript", - files = { "src/parser.c", "src/scanner.c" }, - location = "tree-sitter-tsx/tsx" - } -} - -parserlist.scala = { - install_info = { - url = "https://github.com/tree-sitter/tree-sitter-scala", - files = { "src/parser.c", "src/scanner.c" }, - } -} - -parserlist.haskell = { - install_info = { - url = "https://github.com/tree-sitter/tree-sitter-haskell", - files = { "src/parser.c", "src/scanner.cc" }, - } -} - -parserlist.markdown = { - install_info = { - url = "https://github.com/ikatyang/tree-sitter-markdown", - files = { "src/parser.c", "src/scanner.cc" }, - } -} - -parserlist.toml = { - install_info = { - url = "https://github.com/ikatyang/tree-sitter-toml", - files = { "src/parser.c", "src/scanner.c" }, - } -} - -parserlist.vue = { - install_info = { - url = "https://github.com/ikatyang/tree-sitter-vue", - files = { "src/parser.c", "src/scanner.cc" }, - } -} - -parserlist.elm = { - install_info = { - url = "https://github.com//razzeee/tree-sitter-elm", - files = { "src/parser.c", "src/scanner.cc" }, - } -} - -parserlist.yaml = { - install_info = { - url = "https://github.com/ikatyang/tree-sitter-yaml", - files = { "src/parser.c", "src/scanner.cc" }, - } -} - -parserlist.nix = { - install_info = { - url = "https://github.com/cstrahan/tree-sitter-nix", - files = { "src/parser.c", "src/scanner.cc" }, - } -} - -parserlist.regex = { - install_info = { - url = "https://github.com/tree-sitter/tree-sitter-regex", - files = { "src/parser.c" } - } -} - -- @enable can be true or false -- @disable is a list of languages, only relevant if enable is true -- @keymaps list of user mappings for a given module if relevant @@ -219,8 +12,8 @@ local config = { highlight = { enable = false, disable = {}, - is_supported = function(ft) - return queries.get_query(ft, 'highlights') ~= nil + is_supported = function(lang) + return queries.get_query(lang, 'highlights') ~= nil end }, incremental_selection = { @@ -232,8 +25,8 @@ local config = { scope_incremental="grc", node_decremental="grm" }, - is_supported = function(ft) - return queries.get_query(ft, 'locals') + is_supported = function(lang) + return queries.get_query(lang, 'locals') end } }, @@ -242,56 +35,62 @@ local config = { local M = {} -local function enable_module(mod, bufnr, ft) +local function enable_module(mod, bufnr, lang) local bufnr = bufnr or api.nvim_get_current_buf() - local ft = ft or api.nvim_buf_get_option(bufnr, 'ft') - if not parserlist[ft] or not config.modules[mod] then + local lang = lang or parsers.ft_to_lang(api.nvim_buf_get_option(bufnr, 'ft')) + if not parsers.list[lang] or not config.modules[mod] then return end local loaded_mod = require(string.format("nvim-treesitter.%s", mod)) - loaded_mod.attach(bufnr, ft) + loaded_mod.attach(bufnr, lang) end -local function enable_mod_conf_autocmd(mod, ft) - if not config.modules[mod] or M.is_enabled(mod, ft) then return end +local function enable_mod_conf_autocmd(mod, lang) + if not config.modules[mod] or M.is_enabled(mod, lang) then return end + local ft = parsers.lang_to_ft(lang) local cmd = string.format("lua require'nvim-treesitter.%s'.attach()", mod) api.nvim_command(string.format("autocmd FileType %s %s", ft, cmd)) for i, parser in pairs(config.modules[mod].disable) do - if parser == ft then + if parser == lang then table.remove(config.modules[mod].disable, i) break end end end -local function enable_all(mod, ft) +local function enable_all(mod, lang) if not config.modules[mod] then return end for _, bufnr in pairs(api.nvim_list_bufs()) do - if not ft or api.nvim_buf_get_option(bufnr, 'ft') == ft then - enable_module(mod, bufnr, ft) + local ft = api.nvim_buf_get_option(bufnr, 'ft') + if not lang or ft == parsers.lang_to_ft(lang) then + enable_module(mod, bufnr, lang) end end - if ft then - if parsers.has_parser(ft) then - enable_mod_conf_autocmd(mod, ft) + if lang then + if parsers.has_parser(lang) then + enable_mod_conf_autocmd(mod, lang) end else - for _, ft in pairs(M.available_parsers()) do - if parsers.has_parser(ft) then - enable_mod_conf_autocmd(mod, ft) + for _, lang in pairs(parsers.available_parsers()) do + if parsers.has_parser(lang) then + enable_mod_conf_autocmd(mod, lang) end end end config.modules[mod].enable = true end -local function disable_module(mod, bufnr, ft) +local function disable_module(mod, bufnr, lang) local bufnr = bufnr or api.nvim_get_current_buf() - local ft = ft or api.nvim_buf_get_option(bufnr, 'ft') - if not parserlist[ft] or not config.modules[mod] then + local lang = lang or parsers.ft_to_lang(api.nvim_buf_get_option(bufnr, 'ft')) + if not lang then + return + end + + if not parsers.list[lang] or not config.modules[mod] then return end @@ -299,24 +98,26 @@ local function disable_module(mod, bufnr, ft) loaded_mod.detach(bufnr, ft) end -local function disable_mod_conf_autocmd(mod, ft) - if not config.modules[mod] or not M.is_enabled(mod, ft) then return end +local function disable_mod_conf_autocmd(mod, lang) + if not config.modules[mod] or not M.is_enabled(mod, lang) then return end + local ft = parsers.lang_to_ft(lang) api.nvim_command(string.format("autocmd! FileType %s", ft)) - table.insert(config.modules[mod].disable, ft) + table.insert(config.modules[mod].disable, lang) end -local function disable_all(mod, ft) +local function disable_all(mod, lang) for _, bufnr in pairs(api.nvim_list_bufs()) do - if not ft or api.nvim_buf_get_option(bufnr, 'ft') == ft then - disable_module(mod, bufnr, ft) + local ft = api.nvim_buf_get_option(bufnr, 'ft') + if not lang or ft == parsers.lang_to_ft(lang) then + disable_module(mod, bufnr, lang) end end - if ft then - disable_mod_conf_autocmd(mod, ft) + if lang then + disable_mod_conf_autocmd(mod, lang) else - for _, ft in pairs(M.available_parsers()) do - disable_mod_conf_autocmd(mod, ft) + for _, lang in pairs(parsers.available_parsers()) do + disable_mod_conf_autocmd(mod, lang) end config.modules[mod].enable = false end @@ -359,15 +160,15 @@ M.commands = { -- @param mod: module (string) -- @param ft: filetype (string) -function M.is_enabled(mod, ft) - if not M.get_parser_configs()[ft] or not parsers.has_parser(ft) then +function M.is_enabled(mod, lang) + if not parsers.list[lang] or not parsers.has_parser(lang) then return false end local module_config = config.modules[mod] if not module_config then return false end - if not module_config.enable or not module_config.is_supported(ft) then + if not module_config.enable or not module_config.is_supported(lang) then return false end @@ -403,14 +204,6 @@ function M.setup(user_data) end end -function M.get_parser_configs() - return parserlist -end - -function M.available_parsers() - return vim.tbl_keys(parserlist) -end - function M.available_modules() return vim.tbl_keys(config.modules) end diff --git a/lua/nvim-treesitter/health.lua b/lua/nvim-treesitter/health.lua index ca1e765c7..e73ce7fb5 100644 --- a/lua/nvim-treesitter/health.lua +++ b/lua/nvim-treesitter/health.lua @@ -4,7 +4,7 @@ local fn = vim.fn local queries = require'nvim-treesitter.query' local locals = require'nvim-treesitter.locals' local highlight = require'nvim-treesitter.highlight' -local configs = require'nvim-treesitter.configs' +local parsers = require'nvim-treesitter.parsers' local health_start = vim.fn["health#report_start"] local health_ok = vim.fn['health#report_ok'] @@ -62,7 +62,7 @@ function M.checkhealth() local missing_parsers = {} -- Parser installation checks - for _, parser_name in pairs(configs.available_parsers()) do + for _, parser_name in pairs(parsers.available_parsers()) do local installed = #api.nvim_get_runtime_file('parser/'..parser_name..'.so', false) -- Only print informations about installed parsers diff --git a/lua/nvim-treesitter/highlight.lua b/lua/nvim-treesitter/highlight.lua index ac46010bb..a6c3275f7 100644 --- a/lua/nvim-treesitter/highlight.lua +++ b/lua/nvim-treesitter/highlight.lua @@ -2,6 +2,7 @@ local api = vim.api local ts = vim.treesitter local queries = require'nvim-treesitter.query' +local parsers = require'nvim-treesitter.parsers' local M = { highlighters = {} @@ -49,14 +50,14 @@ hlmap["type.builtin"] = "Type" hlmap["structure"] = "Structure" hlmap["include"] = "Include" -function M.attach(bufnr, ft) - local buf = bufnr or api.nvim_get_current_buf() - local ft = ft or api.nvim_buf_get_option(buf, 'ft') +function M.attach(bufnr, lang) + local bufnr = bufnr or api.nvim_get_current_buf() + local lang = lang or parsers.ft_to_lang(api.nvim_buf_get_option(bufnr, 'ft')) - local query = queries.get_query(ft, "highlights") + local query = queries.get_query(lang, "highlights") if not query then return end - M.highlighters[buf] = ts.TSHighlighter.new(query, buf, ft) + M.highlighters[bufnr] = ts.TSHighlighter.new(query, bufnr, lang) end function M.detach(bufnr) diff --git a/lua/nvim-treesitter/info.lua b/lua/nvim-treesitter/info.lua index 18b1b611f..ba1812e42 100644 --- a/lua/nvim-treesitter/info.lua +++ b/lua/nvim-treesitter/info.lua @@ -1,15 +1,16 @@ local api = vim.api local configs = require'nvim-treesitter.configs' +local parsers = require'nvim-treesitter.parsers' local M = {} local function install_info() local max_len = 0 - for _, ft in pairs(configs.available_parsers()) do + for _, ft in pairs(parsers.available_parsers()) do if #ft > max_len then max_len = #ft end end - for _, ft in pairs(configs.available_parsers()) do + for _, ft in pairs(parsers.available_parsers()) do local is_installed = #api.nvim_get_runtime_file('parser/'..ft..'.so', false) > 0 api.nvim_out_write(ft..string.rep(' ', max_len - #ft + 1)) if is_installed then @@ -66,7 +67,7 @@ end local function module_info(mod) if mod and not configs.get_config()[mod] then return end - local ft_by_len = configs.available_parsers() + local ft_by_len = parsers.available_parsers() table.sort(ft_by_len, function(a, b) return #a > #b end) if mod then print_info_module(ft_by_len, mod) diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua index 381afaa4a..c2eeaf763 100644 --- a/lua/nvim-treesitter/install.lua +++ b/lua/nvim-treesitter/install.lua @@ -2,7 +2,6 @@ local api = vim.api local fn = vim.fn local luv = vim.loop -local configs = require'nvim-treesitter.configs' local utils = require'nvim-treesitter.utils' local parsers = require'nvim-treesitter.parsers' @@ -103,7 +102,7 @@ local function install(...) if not string.match(yesno, '^y.*') then return end end - local parser_config = configs.get_parser_configs()[ft] + local parser_config = parsers.get_parser_configs()[ft] if not parser_config then return api.nvim_err_writeln('Parser not available for language '..ft) end @@ -122,15 +121,15 @@ end M.ensure_installed = function(languages) if type(languages) == 'string' then if languages == 'all' then - languages = configs.available_parsers() + languages = parsers.available_parsers() else languages = {languages} end end - for _, ft in ipairs(languages) do - if not parsers.has_parser(ft) then - install(ft) + for _, lang in ipairs(languages) do + if not parsers.has_parser(lang) then + install(lang) end end end diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua index 3789b7afe..ae0fce277 100644 --- a/lua/nvim-treesitter/parsers.lua +++ b/lua/nvim-treesitter/parsers.lua @@ -1,17 +1,255 @@ local api = vim.api local ts = vim.treesitter -local M = {} +local list = {} + +list.javascript = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-javascript", + files = { "src/parser.c", "src/scanner.c" }, + } +} + +list.c = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-c", + files = { "src/parser.c" } + } +} + +list.cpp = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-cpp", + files = { "src/parser.c", "src/scanner.cc" } + } +} + +list.rust = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-rust", + files = { "src/parser.c", "src/scanner.c" }, + } +} + +list.lua = { + install_info = { + url = "https://github.com/nvim-treesitter/tree-sitter-lua", + files = { "src/parser.c", "src/scanner.cc" } + } +} + +list.python = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-python", + files = { "src/parser.c", "src/scanner.cc" }, + } +} + +list.go = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-go", + files = { "src/parser.c" }, + } +} + +list.ruby = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-ruby", + files = { "src/parser.c", "src/scanner.cc" }, + } +} + +list.bash = { + install_info = { + url = "https://github.com/nvim-treesitter/tree-sitter-bash", + files = { "src/parser.c", "src/scanner.cc" }, + }, + filetype = 'sh' +} + +list.php = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-php", + files = { "src/parser.c", "src/scanner.cc" }, + } +} + +list.java = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-java", + files = { "src/parser.c" }, + } +} + +list.html = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-html", + files = { "src/parser.c", "src/scanner.cc" }, + } +} + +list.julia = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-julia", + files = { "src/parser.c", "src/scanner.c" }, + } +} + +list.json = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-json", + files = { "src/parser.c" }, + } +} + +list.css = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-css", + files = { "src/parser.c", "src/scanner.c" }, + } +} + +list.ocaml = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-ocaml", + files = { "src/parser.c", "src/scanner.cc" }, + } +} + +list.swift = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-swift", + files = { "src/parser.c" }, + } +} + +list.c_sharp = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-c-sharp", + files = { "src/parser.c", "src/scanner.c" }, + }, + filetype = 'cs' +} + +list.typescript = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-typescript", + files = { "src/parser.c", "src/scanner.c" }, + location = "tree-sitter-typescript/typescript" + } +} + +list.tsx = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-typescript", + files = { "src/parser.c", "src/scanner.c" }, + location = "tree-sitter-tsx/tsx" + }, + filetype = 'typescriptreact' +} + +list.scala = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-scala", + files = { "src/parser.c", "src/scanner.c" }, + } +} + +list.haskell = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-haskell", + files = { "src/parser.c", "src/scanner.cc" }, + } +} + +list.markdown = { + install_info = { + url = "https://github.com/ikatyang/tree-sitter-markdown", + files = { "src/parser.c", "src/scanner.cc" }, + } +} + +list.toml = { + install_info = { + url = "https://github.com/ikatyang/tree-sitter-toml", + files = { "src/parser.c", "src/scanner.c" }, + } +} + +list.vue = { + install_info = { + url = "https://github.com/ikatyang/tree-sitter-vue", + files = { "src/parser.c", "src/scanner.cc" }, + } +} + +list.elm = { + install_info = { + url = "https://github.com//razzeee/tree-sitter-elm", + files = { "src/parser.c", "src/scanner.cc" }, + } +} + +list.yaml = { + install_info = { + url = "https://github.com/ikatyang/tree-sitter-yaml", + files = { "src/parser.c", "src/scanner.cc" }, + } +} + +list.nix = { + install_info = { + url = "https://github.com/cstrahan/tree-sitter-nix", + files = { "src/parser.c", "src/scanner.cc" }, + } +} + +list.regex = { + install_info = { + url = "https://github.com/tree-sitter/tree-sitter-regex", + files = { "src/parser.c" } + } +} + +local M = { + list = list +} + +local ft_to_parsername = {} +for name, obj in pairs(M.list) do + if obj.filetype then + ft_to_parsername[obj.filetype] = name + else + ft_to_parsername[name] = name + end +end + +function M.ft_to_lang(ft) + return ft_to_parsername[ft] +end + +function M.lang_to_ft(lang) + return M.list[lang].filetype or lang +end + +function M.available_parsers() + return vim.tbl_keys(M.list) +end + +function M.get_parser_configs() + return M.list +end function M.has_parser(lang) - local lang = lang or api.nvim_buf_get_option(0, 'filetype') + local buf = api.nvim_get_current_buf() + local lang = lang or M.ft_to_lang(api.nvim_buf_get_option(buf, 'ft')) if not lang or #lang == 0 then return false end return #api.nvim_get_runtime_file('parser/' .. lang .. '.*', false) > 0 end function M.get_parser(bufnr, lang) local buf = bufnr or api.nvim_get_current_buf() - local lang = lang or api.nvim_buf_get_option(buf, 'ft') + local lang = lang or M.ft_to_lang(api.nvim_buf_get_option(buf, 'ft')) if M.has_parser(lang) then if not M[buf] then diff --git a/lua/nvim-treesitter/query.lua b/lua/nvim-treesitter/query.lua index bd0f4c542..97a82fc46 100644 --- a/lua/nvim-treesitter/query.lua +++ b/lua/nvim-treesitter/query.lua @@ -21,15 +21,15 @@ M.base_language_map = { tsx = {'typescript', 'javascript'}, } -function M.get_query(ft, query_name) - local query_files = api.nvim_get_runtime_file(string.format('queries/%s/%s.scm', ft, query_name), true) +function M.get_query(lang, query_name) + local query_files = api.nvim_get_runtime_file(string.format('queries/%s/%s.scm', lang, query_name), true) local query_string = '' if #query_files > 0 then query_string = read_query_files(query_files)..query_string end - for _, base_lang in ipairs(M.base_language_map[ft] or {}) do + for _, base_lang in ipairs(M.base_language_map[lang] or {}) do local base_files = api.nvim_get_runtime_file(string.format('queries/%s/%s.scm', base_lang, query_name), true) if base_files and #base_files > 0 then query_string = read_query_files(base_files)..query_string @@ -37,7 +37,7 @@ function M.get_query(ft, query_name) end if #query_string > 0 then - return ts.parse_query(ft, query_string) + return ts.parse_query(lang, query_string) end end diff --git a/plugin/nvim-treesitter.vim b/plugin/nvim-treesitter.vim index 30ee3241d..4769680a3 100644 --- a/plugin/nvim-treesitter.vim +++ b/plugin/nvim-treesitter.vim @@ -11,7 +11,7 @@ let g:loaded_nvim_treesitter = 1 lua << EOF ts_installable_parsers = function() - return table.concat(require'nvim-treesitter.configs'.available_parsers(), '\n') + return table.concat(require'nvim-treesitter.parsers'.available_parsers(), '\n') end ts_available_modules = function() return table.concat(require'nvim-treesitter.configs'.available_modules(), '\n') From 0f836e060266c73e77871bd85b91f4159556035d Mon Sep 17 00:00:00 2001 From: TravonteD Date: Fri, 19 Jun 2020 09:59:27 -0400 Subject: [PATCH 26/51] refactor: use newly introduced consolidated syntax --- CONTRIBUTING.md | 2 + queries/css/highlights.scm | 125 ++++++++++++++---------- queries/html/highlights.scm | 11 ++- queries/ruby/highlights.scm | 188 ++++++++++++++++++++++-------------- queries/ruby/locals.scm | 6 +- 5 files changed, 197 insertions(+), 135 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5a8c74ee6..568a47e3b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -29,6 +29,7 @@ Here are some global advices : - If not, you should consider installing the [tree-sitter cli](https://github.com/tree-sitter/tree-sitter/tree/master/cli), you should then be able to open a local playground using `tree-sitter build-wasm && tree-sitter web-ui` within the parsers repo. + - An Example of somewhat complex highlight queries can be found in queries/ruby/highlights.scm (Maintained by @TravonteD) ### Highlights @@ -36,6 +37,7 @@ As languages differ quite a lot, here is a set of captures available to you when One important thing to note is that many of these capture groups are not supported by `neovim` for now, and will not have any effect on highlighting. We will work on improving highlighting in the near future though. + #### Misc `@comment` `@error` for error `(ERROR)` nodes. diff --git a/queries/css/highlights.scm b/queries/css/highlights.scm index 72009e765..1b876c4b1 100644 --- a/queries/css/highlights.scm +++ b/queries/css/highlights.scm @@ -1,72 +1,91 @@ -"@media" @keyword -"@import" @include -"@charset" @keyword -"@namespace" @keyword -"@supports" @keyword -"@keyframes" @keyword -(at_keyword) @keyword -(to) @keyword -(from) @keyword -(important) @keyword +[ + "@media" + "@import" + "@charset" + "@namespace" + "@supports" + "@keyframes" + (at_keyword) + (to) + (from) + (important) + ] @keyword (comment) @comment -(tag_name) @type -(nesting_selector) @type -(universal_selector) @type +[ + (tag_name) + (nesting_selector) + (universal_selector) + ] @type (function_name) @function -"~" @operator -">" @operator -"+" @operator -"-" @operator -"*" @operator -"/" @operator -"=" @operator -"^=" @operator -"|=" @operator -"~=" @operator -"$=" @operator -"*=" @operator +[ + "~" + ">" + "+" + "-" + "*" + "/" + "=" + "^=" + "|=" + "~=" + "$=" + "*=" + "and" + "or" + "not" + "only" + ] @operator -"and" @operator -"or" @operator -"not" @operator -"only" @operator (attribute_selector (plain_value) @string) (pseudo_element_selector (tag_name) @property) (pseudo_class_selector (class_name) @property) -(class_name) @property -(id_name) @property -(namespace_name) @property -(property_name) @property -(feature_name) @property -(attribute_name) @property +[ + (class_name) + (id_name) + (namespace_name) + (property_name) + (feature_name) + (attribute_name) + ] @property ((property_name) @type - (#match? @type "^--")) + (#match? @type "^--")) ((plain_value) @type - (#match? @type "^--")) + (#match? @type "^--")) -(string_value) @string -(color_value) @string -(identifier) @string +[ + (string_value) + (color_value) + (identifier) + (unit) + ] @string -(integer_value) @number -(float_value) @number -(unit) @string +[ + (integer_value) + (float_value) + ] @number -"#" @punctuation.delimiter -"," @punctuation.delimiter -"." @punctuation.delimiter -":" @punctuation.delimiter -"::" @punctuation.delimiter -";" @punctuation.delimiter -"{" @punctuation.bracket -")" @punctuation.bracket -"(" @punctuation.bracket -"}" @punctuation.bracket +[ + "#" + "," + "." + ":" + "::" + ";" + ] @punctuation.delimiter + +[ + "{" + ")" + "(" + "}" + ] @punctuation.bracket + +(ERROR) @error diff --git a/queries/html/highlights.scm b/queries/html/highlights.scm index 582e1e46f..1e83ecf4c 100644 --- a/queries/html/highlights.scm +++ b/queries/html/highlights.scm @@ -8,8 +8,9 @@ "=" @operator -"<" @punctuation.bracket -">" @punctuation.bracket -"" @punctuation.bracket - +[ + "<" + ">" + "" + ] @punctuation.bracket diff --git a/queries/ruby/highlights.scm b/queries/ruby/highlights.scm index 9e5852cdf..21afbe809 100644 --- a/queries/ruby/highlights.scm +++ b/queries/ruby/highlights.scm @@ -1,32 +1,41 @@ ; Keywords -"alias" @keyword -"and" @keyword -"begin" @keyword -"break" @keyword -"case" @conditional -"class" @keyword -"def" @keyword -"do" @keyword -"else" @conditional -"elsif" @conditional -"end" @keyword -"ensure" @keyword -"for" @repeat -"if" @conditional -"in" @keyword -"module" @keyword -"next" @keyword -"or" @keyword -"rescue" @keyword -"retry" @keyword -"return" @keyword -"then" @keyword -"unless" @conditional -"until" @repeat -"when" @conditional -"while" @repeat -"yield" @keyword +[ + "alias" + "and" + "begin" + "break" + "class" + "def" + "do" + "end" + "ensure" + "in" + "module" + "next" + "or" + "rescue" + "retry" + "return" + "then" + "yield" + ] @keyword + +[ + "case" + "else" + "elsif" + "if" + "unless" + "when" + ] @conditional + +[ + "for" + "until" + "while" + ] @repeat + ((identifier) @keyword (#match? @keyword "^(private|protected|public)$")) @@ -39,32 +48,45 @@ "defined?" @function (call - receiver: (constant) @constant) + [ + receiver: (constant) @constant + method: [ + (identifier) + (constant) + ] @function + ]) + (method_call - receiver: (constant) @constant) -(call - method: (identifier) @function) -(method_call - method: (identifier) @function) -(call - method: (constant) @function) -(method_call - method: (constant) @function) + [ + receiver: (constant) @constant + method: [ + (identifier) + (constant) + ] @function + ]) ; Function definitions (alias (identifier) @function) (setter (identifier) @function) -(method name: (identifier) @function) -(method name: (constant) @constant) + +(method name: [ + (identifier) @function + (constant) @constant + ]) + +(singleton_method name: [ + (identifier) @function + (constant) @constant + ]) + (class name: (constant) @constant) -(singleton_method name: (identifier) @function) -(singleton_method name: (constant) @constant) ; Identifiers - -(class_variable) @label -(instance_variable) @label +[ + (class_variable) + (instance_variable) + ] @label ((identifier) @constant.builtin (#match? @constant.builtin "^__(FILE|LINE|ENCODING)__$")) @@ -74,8 +96,10 @@ (constant) @constant -(self) @constant.builtin -(super) @constant.builtin +[ + (self) + (super) + ] @constant.builtin (method_parameters (identifier) @parameter) (lambda_parameters (identifier) @parameter) @@ -93,22 +117,30 @@ ; Literals -(string) @string -(bare_string) @string -(bare_symbol) @constant -(subshell) @string -(heredoc_beginning) @constant -(heredoc_body) @string -(heredoc_end) @constant -(symbol) @constant +[ + (string) + (bare_string) + (subshell) + (heredoc_body) + ] @string + +[ + (bare_symbol) + (heredoc_beginning) + (heredoc_end) + (symbol) + ] @constant + (regex) @string.regex (escape_sequence) @string.escape (integer) @number (float) @float -(nil) @boolean -(true) @boolean -(false) @boolean +[ + (nil) + (true) + (false) + ] @boolean (interpolation "#{" @punctuation.bracket @@ -118,25 +150,31 @@ ; Operators -"=" @operator -"=>" @operator -"->" @operator -"+" @operator -"-" @operator -"*" @operator -"/" @operator +[ + "=" + "=>" + "->" + "+" + "-" + "*" + "/" + ] @operator -"," @punctuation.delimiter -";" @punctuation.delimiter -"." @punctuation.delimiter +[ + "," + ";" + "." + ] @punctuation.delimiter -"(" @punctuation.bracket -")" @punctuation.bracket -"[" @punctuation.bracket -"]" @punctuation.bracket -"{" @punctuation.bracket -"}" @punctuation.bracket -"%w(" @punctuation.bracket -"%i(" @punctuation.bracket +[ + "(" + ")" + "[" + "]" + "{" + "}" + "%w(" + "%i(" + ] @punctuation.bracket (ERROR) @error diff --git a/queries/ruby/locals.scm b/queries/ruby/locals.scm index f50c2cc99..fe5122d2d 100644 --- a/queries/ruby/locals.scm +++ b/queries/ruby/locals.scm @@ -24,8 +24,10 @@ ((method) @scope (set! scope-inherits false)) -(block) @scope -(do_block) @scope +[ + (block) + (do_block) + ] @scope (method_parameters (identifier) @definition.function) (lambda_parameters (identifier) @definition.function) From 0b4d4b41408ff027888232f951000ca9d2e01fe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=81uczy=C5=84ski?= Date: Tue, 2 Jun 2020 15:59:13 +0200 Subject: [PATCH 27/51] Updated python highlights * allow for digits in constant names * removed redundant/conflicting rules * added missing hlmap * fixed escape_sequence * more explicit @constructor assignment * added rules for function decoration identifiers --- lua/nvim-treesitter/highlight.lua | 1 + queries/python/highlights.scm | 76 +++++++++++++------------------ 2 files changed, 32 insertions(+), 45 deletions(-) diff --git a/lua/nvim-treesitter/highlight.lua b/lua/nvim-treesitter/highlight.lua index ac46010bb..0086fcb0d 100644 --- a/lua/nvim-treesitter/highlight.lua +++ b/lua/nvim-treesitter/highlight.lua @@ -13,6 +13,7 @@ local hlmap = vim.treesitter.TSHighlighter.hl_map hlmap.error = "Error" hlmap["punctuation.delimiter"] = "Delimiter" hlmap["punctuation.bracket"] = "Delimiter" +hlmap["punctuation.special"] = "Delimiter" -- Constants hlmap["constant"] = "Constant" diff --git a/queries/python/highlights.scm b/queries/python/highlights.scm index 0b6e30033..cc11a5bd2 100644 --- a/queries/python/highlights.scm +++ b/queries/python/highlights.scm @@ -3,31 +3,32 @@ ; Identifier naming conventions - -((import_from_statement - name: (dotted_name - (identifier)) @type) - (match? @type "^[A-Z]")) - +(identifier) @Normal ((identifier) @type (match? @type "^[A-Z]")) - ((identifier) @constant - (match? @constant "^[A-Z][A-Z_]*$")) + (match? @constant "^[A-Z][A-Z_0-9]*$")) ; Function calls (decorator) @function +((decorator (dotted_name (identifier) @function)) + (match? @function "^([A-Z])@!.*$")) + +(call + function: (identifier) @function) (call function: (attribute attribute: (identifier) @method)) -(call - function: (identifier) @function) +((call + function: (identifier) @constructor) + (match? @constructor "^[A-Z]")) ((call - (identifier) @constructor) + function: (attribute + attribute: (identifier) @constructor)) (match? @constructor "^[A-Z]")) ;; Builtin functions @@ -43,10 +44,9 @@ (function_definition name: (identifier) @function) -(identifier) @variable -(attribute attribute: (identifier) @property) (type (identifier) @type) -((call + +((call function: (identifier) @isinstance arguments: (argument_list (*) @@ -55,7 +55,7 @@ ; Normal parameters (parameters - (identifier) @parameter) + (identifier) @parameter) ; Default parameters (keyword_argument name: (identifier) @parameter) @@ -65,10 +65,10 @@ ; Variadic parameters *args, **kwargs (parameters (list_splat ; *args - (identifier) @parameter)) + (identifier) @parameter)) (parameters (dictionary_splat ; **kwargs - (identifier) @parameter)) + (identifier) @parameter)) ; Literals @@ -84,11 +84,7 @@ (comment) @comment (string) @string -(escape_sequence) @escape - -(interpolation - "{" @punctuation.special - "}" @punctuation.special) @embedded +(escape_sequence) @string.escape ; Tokens @@ -164,46 +160,36 @@ ")" @punctuation.bracket "[" @punctuation.bracket "]" @punctuation.bracket +"{" @punctuation.bracket +"}" @punctuation.bracket + +(interpolation + "{" @punctuation.special + "}" @punctuation.special) @embedded "," @punctuation.delimiter "." @punctuation.delimiter ":" @punctuation.delimiter +; Class definitions + (class_definition name: (identifier) @type) (class_definition - superclasses: (argument_list + superclasses: (argument_list (identifier) @type)) -(attribute +((attribute attribute: (identifier) @field) - -((attribute - attribute: (identifier) @constant) - (match? @constant "^[A-Z][A-Z_]*$")) - -((attribute - attribute: (identifier) @type) - (match? @type "^[A-Z][a-z_]+")) - -((attribute - object: (identifier) @type) - (match? @type "^[A-Z][a-z_]+")) - -(class_definition - body: (block - (expression_statement - (assignment - left: (expression_list - (identifier) @field))))) + (match? @field "^([A-Z])@!.*$")) ((class_definition body: (block (expression_statement (assignment left: (expression_list - (identifier) @constant))))) - (match? @constant "^[A-Z][A-Z_]*$")) + (identifier) @field))))) + (match? @field "^([A-Z])@!.*$")) ;; Error (ERROR) @error From a85cf1a47c0acc6b22ed99b3228c827f5fb46927 Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Sun, 21 Jun 2020 17:00:17 +0200 Subject: [PATCH 28/51] Add highlighting of dunder identifiers (e.g. __all__, __add__) to Python highlights --- queries/python/highlights.scm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/queries/python/highlights.scm b/queries/python/highlights.scm index cc11a5bd2..c56897804 100644 --- a/queries/python/highlights.scm +++ b/queries/python/highlights.scm @@ -9,6 +9,9 @@ ((identifier) @constant (match? @constant "^[A-Z][A-Z_0-9]*$")) +((identifier) @constant.builtin + (match? @constant.builtin "^__[a-zA-Z0-9_]*__$")) + ; Function calls (decorator) @function From ec903ac99d07e0960d0acc71e70ba9809742bfbf Mon Sep 17 00:00:00 2001 From: Thomas Vigouroux Date: Sun, 21 Jun 2020 19:50:24 +0200 Subject: [PATCH 29/51] fix(statusline): don't call if no parser --- lua/nvim-treesitter.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/nvim-treesitter.lua b/lua/nvim-treesitter.lua index dde4ac0fd..9b3ddce89 100644 --- a/lua/nvim-treesitter.lua +++ b/lua/nvim-treesitter.lua @@ -26,6 +26,7 @@ function M.setup() end function M.statusline(indicator_size) + if not parsers.has_parser() then return end local indicator_size = indicator_size or 100 local current_node = ts_utils.get_node_at_cursor() From 171c7e4bcfd43ca8aef7f841013f0de47c76defd Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Sun, 21 Jun 2020 13:47:56 -0500 Subject: [PATCH 30/51] Fix bash parser url Not sure if this was on purpose or if it was a mistake --- lua/nvim-treesitter/parsers.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua index ae0fce277..9097d335d 100644 --- a/lua/nvim-treesitter/parsers.lua +++ b/lua/nvim-treesitter/parsers.lua @@ -61,7 +61,7 @@ list.ruby = { list.bash = { install_info = { - url = "https://github.com/nvim-treesitter/tree-sitter-bash", + url = "https://github.com/tree-sitter/tree-sitter-bash", files = { "src/parser.c", "src/scanner.cc" }, }, filetype = 'sh' From 895216014b83defa41f15118c1347b789d70e6fc Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Sun, 21 Jun 2020 17:39:58 +0200 Subject: [PATCH 31/51] Add disclaimer to README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 787a2a200..787a9adc9 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,9 @@ # nvim-treesitter Treesitter configurations and abstraction layer for Neovim. +**Warning: Treesitter and Treesitter highlighting are an experimental feature of nightly versions of Neovim. +Please consider the experience with this plug-in as experimental until Neovim 0.5 is released!** + # Quickstart ## Requirements From 3000b878fe7dc99f0bab9192a86e227000814895 Mon Sep 17 00:00:00 2001 From: Thomas Vigouroux Date: Sun, 21 Jun 2020 23:06:13 +0200 Subject: [PATCH 32/51] fix: separate queries with newlines --- lua/nvim-treesitter/query.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/nvim-treesitter/query.lua b/lua/nvim-treesitter/query.lua index 97a82fc46..42e835824 100644 --- a/lua/nvim-treesitter/query.lua +++ b/lua/nvim-treesitter/query.lua @@ -26,13 +26,13 @@ function M.get_query(lang, query_name) local query_string = '' if #query_files > 0 then - query_string = read_query_files(query_files)..query_string + query_string = read_query_files(query_files) .. "\n" .. query_string end for _, base_lang in ipairs(M.base_language_map[lang] or {}) do local base_files = api.nvim_get_runtime_file(string.format('queries/%s/%s.scm', base_lang, query_name), true) if base_files and #base_files > 0 then - query_string = read_query_files(base_files)..query_string + query_string = read_query_files(base_files) .. "\n" .. query_string end end From def8c20dd710d7ee6337af21012535cb860607ae Mon Sep 17 00:00:00 2001 From: kiyan42 Date: Mon, 22 Jun 2020 11:56:55 +0200 Subject: [PATCH 33/51] rename and finish ft->lang migration --- lua/nvim-treesitter/configs.lua | 4 ++-- lua/nvim-treesitter/info.lua | 32 ++++++++++++++++---------------- lua/nvim-treesitter/install.lua | 28 ++++++++++++++-------------- lua/nvim-treesitter/locals.lua | 8 ++++---- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/lua/nvim-treesitter/configs.lua b/lua/nvim-treesitter/configs.lua index ecad20136..f542e2609 100644 --- a/lua/nvim-treesitter/configs.lua +++ b/lua/nvim-treesitter/configs.lua @@ -95,7 +95,7 @@ local function disable_module(mod, bufnr, lang) end local loaded_mod = require(string.format("nvim-treesitter.%s", mod)) - loaded_mod.detach(bufnr, ft) + loaded_mod.detach(bufnr) end local function disable_mod_conf_autocmd(mod, lang) @@ -173,7 +173,7 @@ function M.is_enabled(mod, lang) end for _, parser in pairs(module_config.disable) do - if ft == parser then return false end + if lang == parser then return false end end return true diff --git a/lua/nvim-treesitter/info.lua b/lua/nvim-treesitter/info.lua index ba1812e42..c768595c4 100644 --- a/lua/nvim-treesitter/info.lua +++ b/lua/nvim-treesitter/info.lua @@ -21,14 +21,14 @@ local function install_info() end end -local function print_info_module(sorted_filetypes, mod) - local max_str_len = #sorted_filetypes[1] +local function print_info_module(sorted_languages, mod) + local max_str_len = #sorted_languages[1] local header = string.format('%s%s', string.rep(' ', max_str_len + 2), mod) api.nvim_out_write(header..'\n') - for _, ft in pairs(sorted_filetypes) do - local padding = string.rep(' ', max_str_len - #ft + #mod / 2 + 1) - api.nvim_out_write(ft..":"..padding) - if configs.is_enabled(mod, ft) then + for _, lang in pairs(sorted_languages) do + local padding = string.rep(' ', max_str_len - #lang + #mod / 2 + 1) + api.nvim_out_write(lang..":"..padding) + if configs.is_enabled(mod, lang) then api.nvim_out_write('✓') else api.nvim_out_write('✗') @@ -37,23 +37,23 @@ local function print_info_module(sorted_filetypes, mod) end end -local function print_info_modules(sorted_filetypes) - local max_str_len = #sorted_filetypes[1] +local function print_info_modules(sorted_languages) + local max_str_len = #sorted_languages[1] local header = string.rep(' ', max_str_len + 2) for _, mod in pairs(configs.available_modules()) do header = string.format('%s%s ', header, mod) end api.nvim_out_write(header..'\n') - for _, ft in pairs(sorted_filetypes) do - local padding = string.rep(' ', max_str_len - #ft) - api.nvim_out_write(ft..":"..padding) + for _, lang in pairs(sorted_languages) do + local padding = string.rep(' ', max_str_len - #lang) + api.nvim_out_write(lang..":"..padding) for _, mod in pairs(configs.available_modules()) do local pad_len = #mod / 2 + 1 api.nvim_out_write(string.rep(' ', pad_len)) - if configs.is_enabled(mod, ft) then + if configs.is_enabled(mod, lang) then api.nvim_out_write('✓') else api.nvim_out_write('✗') @@ -67,12 +67,12 @@ end local function module_info(mod) if mod and not configs.get_config()[mod] then return end - local ft_by_len = parsers.available_parsers() - table.sort(ft_by_len, function(a, b) return #a > #b end) + local parserlist = parsers.available_parsers() + table.sort(parserlist, function(a, b) return #a > #b end) if mod then - print_info_module(ft_by_len, mod) + print_info_module(parserlist, mod) else - print_info_modules(ft_by_len) + print_info_modules(parserlist) end end diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua index c2eeaf763..2d33dafda 100644 --- a/lua/nvim-treesitter/install.lua +++ b/lua/nvim-treesitter/install.lua @@ -7,8 +7,8 @@ local parsers = require'nvim-treesitter.parsers' local M = {} -local function iter_cmd(cmd_list, i, ft) - if i == #cmd_list + 1 then return print('Treesitter parser for '..ft..' has been installed') end +local function iter_cmd(cmd_list, i, lang) + if i == #cmd_list + 1 then return print('Treesitter parser for '..lang..' has been installed') end local attr = cmd_list[i] if attr.info then print(attr.info) end @@ -18,16 +18,16 @@ local function iter_cmd(cmd_list, i, ft) handle = luv.spawn(attr.cmd, attr.opts, vim.schedule_wrap(function(code) handle:close() if code ~= 0 then return api.nvim_err_writeln(attr.err) end - iter_cmd(cmd_list, i + 1, ft) + iter_cmd(cmd_list, i + 1, lang) end)) end -local function run_install(cache_folder, package_path, ft, repo) - local project_name = 'tree-sitter-'..ft +local function run_install(cache_folder, package_path, lang, repo) + local project_name = 'tree-sitter-'..lang local project_repo = cache_folder..'/'..project_name -- compile_location only needed for typescript installs. local compile_location = cache_folder..'/'..(repo.location or project_name) - local parser_lib_name = package_path.."/parser/"..ft..".so" + local parser_lib_name = package_path.."/parser/"..lang..".so" local command_list = { { cmd = 'rm', @@ -76,7 +76,7 @@ local function run_install(cache_folder, package_path, ft, repo) } } - iter_cmd(command_list, 1, ft) + iter_cmd(command_list, 1, lang) end -- TODO(kyazdani): this should work on windows too @@ -95,16 +95,16 @@ local function install(...) local cache_folder, err = utils.get_cache_dir() if err then return api.nvim_err_writeln(err) end - for _, ft in ipairs({ ... }) do - if #api.nvim_get_runtime_file('parser/'..ft..'.so', false) > 0 then - local yesno = fn.input(ft .. ' parser already available: would you like to reinstall ? y/n: ') + for _, lang in ipairs({ ... }) do + if #api.nvim_get_runtime_file('parser/'..lang..'.so', false) > 0 then + local yesno = fn.input(lang .. ' parser already available: would you like to reinstall ? y/n: ') print('\n ') -- mandatory to avoid messing up command line if not string.match(yesno, '^y.*') then return end end - local parser_config = parsers.get_parser_configs()[ft] + local parser_config = parsers.get_parser_configs()[lang] if not parser_config then - return api.nvim_err_writeln('Parser not available for language '..ft) + return api.nvim_err_writeln('Parser not available for language '..lang) end local install_info = parser_config.install_info @@ -113,7 +113,7 @@ local function install(...) files={ install_info.files, 'table' } } - run_install(cache_folder, package_path, ft, install_info) + run_install(cache_folder, package_path, lang, install_info) end end @@ -142,7 +142,7 @@ M.commands = { "-nargs=+", "-complete=custom,v:lua.ts_installable_parsers" }, - description = '`:TSInstall {ft}` installs a parser under nvim-treesitter/parser/{name}.so' + description = '`:TSInstall {lang}` installs a parser under nvim-treesitter/parser/{lang}.so' } } diff --git a/lua/nvim-treesitter/locals.lua b/lua/nvim-treesitter/locals.lua index cbea89108..7ace347a3 100644 --- a/lua/nvim-treesitter/locals.lua +++ b/lua/nvim-treesitter/locals.lua @@ -12,13 +12,13 @@ local M = { } function M.collect_locals(bufnr) - local ft = api.nvim_buf_get_option(bufnr, "ft") - if not ft then return end + local lang = parsers.ft_to_lang(api.nvim_buf_get_option(bufnr, "ft")) + if not lang then return end - local query = queries.get_query(ft, 'locals') + local query = queries.get_query(lang, 'locals') if not query then return end - local parser = parsers.get_parser(bufnr, ft) + local parser = parsers.get_parser(bufnr, lang) if not parser then return end local root = parser:parse():root() From 09c2e6e0a73721128b723b9668a8316aebb3a590 Mon Sep 17 00:00:00 2001 From: TravonteD Date: Mon, 22 Jun 2020 11:18:34 -0400 Subject: [PATCH 34/51] Fix the ":" in symbols when used in pairs This fixes the colon not being highlighted when a symbol is represented in a pair like so: symbol: true --- queries/ruby/highlights.scm | 1 + 1 file changed, 1 insertion(+) diff --git a/queries/ruby/highlights.scm b/queries/ruby/highlights.scm index 21afbe809..d7d880043 100644 --- a/queries/ruby/highlights.scm +++ b/queries/ruby/highlights.scm @@ -131,6 +131,7 @@ (symbol) ] @constant +(pair key: (symbol) ":" @constant) (regex) @string.regex (escape_sequence) @string.escape (integer) @number From 35dfd7e1f471c5f470a6c51577e11b7c3b72bb60 Mon Sep 17 00:00:00 2001 From: Thomas Vigouroux <39092278+vigoux@users.noreply.github.com> Date: Tue, 23 Jun 2020 14:30:01 +0200 Subject: [PATCH 35/51] Update CONTRIBUTING.md This makes it more readable --- CONTRIBUTING.md | 108 ++++++++++++++++++++++++++---------------------- 1 file changed, 59 insertions(+), 49 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 568a47e3b..af48cdc62 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -39,64 +39,73 @@ effect on highlighting. We will work on improving highlighting in the near futur #### Misc -`@comment` -`@error` for error `(ERROR)` nodes. -`@punctuation.delimiter` for `;` `.` `,` -`@punctuation.bracket` for `()` or `{}` +``` +@comment +@error for error (ERROR` nodes. +@punctuation.delimiter for `;` `.` `,` +@punctuation.bracket for `()` or `{}` +``` Some captures are related to language injection (like markdown code blocks). As this is not supported by neovim yet, these are optional and will not have any effect for now. -`@embedded` -`@injection` - `language` - `content` - +``` +@embedded +@injection + language + content +``` #### Constants -`@constant` - `builtin` - `macro` -`@string` - `regex` - `escape` -`@character` -`@number` -`@boolean` -`@float` +``` +@constant + builtin + macro +@string + regex + escape +@character +@number +@boolean +@float +``` #### Functions -`@function` - `builtin` - `macro` -`@parameter` +``` +@function + builtin + macro +@parameter -`@method` -`@field` or `@property` +@method +@field or @property -`@constructor` +@constructor +``` #### Keywords -`@conditional` -`@repeat` -`@label` for C/Lua-like labels -`@operator` -`@keyword` -`@exception` -`@include` keywords for including modules (e.g. import/from in Python) - -`@type` - `builtin` -`@structure` +``` +@conditional +@repeat +@label for C/Lua-like labels +@operator +@keyword +@exception +@include keywords for including modules (e.g. import/from in Python) +@type + builtin +@structure +``` ### Locals - -`@definition` for various definitions - `function` - `method` - `var` - `macro` - `type` - `field` - `doc` for documentation adjecent to a definition. E.g. +``` +@definition for various definitions + function + method + var + macro + type + field + doc for documentation adjecent to a definition. E.g. +``` ```scheme (comment)* @definition.doc @@ -104,7 +113,8 @@ are optional and will not have any effect for now. name: (field_identifier) @definition.method) ``` -`@scope` - -`@reference` +``` +@scope +@reference +``` From 51a52b85cf9fdc4d67619e0d71c57c1e6bb0f988 Mon Sep 17 00:00:00 2001 From: TravonteD Date: Mon, 22 Jun 2020 17:39:54 -0400 Subject: [PATCH 36/51] add highlight queries for bash --- README.md | 2 +- queries/bash/highlights.scm | 110 ++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 queries/bash/highlights.scm diff --git a/README.md b/README.md index 787a9adc9..9c8a97d33 100644 --- a/README.md +++ b/README.md @@ -168,7 +168,7 @@ List of currently supported languages: - [x] css (maintained by @TravonteD) - [ ] julia - [ ] php -- [ ] bash +- [x] bash (maintained by @TravonteD) - [ ] scala - [ ] haskell - [ ] toml diff --git a/queries/bash/highlights.scm b/queries/bash/highlights.scm new file mode 100644 index 000000000..c0ec8d698 --- /dev/null +++ b/queries/bash/highlights.scm @@ -0,0 +1,110 @@ +[ + "(" + ")" + "{" + "}" + "[" + "]" + ] @punctuation.bracket + +[ + ";" + ";;" + (heredoc_start) + ] @punctuation.delimiter + +[ + ">" + "<" + "&" + "&&" + "|" + "||" + "=" + "==" + "!=" + ] @operator + +[ + (string) + (raw_string) + (heredoc_body) +] @string + +[ + "if" + "then" + "else" + "elif" + "fi" + "case" + "in" + "esac" + ] @conditional + +[ + "for" + "do" + "done" + "while" + ] @repeat + +[ + "declare" + "export" + "local" + "readonly" + "unset" + ] @keyword + +[ + (special_variable_name) + ("$" (special_variable_name)) + ] @constant + +((word) @constant + (#match? @constant "SIG(INT|TERM|QUIT|TIN|TOU|STP|HUP)")) + +((word) @boolean + (#match? @boolean "true|false")) + +((word) @number + (#match? @number "^\d*$")) + +(comment) @comment +(test_operator) @string. + +(command_substitution + [ "$(" ")" ] @punctuation.bracket) + + +(function_definition + name: (word) @function) + +(command_name (word)) @function + +(command + argument: [ + (word) @parameter + ((word) @number + (#match? @number "^\d*$")) + (concatenation (word) @parameter) + ]) + +(file_redirect + descriptor: (file_descriptor) @operator + destination: (word) @parameter) + + +("$" (variable_name)) @identifier + +(expansion + [ "${" "}" ] @punctuation.bracket) + +(variable_name) @identifier + +(case_item + value: (word) @parameter) + +(concatenation (word) @parameter) + From dfead6cacab1a9f94396169166c9de8f8d4efdb7 Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Sun, 21 Jun 2020 16:32:25 +0200 Subject: [PATCH 37/51] Adapt Python highlights to new query syntax --- queries/python/highlights.scm | 139 ++++++++++++++++------------------ queries/python/locals.scm | 8 +- 2 files changed, 66 insertions(+), 81 deletions(-) diff --git a/queries/python/highlights.scm b/queries/python/highlights.scm index c56897804..739ab81cf 100644 --- a/queries/python/highlights.scm +++ b/queries/python/highlights.scm @@ -77,8 +77,7 @@ ; Literals (none) @constant.builtin -(true) @boolean -(false) @boolean +[(true) (false)] @boolean ((identifier) @constant.builtin (match? @constant.builtin "self")) @@ -91,88 +90,78 @@ ; Tokens -"-" @operator -"->" @operator -"-=" @operator -"!=" @operator -"*" @operator -"**" @operator -"**=" @operator -"*=" @operator -"/" @operator -"//" @operator -"//=" @operator -"/=" @operator -"&" @operator -"%" @operator -"%=" @operator -"^" @operator -"+" @operator -"+=" @operator -"<" @operator -"<<" @operator -"<=" @operator -"<>" @operator -"=" @operator -"==" @operator -">" @operator -">=" @operator -">>" @operator -"|" @operator -"~" @operator -"and" @operator -"in" @operator -"is" @operator -"not" @operator -"or" @operator +[ + "-" + "-=" + "!=" + "*" + "**" + "**=" + "*=" + "/" + "//" + "//=" + "/=" + "&" + "%" + "%=" + "^" + "+" + "+=" + "<" + "<<" + "<=" + "<>" + "=" + "==" + ">" + ">=" + ">>" + "|" + "~" + "and" + "in" + "is" + "not" + "or" +] @operator ; Keywords -"as" @include -"assert" @keyword -"async" @keyword -"await" @keyword -"break" @repeat -"class" @keyword -"continue" @repeat -"def" @keyword -"del" @keyword -"elif" @conditional -"else" @conditional -"except" @keyword -"exec" @keyword -"finally" @keyword -"for" @repeat -"from" @include -"global" @keyword -"if" @conditional -"import" @include -"lambda" @keyword -"nonlocal" @keyword -"pass" @keyword -"print" @keyword -"raise" @keyword -"return" @keyword -"try" @keyword -"while" @repeat -"with" @keyword -"yield" @keyword +[ + "assert" + "await" + "class" + "def" + "del" + "except" + "exec" + "finally" + "global" + "lambda" + "nonlocal" + "pass" + "print" + "raise" + "return" + "try" + "with" + "yield" +] @keyword -; Additions for nvim-treesitter -"(" @punctuation.bracket -")" @punctuation.bracket -"[" @punctuation.bracket -"]" @punctuation.bracket -"{" @punctuation.bracket -"}" @punctuation.bracket +[ "as" "from" "import"] @include + +[ "if" "elif" "else" ] @conditional + +[ "for" "while" "break" "continue" ] @repeat + +[ "(" ")" "[" "]" "{" "}"] @punctuation.bracket (interpolation "{" @punctuation.special "}" @punctuation.special) @embedded -"," @punctuation.delimiter -"." @punctuation.delimiter -":" @punctuation.delimiter +[ "," "." ":" ] @punctuation.delimiter ; Class definitions diff --git a/queries/python/locals.scm b/queries/python/locals.scm index 735271663..cdf4d4117 100644 --- a/queries/python/locals.scm +++ b/queries/python/locals.scm @@ -30,12 +30,8 @@ ; Function defines function and scope (function_definition - name: (identifier) @definition.function) @scope - -;; Should be extended to when syntax supported -;(function_definition - ;name: (identifier) @definition.function - ;body: (block (expression_statement (string) @definition.function.doc)?)) @scope + name: (identifier) @definition.function + body: (block (expression_statement (string) @definition.doc)?)) @scope (class_definition From d04a833e2090aab9899071021c0a959886029247 Mon Sep 17 00:00:00 2001 From: Steven Sojka Date: Wed, 24 Jun 2020 07:46:40 -0500 Subject: [PATCH 38/51] fix(locals): compute locals after later tick --- lua/nvim-treesitter/locals.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/nvim-treesitter/locals.lua b/lua/nvim-treesitter/locals.lua index 7ace347a3..8c7d400eb 100644 --- a/lua/nvim-treesitter/locals.lua +++ b/lua/nvim-treesitter/locals.lua @@ -40,7 +40,7 @@ end function M.get_locals(bufnr) local bufnr = bufnr or api.nvim_get_current_buf() local cached_local = M.locals[bufnr] - if not cached_local or api.nvim_buf_get_changedtick(bufnr) < cached_local.tick then + if not cached_local or api.nvim_buf_get_changedtick(bufnr) > cached_local.tick then update_cached_locals(bufnr,api.nvim_buf_get_changedtick(bufnr)) end From 5e91955b6afd450899e6fd4a10ffaa6601be53b0 Mon Sep 17 00:00:00 2001 From: kiyan42 Date: Thu, 25 Jun 2020 12:02:06 +0200 Subject: [PATCH 39/51] add command to install all parsers --- lua/nvim-treesitter/install.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua index 2d33dafda..2a9257f73 100644 --- a/lua/nvim-treesitter/install.lua +++ b/lua/nvim-treesitter/install.lua @@ -143,6 +143,13 @@ M.commands = { "-complete=custom,v:lua.ts_installable_parsers" }, description = '`:TSInstall {lang}` installs a parser under nvim-treesitter/parser/{lang}.so' + }, + TSInstallAll = { + run = function() + for _, lang in pairs(parsers.available_parsers()) do + install(lang) + end + end } } From 3e4ea3d890d3914d1fe56b21363308470c700678 Mon Sep 17 00:00:00 2001 From: kiyan42 Date: Thu, 25 Jun 2020 12:37:01 +0200 Subject: [PATCH 40/51] install can take 'all' as parameter --- lua/nvim-treesitter/install.lua | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua index 2a9257f73..24f6fbd63 100644 --- a/lua/nvim-treesitter/install.lua +++ b/lua/nvim-treesitter/install.lua @@ -95,11 +95,20 @@ local function install(...) local cache_folder, err = utils.get_cache_dir() if err then return api.nvim_err_writeln(err) end - for _, lang in ipairs({ ... }) do - if #api.nvim_get_runtime_file('parser/'..lang..'.so', false) > 0 then - local yesno = fn.input(lang .. ' parser already available: would you like to reinstall ? y/n: ') - print('\n ') -- mandatory to avoid messing up command line - if not string.match(yesno, '^y.*') then return end + local languages = { ... } + local check_installed = true + if ... == 'all' then + languages = parsers.available_parsers() + check_installed = false + end + + for _, lang in ipairs(languages) do + if check_installed then + if #api.nvim_get_runtime_file('parser/'..lang..'.so', false) > 0 then + local yesno = fn.input(lang .. ' parser already available: would you like to reinstall ? y/n: ') + print('\n ') -- mandatory to avoid messing up command line + if not string.match(yesno, '^y.*') then return end + end end local parser_config = parsers.get_parser_configs()[lang] @@ -143,13 +152,6 @@ M.commands = { "-complete=custom,v:lua.ts_installable_parsers" }, description = '`:TSInstall {lang}` installs a parser under nvim-treesitter/parser/{lang}.so' - }, - TSInstallAll = { - run = function() - for _, lang in pairs(parsers.available_parsers()) do - install(lang) - end - end } } From 0ed1fbf9093a7dda9aadda145c1b35dc5343cc8b Mon Sep 17 00:00:00 2001 From: kiyan42 Date: Thu, 25 Jun 2020 12:39:59 +0200 Subject: [PATCH 41/51] continue installing if not reinstalling one parser --- lua/nvim-treesitter/install.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lua/nvim-treesitter/install.lua b/lua/nvim-treesitter/install.lua index 24f6fbd63..686688bf7 100644 --- a/lua/nvim-treesitter/install.lua +++ b/lua/nvim-treesitter/install.lua @@ -107,7 +107,7 @@ local function install(...) if #api.nvim_get_runtime_file('parser/'..lang..'.so', false) > 0 then local yesno = fn.input(lang .. ' parser already available: would you like to reinstall ? y/n: ') print('\n ') -- mandatory to avoid messing up command line - if not string.match(yesno, '^y.*') then return end + if not string.match(yesno, '^y.*') then goto continue end end end @@ -123,6 +123,7 @@ local function install(...) } run_install(cache_folder, package_path, lang, install_info) + ::continue:: end end From 88c8b70560a0286c325a507e0d498219ee43c20f Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Wed, 24 Jun 2020 16:42:55 +0200 Subject: [PATCH 42/51] Python highlights: Add walrus operator --- queries/python/highlights.scm | 1 + 1 file changed, 1 insertion(+) diff --git a/queries/python/highlights.scm b/queries/python/highlights.scm index 739ab81cf..e238a9a8e 100644 --- a/queries/python/highlights.scm +++ b/queries/python/highlights.scm @@ -93,6 +93,7 @@ [ "-" "-=" + ":=" "!=" "*" "**" From 75bce1dc93293f4f1dfd1541386afb607f09d726 Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Wed, 24 Jun 2020 16:45:17 +0200 Subject: [PATCH 43/51] Python highlights: Reset highlighting in f-string interpolation This solution is preferable to `(identifier) @Normal` since otherwise everything without highlight will use string-highlighting. --- queries/python/highlights.scm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/queries/python/highlights.scm b/queries/python/highlights.scm index e238a9a8e..ca0f84387 100644 --- a/queries/python/highlights.scm +++ b/queries/python/highlights.scm @@ -1,9 +1,10 @@ ;; From tree-sitter-python licensed under MIT License ; Copyright (c) 2016 Max Brunsfeld -; Identifier naming conventions +; Reset highlighing in f-string interpolations +(interpolation) @Normal -(identifier) @Normal +; Identifier naming conventions ((identifier) @type (match? @type "^[A-Z]")) ((identifier) @constant From 2d224ac3bfd0f3ac4afd458a7f2fb55955ebc38c Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Fri, 26 Jun 2020 17:12:10 +0200 Subject: [PATCH 44/51] Fix cpp-highlights: wrong capture name used in regex --- queries/cpp/highlights.scm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/queries/cpp/highlights.scm b/queries/cpp/highlights.scm index 92909f4d9..0d8295a1d 100644 --- a/queries/cpp/highlights.scm +++ b/queries/cpp/highlights.scm @@ -52,7 +52,7 @@ ((call_expression function: (field_expression field: (field_identifier) @constructor)) -(#match? @function "^[A-Z]")) +(#match? @constructor "^[A-Z]")) ;; constructing a type in a intizializer list: Constructor (): **SuperType (1)** ((field_initializer @@ -64,8 +64,7 @@ ; Constants -;(this) @constant.builtin -(this) @keyword +(this) @constant.builtin (nullptr) @constant (true) @boolean From 282e18edd18fdd84e8436440789c0ecb2bc83f82 Mon Sep 17 00:00:00 2001 From: Thomas Vigouroux Date: Sun, 21 Jun 2020 19:43:02 +0200 Subject: [PATCH 45/51] highlight: use custom highlight groups --- doc/nvim-treesitter.txt | 131 ++++++++++++++++++++++++++++++ doc/tags | 32 ++++++++ lua/nvim-treesitter/highlight.lua | 64 +++++++-------- plugin/nvim-treesitter.vim | 41 +++++++++- 4 files changed, 235 insertions(+), 33 deletions(-) diff --git a/doc/nvim-treesitter.txt b/doc/nvim-treesitter.txt index bb53e182e..5a3a4ce11 100644 --- a/doc/nvim-treesitter.txt +++ b/doc/nvim-treesitter.txt @@ -166,4 +166,135 @@ Note: This is highly experimental, and folding can break on some types of edits. If you encounter such breakage, hiting `zx` should fix folding. In any case, feel free to open an issue with the reproducing steps. +============================================================================== +HIGHLIGHTS *nvim-treesitter-highlights* + +TSError + +`TSPunctDelimiter` + *hl-TSPunctDelimiter* +For delimiters ie: `.` + +`TSPunctBracket` + *hl-TSPunctBracket* +For brackets and parens. + +`TSPunctSpecial` + *hl-TSPunctSpecial* +For special punctutation that does not fall in the catagories before. + +`TSConstant` + *hl-TSConstant* +For constants + +`TSConstBuiltin` + *hl-TSConstBuiltin* +For constant that are built in the language: `nil` in Lua. + +`TSConstMacro` + *hl-TSConstMacro* +For constants that are defined by macros: `NULL` in C. + +`TSString` + *hl-TSString* +For strings. + +`TSStringRegex` + *hl-TSStringRegex* +For regexes. + +`TSStringEscape` + *hl-TSStringEscape* +For escape characters within a string. + +`TSCharacter` + *hl-TSCharacter* +For characters. + +`TSNumber` + *hl-TSNumber* +For integers. + +`TSBoolean` + *hl-TSBoolean* +For booleans. + +`TSFloat` + *hl-TSFloat* +For floats. + +`TSFunction` + *hl-TSFunction* +For function (calls and definitions). + +`TSFuncBuiltin` + *hl-TSFuncBuiltin* +For builtin functions: `table.insert` in Lua. + +`TSFuncMacro` + *hl-TSFuncMacro* +For macro defined fuctions (calls and definitions): each `macro_rules` in +Rust. + +`TSParameter` + *hl-TSParameter* +For parameters of a function. + +`TSMethod` + *hl-TSMethod* +For method calls and definitions. + +`TSField` + *hl-TSField* +For fields. + +`TSProperty` + *hl-TSProperty* +Same as `TSField`. + +`TSConstructor` + *hl-TSConstructor* +For constructor calls and definitions: `{}` in Lua, and Java constructors. + +`TSConditional` + *hl-TSConditional* +For keywords related to conditionnals. + +`TSRepeat` + *hl-TSRepeat* +For keywords related to loops. + +`TSLabel` + *hl-TSLabel* +For labels: `labe:` in C and `:label:` in Lua. + +`TSOperator` + *hl-TSOperator* +For any operator: `+`, but also `->` and `*` in C. + +`TSKeyword` + *hl-TSKeyword* +For keywords that don't fall in previous categories. + +`TSException` + *hl-TSException* +For exception related keywords. + +`TSType` + *hl-TSType* +For types. + +`TSTypeBuiltin` + *hl-TSTypeBuiltin* +For builtin types (you guessed it, right ?). + +`TSStructure` + *hl-TSStructure* +This is left as an exercise for the reader. + +`TSInclude` + *hl-TSInclude* +For includes: `#include` in C, `use` or `extern crate` in Rust, or `require` +in Lua + vim:tw=78:ts=8:noet:ft=help:norl: diff --git a/doc/tags b/doc/tags index df33c4d43..7cab44634 100644 --- a/doc/tags +++ b/doc/tags @@ -5,9 +5,41 @@ :TSInstall nvim-treesitter.txt /*:TSInstall* :TSInstallInfo nvim-treesitter.txt /*:TSInstallInfo* :TSModuleInfo nvim-treesitter.txt /*:TSModuleInfo* +hl-TSBoolean nvim-treesitter.txt /*hl-TSBoolean* +hl-TSCharacter nvim-treesitter.txt /*hl-TSCharacter* +hl-TSConditional nvim-treesitter.txt /*hl-TSConditional* +hl-TSConstBuiltin nvim-treesitter.txt /*hl-TSConstBuiltin* +hl-TSConstMacro nvim-treesitter.txt /*hl-TSConstMacro* +hl-TSConstant nvim-treesitter.txt /*hl-TSConstant* +hl-TSConstructor nvim-treesitter.txt /*hl-TSConstructor* +hl-TSException nvim-treesitter.txt /*hl-TSException* +hl-TSField nvim-treesitter.txt /*hl-TSField* +hl-TSFloat nvim-treesitter.txt /*hl-TSFloat* +hl-TSFuncBuiltin nvim-treesitter.txt /*hl-TSFuncBuiltin* +hl-TSFuncMacro nvim-treesitter.txt /*hl-TSFuncMacro* +hl-TSFunction nvim-treesitter.txt /*hl-TSFunction* +hl-TSInclude nvim-treesitter.txt /*hl-TSInclude* +hl-TSKeyword nvim-treesitter.txt /*hl-TSKeyword* +hl-TSLabel nvim-treesitter.txt /*hl-TSLabel* +hl-TSMethod nvim-treesitter.txt /*hl-TSMethod* +hl-TSNumber nvim-treesitter.txt /*hl-TSNumber* +hl-TSOperator nvim-treesitter.txt /*hl-TSOperator* +hl-TSParameter nvim-treesitter.txt /*hl-TSParameter* +hl-TSProperty nvim-treesitter.txt /*hl-TSProperty* +hl-TSPunctBracket nvim-treesitter.txt /*hl-TSPunctBracket* +hl-TSPunctDelimiter nvim-treesitter.txt /*hl-TSPunctDelimiter* +hl-TSPunctSpecial nvim-treesitter.txt /*hl-TSPunctSpecial* +hl-TSRepeat nvim-treesitter.txt /*hl-TSRepeat* +hl-TSString nvim-treesitter.txt /*hl-TSString* +hl-TSStringEscape nvim-treesitter.txt /*hl-TSStringEscape* +hl-TSStringRegex nvim-treesitter.txt /*hl-TSStringRegex* +hl-TSStructure nvim-treesitter.txt /*hl-TSStructure* +hl-TSType nvim-treesitter.txt /*hl-TSType* +hl-TSTypeBuiltin nvim-treesitter.txt /*hl-TSTypeBuiltin* nvim-treesitter nvim-treesitter.txt /*nvim-treesitter* nvim-treesitter-commands nvim-treesitter.txt /*nvim-treesitter-commands* nvim-treesitter-functions nvim-treesitter.txt /*nvim-treesitter-functions* +nvim-treesitter-highlights nvim-treesitter.txt /*nvim-treesitter-highlights* nvim-treesitter-intro nvim-treesitter.txt /*nvim-treesitter-intro* nvim-treesitter-quickstart nvim-treesitter.txt /*nvim-treesitter-quickstart* nvim-treesitter-utils nvim-treesitter.txt /*nvim-treesitter-utils* diff --git a/lua/nvim-treesitter/highlight.lua b/lua/nvim-treesitter/highlight.lua index 717601462..1b4722435 100644 --- a/lua/nvim-treesitter/highlight.lua +++ b/lua/nvim-treesitter/highlight.lua @@ -11,45 +11,45 @@ local M = { local hlmap = vim.treesitter.TSHighlighter.hl_map -- Misc -hlmap.error = "Error" -hlmap["punctuation.delimiter"] = "Delimiter" -hlmap["punctuation.bracket"] = "Delimiter" -hlmap["punctuation.special"] = "Delimiter" +hlmap.error = "TSError" +hlmap["punctuation.delimiter"] = "TSPunctDelimiter" +hlmap["punctuation.bracket"] = "TSPunctBracket" +hlmap["punctuation.special"] = "TSPunctSpecial" -- Constants -hlmap["constant"] = "Constant" -hlmap["constant.builtin"] = "Special" -hlmap["constant.macro"] = "Define" -hlmap["string"] = "String" -hlmap["string.regex"] = "String" -hlmap["string.escape"] = "SpecialChar" -hlmap["character"] = "Character" -hlmap["number"] = "Number" -hlmap["boolean"] = "Boolean" -hlmap["float"] = "Float" +hlmap["constant"] = "TSConstant" +hlmap["constant.builtin"] = "TSConstBuiltin" +hlmap["constant.macro"] = "TSConstMacro" +hlmap["string"] = "TSString" +hlmap["string.regex"] = "TSStringRegex" +hlmap["string.escape"] = "TSStringEscape" +hlmap["character"] = "TSCharacter" +hlmap["number"] = "TSNumber" +hlmap["boolean"] = "TSBoolean" +hlmap["float"] = "TSFloat" -- Functions -hlmap["function"] = "Function" -hlmap["function.builtin"] = "Special" -hlmap["function.macro"] = "Macro" -hlmap["parameter"] = "Identifier" -hlmap["method"] = "Function" -hlmap["field"] = "Identifier" -hlmap["property"] = "Identifier" -hlmap["constructor"] = "Special" +hlmap["function"] = "TSFunction" +hlmap["function.builtin"] = "TSFuncBuiltin" +hlmap["function.macro"] = "TSFuncMacro" +hlmap["parameter"] = "TSIdentifier" +hlmap["method"] = "TSMethod" +hlmap["field"] = "TSField" +hlmap["property"] = "TSProperty" +hlmap["constructor"] = "TSConstructor" -- Keywords -hlmap["conditional"] = "Conditional" -hlmap["repeat"] = "Repeat" -hlmap["label"] = "Label" -hlmap["operator"] = "Operator" -hlmap["keyword"] = "Keyword" -hlmap["exception"] = "Exception" +hlmap["conditional"] = "TSConditional" +hlmap["repeat"] = "TSRepeat" +hlmap["label"] = "TSLabel" +hlmap["operator"] = "TSOperator" +hlmap["keyword"] = "TSKeyword" +hlmap["exception"] = "TSException" -hlmap["type"] = "Type" -hlmap["type.builtin"] = "Type" -hlmap["structure"] = "Structure" -hlmap["include"] = "Include" +hlmap["type"] = "TSType" +hlmap["type.builtin"] = "TSTypeBuiltin" +hlmap["structure"] = "TSStructure" +hlmap["include"] = "TSInclude" function M.attach(bufnr, lang) local bufnr = bufnr or api.nvim_get_current_buf() diff --git a/plugin/nvim-treesitter.vim b/plugin/nvim-treesitter.vim index 4769680a3..cbd08a9bf 100644 --- a/plugin/nvim-treesitter.vim +++ b/plugin/nvim-treesitter.vim @@ -1,4 +1,4 @@ -" Last Change: 2020 avril 25 +" Last Change: 2020 juin 21 if exists('g:loaded_nvim_treesitter') finish @@ -18,3 +18,42 @@ ts_available_modules = function() end require'nvim-treesitter'.setup() EOF + +highlight link TSError Error + +highlight link TSPunctDelimiter Delimiter +highlight link TSPunctBracket Delimiter +highlight link TSPunctSpecial Delimiter + +highlight link TSConstant Constant +highlight link TSConstBuiltin Special +highlight link TSConstMacro Define +highlight link TSString String +highlight link TSStringRegex String +highlight link TSStringEscape SpecialChar +highlight link TSCharacter Character +highlight link TSNumber Number +highlight link TSBoolean Boolean +highlight link TSFloat TSFloat + +highlight link TSFunction Function +highlight link TSFuncBuiltin Special +highlight link TSFuncMacro Macro +highlight link TSParameter Identifier +highlight link TSMethod Function +highlight link TSField Identifier +highlight link TSProperty Identifier +highlight link TSConstructor Special + +highlight link TSConditional Conditional +highlight link TSRepeat Repeat +highlight link TSLabel Label +highlight link TSOperator Operator +highlight link TSKeyword Keyword +highlight link TSException Exception + +highlight link TSType Type +highlight link TSTypeBuiltin Type +highlight link TSStructure Structure +highlight link TSInclude Include + From ddb41c36e8de2c716ebbcb13aff6f50a9b0c4e2f Mon Sep 17 00:00:00 2001 From: kiyan42 Date: Sat, 27 Jun 2020 12:43:19 +0200 Subject: [PATCH 46/51] update docs for TSInstall --- README.md | 2 +- doc/nvim-treesitter.txt | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9c8a97d33..54d17abce 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ $ git clone https://github.com/nvim-treesitter/nvim-treesitter.git Treesitter is using a different _parser_ for every language. It can be quite a pain to install, but fortunately `nvim-treesitter` provides two command to tackle this issue: - - `TSInstall` to install a given parser. + - `TSInstall` to install one or more parser. You can use `TSInstall all` to download all parsers. - `TSInstallInfo` to know which parser is installed. Let's say you need parsers for `lua`, `c`, and `python`, this is how you do with these commands: diff --git a/doc/nvim-treesitter.txt b/doc/nvim-treesitter.txt index 5a3a4ce11..67e9f7581 100644 --- a/doc/nvim-treesitter.txt +++ b/doc/nvim-treesitter.txt @@ -52,9 +52,10 @@ By default, everything is disabled. To enable support for features, in your `ini ============================================================================== COMMANDS *nvim-treesitter-commands* -|:TSInstall| {language} *:TSInstall* +|:TSInstall| {language} ... *:TSInstall* -Download, compile and install a parser for {language} +Install one or more treesitter parsers. +You can use |:TSInstall| `all` to install all parsers. |:TSInstallInfo| *:TSInstallInfo* From c27d35adc5bb8bd8c2ca58883cda6e9ec297106d Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Sat, 27 Jun 2020 20:33:55 +0200 Subject: [PATCH 47/51] Fix typo in documentation: `labe:` -> `label:` --- doc/nvim-treesitter.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/nvim-treesitter.txt b/doc/nvim-treesitter.txt index 67e9f7581..b287b56e3 100644 --- a/doc/nvim-treesitter.txt +++ b/doc/nvim-treesitter.txt @@ -267,7 +267,7 @@ For keywords related to loops. `TSLabel` *hl-TSLabel* -For labels: `labe:` in C and `:label:` in Lua. +For labels: `label:` in C and `:label:` in Lua. `TSOperator` *hl-TSOperator* From 54438439e6e05a52eaca34d815211e61231c9da8 Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Sat, 27 Jun 2020 21:06:11 +0200 Subject: [PATCH 48/51] C highlights: Add highlight for #elif --- queries/c/highlights.scm | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/queries/c/highlights.scm b/queries/c/highlights.scm index 0d718c223..b3889dbd8 100644 --- a/queries/c/highlights.scm +++ b/queries/c/highlights.scm @@ -21,13 +21,16 @@ "while" @repeat "#define" @constant.macro -"#else" @keyword -"#endif" @keyword -"#if" @keyword -"#ifdef" @keyword -"#ifndef" @keyword -"#include" @keyword -(preproc_directive) @keyword +[ + "#if" + "#ifdef" + "#ifndef" + "#else" + "#elif" + "#endif" + "#include" + (preproc_directive) +] @keyword "--" @operator "-" @operator From b184f1cafbe7316ae8671b7eafec5a11383b4fd6 Mon Sep 17 00:00:00 2001 From: Chinmay Dalal Date: Mon, 29 Jun 2020 14:18:13 +0530 Subject: [PATCH 49/51] Java highlights: Capture parameters in declaration (#93) * Capture parameters in declaration * Refactor (new syntax) * Fix spaces * Fix capture (java method parameters) * Improve java parameter capture * Fix bracket and whitespace * Fix java query * Fix java query Co-authored-by: Thomas Vigouroux <39092278+vigoux@users.noreply.github.com> * Add capture for lambda parameters, remove redundant captures, add -> operator * Previous commit wasn't saved properly * Fix formatting * Changes suggested in PR https://github.com/nvim-treesitter/nvim-treesitter/pull/93#pullrequestreview-435630553 * Add bitwise operators * Re-add builtin operators * remove left shift, add ^= * Add &= and |= * remove @variable * Remove duplicate Co-authored-by: Thomas Vigouroux <39092278+vigoux@users.noreply.github.com> --- queries/java/highlights.scm | 95 +++++++++++++++++++++++++------------ 1 file changed, 64 insertions(+), 31 deletions(-) diff --git a/queries/java/highlights.scm b/queries/java/highlights.scm index e51099e58..8d50ebfd6 100644 --- a/queries/java/highlights.scm +++ b/queries/java/highlights.scm @@ -2,20 +2,32 @@ ; Methods + (method_declaration name: (identifier) @method) (method_invocation name: (identifier) @method) + (super) @function.builtin +; Parameters +(formal_parameter + name: (identifier) @parameter) + +(inferred_parameters (identifier) @parameter) + + ; Annotations + (annotation name: (identifier) @attribute) (marker_annotation name: (identifier) @attribute) + ; Operators + [ "@" "+" @@ -41,6 +53,15 @@ "*=" "/=" "%=" +"->" +"^" +"^=" +"&=" +"|=" +"~" +">>" +">>>" +"<<" ] @operator ; Types @@ -51,40 +72,46 @@ name: (identifier) @type) (enum_declaration name: (identifier) @type) +(constructor_declaration + name: (identifier) @type) +(type_identifier) @type + + ((field_access object: (identifier) @type) - (#match? @type "^[A-Z]")) + (#match? @type "^[A-Z]")) ((scoped_identifier scope: (identifier) @type) - (#match? @type "^[A-Z]")) + (#match? @type "^[A-Z]")) -(constructor_declaration - name: (identifier) @type) - -(type_identifier) @type -(boolean_type) @type.builtin -(integral_type) @type.builtin -(floating_point_type) @type.builtin -(floating_point_type) @type.builtin -(void_type) @type.builtin +[ +(boolean_type) +(integral_type) +(floating_point_type) +(void_type) +] @type.builtin ; Variables ((identifier) @constant - (#match? @constant "^_*[A-Z][A-Z\d_]+")) + (#match? @constant "^_*[A-Z][A-Z\d_]+")) -(identifier) @variable -(this) @variable.builtin ; Literals -(hex_integer_literal) @number -(decimal_integer_literal) @number -(octal_integer_literal) @number -(decimal_floating_point_literal) @float -(hex_floating_point_literal) @float +[ +(hex_integer_literal) +(decimal_integer_literal) +(octal_integer_literal) +] @number + +[ +(decimal_floating_point_literal) +(hex_floating_point_literal) +] @float + (character_literal) @character (string_literal) @string (null_literal) @constant.builtin @@ -106,7 +133,6 @@ "class" "continue" "default" -"do" "enum" "exports" "extends" @@ -150,25 +176,32 @@ "case" ] @conditional -; +; [ "for" "while" +"do" ] @repeat -; +; Includes "import" @include +"package" @include ; Punctuation -";" @punctuation.delimiter -"." @punctuation.delimiter -"," @punctuation.delimiter -"[" @punctuation.bracket -"]" @punctuation.bracket -"{" @punctuation.bracket -"}" @punctuation.bracket -"(" @punctuation.bracket -")" @punctuation.bracket +[ +";" +"." +"," +] @punctuation.delimiter + +[ +"[" +"]" +"{" +"}" +"(" +")" +] @punctuation.bracket From f4b87d3364d8ef08aad4fd7aebf59450f2c06d67 Mon Sep 17 00:00:00 2001 From: Thomas Vigouroux Date: Mon, 29 Jun 2020 09:00:06 +0000 Subject: [PATCH 50/51] highlights: declare links as defaults --- plugin/nvim-treesitter.vim | 66 +++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/plugin/nvim-treesitter.vim b/plugin/nvim-treesitter.vim index cbd08a9bf..24a8eceb6 100644 --- a/plugin/nvim-treesitter.vim +++ b/plugin/nvim-treesitter.vim @@ -1,4 +1,4 @@ -" Last Change: 2020 juin 21 +" Last Change: 2020 Jun 29 if exists('g:loaded_nvim_treesitter') finish @@ -19,41 +19,41 @@ end require'nvim-treesitter'.setup() EOF -highlight link TSError Error +highlight default link TSError Error -highlight link TSPunctDelimiter Delimiter -highlight link TSPunctBracket Delimiter -highlight link TSPunctSpecial Delimiter +highlight default link TSPunctDelimiter Delimiter +highlight default link TSPunctBracket Delimiter +highlight default link TSPunctSpecial Delimiter -highlight link TSConstant Constant -highlight link TSConstBuiltin Special -highlight link TSConstMacro Define -highlight link TSString String -highlight link TSStringRegex String -highlight link TSStringEscape SpecialChar -highlight link TSCharacter Character -highlight link TSNumber Number -highlight link TSBoolean Boolean -highlight link TSFloat TSFloat +highlight default link TSConstant Constant +highlight default link TSConstBuiltin Special +highlight default link TSConstMacro Define +highlight default link TSString String +highlight default link TSStringRegex String +highlight default link TSStringEscape SpecialChar +highlight default link TSCharacter Character +highlight default link TSNumber Number +highlight default link TSBoolean Boolean +highlight default link TSFloat TSFloat -highlight link TSFunction Function -highlight link TSFuncBuiltin Special -highlight link TSFuncMacro Macro -highlight link TSParameter Identifier -highlight link TSMethod Function -highlight link TSField Identifier -highlight link TSProperty Identifier -highlight link TSConstructor Special +highlight default link TSFunction Function +highlight default link TSFuncBuiltin Special +highlight default link TSFuncMacro Macro +highlight default link TSParameter Identifier +highlight default link TSMethod Function +highlight default link TSField Identifier +highlight default link TSProperty Identifier +highlight default link TSConstructor Special -highlight link TSConditional Conditional -highlight link TSRepeat Repeat -highlight link TSLabel Label -highlight link TSOperator Operator -highlight link TSKeyword Keyword -highlight link TSException Exception +highlight default link TSConditional Conditional +highlight default link TSRepeat Repeat +highlight default link TSLabel Label +highlight default link TSOperator Operator +highlight default link TSKeyword Keyword +highlight default link TSException Exception -highlight link TSType Type -highlight link TSTypeBuiltin Type -highlight link TSStructure Structure -highlight link TSInclude Include +highlight default link TSType Type +highlight default link TSTypeBuiltin Type +highlight default link TSStructure Structure +highlight default link TSInclude Include From a2f09312540822e9c579fee4534832fefd492250 Mon Sep 17 00:00:00 2001 From: Stephan Seitz Date: Sat, 27 Jun 2020 20:43:41 +0200 Subject: [PATCH 51/51] Extend documentation for TSError --- doc/nvim-treesitter.txt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/doc/nvim-treesitter.txt b/doc/nvim-treesitter.txt index b287b56e3..c9adf93b2 100644 --- a/doc/nvim-treesitter.txt +++ b/doc/nvim-treesitter.txt @@ -170,7 +170,13 @@ Note: This is highly experimental, and folding can break on some types of ============================================================================== HIGHLIGHTS *nvim-treesitter-highlights* -TSError +`TSError` + *hl-TSError* +For syntax/parser errors. + +You can deactivate highlighting of syntax errors by adding this to your +init.vim: > + highlight link TSError Normal `TSPunctDelimiter` *hl-TSPunctDelimiter*