From 7fa089f463dac83f256a8336ddb0adc9eae483a2 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Tue, 9 Jul 2024 19:58:02 +0200 Subject: vim-patch:9.1.0551: filetype: htmlangular files are not properly detected Problem: filetype: htmlangular files are not properly detected Solution: Use the new htmlangular filetype for angular files, because since angular v17, those are no longer valid HTML files. (Dennis van den Berg) Since Angular 17, the new Control Flow Syntax is not valid HTML. This PR adds a new filetype detection for the HTML templates of Angular. It first checks the filename. The Angular convention is to use *.component.html for the template. However, this is not mandatory. If the filename does not match, it will check the contents of the file if it contains: - One of the Control-Flow blocks: @if, @for, @switch, @defer - A structural directive: *ngIf, *ngFor, *ngSwitch, *ngTemplateOutlet - Builtin Angular elements: ng-template or ng-content - String interpolation: {{ something }} This enables the Angular LSP to attach only to htmlangular filetypes, as well as language parsers, such as tree-sitter. closes: vim/vim#15190 https://github.com/vim/vim/commit/1ad194c0dfd82ca1e7a1b6f2fca89a487794158d Co-authored-by: Dennis van den Berg --- runtime/lua/vim/filetype/detect.lua | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'runtime/lua/vim') diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua index 85c8d4c9dc..8a217a4ac2 100644 --- a/runtime/lua/vim/filetype/detect.lua +++ b/runtime/lua/vim/filetype/detect.lua @@ -710,9 +710,22 @@ function M.haredoc(path, _) end --- @type vim.filetype.mapfn -function M.html(_, bufnr) +function M.html(path, bufnr) + -- Test if the filename follows the Angular component template convention + local filename = fn.fnamemodify(path, ':t') + if filename:find('%.component%.html$') then + return 'htmlangular' + end + for _, line in ipairs(getlines(bufnr, 1, 40)) do - if matchregex(line, [[\