vim-patch:9.2.0926: filetype: Business Central files are not recognized (#41230)

Problem:  filetype: Business Central files are not recognized
Solution: Add filetype detection logic for *.al files to detect perl or
          use either perl or al filetype (Torben Leth).

Reference:
https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-dev-overview

closes: vim/vim#20975

Supported by AI.

9b41cf6386
This commit is contained in:
Torben Leth
2026-08-09 02:49:20 +02:00
committed by GitHub
parent a45d3dccf1
commit f538a4f16f
4 changed files with 85 additions and 2 deletions

View File

@@ -245,6 +245,7 @@ local extension = {
adb = 'ada',
tdf = 'ahdl',
aidl = 'aidl',
al = detect.al,
a68 = 'algol68',
aml = 'aml',
run = 'ampl',
@@ -1006,7 +1007,6 @@ local extension = {
plx = 'perl',
prisma = 'prisma',
psgi = 'perl',
al = 'perl',
ctp = 'php',
php = 'php',
phpt = 'php',

View File

@@ -31,6 +31,37 @@ local matchregex = vim.filetype._matchregex
-- luacheck: push no unused args
-- luacheck: push ignore 122
-- AL (Microsoft Dynamics 365 Business Central) or Perl AutoLoader
--- @type vim.filetype.mapfn
function M.al(_, bufnr)
if vim.g.filetype_al then
return vim.g.filetype_al
end
-- AL sources declare an object as "<kind> <id> <name>" at the start of a
-- line, optionally preceded by namespace and using declarations. Perl
-- AutoLoader chunks match neither. Matching a bare keyword anywhere would
-- be wrong: table, page and report are ordinary English words, so the object
-- name must follow. The match is case sensitive because AL tooling emits
-- lowercase keywords, while prose in Perl comments is usually capitalised.
for _, line in ipairs(getlines(bufnr, 1, 200)) do
if
matchregex(
line,
[[^\s*\%(codeunit\|page\|pageextension\|pagecustomization\|table\|tableextension\|]]
.. [[report\|reportextension\|xmlport\|query\|enum\|enumextension\|profile\|profileextension\|]]
.. [[controladdin\|interface\|permissionset\|permissionsetextension\|entitlement\)\>\s\+\%(\d\|"\|\u\)]]
)
or findany(
line,
{ '^%s*dotnet%s*$', '^%s*namespace%s+[%w._]+%s*;', '^%s*using%s+[%w._]+%s*;' }
)
then
return 'al'
end
end
return 'perl'
end
-- Erlang Application Resource Files (*.app.src is matched by extension)
-- See: https://erlang.org/doc/system/applications
--- @type vim.filetype.mapfn