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.
This commit is contained in:
Dmytro Maluka
2024-03-23 17:49:09 +01:00
parent c2c2b2addf
commit 13483602d5

View File

@@ -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
}
}