Skip to content

Commit

Permalink
feat: syntax highlighting for .bazelrc
Browse files Browse the repository at this point in the history
The main purpose here is really to prevent vscode from autodetecting
.bazelrc as a shell file, resulting in complaints about syntax that
isn't valid in a bash script, or mistakenly highlighting e.g. variable
expansions as if they were actually honored in a .bazelrc.

We can also do a bit better, by actually understanding the semantics of
e.g. config specifiers and so on.

This does _not_ try to exhaustively match the list of all possible
flags, and so it can make mistakes like treating --copt -O3 as if it
were two separate flags rather than a flag + value, however that's
mostly harmless.  Maintaining a list of known flags would be
prohibitively difficult to maintain without some kind of automation.

There is special treatment for a couple of flags, including
`--config` and a few flags that expect regex arguments, like
`--instrumentation_filter`.

Closes bazelbuild#259
  • Loading branch information
adam-azarchs committed Apr 6, 2024
1 parent 75705f8 commit 847cf8e
Show file tree
Hide file tree
Showing 3 changed files with 623 additions and 0 deletions.
16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,29 @@
}
],
"grammars": [
{
"language": "bazelrc",
"scopeName": "source.bazelrc",
"path": "./syntaxes/bazelrc.tmLanguage.json"
},
{
"language": "starlark",
"scopeName": "source.starlark",
"path": "./syntaxes/starlark.tmLanguage.json"
}
],
"languages": [
{
"id": "bazelrc",
"extensions": [
".bazelrc"
],
"filenames": [
".bazelrc",
"bazel.rc"
],
"configuration": "./syntaxes/bazelrc.configuration.json"
},
{
"id": "starlark",
"aliases": [
Expand Down
33 changes: 33 additions & 0 deletions syntaxes/bazelrc.configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"comments": {
"lineComment": "#"
},
"autoClosingPairs": [
{
"open": "\"",
"close": "\"",
"notIn": [
"string",
"comment"
]
},
{
"open": "'",
"close": "'",
"notIn": [
"string",
"comment"
]
}
],
"surroundingPairs": [
[
"\"",
"\""
],
[
"'",
"'"
]
]
}
Loading

0 comments on commit 847cf8e

Please sign in to comment.