From 452f7d071ceb57aad9da36473e6d2a0f0bedb462 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Sat, 22 Oct 2022 12:51:20 -0500 Subject: [PATCH] Improve Edoc highlighting within Erlang This highlights edoc within Erlang comments. The trick was to have the Erlang grammar consume newlines and then give them to EDoc in the injection to use so that line-wise elements could be parsed accurately. --- languages.toml | 4 ++-- runtime/queries/edoc/highlights.scm | 2 ++ runtime/queries/edoc/injections.scm | 4 ++-- runtime/queries/erlang/highlights.scm | 10 ++++++---- runtime/queries/erlang/injections.scm | 9 +++++++-- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/languages.toml b/languages.toml index 1e7dcbf7..9007cc65 100644 --- a/languages.toml +++ b/languages.toml @@ -1184,7 +1184,7 @@ language-server = { command = "erlang_ls" } [[grammar]] name = "erlang" -source = { git = "https://github.com/the-mikedavis/tree-sitter-erlang", rev = "0e7d677d11a7379686c53c616825714ccb728059" } +source = { git = "https://github.com/the-mikedavis/tree-sitter-erlang", rev = "ce0ed253d72c199ab93caba7542b6f62075339c4" } [[language]] name = "kotlin" @@ -1574,7 +1574,7 @@ indent = { tab-width = 4, unit = " " } [[grammar]] name = "edoc" -source = { git = "https://github.com/the-mikedavis/tree-sitter-edoc", rev = "1691ec0aa7ad1ed9fa295590545f27e570d12d60" } +source = { git = "https://github.com/the-mikedavis/tree-sitter-edoc", rev = "74774af7b45dd9cefbf9510328fc6ff2374afc50" } [[language]] name = "jsdoc" diff --git a/runtime/queries/edoc/highlights.scm b/runtime/queries/edoc/highlights.scm index 4267cb9e..5bab7992 100644 --- a/runtime/queries/edoc/highlights.scm +++ b/runtime/queries/edoc/highlights.scm @@ -48,3 +48,5 @@ (language_identifier) (quote_content) ] @markup.raw.block + +(parameter) @variable.parameter diff --git a/runtime/queries/edoc/injections.scm b/runtime/queries/edoc/injections.scm index 9630995b..28c44b9f 100644 --- a/runtime/queries/edoc/injections.scm +++ b/runtime/queries/edoc/injections.scm @@ -16,5 +16,5 @@ (tag) @_tag (argument) @injection.content) (#eq? @_tag "@type") - (#set injection.language "erlang") - (#set injection.include-children)) + (#set! injection.language "erlang") + (#set! injection.include-children)) diff --git a/runtime/queries/erlang/highlights.scm b/runtime/queries/erlang/highlights.scm index 58c8fb8a..050fb613 100644 --- a/runtime/queries/erlang/highlights.scm +++ b/runtime/queries/erlang/highlights.scm @@ -94,10 +94,6 @@ (unary_operator operator: _ @operator) ["/" ":" "->"] @operator -(tripledot) @comment.discard - -(comment) @comment - ; Macros (macro "?"+ @constant @@ -112,8 +108,14 @@ ((variable) @comment.discard (#match? @comment.discard "^_")) +(tripledot) @comment.discard + +[(comment) (line_comment) (shebang)] @comment + ; Basic types (variable) @variable +((atom) @constant.builtin.boolean + (#match? @constant.builtin.boolean "^(true|false)$")) (atom) @string.special.symbol (string) @string (character) @constant.character diff --git a/runtime/queries/erlang/injections.scm b/runtime/queries/erlang/injections.scm index 07858185..11cbd01e 100644 --- a/runtime/queries/erlang/injections.scm +++ b/runtime/queries/erlang/injections.scm @@ -1,2 +1,7 @@ -((comment_content) @injection.content - (#set! injection.language "edoc")) +((line_comment (comment_content) @injection.content) + (#set! injection.language "edoc") + (#set! injection.include-children) + (#set! injection.combined)) + +((comment (comment_content) @injection.content) + (#set! injection.language "comment"))