Compare commits

...

4 commits

Author SHA1 Message Date
Bruno BELANYI 045e505073 WIP
All checks were successful
ci/woodpecker/push/check Pipeline was successful
2024-04-10 15:24:57 +00:00
Bruno BELANYI f6e1266493 Consider module as function call for highlighting
All checks were successful
ci/woodpecker/push/check Pipeline was successful
Their semantic is closer to a function call (like i.e: Bazel rules)
rather than a module/namespace.

Similarly for their properties, which are more like parameters than
members.
2024-04-10 15:21:07 +00:00
Bruno BELANYI be1e3f07d3 Make 'line_comment' more explicit about newlines
Because of the way regular expressions work, they were already bounded
at newlines here, but explicit is better than implicit :-).
2024-04-10 15:20:29 +00:00
Bruno BELANYI 73b0797891 Add builtins highlighting 2024-04-10 15:20:29 +00:00
10 changed files with 84 additions and 14 deletions

View file

@ -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

View file

@ -23,7 +23,7 @@ module.exports = grammar({
$.module,
),
line_comment: (_) => seq("//", /.*/),
line_comment: (_) => seq("//", /[^\n]*/),
block_comment: (_) => seq("/*", /[^*]*\*+([^/*][^*]*\*+)*/, '/'),

View file

@ -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 {{{

19
scripts/minimal_init.lua Normal file
View file

@ -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 },
})

2
src/grammar.json generated
View file

@ -30,7 +30,7 @@
},
{
"type": "PATTERN",
"value": ".*"
"value": "[^\\n]*"
}
]
},

View file

@ -85,6 +85,23 @@ Block comment with asterisks
--------------------------------------------------------------------------------
(source_file
(block_comment))
================================================================================
Block comment (multiline)
================================================================================
/*
This
is
a
long
comment
*/
--------------------------------------------------------------------------------
(source_file
(block_comment))

View file

@ -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
})

View file

@ -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
)

View file

@ -1,6 +1,6 @@
foo {
field: {
// <- variable.member
// <- variable.parameter
key: 42,
// <- property
},

View file

@ -11,5 +11,5 @@ select = 42
// Or module property
foo {
select: 42,
// <- variable.member
// <- variable.parameter
}