Skip to content

Commit 250ddea

Browse files
authored
Merge pull request #64 from FalkorDB/support-graph-update
Add Java support
2 parents fff8cc3 + 2771ad2 commit 250ddea

27 files changed

+2640
-3419
lines changed

api/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from .info import *
22
from .llm import ask
33
from .graph import *
4+
from .project import *
45
from .entities import *
6+
from .git_utils import *
57
from .code_coverage import *
8+
from .index import create_app
69
from .analyzers.source_analyzer import *
710
from .auto_complete import prefix_search

api/analyzers/analyzer.py

Lines changed: 82 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,102 @@
1-
import io
21
from pathlib import Path
2+
from typing import Optional
3+
4+
from tree_sitter import Language, Node, Parser, Point
5+
from api.entities.entity import Entity
6+
from api.entities.file import File
37
from abc import ABC, abstractmethod
8+
from multilspy import SyncLanguageServer
49

510
class AbstractAnalyzer(ABC):
11+
def __init__(self, language: Language) -> None:
12+
self.language = language
13+
self.parser = Parser(language)
14+
15+
def find_parent(self, node: Node, parent_types: list) -> Node:
16+
while node and node.type not in parent_types:
17+
node = node.parent
18+
return node
19+
20+
def resolve(self, files: dict[Path, File], lsp: SyncLanguageServer, path: Path, node: Node) -> list[tuple[File, Node]]:
21+
try:
22+
return [(files[Path(location['absolutePath'])], files[Path(location['absolutePath'])].tree.root_node.descendant_for_point_range(Point(location['range']['start']['line'], location['range']['start']['character']), Point(location['range']['end']['line'], location['range']['end']['character']))) for location in lsp.request_definition(str(path), node.start_point.row, node.start_point.column) if location and Path(location['absolutePath']) in files]
23+
except Exception as e:
24+
return []
25+
26+
@abstractmethod
27+
def get_entity_label(self, node: Node) -> str:
28+
"""
29+
Get the entity label from the node.
30+
31+
Args:
32+
node (Node): The node.
33+
34+
Returns:
35+
str: The entity label.
36+
"""
37+
pass
38+
39+
@abstractmethod
40+
def get_entity_name(self, node: Node) -> str:
41+
"""
42+
Get the entity name from the node.
43+
44+
Args:
45+
node (Node): The node.
46+
47+
Returns:
48+
str: The entity name.
49+
"""
50+
pass
51+
52+
@abstractmethod
53+
def get_entity_docstring(self, node: Node) -> Optional[str]:
54+
"""
55+
Get the entity docstring from the node.
56+
57+
Args:
58+
node (Node): The node.
59+
60+
Returns:
61+
Optional[str]: The entity docstring.
62+
"""
63+
pass
64+
665
@abstractmethod
7-
def first_pass(self, path: Path, f: io.TextIOWrapper) -> None:
66+
def get_entity_types(self) -> list[str]:
867
"""
9-
Perform the first pass of analysis on the given file.
68+
Get the top level entity types for the language.
69+
70+
Returns:
71+
list[str]: The list of top level entity types.
72+
"""
73+
74+
pass
75+
76+
@abstractmethod
77+
def add_symbols(self, entity: Entity) -> None:
78+
"""
79+
Add symbols to the entity.
1080
1181
Args:
12-
path (Path): The path to the file being processed.
13-
f (io.TextIOWrapper): The file object.
82+
entity (Entity): The entity to add symbols to.
1483
"""
1584

1685
pass
1786

1887
@abstractmethod
19-
def second_pass(self, path: Path, f: io.TextIOWrapper) -> None:
88+
def resolve_symbol(self, files: dict[Path, File], lsp: SyncLanguageServer, path: Path, key: str, symbol: Node) -> Entity:
2089
"""
21-
Perform a second pass analysis on the given source file.
90+
Resolve a symbol to an entity.
2291
2392
Args:
93+
lsp (SyncLanguageServer): The language server.
2494
path (Path): The path to the file.
25-
f (io.TextIOWrapper): The file handle of the file to be processed.
95+
key (str): The symbol key.
96+
symbol (Node): The symbol node.
97+
98+
Returns:
99+
Entity: The entity.
26100
"""
27101

28102
pass

0 commit comments

Comments
 (0)