Compare commits

...

3 Commits

Author SHA1 Message Date
David Else e4ef096945
Update Bash highlights (#13477) 2025-05-08 08:22:14 -05:00
Michael Davis 9e7a6a5dbd
xtask: Allow passing languages and themes to check
This is for convenience when testing a few languages or themes, for
example while updating a language's parser and queries. query-check in
particular can take a while since parser initialization and query
analysis can each take some time and there are now many many languages.
Specifying the exact language makes the feedback loop much faster.
2025-05-08 09:04:22 -04:00
Nik Revenco 1460a086df
feat: add wgsl built-in functions to `@function.builtin` (#13479)
Co-authored-by: Nik Revenco <154856872+NikitaRevenco@users.noreply.github.com>
2025-05-08 07:56:36 -05:00
4 changed files with 341 additions and 35 deletions

View File

@ -1084,7 +1084,7 @@ indent = { tab-width = 2, unit = " " }
[[grammar]]
name = "bash"
source = { git = "https://github.com/tree-sitter/tree-sitter-bash", rev = "f8fb3274f72a30896075585b32b0c54cad65c086" }
source = { git = "https://github.com/tree-sitter/tree-sitter-bash", rev = "487734f87fd87118028a65a4599352fa99c9cde8" }
[[language]]
name = "php"

View File

@ -1,3 +1,51 @@
[
"("
")"
"{"
"}"
"["
"]"
"[["
"]]"
"(("
"))"
] @punctuation.bracket
[
";"
";;"
";&"
";;&"
"&"
] @punctuation.delimiter
[
">"
">>"
"<"
"<<"
"&&"
"|"
"|&"
"||"
"="
"+="
"=~"
"=="
"!="
"&>"
"&>>"
"<&"
">&"
">|"
"<&-"
">&-"
"<<-"
"<<<"
".."
"!"
] @operator
[
(string)
(raw_string)
@ -10,9 +58,14 @@
(heredoc_end)
] @label
(command_name) @function
(variable_assignment
(word) @string)
(variable_name) @variable.other.member
(command
argument: "$" @string) ; bare dollar
(concatenation
(word) @string)
[
"if"
@ -37,40 +90,161 @@
[
"declare"
"typeset"
"export"
"readonly"
"local"
"unset"
"unsetenv"
] @keyword
"export" @keyword.control.import
"function" @keyword.function
(comment) @comment
(special_variable_name) @constant
; trap -l
((word) @constant.builtin
(#any-of? @constant.builtin
"SIGHUP" "SIGINT" "SIGQUIT" "SIGILL" "SIGTRAP" "SIGABRT" "SIGBUS" "SIGFPE" "SIGKILL" "SIGUSR1"
"SIGSEGV" "SIGUSR2" "SIGPIPE" "SIGALRM" "SIGTERM" "SIGSTKFLT" "SIGCHLD" "SIGCONT" "SIGSTOP"
"SIGTSTP" "SIGTTIN" "SIGTTOU" "SIGURG" "SIGXCPU" "SIGXFSZ" "SIGVTALRM" "SIGPROF" "SIGWINCH"
"SIGIO" "SIGPWR" "SIGSYS" "SIGRTMIN" "SIGRTMIN+1" "SIGRTMIN+2" "SIGRTMIN+3" "SIGRTMIN+4"
"SIGRTMIN+5" "SIGRTMIN+6" "SIGRTMIN+7" "SIGRTMIN+8" "SIGRTMIN+9" "SIGRTMIN+10" "SIGRTMIN+11"
"SIGRTMIN+12" "SIGRTMIN+13" "SIGRTMIN+14" "SIGRTMIN+15" "SIGRTMAX-14" "SIGRTMAX-13"
"SIGRTMAX-12" "SIGRTMAX-11" "SIGRTMAX-10" "SIGRTMAX-9" "SIGRTMAX-8" "SIGRTMAX-7" "SIGRTMAX-6"
"SIGRTMAX-5" "SIGRTMAX-4" "SIGRTMAX-3" "SIGRTMAX-2" "SIGRTMAX-1" "SIGRTMAX"))
((word) @constant.builtin.boolean
(#any-of? @constant.builtin.boolean "true" "false"))
(function_definition name: (word) @function)
(comment) @comment
(file_descriptor) @constant.numeric.integer
(test_operator) @operator
(command_substitution
"$(" @punctuation.special
")" @punctuation.special)
(process_substitution
[
"<("
">("
] @punctuation.special
")" @punctuation.special)
(arithmetic_expansion
[
"$(("
"(("
] @punctuation.special
"))" @punctuation.special)
(arithmetic_expansion
"," @punctuation.delimiter)
(ternary_expression
[
"?"
":"
] @keyword.control.conditional)
(binary_expression
operator: _ @operator)
(unary_expression
operator: _ @operator)
(postfix_expression
operator: _ @operator)
(function_definition
name: (word) @function)
(command_name
(word) @function)
(command_name
(word) @function.builtin
(#any-of? @function.builtin
"." ":" "alias" "bg" "bind" "break" "builtin" "caller" "cd" "command" "compgen" "complete"
"compopt" "continue" "coproc" "dirs" "disown" "echo" "enable" "eval" "exec" "exit" "false" "fc"
"fg" "getopts" "hash" "help" "history" "jobs" "kill" "let" "logout" "mapfile" "popd" "printf"
"pushd" "pwd" "read" "readarray" "return" "set" "shift" "shopt" "source" "suspend" "test" "time"
"times" "trap" "true" "type" "typeset" "ulimit" "umask" "unalias" "wait"))
(command
argument: [
(word) @variable.parameter
(concatenation
(word) @variable.parameter)
])
(declaration_command
(word) @variable.parameter)
(unset_command
(word) @variable.parameter)
(number) @constant.numeric
(file_redirect
(word) @string.special.path)
(herestring_redirect
(word) @string)
(file_descriptor) @operator
(simple_expansion
"$" @punctuation.special) @none
(expansion
"${" @punctuation.special
"}" @punctuation.special) @none
(expansion
operator: _ @punctuation.special)
(expansion
"@"
.
operator: _ @constant.character)
((expansion
(subscript
index: (word) @constant.character))
(#any-of? @constant.character "@" "*"))
"``" @punctuation.special
(variable_name) @variable
((variable_name) @constant
(#match? @constant "^[A-Z][A-Z_0-9]*$"))
((variable_name) @variable.builtin
(#any-of? @variable.builtin
; https://www.gnu.org/software/bash/manual/html_node/Bourne-Shell-Variables.html
"CDPATH" "HOME" "IFS" "MAIL" "MAILPATH" "OPTARG" "OPTIND" "PATH" "PS1" "PS2"
; https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html
"_" "BASH" "BASHOPTS" "BASHPID" "BASH_ALIASES" "BASH_ARGC" "BASH_ARGV" "BASH_ARGV0" "BASH_CMDS"
"BASH_COMMAND" "BASH_COMPAT" "BASH_ENV" "BASH_EXECUTION_STRING" "BASH_LINENO"
"BASH_LOADABLES_PATH" "BASH_REMATCH" "BASH_SOURCE" "BASH_SUBSHELL" "BASH_VERSINFO"
"BASH_VERSION" "BASH_XTRACEFD" "CHILD_MAX" "COLUMNS" "COMP_CWORD" "COMP_LINE" "COMP_POINT"
"COMP_TYPE" "COMP_KEY" "COMP_WORDBREAKS" "COMP_WORDS" "COMPREPLY" "COPROC" "DIRSTACK" "EMACS"
"ENV" "EPOCHREALTIME" "EPOCHSECONDS" "EUID" "EXECIGNORE" "FCEDIT" "FIGNORE" "FUNCNAME"
"FUNCNEST" "GLOBIGNORE" "GROUPS" "histchars" "HISTCMD" "HISTCONTROL" "HISTFILE" "HISTFILESIZE"
"HISTIGNORE" "HISTSIZE" "HISTTIMEFORMAT" "HOSTFILE" "HOSTNAME" "HOSTTYPE" "IGNOREEOF" "INPUTRC"
"INSIDE_EMACS" "LANG" "LC_ALL" "LC_COLLATE" "LC_CTYPE" "LC_MESSAGES" "LC_NUMERIC" "LC_TIME"
"LINENO" "LINES" "MACHTYPE" "MAILCHECK" "MAPFILE" "OLDPWD" "OPTERR" "OSTYPE" "PIPESTATUS"
"POSIXLY_CORRECT" "PPID" "PROMPT_COMMAND" "PROMPT_DIRTRIM" "PS0" "PS3" "PS4" "PWD" "RANDOM"
"READLINE_ARGUMENT" "READLINE_LINE" "READLINE_MARK" "READLINE_POINT" "REPLY" "SECONDS" "SHELL"
"SHELLOPTS" "SHLVL" "SRANDOM" "TIMEFORMAT" "TMOUT" "TMPDIR" "UID"))
(case_item
value: (word) @variable.parameter)
[
(command_substitution)
(process_substitution)
(expansion)
] @embedded
[
"$"
"&&"
">"
">>"
"<"
"|"
] @operator
(
(command (_) @constant)
(#match? @constant "^-")
)
(regex)
(extglob_pattern)
] @string.regexp

View File

@ -31,8 +31,6 @@
["(" ")" "[" "]" "{" "}"] @punctuation.bracket
(type_declaration ["<" ">"] @punctuation.bracket)
[
"break"
"continue"
@ -115,3 +113,120 @@
(identifier) @attribute)
(comment) @comment
; built-in wgsl functions: https://webgpufundamentals.org/webgpu/lessons/webgpu-wgsl-function-reference.html
(
(identifier) @function.builtin
(#any-of? @function.builtin
"abs"
"abs"
"acos"
"acosh"
"all"
"any"
"arrayLength"
"asin"
"asinh"
"atan"
"atan2"
"atanh"
"atomicAdd"
"atomicLoad"
"atomicStore"
"bitcast"
"ceil"
"clamp"
"cos"
"cosh"
"countLeadingZeros"
"countOneBits"
"countTrailingZeros"
"cross"
"degrees"
"determinant"
"distance"
"dot"
"dpdx"
"dpdxCoarse"
"dpdxFine"
"dpdy"
"dpdyCoarse"
"dpdyFine"
"exp"
"exp2"
"extractBits"
"faceForward"
"firstLeadingBit"
"firstTrailingBit"
"floor"
"fma"
"fract"
"frexp"
"fwidth"
"fwidthCoarse"
"fwidthFine"
"gather_depth_compare"
"gather_x_components"
"insertBits"
"inverseSqrt"
"ldexp"
"length"
"log"
"log2"
"max"
"min"
"mix"
"modf"
"normalize"
"pack2x16float"
"pack2x16snorm"
"pack2x16unorm"
"pack4x8snorm"
"pack4x8unorm"
"pow"
"quantizeToF16"
"radians"
"reflect"
"refract"
"reverseBits"
"round"
"saturate"
"select"
"sign"
"sin"
"sinh"
"smoothstep"
"sqrt"
"step"
"storageBarrier"
"tan"
"tanh"
"textureDimensions"
"textureGather"
"textureGatherCompare"
"textureLoad"
"textureNumLayers"
"textureNumLevels"
"textureNumSamples"
"textureSample"
"textureSampleBaseClampToEdge"
"textureSampleBias"
"textureSampleCompare"
"textureSampleCompareLevel"
"textureSampleGrad"
"textureSampleLevel"
"textureStore"
"transpose"
"trunc"
"unpack2x16float"
"unpack2x16snorm"
"unpack2x16unorm"
"unpack4x8snorm"
"unpack4x8unorm"
"workgroupBarrier"
"workgroupUniformLoad"
)
)
(type_declaration ["<" ">"] @punctuation.bracket)
(variable_qualifier ["<" ">"] @punctuation.bracket)

View File

@ -8,6 +8,7 @@ type DynError = Box<dyn Error>;
pub mod tasks {
use crate::DynError;
use std::collections::HashSet;
pub fn docgen() -> Result<(), DynError> {
use crate::docgen::*;
@ -17,7 +18,7 @@ pub mod tasks {
Ok(())
}
pub fn querycheck() -> Result<(), DynError> {
pub fn querycheck(languages: impl Iterator<Item = String>) -> Result<(), DynError> {
use crate::helpers::lang_config;
use helix_core::{syntax::read_query, tree_sitter::Query};
use helix_loader::grammar::get_language;
@ -30,7 +31,14 @@ pub mod tasks {
"indents.scm",
];
let languages_to_check: HashSet<_> = languages.collect();
for language in lang_config().language {
if !languages_to_check.is_empty() && !languages_to_check.contains(&language.language_id)
{
continue;
}
let language_name = &language.language_id;
let grammar_name = language.grammar.as_ref().unwrap_or(language_name);
for query_file in query_files {
@ -55,9 +63,11 @@ pub mod tasks {
Ok(())
}
pub fn themecheck() -> Result<(), DynError> {
pub fn themecheck(themes: impl Iterator<Item = String>) -> Result<(), DynError> {
use helix_view::theme::Loader;
let themes_to_check: HashSet<_> = themes.collect();
let theme_names = [
vec!["default".to_string(), "base16_default".to_string()],
Loader::read_names(&crate::path::themes()),
@ -67,6 +77,10 @@ pub mod tasks {
let mut errors_present = false;
for name in theme_names {
if !themes_to_check.is_empty() && !themes_to_check.contains(&name) {
continue;
}
let (_, warnings) = loader.load_with_warnings(&name).unwrap();
if !warnings.is_empty() {
@ -93,22 +107,25 @@ pub mod tasks {
Usage: Run with `cargo xtask <task>`, eg. `cargo xtask docgen`.
Tasks:
docgen: Generate files to be included in the mdbook output.
query-check: Check that tree-sitter queries are valid.
theme-check: Check that theme files in runtime/themes are valid.
docgen Generate files to be included in the mdbook output.
query-check [languages] Check that tree-sitter queries are valid for the given
languages, or all languages if none are specified.
theme-check [themes] Check that the theme files in runtime/themes/ are valid for the
given themes, or all themes if none are specified.
"
);
}
}
fn main() -> Result<(), DynError> {
let task = env::args().nth(1);
let mut args = env::args().skip(1);
let task = args.next();
match task {
None => tasks::print_help(),
Some(t) => match t.as_str() {
"docgen" => tasks::docgen()?,
"query-check" => tasks::querycheck()?,
"theme-check" => tasks::themecheck()?,
"query-check" => tasks::querycheck(args)?,
"theme-check" => tasks::themecheck(args)?,
invalid => return Err(format!("Invalid task name: {}", invalid).into()),
},
};