1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-04-11 11:32:05 +02:00

docs: note about Get() being slow due to file matching

Fixes #714
This commit is contained in:
Alec Thomas 2023-09-22 07:00:14 +10:00
parent ccd8d68495
commit 9087c632c4
3 changed files with 8 additions and 1 deletions

View File

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

View File

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

View File

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