feat: add fts indexing
This commit is contained in:
@@ -21,14 +21,16 @@ var packageQueries = map[string]string{
|
||||
"erlang": `(module_attribute name: (atom) @name)`,
|
||||
}
|
||||
|
||||
// ExtractPackage extracts the package/module name from source code.
|
||||
// ExtractPackage extracts the package/module name from a pre-parsed tree.
|
||||
// Falls back to deriving from the file path if no language-specific query exists
|
||||
// or the query finds no match.
|
||||
func ExtractPackage(src []byte, filePath string, entry *grammars.LangEntry) string {
|
||||
func ExtractPackage(src []byte, filePath string, entry *grammars.LangEntry, tree *gotreesitter.Tree) string {
|
||||
if queryStr, ok := packageQueries[entry.Name]; ok {
|
||||
lang := entry.Language()
|
||||
if pkg := runPackageQuery(src, lang, queryStr); pkg != "" {
|
||||
return pkg
|
||||
if tree != nil && tree.RootNode() != nil {
|
||||
lang := entry.Language()
|
||||
if pkg := runPackageQuery(src, lang, queryStr, tree); pkg != "" {
|
||||
return pkg
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,14 +42,7 @@ func ExtractPackage(src []byte, filePath string, entry *grammars.LangEntry) stri
|
||||
return filepath.Base(dir)
|
||||
}
|
||||
|
||||
func runPackageQuery(src []byte, lang *gotreesitter.Language, queryStr string) string {
|
||||
parser := gotreesitter.NewParser(lang)
|
||||
tree, err := parser.Parse(src)
|
||||
if err != nil || tree == nil || tree.RootNode() == nil {
|
||||
return ""
|
||||
}
|
||||
defer tree.Release()
|
||||
|
||||
func runPackageQuery(src []byte, lang *gotreesitter.Language, queryStr string, tree *gotreesitter.Tree) string {
|
||||
query, err := gotreesitter.NewQuery(queryStr, lang)
|
||||
if err != nil {
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user