From ee86c290bf319cdde8a87d5abee1ca9e483f2cea Mon Sep 17 00:00:00 2001 From: Steven Sojka Date: Wed, 16 Dec 2020 12:19:18 -0600 Subject: [PATCH] refactor(parser): use angular parser --- after/queries/html/injections.scm | 15 ++++++--------- after/queries/javascript/injections.scm | 12 ++++-------- lua/nvim-treesitter-angular/internal.lua | 21 +++++++++++++++++++++ plugin/nvim-treesitter-angular.vim | 1 + 4 files changed, 32 insertions(+), 17 deletions(-) create mode 100644 lua/nvim-treesitter-angular/internal.lua create mode 100644 plugin/nvim-treesitter-angular.vim diff --git a/after/queries/html/injections.scm b/after/queries/html/injections.scm index 029e3c6..04185dc 100644 --- a/after/queries/html/injections.scm +++ b/after/queries/html/injections.scm @@ -3,27 +3,24 @@ ((attribute_name) @_name (#lua-match? @_name "%[.*%]")) (quoted_attribute_value - ((attribute_value) @injection - (#set! "lang" "javascript")))) + (attribute_value) @angular)) ; (myEvent)="handle($event)" (attribute ((attribute_name) @_name (#lua-match? @_name "%(.*%)")) (quoted_attribute_value - ((attribute_value) @injection - (#set! "lang" "javascript")))) + ((attribute_value) @angular))) ; *ngIf="blorgy" (attribute ((attribute_name) @_name (#lua-match? @_name "^%*.*")) (quoted_attribute_value - ((attribute_value) @injection - (#set! "lang" "javascript")))) + ((attribute_value) @angular))) ; {{ someBinding }} (element - ((text) @_name @injection - (#lua-match? @_name "%{%{.*%}%}") - (#set! "lang" "javascript"))) + ((text) @angular + (#lua-match? @angular "%{%{.*%}%}") + (#offset! @angular 0 2 0 -2))) diff --git a/after/queries/javascript/injections.scm b/after/queries/javascript/injections.scm index 937a07a..5285106 100644 --- a/after/queries/javascript/injections.scm +++ b/after/queries/javascript/injections.scm @@ -11,8 +11,7 @@ (pair key: ((property_identifier) @_prop (#eq? @_prop "template")) - value: ((template_string) @injection - (#set! "lang" "html")))))))) + value: ((template_string) @html))))))) (export_statement decorator: (decorator @@ -24,8 +23,7 @@ (pair key: ((property_identifier) @_prop (#eq? @_prop "template")) - value: ((template_string) @injection - (#set! "lang" "html"))))))) + value: ((template_string) @html)))))) declaration: (class_declaration)) (class_declaration @@ -39,8 +37,7 @@ key: ((property_identifier) @_prop (#eq? @_prop "styles")) value: (array - ((template_string) @injection - (#set! "lang" "css"))))))))) + ((template_string) @css)))))))) (export_statement decorator: (decorator @@ -53,6 +50,5 @@ key: ((property_identifier) @_prop (#eq? @_prop "styles")) value: (array - ((template_string) @injection - (#set! "lang" "css")))))))) + ((template_string) @css))))))) declaration: (class_declaration)) diff --git a/lua/nvim-treesitter-angular/internal.lua b/lua/nvim-treesitter-angular/internal.lua new file mode 100644 index 0000000..3691fd3 --- /dev/null +++ b/lua/nvim-treesitter-angular/internal.lua @@ -0,0 +1,21 @@ +local parsers = require "nvim-treesitter.parsers" +local installer = require "nvim-treesitter.install" + +local M = {} + +function M.init() + parsers.get_parser_configs().angular = { + install_info = { + url = "https://github.com/steelsojka/tree-sitter-angular", + files = { "src/parser.c" }, + branch = "main" + }, + maintainers = {"@steelsojka"} + } + + if not parsers.has_parser("angular") then + installer.update("angular") + end +end + +return M diff --git a/plugin/nvim-treesitter-angular.vim b/plugin/nvim-treesitter-angular.vim new file mode 100644 index 0000000..80af105 --- /dev/null +++ b/plugin/nvim-treesitter-angular.vim @@ -0,0 +1 @@ +lua require "nvim-treesitter-angular.internal".init()