Documentation
¶
Index ¶
Constants ¶
const ( LangGo = "Go" LangPython = "Python" LangJavaScript = "JavaScript" LangTypeScript = "TypeScript" LangRust = "Rust" LangJava = "Java" LangKotlin = "Kotlin" LangCSharp = "C#" LangRuby = "Ruby" LangC = "C" LangCPP = "C++" LangPHP = "PHP" LangScala = "Scala" LangLua = "Lua" LangShell = "Shell" )
Language names returned by langForExt.
Variables ¶
This section is empty.
Functions ¶
func CommentAndStringSpans ¶
CommentAndStringSpans returns the byte ranges [start, end) of the comments and string literals in src, in order, as the language's tree-sitter grammar parses them. ok is false when the language has no grammar or ctx ended.
func IsTestFile ¶
IsTestFile reports whether rel, a slash-separated path relative to a workspace root, is a test, test data or test support code, by the naming and directory conventions of the languages in the extension table (LangForExt). It is the one classifier the tools rank by, so a consumer that ranks, filters or splits files the same way can agree with them.
Any file under a directory named test, tests, __tests__, spec, testdata, testutil, testutils or testhelpers counts. Otherwise a source file (one whose extension is in the table) counts when its name, without the extension:
- ends in _test or starts with test_ (Go, Python, Rust, C, Ruby, ...);
- ends in _spec (Ruby) or in .test or .spec (JavaScript, TypeScript);
- ends in Test or Tests after at least one character (Java, Kotlin, C#, Ruby), or in IT (Java integration tests);
- is test support: conftest.py, setupTests, jest.setup or vitest.setup.
The rule is a convention, not a parse: it reads no file.
func LangFor ¶
LangFor returns the language of the file at path, whose content is src: the extension table's answer, except that a `.h` header containing C++ is C++. src may be nil, in which case the extension alone decides.
func LangForExt ¶
LangForExt returns the language name for a file extension (with the leading dot, in any case), or "" if the extension is not in the table. It is the exported form of the table's lookup, so a package that names languages can use the table instead of keeping a copy.
Types ¶
type Decl ¶
type Decl struct {
Kind Kind
Name string
Container string
Signature string
Exported bool
StartLine int // 1-based, inclusive
EndLine int // 1-based, inclusive; 0 when unknown
}
Decl is one declaration in a source file.
type File ¶
type File struct {
Path string // slash-separated, relative to Options.Root or absolute
Lang string // language name from the extension table
Backend Backend // which backend produced the declarations
Decls []Decl // sorted by StartLine, ties broken by Name; never nil
}
File is the outline of one source file.