Add AL (Microsoft Dynamics 365 Business Central) language support - #16161
Open
SShadowS wants to merge 1 commit into
Open
Add AL (Microsoft Dynamics 365 Business Central) language support#16161SShadowS wants to merge 1 commit into
SShadowS wants to merge 1 commit into
Conversation
AL is the language of Microsoft Dynamics 365 Business Central. It is recognised by GitHub Linguist, and already supported in VS Code, Zed and Sublime Text. Grammar: https://github.com/SShadowS/tree-sitter-al, pinned to v3.2.1. It is published to crates.io, npm and PyPI, runs the upstream tree-sitter CI workflows on Linux, macOS and Windows, has 1472 corpus tests, and targets ABI 15. The queries come from the grammar repository, which targets nvim-treesitter, so they are adapted to Helix rather than copied: - indents.scm is rewritten. AL is written Allman style and the grammar puts the braces inside the declaration node rather than in a separate brace-delimited node, so the declaration scope already covers the line the opening brace sits on; "{" therefore outdents. Nodes whose body is a begin/end code_block no longer open a scope of their own, since the code_block opens one on the following line and the two would stack. Brace-less if/while/for/foreach/with bodies use header-scoped captures the way the C query does, and repeat/until scopes like a block. - locals.scm definitions gain the suffixes Helix resolves against (local.definition.variable, .variable.parameter). Bare local.definition is a discard, so the file previously did nothing. Table fields, enum values and keys are demoted to discards: they are object members, not locals. - highlights.scm captures are renamed to Helix's theme scopes, so property becomes variable.other.member, number becomes constant.numeric.*, module becomes namespace, and the keyword.* and *.definition variants map onto their documented equivalents. The (ERROR) capture is dropped; repainting half-typed code is not wanted. - textobjects.scm loses the block.* captures, which Helix has no textobject for, and the repeat-body capture that made mif inside a loop select the loop rather than the enclosing procedure. - folds.scm is dropped: Helix does not load a folds query. - tags.scm is added, with method mapped onto definition.function and local symbols removed, so the symbol pickers work. - injections.scm is added for comment injection. Verified with cargo xtask query-check al, indent-check al (against the new tests/indent/al.al fixture, covering objects, sections, fields, var sections, begin/end, brace-less and braced if/else, while, for, repeat/until, case with an else branch, and procedures) and docgen.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds AL, the language of Microsoft Dynamics 365 Business Central.
The language
AL is what Business Central extensions are written in. It is a recognised language in GitHub Linguist (since 2020), and already has editor support in VS Code (Microsoft's own extension), Zed and Sublime Text.
The grammar
SShadowS/tree-sitter-al, pinned to v3.2.1.
tree-sitter/parser-test-actionon Linux, macOS and Windows, fuzzes the external scanner, and validates the queries withts_query_lsQueries
The queries come from the grammar repository, which targets nvim-treesitter, so they are adapted rather than copied.
indents.scm is rewritten. Two things make AL different from most C-likes here:
compound_statement. So the declaration's scope already covers the line the opening brace sits on, and"{"has to outdent.begin/endblock must not open a scope of their own, because thecode_blockopens one on the following line and the two stack into a double indent.Brace-less
if/while/for/foreach/withbodies use header-scoped captures in the same shape as the C query;repeat/untilscopes like a block.locals.scm definitions gained the suffixes Helix resolves against (
local.definition.variable,.variable.parameter). A barelocal.definitionis a discard, so the file as inherited did nothing at all. Table fields, enum values and keys are deliberately left as discards, since they are object members rather than locals.highlights.scm captures are renamed to the documented theme scopes:
propertytovariable.other.member,numbertoconstant.numeric.*,moduletonamespace, and thekeyword.*and*.definitionvariants onto their Helix equivalents. The(ERROR)capture is dropped, since repainting half-typed code while typing is not wanted.textobjects.scm loses the
block.*captures, which Helix has no textobject for, and arepeat-body capture that mademifinside a loop select the loop rather than the enclosing procedure.tags.scm is added, with
definition.methodmapped ontodefinition.functionand local symbols removed, so the symbol pickers are useful.injections.scm is added for comment injection.
folds.scm from the grammar repo is deliberately not included, since Helix does not load a folds query.
Verification
query-checkfetched the grammar from the pinned revision and built it before compiling the queries, so it also confirms the pin resolves and the grammar builds and loads under Helix.indent-checkruns against the newtests/indent/al.alfixture, which covers objects, sections, fields, keys,varsections,begin/end, braced and brace-lessif/else,while,for,repeat/until,casewith anelsebranch, and procedures. It caught two real bugs during development thatquery-checkcannot see, which is why the fixture is included rather than offered.highlight-checkruns againsttests/query/highlights/al/constructs.aland pins the renamed captures, which are the riskiest part of this change.cargo xtask docgenwas run and the regeneratedlang-support.mdrow is in the commit; re-running it produces no further change.cargo test --workspacepasses apart fromtest_treesitter_indent_rust_helix, which fails identically onmasteron this machine and is unrelated to this change (it re-indents Helix's own Rust sources, and the checkout has CRLF line endings).No
rainbows.scmis included; happy to add one if you would like the language to land with it.AI disclosure
This change was prepared with AI assistance (Claude). The query adaptation was driven by the checks above, all run locally.