require "tree-sitter"
require "./extract_symbols.cr"
type CodeSymbol = Hash(String, String | Array(Hash(String, String)))
module GitFOSS::Code::Indexer
VERSION = "0.1.0"
@@parser = TreeSitter::Parser.new
@@files = [] of String
@@symbols = {} of String => CodeSymbol
def initialize
@@files = [
"~/tmp/file.js",
"~/tmp/file.cr",
"~/tmp/file.cpp",
"~/tmp/file.c",
]
@@files.each do |p|
@@symbols[p] = get_symbols(p)
end
pp @@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.name,
content: file.gets_to_end,
)
tree = @@parser.parse(file.content)
extract_symbols(
@@parser,
tree.root_node,
file,
)
end
symbols
end
end