diff --git a/lexers/lexers.go b/lexers/lexers.go index 161caefea..4fa35ad22 100644 --- a/lexers/lexers.go +++ b/lexers/lexers.go @@ -30,6 +30,9 @@ func Names(withAliases bool) []string { } // Get a Lexer by name, alias or file extension. +// +// Note that this if there isn't an exact match on name or alias, this will +// call Match(), so it is not efficient. func Get(name string) chroma.Lexer { return GlobalLexerRegistry.Get(name) } @@ -40,6 +43,9 @@ func MatchMimeType(mimeType string) chroma.Lexer { } // Match returns the first lexer matching filename. +// +// Note that this iterates over all file patterns in all lexers, so it's not +// particularly efficient. func Match(filename string) chroma.Lexer { return GlobalLexerRegistry.Match(filename) } diff --git a/lexers/lexers_test.go b/lexers/lexers_test.go index 46513ea61..453207ef8 100644 --- a/lexers/lexers_test.go +++ b/lexers/lexers_test.go @@ -179,7 +179,6 @@ func FileTestAnalysis(t *testing.T, lexer chroma.Lexer, actualFilepath, expected assert.NoError(t, err) assert.NoError(t, f.Close()) } else { - // fail via an assertion of string comparison for nicer diff output assert.Equal(t, string(expectedData), actualData.String()) } } diff --git a/registry.go b/registry.go index 55ed36233..4742e8c5a 100644 --- a/registry.go +++ b/registry.go @@ -97,6 +97,8 @@ func (l *LexerRegistry) MatchMimeType(mimeType string) Lexer { } // Match returns the first lexer matching filename. +// +// Note that this iterates over all file patterns in all lexers, so is not fast. func (l *LexerRegistry) Match(filename string) Lexer { filename = filepath.Base(filename) matched := PrioritisedLexers{}