Skip to content

Commit 5610d01

Browse files
committed
UpdateRules: fix set filetype unknown
Fix `set filetype unknown` not working as expected in the following scenario: 1. open foo.txt (no filetype detected) -> ft is `unknown`, highlighted with default.yaml, as expected 2. `set filetype go` -> ft is `go`, highlighted with go.yaml as expected 3. `set filetype unknown` -> ft is still `go`, still highlighted with go.yaml (whereas expected behavior is: ft is `unknown`, highlighted with default.yaml) Fix that by always updating b.SyntaxDef value, not reusing the old one. This also makes the code simpler and easier to understand.
1 parent 0806add commit 5610d01

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

internal/buffer/buffer.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,8 @@ func (b *Buffer) UpdateRules() {
753753
return
754754
}
755755

756+
b.SyntaxDef = nil
757+
756758
// syntaxFileInfo is an internal helper structure
757759
// to store properties of one single syntax file
758760
type syntaxFileInfo struct {
@@ -945,16 +947,14 @@ func (b *Buffer) UpdateRules() {
945947
highlight.ResolveIncludes(b.SyntaxDef, files)
946948
}
947949

948-
if b.Highlighter == nil || syntaxFile != "" {
949-
if b.SyntaxDef != nil {
950-
b.Settings["filetype"] = b.SyntaxDef.FileType
951-
} else {
952-
// search for the default file in the user's custom syntax files
953-
b.SyntaxDef = findRealRuntimeSyntaxDef("default", nil)
954-
if b.SyntaxDef == nil {
955-
// search for the default file in the runtime files
956-
b.SyntaxDef = findRuntimeSyntaxDef("default", nil)
957-
}
950+
if b.SyntaxDef != nil {
951+
b.Settings["filetype"] = b.SyntaxDef.FileType
952+
} else {
953+
// search for the default file in the user's custom syntax files
954+
b.SyntaxDef = findRealRuntimeSyntaxDef("default", nil)
955+
if b.SyntaxDef == nil {
956+
// search for the default file in the runtime files
957+
b.SyntaxDef = findRuntimeSyntaxDef("default", nil)
958958
}
959959
}
960960

0 commit comments

Comments
 (0)