diff --git a/flake.nix b/flake.nix index e7053c4..7449fd2 100644 --- a/flake.nix +++ b/flake.nix @@ -41,11 +41,21 @@ eachDefaultSystem (system: let + inherit (nixpkgs) lib; pkgs = import nixpkgs { inherit system; overlays = [ self.overlays.default ]; }; + # FIXME: does it pickup the parser correctly? + nvim-test = pkgs.writeShellScriptBin "nvim-test" '' + export NVIM_PLENARY='${pkgs.vimPlugins.plenary-nvim}' + export NVIM_TREESITTER='${pkgs.vimPlugins.nvim-treesitter}' + + ${pkgs.neovim}/bin/nvim --headless --noplugin -u scripts/minimal_init.lua \ + -c "PlenaryBustedDirectory test/ { minimal_init = '${./scripts/minimal_init.lua}' }" + ''; + bump-version = pkgs.writeShellScriptBin "bump-version" '' set -eu @@ -90,6 +100,13 @@ enable = true; }; + nvim-test = { + enable = true; + name = "nvim tests"; + entry = "${lib.getExe nvim-test}"; + pass_filenames = false; + }; + tree-sitter = { enable = true; name = "tree-sitter tests"; @@ -112,6 +129,7 @@ nativeBuildInputs = with pkgs; [ bump-version nodejs + nvim-test # FIXME: waiting on #301336 # (tree-sitter.override { webUISupport = true; }) tree-sitter diff --git a/grammar.js b/grammar.js index 86d0dd6..929f36e 100644 --- a/grammar.js +++ b/grammar.js @@ -23,7 +23,7 @@ module.exports = grammar({ $.module, ), - line_comment: (_) => seq("//", /.*/), + line_comment: (_) => seq("//", /[^\n]*/), block_comment: (_) => seq("/*", /[^*]*\*+([^/*][^*]*\*+)*/, '/'), diff --git a/queries/highlights.scm b/queries/highlights.scm index b4cc660..17c5692 100644 --- a/queries/highlights.scm +++ b/queries/highlights.scm @@ -42,11 +42,19 @@ (identifier) @variable (module - type: (identifier) @module) + type: (identifier) @function.call) (module (property - field: (identifier) @variable.member)) + field: (identifier) @variable.parameter)) +; }}} + +; Built-ins {{{ +[ + (unset) + "default" +] @variable.builtin +(selection_type) @function.builtin ; }}} ; Expressions {{{ diff --git a/scripts/minimal_init.lua b/scripts/minimal_init.lua new file mode 100644 index 0000000..d43d3dc --- /dev/null +++ b/scripts/minimal_init.lua @@ -0,0 +1,19 @@ +vim.opt.runtimepath:append(os.getenv("NVIM_PLENARY")) +vim.opt.runtimepath:append(os.getenv("NVIM_TREESITTER")) + +vim.cmd.runtime({ "plugin/plenary.vim", bang = true }) +vim.cmd.runtime({ "plugin/nvim-treesitter.lua", bang = true }) + +vim.filetype.add({ + extension = { + bp = "bp", + }, +}) + +vim.o.swapfile = false +vim.bo.swapfile = false + +require("nvim-treesitter.configs").setup({ + indent = { enable = true }, + highlight = { enable = true }, +}) diff --git a/src/grammar.json b/src/grammar.json index c9b0e32..2ac5436 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -30,7 +30,7 @@ }, { "type": "PATTERN", - "value": ".*" + "value": "[^\\n]*" } ] }, diff --git a/test/corpus/comments.txt b/test/corpus/comments.txt index 5304a7e..6c91a89 100644 --- a/test/corpus/comments.txt +++ b/test/corpus/comments.txt @@ -85,6 +85,23 @@ Block comment with asterisks -------------------------------------------------------------------------------- +(source_file + (block_comment)) + +================================================================================ +Block comment (multiline) +================================================================================ + +/* + This + is + a + long + comment +*/ + +-------------------------------------------------------------------------------- + (source_file (block_comment)) diff --git a/test/highlight/builtins.bp b/test/highlight/builtins.bp new file mode 100644 index 0000000..73b32e3 --- /dev/null +++ b/test/highlight/builtins.bp @@ -0,0 +1,8 @@ +foo = select(soong_config_variable("my_namespace", "my_var"), { + // ^ function.builtin + "foo": unset, + // ^ variable.builtin + default: select(variant("VARIANT"), {}), + // <- variable.builtin + // ^ function.builtin +}) diff --git a/test/highlight/modules.bp b/test/highlight/modules.bp index 248acdf..e115e6a 100644 --- a/test/highlight/modules.bp +++ b/test/highlight/modules.bp @@ -1,21 +1,21 @@ foo {} -// <- module +// <- function.call foo () -// <- module +// <- function.call foo { -// <- module +// <- function.call field: 12, - // <- variable.member + // <- variable.parameter another_field: 27, - // <- variable.member + // <- variable.parameter } foo ( -// <- module +// <- function.call field = 42, - // <- variable.member + // <- variable.parameter done = false, - // <- variable.member + // <- variable.parameter ) diff --git a/test/highlight/properties.bp b/test/highlight/properties.bp index 6bc97ef..8ad2c55 100644 --- a/test/highlight/properties.bp +++ b/test/highlight/properties.bp @@ -1,6 +1,6 @@ foo { field: { - // <- variable.member + // <- variable.parameter key: 42, // <- property }, diff --git a/test/highlight/select.bp b/test/highlight/select.bp index 831608d..b857c1e 100644 --- a/test/highlight/select.bp +++ b/test/highlight/select.bp @@ -11,5 +11,5 @@ select = 42 // Or module property foo { select: 42, - // <- variable.member + // <- variable.parameter }