require "tree_sitter"
require "./extract_symbols.cr"
class GitFOSS::Code::Indexer
VERSION = "0.1.0"
@parser = TreeSitter::Parser.new
@files = [] of String
@symbols = {} of String => Array(CodeSymbol)
def initialize
end
def files=(values : Array(String))
@files = values
end
def get_files_symbols : Hash(String, Array(CodeSymbol))
@files.each do |p|
@symbols[p] = get_symbols(p)
end
@symbols
end
def get_symbols(
file_path : String
) : Array(CodeSymbol)
symbols = [] of CodeSymbol
path = Path[file_path]
symbols = File.open(path) do |f|
file = RepositoryFile.new(
name: path.basename,
content: f.gets_to_end,
)
@parser = TreeSitter::Parser.new ("crystal")
tree = @parser.parse(nil, file.content)
extract_symbols(
@parser,
tree.root_node,
file,
)
end
symbols
end
end
code_indexer = GitFOSS::Code::Indexer.new
code_indexer.files = [
"/home/xana/Dev/gitfoss-code-indexer/src/extract_symbols.cr",
"/home/xana/Dev/gitfoss-code-indexer/shard.yml",
"/home/xana/Dev/gitfoss/app/islands/RepositoriesList.tsx"
]
code_indexer.get_files_symbols