From 13483602d56f984c043a722f3dcab6c24b80b6fd Mon Sep 17 00:00:00 2001 From: Dmytro Maluka Date: Sat, 23 Mar 2024 17:49:09 +0100 Subject: [PATCH] UpdateRules: fix foundDef logic The original meaning of foundDef was: "we already found the final syntax definition in a user's custom syntax file". After introducing signatures its meaning became: "we found some potential syntax definition in a user's custom syntax file, but we don't know yet if it's the final one". This makes the code confusing and actually buggy. At least one bug is that if we found some potential filename matches in the user's custom syntax files, we don't search for more matches in the built-in syntax files. Which is wrong: we should keep searching for as many potential matches as possible, in both user's and built-in syntax files, to select the best one among them. Fix that by restoring the original meaning of foundDef and updating the logic accordingly. --- internal/buffer/buffer.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/internal/buffer/buffer.go b/internal/buffer/buffer.go index 8720aa47..0ba7aa62 100644 --- a/internal/buffer/buffer.go +++ b/internal/buffer/buffer.go @@ -730,11 +730,11 @@ func (b *Buffer) UpdateRules() { screen.TermMessage("Error parsing syntax file " + f.Name() + ": " + err.Error()) continue } - foundDef = true if header.FileType == ft { b.SyntaxDef = syndef syntaxFile = f.Name() + foundDef = true break } else { syntaxFiles = append(syntaxFiles, syntaxFileBuffer{header, f.Name(), syndef}) @@ -784,7 +784,10 @@ func (b *Buffer) UpdateRules() { for j := 0; j < limit && !signatureMatch; j++ { if syntaxFiles[i].header.MatchFileSignature(b.lines[j].data) { syntaxFile = syntaxFiles[i].fileName - b.SyntaxDef = syntaxFiles[i].syntaxDef + if syntaxFiles[i].syntaxDef != nil { + b.SyntaxDef = syntaxFiles[i].syntaxDef + foundDef = true + } header = syntaxFiles[i].header signatureMatch = true } @@ -794,7 +797,10 @@ func (b *Buffer) UpdateRules() { } if length == 1 || !signatureMatch { syntaxFile = syntaxFiles[0].fileName - b.SyntaxDef = syntaxFiles[0].syntaxDef + if syntaxFiles[0].syntaxDef != nil { + b.SyntaxDef = syntaxFiles[0].syntaxDef + foundDef = true + } header = syntaxFiles[0].header } }