diff options
| author | Connor Lay (Clay) <connorlay@users.noreply.github.com> | 2021-08-01 13:09:41 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-01 19:09:41 +0000 |
| commit | 6944173e8778795863eda56a3bd2f98efdd82c10 (patch) | |
| tree | f8e5dc111b93c3e7f845c8374f39aba51c41d8cf | |
| parent | 8ab1a5e5f7087c4ed49c42e8d14ecb9d91d58363 (diff) | |
Feature: Add Surface language and integrate with Elixir (#1645)
* Add initial surface highlights & injections
* Additional surface highlights
* Filetype detection, fix injections
* Fix Elixir function highlight when left is an identifier
* Add surface parser
* Fix comment highlights
* Surface folds, indents, better highlights
* Highlight surface components & directives
* Restore comments Elixir injections
| -rw-r--r-- | ftdetect/elixir.vim | 2 | ||||
| -rw-r--r-- | ftdetect/surface.vim | 1 | ||||
| -rw-r--r-- | lua/nvim-treesitter/parsers.lua | 10 | ||||
| -rw-r--r-- | queries/elixir/highlights.scm | 4 | ||||
| -rw-r--r-- | queries/elixir/injections.scm | 5 | ||||
| -rw-r--r-- | queries/surface/folds.scm | 5 | ||||
| -rw-r--r-- | queries/surface/highlights.scm | 46 | ||||
| -rw-r--r-- | queries/surface/indents.scm | 12 | ||||
| -rw-r--r-- | queries/surface/injections.scm | 8 |
9 files changed, 93 insertions, 0 deletions
diff --git a/ftdetect/elixir.vim b/ftdetect/elixir.vim new file mode 100644 index 00000000..b06597ce --- /dev/null +++ b/ftdetect/elixir.vim @@ -0,0 +1,2 @@ +au BufRead,BufNewFile *.ex,*.exs,mix.lock set filetype=elixir +au BufRead,BufNewFile *.eex,*.leex,*.heex set filetype=eelixir diff --git a/ftdetect/surface.vim b/ftdetect/surface.vim new file mode 100644 index 00000000..6fb2a69b --- /dev/null +++ b/ftdetect/surface.vim @@ -0,0 +1 @@ +au BufRead,BufNewFile *.sface set filetype=surface diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua index 2fa20fd7..afe02f70 100644 --- a/lua/nvim-treesitter/parsers.lua +++ b/lua/nvim-treesitter/parsers.lua @@ -261,6 +261,16 @@ list.elixir = { maintainers = { "@nifoc" }, } +list.surface = { + install_info = { + url = "https://github.com/connorlay/tree-sitter-surface", + files = { "src/parser.c" }, + branch = "main", + }, + filetype = "sface", + maintainers = { "@connorlay" }, +} + list.ocaml = { install_info = { url = "https://github.com/tree-sitter/tree-sitter-ocaml", diff --git a/queries/elixir/highlights.scm b/queries/elixir/highlights.scm index bcbc4391..51c57494 100644 --- a/queries/elixir/highlights.scm +++ b/queries/elixir/highlights.scm @@ -78,6 +78,10 @@ remote: [(atom) (module)] @type function: (function_identifier) @method) +(dot_call + remote: (identifier) @variable + function: (function_identifier) @method) + "fn" @keyword.function ; def, defp, defguard, ... everything that starts with def diff --git a/queries/elixir/injections.scm b/queries/elixir/injections.scm index 0f12cdba..02709add 100644 --- a/queries/elixir/injections.scm +++ b/queries/elixir/injections.scm @@ -8,3 +8,8 @@ (sigil_start) @_start (sigil_content) @regex) (#match? @_start "~(r|R)[/</\\\"[({|]")) + +((sigil + (sigil_start) @_start + (sigil_content) @surface) + (#eq? @_start "~F\"\"\"")) diff --git a/queries/surface/folds.scm b/queries/surface/folds.scm new file mode 100644 index 00000000..57763a6e --- /dev/null +++ b/queries/surface/folds.scm @@ -0,0 +1,5 @@ +; Surface folds similar to HTML and includes blocks +[ + (tag) + (block) +] @fold diff --git a/queries/surface/highlights.scm b/queries/surface/highlights.scm new file mode 100644 index 00000000..77b88c05 --- /dev/null +++ b/queries/surface/highlights.scm @@ -0,0 +1,46 @@ +; Surface text is highlighted as such +(text) @text + +; Surface has two types of comments, both are highlighted as such +(comment) @comment + +; Surface attributes are highlighted as HTML attributes +(attribute_name) @tag.attribute + +; Attributes are highlighted as strings +(attribute_value) @string + +; Surface blocks are highlighted as keywords +[ + (start_block) + (end_block) + (subblock) +] @keyword + +; Surface supports HTML tags and are highlighted as such +[ + (start_tag) + (end_tag) + (self_closing_tag) + (start_component) + (end_component) + (self_closing_component) +] @tag.delimiter + +; Expressions are similar to string interpolation, and are highloghted as such +(expression) @punctuation.special + +; Expressions should be highlighted as Elixir, fallback to special strings +(expression_value) @string.special + +; Surface tags are highlighted as HTML +(tag_name) @tag + +; Surface components are highlighted as types (Elixir modules) +(component_name) @type + +; Surface directives are highlighted as keywords +(directive_name) @keyword + +; Surface operators +["="] @operator diff --git a/queries/surface/indents.scm b/queries/surface/indents.scm new file mode 100644 index 00000000..ad683575 --- /dev/null +++ b/queries/surface/indents.scm @@ -0,0 +1,12 @@ +; Surface indents like HTML, with the addition of blocks +[ + (tag) + (block) +] @indent + +; Dedent at the end of each tag, as well as a subblock +[ + (end_tag) + (end_block) + (subblock) +] @branch diff --git a/queries/surface/injections.scm b/queries/surface/injections.scm new file mode 100644 index 00000000..928977a3 --- /dev/null +++ b/queries/surface/injections.scm @@ -0,0 +1,8 @@ +; Surface expressions and components are Elixir code +[ + (expression_value) + (component_name) +] @elixir + +; Surface comments are nvim-treesitter comments +(comment) @comment |
