diff --git a/src/codegen/runner/diff/get_raw_diff.py b/src/codegen/runner/diff/get_raw_diff.py index 1a530fc17..973236836 100644 --- a/src/codegen/runner/diff/get_raw_diff.py +++ b/src/codegen/runner/diff/get_raw_diff.py @@ -27,7 +27,7 @@ def patch_to_limited_diff_string(patch, codebase: Codebase, max_lines=10000): # Add flags that are not in the diff filenames = [patched_file.path for patched_file in patch] - flags_not_in_diff = list(filter(lambda flag: flag.symbol.filepath not in filenames, codebase.G.flags._flags)) + flags_not_in_diff = list(filter(lambda flag: flag.symbol.filepath not in filenames, codebase.ctx.flags._flags)) for flag in flags_not_in_diff: filename = flag.symbol.filepath @@ -39,7 +39,7 @@ def patch_to_limited_diff_string(patch, codebase: Codebase, max_lines=10000): patch.append(patched_file) for patched_file in patch: - filtered_flags = filter(lambda flag: flag.symbol.filepath == patched_file.path, codebase.G.flags._flags) + filtered_flags = filter(lambda flag: flag.symbol.filepath == patched_file.path, codebase.ctx.flags._flags) sorted_flags = list(map(lambda flag: flag.symbol.start_point.row + 1, filtered_flags)) sorted_flags.sort() diff --git a/src/codegen/runner/sandbox/executor.py b/src/codegen/runner/sandbox/executor.py index 596275d86..e555f2b68 100644 --- a/src/codegen/runner/sandbox/executor.py +++ b/src/codegen/runner/sandbox/executor.py @@ -36,8 +36,8 @@ async def find_flags(self, execute_func: Callable) -> list[CodeFlag]: """Runs the execute_func in find_mode to find flags""" self.codebase.set_find_mode(True) await self._execute_with_try_catch(execute_func, commit=False) - code_flags = self.codebase.G.flags._flags - logger.info(f"> Found {len(self.codebase.G.flags._flags)} CodeFlags") + code_flags = self.codebase.ctx.flags._flags + logger.info(f"> Found {len(self.codebase.ctx.flags._flags)} CodeFlags") return code_flags async def find_flag_groups(self, code_flags: list[CodeFlag], grouping_config: GroupingConfig) -> list[Group]: @@ -77,7 +77,7 @@ async def execute_flag_groups(self, commit_msg: str, execute_func: Callable, fla run_results.append(run_result) head_branches.append(created_branch) - self.codebase.G.flags._flags.clear() + self.codebase.ctx.flags._flags.clear() return run_results, head_branches async def execute(self, execute_func: Callable, group: Group | None = None, session_options: SessionOptions = SessionOptions()) -> CodemodRunResult: @@ -155,7 +155,7 @@ async def _get_structured_run_output(self, result: CodemodRunResult) -> CodemodR "messageType": str(flag.message_type), "messageRecipient": flag.message_recipient, } - for flag in self.codebase.G.flags._flags + for flag in self.codebase.ctx.flags._flags ] result.flags = flags if result.observation_meta is None: diff --git a/src/codegen/runner/sandbox/middlewares.py b/src/codegen/runner/sandbox/middlewares.py index 96e0d6b85..52e797baf 100644 --- a/src/codegen/runner/sandbox/middlewares.py +++ b/src/codegen/runner/sandbox/middlewares.py @@ -69,6 +69,6 @@ async def cleanup_after_codemod(self, is_exception: bool = False): if is_exception: # TODO: instead of committing transactions, we should just rollback logger.info("Committing pending transactions due to exception") - self.runner.codebase.G.commit_transactions(sync_graph=False) + self.runner.codebase.ctx.commit_transactions(sync_graph=False) self.runner.reset_runner() self.server_info.is_running_codemod = False diff --git a/src/codegen/runner/sandbox/runner.py b/src/codegen/runner/sandbox/runner.py index 5440df1cf..bcdefd9c5 100644 --- a/src/codegen/runner/sandbox/runner.py +++ b/src/codegen/runner/sandbox/runner.py @@ -112,5 +112,5 @@ async def create_branch(self, request: CreateBranchRequest) -> CreateBranchRespo response.results = run_results response.branches = branches - self.codebase.G.flags._flags.clear() + self.codebase.ctx.flags._flags.clear() return response diff --git a/src/codegen/sdk/code_generation/doc_utils/generate_docs_json.py b/src/codegen/sdk/code_generation/doc_utils/generate_docs_json.py index 8fdda80b8..3cd8f623c 100644 --- a/src/codegen/sdk/code_generation/doc_utils/generate_docs_json.py +++ b/src/codegen/sdk/code_generation/doc_utils/generate_docs_json.py @@ -8,7 +8,7 @@ from codegen.sdk.core.placeholder.placeholder_type import TypePlaceholder ATTRIBUTES_TO_IGNORE = [ - "G", + "ctx", "node_id", "angular", "model_config", @@ -19,7 +19,6 @@ "node_type", "ts_node", "file_node_id", - "G", "statement_type", "assignment_types", ] diff --git a/src/codegen/sdk/codebase/codebase_analysis.py b/src/codegen/sdk/codebase/codebase_analysis.py index f9dffe314..8a33707db 100644 --- a/src/codegen/sdk/codebase/codebase_analysis.py +++ b/src/codegen/sdk/codebase/codebase_analysis.py @@ -9,7 +9,7 @@ def get_codebase_summary(codebase: Codebase) -> str: - node_summary = f"""Contains {len(codebase.G.get_nodes())} nodes + node_summary = f"""Contains {len(codebase.ctx.get_nodes())} nodes - {len(list(codebase.files))} files - {len(list(codebase.imports))} imports - {len(list(codebase.external_modules))} external_modules @@ -19,10 +19,10 @@ def get_codebase_summary(codebase: Codebase) -> str: \t- {len(list(codebase.global_vars))} global_vars \t- {len(list(codebase.interfaces))} interfaces """ - edge_summary = f"""Contains {len(codebase.G.edges)} edges -- {len([x for x in codebase.G.edges if x[2].type == EdgeType.SYMBOL_USAGE])} symbol -> used symbol -- {len([x for x in codebase.G.edges if x[2].type == EdgeType.IMPORT_SYMBOL_RESOLUTION])} import -> used symbol -- {len([x for x in codebase.G.edges if x[2].type == EdgeType.EXPORT])} export -> exported symbol + edge_summary = f"""Contains {len(codebase.ctx.edges)} edges +- {len([x for x in codebase.ctx.edges if x[2].type == EdgeType.SYMBOL_USAGE])} symbol -> used symbol +- {len([x for x in codebase.ctx.edges if x[2].type == EdgeType.IMPORT_SYMBOL_RESOLUTION])} import -> used symbol +- {len([x for x in codebase.ctx.edges if x[2].type == EdgeType.EXPORT])} export -> exported symbol """ return f"{node_summary}\n{edge_summary}" diff --git a/src/codegen/sdk/codebase/codebase_graph.py b/src/codegen/sdk/codebase/codebase_context.py similarity index 99% rename from src/codegen/sdk/codebase/codebase_graph.py rename to src/codegen/sdk/codebase/codebase_context.py index 711e819f9..abe519558 100644 --- a/src/codegen/sdk/codebase/codebase_graph.py +++ b/src/codegen/sdk/codebase/codebase_context.py @@ -76,7 +76,7 @@ def get_node_classes(programming_language: ProgrammingLanguage) -> NodeClasses: raise ValueError(msg) -class CodebaseGraph: +class CodebaseContext: """MultiDiGraph Wrapper with TransactionManager""" # =====[ __init__ attributes ]===== diff --git a/src/codegen/sdk/codebase/config_parser.py b/src/codegen/sdk/codebase/config_parser.py index 4f8ac6cc7..8ab48bd7b 100644 --- a/src/codegen/sdk/codebase/config_parser.py +++ b/src/codegen/sdk/codebase/config_parser.py @@ -4,7 +4,7 @@ from codegen.sdk.enums import ProgrammingLanguage if TYPE_CHECKING: - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext class ConfigParser(ABC): @@ -12,13 +12,13 @@ def __init__(self): pass @abstractmethod - def parse_configs(self, codebase_graph: "CodebaseGraph"): ... + def parse_configs(self, codebase_context: "CodebaseContext"): ... -def get_config_parser_for_language(language: ProgrammingLanguage, codebase_graph: "CodebaseGraph") -> ConfigParser | None: +def get_config_parser_for_language(language: ProgrammingLanguage, codebase_context: "CodebaseContext") -> ConfigParser | None: from codegen.sdk.typescript.config_parser import TSConfigParser if language == ProgrammingLanguage.TYPESCRIPT: - return TSConfigParser(codebase_graph) + return TSConfigParser(codebase_context) return None diff --git a/src/codegen/sdk/codebase/factory/get_session.py b/src/codegen/sdk/codebase/factory/get_session.py index 2feccb386..b8bf00152 100644 --- a/src/codegen/sdk/codebase/factory/get_session.py +++ b/src/codegen/sdk/codebase/factory/get_session.py @@ -6,7 +6,7 @@ from codegen.git.repo_operator.local_repo_operator import LocalRepoOperator from codegen.git.schemas.repo_config import BaseRepoConfig -from codegen.sdk.codebase.codebase_graph import CodebaseGraph +from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.codebase.config import CodebaseConfig, GSFeatureFlags, ProjectConfig, SessionOptions, TestFlags from codegen.sdk.codebase.factory.codebase_factory import CodebaseFactory from codegen.sdk.core.codebase import Codebase, PyCodebaseType, TSCodebaseType @@ -108,12 +108,12 @@ def get_codebase_graph_session( files: dict[str, str] = {}, sync_graph: bool = True, session_options: SessionOptions = SessionOptions(), -) -> Generator[CodebaseGraph, None, None]: +) -> Generator[CodebaseContext, None, None]: """Gives you a Codebase2 operating on the files you provided as a dict""" op = LocalRepoOperator.create_from_files(repo_path=tmpdir, files=files) config = CodebaseConfig(feature_flags=TestFlags) projects = [ProjectConfig(repo_operator=op, programming_language=programming_language)] - graph = CodebaseGraph(projects=projects, config=config) + graph = CodebaseContext(projects=projects, config=config) with graph.session(sync_graph=sync_graph, session_options=session_options): try: yield graph diff --git a/src/codegen/sdk/codebase/node_classes/py_node_classes.py b/src/codegen/sdk/codebase/node_classes/py_node_classes.py index 533553e4e..50cb13df4 100644 --- a/src/codegen/sdk/codebase/node_classes/py_node_classes.py +++ b/src/codegen/sdk/codebase/node_classes/py_node_classes.py @@ -31,10 +31,10 @@ from codegen.sdk.python.statements.import_statement import PyImportStatement -def parse_subscript(node: TSNode, file_node_id, G, parent): +def parse_subscript(node: TSNode, file_node_id, ctx, parent): if (node.prev_named_sibling and node.prev_named_sibling.text.decode("utf-8") == "TypeAlias") or isinstance(parent, Type): - return PyGenericType(node, file_node_id, G, parent) - return SubscriptExpression(node, file_node_id, G, parent) + return PyGenericType(node, file_node_id, ctx, parent) + return SubscriptExpression(node, file_node_id, ctx, parent) PyExpressionMap = { diff --git a/src/codegen/sdk/codebase/range_index.py b/src/codegen/sdk/codebase/range_index.py index ea8cdd4b9..e92a229d0 100644 --- a/src/codegen/sdk/codebase/range_index.py +++ b/src/codegen/sdk/codebase/range_index.py @@ -43,7 +43,7 @@ def nodes(self) -> list[Editable]: def children(self) -> dict[Editable, list[Editable]]: ret = defaultdict(list) for node in self.nodes: - # if node.G.config.feature_flags.debug: + # if node.ctx.config.feature_flags.debug: # assert node.parent != node, node.__class__ if node.parent != node: ret[node.parent].append(node) diff --git a/src/codegen/sdk/codebase/transactions.py b/src/codegen/sdk/codebase/transactions.py index 1abdf912c..d2e71f8fa 100644 --- a/src/codegen/sdk/codebase/transactions.py +++ b/src/codegen/sdk/codebase/transactions.py @@ -262,7 +262,7 @@ def __init__( priority: int = 0, ) -> None: super().__init__(0, 0, file.path, priority=priority, new_content=new_file_path) - self.new_file_path = file.G.to_absolute(new_file_path) + self.new_file_path = file.ctx.to_absolute(new_file_path) self.file = file def execute(self) -> None: diff --git a/src/codegen/sdk/codebase/validation.py b/src/codegen/sdk/codebase/validation.py index d8d11c288..5d3a5aff7 100644 --- a/src/codegen/sdk/codebase/validation.py +++ b/src/codegen/sdk/codebase/validation.py @@ -30,14 +30,14 @@ class PostInitValidationStatus(StrEnum): def post_init_validation(codebase: CodebaseType) -> PostInitValidationStatus: """Post codebase._init_graph verifies that the built graph is valid.""" - from codegen.sdk.codebase.codebase_graph import GLOBAL_FILE_IGNORE_LIST + from codegen.sdk.codebase.codebase_context import GLOBAL_FILE_IGNORE_LIST # Verify the graph has nodes - if len(codebase.G.nodes) == 0: + if len(codebase.ctx.nodes) == 0: return PostInitValidationStatus.NO_NODES # Verify the graph has the same number of files as there are in the repo - if len(codebase.files) != len(list(codebase.op.iter_files(codebase.G.projects[0].subdirectories, extensions=codebase.G.extensions, ignore_list=GLOBAL_FILE_IGNORE_LIST))): + if len(codebase.files) != len(list(codebase.op.iter_files(codebase.ctx.projects[0].subdirectories, extensions=codebase.ctx.extensions, ignore_list=GLOBAL_FILE_IGNORE_LIST))): return PostInitValidationStatus.MISSING_FILES # Verify import resolution @@ -64,14 +64,14 @@ def post_reset_validation(init_nodes, nodes, init_edges, edges, repo_name: str, def post_sync_validation(codebase: CodebaseType) -> bool: """Post codebase.sync, checks that the codebase graph is in a valid state (i.e. not corrupted by codebase.sync)""" - if len(codebase.G.all_syncs) > 0 or len(codebase.G.pending_syncs) > 0 or len(codebase.G.transaction_manager.to_commit()) > 0: + if len(codebase.ctx.all_syncs) > 0 or len(codebase.ctx.pending_syncs) > 0 or len(codebase.ctx.transaction_manager.to_commit()) > 0: msg = "Can only be called on a reset codebase" raise NotImplementedError(msg) - if not codebase.G.config.feature_flags.track_graph: + if not codebase.ctx.config.feature_flags.track_graph: msg = "Can only be called with track_graph=true" raise NotImplementedError(msg) - return len(dict.fromkeys(codebase.G.old_graph.nodes())) == len(dict.fromkeys(codebase.G.nodes)) and len(dict.fromkeys(codebase.G.old_graph.weighted_edge_list())) == len( - dict.fromkeys(codebase.G.edges) + return len(dict.fromkeys(codebase.ctx.old_graph.nodes())) == len(dict.fromkeys(codebase.ctx.nodes)) and len(dict.fromkeys(codebase.ctx.old_graph.weighted_edge_list())) == len( + dict.fromkeys(codebase.ctx.edges) ) @@ -140,7 +140,7 @@ def get_nodes_error(init_nodes, nodes): from codegen.sdk.core.external_module import ExternalModule if isinstance(node, ExternalModule): - message += "External Module persisted with following dependencies: " + str(list((node.G.get_node(source), edge) for source, _, edge in node.G.in_edges(node.node_id))) + message += "External Module persisted with following dependencies: " + str(list((node.ctx.get_node(source), edge) for source, _, edge in node.ctx.in_edges(node.node_id))) return message diff --git a/src/codegen/sdk/core/assignment.py b/src/codegen/sdk/core/assignment.py index cb0339307..116fca79d 100644 --- a/src/codegen/sdk/core/assignment.py +++ b/src/codegen/sdk/core/assignment.py @@ -27,7 +27,7 @@ from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.codebase.resolution_stack import ResolutionStack from codegen.sdk.core.expressions.type import Type from codegen.sdk.core.interfaces.editable import Editable @@ -58,9 +58,9 @@ class Assignment(Symbol[Parent, ...], Typeable[Parent, ...], HasValue, Generic[P _left: Expression[Self] symbol_type = SymbolType.GlobalVar - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: Parent, left: TSNode, value: TSNode, name_node: TSNode, type: Type | None = None) -> None: + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: Parent, left: TSNode, value: TSNode, name_node: TSNode, type: Type | None = None) -> None: self._unique_node = name_node # HACK: This prevents deduplication of Assignments - super().__init__(ts_node, file_node_id, G, parent=parent, name_node=name_node, name_node_type=Name) + super().__init__(ts_node, file_node_id, ctx, parent=parent, name_node=name_node, name_node_type=Name) self._left = self._parse_expression(left, default=Name) self._value_node = self._parse_expression(value) self.type = type @@ -68,27 +68,27 @@ def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, pare self._init_type() @classmethod - def _from_left_and_right_nodes(cls, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: Parent, left_node: TSNode, right_node: TSNode) -> list[Assignment]: - left = G.parser.parse_expression(left_node, file_node_id, G, parent) - value = G.parser.parse_expression(right_node, file_node_id, G, parent) + def _from_left_and_right_nodes(cls, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: Parent, left_node: TSNode, right_node: TSNode) -> list[Assignment]: + left = ctx.parser.parse_expression(left_node, file_node_id, ctx, parent) + value = ctx.parser.parse_expression(right_node, file_node_id, ctx, parent) if isinstance(left, Collection | Dict): assignments = [] for var in left.symbols: # Make a deep copy of the value expression for each child - value = G.parser.parse_expression(right_node, file_node_id, G, parent) - assignments.extend(cls._from_value_expression(ts_node, file_node_id, G, parent, left, value, var.ts_node)) + value = ctx.parser.parse_expression(right_node, file_node_id, ctx, parent) + assignments.extend(cls._from_value_expression(ts_node, file_node_id, ctx, parent, left, value, var.ts_node)) return sort_editables(assignments) - return cls._from_value_expression(ts_node, file_node_id, G, parent, left, value, left_node) + return cls._from_value_expression(ts_node, file_node_id, ctx, parent, left, value, left_node) @classmethod def _from_value_expression( - cls, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: Parent, left: Expression[Self], value: Expression[Self] | list[Expression], name_node: TSNode + cls, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: Parent, left: Expression[Self], value: Expression[Self] | list[Expression], name_node: TSNode ) -> list[Assignment]: - assignments = [cls(ts_node, file_node_id, G, parent, left, value, name_node)] + assignments = [cls(ts_node, file_node_id, ctx, parent, left, value, name_node)] if value and isinstance(value, MultiExpression) and isinstance(value.expressions[0], Assignment): for expr in value.expressions: - assignments.extend(cls._from_value_expression(expr.ts_node, file_node_id, G, parent, expr.left, expr.value, expr.get_name().ts_node)) + assignments.extend(cls._from_value_expression(expr.ts_node, file_node_id, ctx, parent, expr.left, expr.value, expr.get_name().ts_node)) return sort_editables(assignments) @noapidoc diff --git a/src/codegen/sdk/core/autocommit/decorators.py b/src/codegen/sdk/core/autocommit/decorators.py index e12a1f30c..9e45c6df8 100644 --- a/src/codegen/sdk/core/autocommit/decorators.py +++ b/src/codegen/sdk/core/autocommit/decorators.py @@ -47,7 +47,7 @@ def wrapper(wrapped: Callable[P, T], instance: "Editable", args, kwargs) -> T: instance = args[0] if instance.removed: logger.warning("Editing a removed node") - autocommit = instance.G._autocommit + autocommit = instance.ctx._autocommit logger.debug("Writing node %r,%r", instance, wrapped) with autocommit.write_state(instance, commit=commit): return wrapped(*args, **kwargs) @@ -69,9 +69,9 @@ def remover( if instance is None: instance = args[0] logger.debug("Removing node %r, %r", instance, wrapped) - with instance.G._autocommit.write_state(instance): + with instance.ctx._autocommit.write_state(instance): ret = wrapped(*args, **kwargs) - # instance.G._autocommit.set_pending(instance, REMOVED) + # instance.ctx._autocommit.set_pending(instance, REMOVED) instance.removed = True return ret @@ -86,7 +86,7 @@ def repr_func( """Indicates the method is use in debugging/logs.""" if instance is None: instance = args[0] - autocommit = instance.G._autocommit + autocommit = instance.ctx._autocommit old_state = autocommit.enter_state(AutoCommitState.Special) try: ret = wrapped(*args, **kwargs) @@ -108,8 +108,8 @@ def mover( """ if instance is None: instance = args[0] - with instance.G._autocommit.write_state(instance, move=True): + with instance.ctx._autocommit.write_state(instance, move=True): file_node_id, node_id = wrapped(*args, **kwargs) - instance.G._autocommit.set_pending(instance, node_id, file_node_id) + instance.ctx._autocommit.set_pending(instance, node_id, file_node_id) instance.removed = False return None diff --git a/src/codegen/sdk/core/autocommit/manager.py b/src/codegen/sdk/core/autocommit/manager.py index 5e7370db8..de8c8e100 100644 --- a/src/codegen/sdk/core/autocommit/manager.py +++ b/src/codegen/sdk/core/autocommit/manager.py @@ -17,7 +17,7 @@ from codegen.sdk.extensions.autocommit import update_dict if TYPE_CHECKING: - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.file import File from codegen.sdk.core.import_resolution import Import from codegen.sdk.core.symbol import Symbol @@ -73,12 +73,12 @@ class AutoCommit: state: AutoCommitState | None = None _files: dict[Path, NodeId | None] _nodes: dict[NodeId, AutoCommitNode] - G: "CodebaseGraph" + ctx: "CodebaseContext" _locked_files: set[str] _lock_all: bool = False - def __init__(self, G: "CodebaseGraph") -> None: - self.G = G + def __init__(self, ctx: "CodebaseContext") -> None: + self.ctx = ctx self._files = {} self._nodes = {} self._locked_files = set() @@ -94,7 +94,7 @@ def _commit(self, lock: PendingFiles, additional: str | None = None) -> None: files = lock.files if not lock.all else None if additional and files: files.add(additional) - self.G.commit_transactions(files=files) + self.ctx.commit_transactions(files=files) def _update_file(self, symbol: "File", lock: PendingFiles) -> None: """Check for an update to a file, and if there is one, copy its dict.""" @@ -104,8 +104,8 @@ def _update_file(self, symbol: "File", lock: PendingFiles) -> None: logger.warning("Editing a removed node") return self._commit(lock, new_id) - old_node = self.G.get_node(symbol.file_node_id) - new_node = self.G.get_node( + old_node = self.ctx.get_node(symbol.file_node_id) + new_node = self.ctx.get_node( new_id if new_id is not None else symbol.file_node_id ) old_node.__dict__ = new_node.__dict__ @@ -120,7 +120,7 @@ def _reaquire_node( ): """Re-aquire a symbol.""" # Prevent double re-aquire - new_node = self.G.get_node(new_node_id) + new_node = self.ctx.get_node(new_node_id) if new_node is None: if missing_ok: return @@ -209,7 +209,7 @@ def set_pending( if new_file is not None: self.set_pending_file(node, update_id=new_file) if is_symbol(node): - new_file_node = self.G.get_node(new_file) if new_file else None + new_file_node = self.ctx.get_node(new_file) if new_file else None if symbol_update := self._nodes.get(node.node_id, None): assert symbol_update.symbol == node if new_id is not None: diff --git a/src/codegen/sdk/core/class_definition.py b/src/codegen/sdk/core/class_definition.py index 785f0e20e..623986bb6 100644 --- a/src/codegen/sdk/core/class_definition.py +++ b/src/codegen/sdk/core/class_definition.py @@ -21,7 +21,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.detached_symbols.code_block import CodeBlock from codegen.sdk.core.detached_symbols.decorator import Decorator from codegen.sdk.core.detached_symbols.parameter import Parameter @@ -64,8 +64,8 @@ class Class(Inherits[TType], HasBlock[TCodeBlock, TDecorator], Callable[TParamet parent_classes: Parents[TType, Self] | None = None _methods: MultiLineCollection[TFunction, Self] | None = None - def __init__(self, ts_node: TSNode, file_id: NodeId, G: CodebaseGraph, parent: SymbolStatement) -> None: - super().__init__(ts_node, file_id, G, parent) + def __init__(self, ts_node: TSNode, file_id: NodeId, ctx: CodebaseContext, parent: SymbolStatement) -> None: + super().__init__(ts_node, file_id, ctx, parent) self._methods = self._parse_methods() self._parameters = [] diff --git a/src/codegen/sdk/core/codebase.py b/src/codegen/sdk/core/codebase.py index 59bbd180f..0324c05ed 100644 --- a/src/codegen/sdk/core/codebase.py +++ b/src/codegen/sdk/core/codebase.py @@ -27,7 +27,7 @@ from codegen.sdk._proxy import proxy_property from codegen.sdk.ai.helpers import AbstractAIHelper, MultiProviderAIHelper from codegen.sdk.codebase.codebase_ai import generate_system_prompt, generate_tools -from codegen.sdk.codebase.codebase_graph import GLOBAL_FILE_IGNORE_LIST, CodebaseGraph +from codegen.sdk.codebase.codebase_context import GLOBAL_FILE_IGNORE_LIST, CodebaseContext from codegen.sdk.codebase.config import CodebaseConfig, DefaultConfig, ProjectConfig, SessionOptions from codegen.sdk.codebase.diff_lite import DiffLite from codegen.sdk.codebase.flagging.code_flag import CodeFlag @@ -174,7 +174,7 @@ def __init__( self._op = main_project.repo_operator self.viz = VisualizationManager(op=self._op) self.repo_path = Path(self._op.repo_path) - self.G = CodebaseGraph(projects, config=config) + self.ctx = CodebaseContext(projects, config=config) self.console = Console(record=True, soft_wrap=True) @noapidoc @@ -186,9 +186,9 @@ def __repr__(self): return str(self) def __rich_repr__(self) -> rich.repr.Result: - yield "repo", self.G.repo_name - yield "nodes", len(self.G.nodes) - yield "edges", len(self.G.edges) + yield "repo", self.ctx.repo_name + yield "nodes", len(self.ctx.nodes) + yield "edges", len(self.ctx.edges) __rich_repr__.angular = ANGULAR_STYLE @@ -205,12 +205,12 @@ def op(self) -> RepoOperator: @property def name(self) -> str: """The name of the repository.""" - return self.G.repo_name + return self.ctx.repo_name @property def language(self) -> ProgrammingLanguage: """The programming language of the repository.""" - return self.G.programming_language + return self.ctx.programming_language #################################################################################################################### # NODES @@ -218,7 +218,7 @@ def language(self) -> ProgrammingLanguage: @noapidoc def _symbols(self, symbol_type: SymbolType | None = None) -> list[TSymbol | TClass | TFunction | TGlobalVar]: - matches: list[Symbol] = self.G.get_nodes(NodeType.SYMBOL) + matches: list[Symbol] = self.ctx.get_nodes(NodeType.SYMBOL) return [x for x in matches if x.is_top_level and (symbol_type is None or x.symbol_type == symbol_type)] # =====[ Node Types ]===== @@ -245,7 +245,7 @@ def files(self, *, extensions: list[str] | Literal["*"] | None = None) -> list[T """ if extensions is None: # Return all source files - files = self.G.get_nodes(NodeType.FILE) + files = self.ctx.get_nodes(NodeType.FILE) elif isinstance(extensions, str) and extensions != "*": msg = "extensions must be a list of extensions or '*'" raise ValueError(msg) @@ -267,7 +267,7 @@ def directories(self) -> list[TDirectory]: Returns: list[TDirectory]: A list of Directory objects in the codebase. """ - return list(self.G.directories.values()) + return list(self.ctx.directories.values()) @property def imports(self) -> list[TImport]: @@ -283,7 +283,7 @@ def imports(self) -> list[TImport]: list[TImport]: A list of Import nodes representing all imports in the codebase. TImport can be PyImport for Python codebases or TSImport for TypeScript codebases. """ - return self.G.get_nodes(NodeType.IMPORT) + return self.ctx.get_nodes(NodeType.IMPORT) @property @py_noapidoc @@ -305,7 +305,7 @@ def exports(self: "TSCodebaseType") -> list[TSExport]: msg = "Exports are not supported for Python codebases since Python does not have an export mechanism." raise NotImplementedError(msg) - return self.G.get_nodes(NodeType.EXPORT) + return self.ctx.get_nodes(NodeType.EXPORT) @property def external_modules(self) -> list[ExternalModule]: @@ -316,7 +316,7 @@ def external_modules(self) -> list[ExternalModule]: Returns: list[ExternalModule]: List of external module nodes from the codebase graph. """ - return self.G.get_nodes(NodeType.EXTERNAL) + return self.ctx.get_nodes(NodeType.EXTERNAL) @property def symbols(self) -> list[TSymbol]: @@ -417,17 +417,17 @@ def create_file(self, filepath: str, content: str = "", sync: bool = True) -> TS # if os.path.exists(filepath): # raise ValueError(f"File {filepath} already exists on disk.") - file_exts = self.G.extensions + file_exts = self.ctx.extensions # Create file as source file if it has a registered extension if any(filepath.endswith(ext) for ext in file_exts): - file_cls = self.G.node_classes.file_cls - file = file_cls.from_content(filepath, content, self.G, sync=sync) + file_cls = self.ctx.node_classes.file_cls + file = file_cls.from_content(filepath, content, self.ctx, sync=sync) if file is None: msg = f"Failed to parse file with content {content}. Please make sure the content syntax is valid with respect to the filepath extension." raise ValueError(msg) else: # Create file as non-source file - file = File.from_content(filepath, content, self.G, sync=False) + file = File.from_content(filepath, content, self.ctx, sync=False) # This is to make sure we keep track of this file for diff purposes uncache_all() @@ -444,7 +444,7 @@ def create_directory(self, dir_path: str, exist_ok: bool = False, parents: bool Raises: FileExistsError: If the directory already exists and exist_ok is False. """ - self.G.to_absolute(dir_path).mkdir(parents=parents, exist_ok=exist_ok) + self.ctx.to_absolute(dir_path).mkdir(parents=parents, exist_ok=exist_ok) def has_file(self, filepath: str, ignore_case: bool = False) -> bool: """Determines if a file exists in the codebase. @@ -481,26 +481,26 @@ def get_file(self, filepath: str, *, optional: bool = False, ignore_case: bool = def get_file_from_path(path: Path) -> File | None: try: - return File.from_content(path, path.read_text(), self.G, sync=False) + return File.from_content(path, path.read_text(), self.ctx, sync=False) except UnicodeDecodeError: # Handle when file is a binary file - return File.from_content(path, path.read_bytes(), self.G, sync=False, binary=True) + return File.from_content(path, path.read_bytes(), self.ctx, sync=False, binary=True) # Try to get the file from the graph first - file = self.G.get_file(filepath, ignore_case=ignore_case) + file = self.ctx.get_file(filepath, ignore_case=ignore_case) if file is not None: return file - absolute_path = self.G.to_absolute(filepath) + absolute_path = self.ctx.to_absolute(filepath) if absolute_path.exists(): return get_file_from_path(absolute_path) elif ignore_case: parent = absolute_path.parent - if parent == Path(self.G.repo_path): - for file in self.G.to_absolute(self.G.repo_path).iterdir(): + if parent == Path(self.ctx.repo_path): + for file in self.ctx.to_absolute(self.ctx.repo_path).iterdir(): if str(absolute_path).lower() == str(file).lower(): return get_file_from_path(file) else: - dir = self.G.get_directory(parent, ignore_case=ignore_case) + dir = self.ctx.get_directory(parent, ignore_case=ignore_case) if dir is None: return None for file in dir.path.iterdir(): @@ -540,7 +540,7 @@ def get_directory(self, dir_path: str, optional: bool = False, ignore_case: bool # Sanitize the path dir_path = os.path.normpath(dir_path) dir_path = "" if dir_path == "." else dir_path - directory = self.G.get_directory(self.G.to_absolute(dir_path), ignore_case=ignore_case) + directory = self.ctx.get_directory(self.ctx.to_absolute(dir_path), ignore_case=ignore_case) if directory is None and not optional: msg = f"Directory {dir_path} not found in codebase. Use optional=True to return None instead." raise ValueError(msg) @@ -710,7 +710,7 @@ def git_commit(self, message: str, *, verify: bool = False) -> GitCommit | None: Returns: GitCommit | None: The commit object if changes were committed, None otherwise. """ - self.G.commit_transactions(sync_graph=False) + self.ctx.commit_transactions(sync_graph=False) if self._op.stage_and_commit_all_changes(message, verify): logger.info(f"Commited repository to {self._op.head_commit} on {self._op.get_active_branch_or_commit()}") return self._op.head_commit @@ -728,7 +728,7 @@ def commit(self, sync_graph: bool = True) -> None: Returns: None """ - self.G.commit_transactions(sync_graph=sync_graph and self.G.config.feature_flags.sync_enabled) + self.ctx.commit_transactions(sync_graph=sync_graph and self.ctx.config.feature_flags.sync_enabled) @noapidoc def git_push(self, *args, **kwargs) -> PushInfoList: @@ -776,7 +776,7 @@ def reset(self, git_reset: bool = False) -> None: self._op.discard_changes() # Discard any changes made to the raw file state self._num_ai_requests = 0 self.reset_logs() - self.G.undo_applied_diffs() + self.ctx.undo_applied_diffs() def checkout(self, *, commit: str | GitCommit | None = None, branch: str | None = None, create_if_missing: bool = False, remote: bool = False) -> CheckoutResult: """Checks out a git branch or commit and syncs the codebase graph to the new state. @@ -816,11 +816,11 @@ def checkout(self, *, commit: str | GitCommit | None = None, branch: str | None @noapidoc def sync_to_commit(self, target_commit: GitCommit) -> None: """Updates the current base to a new commit.""" - origin_commit = self.G.synced_commit + origin_commit = self.ctx.synced_commit if origin_commit.hexsha == target_commit.hexsha: logger.info(f"Codebase is already synced to {target_commit.hexsha}. Skipping sync_to_commit.") return - if not self.G.config.feature_flags.sync_enabled: + if not self.ctx.config.feature_flags.sync_enabled: logger.info(f"Syncing codebase is disabled for repo {self._op.repo_name}. Skipping sync_to_commit.") return @@ -829,8 +829,8 @@ def sync_to_commit(self, target_commit: GitCommit) -> None: diff_lites = [] for diff in diff_index: diff_lites.append(DiffLite.from_git_diff(diff)) - self.G.apply_diffs(diff_lites) - self.G.save_commit(target_commit) + self.ctx.apply_diffs(diff_lites) + self.ctx.save_commit(target_commit) @noapidoc def get_diffs(self, base: str | None = None) -> list[Diff]: @@ -902,7 +902,7 @@ def flags(self) -> list[CodeFlag]: Returns: list[CodeFlag]: A list of all flags in the codebase. """ - return self.G.flags._flags + return self.ctx.flags._flags @noapidoc def flag_instance( @@ -922,7 +922,7 @@ def flag_instance( Returns: CodeFlag: A flag object representing the flagged entity. """ - return self.G.flags.flag_instance(symbol, **kwargs) + return self.ctx.flags.flag_instance(symbol, **kwargs) def should_fix(self, flag: CodeFlag) -> bool: """Returns True if the flag should be fixed based on the current mode and active group. @@ -938,17 +938,17 @@ def should_fix(self, flag: CodeFlag) -> bool: Returns True if no active group is set. Returns True if the flag's hash exists in the active group hashes. """ - return self.G.flags.should_fix(flag) + return self.ctx.flags.should_fix(flag) @noapidoc def set_find_mode(self, find_mode: bool) -> None: - self.G.flags.set_find_mode(find_mode) + self.ctx.flags.set_find_mode(find_mode) @noapidoc def set_active_group(self, group: Group) -> None: """Will only fix these flags.""" # TODO - flesh this out more with Group datatype and GroupBy - self.G.flags.set_active_group(group) + self.ctx.flags.set_active_group(group) #################################################################################################################### # LOGGING @@ -965,7 +965,7 @@ def log(self, *args) -> None: At the end, we will save a tail of these logs on the CodemodRun """ - self.G.transaction_manager.check_max_preview_time() + self.ctx.transaction_manager.check_max_preview_time() if self.console.export_text(clear=False).count("\n") >= MAX_LINES: return # if max lines has been reached, skip logging for arg in args: @@ -996,31 +996,31 @@ def get_finalized_logs(self) -> str: @contextmanager @noapidoc def session(self, sync_graph: bool = True, commit: bool = True, session_options: SessionOptions = SessionOptions()) -> Generator[None, None, None]: - with self.G.session(sync_graph=sync_graph, commit=commit, session_options=session_options): + with self.ctx.session(sync_graph=sync_graph, commit=commit, session_options=session_options): yield None @noapidoc def _enable_experimental_language_engine(self, async_start: bool = False, install_deps: bool = False, use_v8: bool = False) -> None: """Debug option to enable experimental language engine for the current codebase.""" - if install_deps and not self.G.language_engine: + if install_deps and not self.ctx.language_engine: from codegen.sdk.core.external.dependency_manager import get_dependency_manager logger.info("Cold installing dependencies...") logger.info("This may take a while for large repos...") - self.G.dependency_manager = get_dependency_manager(self.G.projects[0].programming_language, self.G, enabled=True) - self.G.dependency_manager.start(async_start=False) + self.ctx.dependency_manager = get_dependency_manager(self.ctx.projects[0].programming_language, self.ctx, enabled=True) + self.ctx.dependency_manager.start(async_start=False) # Wait for the dependency manager to be ready - self.G.dependency_manager.wait_until_ready(ignore_error=False) + self.ctx.dependency_manager.wait_until_ready(ignore_error=False) logger.info("Dependencies ready") - if not self.G.language_engine: + if not self.ctx.language_engine: from codegen.sdk.core.external.language_engine import get_language_engine logger.info("Cold starting language engine...") logger.info("This may take a while for large repos...") - self.G.language_engine = get_language_engine(self.G.projects[0].programming_language, self.G, use_ts=True, use_v8=use_v8) - self.G.language_engine.start(async_start=async_start) + self.ctx.language_engine = get_language_engine(self.ctx.projects[0].programming_language, self.ctx, use_ts=True, use_v8=use_v8) + self.ctx.language_engine.start(async_start=async_start) # Wait for the language engine to be ready - self.G.language_engine.wait_until_ready(ignore_error=False) + self.ctx.language_engine.wait_until_ready(ignore_error=False) logger.info("Language engine ready") #################################################################################################################### @@ -1036,11 +1036,11 @@ def ai_client(self) -> AbstractAIHelper: """Enables calling AI/LLM APIs - re-export of the initialized `openai` module""" # Create a singleton AIHelper instance if self._ai_helper is None: - if self.G.config.secrets.openai_key is None: + if self.ctx.config.secrets.openai_key is None: msg = "OpenAI key is not set" raise ValueError(msg) - self._ai_helper = MultiProviderAIHelper(openai_key=self.G.config.secrets.openai_key, use_openai=True, use_claude=False) + self._ai_helper = MultiProviderAIHelper(openai_key=self.ctx.config.secrets.openai_key, use_openai=True, use_claude=False) return self._ai_helper def ai(self, prompt: str, target: Editable | None = None, context: Editable | list[Editable] | dict[str, Editable | list[Editable]] | None = None, model: str = "gpt-4o") -> str: @@ -1064,10 +1064,10 @@ def ai(self, prompt: str, target: Editable | None = None, context: Editable | li # Check max transactions logger.info("Creating call to OpenAI...") self._num_ai_requests += 1 - if self.G.session_options.max_ai_requests is not None and self._num_ai_requests > self.G.session_options.max_ai_requests: - logger.info(f"Max AI requests reached: {self.G.session_options.max_ai_requests}. Stopping codemod.") - msg = f"Maximum number of AI requests reached: {self.G.session_options.max_ai_requests}" - raise MaxAIRequestsError(msg, threshold=self.G.session_options.max_ai_requests) + if self.ctx.session_options.max_ai_requests is not None and self._num_ai_requests > self.ctx.session_options.max_ai_requests: + logger.info(f"Max AI requests reached: {self.ctx.session_options.max_ai_requests}. Stopping codemod.") + msg = f"Maximum number of AI requests reached: {self.ctx.session_options.max_ai_requests}" + raise MaxAIRequestsError(msg, threshold=self.ctx.session_options.max_ai_requests) params = { "messages": [{"role": "system", "content": generate_system_prompt(target, context)}, {"role": "user", "content": prompt}], @@ -1123,7 +1123,7 @@ def set_ai_key(self, key: str) -> None: self._ai_helper = None # Set the AI key - self.G.config.secrets.openai_key = key + self.ctx.config.secrets.openai_key = key def find_by_span(self, span: Span) -> list[Editable]: """Finds editable objects that overlap with the given source code span. @@ -1158,9 +1158,9 @@ def set_session_options(self, **kwargs: Unpack[SessionOptions]) -> None: - max_ai_requests (int, optional): The maximum number of AI requests allowed in a session. """ - self.G.session_options = self.G.session_options.model_copy(update=kwargs) - self.G.transaction_manager.set_max_transactions(self.G.session_options.max_transactions) - self.G.transaction_manager.reset_stopwatch(self.G.session_options.max_seconds) + self.ctx.session_options = self.ctx.session_options.model_copy(update=kwargs) + self.ctx.transaction_manager.set_max_transactions(self.ctx.session_options.max_transactions) + self.ctx.transaction_manager.reset_stopwatch(self.ctx.session_options.max_seconds) @classmethod def from_repo( diff --git a/src/codegen/sdk/core/detached_symbols/argument.py b/src/codegen/sdk/core/detached_symbols/argument.py index c6d771397..948619f15 100644 --- a/src/codegen/sdk/core/detached_symbols/argument.py +++ b/src/codegen/sdk/core/detached_symbols/argument.py @@ -14,7 +14,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.dataclasses.usage import UsageKind from codegen.sdk.core.detached_symbols.function_call import FunctionCall from codegen.sdk.core.detached_symbols.parameter import Parameter @@ -33,7 +33,7 @@ class Argument(Expression[Parent], HasName, HasValue, Generic[Parent, TParameter _pos: int def __init__(self, node: TSNode, positional_idx: int, parent: FunctionCall) -> None: - super().__init__(node, parent.file_node_id, parent.G, parent) + super().__init__(node, parent.file_node_id, parent.ctx, parent) self._pos = positional_idx # TODO: Make the python and typescript implementations into different classes @@ -61,9 +61,9 @@ def __repr__(self) -> str: @noapidoc @classmethod - def from_argument_list(cls, node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: FunctionCall) -> MultiExpression[Parent, Argument]: - args = [Argument(x, file_node_id, G, parent, i) for i, x in enumerate(node.named_children) if x.type != "comment"] - return MultiExpression(node, file_node_id, G, parent, expressions=args) + def from_argument_list(cls, node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: FunctionCall) -> MultiExpression[Parent, Argument]: + args = [Argument(x, file_node_id, ctx, parent, i) for i, x in enumerate(node.named_children) if x.type != "comment"] + return MultiExpression(node, file_node_id, ctx, parent, expressions=args) @property @reader diff --git a/src/codegen/sdk/core/detached_symbols/code_block.py b/src/codegen/sdk/core/detached_symbols/code_block.py index c267d328c..a5fde4d62 100644 --- a/src/codegen/sdk/core/detached_symbols/code_block.py +++ b/src/codegen/sdk/core/detached_symbols/code_block.py @@ -56,7 +56,7 @@ class CodeBlock(Expression[Parent], Generic[Parent, TAssignment]): _statements: MultiLineCollection[Statement, Self] def __init__(self, ts_node: TSNode, level: int, parent_block: CodeBlock | None, parent: Parent) -> None: - super().__init__(ts_node, parent.file_node_id, parent.G, parent) + super().__init__(ts_node, parent.file_node_id, parent.ctx, parent) self.parent_block = parent_block self.level = level # self.parse() @@ -492,7 +492,7 @@ def foo(): for comment in self.get_statements(statement_type=StatementType.COMMENT, max_level=self.level): if comment.start_byte < self.start_byte: starts.append(comment) - starts.extend([Value(x[0], self.file_node_id, self.G, self) for x in find_line_start_and_end_nodes(self.ts_node)]) + starts.extend([Value(x[0], self.file_node_id, self.ctx, self) for x in find_line_start_and_end_nodes(self.ts_node)]) return starts @reader @@ -513,7 +513,7 @@ def foo(): for comment in self.get_statements(statement_type=StatementType.COMMENT, max_level=self.level): if comment.start_byte < self.start_byte: ends.append(comment) - ends.extend([Value(x[1], self.file_node_id, self.G, self) for x in find_line_start_and_end_nodes(self.ts_node)]) + ends.extend([Value(x[1], self.file_node_id, self.ctx, self) for x in find_line_start_and_end_nodes(self.ts_node)]) return ends def _compute_dependencies(self, usage_type: UsageKind | None = None, dest: HasName | None = None) -> None: diff --git a/src/codegen/sdk/core/detached_symbols/decorator.py b/src/codegen/sdk/core/detached_symbols/decorator.py index 8371ad98a..ee23d0f80 100644 --- a/src/codegen/sdk/core/detached_symbols/decorator.py +++ b/src/codegen/sdk/core/detached_symbols/decorator.py @@ -29,7 +29,7 @@ class Decorator(Expression[TClass | TFunction], HasName, Generic[TClass, TFuncti """Abstract representation of a Decorator.""" def __init__(self, ts_node: TSNode, parent: TClass | TFunction) -> None: - super().__init__(ts_node, parent.file_node_id, parent.G, parent) + super().__init__(ts_node, parent.file_node_id, parent.ctx, parent) self._name_node = self._parse_expression(self._get_name_node(), default=Name) @abstractmethod diff --git a/src/codegen/sdk/core/detached_symbols/function_call.py b/src/codegen/sdk/core/detached_symbols/function_call.py index 4646946b0..8f8916978 100644 --- a/src/codegen/sdk/core/detached_symbols/function_call.py +++ b/src/codegen/sdk/core/detached_symbols/function_call.py @@ -25,7 +25,7 @@ from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.detached_symbols.parameter import Parameter from codegen.sdk.core.function import Function from codegen.sdk.core.interfaces.callable import Callable @@ -48,8 +48,8 @@ def f(): _arg_list: Collection[Argument, Self] - def __init__(self, node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: Parent) -> None: - super().__init__(node, file_node_id, G, parent) + def __init__(self, node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: Parent) -> None: + super().__init__(node, file_node_id, ctx, parent) # =====[ Grab the function name ]===== self._name_node = self.child_by_field_name("function", default=Name) or self.child_by_field_name("constructor", default=Name) if self._name_node is not None and self._name_node.ts_node.type in ("unary_expression", "await_expression"): @@ -60,7 +60,7 @@ def __init__(self, node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: msg = f"Failed to parse function call. Child 'argument_list' node does not exist. Source: {self.source}" raise ValueError(msg) args = [Argument(x, i, self) for i, x in enumerate(arg_list_node.named_children) if x.type != "comment"] - self._arg_list = Collection(arg_list_node, self.file_node_id, self.G, self, children=args) + self._arg_list = Collection(arg_list_node, self.file_node_id, self.ctx, self, children=args) def __repr__(self) -> str: """Custom string representation showing the function call chain structure. @@ -101,7 +101,7 @@ def from_usage(cls, node: Editable[Parent], parent: Parent | None = None) -> Sel call_node = find_first_ancestor(node.ts_node, ["call", "call_expression"]) if call_node is None: return None - return cls(call_node, node.file_node_id, node.G, parent or node.parent) + return cls(call_node, node.file_node_id, node.ctx, parent or node.parent) @property @reader @@ -118,10 +118,10 @@ def parent_function(self) -> Function | None: if func := find_first_ancestor(self.ts_node, [function_type.value for function_type in TSFunctionTypeNames]): from codegen.sdk.typescript.function import TSFunction - return TSFunction.from_function_type(func, self.file_node_id, self.G, self.parent) + return TSFunction.from_function_type(func, self.file_node_id, self.ctx, self.parent) elif self.file.programming_language == ProgrammingLanguage.PYTHON: if func := find_first_ancestor(self.ts_node, ["function_definition"]): - return self.G.node_classes.function_cls(func, self.file_node_id, self.G, self.parent) + return self.ctx.node_classes.function_cls(func, self.file_node_id, self.ctx, self.parent) return None @@ -179,7 +179,7 @@ def is_awaited(self) -> bool: return False # 3) Check if the nearest parent call is awaited - parent_call_obj = FunctionCall(nearest_call, self.file_node_id, self.G, None) + parent_call_obj = FunctionCall(nearest_call, self.file_node_id, self.ctx, None) if not parent_call_obj.is_awaited: return False @@ -527,7 +527,7 @@ def remove(self, delete_formatting: bool = True, priority: int = 0, dedupe: bool None """ if self.ts_node.parent.type == "expression_statement": - Value(self.ts_node.parent, self.file_node_id, self.G, self.parent).remove(delete_formatting=delete_formatting, priority=priority, dedupe=dedupe) + Value(self.ts_node.parent, self.file_node_id, self.ctx, self.parent).remove(delete_formatting=delete_formatting, priority=priority, dedupe=dedupe) else: super().remove(delete_formatting=delete_formatting, priority=priority, dedupe=dedupe) @@ -565,7 +565,7 @@ def _resolved_types(self) -> Generator[ResolutionStack[Self], None, None]: if generic := function_def_frame.generics.get(return_type.source, None): yield from self.with_resolution_frame(generic, direct=function_def_frame.direct) return - if self.G.config.feature_flags.generics: + if self.ctx.config.feature_flags.generics: for arg in self.args: if arg.parameter and (type := arg.parameter.type): if type.source == return_type.source: @@ -600,7 +600,7 @@ def _compute_dependencies(self, usage_type: UsageKind, dest: HasName | None = No if isinstance(match, FunctionCall): match._compute_dependencies(usage_type, dest) for definition in self.function_definition_frames: - definition.add_usage(match=self, dest=dest, usage_type=usage_type, G=self.G) + definition.add_usage(match=self, dest=dest, usage_type=usage_type, codebase_context=self.ctx) else: match._compute_dependencies(usage_type, dest) @@ -664,7 +664,7 @@ def rename_if_matching(self, old: str, new: str): @noapidoc def register_api_call(self, url: str): assert url, self - self.G.global_context.multigraph.usages[url].append(self) + self.ctx.global_context.multigraph.usages[url].append(self) @property @reader diff --git a/src/codegen/sdk/core/detached_symbols/parameter.py b/src/codegen/sdk/core/detached_symbols/parameter.py index e07192220..f3ac697d5 100644 --- a/src/codegen/sdk/core/detached_symbols/parameter.py +++ b/src/codegen/sdk/core/detached_symbols/parameter.py @@ -45,7 +45,7 @@ class Parameter(Usable[Parent], Typeable[TType, Parent], HasValue, Expression[Pa _name_node: Name | None = None def __init__(self, ts_node: TSNode, index: int, parent: Parent) -> None: - super().__init__(ts_node, parent.file_node_id, parent.G, parent) + super().__init__(ts_node, parent.file_node_id, parent.ctx, parent) self._pos = index name_node = self._get_name_node(ts_node) self._name_node = self._parse_expression(name_node, default=Name) diff --git a/src/codegen/sdk/core/export.py b/src/codegen/sdk/core/export.py index 3c419a2ef..e9d63a9e5 100644 --- a/src/codegen/sdk/core/export.py +++ b/src/codegen/sdk/core/export.py @@ -10,7 +10,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.node_id_factory import NodeId from codegen.sdk.core.statements.export_statement import ExportStatement from codegen.sdk.core.symbol_groups.collection import Collection @@ -29,13 +29,13 @@ class Export(Exportable[Parent], Generic[Parent]): export_statement: ExportStatement - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: Parent) -> None: + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: Parent) -> None: self.to_file_id = file_node_id - super().__init__(ts_node=ts_node, file_node_id=file_node_id, G=G, parent=parent) + super().__init__(ts_node=ts_node, file_node_id=file_node_id, ctx=ctx, parent=parent) @noapidoc @abstractmethod - def parse(self, G: CodebaseGraph) -> None: + def parse(self, ctx: CodebaseContext) -> None: """Add self to the graph and SYMBOL_USAGE edges from export to exported symbol.""" @property diff --git a/src/codegen/sdk/core/expressions/await_expression.py b/src/codegen/sdk/core/expressions/await_expression.py index 15e2a9083..e3643de34 100644 --- a/src/codegen/sdk/core/expressions/await_expression.py +++ b/src/codegen/sdk/core/expressions/await_expression.py @@ -17,10 +17,10 @@ class AwaitExpression(Expression[Parent], HasValue, IWrapper, Generic[Parent]): """An awaited expression, only found in asynchronous contexts, e.g. await(foo(bar))""" - def __init__(self, ts_node, file_node_id, G, parent: Parent): - super().__init__(ts_node, file_node_id, G, parent=parent) + def __init__(self, ts_node, file_node_id, ctx, parent: Parent): + super().__init__(ts_node, file_node_id, ctx, parent=parent) value_node = self.ts_node.named_children[0] - self._value_node = self.G.parser.parse_expression(value_node, self.file_node_id, self.G, parent) if value_node else None + self._value_node = self.ctx.parser.parse_expression(value_node, self.file_node_id, self.ctx, parent) if value_node else None @property @reader diff --git a/src/codegen/sdk/core/expressions/binary_expression.py b/src/codegen/sdk/core/expressions/binary_expression.py index 24554845a..fdb4ec349 100644 --- a/src/codegen/sdk/core/expressions/binary_expression.py +++ b/src/codegen/sdk/core/expressions/binary_expression.py @@ -33,8 +33,8 @@ class BinaryExpression(Expression[Parent], Chainable, Generic[Parent]): left: Expression[Self] | None right: Expression[Self] | None - def __init__(self, ts_node, file_node_id, G, parent: Parent) -> None: - super().__init__(ts_node, file_node_id, G, parent=parent) + def __init__(self, ts_node, file_node_id, ctx, parent: Parent) -> None: + super().__init__(ts_node, file_node_id, ctx, parent=parent) self.left = self.child_by_field_name("left") self.right = self.child_by_field_name("right") @@ -43,7 +43,7 @@ def __init__(self, ts_node, file_node_id, G, parent: Parent) -> None: def operator(self) -> ExpressionGroup[Expression[Self], Self]: """Returns the operator of the binary expression.""" operator_nodes = self.ts_node.children[1:-1] - return ExpressionGroup(self.file_node_id, self.G, self, children=[self._parse_expression(node) for node in operator_nodes]) + return ExpressionGroup(self.file_node_id, self.ctx, self, children=[self._parse_expression(node) for node in operator_nodes]) @property def operators(self) -> list[ExpressionGroup[Expression[Self], Self]]: diff --git a/src/codegen/sdk/core/expressions/builtin.py b/src/codegen/sdk/core/expressions/builtin.py index d8d60998e..04be98f97 100644 --- a/src/codegen/sdk/core/expressions/builtin.py +++ b/src/codegen/sdk/core/expressions/builtin.py @@ -25,4 +25,4 @@ def _resolved_types(self) -> Generator[ResolutionStack[Self], None, None]: def resolve_attribute(self, name: str) -> "ExternalModule | None": # HACK/TODO return None - # return ExternalModule(self.ts_node, self.file_node_id, self.G, name) + # return ExternalModule(self.ts_node, self.file_node_id, self.ctx, name) diff --git a/src/codegen/sdk/core/expressions/chained_attribute.py b/src/codegen/sdk/core/expressions/chained_attribute.py index 45ee7a90f..788fb0241 100644 --- a/src/codegen/sdk/core/expressions/chained_attribute.py +++ b/src/codegen/sdk/core/expressions/chained_attribute.py @@ -36,15 +36,15 @@ class ChainedAttribute(Expression[Parent], Resolvable, Generic[Object, Attribute _object: Object _attribute: Attribute - def __init__(self, ts_node, file_node_id, G, parent: Parent, object: TSNode, attribute: TSNode): - super().__init__(ts_node, file_node_id, G, parent=parent) + def __init__(self, ts_node, file_node_id, ctx, parent: Parent, object: TSNode, attribute: TSNode): + super().__init__(ts_node, file_node_id, ctx, parent=parent) self._object = self._parse_expression(object, default=Name) - if self.G.parser._should_log: + if self.ctx.parser._should_log: if not isinstance(self._object, Chainable): msg = f"{self._object.__class__} is not chainable: {self._object.source}\nfile: {self.filepath}" raise ValueError(msg) self._attribute = self._parse_expression(attribute, default=Name) - if self.G.parser._should_log: + if self.ctx.parser._should_log: if not isinstance(self._attribute, Resolvable): msg = f"{self._attribute.__class__} is not resolvable: {self._attribute.source}\nfile: {self.filepath}" raise ValueError(msg) @@ -136,7 +136,7 @@ def object(self) -> Object: def _resolved_types(self) -> Generator[ResolutionStack[Self], None, None]: from codegen.sdk.typescript.namespace import TSNamespace - if not self.G.config.feature_flags.method_usages: + if not self.ctx.config.feature_flags.method_usages: return if res := self.file.valid_import_names.get(self.full_name, None): # Module imports @@ -167,9 +167,9 @@ def _resolved_types(self) -> Generator[ResolutionStack[Self], None, None]: def _compute_dependencies(self, usage_type: UsageKind, dest: Optional["HasName | None"] = None) -> None: edges = [] for used_frame in self.resolved_type_frames: - edges.extend(used_frame.get_edges(self, usage_type, dest, self.G)) + edges.extend(used_frame.get_edges(self, usage_type, dest, self.ctx)) edges = list(dict.fromkeys(edges)) - self.G.add_edges(edges) + self.ctx.add_edges(edges) if self.object.source not in ("self", "this"): self.object._compute_dependencies(usage_type, dest) diff --git a/src/codegen/sdk/core/expressions/comparison_expression.py b/src/codegen/sdk/core/expressions/comparison_expression.py index 7cbafd350..fc0cb2f2a 100644 --- a/src/codegen/sdk/core/expressions/comparison_expression.py +++ b/src/codegen/sdk/core/expressions/comparison_expression.py @@ -16,8 +16,8 @@ class ComparisonExpression(BinaryExpression): Includes all set of `<`, `<=`, `>`, `>=`, `==`, `!=` etc. """ - def __init__(self, ts_node, file_node_id, G, parent: Parent) -> None: - super().__init__(ts_node, file_node_id, G, parent=parent) + def __init__(self, ts_node, file_node_id, ctx, parent: Parent) -> None: + super().__init__(ts_node, file_node_id, ctx, parent=parent) self.left = self.elements[0] self.right = self.elements[-1] @@ -41,7 +41,7 @@ def operators(self) -> list[ExpressionGroup[Expression[Self], Self]]: if n not in elements: operator_group.append(n) elif operator_group: - operator = ExpressionGroup(self.file_node_id, self.G, self, children=[self._parse_expression(op) for op in operator_group]) + operator = ExpressionGroup(self.file_node_id, self.ctx, self, children=[self._parse_expression(op) for op in operator_group]) operators.append(operator) operator_group.clear() return operators diff --git a/src/codegen/sdk/core/expressions/generic_type.py b/src/codegen/sdk/core/expressions/generic_type.py index 34f0d56f8..5fc60e7c9 100644 --- a/src/codegen/sdk/core/expressions/generic_type.py +++ b/src/codegen/sdk/core/expressions/generic_type.py @@ -14,7 +14,7 @@ from codegen.shared.decorators.docs import apidoc, noapidoc if TYPE_CHECKING: - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.expressions.type import Type from codegen.sdk.core.interfaces.editable import Editable @@ -31,8 +31,8 @@ class GenericType(NamedType[Parent], Generic[TType, Parent]): _parameters: Collection[TType, Self] - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: "CodebaseGraph", parent: Parent): - super().__init__(ts_node, file_node_id, G, parent) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: "CodebaseContext", parent: Parent): + super().__init__(ts_node, file_node_id, ctx, parent) self._parameters = self._get_parameters() @property diff --git a/src/codegen/sdk/core/expressions/multi_expression.py b/src/codegen/sdk/core/expressions/multi_expression.py index 58bfa8ccc..58d09874c 100644 --- a/src/codegen/sdk/core/expressions/multi_expression.py +++ b/src/codegen/sdk/core/expressions/multi_expression.py @@ -9,7 +9,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.dataclasses.usage import UsageKind from codegen.sdk.core.interfaces.has_name import HasName from codegen.sdk.core.node_id_factory import NodeId @@ -29,8 +29,8 @@ class MultiExpression(Expression[Parent], Generic[Parent, TExpression]): expressions: list[TExpression] - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: Parent, expressions: list[TExpression]) -> None: - super().__init__(ts_node, file_node_id, G, parent) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: Parent, expressions: list[TExpression]) -> None: + super().__init__(ts_node, file_node_id, ctx, parent) self.expressions = expressions @noapidoc diff --git a/src/codegen/sdk/core/expressions/name.py b/src/codegen/sdk/core/expressions/name.py index bb7ecbf19..e697caf26 100644 --- a/src/codegen/sdk/core/expressions/name.py +++ b/src/codegen/sdk/core/expressions/name.py @@ -38,10 +38,10 @@ def _compute_dependencies(self, usage_type: UsageKind, dest: Optional["HasName | """Compute the dependencies of the export object.""" edges = [] for used_frame in self.resolved_type_frames: - edges.extend(used_frame.get_edges(self, usage_type, dest, self.G)) - if self.G.config.feature_flags.debug: + edges.extend(used_frame.get_edges(self, usage_type, dest, self.ctx)) + if self.ctx.config.feature_flags.debug: edges = list(dict.fromkeys(edges)) - self.G.add_edges(edges) + self.ctx.add_edges(edges) @noapidoc @writer diff --git a/src/codegen/sdk/core/expressions/named_type.py b/src/codegen/sdk/core/expressions/named_type.py index 7628a1291..f908244c0 100644 --- a/src/codegen/sdk/core/expressions/named_type.py +++ b/src/codegen/sdk/core/expressions/named_type.py @@ -16,7 +16,7 @@ from codegen.shared.decorators.docs import apidoc, noapidoc if TYPE_CHECKING: - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.interfaces.editable import Editable Parent = TypeVar("Parent", bound="Editable") @@ -26,8 +26,8 @@ class NamedType(Resolvable, Type[Parent], HasName, Generic[Parent]): """An abstract representation of a named type.""" - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: "CodebaseGraph", parent: Parent): - super().__init__(ts_node, file_node_id, G, parent) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: "CodebaseContext", parent: Parent): + super().__init__(ts_node, file_node_id, ctx, parent) self._name_node = self._parse_expression(self._get_name_node(), default=Name) def __eq__(self, other: object) -> bool: diff --git a/src/codegen/sdk/core/expressions/parenthesized_expression.py b/src/codegen/sdk/core/expressions/parenthesized_expression.py index e4452a7c0..6e05de3fa 100644 --- a/src/codegen/sdk/core/expressions/parenthesized_expression.py +++ b/src/codegen/sdk/core/expressions/parenthesized_expression.py @@ -25,10 +25,10 @@ class ParenthesizedExpression(Unwrappable[Parent], HasValue, IWrapper, Generic[P ``` """ - def __init__(self, ts_node, file_node_id, G, parent: Parent): - super().__init__(ts_node, file_node_id, G, parent=parent) + def __init__(self, ts_node, file_node_id, ctx, parent: Parent): + super().__init__(ts_node, file_node_id, ctx, parent=parent) value_node = self.ts_node.named_children[0] - self._value_node = self.G.parser.parse_expression(value_node, self.file_node_id, self.G, self) if value_node else None + self._value_node = self.ctx.parser.parse_expression(value_node, self.file_node_id, self.ctx, self) if value_node else None @property @reader diff --git a/src/codegen/sdk/core/expressions/string.py b/src/codegen/sdk/core/expressions/string.py index aa4240db4..3be669a98 100644 --- a/src/codegen/sdk/core/expressions/string.py +++ b/src/codegen/sdk/core/expressions/string.py @@ -14,7 +14,7 @@ from codegen.shared.decorators.docs import apidoc, noapidoc if TYPE_CHECKING: - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext Parent = TypeVar("Parent", bound="Expression") @@ -34,10 +34,10 @@ class String(Expression[Parent], Builtin, Generic[Parent]): content_nodes: Collection[Expression[Editable], Self] # string content is a collection of string_fragments and escape_sequences in TS and a single string_content in Python expressions: list[Expression[Editable]] # expressions in the string, only applicable for template strings - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: "CodebaseGraph", parent: Parent) -> None: - super().__init__(ts_node, file_node_id, G, parent=parent) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: "CodebaseContext", parent: Parent) -> None: + super().__init__(ts_node, file_node_id, ctx, parent=parent) content_children = list(self.children_by_field_types({"string_content", "string_fragment", "escape_sequence"})) - self.content_nodes = Collection(ts_node, self.file_node_id, self.G, self, delimiter="", children=content_children) + self.content_nodes = Collection(ts_node, self.file_node_id, self.ctx, self, delimiter="", children=content_children) self.content = "".join(x.ts_node.text.decode("utf-8") for x in content_children) @reader diff --git a/src/codegen/sdk/core/expressions/subscript_expression.py b/src/codegen/sdk/core/expressions/subscript_expression.py index e69ecc575..51d92a7aa 100644 --- a/src/codegen/sdk/core/expressions/subscript_expression.py +++ b/src/codegen/sdk/core/expressions/subscript_expression.py @@ -36,8 +36,8 @@ class SubscriptExpression(Expression[Parent], Resolvable[Parent], Generic[Object object: Object indices: list[Index] - def __init__(self, ts_node, file_node_id, G, parent: Parent): - super().__init__(ts_node, file_node_id, G, parent=parent) + def __init__(self, ts_node, file_node_id, ctx, parent: Parent): + super().__init__(ts_node, file_node_id, ctx, parent=parent) self.object = self._parse_expression(self.ts_node.children[0], default=Name) self.indices = self.children[1:] diff --git a/src/codegen/sdk/core/expressions/tuple_type.py b/src/codegen/sdk/core/expressions/tuple_type.py index 315c9ed09..1495fe8a5 100644 --- a/src/codegen/sdk/core/expressions/tuple_type.py +++ b/src/codegen/sdk/core/expressions/tuple_type.py @@ -11,7 +11,7 @@ from codegen.shared.decorators.docs import apidoc, noapidoc if TYPE_CHECKING: - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.interfaces.editable import Editable from codegen.sdk.core.interfaces.importable import Importable @@ -26,15 +26,15 @@ class TupleType(Collection[Type, Parent], Type[Parent], Generic[TType, Parent]): For example `[number, number]`. """ - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: "CodebaseGraph", parent: Parent): - super().__init__(ts_node, file_node_id, G, parent, delimiter=" |") + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: "CodebaseContext", parent: Parent): + super().__init__(ts_node, file_node_id, ctx, parent, delimiter=" |") elements = list(self._get_types(ts_node)) self._init_children(elements) self._bracket_size = 0 def _get_types(self, node: TSNode) -> Generator[TType, None, None]: for child in node.named_children: - type_cls = self.G.node_classes.type_map.get(child.type, None) + type_cls = self.ctx.node_classes.type_map.get(child.type, None) if isinstance(type_cls, type) and issubclass(type_cls, self.__class__): yield from self._get_types(child) else: diff --git a/src/codegen/sdk/core/expressions/unary_expression.py b/src/codegen/sdk/core/expressions/unary_expression.py index fbaa4db0a..e1f8c3ba8 100644 --- a/src/codegen/sdk/core/expressions/unary_expression.py +++ b/src/codegen/sdk/core/expressions/unary_expression.py @@ -1,7 +1,7 @@ from collections.abc import Generator from typing import Generic, Self, TypeVar, override -from codegen.sdk.codebase.codebase_graph import CodebaseGraph +from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.autocommit import writer from codegen.sdk.core.dataclasses.usage import UsageKind from codegen.sdk.core.expressions.expression import Expression @@ -27,8 +27,8 @@ class UnaryExpression(Expression[Parent], Chainable, Generic[Parent]): argument: Expression[Self] - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: Parent) -> None: - super().__init__(ts_node, file_node_id, G, parent) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: Parent) -> None: + super().__init__(ts_node, file_node_id, ctx, parent) self.argument = self._parse_expression(ts_node.child_by_field_name("argument")) @reader diff --git a/src/codegen/sdk/core/expressions/union_type.py b/src/codegen/sdk/core/expressions/union_type.py index 877a6ef9d..a9c979cae 100644 --- a/src/codegen/sdk/core/expressions/union_type.py +++ b/src/codegen/sdk/core/expressions/union_type.py @@ -11,7 +11,7 @@ from codegen.shared.decorators.docs import apidoc, noapidoc if TYPE_CHECKING: - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.interfaces.editable import Editable from codegen.sdk.core.interfaces.importable import Importable @@ -26,15 +26,15 @@ class UnionType(Collection[Type, Parent], Type[Parent], Generic[TType, Parent]): For example `str | None` or `string | number`. """ - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: "CodebaseGraph", parent: Parent): - super().__init__(ts_node, file_node_id, G, parent, delimiter=" |") + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: "CodebaseContext", parent: Parent): + super().__init__(ts_node, file_node_id, ctx, parent, delimiter=" |") elements = list(self._get_types(ts_node)) self._init_children(elements) self._bracket_size = 0 def _get_types(self, node: TSNode) -> Generator[TType, None, None]: for child in node.named_children: - type_cls = self.G.node_classes.type_map.get(child.type, None) + type_cls = self.ctx.node_classes.type_map.get(child.type, None) if isinstance(type_cls, type) and issubclass(type_cls, self.__class__): yield from self._get_types(child) else: diff --git a/src/codegen/sdk/core/expressions/unpack.py b/src/codegen/sdk/core/expressions/unpack.py index 6a2c8b814..10dd7be52 100644 --- a/src/codegen/sdk/core/expressions/unpack.py +++ b/src/codegen/sdk/core/expressions/unpack.py @@ -22,8 +22,8 @@ class Unpack(Unwrappable[Parent], HasValue, IWrapper, Generic[Parent]): ``` """ - def __init__(self, ts_node, file_node_id, G, parent: Parent): - super().__init__(ts_node, file_node_id, G, parent=parent) + def __init__(self, ts_node, file_node_id, ctx, parent: Parent): + super().__init__(ts_node, file_node_id, ctx, parent=parent) self._value_node = self.children[0] def unwrap(self, node: Expression | None = None) -> None: diff --git a/src/codegen/sdk/core/expressions/value.py b/src/codegen/sdk/core/expressions/value.py index b6116dd7e..c70dec4ba 100644 --- a/src/codegen/sdk/core/expressions/value.py +++ b/src/codegen/sdk/core/expressions/value.py @@ -25,7 +25,7 @@ class Value(Expression[Parent], Generic[Parent]): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.G.parser.log_unparsed(self.ts_node) + self.ctx.parser.log_unparsed(self.ts_node) @noapidoc @commiter diff --git a/src/codegen/sdk/core/external/dependency_manager.py b/src/codegen/sdk/core/external/dependency_manager.py index 85e250c34..e067be9b6 100644 --- a/src/codegen/sdk/core/external/dependency_manager.py +++ b/src/codegen/sdk/core/external/dependency_manager.py @@ -5,7 +5,7 @@ from codegen.sdk.enums import ProgrammingLanguage if TYPE_CHECKING: - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext class DependencyManager(ExternalProcess): @@ -27,12 +27,12 @@ def remove_dependencies(self): pass -def get_dependency_manager(language: ProgrammingLanguage, codebase_graph: "CodebaseGraph", enabled: bool = False) -> DependencyManager | None: +def get_dependency_manager(language: ProgrammingLanguage, codebase_context: "CodebaseContext", enabled: bool = False) -> DependencyManager | None: from codegen.sdk.typescript.external.dependency_manager import TypescriptDependencyManager - ts_enabled = enabled or codebase_graph.config.feature_flags.ts_dependency_manager + ts_enabled = enabled or codebase_context.config.feature_flags.ts_dependency_manager if language == ProgrammingLanguage.TYPESCRIPT: if ts_enabled: - return TypescriptDependencyManager(repo_path=codebase_graph.repo_path, base_path=codebase_graph.projects[0].base_path) + return TypescriptDependencyManager(repo_path=codebase_context.repo_path, base_path=codebase_context.projects[0].base_path) return None diff --git a/src/codegen/sdk/core/external/language_engine.py b/src/codegen/sdk/core/external/language_engine.py index 8e2706460..74564364f 100644 --- a/src/codegen/sdk/core/external/language_engine.py +++ b/src/codegen/sdk/core/external/language_engine.py @@ -5,7 +5,7 @@ from codegen.sdk.enums import ProgrammingLanguage if TYPE_CHECKING: - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.interfaces.editable import Editable @@ -21,17 +21,17 @@ def get_return_type(self, node: "Editable") -> str | None: pass -def get_language_engine(language: ProgrammingLanguage, codebase_graph: "CodebaseGraph", use_ts: bool = False, use_v8: bool = False) -> LanguageEngine | None: +def get_language_engine(language: ProgrammingLanguage, codebase_context: "CodebaseContext", use_ts: bool = False, use_v8: bool = False) -> LanguageEngine | None: from codegen.sdk.typescript.external.ts_analyzer_engine import NodeTypescriptEngine, V8TypescriptEngine - use_ts = use_ts or codebase_graph.config.feature_flags.ts_language_engine - use_v8 = use_v8 or codebase_graph.config.feature_flags.v8_ts_engine + use_ts = use_ts or codebase_context.config.feature_flags.ts_language_engine + use_v8 = use_v8 or codebase_context.config.feature_flags.v8_ts_engine if language == ProgrammingLanguage.TYPESCRIPT: if use_ts and use_v8: # Enables with both ts_language_engine and v8_ts_engine feature flags are on - return V8TypescriptEngine(repo_path=codebase_graph.repo_path, base_path=codebase_graph.projects[0].base_path, dependency_manager=codebase_graph.dependency_manager) + return V8TypescriptEngine(repo_path=codebase_context.repo_path, base_path=codebase_context.projects[0].base_path, dependency_manager=codebase_context.dependency_manager) elif use_ts: # Enabled with only ts_language_engine feature flag is on - return NodeTypescriptEngine(repo_path=codebase_graph.repo_path, base_path=codebase_graph.projects[0].base_path, dependency_manager=codebase_graph.dependency_manager) + return NodeTypescriptEngine(repo_path=codebase_context.repo_path, base_path=codebase_context.projects[0].base_path, dependency_manager=codebase_context.dependency_manager) return None diff --git a/src/codegen/sdk/core/external_module.py b/src/codegen/sdk/core/external_module.py index 7a57eba56..0e97bbf04 100644 --- a/src/codegen/sdk/core/external_module.py +++ b/src/codegen/sdk/core/external_module.py @@ -13,7 +13,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.dataclasses.usage import UsageKind from codegen.sdk.core.detached_symbols.parameter import Parameter from codegen.sdk.core.expressions.name import Name @@ -39,13 +39,13 @@ class ExternalModule( node_type: Literal[NodeType.EXTERNAL] = NodeType.EXTERNAL _import: Import | None = None - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, import_name: Name, import_node: Import | None = None) -> None: - self.node_id = G.add_node(self) - super().__init__(ts_node, file_node_id, G, None) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, import_name: Name, import_node: Import | None = None) -> None: + self.node_id = ctx.add_node(self) + super().__init__(ts_node, file_node_id, ctx, None) self._name_node = import_name self.return_type = StubPlaceholder(parent=self) - assert self._idx_key not in self.G._ext_module_idx - self.G._ext_module_idx[self._idx_key] = self.node_id + assert self._idx_key not in self.ctx._ext_module_idx + self.ctx._ext_module_idx[self._idx_key] = self.node_id self._import = import_node @property @@ -54,7 +54,7 @@ def _idx_key(self) -> str: @noapidoc @commiter - def parse(self, G: CodebaseGraph) -> None: + def parse(self, ctx: CodebaseContext) -> None: msg = f"{type(self)} is not part of the graph at the moment" raise NotImplementedError(msg) @@ -72,7 +72,7 @@ def from_import(cls, imp: Import) -> ExternalModule: Returns: ExternalModule: A new ExternalModule instance representing the external module. """ - return cls(imp.ts_node, imp.file_node_id, imp.G, imp._unique_node, imp) + return cls(imp.ts_node, imp.file_node_id, imp.ctx, imp._unique_node, imp) @property @reader diff --git a/src/codegen/sdk/core/file.py b/src/codegen/sdk/core/file.py index aaacb5fcd..67c2faf20 100644 --- a/src/codegen/sdk/core/file.py +++ b/src/codegen/sdk/core/file.py @@ -13,7 +13,7 @@ from tree_sitter import Node as TSNode from codegen.sdk._proxy import proxy_property -from codegen.sdk.codebase.codebase_graph import CodebaseGraph +from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.codebase.range_index import RangeIndex from codegen.sdk.codebase.span import Range from codegen.sdk.core.autocommit import commiter, mover, reader, remover, writer @@ -72,15 +72,15 @@ class File(Editable[None]): _binary: bool = False _range_index: RangeIndex - def __init__(self, filepath: PathLike, G: CodebaseGraph, ts_node: TSNode | None = None, binary: bool = False) -> None: + def __init__(self, filepath: PathLike, ctx: CodebaseContext, ts_node: TSNode | None = None, binary: bool = False) -> None: if ts_node is None: # TODO: this is a temp hack to deal with all symbols needing a TSNode. parser = get_parser_by_filepath_or_extension(".py") ts_node = parser.parse(bytes("", "utf-8")).root_node self._range_index = RangeIndex() - super().__init__(ts_node, getattr(self, "node_id", None), G, None) - self.path = self.G.to_absolute(filepath) - self.file_path = str(self.G.to_relative(self.path)) + super().__init__(ts_node, getattr(self, "node_id", None), ctx, None) + self.path = self.ctx.to_absolute(filepath) + self.file_path = str(self.ctx.to_relative(self.path)) self.name = self.path.stem self._directory = None self._binary = binary @@ -109,11 +109,11 @@ def file(self) -> Self: @classmethod @noapidoc - def from_content(cls, filepath: str | Path, content: str | bytes, G: CodebaseGraph, sync: bool = False, binary: bool = False) -> Self | None: + def from_content(cls, filepath: str | Path, content: str | bytes, ctx: CodebaseContext, sync: bool = False, binary: bool = False) -> Self | None: """Creates a new file from content.""" if sync: logger.warn("Creating & Syncing non-source files are not supported. Ignoring sync...") - path = G.to_absolute(filepath) + path = ctx.to_absolute(filepath) if not path.exists(): update_graph = True path.parent.mkdir(parents=True, exist_ok=True) @@ -122,7 +122,7 @@ def from_content(cls, filepath: str | Path, content: str | bytes, G: CodebaseGra else: path.write_bytes(content) - new_file = cls(filepath, G, ts_node=None, binary=binary) + new_file = cls(filepath, ctx, ts_node=None, binary=binary) return new_file @property @@ -168,7 +168,7 @@ def write(self, content: str | bytes, to_disk: bool = False) -> None: @noapidoc def write_bytes(self, content_bytes: bytes, to_disk: bool = False) -> None: self._pending_content_bytes = content_bytes - self.G.pending_files.add(self) + self.ctx.pending_files.add(self) if to_disk: self.write_pending_content() if self.ts_node.start_byte == self.ts_node.end_byte: @@ -235,17 +235,17 @@ def owners(self) -> set[str]: Returns: set[str]: A set of Github usernames or team names that own this file. Empty if no CODEOWNERS file exists. """ - if self.G.codeowners_parser: - # return get_filepath_owners(codeowners=self.G.codeowners_parser, filepath=self.file_path) - filename_owners = self.G.codeowners_parser.of(self.file_path) + if self.ctx.codeowners_parser: + # return get_filepath_owners(codeowners=self.ctx.codeowners_parser, filepath=self.file_path) + filename_owners = self.ctx.codeowners_parser.of(self.file_path) return {owner[1] for owner in filename_owners} return set() @cached_property @noapidoc def github_url(self) -> str | None: - if self.G.base_url: - return self.G.base_url + "/" + self.file_path + if self.ctx.base_url: + return self.ctx.base_url + "/" + self.file_path @property @reader @@ -332,13 +332,13 @@ def update_filepath(self, new_filepath: str) -> None: # =====[ Change the file on disk ]===== self.transaction_manager.add_file_rename_transaction(self, new_filepath) - def parse(self, G: "CodebaseGraph") -> None: + def parse(self, ctx: "CodebaseContext") -> None: """Parses the file representation into the graph. This method is called during file initialization to parse the file and build its graph representation within the codebase graph. Args: - G (CodebaseGraph): The codebase graph that the file belongs to. + ctx (CodebaseContext): The codebase context that the file belongs to. Returns: None @@ -446,16 +446,16 @@ class SourceFile( code_block: TCodeBlock _nodes: list[Importable] - def __init__(self, ts_node: TSNode, filepath: PathLike, G: CodebaseGraph) -> None: - self.node_id = G.add_node(self) + def __init__(self, ts_node: TSNode, filepath: PathLike, ctx: CodebaseContext) -> None: + self.node_id = ctx.add_node(self) self._nodes = [] - super().__init__(filepath, G, ts_node=ts_node) + super().__init__(filepath, ctx, ts_node=ts_node) self._nodes.clear() - self.G.filepath_idx[self.file_path] = self.node_id + self.ctx.filepath_idx[self.file_path] = self.node_id self._directory = None self._pending_imports = set() try: - self.parse(G) + self.parse(ctx) except RecursionError as e: logger.exception(f"RecursionError parsing file {filepath}: {e} at depth {sys.getrecursionlimit()} and {resource.getrlimit(resource.RLIMIT_STACK)}") raise e @@ -472,7 +472,7 @@ def _source(self): @noapidoc @commiter - def parse(self, G: CodebaseGraph) -> None: + def parse(self, ctx: CodebaseContext) -> None: self.__dict__.pop("_source", None) # Add self to the graph self.code_block = self._parse_code_block(self.ts_node) @@ -525,18 +525,18 @@ def unparse(self, reparse: bool = False) -> list[Importable]: # Save any external import resolution edges to be re-resolved before removing the nodes for node_id in node_ids_to_remove: - external_edges_to_resolve.extend(self.G.predecessors(node_id)) + external_edges_to_resolve.extend(self.ctx.predecessors(node_id)) # Finally, remove the nodes for node_id in node_ids_to_remove: if reparse and node_id == self.node_id: continue - if self.G.has_node(node_id): - self.G.remove_node(node_id) + if self.ctx.has_node(node_id): + self.ctx.remove_node(node_id) if not reparse: - self.G.filepath_idx.pop(self.file_path, None) + self.ctx.filepath_idx.pop(self.file_path, None) self._nodes.clear() - return list(filter(lambda node: self.G.has_node(node.node_id) and node is not None, external_edges_to_resolve)) + return list(filter(lambda node: self.ctx.has_node(node.node_id) and node is not None, external_edges_to_resolve)) @noapidoc @commiter @@ -545,13 +545,13 @@ def sync_with_file_content(self) -> None: self._pending_imports.clear() self.ts_node = parse_file(self.filepath, self.content) if self.node_id is None: - self.G.filepath_idx[self.file_path] = self.node_id + self.ctx.filepath_idx[self.file_path] = self.node_id self.file_node_id = self.node_id else: - assert self.G.has_node(self.node_id) + assert self.ctx.has_node(self.node_id) self.name = self.path.stem self._range_index.clear() - self.parse(self.G) + self.parse(self.ctx) @staticmethod @noapidoc @@ -587,9 +587,9 @@ def invalidate(self): @classmethod @noapidoc - def from_content(cls, filepath: str | PathLike | Path, content: str, G: CodebaseGraph, sync: bool = True, verify_syntax: bool = True) -> Self | None: + def from_content(cls, filepath: str | PathLike | Path, content: str, ctx: CodebaseContext, sync: bool = True, verify_syntax: bool = True) -> Self | None: """Creates a new file from content and adds it to the graph.""" - path = G.to_absolute(filepath) + path = ctx.to_absolute(filepath) ts_node = parse_file(path, content) if ts_node.has_error and verify_syntax: logger.info("Failed to parse file %s", filepath) @@ -602,19 +602,19 @@ def from_content(cls, filepath: str | PathLike | Path, content: str, G: Codebase path.write_text(content) if update_graph and sync: - G.add_single_file(path) - return G.get_file(filepath) + ctx.add_single_file(path) + return ctx.get_file(filepath) else: - return cls(ts_node, Path(filepath), G) + return cls(ts_node, Path(filepath), ctx) @classmethod @noapidoc - def create_from_filepath(cls, filepath: str, G: CodebaseGraph) -> Self | None: + def create_from_filepath(cls, filepath: str, ctx: CodebaseContext) -> Self | None: """Makes a new empty file and adds it to the graph. Graph-safe. """ - if filepath in G.filepath_idx: + if filepath in ctx.filepath_idx: msg = f"File already exists in graph: {filepath}" raise ValueError(msg) @@ -623,7 +623,7 @@ def create_from_filepath(cls, filepath: str, G: CodebaseGraph) -> Self | None: logger.info("Failed to parse file %s", filepath) raise SyntaxError - file = cls(ts_node, filepath, G) + file = cls(ts_node, filepath, ctx) file.write("", to_disk=True) return file @@ -680,8 +680,8 @@ def importers(self) -> list[TImport]: list[TImport]: List of Import objects that import this file as a module, sorted by file location. """ - imps = [x for x in self.G.in_edges(self.node_id) if x[2].type == EdgeType.IMPORT_SYMBOL_RESOLUTION] - return sort_editables((self.G.get_node(x[0]) for x in imps), by_file=True, dedupe=False) + imps = [x for x in self.ctx.in_edges(self.node_id) if x[2].type == EdgeType.IMPORT_SYMBOL_RESOLUTION] + return sort_editables((self.ctx.get_node(x[0]) for x in imps), by_file=True, dedupe=False) @property @reader(cache=False) @@ -783,7 +783,7 @@ def symbols_sorted_topologically(self) -> list[Symbol]: """ ids = [x.node_id for x in self.symbols] # Create a subgraph based on G - subgraph = self.G.build_subgraph(ids) + subgraph = self.ctx.build_subgraph(ids) symbol_names = pseudo_topological_sort(subgraph) return [subgraph.get_node_data(x) for x in symbol_names] @@ -915,12 +915,12 @@ def import_module_name(self) -> str: Returns: str: The module name used when importing this file. """ - return self.get_import_module_name_for_file(self.filepath, self.G) + return self.get_import_module_name_for_file(self.filepath, self.ctx) @classmethod @abstractmethod @noapidoc - def get_import_module_name_for_file(cls, filepath: str, G: CodebaseGraph) -> str: ... + def get_import_module_name_for_file(cls, filepath: str, ctx: CodebaseContext) -> str: ... @abstractmethod def remove_unused_exports(self) -> None: @@ -952,7 +952,7 @@ def update_filepath(self, new_filepath: str) -> None: None """ # =====[ Add the new filepath as a new file node in the graph ]===== - new_file = self.G.node_classes.file_cls.from_content(new_filepath, self.content, self.G) + new_file = self.ctx.node_classes.file_cls.from_content(new_filepath, self.content, self.ctx) # =====[ Change the file on disk ]===== super().update_filepath(new_filepath) # =====[ Update all the inbound imports to point to the new module ]===== diff --git a/src/codegen/sdk/core/function.py b/src/codegen/sdk/core/function.py index ee5a0bf31..20b400cc6 100644 --- a/src/codegen/sdk/core/function.py +++ b/src/codegen/sdk/core/function.py @@ -393,8 +393,8 @@ def inferred_return_type(self) -> str | None: Only enabled for specific languages that support native type inference. """ - if self.G.language_engine: - return self.G.language_engine.get_return_type(self) + if self.ctx.language_engine: + return self.ctx.language_engine.get_return_type(self) else: msg = "Language engine not enabled for this repo or language." raise NotImplementedError(msg) @@ -412,4 +412,4 @@ def descendant_symbols(self) -> Sequence[Importable]: @noapidoc def register_api(self, url: str): - self.G.global_context.multigraph.api_definitions[url] = self + self.ctx.global_context.multigraph.api_definitions[url] = self diff --git a/src/codegen/sdk/core/import_resolution.py b/src/codegen/sdk/core/import_resolution.py index 2e54bb2b8..7e6aa6538 100644 --- a/src/codegen/sdk/core/import_resolution.py +++ b/src/codegen/sdk/core/import_resolution.py @@ -27,7 +27,7 @@ import rich.repr from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.file import SourceFile from codegen.sdk.core.interfaces.exportable import Exportable from codegen.sdk.core.interfaces.has_name import HasName @@ -84,7 +84,7 @@ def __init__( self, ts_node: TSNode, file_node_id: NodeId, - G: CodebaseGraph, + ctx: CodebaseContext, parent: ImportStatement, module_node: TSNode | None, name_node: TSNode | None, @@ -92,10 +92,10 @@ def __init__( import_type: ImportType = ImportType.UNKNOWN, ) -> None: self.to_file_id = file_node_id - super().__init__(ts_node, file_node_id, G, parent) - self.module = self.G.parser.parse_expression(module_node, self.file_node_id, G, self, default=Name) if module_node else None - self.alias = self.G.parser.parse_expression(alias_node, self.file_node_id, G, self, default=Name) if alias_node else None - self.symbol_name = self.G.parser.parse_expression(name_node, self.file_node_id, G, self, default=Name) if name_node else None + super().__init__(ts_node, file_node_id, ctx, parent) + self.module = self.ctx.parser.parse_expression(module_node, self.file_node_id, ctx, self, default=Name) if module_node else None + self.alias = self.ctx.parser.parse_expression(alias_node, self.file_node_id, ctx, self, default=Name) if alias_node else None + self.symbol_name = self.ctx.parser.parse_expression(name_node, self.file_node_id, ctx, self, default=Name) if name_node else None self._name_node = self._parse_expression(name_node, default=Name) self.import_type = import_type @@ -133,25 +133,25 @@ def add_symbol_resolution_edge(self) -> None: # =====[ Case: Can't resolve the filepath ]===== if resolution is None: # =====[ Check if we are importing an external module in the graph ]===== - ext = self.G.get_external_module(self.source, self._unique_node.source) + ext = self.ctx.get_external_module(self.source, self._unique_node.source) if ext is None: ext = ExternalModule.from_import(self) - self.G.add_edge(self.node_id, ext.node_id, type=EdgeType.IMPORT_SYMBOL_RESOLUTION) + self.ctx.add_edge(self.node_id, ext.node_id, type=EdgeType.IMPORT_SYMBOL_RESOLUTION) # =====[ Case: Can resolve the filepath ]===== elif resolution.symbol: if resolution.symbol.node_id == self.node_id: return [] # Circular to self - self.G.add_edge( + self.ctx.add_edge( self.node_id, resolution.symbol.node_id, type=EdgeType.IMPORT_SYMBOL_RESOLUTION, ) elif resolution.imports_file: - self.G.add_edge(self.node_id, resolution.from_file.node_id, type=EdgeType.IMPORT_SYMBOL_RESOLUTION) + self.ctx.add_edge(self.node_id, resolution.from_file.node_id, type=EdgeType.IMPORT_SYMBOL_RESOLUTION) # for symbol in resolution.from_file.symbols: # usage = SymbolUsage(parent_symbol_name=self.name, child_symbol_name=self.name, type=SymbolUsageType.IMPORTED, match=self, usage_type=UsageType.DIRECT) - # self.G.add_edge(self.node_id, symbol.node_id, type=EdgeType.SYMBOL_USAGE, usage=usage) + # self.ctx.add_edge(self.node_id, symbol.node_id, type=EdgeType.SYMBOL_USAGE, usage=usage) # Referenced symbols that we can't find. # Could be: @@ -286,7 +286,7 @@ def to_file(self) -> TSourceFile: Returns: TSourceFile: The source file containing this import statement. """ - return self.G.get_node(self.to_file_id) + return self.ctx.get_node(self.to_file_id) @property @reader @@ -326,7 +326,7 @@ def _imported_symbol(self, resolve_exports: bool = False) -> Symbol | ExternalMo """ from codegen.sdk.typescript.file import TSFile - symbol = next(iter(self.G.successors(self.node_id, edge_type=EdgeType.IMPORT_SYMBOL_RESOLUTION, sort=False)), None) + symbol = next(iter(self.ctx.successors(self.node_id, edge_type=EdgeType.IMPORT_SYMBOL_RESOLUTION, sort=False)), None) if symbol is None: # Unresolve import - could occur during unparse() return None @@ -423,7 +423,7 @@ def my_function(): # always traverses upto the module level while curr: - if curr.type in self.G.node_classes.dynamic_import_parent_types: + if curr.type in self.ctx.node_classes.dynamic_import_parent_types: return True curr = curr.parent @@ -628,11 +628,11 @@ def _compute_dependencies(self, *args, **kwargs) -> None: # for _, wildcard in self._wildcards.items(): # for used_frame in wildcard.resolved_type_frames: # if used_frame.parent_frame: - # used_frame.parent_frame.add_usage(self.symbol_name or self.module, SymbolUsageType.IMPORTED_WILDCARD, self, self.G) + # used_frame.parent_frame.add_usage(self.symbol_name or self.module, SymbolUsageType.IMPORTED_WILDCARD, self, self.ctx) # else: for used_frame in self.resolved_type_frames: if used_frame.parent_frame: - used_frame.parent_frame.add_usage(self._unique_node, UsageKind.IMPORTED, self, self.G) + used_frame.parent_frame.add_usage(self._unique_node, UsageKind.IMPORTED, self, self.ctx) @property def _unique_node(self): diff --git a/src/codegen/sdk/core/interfaces/chainable.py b/src/codegen/sdk/core/interfaces/chainable.py index a72366418..0617aa087 100644 --- a/src/codegen/sdk/core/interfaces/chainable.py +++ b/src/codegen/sdk/core/interfaces/chainable.py @@ -45,7 +45,7 @@ def with_resolution( assert resolution is not self generics = generics or resolution.generics if generic_parameters: - if isinstance(resolution.top.node, SupportsGenerics) and self.G.config.feature_flags.generics: + if isinstance(resolution.top.node, SupportsGenerics) and self.ctx.config.feature_flags.generics: generics = {k: v for v, k in zip(generic_parameters, resolution.top.node.generics)} elif not generics: generics = {i: v for i, v in enumerate(generic_parameters)} diff --git a/src/codegen/sdk/core/interfaces/editable.py b/src/codegen/sdk/core/interfaces/editable.py index 416b4285c..2193bfaa1 100644 --- a/src/codegen/sdk/core/interfaces/editable.py +++ b/src/codegen/sdk/core/interfaces/editable.py @@ -29,7 +29,7 @@ from tree_sitter import Node as TSNode from tree_sitter import Point, Range - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.codebase.flagging.code_flag import CodeFlag from codegen.sdk.codebase.flagging.enums import FlagKwargs from codegen.sdk.codebase.transaction_manager import TransactionManager @@ -64,7 +64,7 @@ def _is_empty_container(text: str) -> bool: _EXCLUDE_FROM_REPR: list[str] = [ - "G", + "ctx", "autocommit_cache", "parent", "file_node_id", @@ -106,31 +106,31 @@ class Editable(JSONable, Generic[Parent]): Attributes: ts_node: The TreeSitter node associated with this Editable instance. file_node_id: The unique identifier for the file node. - G: The codebase graph that this Editable instance is part of. + ctx: The codebase context that this Editable instance is part of. parent: The parent node of this Editable instance. node_type: The type of node this Editable instance represents. """ ts_node: TSNode file_node_id: NodeId - G: CodebaseGraph + ctx: CodebaseContext parent: Parent node_type: NodeType _file: File | None = None _hash: int | None = None - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: Parent) -> None: + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: Parent) -> None: self.ts_node = ts_node self.file_node_id = file_node_id - self.G = G + self.ctx = ctx self.parent = parent - if G.config.feature_flags.debug: + if ctx.config.feature_flags.debug: seen = set() while parent is not None: assert (parent.ts_node, parent.__class__) not in seen seen.add((parent.ts_node, parent.__class__)) parent = parent.parent - if self.file and self.G.config.feature_flags.full_range_index: + if self.file and self.ctx.config.feature_flags.full_range_index: self._add_to_index def __hash__(self): @@ -187,7 +187,7 @@ def __contains__(self, item: str | Editable) -> bool: @property @noapidoc def transaction_manager(self) -> TransactionManager: - return self.G.transaction_manager + return self.ctx.transaction_manager @cached_property @noapidoc @@ -287,7 +287,7 @@ def extended(self) -> SymbolGroup: """ from codegen.sdk.core.symbol_group import SymbolGroup - return SymbolGroup(self.file_node_id, self.G, self.parent, children=self.extended_nodes) + return SymbolGroup(self.file_node_id, self.ctx, self.parent, children=self.extended_nodes) @property @reader @@ -380,7 +380,7 @@ def file(self) -> SourceFile: File: The File object containing this Editable instance. """ if self._file is None: - self._file = self.G.get_node(self.file_node_id) + self._file = self.ctx.get_node(self.file_node_id) return self._file # type: ignore @property @@ -678,7 +678,7 @@ def _edit_byte_range(self, new_src: str, start_byte: int, end_byte: int, priorit @remover @noapidoc def remove_byte_range(self, start_byte: int, end_byte: int) -> None: - if self.G.config.feature_flags.debug: + if self.ctx.config.feature_flags.debug: assert start_byte < end_byte t = RemoveTransaction(start_byte, end_byte, self.file) self.transaction_manager.add_transaction(t) @@ -849,7 +849,7 @@ def commit(self) -> None: Returns: None """ - self.G.commit_transactions(files={self.file.path}) + self.ctx.commit_transactions(files={self.file.path}) @noapidoc def _removed_child(self) -> None: @@ -931,10 +931,10 @@ def _parse_expression(self, node: TSNode, **kwargs) -> Expression[Self]: ... def _parse_expression(self, node: TSNode | None, **kwargs) -> Expression[Self] | None: ... def _parse_expression(self, node: TSNode | None, **kwargs) -> Expression[Self] | None: - return self.G.parser.parse_expression(node, self.file_node_id, self.G, self, **kwargs) + return self.ctx.parser.parse_expression(node, self.file_node_id, self.ctx, self, **kwargs) def _parse_type(self, node: TSNode) -> Type[Self] | None: - return self.G.parser.parse_type(node, self.file_node_id, self.G, self) + return self.ctx.parser.parse_type(node, self.file_node_id, self.ctx, self) def flag(self, **kwargs: Unpack[FlagKwargs]) -> CodeFlag[Self]: """Adds a visual flag comment to the end of this Editable's source text. @@ -947,7 +947,7 @@ def flag(self, **kwargs: Unpack[FlagKwargs]) -> CodeFlag[Self]: None """ # TODO: remove this once the frontend can process code flags - return self.G.flags.flag_instance(self, **kwargs) + return self.ctx.flags.flag_instance(self, **kwargs) @noapidoc @abstractmethod @@ -972,7 +972,7 @@ def _add_symbol_usages(self: HasName, identifiers: list[TSNode], usage_type: Usa @commiter @noapidoc def _add_all_identifier_usages(self, usage_type: UsageKind, dest: HasName | None = None) -> None: - id_types = self.G.node_classes.resolvables + id_types = self.ctx.node_classes.resolvables # Skip identifiers that are part of a property identifiers = find_all_descendants(self.ts_node, id_types, nested=False) return self._add_symbol_usages(identifiers, usage_type, dest) @@ -981,14 +981,14 @@ def _add_all_identifier_usages(self, usage_type: UsageKind, dest: HasName | None @noapidoc def add_all_identifier_usages_for_child_node(self, usage_type: UsageKind, child: TSNode, dest=None) -> None: # Interim hack. Don't use - id_types = self.G.node_classes.resolvables + id_types = self.ctx.node_classes.resolvables # Skip identifiers that are part of a property identifiers = find_all_descendants(child, id_types, nested=False) return self._add_symbol_usages(identifiers, usage_type, dest) @noapidoc def _log_parse(self, msg: str, *args, **kwargs): - self.G.parser.log(msg, *args, **kwargs) + self.ctx.parser.log(msg, *args, **kwargs) @property @noapidoc @@ -1043,7 +1043,7 @@ def descendant_symbols(self) -> list[Importable]: def reduce_condition(self, bool_condition: bool, node: Editable | None = None) -> None: """Reduces an editable to the following condition""" if node is not None: - node.edit(self.G.node_classes.bool_conversion[bool_condition]) + node.edit(self.ctx.node_classes.bool_conversion[bool_condition]) else: self.parent.reduce_condition(bool_condition, self) @@ -1145,7 +1145,7 @@ def _get_ast_children(self) -> list[tuple[str | None, AST]]: if isinstance(val, Editable): names[val] = name for child in self.file._range_index.get_children(self): - if self.G.config.feature_flags.debug: + if self.ctx.config.feature_flags.debug: assert child != self, child elif child == self: continue diff --git a/src/codegen/sdk/core/interfaces/exportable.py b/src/codegen/sdk/core/interfaces/exportable.py index 28f77b963..b201316ac 100644 --- a/src/codegen/sdk/core/interfaces/exportable.py +++ b/src/codegen/sdk/core/interfaces/exportable.py @@ -35,7 +35,7 @@ def is_exported(self) -> bool: def export(self) -> Export | None: """Returns the export object that exports this symbol. - Retrieves the export object by examining incoming EXPORT edges in the CodebaseGraph. + Retrieves the export object by examining incoming EXPORT edges in the CodebaseContext. Args: None @@ -46,7 +46,7 @@ def export(self) -> Export | None: try: if self.node_id is None: return None - return self.G.predecessor(self.node_id, edge_type=EdgeType.EXPORT) + return self.ctx.predecessor(self.node_id, edge_type=EdgeType.EXPORT) except NoSuitableNeighbors: return None diff --git a/src/codegen/sdk/core/interfaces/has_block.py b/src/codegen/sdk/core/interfaces/has_block.py index 678fee099..0d26a92a1 100644 --- a/src/codegen/sdk/core/interfaces/has_block.py +++ b/src/codegen/sdk/core/interfaces/has_block.py @@ -47,7 +47,7 @@ def _parse_code_block(self, body_node: TSNode | None = None) -> TCodeBlock | Non break parent = parent.parent - return self.G.node_classes.code_block_cls(body_node, level, parent_block, self) + return self.ctx.node_classes.code_block_cls(body_node, level, parent_block, self) @property @reader diff --git a/src/codegen/sdk/core/interfaces/importable.py b/src/codegen/sdk/core/interfaces/importable.py index 237606640..c2db81607 100644 --- a/src/codegen/sdk/core/interfaces/importable.py +++ b/src/codegen/sdk/core/interfaces/importable.py @@ -14,7 +14,7 @@ from codegen.shared.decorators.docs import apidoc, noapidoc if TYPE_CHECKING: - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.import_resolution import Import from codegen.sdk.core.interfaces.editable import Editable from codegen.sdk.core.symbol import Symbol @@ -33,10 +33,10 @@ class Importable(Expression[Parent], HasName, Generic[Parent]): node_id: int - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: "CodebaseGraph", parent: Parent) -> None: + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: "CodebaseContext", parent: Parent) -> None: if not hasattr(self, "node_id"): - self.node_id = G.add_node(self) - super().__init__(ts_node, file_node_id, G, parent) + self.node_id = ctx.add_node(self) + super().__init__(ts_node, file_node_id, ctx, parent) if self.file: self.file._nodes.append(self) @@ -75,11 +75,11 @@ def _get_dependencies(self, usage_types: UsageType) -> list[Union["Symbol", "Imp Opposite of `usages` """ # TODO: sort out attribute usages in dependencies - edges = [x for x in self.G.out_edges(self.node_id) if x[2].type == EdgeType.SYMBOL_USAGE] + edges = [x for x in self.ctx.out_edges(self.node_id) if x[2].type == EdgeType.SYMBOL_USAGE] unique_dependencies = [] for edge in edges: if edge[2].usage.usage_type is None or edge[2].usage.usage_type in usage_types: - dependency = self.G.get_node(edge[1]) + dependency = self.ctx.get_node(edge[1]) unique_dependencies.append(dependency) return sort_editables(unique_dependencies, by_file=True) @@ -110,8 +110,8 @@ def _remove_internal_edges(self, edge_type: EdgeType | None = None) -> None: Returns a list of node ids for edges that were removed. """ # Must store edges to remove in a static read-only view before removing to avoid concurrent dict modification - for v in self.G.successors(self.node_id, edge_type=edge_type): - self.G.remove_edge(self.node_id, v.node_id, edge_type=edge_type) + for v in self.ctx.successors(self.node_id, edge_type=edge_type): + self.ctx.remove_edge(self.node_id, v.node_id, edge_type=edge_type) @property @noapidoc diff --git a/src/codegen/sdk/core/interfaces/inherits.py b/src/codegen/sdk/core/interfaces/inherits.py index 73778d971..10a67a3d6 100644 --- a/src/codegen/sdk/core/interfaces/inherits.py +++ b/src/codegen/sdk/core/interfaces/inherits.py @@ -40,7 +40,7 @@ def traverse_classes(classes: list[Inherits], depth: int = 0) -> Generator[Class return next_level = [] for node in classes: - for result in self.G.successors(node.node_id, edge_type=EdgeType.SUBCLASS): + for result in self.ctx.successors(node.node_id, edge_type=EdgeType.SUBCLASS): if result.node_id not in seen: seen.add(result.node_id) yield result @@ -62,7 +62,7 @@ def traverse_classes(classes: list[Inherits], depth: int = 0) -> Generator[Class return next_level = [] for node in classes: - for result in self.G.predecessors(node.node_id, edge_type=EdgeType.SUBCLASS): + for result in self.ctx.predecessors(node.node_id, edge_type=EdgeType.SUBCLASS): if result.node_id not in seen: seen.add(result.node_id) yield result diff --git a/src/codegen/sdk/core/interfaces/parseable.py b/src/codegen/sdk/core/interfaces/parseable.py index 86185bf11..28a995892 100644 --- a/src/codegen/sdk/core/interfaces/parseable.py +++ b/src/codegen/sdk/core/interfaces/parseable.py @@ -2,10 +2,10 @@ from typing import TYPE_CHECKING if TYPE_CHECKING: - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext class Parseable(ABC): @abstractmethod - def parse(self, G: "CodebaseGraph") -> None: + def parse(self, ctx: "CodebaseContext") -> None: """Adds itself and its children to the codebase graph.""" diff --git a/src/codegen/sdk/core/interfaces/usable.py b/src/codegen/sdk/core/interfaces/usable.py index 8c9ab922d..f1d2ed450 100644 --- a/src/codegen/sdk/core/interfaces/usable.py +++ b/src/codegen/sdk/core/interfaces/usable.py @@ -66,7 +66,7 @@ def usages(self, usage_types: UsageType | None = None) -> list[Usage]: assert self.node_id is not None usages_to_return = [] - in_edges = self.G.in_edges(self.node_id) + in_edges = self.ctx.in_edges(self.node_id) for edge in in_edges: meta_data = edge[2] if meta_data.type == EdgeType.SYMBOL_USAGE: diff --git a/src/codegen/sdk/core/parser.py b/src/codegen/sdk/core/parser.py index 37be5d4d0..cfa5f64f3 100644 --- a/src/codegen/sdk/core/parser.py +++ b/src/codegen/sdk/core/parser.py @@ -13,7 +13,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.codebase.node_classes.node_classes import NodeClasses from codegen.sdk.core.expressions.type import Type from codegen.sdk.core.interfaces.editable import Editable @@ -28,7 +28,7 @@ class CanParse(Protocol, Generic[Parent]): - def __init__(self, node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: Parent) -> None: ... + def __init__(self, node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: Parent) -> None: ... Expression = TypeVar("Expression", bound="CanParse") @@ -60,20 +60,20 @@ def _process_type(self, expr_type: type[Type] | dict[str, type[Type]], node: TSN def from_node_classes(cls, node_classes: NodeClasses, log_parse_warnings: bool = False) -> Self: return cls(symbol_map=node_classes.symbol_map, expressions=node_classes.expression_map, types=node_classes.type_map, type_node=node_classes.type_node_type, _should_log=log_parse_warnings) - def parse_expression(self, node: TSNode | None, file_node_id: NodeId, G: CodebaseGraph, parent: Parent, *args, default: type[Expression] = Value, **kwargs) -> Expression[Parent] | None: + def parse_expression(self, node: TSNode | None, file_node_id: NodeId, ctx: CodebaseContext, parent: Parent, *args, default: type[Expression] = Value, **kwargs) -> Expression[Parent] | None: if node is None: return None if node.type == self.type_node: - return self.parse_type(node, file_node_id, G, parent) + return self.parse_type(node, file_node_id, ctx, parent) assert default is not None if default == Value: if previous := parent.file._range_index.get_canonical_for_range(node.range, node.kind_id): return previous if symbol_cls := self.symbol_map.get(node.type, None): - ret = symbol_cls(node, file_node_id, G, parent, *args, **kwargs) + ret = symbol_cls(node, file_node_id, ctx, parent, *args, **kwargs) else: expr_type = self.expressions.get(node.type, default) - ret = expr_type(node, file_node_id, G, parent) + ret = expr_type(node, file_node_id, ctx, parent) if default == Value: ret.file._range_index.mark_as_canonical(ret) if isinstance(ret, Value): @@ -85,18 +85,18 @@ def log_unparsed(self, node: TSNode) -> None: self._uncovered_nodes.add(node.type) self.log(f"Encountered unimplemented node {node.type} with text {node.text.decode('utf-8')}") - def parse_type(self, node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: Parent) -> Type: + def parse_type(self, node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: Parent) -> Type: if node.type == self.type_node: - return self.parse_type(node.named_children[0], file_node_id, G, parent) + return self.parse_type(node.named_children[0], file_node_id, ctx, parent) if expr_type := self.types.get(node.type, None): expr_type, node = self._process_type(expr_type, node) - return expr_type(node, file_node_id, G, parent) + return expr_type(node, file_node_id, ctx, parent) self.log_unparsed(node) from codegen.sdk.core.expressions.placeholder_type import PlaceholderType - return PlaceholderType(node, file_node_id, G, parent) + return PlaceholderType(node, file_node_id, ctx, parent) - def parse_ts_statements(self, node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: TSCodeBlock) -> list[Statement]: + def parse_ts_statements(self, node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: TSCodeBlock) -> list[Statement]: from codegen.sdk.core.statements.export_statement import ExportStatement from codegen.sdk.core.statements.expression_statement import ExpressionStatement from codegen.sdk.core.statements.return_statement import ReturnStatement @@ -116,35 +116,35 @@ def parse_ts_statements(self, node: TSNode, file_node_id: NodeId, G: CodebaseGra statements = [] if node.type in self.expressions or node.type == "expression_statement": - return [ExpressionStatement(node, file_node_id, G, parent, 0, expression_node=node)] + return [ExpressionStatement(node, file_node_id, ctx, parent, 0, expression_node=node)] for child in node.named_children: # =====[ Functions + Methods ]===== if child.type in _VALID_TYPE_NAMES: - statements.append(SymbolStatement(child, file_node_id, G, parent, len(statements))) + statements.append(SymbolStatement(child, file_node_id, ctx, parent, len(statements))) # =====[ Classes ]===== elif child.type in ("class_declaration", "abstract_class_declaration"): - statements.append(SymbolStatement(child, file_node_id, G, parent, len(statements))) + statements.append(SymbolStatement(child, file_node_id, ctx, parent, len(statements))) # =====[ Interface Declarations ]===== elif child.type == "interface_declaration": - statements.append(SymbolStatement(child, file_node_id, G, parent, len(statements))) + statements.append(SymbolStatement(child, file_node_id, ctx, parent, len(statements))) # =====[ Type Alias Declarations ]===== elif child.type == "type_alias_declaration": - statements.append(SymbolStatement(child, file_node_id, G, parent, len(statements))) + statements.append(SymbolStatement(child, file_node_id, ctx, parent, len(statements))) # =====[ Enum Declarations ]===== elif child.type == "enum_declaration": - statements.append(SymbolStatement(child, file_node_id, G, parent, len(statements))) + statements.append(SymbolStatement(child, file_node_id, ctx, parent, len(statements))) # =====[ Exports ]===== elif child.type == "export_statement" or child.text.decode("utf-8") == "export *;": - statements.append(ExportStatement(child, file_node_id, G, parent, len(statements))) + statements.append(ExportStatement(child, file_node_id, ctx, parent, len(statements))) # =====[ Imports ] ===== elif child.type == "import_statement": - # statements.append(TSImportStatement(child, file_node_id, G, parent, len(statements))) + # statements.append(TSImportStatement(child, file_node_id, ctx, parent, len(statements))) pass # Temporarily opting to identify all imports using find_all_descendants # =====[ Non-symbol statements ] ===== @@ -163,28 +163,28 @@ def parse_ts_statements(self, node: TSNode, file_node_id: NodeId, G: CodebaseGra elif child.type == "switch_statement": statements.append(TSSwitchStatement.from_code_block(child, parent, pos=len(statements))) elif child.type == "labeled_statement": - statements.append(TSLabeledStatement(child, file_node_id, G, parent, len(statements))) + statements.append(TSLabeledStatement(child, file_node_id, ctx, parent, len(statements))) elif child.type in ["lexical_declaration", "variable_declaration"]: if function_node := find_first_function_descendant(child): - statements.append(SymbolStatement(child, file_node_id, G, parent, len(statements), function_node)) + statements.append(SymbolStatement(child, file_node_id, ctx, parent, len(statements), function_node)) else: statements.append( TSAssignmentStatement.from_assignment( - child, file_node_id, G, parent, pos=len(statements), assignment_node=next(var for var in child.named_children if var.type == "variable_declarator") + child, file_node_id, ctx, parent, pos=len(statements), assignment_node=next(var for var in child.named_children if var.type == "variable_declarator") ) ) elif child.type in ["public_field_definition", "property_signature", "enum_assignment"]: - statements.append(TSAttribute(child, file_node_id, G, parent, pos=len(statements))) + statements.append(TSAttribute(child, file_node_id, ctx, parent, pos=len(statements))) elif child.type == "expression_statement": for var in child.named_children: if var.type == "string": statements.append(TSComment.from_code_block(var, parent, pos=len(statements))) elif var.type in ["assignment_expression", "augmented_assignment_expression"]: - statements.append(TSAssignmentStatement.from_assignment(child, file_node_id, G, parent, pos=len(statements), assignment_node=var)) + statements.append(TSAssignmentStatement.from_assignment(child, file_node_id, ctx, parent, pos=len(statements), assignment_node=var)) else: - statements.append(ExpressionStatement(child, file_node_id, G, parent, pos=len(statements), expression_node=var)) + statements.append(ExpressionStatement(child, file_node_id, ctx, parent, pos=len(statements), expression_node=var)) elif child.type in self.expressions: - statements.append(ExpressionStatement(child, file_node_id, G, parent, len(statements), expression_node=child)) + statements.append(ExpressionStatement(child, file_node_id, ctx, parent, len(statements), expression_node=child)) else: self.log("Couldn't parse statement with type: %s", child.type) @@ -193,7 +193,7 @@ def parse_ts_statements(self, node: TSNode, file_node_id: NodeId, G: CodebaseGra return statements - def parse_py_statements(self, node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: PyCodeBlock) -> list[Statement]: + def parse_py_statements(self, node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: PyCodeBlock) -> list[Statement]: from codegen.sdk.core.statements.expression_statement import ExpressionStatement from codegen.sdk.core.statements.raise_statement import RaiseStatement from codegen.sdk.core.statements.return_statement import ReturnStatement @@ -225,19 +225,19 @@ def parse_py_statements(self, node: TSNode, file_node_id: NodeId, G: CodebaseGra for child in node.named_children: # =====[ Decorated definitions ]===== if child.type == "decorated_definition": - statements.append(SymbolStatement(child, file_node_id, G, parent, len(statements))) + statements.append(SymbolStatement(child, file_node_id, ctx, parent, len(statements))) # =====[ Functions ]===== elif child.type == "function_definition": - statements.append(SymbolStatement(child, file_node_id, G, parent, len(statements))) + statements.append(SymbolStatement(child, file_node_id, ctx, parent, len(statements))) # =====[ Classes ]===== elif child.type == "class_definition": - statements.append(SymbolStatement(child, file_node_id, G, parent, len(statements))) + statements.append(SymbolStatement(child, file_node_id, ctx, parent, len(statements))) # =====[ Imports ] ===== elif child.type in ["import_statement", "import_from_statement", "future_import_statement"]: - # statements.append(PyImportStatement(child, file_node_id, G, parent, len(statements))) + # statements.append(PyImportStatement(child, file_node_id, ctx, parent, len(statements))) pass # Temporarily opting to identify all imports using find_all_descendants # =====[ Non-symbol statements ] ===== @@ -271,11 +271,11 @@ def parse_py_statements(self, node: TSNode, file_node_id: NodeId, G: CodebaseGra from codegen.sdk.core.class_definition import Class if isinstance(parent.parent, Class): - statements.append(PyAttribute(child, file_node_id, G, parent, len(statements), var)) + statements.append(PyAttribute(child, file_node_id, ctx, parent, len(statements), var)) else: - statements.append(PyAssignmentStatement.from_assignment(child, file_node_id, G, parent, pos=len(statements), assignment_node=var)) + statements.append(PyAssignmentStatement.from_assignment(child, file_node_id, ctx, parent, pos=len(statements), assignment_node=var)) else: - statements.append(ExpressionStatement(child, file_node_id, G, parent, pos=len(statements), expression_node=var)) + statements.append(ExpressionStatement(child, file_node_id, ctx, parent, pos=len(statements), expression_node=var)) else: self.log("Couldn't parse statement with type: %s", node.type) statements.append(Statement.from_code_block(child, parent, pos=len(statements))) diff --git a/src/codegen/sdk/core/statements/assignment_statement.py b/src/codegen/sdk/core/statements/assignment_statement.py index 3beac4781..c6e6880eb 100644 --- a/src/codegen/sdk/core/statements/assignment_statement.py +++ b/src/codegen/sdk/core/statements/assignment_statement.py @@ -13,7 +13,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.assignment import Assignment from codegen.sdk.core.detached_symbols.code_block import CodeBlock from codegen.sdk.core.expressions import Expression @@ -47,15 +47,15 @@ class AssignmentStatement(Statement[TCodeBlock], HasValue, Generic[TCodeBlock, T left: Expression[TAssignment] right: Expression[TAssignment] | None - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: TCodeBlock, pos: int, assignment_node: TSNode) -> None: - super().__init__(ts_node, file_node_id, G, parent, pos=pos) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: TCodeBlock, pos: int, assignment_node: TSNode) -> None: + super().__init__(ts_node, file_node_id, ctx, parent, pos=pos) self.assignments = self._DEPRECATED_parse_assignments().expressions if len(self.assignments) == 0: msg = f"No assignments found: {self.ts_node}\n\n{self.source}" raise ValueError(msg) first_assignment: TAssignment = self.assignments[0] - self._name_node = self.G.parser.parse_expression(first_assignment.ts_node, self.file_node_id, self.G, parent, default=Name) + self._name_node = self.ctx.parser.parse_expression(first_assignment.ts_node, self.file_node_id, self.ctx, parent, default=Name) self.left = first_assignment.left self.right = first_assignment.value self._value_node = self.right diff --git a/src/codegen/sdk/core/statements/attribute.py b/src/codegen/sdk/core/statements/attribute.py index 9316fc672..1972f2398 100644 --- a/src/codegen/sdk/core/statements/attribute.py +++ b/src/codegen/sdk/core/statements/attribute.py @@ -17,7 +17,7 @@ from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.assignment import Assignment from codegen.sdk.core.detached_symbols.code_block import CodeBlock from codegen.sdk.core.interfaces.importable import Importable @@ -39,8 +39,8 @@ class Attribute(AssignmentStatement[TCodeBlock, TAssignment], Usable, Chainable, statement_type = StatementType.CLASS_ATTRIBUTE assignment: TAssignment - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: TCodeBlock, pos: int, assignment_node: TSNode) -> None: - super().__init__(ts_node, file_node_id, G, parent, pos=pos, assignment_node=assignment_node) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: TCodeBlock, pos: int, assignment_node: TSNode) -> None: + super().__init__(ts_node, file_node_id, ctx, parent, pos=pos, assignment_node=assignment_node) self.assignment = self.assignments[0] self._name_node = self.assignment.get_name() diff --git a/src/codegen/sdk/core/statements/block_statement.py b/src/codegen/sdk/core/statements/block_statement.py index 07eb02855..2ca003c72 100644 --- a/src/codegen/sdk/core/statements/block_statement.py +++ b/src/codegen/sdk/core/statements/block_statement.py @@ -11,7 +11,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.dataclasses.usage import UsageKind from codegen.sdk.core.detached_symbols.code_block import CodeBlock from codegen.sdk.core.detached_symbols.function_call import FunctionCall @@ -33,8 +33,8 @@ class BlockStatement(Statement[TCodeBlock], HasBlock, ABC, Generic[TCodeBlock]): code_block: TCodeBlock | None - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: TCodeBlock, pos: int | None = None) -> None: - super().__init__(ts_node, file_node_id, G, parent, pos) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: TCodeBlock, pos: int | None = None) -> None: + super().__init__(ts_node, file_node_id, ctx, parent, pos) self.code_block = self._parse_code_block() if self.code_block: self.code_block.parse() diff --git a/src/codegen/sdk/core/statements/comment.py b/src/codegen/sdk/core/statements/comment.py index 46c5f8c15..9bc84b1ca 100644 --- a/src/codegen/sdk/core/statements/comment.py +++ b/src/codegen/sdk/core/statements/comment.py @@ -10,7 +10,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.detached_symbols.code_block import CodeBlock from codegen.sdk.core.interfaces.has_name import HasName from codegen.sdk.core.node_id_factory import NodeId @@ -63,8 +63,8 @@ def nested_code_blocks(self: Statement[TCodeBlock]) -> list[TCodeBlock]: @noapidoc @classmethod @reader - def from_expression_statement(cls, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: Statement, code_block: TCodeBlock, pos: int, comment_node: TSNode) -> Comment: - return cls(ts_node, file_node_id, G, code_block, pos) + def from_expression_statement(cls, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: Statement, code_block: TCodeBlock, pos: int, comment_node: TSNode) -> Comment: + return cls(ts_node, file_node_id, ctx, code_block, pos) @property @reader diff --git a/src/codegen/sdk/core/statements/export_statement.py b/src/codegen/sdk/core/statements/export_statement.py index 67d4fbbb3..c8a8d10df 100644 --- a/src/codegen/sdk/core/statements/export_statement.py +++ b/src/codegen/sdk/core/statements/export_statement.py @@ -14,7 +14,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.export import Export from codegen.sdk.core.interfaces.has_name import HasName from codegen.sdk.core.node_id_factory import NodeId @@ -35,28 +35,28 @@ class ExportStatement(Statement["TSCodeBlock"], Generic[TExport]): exports: Collection[TExport, Self] statement_type = StatementType.EXPORT_STATEMENT - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: TSCodeBlock, pos: int): - super().__init__(ts_node, parent.file_node_id, parent.G, parent, pos) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: TSCodeBlock, pos: int): + super().__init__(ts_node, parent.file_node_id, parent.ctx, parent, pos) export_node = self.ts_node if node := self.child_by_field_types(["export_clause", "export_statement"]): export_node = node.ts_node - self.exports = Collection(export_node, self.file_node_id, self.G, self, bracket_size=2) + self.exports = Collection(export_node, self.file_node_id, self.ctx, self, bracket_size=2) if declaration := ts_node.child_by_field_name("declaration"): - exports = TSExport.from_export_statement_with_declaration(ts_node, declaration, file_node_id, G, self, pos) + exports = TSExport.from_export_statement_with_declaration(ts_node, declaration, file_node_id, ctx, self, pos) elif value := ts_node.child_by_field_name("value"): - exports = TSExport.from_export_statement_with_value(self.ts_node, value, self.file_node_id, self.G, self, self.index) + exports = TSExport.from_export_statement_with_value(self.ts_node, value, self.file_node_id, self.ctx, self, self.index) else: exports = [] if source_node := ts_node.child_by_field_name("source"): # ==== [ Re-export ] ==== # e.g. export { name1, name2 } from './other-module'; - import_statement = TSImportStatement(ts_node, file_node_id, G, parent, pos, source_node=source_node) + import_statement = TSImportStatement(ts_node, file_node_id, ctx, parent, pos, source_node=source_node) for imp in import_statement.imports: name_node = imp.alias.ts_node if imp.alias else None export = TSExport( ts_node=find_first_ancestor(imp._name_node.ts_node, ["export_statement", "export_clause", "export_specifier"]) if imp._name_node else imp.ts_node, file_node_id=file_node_id, - G=G, + ctx=ctx, name_node=name_node, declared_symbol=imp, parent=self.exports, @@ -71,13 +71,13 @@ def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, pare continue name_node = export_specifier.child_by_field_name("name") alias_node = export_specifier.child_by_field_name("alias") or name_node - export = TSExport(ts_node=export_specifier, file_node_id=file_node_id, G=G, name_node=alias_node, exported_symbol=name_node, parent=self.exports) + export = TSExport(ts_node=export_specifier, file_node_id=file_node_id, ctx=ctx, name_node=alias_node, exported_symbol=name_node, parent=self.exports) exports.append(export) else: # ==== [ Export assignment ] ==== # Examples: `export = XYZ;`, `export = function foo() {}`, `export = function() {}`, `export = { f1, f2 }` # No other named exports can exist alongside this type of export in the file - exports.extend(TSExport.from_export_statement_with_value(self.ts_node, ts_node.named_children[0], self.file_node_id, self.G, self, self.index)) + exports.extend(TSExport.from_export_statement_with_value(self.ts_node, ts_node.named_children[0], self.file_node_id, self.ctx, self, self.index)) self.exports._init_children(exports) for exp in self.exports: exp.export_statement = self diff --git a/src/codegen/sdk/core/statements/expression_statement.py b/src/codegen/sdk/core/statements/expression_statement.py index 142fdf1f7..6aeda5f99 100644 --- a/src/codegen/sdk/core/statements/expression_statement.py +++ b/src/codegen/sdk/core/statements/expression_statement.py @@ -11,7 +11,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.dataclasses.usage import UsageKind from codegen.sdk.core.detached_symbols.code_block import CodeBlock from codegen.sdk.core.detached_symbols.function_call import FunctionCall @@ -45,8 +45,8 @@ class ExpressionStatement(Statement, HasValue, IWrapper, Generic[Parent, TCodeBl statement_type = StatementType.EXPRESSION_STATEMENT - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: Parent, pos: int, expression_node: TSNode) -> None: - super().__init__(ts_node, file_node_id, G, parent, pos=pos) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: Parent, pos: int, expression_node: TSNode) -> None: + super().__init__(ts_node, file_node_id, ctx, parent, pos=pos) self._value_node = self._parse_expression(expression_node) @property diff --git a/src/codegen/sdk/core/statements/import_statement.py b/src/codegen/sdk/core/statements/import_statement.py index c1a18bf8f..2a67ee06a 100644 --- a/src/codegen/sdk/core/statements/import_statement.py +++ b/src/codegen/sdk/core/statements/import_statement.py @@ -10,7 +10,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.detached_symbols.code_block import CodeBlock from codegen.sdk.core.file import SourceFile from codegen.sdk.core.import_resolution import Import @@ -35,8 +35,8 @@ class ImportStatement(Statement[TCodeBlock], Generic[TSourceFile, TImport, TCode imports: Collection[TImport, Self] - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: TCodeBlock, pos: int) -> None: - super().__init__(ts_node, file_node_id, G, parent, pos) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: TCodeBlock, pos: int) -> None: + super().__init__(ts_node, file_node_id, ctx, parent, pos) @noapidoc @commiter diff --git a/src/codegen/sdk/core/statements/raise_statement.py b/src/codegen/sdk/core/statements/raise_statement.py index c0c5146e4..ec267f88b 100644 --- a/src/codegen/sdk/core/statements/raise_statement.py +++ b/src/codegen/sdk/core/statements/raise_statement.py @@ -10,7 +10,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.dataclasses.usage import UsageKind from codegen.sdk.core.detached_symbols.code_block import CodeBlock from codegen.sdk.core.detached_symbols.function_call import FunctionCall @@ -32,8 +32,8 @@ def f(x): statement_type = StatementType.RAISE_STATEMENT - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: Parent, pos: int | None = None) -> None: - super().__init__(ts_node, file_node_id, G, parent, pos) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: Parent, pos: int | None = None) -> None: + super().__init__(ts_node, file_node_id, ctx, parent, pos) value_node = self._get_value_node() self._value_node = self._parse_expression(value_node) if value_node else None diff --git a/src/codegen/sdk/core/statements/return_statement.py b/src/codegen/sdk/core/statements/return_statement.py index 368c5e720..d71c95134 100644 --- a/src/codegen/sdk/core/statements/return_statement.py +++ b/src/codegen/sdk/core/statements/return_statement.py @@ -10,7 +10,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.dataclasses.usage import UsageKind from codegen.sdk.core.detached_symbols.code_block import CodeBlock from codegen.sdk.core.detached_symbols.function_call import FunctionCall @@ -37,8 +37,8 @@ def f(x): statement_type = StatementType.RETURN_STATEMENT - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: Parent, pos: int | None = None) -> None: - super().__init__(ts_node, file_node_id, G, parent, pos) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: Parent, pos: int | None = None) -> None: + super().__init__(ts_node, file_node_id, ctx, parent, pos) value_node = self._get_value_node() self._value_node = self._parse_expression(value_node) if value_node else None diff --git a/src/codegen/sdk/core/statements/statement.py b/src/codegen/sdk/core/statements/statement.py index 88c5c807b..75fb4f569 100644 --- a/src/codegen/sdk/core/statements/statement.py +++ b/src/codegen/sdk/core/statements/statement.py @@ -15,7 +15,7 @@ import rich.repr from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.dataclasses.usage import UsageKind from codegen.sdk.core.detached_symbols.code_block import CodeBlock from codegen.sdk.core.interfaces.has_name import HasName @@ -81,8 +81,8 @@ class Statement(Expression[Parent], Generic[Parent]): statement_type: StatementType = StatementType.UNSPECIFIED _pos: int - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: Parent, pos: int | None = None) -> None: - super().__init__(ts_node, file_node_id, G, parent) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: Parent, pos: int | None = None) -> None: + super().__init__(ts_node, file_node_id, ctx, parent) self._pos = pos def __rich_repr__(self) -> rich.repr.Result: @@ -107,7 +107,7 @@ def index(self) -> int: @noapidoc @final def from_code_block(cls, ts_node: TSNode, code_block: CodeBlock, pos: int | None = None) -> Statement: - return cls(ts_node, code_block.file_node_id, code_block.G, parent=code_block, pos=pos) + return cls(ts_node, code_block.file_node_id, code_block.ctx, parent=code_block, pos=pos) @cached_property @reader @@ -123,7 +123,7 @@ def nested_code_blocks(self) -> list[Parent]: nested_blocks = [] for block_node in block_nodes: - block = self.G.node_classes.code_block_cls(block_node, self.parent.level + 1, self.parent, self) + block = self.ctx.node_classes.code_block_cls(block_node, self.parent.level + 1, self.parent, self) block.parse() nested_blocks.append(block) return nested_blocks diff --git a/src/codegen/sdk/core/statements/symbol_statement.py b/src/codegen/sdk/core/statements/symbol_statement.py index 22981a2ef..76064fe4f 100644 --- a/src/codegen/sdk/core/statements/symbol_statement.py +++ b/src/codegen/sdk/core/statements/symbol_statement.py @@ -9,7 +9,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.dataclasses.usage import UsageKind from codegen.sdk.core.detached_symbols.code_block import CodeBlock from codegen.sdk.core.detached_symbols.function_call import FunctionCall @@ -37,9 +37,9 @@ class SymbolStatement(Statement[Parent], Generic[Parent, Child]): statement_type = StatementType.SYMBOL_STATEMENT symbol: Child - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: Parent, pos: int, symbol_node: TSNode | None = None) -> None: - super().__init__(ts_node, file_node_id, G, parent, pos) - self.symbol = self.G.parser.parse_expression(symbol_node or ts_node, file_node_id, G, parent=self) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: Parent, pos: int, symbol_node: TSNode | None = None) -> None: + super().__init__(ts_node, file_node_id, ctx, parent, pos) + self.symbol = self.ctx.parser.parse_expression(symbol_node or ts_node, file_node_id, ctx, parent=self) def _compute_dependencies(self, usage_type: UsageKind, dest: HasName | None = None) -> None: pass diff --git a/src/codegen/sdk/core/statements/while_statement.py b/src/codegen/sdk/core/statements/while_statement.py index 033d7c7f2..b203ad4cb 100644 --- a/src/codegen/sdk/core/statements/while_statement.py +++ b/src/codegen/sdk/core/statements/while_statement.py @@ -11,7 +11,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.dataclasses.usage import UsageKind from codegen.sdk.core.detached_symbols.code_block import CodeBlock from codegen.sdk.core.detached_symbols.function_call import FunctionCall @@ -37,8 +37,8 @@ class WhileStatement(Statement[TCodeBlock], HasBlock, ABC, Generic[TCodeBlock]): condition: Expression[Self] code_block: TCodeBlock - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: TCodeBlock, pos: int | None = None) -> None: - super().__init__(ts_node, file_node_id, G, parent, pos) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: TCodeBlock, pos: int | None = None) -> None: + super().__init__(ts_node, file_node_id, ctx, parent, pos) self.code_block = self._parse_code_block() self.code_block.parse() diff --git a/src/codegen/sdk/core/symbol.py b/src/codegen/sdk/core/symbol.py index 24b6afd77..559a5cd58 100644 --- a/src/codegen/sdk/core/symbol.py +++ b/src/codegen/sdk/core/symbol.py @@ -23,7 +23,7 @@ import rich.repr from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.detached_symbols.code_block import CodeBlock from codegen.sdk.core.export import Export from codegen.sdk.core.file import SourceFile @@ -54,19 +54,19 @@ def __init__( self, ts_node: TSNode, file_id: NodeId, - G: CodebaseGraph, + ctx: CodebaseContext, parent: Statement[CodeBlock[Parent, ...]], name_node: TSNode | None = None, name_node_type: type[Name] = DefinedName, ) -> None: - super().__init__(ts_node, file_id, G, parent) + super().__init__(ts_node, file_id, ctx, parent) name_node = self._get_name_node(ts_node) if name_node is None else name_node self._name_node = self._parse_expression(name_node, default=name_node_type) from codegen.sdk.core.interfaces.has_block import HasBlock if isinstance(self, HasBlock): self.code_block = self._parse_code_block() - self.parse(G) + self.parse(ctx) if isinstance(self, HasBlock): self.code_block.parse() @@ -117,7 +117,7 @@ def extended_nodes(self) -> list[Editable]: if isinstance(self, HasBlock) and self.is_decorated: new_ts_node = self.ts_node.parent - extended_nodes = [(Value(new_ts_node, self.file_node_id, self.G, self.parent) if node.ts_node == self.ts_node else node) for node in nodes] + extended_nodes = [(Value(new_ts_node, self.file_node_id, self.ctx, self.parent) if node.ts_node == self.ts_node else node) for node in nodes] return sort_editables(extended_nodes) @writer @@ -233,7 +233,7 @@ def set_inline_comment(self, comment: str) -> None: @noapidoc @commiter - def parse(self, G: CodebaseGraph) -> None: + def parse(self, ctx: CodebaseContext) -> None: """Adds itself as a symbol node in the graph, and an edge from the parent file to itself.""" #################################################################################################################### @@ -418,11 +418,11 @@ def add_keyword(self, keyword: str) -> None: Raises: AssertionError: If the provided keyword is not in the language's valid keywords list. """ - assert keyword in self.G.node_classes.keywords + assert keyword in self.ctx.node_classes.keywords to_insert_onto = None - to_insert_idx = self.G.node_classes.keywords.index(keyword) - for node in self.children_by_field_types(self.G.node_classes.keywords): - idx = self.G.node_classes.keywords.index(node) + to_insert_idx = self.ctx.node_classes.keywords.index(keyword) + for node in self.children_by_field_types(self.ctx.node_classes.keywords): + idx = self.ctx.node_classes.keywords.index(node) if node == keyword: return if idx < to_insert_idx: diff --git a/src/codegen/sdk/core/symbol_group.py b/src/codegen/sdk/core/symbol_group.py index 6f548cd60..4d72b1d9f 100644 --- a/src/codegen/sdk/core/symbol_group.py +++ b/src/codegen/sdk/core/symbol_group.py @@ -11,7 +11,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.dataclasses.usage import UsageKind from codegen.sdk.core.interfaces.has_name import HasName from codegen.sdk.core.node_id_factory import NodeId @@ -30,12 +30,12 @@ class SymbolGroup(Editable[Parent], Collection[Child], Generic[Child, Parent]): _symbols: list[Child] - def __init__(self, file_node_id: NodeId, G: CodebaseGraph, parent: Parent, node: TSNode | None = None, children: list[Child] | None = None) -> None: + def __init__(self, file_node_id: NodeId, ctx: CodebaseContext, parent: Parent, node: TSNode | None = None, children: list[Child] | None = None) -> None: self._symbols = children if node is None: # For backwards compatibility, assure that the first node is the main node node = children[0].ts_node - super().__init__(node, file_node_id, G, parent) + super().__init__(node, file_node_id, ctx, parent) def __repr__(self) -> str: return f"Collection({self.symbols})" if self.symbols is not None else super().__repr__() diff --git a/src/codegen/sdk/core/symbol_groups/collection.py b/src/codegen/sdk/core/symbol_groups/collection.py index 08e210b7b..d9b962701 100644 --- a/src/codegen/sdk/core/symbol_groups/collection.py +++ b/src/codegen/sdk/core/symbol_groups/collection.py @@ -12,7 +12,7 @@ from codegen.shared.decorators.docs import noapidoc if TYPE_CHECKING: - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext Child = TypeVar("Child", bound="Editable") @@ -36,8 +36,8 @@ class Collection(SymbolGroup[Child, Parent], MutableSequence[Child], Generic[Chi _container_start_byte: int _container_end_byte: int - def __init__(self, node: TSNode, file_node_id: NodeId, G: "CodebaseGraph", parent: Parent, delimiter: str = ",", children: list[Child] | None = None, *, bracket_size: int = 1) -> None: - super().__init__(file_node_id, G, parent, node) + def __init__(self, node: TSNode, file_node_id: NodeId, ctx: "CodebaseContext", parent: Parent, delimiter: str = ",", children: list[Child] | None = None, *, bracket_size: int = 1) -> None: + super().__init__(file_node_id, ctx, parent, node) self._delimiter = delimiter self._reversed = set() self._inserts = defaultdict(lambda: 0) diff --git a/src/codegen/sdk/core/symbol_groups/comment_group.py b/src/codegen/sdk/core/symbol_groups/comment_group.py index 8e36eaa81..a6c64931e 100644 --- a/src/codegen/sdk/core/symbol_groups/comment_group.py +++ b/src/codegen/sdk/core/symbol_groups/comment_group.py @@ -8,7 +8,7 @@ from codegen.shared.decorators.docs import apidoc, noapidoc if TYPE_CHECKING: - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.node_id_factory import NodeId Parent = TypeVar("Parent") @@ -20,9 +20,9 @@ class CommentGroup(SymbolGroup[Comment, Parent]): _indentation: int # Indentation level of the comment block - def __init__(self, children: list[Comment], file_node_id: NodeId, G: CodebaseGraph, parent: Parent) -> None: + def __init__(self, children: list[Comment], file_node_id: NodeId, ctx: CodebaseContext, parent: Parent) -> None: assert len(children) > 0, "CommentGroup must have at least one symbol" - super().__init__(file_node_id, G, parent, node=children[0].ts_node, children=children) + super().__init__(file_node_id, ctx, parent, node=children[0].ts_node, children=children) self._indentation = self._calculate_indentation() @property diff --git a/src/codegen/sdk/core/symbol_groups/dict.py b/src/codegen/sdk/core/symbol_groups/dict.py index 26365d948..20bc3b984 100644 --- a/src/codegen/sdk/core/symbol_groups/dict.py +++ b/src/codegen/sdk/core/symbol_groups/dict.py @@ -17,7 +17,7 @@ from codegen.shared.decorators.docs import apidoc, noapidoc if TYPE_CHECKING: - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.interfaces.importable import Importable @@ -35,8 +35,8 @@ class Pair(Editable[Parent], HasValue, Generic[TExpression, Parent]): key: TExpression - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: "CodebaseGraph", parent: Parent) -> None: - super().__init__(ts_node, file_node_id, G, parent) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: "CodebaseContext", parent: Parent) -> None: + super().__init__(ts_node, file_node_id, ctx, parent) self.key, self._value_node = self._get_key_value() if self.key is None: self._log_parse(f"{self} {self.ts_node} in {self.filepath} has no key") @@ -88,10 +88,10 @@ class Dict(Expression[Parent], Builtin, MutableMapping[str, TExpression], Generi _underlying: Collection[Pair[TExpression, Self] | Unpack[Self], Parent] unpack: Unpack[Self] | None = None - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: "CodebaseGraph", parent: Parent, delimiter: str = ",", pair_type: type[Pair] = Pair) -> None: + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: "CodebaseContext", parent: Parent, delimiter: str = ",", pair_type: type[Pair] = Pair) -> None: # TODO: handle spread_element - super().__init__(ts_node, file_node_id, G, parent) - children = [pair_type(child, file_node_id, G, self) for child in ts_node.named_children if child.type not in (None, "comment", "spread_element", "dictionary_splat") and not child.is_error] + super().__init__(ts_node, file_node_id, ctx, parent) + children = [pair_type(child, file_node_id, ctx, self) for child in ts_node.named_children if child.type not in (None, "comment", "spread_element", "dictionary_splat") and not child.is_error] if unpack := self.child_by_field_types({"spread_element", "dictionary_splat"}): children.append(unpack) self.unpack = unpack @@ -99,7 +99,7 @@ def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: "CodebaseGraph", pa first_child = children[0].ts_node.end_byte - ts_node.start_byte second_child = children[1].ts_node.start_byte - ts_node.start_byte delimiter = ts_node.text[first_child:second_child].decode("utf-8").rstrip() - self._underlying = Collection(ts_node, file_node_id, G, parent, delimiter=delimiter, children=children) + self._underlying = Collection(ts_node, file_node_id, ctx, parent, delimiter=delimiter, children=children) def __bool__(self) -> bool: return True @@ -133,7 +133,7 @@ def __setitem__(self, __key, __value: TExpression) -> None: if value := self.get(__key, None): value.edit(new_value) else: - if not self.G.node_classes.int_dict_key: + if not self.ctx.node_classes.int_dict_key: try: int(__key) __key = f"'{__key}'" diff --git a/src/codegen/sdk/core/symbol_groups/list.py b/src/codegen/sdk/core/symbol_groups/list.py index 06fce41bf..81099db28 100644 --- a/src/codegen/sdk/core/symbol_groups/list.py +++ b/src/codegen/sdk/core/symbol_groups/list.py @@ -10,7 +10,7 @@ from codegen.shared.decorators.docs import apidoc if TYPE_CHECKING: - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext Parent = TypeVar("Parent", bound=Editable) @@ -21,8 +21,8 @@ class List(Collection["Expression[Self, None]", Parent], Expression[Parent], Bui You can use standard operations to operate on this list (IE len, del, append, insert, etc) """ - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: "CodebaseGraph", parent: Parent) -> None: - super().__init__(ts_node, file_node_id, G, parent) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: "CodebaseContext", parent: Parent) -> None: + super().__init__(ts_node, file_node_id, ctx, parent) self._init_children([self._parse_expression(child) for child in ts_node.named_children if child.type]) @property diff --git a/src/codegen/sdk/core/symbol_groups/multi_line_collection.py b/src/codegen/sdk/core/symbol_groups/multi_line_collection.py index bdc176042..cfbbb63b9 100644 --- a/src/codegen/sdk/core/symbol_groups/multi_line_collection.py +++ b/src/codegen/sdk/core/symbol_groups/multi_line_collection.py @@ -10,7 +10,7 @@ from codegen.shared.decorators.docs import apidoc, noapidoc if TYPE_CHECKING: - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext Child = TypeVar("Child", bound=Editable) @@ -33,7 +33,7 @@ def __init__( self, children: list[Child], file_node_id: NodeId, - G: "CodebaseGraph", + ctx: "CodebaseContext", parent: Parent, node: TSNode, indent_size: int, @@ -42,7 +42,7 @@ def __init__( start_byte: int | None = None, end_byte: int | None = None, ) -> None: - super().__init__(node, file_node_id, G, parent, trailing_delimiter, children=children, bracket_size=0) + super().__init__(node, file_node_id, ctx, parent, trailing_delimiter, children=children, bracket_size=0) self._inserts_max_size = defaultdict(lambda: 0) self._leading_delimiter = leading_delimiter self._trailing_delimiter = trailing_delimiter diff --git a/src/codegen/sdk/core/symbol_groups/parents.py b/src/codegen/sdk/core/symbol_groups/parents.py index f302b3a73..a0857d045 100644 --- a/src/codegen/sdk/core/symbol_groups/parents.py +++ b/src/codegen/sdk/core/symbol_groups/parents.py @@ -13,7 +13,7 @@ from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.codebase.resolution_stack import ResolutionStack from codegen.sdk.core.expressions.chained_attribute import ChainedAttribute from codegen.sdk.core.expressions.name import Name @@ -29,8 +29,8 @@ class Parents(Collection["TType", Parent], Generic[TType, Parent]): type_arguments: list[Type] - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: Parent) -> None: - super().__init__(ts_node, file_node_id, G, parent) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: Parent) -> None: + super().__init__(ts_node, file_node_id, ctx, parent) self._init_children([self._parse_type(child) for child in ts_node.named_children if child.type != "type_arguments"]) self.type_arguments = [self._parse_type(child) for child in ts_node.children if child.type == "type_arguments"] @@ -42,8 +42,8 @@ def compute_superclass_dependencies(self) -> None: dest = self.parent for superclass in self: resolution: list[ResolutionStack] = superclass.resolved_types - if len(resolution) == 1 and self.G.has_node(getattr(resolution[0], "node_id", None)): - self.G.add_edge(dest.node_id, resolution[0].node_id, type=EdgeType.SUBCLASS) + if len(resolution) == 1 and self.ctx.has_node(getattr(resolution[0], "node_id", None)): + self.ctx.add_edge(dest.node_id, resolution[0].node_id, type=EdgeType.SUBCLASS) else: self._log_parse("%r is ambiguous with possibilities: %r.", superclass, resolution) self.parent.__dict__.pop("superclasses", None) diff --git a/src/codegen/sdk/core/symbol_groups/tuple.py b/src/codegen/sdk/core/symbol_groups/tuple.py index 525d5bba2..47ecb18e2 100644 --- a/src/codegen/sdk/core/symbol_groups/tuple.py +++ b/src/codegen/sdk/core/symbol_groups/tuple.py @@ -10,7 +10,7 @@ from codegen.shared.decorators.docs import apidoc if TYPE_CHECKING: - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext Parent = TypeVar("Parent", bound=Editable) @@ -21,8 +21,8 @@ class Tuple(Collection["Expression[Self, None]", Parent], Expression[Parent], Bu You can use standard operations to operate on this list (IE len, del, append, insert, etc) """ - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: "CodebaseGraph", parent: Parent) -> None: - super().__init__(ts_node, file_node_id, G, parent) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: "CodebaseContext", parent: Parent) -> None: + super().__init__(ts_node, file_node_id, ctx, parent) self._init_children([self._parse_expression(child) for child in ts_node.named_children if child.type]) @property diff --git a/src/codegen/sdk/core/symbol_groups/type_parameters.py b/src/codegen/sdk/core/symbol_groups/type_parameters.py index 1061658ac..aa83615c5 100644 --- a/src/codegen/sdk/core/symbol_groups/type_parameters.py +++ b/src/codegen/sdk/core/symbol_groups/type_parameters.py @@ -7,7 +7,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.expressions.type import Type from codegen.sdk.core.interfaces.supports_generic import SupportsGenerics from codegen.sdk.core.node_id_factory import NodeId @@ -18,6 +18,6 @@ class TypeParameters(Collection["TType", Parent], Generic[TType, Parent]): - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: Parent) -> None: - super().__init__(ts_node, file_node_id, G, parent) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: Parent) -> None: + super().__init__(ts_node, file_node_id, ctx, parent) self._init_children([self._parse_type(child) for child in ts_node.named_children]) diff --git a/src/codegen/sdk/core/type_alias.py b/src/codegen/sdk/core/type_alias.py index 5d162cb04..17171155c 100644 --- a/src/codegen/sdk/core/type_alias.py +++ b/src/codegen/sdk/core/type_alias.py @@ -14,7 +14,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.detached_symbols.code_block import CodeBlock from codegen.sdk.core.interfaces.importable import Importable from codegen.sdk.core.node_id_factory import NodeId @@ -45,10 +45,10 @@ def __init__( self, ts_node: TSNode, file_node_id: NodeId, - G: CodebaseGraph, + ctx: CodebaseContext, parent: Statement[CodeBlock[Parent, ...]], ) -> None: - super().__init__(ts_node, file_node_id, G, parent) + super().__init__(ts_node, file_node_id, ctx, parent) value_node = self.ts_node.child_by_field_name("value") self._value_node = self._parse_type(value_node) if value_node else None self.type_parameters = self.child_by_field_name("type_parameters") diff --git a/src/codegen/sdk/extensions/autocommit.pyi b/src/codegen/sdk/extensions/autocommit.pyi index fea4fad06..51f4ebd81 100644 --- a/src/codegen/sdk/extensions/autocommit.pyi +++ b/src/codegen/sdk/extensions/autocommit.pyi @@ -1,7 +1,7 @@ from collections.abc import Callable from typing import Any, ParamSpec, TypeVar, overload -from codegen.sdk.codebase.codebase_graph import CodebaseGraph +from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.interfaces.editable import Editable P = ParamSpec("P") @@ -18,7 +18,7 @@ class AutoCommitMixin: autocommit_cache: dict[str, Any] removed: bool - def __init__(self, G: CodebaseGraph) -> None: ... + def __init__(self, ctx: CodebaseContext) -> None: ... def update_generation(self, generation: int | None = None) -> None: ... @property def is_outdated(self) -> bool: ... diff --git a/src/codegen/sdk/extensions/autocommit.pyx b/src/codegen/sdk/extensions/autocommit.pyx index cde308e15..d9d2b69eb 100644 --- a/src/codegen/sdk/extensions/autocommit.pyx +++ b/src/codegen/sdk/extensions/autocommit.pyx @@ -47,7 +47,7 @@ def reader(wrapped: Callable[P, T] | None = None, *, cache: bool | None = None) instance = args[0] num_args -= 1 name = wrapped.__name__ - autocommit = instance.G._autocommit + autocommit = instance.ctx._autocommit should_cache = cache def run_func(): @@ -92,8 +92,8 @@ class AutoCommitMixin: autocommit_cache: dict[str, Any] removed: bool = False - def __init__(self, G: "CodebaseGraph"): - self._generation = G.generation + def __init__(self, codebase_context: "CodebaseContext"): + self._generation = codebase_context.generation self.autocommit_cache = {} def update_generation(self: "Editable", generation: int | None = None) -> None: @@ -196,15 +196,15 @@ def commiter(wrapped: Callable[P, T] | None = None, *, reset: bool = False) -> C return functools.partial(commiter, reset=reset) @wrapt.decorator(enabled=enabled) - def wrapper(wrapped: Callable[P, T], instance: Union["Editable", "CodebaseGraph", None] = None, args: P.args = None, kwargs: P.kwargs = None) -> T: + def wrapper(wrapped: Callable[P, T], instance: Union["Editable", "CodebaseContext", None] = None, args: P.args = None, kwargs: P.kwargs = None) -> T: if instance is None: instance = args[0] - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext - if isinstance(instance, CodebaseGraph): + if isinstance(instance, CodebaseContext): autocommit = instance._autocommit else: - autocommit = instance.G._autocommit + autocommit = instance.ctx._autocommit old_state = autocommit.enter_state(AutoCommitState.Committing) try: ret = wrapped(*args, **kwargs) diff --git a/src/codegen/sdk/extensions/resolution.pyi b/src/codegen/sdk/extensions/resolution.pyi index e0f0c8324..9a8cb07d9 100644 --- a/src/codegen/sdk/extensions/resolution.pyi +++ b/src/codegen/sdk/extensions/resolution.pyi @@ -4,7 +4,7 @@ from typing import Generic from typing_extensions import TypeVar -from codegen.sdk.codebase.codebase_graph import CodebaseGraph +from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.dataclasses.usage import UsageKind, UsageType from codegen.sdk.core.interfaces.editable import Editable from codegen.sdk.core.interfaces.has_name import HasName @@ -36,7 +36,7 @@ class ResolutionStack(Generic[NodeType]): ... def usage_type(self, direct: bool, aliased: bool) -> UsageType: ... - def add_usage(self, match: Editable, usage_type: UsageKind, dest: HasName, G: CodebaseGraph, *, direct: bool = True, aliased: bool = False, chained: bool = False) -> None: + def add_usage(self, match: Editable, usage_type: UsageKind, dest: HasName, codebase_context: CodebaseContext, *, direct: bool = True, aliased: bool = False, chained: bool = False) -> None: """Add the resolved type to the graph. Also adds any intermediate nodes as usages as well if they are on the graph.""" @cached_property diff --git a/src/codegen/sdk/extensions/resolution.pyx b/src/codegen/sdk/extensions/resolution.pyx index 47643172a..4e8d8bebf 100644 --- a/src/codegen/sdk/extensions/resolution.pyx +++ b/src/codegen/sdk/extensions/resolution.pyx @@ -57,7 +57,7 @@ class ResolutionStack(Generic[NodeType]): match: "Editable", usage_type: UsageKind, dest: "HasName", - G: "CodebaseGraph", + codebase_context: "CodebaseContext", *, direct: bool = True, aliased: bool = False, @@ -67,7 +67,7 @@ class ResolutionStack(Generic[NodeType]): """Get usage edges for a given node.""" # Only add nodes that are already on the graph edge_usage_type = self.usage_type(direct, aliased, chained) - if hasattr(self.node, "node_id") and G.has_node(getattr(self.node, "node_id")): + if hasattr(self.node, "node_id") and codebase_context.has_node(getattr(self.node, "node_id")): usage = Usage(kind=usage_type, match=match, usage_type=edge_usage_type, usage_symbol=dest.parent_symbol, imported_by=imported_by) yield dest.node_id, self.node.node_id, Edge(type=EdgeType.SYMBOL_USAGE, usage=usage) if self.parent_frame is not None: @@ -78,12 +78,12 @@ class ResolutionStack(Generic[NodeType]): aliased = self.aliased or aliased direct = self.direct and direct chained = self.chained or (chained and self.direct) - yield from self.parent_frame.get_edges(match, usage_type, dest, G, direct=direct, aliased=aliased, chained=chained, imported_by=imported_by) + yield from self.parent_frame.get_edges(match, usage_type, dest, codebase_context, direct=direct, aliased=aliased, chained=chained, imported_by=imported_by) - def add_usage(self, match: "Editable", usage_type: UsageKind, dest: "HasName", G: "CodebaseGraph", *, direct: bool = True, aliased: bool = False, chained: bool = False) -> None: + def add_usage(self, match: "Editable", usage_type: UsageKind, dest: "HasName", codebase_context: "CodebaseContext", *, direct: bool = True, aliased: bool = False, chained: bool = False) -> None: """Add the resolved type to the graph. Also adds any intermediate nodes as usages as well if they are on the graph.""" # Only add nodes that are already on the graph - G.add_edges(list(self.get_edges(match, usage_type, dest, G, direct=direct, aliased=aliased, chained=chained))) + codebase_context.add_edges(list(self.get_edges(match, usage_type, dest, codebase_context, direct=direct, aliased=aliased, chained=chained))) @cached_property def top(self) -> ResolutionStack: diff --git a/src/codegen/sdk/python/assignment.py b/src/codegen/sdk/python/assignment.py index 9dfa593e4..f295f741c 100644 --- a/src/codegen/sdk/python/assignment.py +++ b/src/codegen/sdk/python/assignment.py @@ -12,7 +12,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.node_id_factory import NodeId from codegen.sdk.python.statements.assignment_statement import PyAssignmentStatement @@ -26,18 +26,18 @@ class PyAssignment(Assignment["PyAssignmentStatement"], PySymbol): @noapidoc @classmethod - def from_assignment(cls, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: PyAssignmentStatement) -> MultiExpression[PyAssignmentStatement, PyAssignment]: + def from_assignment(cls, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: PyAssignmentStatement) -> MultiExpression[PyAssignmentStatement, PyAssignment]: if ts_node.type not in ["assignment", "augmented_assignment"]: msg = f"Unknown assignment type: {ts_node.type}" raise ValueError(msg) left_node = ts_node.child_by_field_name("left") right_node = ts_node.child_by_field_name("right") - assignments = cls._from_left_and_right_nodes(ts_node, file_node_id, G, parent, left_node, right_node) - return MultiExpression(ts_node, file_node_id, G, parent, assignments) + assignments = cls._from_left_and_right_nodes(ts_node, file_node_id, ctx, parent, left_node, right_node) + return MultiExpression(ts_node, file_node_id, ctx, parent, assignments) @classmethod - def from_named_expression(cls, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: PyAssignmentStatement) -> MultiExpression[PyAssignmentStatement, PyAssignment]: + def from_named_expression(cls, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: PyAssignmentStatement) -> MultiExpression[PyAssignmentStatement, PyAssignment]: """Creates a MultiExpression from a Python named expression. Creates assignments from a named expression node ('walrus operator' :=) by parsing its name and value fields. @@ -45,7 +45,7 @@ def from_named_expression(cls, ts_node: TSNode, file_node_id: NodeId, G: Codebas Args: ts_node (TSNode): The TreeSitter node representing the named expression. file_node_id (NodeId): The identifier of the file containing this node. - G (CodebaseGraph): The codebase graph instance. + ctx (CodebaseContext): The codebase context instance. parent (Parent): The parent node that contains this expression. Returns: @@ -60,8 +60,8 @@ def from_named_expression(cls, ts_node: TSNode, file_node_id: NodeId, G: Codebas left_node = ts_node.child_by_field_name("name") right_node = ts_node.child_by_field_name("value") - assignments = cls._from_left_and_right_nodes(ts_node, file_node_id, G, parent, left_node, right_node) - return MultiExpression(ts_node, file_node_id, G, parent, assignments) + assignments = cls._from_left_and_right_nodes(ts_node, file_node_id, ctx, parent, left_node, right_node) + return MultiExpression(ts_node, file_node_id, ctx, parent, assignments) @property @reader diff --git a/src/codegen/sdk/python/class_definition.py b/src/codegen/sdk/python/class_definition.py index 6a5c28a68..d4c6e2394 100644 --- a/src/codegen/sdk/python/class_definition.py +++ b/src/codegen/sdk/python/class_definition.py @@ -2,7 +2,7 @@ from tree_sitter import Node as TSNode -from codegen.sdk.codebase.codebase_graph import CodebaseGraph +from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.autocommit import commiter, reader, writer from codegen.sdk.core.class_definition import Class from codegen.sdk.core.dataclasses.usage import UsageKind @@ -34,14 +34,14 @@ class PyClass(Class[PyFunction, PyDecorator, PyCodeBlock, PyParameter, PyType], _decorated_node: TSNode | None constructor_keyword = "__init__" - def __init__(self, ts_node: TSNode, file_id: NodeId, G: CodebaseGraph, parent: PyHasBlock, decorated_node: TSNode | None = None) -> None: - super().__init__(ts_node, file_id, G, parent) + def __init__(self, ts_node: TSNode, file_id: NodeId, ctx: CodebaseContext, parent: PyHasBlock, decorated_node: TSNode | None = None) -> None: + super().__init__(ts_node, file_id, ctx, parent) self._decorated_node = decorated_node if superclasses_node := self.ts_node.child_by_field_name("superclasses"): - self.parent_classes = Parents(superclasses_node, self.file_node_id, self.G, self) + self.parent_classes = Parents(superclasses_node, self.file_node_id, self.ctx, self) if self.constructor is not None and len(self.constructor.parameters) > 1: - self._parameters = SymbolGroup(self.file_node_id, self.G, self, children=self.constructor.parameters[1:]) + self._parameters = SymbolGroup(self.file_node_id, self.ctx, self, children=self.constructor.parameters[1:]) self.type_parameters = self.child_by_field_name("type_parameters") @noapidoc @@ -76,7 +76,7 @@ def _parse_methods(self) -> MultiLineCollection[PyFunction, Self]: else: # Set start byte at column=0 of start of the code block start_byte = block_node.start_byte - block_node.start_point[1] - return MultiLineCollection(children=methods, file_node_id=self.file_node_id, G=self.G, parent=self, node=self.code_block.ts_node, indent_size=indent_size, start_byte=start_byte) + return MultiLineCollection(children=methods, file_node_id=self.file_node_id, ctx=self.ctx, parent=self, node=self.code_block.ts_node, indent_size=indent_size, start_byte=start_byte) #################################################################################################################### # MANIPULATIONS diff --git a/src/codegen/sdk/python/detached_symbols/code_block.py b/src/codegen/sdk/python/detached_symbols/code_block.py index 4f09d2ad9..f251fd324 100644 --- a/src/codegen/sdk/python/detached_symbols/code_block.py +++ b/src/codegen/sdk/python/detached_symbols/code_block.py @@ -26,11 +26,11 @@ class PyCodeBlock(CodeBlock[Parent, "PyAssignment"], Generic[Parent]): @noapidoc @reader def _parse_statements(self) -> MultiLineCollection[Statement, Self]: - statements: list[Statement] = self.G.parser.parse_py_statements(self.ts_node, self.file_node_id, self.G, self) + statements: list[Statement] = self.ctx.parser.parse_py_statements(self.ts_node, self.file_node_id, self.ctx, self) collection = MultiLineCollection( children=statements, file_node_id=self.file_node_id, - G=self.G, + ctx=self.ctx, parent=self, node=self.ts_node, indent_size=self.start_point[1], diff --git a/src/codegen/sdk/python/detached_symbols/decorator.py b/src/codegen/sdk/python/detached_symbols/decorator.py index e56902edc..861dfea0c 100644 --- a/src/codegen/sdk/python/detached_symbols/decorator.py +++ b/src/codegen/sdk/python/detached_symbols/decorator.py @@ -58,5 +58,5 @@ def call(self) -> FunctionCall | None: None if it's a simple decorator. """ if call_node := next((x for x in self.ts_node.named_children if x.type == "call"), None): - return FunctionCall(call_node, self.file_node_id, self.G, self.parent) + return FunctionCall(call_node, self.file_node_id, self.ctx, self.parent) return None diff --git a/src/codegen/sdk/python/expressions/chained_attribute.py b/src/codegen/sdk/python/expressions/chained_attribute.py index b540ddee0..19639f8d7 100644 --- a/src/codegen/sdk/python/expressions/chained_attribute.py +++ b/src/codegen/sdk/python/expressions/chained_attribute.py @@ -16,5 +16,5 @@ class PyChainedAttribute(ChainedAttribute[Expression, Name, Parent], Generic[Par This includes methods of python classes and module functions. """ - def __init__(self, ts_node, file_node_id, G, parent: Parent): - super().__init__(ts_node, file_node_id, G, parent=parent, object=ts_node.child_by_field_name("object"), attribute=ts_node.child_by_field_name("attribute")) + def __init__(self, ts_node, file_node_id, ctx, parent: Parent): + super().__init__(ts_node, file_node_id, ctx, parent=parent, object=ts_node.child_by_field_name("object"), attribute=ts_node.child_by_field_name("attribute")) diff --git a/src/codegen/sdk/python/expressions/conditional_expression.py b/src/codegen/sdk/python/expressions/conditional_expression.py index 01cd0c73e..16e52c28a 100644 --- a/src/codegen/sdk/python/expressions/conditional_expression.py +++ b/src/codegen/sdk/python/expressions/conditional_expression.py @@ -13,8 +13,8 @@ class PyConditionalExpression(TernaryExpression[Parent]): """Conditional Expressions (A if condition else B)""" - def __init__(self, ts_node, file_node_id, G, parent: Parent) -> None: - super().__init__(ts_node, file_node_id, G, parent=parent) + def __init__(self, ts_node, file_node_id, ctx, parent: Parent) -> None: + super().__init__(ts_node, file_node_id, ctx, parent=parent) self.consequence = self.children[0] self.condition = self.children[1] self.alternative = self.children[2] diff --git a/src/codegen/sdk/python/expressions/generic_type.py b/src/codegen/sdk/python/expressions/generic_type.py index 1165c1c10..633d6cceb 100644 --- a/src/codegen/sdk/python/expressions/generic_type.py +++ b/src/codegen/sdk/python/expressions/generic_type.py @@ -35,11 +35,11 @@ def _get_name_node(self) -> TSNode | None: def _get_parameters(self) -> Collection["PyType", Self] | None: if self.ts_node_type == "subscript": types = [self._parse_type(child) for child in self.ts_node.children_by_field_name("subscript")] - return Collection(node=self.ts_node, file_node_id=self.file_node_id, G=self.G, parent=self, children=types) + return Collection(node=self.ts_node, file_node_id=self.file_node_id, ctx=self.ctx, parent=self, children=types) elif self.ts_node_type == "generic_type": type_parameter = self.ts_node.named_children[1] assert type_parameter.type == "type_parameter" types = [self._parse_type(child) for child in type_parameter.named_children] - return Collection(node=type_parameter, file_node_id=self.file_node_id, G=self.G, parent=self, children=types) + return Collection(node=type_parameter, file_node_id=self.file_node_id, ctx=self.ctx, parent=self, children=types) logger.warning(f"Type {self.ts_node_type} not implemented") return None diff --git a/src/codegen/sdk/python/expressions/string.py b/src/codegen/sdk/python/expressions/string.py index be2f186cf..7c717f11f 100644 --- a/src/codegen/sdk/python/expressions/string.py +++ b/src/codegen/sdk/python/expressions/string.py @@ -7,7 +7,7 @@ from codegen.shared.decorators.docs import py_apidoc if TYPE_CHECKING: - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext Parent = TypeVar("Parent", bound="Expression") @@ -17,7 +17,7 @@ class PyString(String, Generic[Parent]): """An abstract representation of a python string.""" - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: "CodebaseGraph", parent: Parent) -> None: - super().__init__(ts_node, file_node_id, G, parent=parent) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: "CodebaseContext", parent: Parent) -> None: + super().__init__(ts_node, file_node_id, ctx, parent=parent) substitutions = [x for x in ts_node.named_children if x.type == "interpolation"] self.expressions = [self._parse_expression(x.child_by_field_name("expression")) for x in substitutions] diff --git a/src/codegen/sdk/python/file.py b/src/codegen/sdk/python/file.py index 47d6003aa..57e82bb6e 100644 --- a/src/codegen/sdk/python/file.py +++ b/src/codegen/sdk/python/file.py @@ -19,7 +19,7 @@ from codegen.shared.decorators.docs import noapidoc, py_apidoc if TYPE_CHECKING: - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.import_resolution import WildcardImport from codegen.sdk.python.symbol import PySymbol @@ -62,19 +62,19 @@ def symbol_can_be_added(self, symbol: PySymbol) -> bool: @commiter def _parse_imports(self) -> None: for import_node in iter_all_descendants(self.ts_node, frozenset({"import_statement", "import_from_statement", "future_import_statement"})): - PyImportStatement(import_node, self.node_id, self.G, self.code_block, 0) + PyImportStatement(import_node, self.node_id, self.ctx, self.code_block, 0) #################################################################################################################### # GETTERS #################################################################################################################### @noapidoc - def get_import_module_name_for_file(self, filepath: str, G: CodebaseGraph) -> str: + def get_import_module_name_for_file(self, filepath: str, ctx: CodebaseContext) -> str: """Returns the module name that this file gets imported as For example, `my/package/name.py` => `my.package.name` """ - base_path = G.projects[0].base_path + base_path = ctx.projects[0].base_path module = filepath.replace(".py", "") if module.endswith("__init__"): module = "/".join(module.split("/")[:-1]) diff --git a/src/codegen/sdk/python/function.py b/src/codegen/sdk/python/function.py index 2c9deb424..dd8720317 100644 --- a/src/codegen/sdk/python/function.py +++ b/src/codegen/sdk/python/function.py @@ -21,7 +21,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.import_resolution import Import, WildcardImport from codegen.sdk.core.interfaces.has_name import HasName from codegen.sdk.core.node_id_factory import NodeId @@ -36,8 +36,8 @@ class PyFunction(Function["PyFunction", PyDecorator, PyCodeBlock, PyParameter, P _decorated_node: TSNode | None - def __init__(self, ts_node: TSNode, file_id: NodeId, G: CodebaseGraph, parent: PyHasBlock, decorated_node: TSNode | None = None) -> None: - super().__init__(ts_node, file_id, G, parent) + def __init__(self, ts_node: TSNode, file_id: NodeId, ctx: CodebaseContext, parent: PyHasBlock, decorated_node: TSNode | None = None) -> None: + super().__init__(ts_node, file_id, ctx, parent) self._decorated_node = decorated_node @cached_property @@ -131,8 +131,8 @@ def resolve_name(self, name: str, start_byte: int | None = None) -> Symbol | Imp @noapidoc @commiter - def parse(self, G: CodebaseGraph) -> None: - super().parse(G) + def parse(self, ctx: CodebaseContext) -> None: + super().parse(ctx) self.return_type = self.child_by_field_name("return_type", placeholder=PyReturnTypePlaceholder) if parameters_node := self.ts_node.child_by_field_name("parameters"): params = [ @@ -148,7 +148,7 @@ def parse(self, G: CodebaseGraph) -> None: "dictionary_splat_pattern", ) ] - self._parameters = Collection(parameters_node, self.file_node_id, self.G, self) + self._parameters = Collection(parameters_node, self.file_node_id, self.ctx, self) self._parameters._init_children([PyParameter(x, i, self._parameters) for (i, x) in enumerate(params)]) else: logger.warning(f"Couldn't find parameters for {self!r}") diff --git a/src/codegen/sdk/python/import_resolution.py b/src/codegen/sdk/python/import_resolution.py index 64e3b5f1c..a80bb2ada 100644 --- a/src/codegen/sdk/python/import_resolution.py +++ b/src/codegen/sdk/python/import_resolution.py @@ -12,7 +12,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.interfaces.editable import Editable from codegen.sdk.core.interfaces.exportable import Exportable from codegen.sdk.core.node_id_factory import NodeId @@ -83,7 +83,7 @@ def imported_exports(self) -> list[Exportable]: @noapidoc @reader def resolve_import(self, base_path: str | None = None, *, add_module_name: str | None = None) -> ImportResolution[PyFile] | None: - base_path = base_path or self.G.projects[0].base_path or "" + base_path = base_path or self.ctx.projects[0].base_path or "" module_source = self.module.source if self.module else "" symbol_name = self.symbol_name.source if self.symbol_name else "" if add_module_name: @@ -104,11 +104,11 @@ def resolve_import(self, base_path: str | None = None, *, add_module_name: str | base_path, module_source.replace(".", "/") + "/" + symbol_name + ".py", ) - if file := self.G.get_file(filepath): + if file := self.ctx.get_file(filepath): return ImportResolution(from_file=file, symbol=None, imports_file=True) filepath = filepath.replace(".py", "/__init__.py") - if file := self.G.get_file(filepath): + if file := self.ctx.get_file(filepath): # TODO - I think this is another edge case, due to `dao/__init__.py` etc. # You can't do `from a.b.c import foo` => `foo.utils.x` right now since `foo` is just a file... return ImportResolution(from_file=file, symbol=None, imports_file=True) @@ -116,13 +116,13 @@ def resolve_import(self, base_path: str | None = None, *, add_module_name: str | # =====[ Check if `module.py` file exists in the graph ]===== filepath = module_source.replace(".", "/") + ".py" filepath = os.path.join(base_path, filepath) - if file := self.G.get_file(filepath): + if file := self.ctx.get_file(filepath): symbol = file.get_node_by_name(symbol_name) return ImportResolution(from_file=file, symbol=symbol) # =====[ Check if `module/__init__.py` file exists in the graph ]===== filepath = filepath.replace(".py", "/__init__.py") - if from_file := self.G.get_file(filepath): + if from_file := self.ctx.get_file(filepath): symbol = from_file.get_node_by_name(symbol_name) return ImportResolution(from_file=from_file, symbol=symbol) @@ -135,13 +135,13 @@ def resolve_import(self, base_path: str | None = None, *, add_module_name: str | return self.resolve_import(base_path="test", add_module_name=add_module_name) # if not G_override: - # for resolver in G.import_resolvers: + # for resolver in ctx.import_resolvers: # if imp := resolver.resolve(self): # return imp return None # # =====[ Check if we are importing an external module in the graph ]===== - # if ext := self.G.get_external_module(self.source, self._unique_node.source): + # if ext := self.ctx.get_external_module(self.source, self._unique_node.source): # return ImportResolution(symbol=ext) # # Implies we are not importing the symbol from the current repo. # # In these cases, consider the import as an ExternalModule and add to graph @@ -183,23 +183,23 @@ def _relative_to_absolute_import(self, relative_import: str) -> str: @classmethod @noapidoc - def from_import_statement(cls, import_statement: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: ImportStatement) -> list[PyImport]: + def from_import_statement(cls, import_statement: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: ImportStatement) -> list[PyImport]: imports = [] for module_node in import_statement.children_by_field_name("name"): if module_node.type == "dotted_name": - imports.append(cls(import_statement, file_node_id, G, parent, module_node=module_node, name_node=module_node, alias_node=module_node, import_type=ImportType.MODULE)) + imports.append(cls(import_statement, file_node_id, ctx, parent, module_node=module_node, name_node=module_node, alias_node=module_node, import_type=ImportType.MODULE)) elif module_node.type == "aliased_import": module = module_node.child_by_field_name("name") symbol_name = module alias = module_node.child_by_field_name("alias") - imports.append(cls(import_statement, file_node_id, G, parent, module_node=module, name_node=symbol_name, alias_node=alias, import_type=ImportType.MODULE)) + imports.append(cls(import_statement, file_node_id, ctx, parent, module_node=module, name_node=symbol_name, alias_node=alias, import_type=ImportType.MODULE)) else: logger.error(f"Unsupported import statement: {import_statement.text.decode('utf-8')}") return imports @classmethod @noapidoc - def from_import_from_statement(cls, import_statement: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: ImportStatement) -> list[PyImport]: + def from_import_from_statement(cls, import_statement: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: ImportStatement) -> list[PyImport]: module_node = import_statement.child_by_field_name("module_name") import_symbols = import_statement.children_by_field_name("name") if len(import_symbols) == 0: @@ -207,16 +207,16 @@ def from_import_from_statement(cls, import_statement: TSNode, file_node_id: Node if wildcard_import is None: msg = f"Unsupported import statement: {import_statement.text.decode('utf-8')}" raise ValueError(msg) - return [cls(import_statement, file_node_id, G, parent, module_node=module_node, name_node=module_node, alias_node=module_node, import_type=ImportType.WILDCARD)] + return [cls(import_statement, file_node_id, ctx, parent, module_node=module_node, name_node=module_node, alias_node=module_node, import_type=ImportType.WILDCARD)] imports = [] for import_symbol in import_symbols: if import_symbol.type == "dotted_name": - imp = cls(import_statement, file_node_id, G, parent, module_node=module_node, name_node=import_symbol, alias_node=import_symbol, import_type=ImportType.NAMED_EXPORT) + imp = cls(import_statement, file_node_id, ctx, parent, module_node=module_node, name_node=import_symbol, alias_node=import_symbol, import_type=ImportType.NAMED_EXPORT) elif import_symbol.type == "aliased_import": symbol_name = import_symbol.child_by_field_name("name") alias = import_symbol.child_by_field_name("alias") - imp = cls(import_statement, file_node_id, G, parent, module_node=module_node, name_node=symbol_name, alias_node=alias, import_type=ImportType.NAMED_EXPORT) + imp = cls(import_statement, file_node_id, ctx, parent, module_node=module_node, name_node=symbol_name, alias_node=alias, import_type=ImportType.NAMED_EXPORT) else: msg = f"Unsupported import statement: {import_statement.text.decode('utf-8')}" raise ValueError(msg) @@ -225,10 +225,10 @@ def from_import_from_statement(cls, import_statement: TSNode, file_node_id: Node @classmethod @noapidoc - def from_future_import_statement(cls, import_statement: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: ImportStatement) -> list[PyImport]: + def from_future_import_statement(cls, import_statement: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: ImportStatement) -> list[PyImport]: imports = [] for module_node in import_statement.children_by_field_name("name"): - imp = cls(import_statement, file_node_id, G, parent, module_node=module_node, name_node=module_node, alias_node=module_node, import_type=ImportType.SIDE_EFFECT) + imp = cls(import_statement, file_node_id, ctx, parent, module_node=module_node, name_node=module_node, alias_node=module_node, import_type=ImportType.SIDE_EFFECT) imports.append(imp) return imports @@ -252,7 +252,7 @@ def import_specifier(self) -> Editable: else: is_match = self.symbol_name.source == import_specifier.text.decode("utf-8") if is_match: - return Name(import_specifier, self.file_node_id, self.G, self) + return Name(import_specifier, self.file_node_id, self.ctx, self) @reader def get_import_string( @@ -286,7 +286,7 @@ def get_import_string( class PyExternalImportResolver(ExternalImportResolver): - def __init__(self, from_alias: str, to_context: CodebaseGraph) -> None: + def __init__(self, from_alias: str, to_context: CodebaseContext) -> None: self.from_alias = from_alias self.to_context = to_context diff --git a/src/codegen/sdk/python/statements/assignment_statement.py b/src/codegen/sdk/python/statements/assignment_statement.py index 65d72f30c..a53690fcd 100644 --- a/src/codegen/sdk/python/statements/assignment_statement.py +++ b/src/codegen/sdk/python/statements/assignment_statement.py @@ -11,7 +11,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.node_id_factory import NodeId from codegen.sdk.python.detached_symbols.code_block import PyCodeBlock from codegen.sdk.python.interfaces.has_block import PyHasBlock @@ -31,7 +31,7 @@ class PyAssignmentStatement(AssignmentStatement["PyCodeBlock", PyAssignment]): assignment_types = {"assignment", "augmented_assignment", "named_expression"} @classmethod - def from_assignment(cls, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: PyCodeBlock, pos: int, assignment_node: TSNode) -> PyAssignmentStatement: + def from_assignment(cls, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: PyCodeBlock, pos: int, assignment_node: TSNode) -> PyAssignmentStatement: """Creates a PyAssignmentStatement instance from a TreeSitter assignment node. Factory method to create appropriate assignment statement objects based on the node type and parent context. @@ -40,7 +40,7 @@ def from_assignment(cls, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph Args: ts_node (TSNode): The TreeSitter node representing the entire statement. file_node_id (NodeId): The ID of the file containing this node. - G (CodebaseGraph): The codebase graph instance. + ctx (CodebaseContext): The codebase context instance. parent (PyHasBlock): The parent block containing this statement. code_block (PyCodeBlock): The code block containing this statement. pos (int): The position of this statement within its code block. @@ -61,17 +61,17 @@ def from_assignment(cls, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph if isinstance(parent, PyClass): from codegen.sdk.python.statements.attribute import PyAttribute - return PyAttribute(ts_node, file_node_id, G, parent, pos, assignment_node=assignment_node) - return cls(ts_node, file_node_id, G, parent, pos, assignment_node=assignment_node) + return PyAttribute(ts_node, file_node_id, ctx, parent, pos, assignment_node=assignment_node) + return cls(ts_node, file_node_id, ctx, parent, pos, assignment_node=assignment_node) def _parse_assignments(self, assignment_node: TSNode) -> MultiExpression[PyHasBlock, PyAssignment]: if assignment_node.type in ["assignment", "augmented_assignment"]: - return PyAssignment.from_assignment(assignment_node, self.file_node_id, self.G, self.parent) + return PyAssignment.from_assignment(assignment_node, self.file_node_id, self.ctx, self.parent) elif assignment_node.type == "named_expression": - return PyAssignment.from_named_expression(assignment_node, self.file_node_id, self.G, self.parent) + return PyAssignment.from_named_expression(assignment_node, self.file_node_id, self.ctx, self.parent) logger.info(f"Unknown assignment type: {assignment_node.type}") - return MultiExpression(assignment_node, self.file_node_id, self.G, self.parent, [self.parent._parse_expression(assignment_node)]) + return MultiExpression(assignment_node, self.file_node_id, self.ctx, self.parent, [self.parent._parse_expression(assignment_node)]) def _DEPRECATED_parse_assignments(self) -> MultiExpression[PyHasBlock, PyAssignment]: assignments = [] @@ -80,8 +80,8 @@ def _DEPRECATED_parse_assignments(self) -> MultiExpression[PyHasBlock, PyAssignm right = assignment.child_by_field_name("right") if left.type == "pattern_list": for identifier in find_all_descendants(left, {"identifier", "attribute"}): - assignments.append(PyAssignment(assignment, self.file_node_id, self.G, self, left, right, identifier)) + assignments.append(PyAssignment(assignment, self.file_node_id, self.ctx, self, left, right, identifier)) else: - assignments.append(PyAssignment(assignment, self.file_node_id, self.G, self, left, right, left)) + assignments.append(PyAssignment(assignment, self.file_node_id, self.ctx, self, left, right, left)) - return MultiExpression(self.ts_node, self.file_node_id, self.G, self.parent, assignments) + return MultiExpression(self.ts_node, self.file_node_id, self.ctx, self.parent, assignments) diff --git a/src/codegen/sdk/python/statements/catch_statement.py b/src/codegen/sdk/python/statements/catch_statement.py index 2821c4f51..3bbea1b46 100644 --- a/src/codegen/sdk/python/statements/catch_statement.py +++ b/src/codegen/sdk/python/statements/catch_statement.py @@ -10,7 +10,7 @@ if TYPE_CHECKING: from tree_sitter import Node as PyNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.node_id_factory import NodeId @@ -23,6 +23,6 @@ class PyCatchStatement(CatchStatement[PyCodeBlock], PyBlockStatement): condition: The condition which triggers this clause """ - def __init__(self, ts_node: PyNode, file_node_id: NodeId, G: CodebaseGraph, parent: PyCodeBlock, pos: int | None = None) -> None: - super().__init__(ts_node, file_node_id, G, parent, pos) + def __init__(self, ts_node: PyNode, file_node_id: NodeId, ctx: CodebaseContext, parent: PyCodeBlock, pos: int | None = None) -> None: + super().__init__(ts_node, file_node_id, ctx, parent, pos) self.condition = self.children[0] diff --git a/src/codegen/sdk/python/statements/for_loop_statement.py b/src/codegen/sdk/python/statements/for_loop_statement.py index cbd212bcd..84f716cd3 100644 --- a/src/codegen/sdk/python/statements/for_loop_statement.py +++ b/src/codegen/sdk/python/statements/for_loop_statement.py @@ -10,7 +10,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.dataclasses.usage import UsageKind from codegen.sdk.core.detached_symbols.function_call import FunctionCall from codegen.sdk.core.expressions import Expression @@ -32,8 +32,8 @@ class PyForLoopStatement(ForLoopStatement["PyCodeBlock"], PyBlockStatement): item: Expression[PyForLoopStatement] iterable: Expression[PyForLoopStatement] - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: PyCodeBlock, pos: int | None = None) -> None: - super().__init__(ts_node, file_node_id, G, parent, pos) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: PyCodeBlock, pos: int | None = None) -> None: + super().__init__(ts_node, file_node_id, ctx, parent, pos) self.item = self.child_by_field_name("left") self.iterable = self.child_by_field_name("right") diff --git a/src/codegen/sdk/python/statements/if_block_statement.py b/src/codegen/sdk/python/statements/if_block_statement.py index 872b3110f..54585b9e7 100644 --- a/src/codegen/sdk/python/statements/if_block_statement.py +++ b/src/codegen/sdk/python/statements/if_block_statement.py @@ -10,7 +10,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.node_id_factory import NodeId from codegen.sdk.python.detached_symbols.code_block import PyCodeBlock @@ -34,8 +34,8 @@ class PyIfBlockStatement(IfBlockStatement[Parent, "PyIfBlockStatement"], Generic statement_type = StatementType.IF_BLOCK_STATEMENT - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: Parent, pos: int, main_if_block: PyIfBlockStatement | None = None) -> None: - super().__init__(ts_node, file_node_id, G, parent, pos) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: Parent, pos: int, main_if_block: PyIfBlockStatement | None = None) -> None: + super().__init__(ts_node, file_node_id, ctx, parent, pos) self._main_if_block = main_if_block self.condition = self.child_by_field_name("condition") self.consequence_block = self._parse_consequence_block() @@ -55,7 +55,7 @@ def _parse_alternative_blocks(self) -> list[PyIfBlockStatement]: alt_blocks = [] if self.is_if_statement: for alt_node in self.ts_node.children_by_field_name("alternative"): - alt_block = PyIfBlockStatement(alt_node, self.file_node_id, self.G, self.parent, self.index, main_if_block=self._main_if_block or self) + alt_block = PyIfBlockStatement(alt_node, self.file_node_id, self.ctx, self.parent, self.index, main_if_block=self._main_if_block or self) alt_blocks.append(alt_block) return alt_blocks diff --git a/src/codegen/sdk/python/statements/import_statement.py b/src/codegen/sdk/python/statements/import_statement.py index 81473009e..5b84c213e 100644 --- a/src/codegen/sdk/python/statements/import_statement.py +++ b/src/codegen/sdk/python/statements/import_statement.py @@ -11,7 +11,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.node_id_factory import NodeId from codegen.sdk.python.file import PyFile @@ -20,15 +20,15 @@ class PyImportStatement(ImportStatement["PyFile", PyImport, PyCodeBlock]): """An abstract representation of a python import statement.""" - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: PyCodeBlock, pos: int) -> None: - super().__init__(ts_node, file_node_id, G, parent, pos) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: PyCodeBlock, pos: int) -> None: + super().__init__(ts_node, file_node_id, ctx, parent, pos) imports = [] if ts_node.type == "import_statement": - imports.extend(PyImport.from_import_statement(ts_node, file_node_id, G, self)) + imports.extend(PyImport.from_import_statement(ts_node, file_node_id, ctx, self)) elif ts_node.type == "import_from_statement": - imports.extend(PyImport.from_import_from_statement(ts_node, file_node_id, G, self)) + imports.extend(PyImport.from_import_from_statement(ts_node, file_node_id, ctx, self)) elif ts_node.type == "future_import_statement": - imports.extend(PyImport.from_future_import_statement(ts_node, file_node_id, G, self)) - self.imports = Collection(ts_node, file_node_id, G, self, delimiter="\n", children=imports) + imports.extend(PyImport.from_future_import_statement(ts_node, file_node_id, ctx, self)) + self.imports = Collection(ts_node, file_node_id, ctx, self, delimiter="\n", children=imports) for imp in self.imports: imp.import_statement = self diff --git a/src/codegen/sdk/python/statements/match_case.py b/src/codegen/sdk/python/statements/match_case.py index 978e1a386..69528fbba 100644 --- a/src/codegen/sdk/python/statements/match_case.py +++ b/src/codegen/sdk/python/statements/match_case.py @@ -9,7 +9,7 @@ from codegen.shared.decorators.docs import py_apidoc if TYPE_CHECKING: - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.python.statements.match_statement import PyMatchStatement @@ -17,6 +17,6 @@ class PyMatchCase(SwitchCase[PyCodeBlock["PyMatchStatement"]], PyBlockStatement): """Python match case.""" - def __init__(self, ts_node: PyNode, file_node_id: NodeId, G: "CodebaseGraph", parent: PyCodeBlock, pos: int | None = None) -> None: - super().__init__(ts_node, file_node_id, G, parent, pos) + def __init__(self, ts_node: PyNode, file_node_id: NodeId, ctx: "CodebaseContext", parent: PyCodeBlock, pos: int | None = None) -> None: + super().__init__(ts_node, file_node_id, ctx, parent, pos) self.condition = self.child_by_field_name("alternative") diff --git a/src/codegen/sdk/python/statements/match_statement.py b/src/codegen/sdk/python/statements/match_statement.py index 520a6fb06..804ff2029 100644 --- a/src/codegen/sdk/python/statements/match_statement.py +++ b/src/codegen/sdk/python/statements/match_statement.py @@ -9,7 +9,7 @@ if TYPE_CHECKING: from tree_sitter import Node as PyNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.node_id_factory import NodeId from codegen.sdk.python.detached_symbols.code_block import PyCodeBlock @@ -18,10 +18,10 @@ class PyMatchStatement(SwitchStatement["PyCodeBlock", "PyCodeBlock", PyMatchCase]): """Abstract representation of the match block""" - def __init__(self, ts_node: PyNode, file_node_id: NodeId, G: CodebaseGraph, parent: PyCodeBlock, pos: int | None = None) -> None: - super().__init__(ts_node, file_node_id, G, parent, pos) + def __init__(self, ts_node: PyNode, file_node_id: NodeId, ctx: CodebaseContext, parent: PyCodeBlock, pos: int | None = None) -> None: + super().__init__(ts_node, file_node_id, ctx, parent, pos) self.value = self.child_by_field_name("subject") code_block = self.ts_node.child_by_field_name("body") self.cases = [] for node in code_block.children_by_field_name("alternative"): - self.cases.append(PyMatchCase(node, file_node_id, G, self.parent, self.index)) + self.cases.append(PyMatchCase(node, file_node_id, ctx, self.parent, self.index)) diff --git a/src/codegen/sdk/python/statements/try_catch_statement.py b/src/codegen/sdk/python/statements/try_catch_statement.py index 06e1f5863..c4a4827b3 100644 --- a/src/codegen/sdk/python/statements/try_catch_statement.py +++ b/src/codegen/sdk/python/statements/try_catch_statement.py @@ -11,7 +11,7 @@ if TYPE_CHECKING: from tree_sitter import Node as PyNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.dataclasses.usage import UsageKind from codegen.sdk.core.detached_symbols.function_call import FunctionCall from codegen.sdk.core.interfaces.has_name import HasName @@ -30,14 +30,14 @@ class PyTryCatchStatement(TryCatchStatement["PyCodeBlock"], PyBlockStatement): except_clauses: list[PyCatchStatement[Self]] - def __init__(self, ts_node: PyNode, file_node_id: NodeId, G: CodebaseGraph, parent: PyCodeBlock, pos: int | None = None) -> None: - super().__init__(ts_node, file_node_id, G, parent, pos) + def __init__(self, ts_node: PyNode, file_node_id: NodeId, ctx: CodebaseContext, parent: PyCodeBlock, pos: int | None = None) -> None: + super().__init__(ts_node, file_node_id, ctx, parent, pos) self.except_clauses = [] for node in self.ts_node.named_children: if node.type == "finally_clause": - self.finalizer = PyBlockStatement(node, file_node_id, G, self, self.index) + self.finalizer = PyBlockStatement(node, file_node_id, ctx, self, self.index) elif node.type == "except_clause": - self.except_clauses.append(PyCatchStatement(node, file_node_id, G, self, self.index)) + self.except_clauses.append(PyCatchStatement(node, file_node_id, ctx, self, self.index)) @property @reader diff --git a/src/codegen/sdk/python/statements/while_statement.py b/src/codegen/sdk/python/statements/while_statement.py index 9182f5e52..2ae5e80c5 100644 --- a/src/codegen/sdk/python/statements/while_statement.py +++ b/src/codegen/sdk/python/statements/while_statement.py @@ -12,7 +12,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.dataclasses.usage import UsageKind from codegen.sdk.core.detached_symbols.function_call import FunctionCall from codegen.sdk.core.interfaces.has_name import HasName @@ -31,11 +31,11 @@ class PyWhileStatement(WhileStatement["PyCodeBlock"], PyHasBlock): else_statement: PyIfBlockStatement[PyCodeBlock[PyWhileStatement]] | None = None - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: PyCodeBlock, pos: int | None = None) -> None: - super().__init__(ts_node, file_node_id, G, parent, pos) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: PyCodeBlock, pos: int | None = None) -> None: + super().__init__(ts_node, file_node_id, ctx, parent, pos) self.condition = self.child_by_field_name("condition") if else_block := ts_node.child_by_field_name("alternative"): - self.else_statement = PyIfBlockStatement(else_block, file_node_id, G, self.code_block, self.index, main_if_block=self) + self.else_statement = PyIfBlockStatement(else_block, file_node_id, ctx, self.code_block, self.index, main_if_block=self) else: self.else_statement = None diff --git a/src/codegen/sdk/python/statements/with_statement.py b/src/codegen/sdk/python/statements/with_statement.py index d507abdbd..64c2f76bd 100644 --- a/src/codegen/sdk/python/statements/with_statement.py +++ b/src/codegen/sdk/python/statements/with_statement.py @@ -14,7 +14,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.dataclasses.usage import UsageKind from codegen.sdk.core.detached_symbols.function_call import FunctionCall from codegen.sdk.core.interfaces.has_name import HasName @@ -47,13 +47,13 @@ class WithStatement(Statement["PyCodeBlock"], PyHasBlock): code_block: PyCodeBlock[WithStatement] clause: ExpressionGroup - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: PyCodeBlock, pos: int | None = None) -> None: - super().__init__(ts_node, file_node_id, G, parent, pos) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: PyCodeBlock, pos: int | None = None) -> None: + super().__init__(ts_node, file_node_id, ctx, parent, pos) self.code_block = self._parse_code_block() self.code_block.parse() clause = next(x for x in self.ts_node.children if x.type == "with_clause") items = [self._parse_expression(item.child_by_field_name("value")) for item in clause.children if item.type == "with_item"] - self.clause = ExpressionGroup(self.file_node_id, self.G, self, children=items) + self.clause = ExpressionGroup(self.file_node_id, self.ctx, self, children=items) @property @reader diff --git a/src/codegen/sdk/python/symbol.py b/src/codegen/sdk/python/symbol.py index 3fd84631a..0e026213d 100644 --- a/src/codegen/sdk/python/symbol.py +++ b/src/codegen/sdk/python/symbol.py @@ -12,7 +12,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.codebase.flagging.code_flag import CodeFlag from codegen.sdk.codebase.flagging.enums import FlagKwargs from codegen.sdk.core.interfaces.has_block import HasBlock @@ -27,9 +27,9 @@ class PySymbol(Symbol["PyHasBlock", "PyCodeBlock"]): @classmethod @noapidoc - def from_decorated_definition(cls, ts_node: TSNode, file_id: NodeId, G: CodebaseGraph, parent: HasBlock) -> Symbol: + def from_decorated_definition(cls, ts_node: TSNode, file_id: NodeId, ctx: CodebaseContext, parent: HasBlock) -> Symbol: definition = ts_node.child_by_field_name("definition") - return G.parser.parse_expression(definition, file_id, G, parent, decorated_node=ts_node) + return ctx.parser.parse_expression(definition, file_id, ctx, parent, decorated_node=ts_node) @property @reader diff --git a/src/codegen/sdk/python/symbol_groups/comment_group.py b/src/codegen/sdk/python/symbol_groups/comment_group.py index 701445fab..a35cdf3dd 100644 --- a/src/codegen/sdk/python/symbol_groups/comment_group.py +++ b/src/codegen/sdk/python/symbol_groups/comment_group.py @@ -63,7 +63,7 @@ def from_symbol_comments(cls, symbol: PySymbol): if not comments: return None - return cls(comments, symbol.file_node_id, symbol.G, symbol) + return cls(comments, symbol.file_node_id, symbol.ctx, symbol) @classmethod @noapidoc @@ -82,7 +82,7 @@ def from_symbol_inline_comments(cls, symbol: PySymbol, node: TSNode | None = Non if not comment_nodes: return None - return cls(comment_nodes, symbol.file_node_id, symbol.G, symbol) + return cls(comment_nodes, symbol.file_node_id, symbol.ctx, symbol) @classmethod @noapidoc @@ -94,7 +94,7 @@ def from_docstring(cls, symbol: PySymbol): if string_node.type == "string": text = string_node.text.decode("utf-8") comment_node = PyComment.from_code_block(string_node, symbol) - return cls([comment_node], symbol.file_node_id, symbol.G, symbol) + return cls([comment_node], symbol.file_node_id, symbol.ctx, symbol) return None def to_google_docstring(self, function: PyFunction) -> str: # pragma: no cover diff --git a/src/codegen/sdk/typescript/assignment.py b/src/codegen/sdk/typescript/assignment.py index 0c9116d15..538f0e5ca 100644 --- a/src/codegen/sdk/typescript/assignment.py +++ b/src/codegen/sdk/typescript/assignment.py @@ -11,7 +11,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.node_id_factory import NodeId from codegen.sdk.core.statements.export_statement import ExportStatement from codegen.sdk.typescript.statements.assignment_statement import TSAssignmentStatement @@ -30,18 +30,18 @@ class TSAssignment(Assignment["TSAssignmentStatement | ExportStatement"], TSSymb @noapidoc @classmethod - def from_assignment(cls, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: TSAssignmentStatement) -> MultiExpression[TSAssignmentStatement, TSAssignment]: + def from_assignment(cls, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: TSAssignmentStatement) -> MultiExpression[TSAssignmentStatement, TSAssignment]: if ts_node.type not in ["assignment_expression", "augmented_assignment_expression"]: msg = f"Unknown assignment type: {ts_node.type}" raise ValueError(msg) left_node = ts_node.child_by_field_name("left") right_node = ts_node.child_by_field_name("right") - assignments = cls._from_left_and_right_nodes(ts_node, file_node_id, G, parent, left_node, right_node) - return MultiExpression(ts_node, file_node_id, G, parent, assignments) + assignments = cls._from_left_and_right_nodes(ts_node, file_node_id, ctx, parent, left_node, right_node) + return MultiExpression(ts_node, file_node_id, ctx, parent, assignments) @classmethod - def from_named_expression(cls, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: TSAssignmentStatement) -> MultiExpression[TSAssignmentStatement, TSAssignment]: + def from_named_expression(cls, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: TSAssignmentStatement) -> MultiExpression[TSAssignmentStatement, TSAssignment]: """Creates a MultiExpression object from a TypeScript named expression node. Constructs assignments from a TypeScript named expression node (variable declarator, public field definition, or property signature) by extracting the left (name) and right (value) nodes. @@ -49,7 +49,7 @@ def from_named_expression(cls, ts_node: TSNode, file_node_id: NodeId, G: Codebas Args: ts_node (TSNode): The TypeScript node representing the named expression. file_node_id (NodeId): The unique identifier for the file containing this node. - G (CodebaseGraph): The graph representation of the codebase. + ctx (CodebaseContext): The graph representation of the codebase. parent (Parent): The parent node containing this expression. Returns: @@ -64,8 +64,8 @@ def from_named_expression(cls, ts_node: TSNode, file_node_id: NodeId, G: Codebas left_node = ts_node.child_by_field_name("name") right_node = ts_node.child_by_field_name("value") - assignments = cls._from_left_and_right_nodes(ts_node, file_node_id, G, parent, left_node, right_node) - return MultiExpression(ts_node, file_node_id, G, parent, assignments) + assignments = cls._from_left_and_right_nodes(ts_node, file_node_id, ctx, parent, left_node, right_node) + return MultiExpression(ts_node, file_node_id, ctx, parent, assignments) @writer def set_inline_comment(self, comment: str, auto_format: bool = True, clean_format: bool = True) -> None: diff --git a/src/codegen/sdk/typescript/class_definition.py b/src/codegen/sdk/typescript/class_definition.py index f5cdcb6ff..62fd0c0c8 100644 --- a/src/codegen/sdk/typescript/class_definition.py +++ b/src/codegen/sdk/typescript/class_definition.py @@ -24,7 +24,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.node_id_factory import NodeId from codegen.sdk.core.statements.symbol_statement import SymbolStatement from codegen.sdk.typescript.detached_symbols.code_block import TSCodeBlock @@ -49,13 +49,13 @@ class TSClass(Class[TSFunction, TSDecorator, "TSCodeBlock", TSParameter, TSType] Representation of a Class in JavaScript/TypeScript """ - def __init__(self, ts_node: TSNode, file_id: NodeId, G: CodebaseGraph, parent: SymbolStatement) -> None: - super().__init__(ts_node, file_id, G, parent) + def __init__(self, ts_node: TSNode, file_id: NodeId, ctx: CodebaseContext, parent: SymbolStatement) -> None: + super().__init__(ts_node, file_id, ctx, parent) if superclasses_node := self.child_by_field_types("class_heritage"): if extends_clause := superclasses_node.child_by_field_types(["extends_clause", "implements_clause"]): - self.parent_classes = Parents(extends_clause.ts_node, self.file_node_id, self.G, self) + self.parent_classes = Parents(extends_clause.ts_node, self.file_node_id, self.ctx, self) if self.constructor is not None and len(self.constructor.parameters) > 0: - self._parameters = SymbolGroup(self.file_node_id, self.G, self, children=self.constructor.parameters) + self._parameters = SymbolGroup(self.file_node_id, self.ctx, self, children=self.constructor.parameters) self.type_parameters = self.child_by_field_name("type_parameters") @noapidoc @@ -98,7 +98,7 @@ def _parse_methods(self) -> MultiLineCollection[TSFunction, Self]: else: start_byte = block_node.start_byte - block_node.start_point[1] return MultiLineCollection( - children=methods, file_node_id=self.file_node_id, G=self.G, parent=self, node=self.code_block.ts_node, indent_size=indent_size, start_byte=start_byte, end_byte=block_node.end_byte - 1 + children=methods, file_node_id=self.file_node_id, ctx=self.ctx, parent=self, node=self.code_block.ts_node, indent_size=indent_size, start_byte=start_byte, end_byte=block_node.end_byte - 1 ) @property @@ -225,4 +225,4 @@ class Button extends React.Component { @writer def class_component_to_function_component(self) -> None: """Converts a class component to a function component.""" - return self.G.ts_declassify.declassify(self.source, filename=os.path.basename(self.file.file_path)) + return self.ctx.ts_declassify.declassify(self.source, filename=os.path.basename(self.file.file_path)) diff --git a/src/codegen/sdk/typescript/config_parser.py b/src/codegen/sdk/typescript/config_parser.py index 2f5e79861..0c9e8bfe7 100644 --- a/src/codegen/sdk/typescript/config_parser.py +++ b/src/codegen/sdk/typescript/config_parser.py @@ -7,7 +7,7 @@ from codegen.sdk.typescript.ts_config import TSConfig if TYPE_CHECKING: - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.typescript.file import TSFile import os @@ -17,20 +17,20 @@ class TSConfigParser(ConfigParser): # Cache of path names to TSConfig objects config_files: dict[Path, TSConfig] - G: "CodebaseGraph" + ctx: "CodebaseContext" - def __init__(self, codebase_graph: "CodebaseGraph", default_config_name: str = "tsconfig.json"): + def __init__(self, codebase_context: "CodebaseContext", default_config_name: str = "tsconfig.json"): super().__init__() self.config_files = dict() - self.G = codebase_graph + self.ctx = codebase_context self.default_config_name = default_config_name def get_config(self, config_path: os.PathLike) -> TSConfig | None: - path = self.G.to_absolute(config_path) + path = self.ctx.to_absolute(config_path) if path in self.config_files: return self.config_files[path] if path.exists(): - self.config_files[path] = TSConfig(File.from_content(config_path, path.read_text(), self.G, sync=False), self) + self.config_files[path] = TSConfig(File.from_content(config_path, path.read_text(), self.ctx, sync=False), self) return self.config_files.get(path) return None @@ -42,16 +42,16 @@ def get_config_for_dir(dir_path: Path) -> TSConfig | None: ts_config_path = dir_path / self.default_config_name # If it does, return the config if ts_config_path.exists(): - if ts_config := self.get_config(self.G.to_absolute(ts_config_path)): + if ts_config := self.get_config(self.ctx.to_absolute(ts_config_path)): self.config_files[ts_config_path] = ts_config return ts_config # Otherwise, check the parent directory - if dir_path.is_relative_to(self.G.repo_path): + if dir_path.is_relative_to(self.ctx.repo_path): return get_config_for_dir(dir_path.parent) return None # Get all the files in the codebase - for file in self.G.get_nodes(NodeType.FILE): + for file in self.ctx.get_nodes(NodeType.FILE): file: TSFile # This should be safe because we only call this on TSFiles # Get the config for the directory the file is in config = get_config_for_dir(file.path.parent) diff --git a/src/codegen/sdk/typescript/detached_symbols/code_block.py b/src/codegen/sdk/typescript/detached_symbols/code_block.py index c69d73f73..c6871100e 100644 --- a/src/codegen/sdk/typescript/detached_symbols/code_block.py +++ b/src/codegen/sdk/typescript/detached_symbols/code_block.py @@ -23,7 +23,7 @@ class TSCodeBlock(CodeBlock[Parent, "TSAssignment"], Generic[Parent]): @noapidoc @reader def _parse_statements(self) -> MultiLineCollection[Statement, Self]: - statements: list[Statement] = self.G.parser.parse_ts_statements(self.ts_node, self.file_node_id, self.G, self) + statements: list[Statement] = self.ctx.parser.parse_ts_statements(self.ts_node, self.file_node_id, self.ctx, self) line_nodes = find_line_start_and_end_nodes(self.ts_node) start_node = line_nodes[1][0] if len(line_nodes) > 1 else line_nodes[0][0] end_node = line_nodes[-2][1] if len(line_nodes) > 1 else line_nodes[-1][1] @@ -31,7 +31,7 @@ def _parse_statements(self) -> MultiLineCollection[Statement, Self]: collection = MultiLineCollection( children=statements, file_node_id=self.file_node_id, - G=self.G, + ctx=self.ctx, parent=self, node=self.ts_node, indent_size=indent_size, diff --git a/src/codegen/sdk/typescript/detached_symbols/decorator.py b/src/codegen/sdk/typescript/detached_symbols/decorator.py index e06da867e..2d24c10c0 100644 --- a/src/codegen/sdk/typescript/detached_symbols/decorator.py +++ b/src/codegen/sdk/typescript/detached_symbols/decorator.py @@ -54,5 +54,5 @@ def call(self) -> FunctionCall | None: FunctionCall | None: A FunctionCall object representing the decorator's call expression if present, None otherwise. """ if call_node := next((x for x in self.ts_node.named_children if x.type == "call_expression"), None): - return FunctionCall(call_node, self.file_node_id, self.G, self.parent) + return FunctionCall(call_node, self.file_node_id, self.ctx, self.parent) return None diff --git a/src/codegen/sdk/typescript/detached_symbols/jsx/element.py b/src/codegen/sdk/typescript/detached_symbols/jsx/element.py index 5682f0fd3..f640f543e 100644 --- a/src/codegen/sdk/typescript/detached_symbols/jsx/element.py +++ b/src/codegen/sdk/typescript/detached_symbols/jsx/element.py @@ -15,7 +15,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.dataclasses.usage import UsageKind from codegen.sdk.core.interfaces.editable import Editable from codegen.sdk.core.node_id_factory import NodeId @@ -30,8 +30,8 @@ class JSXElement(Expression[Parent], HasName, Generic[Parent]): _name_node: Name | None - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: Parent) -> None: - super().__init__(ts_node, file_node_id, G, parent) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: Parent) -> None: + super().__init__(ts_node, file_node_id, ctx, parent) open_tag = self.ts_node.child_by_field_name("open_tag") or self.ts_node name_node = open_tag.child_by_field_name("name") self._name_node = self._parse_expression(name_node, default=Name) @@ -80,7 +80,7 @@ def _attribute_nodes(self) -> list[Editable]: """Returns all attribute nodes of the element""" open_tag = self.ts_node.child_by_field_name("open_tag") or self.ts_node attribute_nodes = open_tag.children_by_field_name("attribute") - return [Value(x, self.file_node_id, self.G, self) for x in attribute_nodes] + return [Value(x, self.file_node_id, self.ctx, self) for x in attribute_nodes] @property @reader diff --git a/src/codegen/sdk/typescript/detached_symbols/jsx/expression.py b/src/codegen/sdk/typescript/detached_symbols/jsx/expression.py index b9f992745..51f44e846 100644 --- a/src/codegen/sdk/typescript/detached_symbols/jsx/expression.py +++ b/src/codegen/sdk/typescript/detached_symbols/jsx/expression.py @@ -54,7 +54,7 @@ def reduce_condition(self, bool_condition: bool, node: Editable) -> None: """ if self.ts_node.parent.type == "jsx_attribute" and not bool_condition: - node.edit(self.G.node_classes.bool_conversion[bool_condition]) + node.edit(self.ctx.node_classes.bool_conversion[bool_condition]) else: self.remove() diff --git a/src/codegen/sdk/typescript/detached_symbols/jsx/prop.py b/src/codegen/sdk/typescript/detached_symbols/jsx/prop.py index 7459146d8..8732cd8dc 100644 --- a/src/codegen/sdk/typescript/detached_symbols/jsx/prop.py +++ b/src/codegen/sdk/typescript/detached_symbols/jsx/prop.py @@ -2,7 +2,7 @@ from tree_sitter import Node as TSNode -from codegen.sdk.codebase.codebase_graph import CodebaseGraph +from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.autocommit import reader, writer from codegen.sdk.core.dataclasses.usage import UsageKind from codegen.sdk.core.expressions import Expression @@ -26,8 +26,8 @@ class JSXProp(Expression["Function | JSXElement | JSXProp"], HasName, HasValue): _name_node: Name | None _expression_node: JSXExpression | None - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: "Function | JSXElement | JSXProp") -> None: - super().__init__(ts_node, file_node_id, G, parent) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: "Function | JSXElement | JSXProp") -> None: + super().__init__(ts_node, file_node_id, ctx, parent) self._name_node = self._parse_expression(self.ts_node.children[0], default=Name) if len(self.ts_node.children) > 2: self._value_node = self._parse_expression(self.ts_node.children[2]) diff --git a/src/codegen/sdk/typescript/enum_definition.py b/src/codegen/sdk/typescript/enum_definition.py index 2da12ef4a..faacc6e32 100644 --- a/src/codegen/sdk/typescript/enum_definition.py +++ b/src/codegen/sdk/typescript/enum_definition.py @@ -14,7 +14,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.detached_symbols.code_block import CodeBlock from codegen.sdk.core.expressions import Expression from codegen.sdk.core.interfaces.has_name import HasName @@ -44,11 +44,11 @@ def __init__( self, ts_node: TSNode, file_id: NodeId, - G: CodebaseGraph, + ctx: CodebaseContext, parent: Statement[CodeBlock[Parent, ...]], ) -> None: name_node = ts_node.child_by_field_name("name") - super().__init__(ts_node, file_id, G, parent, name_node=name_node) + super().__init__(ts_node, file_id, ctx, parent, name_node=name_node) self.body = self._parse_expression(ts_node.child_by_field_name("body")) @property diff --git a/src/codegen/sdk/typescript/export.py b/src/codegen/sdk/typescript/export.py index 3ce36c824..44703749c 100644 --- a/src/codegen/sdk/typescript/export.py +++ b/src/codegen/sdk/typescript/export.py @@ -32,7 +32,7 @@ from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.codebase.resolution_stack import ResolutionStack from codegen.sdk.core.interfaces.exportable import Exportable from codegen.sdk.core.interfaces.has_name import HasName @@ -62,7 +62,7 @@ def __init__( ts_node: TSNode, file_node_id: NodeId, parent: Collection[TSExport, ExportStatement[TSExport]], - G: CodebaseGraph, + ctx: CodebaseContext, name_node: TSNode | None = None, declared_symbol: TSSymbol | TSImport | None = None, exported_symbol: TSNode | None = None, @@ -73,7 +73,7 @@ def __init__( msg = "The exported symbol name must match the declared symbol name" raise ValueError(msg) - super().__init__(ts_node, file_node_id, G, parent) + super().__init__(ts_node, file_node_id, ctx, parent) self._name_node = self._parse_expression(name_node, default=Name) self._declared_symbol = declared_symbol self._exported_symbol = self._parse_expression(exported_symbol, default=Name) @@ -81,57 +81,65 @@ def __init__( # self.node_id = NodeIdFactory.export_node_id(name=f"wildcard_export_<{self._declared_symbol.node_id}>", file_id=self.file_node_id, is_default=self.is_default_export()) # else: # self.node_id = NodeIdFactory.export_node_id(name=self.name, file_id=self.file_node_id, is_default=self.is_default_export()) - self.parse(G) + self.parse(ctx) self._value_node = self._parse_expression(value_node) @classmethod @noapidoc - def from_export_statement_with_declaration(cls, export_statement: TSNode, declaration: TSNode, file_id: NodeId, G: CodebaseGraph, parent: ExportStatement[TSExport], pos: int) -> list[TSExport]: + def from_export_statement_with_declaration( + cls, + export_statement: TSNode, + declaration: TSNode, + file_id: NodeId, + ctx: CodebaseContext, + parent: ExportStatement[TSExport], + pos: int, + ) -> list[TSExport]: declared_symbols = [] # =====[ Symbol Definitions ]===== if declaration.type in ["function_declaration", "generator_function_declaration"]: # e.g. export function* namedGenerator() {} - declared_symbols.append(TSFunction(declaration, file_id, G, parent)) + declared_symbols.append(TSFunction(declaration, file_id, ctx, parent)) elif declaration.type == "class_declaration": # e.g. export class NamedClass {} - declared_symbols.append(TSClass(declaration, file_id, G, parent)) + declared_symbols.append(TSClass(declaration, file_id, ctx, parent)) elif declaration.type in ["variable_declaration", "lexical_declaration"]: if len(arrow_functions := find_all_descendants(declaration, {"arrow_function"}, max_depth=2)) > 0: # e.g. export const arrowFunction = () => {}, but not export const a = { func: () => null } for arrow_func in arrow_functions: - declared_symbols.append(TSFunction.from_function_type(arrow_func, file_id, G, parent)) + declared_symbols.append(TSFunction.from_function_type(arrow_func, file_id, ctx, parent)) else: # e.g. export const a = value; for child in declaration.named_children: if child.type in TSAssignmentStatement.assignment_types: - s = TSAssignmentStatement.from_assignment(declaration, file_id, G, parent.parent, pos, assignment_node=child) + s = TSAssignmentStatement.from_assignment(declaration, file_id, ctx, parent.parent, pos, assignment_node=child) declared_symbols.extend(s.assignments) elif declaration.type == "interface_declaration": # e.g. export interface MyInterface {} - declared_symbols.append(TSInterface(declaration, file_id, G, parent)) + declared_symbols.append(TSInterface(declaration, file_id, ctx, parent)) elif declaration.type == "type_alias_declaration": # e.g. export type MyType = {} - declared_symbols.append(TSTypeAlias(declaration, file_id, G, parent)) + declared_symbols.append(TSTypeAlias(declaration, file_id, ctx, parent)) elif declaration.type == "enum_declaration": # e.g. export enum MyEnum {} - declared_symbols.append(TSEnum(declaration, file_id, G, parent)) + declared_symbols.append(TSEnum(declaration, file_id, ctx, parent)) elif declaration.type == "internal_module": # e.g. export namespace MyNamespace {} - declared_symbols.append(TSNamespace(declaration, file_id, G, parent)) + declared_symbols.append(TSNamespace(declaration, file_id, ctx, parent)) else: declared_symbols.append(None) exports = [] for declared_symbol in declared_symbols: name_node = declared_symbol._name_node.ts_node if declared_symbol and declared_symbol._name_node else declaration - export = cls(ts_node=declaration, file_node_id=file_id, G=G, name_node=name_node, declared_symbol=declared_symbol, parent=parent.exports) + export = cls(ts_node=declaration, file_node_id=file_id, ctx=ctx, name_node=name_node, declared_symbol=declared_symbol, parent=parent.exports) exports.append(export) return exports @classmethod @noapidoc - def from_export_statement_with_value(cls, export_statement: TSNode, value: TSNode, file_id: NodeId, G: CodebaseGraph, parent: ExportStatement[TSExport], pos: int) -> list[TSExport]: + def from_export_statement_with_value(cls, export_statement: TSNode, value: TSNode, file_id: NodeId, ctx: CodebaseContext, parent: ExportStatement[TSExport], pos: int) -> list[TSExport]: declared_symbols = [] exported_name_and_symbol = [] # tuple of export name node and export symbol name detached_value_node = None @@ -153,9 +161,9 @@ def from_export_statement_with_value(cls, export_statement: TSNode, value: TSNod key_value = child.child_by_field_name("key") pair_value = child.child_by_field_name("value") if pair_value.type in [function_type.value for function_type in TSFunctionTypeNames]: - declared_symbols.append(TSFunction(pair_value, file_id, G, parent)) + declared_symbols.append(TSFunction(pair_value, file_id, ctx, parent)) elif pair_value.type == "class": - declared_symbols.append(TSClass(pair_value, file_id, G, parent)) + declared_symbols.append(TSClass(pair_value, file_id, ctx, parent)) else: exported_name_and_symbol.append((key_value, pair_value)) elif child.type == "shorthand_property_identifier": @@ -163,7 +171,7 @@ def from_export_statement_with_value(cls, export_statement: TSNode, value: TSNod elif value.type == "assignment_expression": left = value.child_by_field_name("left") right = value.child_by_field_name("right") - assignment = TSAssignment(value, file_id, G, parent, left, right, left) + assignment = TSAssignment(value, file_id, ctx, parent, left, right, left) declared_symbols.append(assignment) else: # Other values are detached symbols: array, number, string, true, null, undefined, new_expression, call_expression @@ -177,15 +185,15 @@ def from_export_statement_with_value(cls, export_statement: TSNode, value: TSNod name_node = value else: name_node = declared_symbol._name_node.ts_node if declared_symbol._name_node else declared_symbol.ts_node - export = cls(ts_node=export_statement, file_node_id=file_id, G=G, name_node=name_node, declared_symbol=declared_symbol, value_node=detached_value_node, parent=parent.exports) + export = cls(ts_node=export_statement, file_node_id=file_id, ctx=ctx, name_node=name_node, declared_symbol=declared_symbol, value_node=detached_value_node, parent=parent.exports) exports.append(export) for name_node, symbol_name_node in exported_name_and_symbol: - exports.append(cls(ts_node=export_statement, file_node_id=file_id, G=G, name_node=name_node, exported_symbol=symbol_name_node, value_node=detached_value_node, parent=parent.exports)) + exports.append(cls(ts_node=export_statement, file_node_id=file_id, ctx=ctx, name_node=name_node, exported_symbol=symbol_name_node, value_node=detached_value_node, parent=parent.exports)) return exports @noapidoc @commiter - def parse(self, G: CodebaseGraph) -> None: + def parse(self, ctx: CodebaseContext) -> None: pass @noapidoc @@ -194,7 +202,7 @@ def _compute_dependencies(self, usage_type: UsageKind | None = None, dest: HasNa if self.exported_symbol: for frame in self.resolved_type_frames: if frame.parent_frame: - frame.parent_frame.add_usage(self._name_node or self, UsageKind.EXPORTED_SYMBOL, self, self.G) + frame.parent_frame.add_usage(self._name_node or self, UsageKind.EXPORTED_SYMBOL, self, self.ctx) elif self._exported_symbol: if not self.resolve_name(self._exported_symbol.source): self._exported_symbol._compute_dependencies(UsageKind.BODY, dest=dest or self) @@ -206,20 +214,20 @@ def _compute_dependencies(self, usage_type: UsageKind | None = None, dest: HasNa def compute_export_dependencies(self) -> None: """Create Export edges from this export to it's used symbols""" if self.declared_symbol is not None: - assert self.G.has_node(self.declared_symbol.node_id) - self.G.add_edge(self.node_id, self.declared_symbol.node_id, type=EdgeType.EXPORT) + assert self.ctx.has_node(self.declared_symbol.node_id) + self.ctx.add_edge(self.node_id, self.declared_symbol.node_id, type=EdgeType.EXPORT) elif self._exported_symbol is not None: symbol_name = self._exported_symbol.source - if (used_node := self.resolve_name(symbol_name)) and isinstance(used_node, Importable) and self.G.has_node(used_node.node_id): - self.G.add_edge(self.node_id, used_node.node_id, type=EdgeType.EXPORT) + if (used_node := self.resolve_name(symbol_name)) and isinstance(used_node, Importable) and self.ctx.has_node(used_node.node_id): + self.ctx.add_edge(self.node_id, used_node.node_id, type=EdgeType.EXPORT) elif self.value is not None: if isinstance(self.value, Chainable): for resolved in self.value.resolved_types: - if self.G.has_node(getattr(resolved, "node_id", None)): - self.G.add_edge(self.node_id, resolved.node_id, type=EdgeType.EXPORT) + if self.ctx.has_node(getattr(resolved, "node_id", None)): + self.ctx.add_edge(self.node_id, resolved.node_id, type=EdgeType.EXPORT) elif self.name is None: # This is the export *; case - self.G.add_edge(self.node_id, self.file_node_id, type=EdgeType.EXPORT) + self.ctx.add_edge(self.node_id, self.file_node_id, type=EdgeType.EXPORT) if self.is_wildcard_export(): for file in self.file.importers: file.__dict__.pop("valid_symbol_names", None) @@ -368,7 +376,7 @@ def exported_symbol(self) -> Exportable | None: Returns: Exportable | None: The exported symbol, file, or import, or None if no symbol is exported. """ - return next(iter(self.G.successors(self.node_id, edge_type=EdgeType.EXPORT)), None) + return next(iter(self.ctx.successors(self.node_id, edge_type=EdgeType.EXPORT)), None) @property @reader diff --git a/src/codegen/sdk/typescript/expressions/chained_attribute.py b/src/codegen/sdk/typescript/expressions/chained_attribute.py index 5277ceb20..87734848c 100644 --- a/src/codegen/sdk/typescript/expressions/chained_attribute.py +++ b/src/codegen/sdk/typescript/expressions/chained_attribute.py @@ -21,8 +21,8 @@ class TSChainedAttribute(ChainedAttribute[Expression, Name, Parent], Generic[Par and property components of the expression, as well as analyzing function calls made on the object. """ - def __init__(self, ts_node, file_node_id, G, parent: Parent): - super().__init__(ts_node, file_node_id, G, parent=parent, object=ts_node.child_by_field_name("object"), attribute=ts_node.child_by_field_name("property")) + def __init__(self, ts_node, file_node_id, ctx, parent: Parent): + super().__init__(ts_node, file_node_id, ctx, parent=parent, object=ts_node.child_by_field_name("object"), attribute=ts_node.child_by_field_name("property")) @property @reader diff --git a/src/codegen/sdk/typescript/expressions/conditional_type.py b/src/codegen/sdk/typescript/expressions/conditional_type.py index fce03749f..654876e4a 100644 --- a/src/codegen/sdk/typescript/expressions/conditional_type.py +++ b/src/codegen/sdk/typescript/expressions/conditional_type.py @@ -12,7 +12,7 @@ from codegen.shared.decorators.docs import noapidoc, ts_apidoc if TYPE_CHECKING: - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.typescript.expressions.type import TSType @@ -38,8 +38,8 @@ class TSConditionalType(Type[Parent], Generic[Parent]): consequence: "TSType[Self]" alternative: "TSType[Self]" - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: "CodebaseGraph", parent: Parent): - super().__init__(ts_node, file_node_id, G, parent) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: "CodebaseContext", parent: Parent): + super().__init__(ts_node, file_node_id, ctx, parent) self.left = self.child_by_field_name("left") self.right = self.child_by_field_name("right") self.consequence = self.child_by_field_name("consequence") diff --git a/src/codegen/sdk/typescript/expressions/expression_type.py b/src/codegen/sdk/typescript/expressions/expression_type.py index 6f40dd3e1..8a866bb60 100644 --- a/src/codegen/sdk/typescript/expressions/expression_type.py +++ b/src/codegen/sdk/typescript/expressions/expression_type.py @@ -8,7 +8,7 @@ from codegen.shared.decorators.docs import ts_apidoc if TYPE_CHECKING: - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.interfaces.editable import Editable Parent = TypeVar("Parent", bound="Editable") @@ -24,6 +24,6 @@ class TSExpressionType(TSNamedType, Generic[Parent]): expression: Expression["TSExpressionType[Parent]"] - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: "CodebaseGraph", parent: Parent): - super().__init__(ts_node, file_node_id, G, parent) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: "CodebaseContext", parent: Parent): + super().__init__(ts_node, file_node_id, ctx, parent) self.expression = self._parse_expression(ts_node) diff --git a/src/codegen/sdk/typescript/expressions/function_type.py b/src/codegen/sdk/typescript/expressions/function_type.py index 14126c02d..85807bade 100644 --- a/src/codegen/sdk/typescript/expressions/function_type.py +++ b/src/codegen/sdk/typescript/expressions/function_type.py @@ -15,7 +15,7 @@ from codegen.shared.decorators.docs import noapidoc, ts_apidoc if TYPE_CHECKING: - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.typescript.expressions.type import TSType @@ -38,12 +38,12 @@ class TSFunctionType(Type[Parent], Generic[Parent]): _parameters: Collection[TSParameter, Self] name: None = None - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: "CodebaseGraph", parent: Parent): - super().__init__(ts_node, file_node_id, G, parent) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: "CodebaseContext", parent: Parent): + super().__init__(ts_node, file_node_id, ctx, parent) self.return_type = self.child_by_field_name("return_type", placeholder=TSReturnTypePlaceholder) params_node = self.ts_node.child_by_field_name("parameters") params = [TSParameter(child, idx, self) for idx, child in enumerate(params_node.named_children) if child.type != "comment"] - self._parameters = Collection(params_node, file_node_id, G, self, children=params) + self._parameters = Collection(params_node, file_node_id, ctx, self, children=params) @property @reader diff --git a/src/codegen/sdk/typescript/expressions/generic_type.py b/src/codegen/sdk/typescript/expressions/generic_type.py index 71c0b9971..6e43572a7 100644 --- a/src/codegen/sdk/typescript/expressions/generic_type.py +++ b/src/codegen/sdk/typescript/expressions/generic_type.py @@ -27,4 +27,4 @@ def _get_name_node(self) -> TSNode: def _get_parameters(self) -> Collection[Self, Self] | Dict[Self, Self] | None: type_parameter = self.child_by_field_types("type_arguments").ts_node types = [self._parse_type(child) for child in type_parameter.named_children] - return Collection(node=type_parameter, file_node_id=self.file_node_id, G=self.G, parent=self, children=types) + return Collection(node=type_parameter, file_node_id=self.file_node_id, ctx=self.ctx, parent=self, children=types) diff --git a/src/codegen/sdk/typescript/expressions/lookup_type.py b/src/codegen/sdk/typescript/expressions/lookup_type.py index 207747296..1885b9545 100644 --- a/src/codegen/sdk/typescript/expressions/lookup_type.py +++ b/src/codegen/sdk/typescript/expressions/lookup_type.py @@ -13,7 +13,7 @@ from codegen.shared.decorators.docs import noapidoc, ts_apidoc if TYPE_CHECKING: - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.typescript.expressions.type import TSType @@ -35,8 +35,8 @@ class TSLookupType(Type[Parent], Generic[Parent]): type: "TSType[Self]" lookup: Expression - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: "CodebaseGraph", parent: Parent): - super().__init__(ts_node, file_node_id, G, parent) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: "CodebaseContext", parent: Parent): + super().__init__(ts_node, file_node_id, ctx, parent) self.type = self._parse_type(ts_node.named_children[0]) if literal_type := self.child_by_field_types("literal_type"): self.lookup = self._parse_expression(literal_type.ts_node.named_children[0]) diff --git a/src/codegen/sdk/typescript/expressions/object_type.py b/src/codegen/sdk/typescript/expressions/object_type.py index 63f5c3cd6..87b91096c 100644 --- a/src/codegen/sdk/typescript/expressions/object_type.py +++ b/src/codegen/sdk/typescript/expressions/object_type.py @@ -12,7 +12,7 @@ from codegen.shared.decorators.docs import ts_apidoc if TYPE_CHECKING: - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext import logging @@ -38,12 +38,12 @@ def _get_key_value(self) -> tuple[Expression[Self] | None, Expression[Self] | No value = self._parse_expression(type_node) key = self._parse_expression(self.ts_node.child_by_field_name("name")) elif self.ts_node_type == "call_signature": - value = TSFunctionType(self.ts_node, self.file_node_id, self.G, self) + value = TSFunctionType(self.ts_node, self.file_node_id, self.ctx, self) elif self.ts_node_type == "index_signature": value = self._parse_expression(self.ts_node.child_by_field_name("type")) key = self._parse_expression(self.ts_node.named_children[0]) elif self.ts_node_type == "method_signature": - value = TSFunctionType(self.ts_node, self.file_node_id, self.G, self) + value = TSFunctionType(self.ts_node, self.file_node_id, self.ctx, self) key = self._parse_expression(self.ts_node.child_by_field_name("name")) elif self.ts_node_type == "method_definition": key = self._parse_expression(self.ts_node.child_by_field_name("mapped_clause_type")) @@ -72,8 +72,8 @@ class TSObjectType(TSDict, Type[Parent], Generic[Parent]): in TypeScript code. """ - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: "CodebaseGraph", parent: Parent) -> None: - super().__init__(ts_node, file_node_id, G, parent, delimiter=";", pair_type=TSObjectPair) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: "CodebaseContext", parent: Parent) -> None: + super().__init__(ts_node, file_node_id, ctx, parent, delimiter=";", pair_type=TSObjectPair) def _compute_dependencies(self, usage_type: UsageKind, dest: Importable): for child in self.values(): diff --git a/src/codegen/sdk/typescript/expressions/query_type.py b/src/codegen/sdk/typescript/expressions/query_type.py index 80a678cc1..1fde11789 100644 --- a/src/codegen/sdk/typescript/expressions/query_type.py +++ b/src/codegen/sdk/typescript/expressions/query_type.py @@ -12,7 +12,7 @@ from codegen.shared.decorators.docs import noapidoc, ts_apidoc if TYPE_CHECKING: - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.typescript.expressions.type import TSType @@ -32,8 +32,8 @@ class TSQueryType(Type[Parent], Generic[Parent]): query: "TSType[Self]" - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: "CodebaseGraph", parent: Parent): - super().__init__(ts_node, file_node_id, G, parent) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: "CodebaseContext", parent: Parent): + super().__init__(ts_node, file_node_id, ctx, parent) self.query = self._parse_type(ts_node.named_children[0]) @property diff --git a/src/codegen/sdk/typescript/expressions/readonly_type.py b/src/codegen/sdk/typescript/expressions/readonly_type.py index 865b1528f..40e12083f 100644 --- a/src/codegen/sdk/typescript/expressions/readonly_type.py +++ b/src/codegen/sdk/typescript/expressions/readonly_type.py @@ -12,7 +12,7 @@ from codegen.shared.decorators.docs import noapidoc, ts_apidoc if TYPE_CHECKING: - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.typescript.expressions.type import TSType @@ -32,8 +32,8 @@ class TSReadonlyType(Type[Parent], Generic[Parent]): type: "TSType[Self]" - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: "CodebaseGraph", parent: Parent): - super().__init__(ts_node, file_node_id, G, parent) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: "CodebaseContext", parent: Parent): + super().__init__(ts_node, file_node_id, ctx, parent) self.type = self._parse_type(ts_node.named_children[0]) @property diff --git a/src/codegen/sdk/typescript/expressions/string.py b/src/codegen/sdk/typescript/expressions/string.py index 04d80ab06..1b078abd7 100644 --- a/src/codegen/sdk/typescript/expressions/string.py +++ b/src/codegen/sdk/typescript/expressions/string.py @@ -7,7 +7,7 @@ from codegen.shared.decorators.docs import ts_apidoc if TYPE_CHECKING: - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext Parent = TypeVar("Parent", bound="Expression") @@ -26,8 +26,8 @@ class TSString(String, Generic[Parent]): Empty for regular string literals. """ - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: "CodebaseGraph", parent: Parent) -> None: - super().__init__(ts_node, file_node_id, G, parent=parent) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: "CodebaseContext", parent: Parent) -> None: + super().__init__(ts_node, file_node_id, ctx, parent=parent) if ts_node.type == "template_string": substitutions = [x for x in ts_node.named_children if x.type == "template_substitution"] self.expressions = [self._parse_expression(x.named_children[0]) for x in substitutions] diff --git a/src/codegen/sdk/typescript/expressions/ternary_expression.py b/src/codegen/sdk/typescript/expressions/ternary_expression.py index aa141978d..a10d70667 100644 --- a/src/codegen/sdk/typescript/expressions/ternary_expression.py +++ b/src/codegen/sdk/typescript/expressions/ternary_expression.py @@ -13,8 +13,8 @@ class TSTernaryExpression(TernaryExpression[Parent]): """Any ternary expression in the code where a condition will determine branched execution""" - def __init__(self, ts_node, file_node_id, G, parent: Parent) -> None: - super().__init__(ts_node, file_node_id, G, parent=parent) + def __init__(self, ts_node, file_node_id, ctx, parent: Parent) -> None: + super().__init__(ts_node, file_node_id, ctx, parent=parent) self.condition = self.child_by_field_name("condition") self.consequence = self.child_by_field_name("consequence") self.alternative = self.child_by_field_name("alternative") diff --git a/src/codegen/sdk/typescript/file.py b/src/codegen/sdk/typescript/file.py index 852947fcc..a132a125d 100644 --- a/src/codegen/sdk/typescript/file.py +++ b/src/codegen/sdk/typescript/file.py @@ -23,7 +23,7 @@ from codegen.shared.decorators.docs import noapidoc, ts_apidoc if TYPE_CHECKING: - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.statements.export_statement import ExportStatement from codegen.sdk.core.symbol import Symbol from codegen.sdk.typescript.symbol import TSSymbol @@ -232,11 +232,11 @@ def _parse_imports(self) -> None: import_nodes = find_all_descendants(self.ts_node, {"import_statement", "call_expression"}) for import_node in import_nodes: if import_node.type == "import_statement": - TSImportStatement(import_node, self.node_id, self.G, self.code_block, 0) + TSImportStatement(import_node, self.node_id, self.ctx, self.code_block, 0) elif import_node.type == "call_expression": function = import_node.child_by_field_name("function") if function.type == "import" or (function.type == "identifier" and function.text.decode("utf-8") == "require"): - TSImportStatement(import_node, self.node_id, self.G, self.code_block, 0) + TSImportStatement(import_node, self.node_id, self.ctx, self.code_block, 0) @writer def remove_unused_exports(self) -> None: @@ -356,7 +356,7 @@ def get_export_statement_for_path(self, relative_path: str, export_type: str = " return None @noapidoc - def get_import_module_name_for_file(self, filepath: str, G: CodebaseGraph) -> str: + def get_import_module_name_for_file(self, filepath: str, ctx: CodebaseContext) -> str: """Returns the module name that this file gets imported as""" # TODO: support relative and absolute module path import_path = filepath @@ -418,7 +418,7 @@ def update_filepath(self, new_filepath: str) -> None: None """ # =====[ Add the new filepath as a new file node in the graph ]===== - new_file = self.G.node_classes.file_cls.from_content(new_filepath, self.content, self.G) + new_file = self.ctx.node_classes.file_cls.from_content(new_filepath, self.content, self.ctx) # =====[ Change the file on disk ]===== self.transaction_manager.add_file_rename_transaction(self, new_filepath) # =====[ Update all the inbound imports to point to the new module ]===== @@ -426,7 +426,7 @@ def update_filepath(self, new_filepath: str) -> None: existing_imp = imp.module.source.strip("'") new_module_name = new_file.import_module_name.strip("'") # Web specific hacks - if self.G.repo_name == "web": + if self.ctx.repo_name == "web": if existing_imp.startswith("./"): relpath = calculate_base_path(new_filepath, existing_imp) new_module_name = new_module_name.replace(relpath, ".") diff --git a/src/codegen/sdk/typescript/function.py b/src/codegen/sdk/typescript/function.py index 77f2910b3..8242e5909 100644 --- a/src/codegen/sdk/typescript/function.py +++ b/src/codegen/sdk/typescript/function.py @@ -21,7 +21,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.import_resolution import Import, WildcardImport from codegen.sdk.core.interfaces.has_name import HasName from codegen.sdk.core.node_id_factory import NodeId @@ -39,12 +39,12 @@ class TSFunction(Function["TSFunction", TSDecorator, "TSCodeBlock", TSParameter, @noapidoc @commiter - def parse(self, G: CodebaseGraph) -> None: - super().parse(G) + def parse(self, ctx: CodebaseContext) -> None: + super().parse(ctx) self.return_type = self.child_by_field_name("return_type", placeholder=TSReturnTypePlaceholder) if parameters_node := self.ts_node.child_by_field_name("parameters"): - self._parameters = Collection(parameters_node, self.file_node_id, self.G, self) + self._parameters = Collection(parameters_node, self.file_node_id, self.ctx, self) params = [x for x in parameters_node.children if x.type in ("required_parameter", "optional_parameter")] symbols = None # Deconstructed object parameters @@ -61,7 +61,7 @@ def parse(self, G: CodebaseGraph) -> None: symbols = [TSParameter(x, i, self._parameters) for (i, x) in enumerate(params)] self._parameters._init_children(symbols) elif parameters_node := self.ts_node.child_by_field_name("parameter"): - self._parameters = Collection(parameters_node, self.file_node_id, self.G, self) + self._parameters = Collection(parameters_node, self.file_node_id, self.ctx, self) self._parameters._init_children([TSParameter(parameters_node, 0, self._parameters)]) else: logger.warning(f"Couldn't find parameters for {self!r}") @@ -110,15 +110,15 @@ def _compute_dependencies(self, usage_type: UsageKind | None = None, dest: HasNa @classmethod @noapidoc - def from_function_type(cls, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: SymbolStatement | ExportStatement) -> TSFunction: + def from_function_type(cls, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: SymbolStatement | ExportStatement) -> TSFunction: """Creates a TSFunction object from a function declaration.""" if ts_node.type not in [function_type.value for function_type in TSFunctionTypeNames]: msg = f"Node type={ts_node.type} is not a function declaration" raise ValueError(msg) - file = G.get_node(file_node_id) + file = ctx.get_node(file_node_id) if canonical := file._range_index.get_canonical_for_range(ts_node.range, ts_node.kind_id): return canonical - return cls(ts_node, file_node_id, G, parent=parent) + return cls(ts_node, file_node_id, ctx, parent=parent) @staticmethod @noapidoc diff --git a/src/codegen/sdk/typescript/import_resolution.py b/src/codegen/sdk/typescript/import_resolution.py index 51efda9e0..5954c5304 100644 --- a/src/codegen/sdk/typescript/import_resolution.py +++ b/src/codegen/sdk/typescript/import_resolution.py @@ -17,7 +17,7 @@ from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.external_module import ExternalModule from codegen.sdk.core.interfaces.editable import Editable from codegen.sdk.core.node_id_factory import NodeId @@ -216,7 +216,7 @@ def resolve_import(self, base_path: str | None = None, *, add_module_name: str | - imports_file: True if importing the entire file/module """ self.file: TSFile # Type cast ts_file - base_path = base_path or self.G.projects[0].base_path or "" + base_path = base_path or self.ctx.projects[0].base_path or "" # Get the import source path import_source = self.module.source.strip('"').strip("'") if self.module else "" @@ -246,7 +246,7 @@ def resolve_import(self, base_path: str | None = None, *, add_module_name: str | if "." not in import_name: possible_paths = ["index.ts", "index.js", "index.tsx", "index.jsx"] for p_path in possible_paths: - if self.G.to_absolute(os.path.join(import_source, p_path)).exists(): + if self.ctx.to_absolute(os.path.join(import_source, p_path)).exists(): import_source = os.path.join(import_source, p_path) break @@ -256,7 +256,7 @@ def resolve_import(self, base_path: str | None = None, *, add_module_name: str | for import_source_base in (import_source, os.path.splitext(import_source)[0]): for extension in extensions: import_source_ext = import_source_base + extension - if file := self.G.get_file(import_source_ext): + if file := self.ctx.get_file(import_source_ext): if self.is_module_import(): return ImportResolution(from_file=file, symbol=None, imports_file=True) else: @@ -288,7 +288,7 @@ def _relative_to_absolute_import(self, relative_import: str) -> str: @classmethod @noapidoc - def from_export_statement(cls, source_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: TSImportStatement) -> list[TSImport]: + def from_export_statement(cls, source_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: TSImportStatement) -> list[TSImport]: """Constructs import objects defined from an export statement""" export_statement_node = find_first_ancestor(source_node, ["export_statement"]) imports = [] @@ -299,7 +299,7 @@ def from_export_statement(cls, source_node: TSNode, file_node_id: NodeId, G: Cod name = export_specifier.child_by_field_name("name") alias = export_specifier.child_by_field_name("alias") or name import_type = ImportType.DEFAULT_EXPORT if (name and name.text.decode("utf-8") == "default") else ImportType.NAMED_EXPORT - imp = cls(ts_node=export_statement_node, file_node_id=file_node_id, G=G, parent=parent, module_node=source_node, name_node=name, alias_node=alias, import_type=import_type) + imp = cls(ts_node=export_statement_node, file_node_id=file_node_id, ctx=ctx, parent=parent, module_node=source_node, name_node=name, alias_node=alias, import_type=import_type) imports.append(imp) else: # ==== [ Wildcard export import ] ==== @@ -310,7 +310,7 @@ def from_export_statement(cls, source_node: TSNode, file_node_id: NodeId, G: Cod imp = cls( ts_node=export_statement_node, file_node_id=file_node_id, - G=G, + ctx=ctx, parent=parent, module_node=source_node, name_node=namespace_export, @@ -320,19 +320,19 @@ def from_export_statement(cls, source_node: TSNode, file_node_id: NodeId, G: Cod imports.append(imp) else: # No alias wildcard export (e.g. export * from './m';) - imp = cls(ts_node=export_statement_node, file_node_id=file_node_id, G=G, parent=parent, module_node=source_node, name_node=None, alias_node=None, import_type=ImportType.WILDCARD) + imp = cls(ts_node=export_statement_node, file_node_id=file_node_id, ctx=ctx, parent=parent, module_node=source_node, name_node=None, alias_node=None, import_type=ImportType.WILDCARD) imports.append(imp) return imports @classmethod @noapidoc - def from_import_statement(cls, import_statement_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: TSImportStatement) -> list[TSImport]: + def from_import_statement(cls, import_statement_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: TSImportStatement) -> list[TSImport]: source_node = import_statement_node.child_by_field_name("source") import_clause = next((x for x in import_statement_node.named_children if x.type == "import_clause"), None) if import_clause is None: # === [ Side effect module import ] === # Will not have any import usages in the file! (e.g. import './module';) - return [cls(ts_node=import_statement_node, file_node_id=file_node_id, G=G, parent=parent, module_node=source_node, name_node=None, alias_node=None, import_type=ImportType.SIDE_EFFECT)] + return [cls(ts_node=import_statement_node, file_node_id=file_node_id, ctx=ctx, parent=parent, module_node=source_node, name_node=None, alias_node=None, import_type=ImportType.SIDE_EFFECT)] imports = [] for import_type_node in import_clause.named_children: @@ -342,7 +342,7 @@ def from_import_statement(cls, import_statement_node: TSNode, file_node_id: Node imp = cls( ts_node=import_statement_node, file_node_id=file_node_id, - G=G, + ctx=ctx, parent=parent, module_node=source_node, name_node=import_type_node, @@ -363,7 +363,7 @@ def from_import_statement(cls, import_statement_node: TSNode, file_node_id: Node imp = cls( ts_node=import_statement_node, file_node_id=file_node_id, - G=G, + ctx=ctx, parent=parent, module_node=source_node, name_node=name_node, @@ -378,7 +378,7 @@ def from_import_statement(cls, import_statement_node: TSNode, file_node_id: Node imp = cls( ts_node=import_statement_node, file_node_id=file_node_id, - G=G, + ctx=ctx, module_node=source_node, parent=parent, name_node=import_type_node, @@ -390,7 +390,7 @@ def from_import_statement(cls, import_statement_node: TSNode, file_node_id: Node @classmethod @noapidoc - def from_dynamic_import_statement(cls, import_call_node: TSNode, module_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: ImportStatement) -> list[TSImport]: + def from_dynamic_import_statement(cls, import_call_node: TSNode, module_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: ImportStatement) -> list[TSImport]: """Parses a dynamic import statement, given a reference to the `import`/`require` node and `module` node. e.g. const myModule = await import('./someFile')`; @@ -423,7 +423,7 @@ def from_dynamic_import_statement(cls, import_call_node: TSNode, module_node: TS if import_statement_node.type == "expression_statement": # ==== [ Side effect module import ] ==== # Will not have any import usages in the file! (e.g. await import('./module');) - imp = cls(ts_node=import_statement_node, file_node_id=file_node_id, G=G, parent=parent, module_node=module_node, name_node=None, alias_node=None, import_type=ImportType.SIDE_EFFECT) + imp = cls(ts_node=import_statement_node, file_node_id=file_node_id, ctx=ctx, parent=parent, module_node=module_node, name_node=None, alias_node=None, import_type=ImportType.SIDE_EFFECT) imports.append(imp) else: if import_statement_node.type == "member_expression": @@ -445,7 +445,7 @@ def from_dynamic_import_statement(cls, import_call_node: TSNode, module_node: TS if name_node is None: alias_node = import_statement_node.child_by_field_name("name") or import_statement_node.child_by_field_name("left") imp = cls( - ts_node=import_statement_node, file_node_id=file_node_id, G=G, parent=parent, module_node=module_node, name_node=None, alias_node=alias_node, import_type=ImportType.SIDE_EFFECT + ts_node=import_statement_node, file_node_id=file_node_id, ctx=ctx, parent=parent, module_node=module_node, name_node=None, alias_node=alias_node, import_type=ImportType.SIDE_EFFECT ) imports.append(imp) return imports @@ -463,12 +463,12 @@ def from_dynamic_import_statement(cls, import_call_node: TSNode, module_node: TS else: alias_node = name_node import_type = ImportType.DEFAULT_EXPORT if name_node.text.decode("utf-8") == "default" else ImportType.NAMED_EXPORT - imp = cls(ts_node=statement_node, file_node_id=file_node_id, G=G, parent=parent, module_node=module_node, name_node=name_node, alias_node=alias_node, import_type=import_type) + imp = cls(ts_node=statement_node, file_node_id=file_node_id, ctx=ctx, parent=parent, module_node=module_node, name_node=name_node, alias_node=alias_node, import_type=import_type) imports.append(imp) elif name_node.type == "identifier": # ==== [ Aliased module import ] ==== # Imports both default and named exports (e.g. const moduleImp = await import('./module');) - imp = cls(ts_node=statement_node, file_node_id=file_node_id, G=G, parent=parent, module_node=module_node, name_node=name_node, alias_node=name_node, import_type=ImportType.MODULE) + imp = cls(ts_node=statement_node, file_node_id=file_node_id, ctx=ctx, parent=parent, module_node=module_node, name_node=name_node, alias_node=name_node, import_type=ImportType.MODULE) imports.append(imp) elif name_node.type == "object_pattern": # ==== [ Deconstructed import ] ==== @@ -479,7 +479,7 @@ def from_dynamic_import_statement(cls, import_call_node: TSNode, module_node: TS imp = cls( ts_node=statement_node, file_node_id=file_node_id, - G=G, + ctx=ctx, parent=parent, module_node=module_node, name_node=imported_symbol, @@ -495,7 +495,7 @@ def from_dynamic_import_statement(cls, import_call_node: TSNode, module_node: TS imp = cls( ts_node=statement_node, file_node_id=file_node_id, - G=G, + ctx=ctx, parent=parent, module_node=module_node, name_node=name_node, @@ -532,10 +532,10 @@ def import_specifier(self) -> Editable: name = import_specifier.child_by_field_name("name") is_match = self.symbol_name.source == name.text.decode("utf-8") if is_match: - return Name(import_specifier, self.file_node_id, self.G, self) + return Name(import_specifier, self.file_node_id, self.ctx, self) if named := next(iter(find_all_descendants(self.ts_node, {"identifier"})), None): if named.text.decode("utf-8") == self.symbol_name.source: - return Name(named, self.file_node_id, self.G, self) + return Name(named, self.file_node_id, self.ctx, self) @reader def get_import_string(self, alias: str | None = None, module: str | None = None, import_type: ImportType = ImportType.UNKNOWN, is_type_import: bool = False) -> str: diff --git a/src/codegen/sdk/typescript/interface.py b/src/codegen/sdk/typescript/interface.py index 53d891e7d..4107cde7c 100644 --- a/src/codegen/sdk/typescript/interface.py +++ b/src/codegen/sdk/typescript/interface.py @@ -17,7 +17,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.detached_symbols.code_block import CodeBlock from codegen.sdk.core.interfaces.has_name import HasName from codegen.sdk.core.node_id_factory import NodeId @@ -39,12 +39,12 @@ def __init__( self, ts_node: TSNode, file_id: NodeId, - G: CodebaseGraph, + ctx: CodebaseContext, parent: Statement[CodeBlock[Parent, ...]], ) -> None: from codegen.sdk.typescript.detached_symbols.code_block import TSCodeBlock - super().__init__(ts_node, file_id, G, parent) + super().__init__(ts_node, file_id, ctx, parent) body_node = ts_node.child_by_field_name("body") # Find the nearest parent with a code_block @@ -57,12 +57,12 @@ def __init__( @commiter @noapidoc - def parse(self, G: CodebaseGraph) -> None: + def parse(self, ctx: CodebaseContext) -> None: # =====[ Extends ]===== # Look for parent interfaces in the "extends" clause if extends_clause := self.child_by_field_types("extends_type_clause"): - self.parent_interfaces = Parents(extends_clause.ts_node, self.file_node_id, self.G, self) - super().parse(G) + self.parent_interfaces = Parents(extends_clause.ts_node, self.file_node_id, self.ctx, self) + super().parse(ctx) @noapidoc @commiter diff --git a/src/codegen/sdk/typescript/namespace.py b/src/codegen/sdk/typescript/namespace.py index 9d29c16ea..4d1e3f7db 100644 --- a/src/codegen/sdk/typescript/namespace.py +++ b/src/codegen/sdk/typescript/namespace.py @@ -19,7 +19,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.dataclasses.usage import UsageKind from codegen.sdk.core.node_id_factory import NodeId from codegen.sdk.core.statements.statement import Statement @@ -39,10 +39,10 @@ class TSNamespace(TSSymbol, TSHasBlock, HasName): symbol_type = SymbolType.Namespace code_block: TSCodeBlock - def __init__(self, ts_node: TSNode, file_id: NodeId, G: CodebaseGraph, parent: Statement, namespace_node: TSNode | None = None) -> None: + def __init__(self, ts_node: TSNode, file_id: NodeId, ctx: CodebaseContext, parent: Statement, namespace_node: TSNode | None = None) -> None: ts_node = namespace_node or ts_node name_node = ts_node.child_by_field_name("name") - super().__init__(ts_node, file_id, G, parent, name_node=name_node) + super().__init__(ts_node, file_id, ctx, parent, name_node=name_node) @noapidoc @commiter diff --git a/src/codegen/sdk/typescript/statements/assignment_statement.py b/src/codegen/sdk/typescript/statements/assignment_statement.py index 974279168..b1e605de8 100644 --- a/src/codegen/sdk/typescript/statements/assignment_statement.py +++ b/src/codegen/sdk/typescript/statements/assignment_statement.py @@ -12,7 +12,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.node_id_factory import NodeId from codegen.sdk.typescript.detached_symbols.code_block import TSCodeBlock from codegen.sdk.typescript.interfaces.has_block import TSHasBlock @@ -31,7 +31,7 @@ class TSAssignmentStatement(AssignmentStatement["TSCodeBlock", TSAssignment]): @classmethod @reader @noapidoc - def from_assignment(cls, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: TSCodeBlock, pos: int, assignment_node: TSNode) -> TSAssignmentStatement: + def from_assignment(cls, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: TSCodeBlock, pos: int, assignment_node: TSNode) -> TSAssignmentStatement: """Creates an assignment statement node from a TreeSitter assignment node. This class method constructs a TSAssignmentStatement from a TreeSitter node representing an assignment. The method validates that the assignment node type is @@ -40,7 +40,7 @@ def from_assignment(cls, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph Args: ts_node (TSNode): The TreeSitter node representing the entire statement. file_node_id (NodeId): The identifier for the file containing this node. - G (CodebaseGraph): The codebase graph being constructed. + ctx (CodebaseContext): The codebase context being constructed. parent (TSHasBlock): The parent block containing this statement. code_block (TSCodeBlock): The code block containing this statement. pos (int): The position of this statement within its code block. @@ -56,24 +56,24 @@ def from_assignment(cls, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph msg = f"Invalid assignment node type: {assignment_node.type}" raise ValueError(msg) - return cls(ts_node, file_node_id, G, parent, pos, assignment_node=assignment_node) + return cls(ts_node, file_node_id, ctx, parent, pos, assignment_node=assignment_node) def _parse_assignments(self, assignment_node: TSNode) -> MultiExpression[Self, TSAssignment]: if assignment_node.type in ["assignment_expression", "augmented_assignment_expression"]: - return TSAssignment.from_assignment(assignment_node, self.file_node_id, self.G, self) + return TSAssignment.from_assignment(assignment_node, self.file_node_id, self.ctx, self) elif assignment_node.type in ["variable_declarator", "public_field_definition", "property_signature"]: - return TSAssignment.from_named_expression(assignment_node, self.file_node_id, self.G, self) + return TSAssignment.from_named_expression(assignment_node, self.file_node_id, self.ctx, self) logger.info(f"Unknown assignment type: {assignment_node.type}") - return MultiExpression(assignment_node, self.file_node_id, self.G, self.parent, [self.parent._parse_expression(assignment_node)]) + return MultiExpression(assignment_node, self.file_node_id, self.ctx, self.parent, [self.parent._parse_expression(assignment_node)]) def _DEPRECATED_parse_assignments(self) -> MultiExpression[TSHasBlock, TSAssignment]: if self.ts_node.type in ["lexical_declaration", "variable_declaration"]: - return MultiExpression(self.ts_node, self.file_node_id, self.G, self.parent, self._DEPRECATED_parse_assignment_declarations()) + return MultiExpression(self.ts_node, self.file_node_id, self.ctx, self.parent, self._DEPRECATED_parse_assignment_declarations()) elif self.ts_node.type in ["expression_statement"]: - return MultiExpression(self.ts_node, self.file_node_id, self.G, self.parent, self._DEPRECATED_parse_assignment_expression()) + return MultiExpression(self.ts_node, self.file_node_id, self.ctx, self.parent, self._DEPRECATED_parse_assignment_expression()) elif self.ts_node.type in ["public_field_definition", "property_signature", "enum_assignment"]: - return MultiExpression(self.ts_node, self.file_node_id, self.G, self.parent, self._DEPRECATED_parse_attribute_assignments()) + return MultiExpression(self.ts_node, self.file_node_id, self.ctx, self.parent, self._DEPRECATED_parse_attribute_assignments()) else: msg = f"Unknown assignment type: {self.ts_node.type}" raise ValueError(msg) @@ -81,7 +81,7 @@ def _DEPRECATED_parse_assignments(self) -> MultiExpression[TSHasBlock, TSAssignm def _DEPRECATED_parse_attribute_assignments(self) -> list[TSAssignment]: left = self.ts_node.child_by_field_name("name") right = self.ts_node.child_by_field_name("value") - return [TSAssignment(self.ts_node, self.file_node_id, self.G, self, left, right, left)] + return [TSAssignment(self.ts_node, self.file_node_id, self.ctx, self, left, right, left)] def _DEPRECATED_parse_assignment_declarations(self) -> list[TSAssignment]: assignments = [] @@ -101,19 +101,19 @@ def _DEPRECATED_parse_assignment_declarations(self) -> list[TSAssignment]: to_parse.append((value, _type)) # TODO:CG-10064 if value.type == "identifier": # TODO: Support type resolution for aliased object unpacks - assignments.append(TSAssignment(variable_declarator, self.file_node_id, self.G, self, left, right, value)) + assignments.append(TSAssignment(variable_declarator, self.file_node_id, self.ctx, self, left, right, value)) else: key = identifier.child_by_field_name("key") - assignments.append(TSAssignment(variable_declarator, self.file_node_id, self.G, self, left, right, key)) + assignments.append(TSAssignment(variable_declarator, self.file_node_id, self.ctx, self, left, right, key)) else: - assignments.append(TSAssignment(variable_declarator, self.file_node_id, self.G, self, left, right, identifier)) + assignments.append(TSAssignment(variable_declarator, self.file_node_id, self.ctx, self, left, right, identifier)) else: - assignments.append(TSAssignment(variable_declarator, self.file_node_id, self.G, self, left, right, left)) + assignments.append(TSAssignment(variable_declarator, self.file_node_id, self.ctx, self, left, right, left)) while right and right.type == "assignment_expression": left = right.child_by_field_name("left") right = right.child_by_field_name("right") - assignments.append(TSAssignment(variable_declarator, self.file_node_id, self.G, self, left, right, left)) + assignments.append(TSAssignment(variable_declarator, self.file_node_id, self.ctx, self, left, right, left)) return assignments @@ -124,6 +124,6 @@ def _DEPRECATED_parse_assignment_expression(self) -> list[TSAssignment]: continue left = child.child_by_field_name("left") right = child.child_by_field_name("right") - assignments.append(TSAssignment(child, self.file_node_id, self.G, self, left, right, left)) + assignments.append(TSAssignment(child, self.file_node_id, self.ctx, self, left, right, left)) return assignments diff --git a/src/codegen/sdk/typescript/statements/attribute.py b/src/codegen/sdk/typescript/statements/attribute.py index 15d818936..9de9ae260 100644 --- a/src/codegen/sdk/typescript/statements/attribute.py +++ b/src/codegen/sdk/typescript/statements/attribute.py @@ -13,7 +13,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.interfaces.editable import Editable from codegen.sdk.core.node_id_factory import NodeId from codegen.sdk.typescript.interfaces.has_block import TSHasBlock @@ -23,8 +23,8 @@ class TSAttribute(Attribute[TSCodeBlock, TSAssignment], TSAssignmentStatement): """Typescript implementation of Attribute detached symbol.""" - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: TSCodeBlock, pos: int) -> None: - super().__init__(ts_node, file_node_id, G, parent, pos=pos, assignment_node=ts_node) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: TSCodeBlock, pos: int) -> None: + super().__init__(ts_node, file_node_id, ctx, parent, pos=pos, assignment_node=ts_node) self.type = self.assignments[0].type @reader diff --git a/src/codegen/sdk/typescript/statements/catch_statement.py b/src/codegen/sdk/typescript/statements/catch_statement.py index 33cfdf5c5..c6dc10bae 100644 --- a/src/codegen/sdk/typescript/statements/catch_statement.py +++ b/src/codegen/sdk/typescript/statements/catch_statement.py @@ -9,7 +9,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.node_id_factory import NodeId from codegen.sdk.typescript.detached_symbols.code_block import TSCodeBlock @@ -26,6 +26,6 @@ class TSCatchStatement(CatchStatement[Parent], TSBlockStatement, Generic[Parent] condition: The condition which triggers this clause """ - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: Parent, pos: int | None = None) -> None: - super().__init__(ts_node, file_node_id, G, parent, pos) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: Parent, pos: int | None = None) -> None: + super().__init__(ts_node, file_node_id, ctx, parent, pos) self.condition = self.child_by_field_name("parameter") diff --git a/src/codegen/sdk/typescript/statements/for_loop_statement.py b/src/codegen/sdk/typescript/statements/for_loop_statement.py index 30fe2c0d0..23a6e0ca4 100644 --- a/src/codegen/sdk/typescript/statements/for_loop_statement.py +++ b/src/codegen/sdk/typescript/statements/for_loop_statement.py @@ -10,7 +10,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.dataclasses.usage import UsageKind from codegen.sdk.core.detached_symbols.function_call import FunctionCall from codegen.sdk.core.expressions import Expression @@ -42,8 +42,8 @@ class TSForLoopStatement(ForLoopStatement["TSCodeBlock"], TSBlockStatement["TSCo condition: Expression[TSForLoopStatement] | None = None increment: Expression[TSForLoopStatement] | None = None - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: TSCodeBlock, pos: int | None = None) -> None: - super().__init__(ts_node, file_node_id, G, parent, pos) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: TSCodeBlock, pos: int | None = None) -> None: + super().__init__(ts_node, file_node_id, ctx, parent, pos) if ts_node.type == "for_statement": self.initializer = self.child_by_field_name("initializer") self.condition = self.child_by_field_name("condition") diff --git a/src/codegen/sdk/typescript/statements/if_block_statement.py b/src/codegen/sdk/typescript/statements/if_block_statement.py index aff9dee22..c25a71e77 100644 --- a/src/codegen/sdk/typescript/statements/if_block_statement.py +++ b/src/codegen/sdk/typescript/statements/if_block_statement.py @@ -10,7 +10,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.node_id_factory import NodeId from codegen.sdk.typescript.detached_symbols.code_block import TSCodeBlock @@ -43,13 +43,13 @@ def __init__( self, ts_node: TSNode, file_node_id: NodeId, - G: CodebaseGraph, + ctx: CodebaseContext, parent: Parent, pos: int, else_clause_node: TSNode | None = None, main_if_block: TSIfBlockStatement | None = None, ) -> None: - super().__init__(ts_node, file_node_id, G, parent, pos) + super().__init__(ts_node, file_node_id, ctx, parent, pos) self._else_clause_node = else_clause_node self._main_if_block = main_if_block # Call .value to unwrap the parenthesis @@ -79,10 +79,10 @@ def _parse_alternative_blocks(self) -> list[TSIfBlockStatement]: while alt_node := alt_block.ts_node.child_by_field_name("alternative"): if (if_node := alt_node.named_children[0]).type == "if_statement": # Elif statements are represented as if statements with an else clause as the parent node - alt_block = TSIfBlockStatement(if_node, self.file_node_id, self.G, self.parent, self.index, else_clause_node=alt_node, main_if_block=self._main_if_block or self) + alt_block = TSIfBlockStatement(if_node, self.file_node_id, self.ctx, self.parent, self.index, else_clause_node=alt_node, main_if_block=self._main_if_block or self) else: # Else clause - alt_block = TSIfBlockStatement(alt_node, self.file_node_id, self.G, self.parent, self.index, main_if_block=self._main_if_block or self) + alt_block = TSIfBlockStatement(alt_node, self.file_node_id, self.ctx, self.parent, self.index, main_if_block=self._main_if_block or self) if_blocks.append(alt_block) return if_blocks diff --git a/src/codegen/sdk/typescript/statements/import_statement.py b/src/codegen/sdk/typescript/statements/import_statement.py index 458007005..cde889d8e 100644 --- a/src/codegen/sdk/typescript/statements/import_statement.py +++ b/src/codegen/sdk/typescript/statements/import_statement.py @@ -11,7 +11,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.node_id_factory import NodeId from codegen.sdk.typescript.detached_symbols.code_block import TSCodeBlock from codegen.sdk.typescript.file import TSFile @@ -30,17 +30,17 @@ class TSImportStatement(ImportStatement["TSFile", TSImport, "TSCodeBlock"], Buil imports (Collection): A collection of TypeScript imports contained within the statement. """ - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: TSCodeBlock, pos: int, *, source_node: TSNode | None = None) -> None: - super().__init__(ts_node, file_node_id, G, parent, pos) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: TSCodeBlock, pos: int, *, source_node: TSNode | None = None) -> None: + super().__init__(ts_node, file_node_id, ctx, parent, pos) imports = [] if ts_node.type == "import_statement": - imports.extend(TSImport.from_import_statement(ts_node, file_node_id, G, self)) + imports.extend(TSImport.from_import_statement(ts_node, file_node_id, ctx, self)) elif ts_node.type == "call_expression": import_call_node = ts_node.child_by_field_name("function") arguments = ts_node.child_by_field_name("arguments") - imports.extend(TSImport.from_dynamic_import_statement(import_call_node, arguments, file_node_id, G, self)) + imports.extend(TSImport.from_dynamic_import_statement(import_call_node, arguments, file_node_id, ctx, self)) elif ts_node.type == "export_statement": - imports.extend(TSImport.from_export_statement(source_node, file_node_id, G, self)) - self.imports = Collection(ts_node, file_node_id, G, self, delimiter="\n", children=imports) + imports.extend(TSImport.from_export_statement(source_node, file_node_id, ctx, self)) + self.imports = Collection(ts_node, file_node_id, ctx, self, delimiter="\n", children=imports) for imp in self.imports: imp.import_statement = self diff --git a/src/codegen/sdk/typescript/statements/labeled_statement.py b/src/codegen/sdk/typescript/statements/labeled_statement.py index 3a9b5eb7e..a898418d4 100644 --- a/src/codegen/sdk/typescript/statements/labeled_statement.py +++ b/src/codegen/sdk/typescript/statements/labeled_statement.py @@ -10,7 +10,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.node_id_factory import NodeId from codegen.sdk.typescript.detached_symbols.code_block import TSCodeBlock @@ -44,9 +44,9 @@ class TSLabeledStatement(Statement[Parent], HasName, Generic[Parent]): statement_type = StatementType.LABELED_STATEMENT body: Expression | None - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: Parent, pos: int) -> None: - super().__init__(ts_node, file_node_id, G, parent, pos) - self._name_node = Name(ts_node.child_by_field_name("label"), file_node_id, G, self) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: Parent, pos: int) -> None: + super().__init__(ts_node, file_node_id, ctx, parent, pos) + self._name_node = Name(ts_node.child_by_field_name("label"), file_node_id, ctx, self) body_node = self.ts_node.child_by_field_name("body") self.body = self._parse_expression(body_node) if body_node else None diff --git a/src/codegen/sdk/typescript/statements/switch_case.py b/src/codegen/sdk/typescript/statements/switch_case.py index 1e93fdc67..cdd43e1dd 100644 --- a/src/codegen/sdk/typescript/statements/switch_case.py +++ b/src/codegen/sdk/typescript/statements/switch_case.py @@ -9,7 +9,7 @@ from codegen.shared.decorators.docs import ts_apidoc if TYPE_CHECKING: - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.typescript.statements.switch_statement import TSSwitchStatement @@ -23,7 +23,7 @@ class TSSwitchCase(SwitchCase[TSCodeBlock["TSSwitchStatement"]], TSBlockStatemen default: bool - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: "CodebaseGraph", parent: TSCodeBlock, pos: int | None = None) -> None: - super().__init__(ts_node, file_node_id, G, parent, pos) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: "CodebaseContext", parent: TSCodeBlock, pos: int | None = None) -> None: + super().__init__(ts_node, file_node_id, ctx, parent, pos) self.condition = self.child_by_field_name("value") self.default = self.ts_node.type == "switch_default" diff --git a/src/codegen/sdk/typescript/statements/switch_statement.py b/src/codegen/sdk/typescript/statements/switch_statement.py index a633fe402..914bde227 100644 --- a/src/codegen/sdk/typescript/statements/switch_statement.py +++ b/src/codegen/sdk/typescript/statements/switch_statement.py @@ -9,7 +9,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.node_id_factory import NodeId from codegen.sdk.typescript.detached_symbols.code_block import TSCodeBlock @@ -18,10 +18,10 @@ class TSSwitchStatement(SwitchStatement["TSCodeBlock[Self]", "TSCodeBlock", TSSwitchCase]): """Typescript switch statement""" - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: TSCodeBlock, pos: int | None = None) -> None: - super().__init__(ts_node, file_node_id, G, parent, pos) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: TSCodeBlock, pos: int | None = None) -> None: + super().__init__(ts_node, file_node_id, ctx, parent, pos) self.value = self.child_by_field_name("value") code_block = self.ts_node.child_by_field_name("body") self.cases = [] for node in code_block.named_children: - self.cases.append(TSSwitchCase(node, file_node_id, G, self.parent)) + self.cases.append(TSSwitchCase(node, file_node_id, ctx, self.parent)) diff --git a/src/codegen/sdk/typescript/statements/try_catch_statement.py b/src/codegen/sdk/typescript/statements/try_catch_statement.py index 28d39b64a..aa24178d2 100644 --- a/src/codegen/sdk/typescript/statements/try_catch_statement.py +++ b/src/codegen/sdk/typescript/statements/try_catch_statement.py @@ -11,7 +11,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.dataclasses.usage import UsageKind from codegen.sdk.core.detached_symbols.function_call import FunctionCall from codegen.sdk.core.interfaces.has_name import HasName @@ -30,12 +30,12 @@ class TSTryCatchStatement(TryCatchStatement["TSCodeBlock"], TSBlockStatement): catch: TSCatchStatement[Self] | None = None - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: TSCodeBlock, pos: int | None = None) -> None: - super().__init__(ts_node, file_node_id, G, parent, pos) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: TSCodeBlock, pos: int | None = None) -> None: + super().__init__(ts_node, file_node_id, ctx, parent, pos) if handler_node := self.ts_node.child_by_field_name("handler"): - self.catch = TSCatchStatement(handler_node, file_node_id, G, self.code_block) + self.catch = TSCatchStatement(handler_node, file_node_id, ctx, self.code_block) if finalizer_node := self.ts_node.child_by_field_name("finalizer"): - self.finalizer = TSBlockStatement(finalizer_node, file_node_id, G, self.code_block) + self.finalizer = TSBlockStatement(finalizer_node, file_node_id, ctx, self.code_block) @property @reader diff --git a/src/codegen/sdk/typescript/statements/while_statement.py b/src/codegen/sdk/typescript/statements/while_statement.py index 5d2583ac7..fdbb1dee8 100644 --- a/src/codegen/sdk/typescript/statements/while_statement.py +++ b/src/codegen/sdk/typescript/statements/while_statement.py @@ -9,7 +9,7 @@ if TYPE_CHECKING: from tree_sitter import Node as TSNode - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.core.node_id_factory import NodeId from codegen.sdk.typescript.detached_symbols.code_block import TSCodeBlock @@ -26,7 +26,7 @@ class TSWhileStatement(WhileStatement["TSCodeBlock"], TSHasBlock): condition (str | None): The condition expression of the while loop. """ - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: CodebaseGraph, parent: TSCodeBlock, pos: int | None = None) -> None: - super().__init__(ts_node, file_node_id, G, parent, pos) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: CodebaseContext, parent: TSCodeBlock, pos: int | None = None) -> None: + super().__init__(ts_node, file_node_id, ctx, parent, pos) condition = self.child_by_field_name("condition") self.condition = condition.value if condition else None diff --git a/src/codegen/sdk/typescript/symbol.py b/src/codegen/sdk/typescript/symbol.py index bb41f3a52..fc41d1ee7 100644 --- a/src/codegen/sdk/typescript/symbol.py +++ b/src/codegen/sdk/typescript/symbol.py @@ -95,7 +95,7 @@ def extended_nodes(self) -> list[Editable]: while (parent := new_ts_node.parent).type in ("export_statement", "lexical_declaration", "variable_declarator"): new_ts_node = parent - return [Value(new_ts_node, self.file_node_id, self.G, self.parent) if node.ts_node == self.ts_node else node for node in nodes] + return [Value(new_ts_node, self.file_node_id, self.ctx, self.parent) if node.ts_node == self.ts_node else node for node in nodes] @property @reader @@ -224,7 +224,7 @@ def set_inline_comment(self, comment: str, auto_format: bool = True, clean_forma if auto_format: comment = " " + TSComment.generate_comment(comment, TSCommentType.DOUBLE_SLASH) node = node or self.ts_node - Value(node, self.file_node_id, self.G, self).insert_after(comment, fix_indentation=False, newline=False) + Value(node, self.file_node_id, self.ctx, self).insert_after(comment, fix_indentation=False, newline=False) @property @reader @@ -238,7 +238,7 @@ def semicolon_node(self) -> Editable | None: """ sibbling = self.ts_node.next_sibling if sibbling and sibbling.type == ";": - return Value(sibbling, self.file_node_id, self.G, self) + return Value(sibbling, self.file_node_id, self.ctx, self) return None @property diff --git a/src/codegen/sdk/typescript/symbol_groups/comment_group.py b/src/codegen/sdk/typescript/symbol_groups/comment_group.py index b15be09dc..3f23b276b 100644 --- a/src/codegen/sdk/typescript/symbol_groups/comment_group.py +++ b/src/codegen/sdk/typescript/symbol_groups/comment_group.py @@ -66,7 +66,7 @@ def from_symbol_comments(cls, symbol: TSSymbol): comment_nodes = cls._get_sibbling_comments(symbol) if not comment_nodes: return None - return cls(comment_nodes, symbol.file_node_id, symbol.G, symbol) + return cls(comment_nodes, symbol.file_node_id, symbol.ctx, symbol) @classmethod @noapidoc @@ -99,7 +99,7 @@ def from_symbol_inline_comments(cls, symbol: TSSymbol): if not comment_nodes: return None - return cls(comment_nodes, symbol.file_node_id, symbol.G, symbol) + return cls(comment_nodes, symbol.file_node_id, symbol.ctx, symbol) @classmethod @noapidoc @@ -112,7 +112,7 @@ def from_docstring(cls, symbol: TSSymbol) -> TSCommentGroup | None: docstring_nodes = [comment for comment in comment_nodes if comment.comment_type == TSCommentType.SLASH_STAR] if not docstring_nodes: return None - return cls(docstring_nodes, symbol.file_node_id, symbol.G, symbol) + return cls(docstring_nodes, symbol.file_node_id, symbol.ctx, symbol) @classmethod @noapidoc @@ -124,4 +124,4 @@ def from_comment_nodes(cls, comment_nodes: list[TSComment], symbol: TSSymbol): docstring_nodes = [comment for comment in comment_nodes if comment.comment_type == TSCommentType.SLASH_STAR] if not docstring_nodes: return None - return cls(docstring_nodes, symbol.file_node_id, symbol.G, symbol) + return cls(docstring_nodes, symbol.file_node_id, symbol.ctx, symbol) diff --git a/src/codegen/sdk/typescript/symbol_groups/dict.py b/src/codegen/sdk/typescript/symbol_groups/dict.py index 78f37cfcc..09fb9ad4d 100644 --- a/src/codegen/sdk/typescript/symbol_groups/dict.py +++ b/src/codegen/sdk/typescript/symbol_groups/dict.py @@ -14,7 +14,7 @@ from codegen.shared.decorators.docs import apidoc, noapidoc, ts_apidoc if TYPE_CHECKING: - from codegen.sdk.codebase.codebase_graph import CodebaseGraph + from codegen.sdk.codebase.codebase_context import CodebaseContext Parent = TypeVar("Parent", bound="Editable") TExpression = TypeVar("TExpression", bound=Expression) @@ -37,8 +37,8 @@ class TSPair(Pair): shorthand: bool - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: "CodebaseGraph", parent: Parent) -> None: - super().__init__(ts_node, file_node_id, G, parent) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: "CodebaseContext", parent: Parent) -> None: + super().__init__(ts_node, file_node_id, ctx, parent) self.shorthand = ts_node.type == "shorthand_property_identifier" def _get_key_value(self) -> tuple[Expression[Self] | None, Expression[Self] | None]: @@ -65,7 +65,7 @@ def reduce_condition(self, bool_condition: bool, node: Editable | None = None) - """Reduces an editable to the following condition""" if self.shorthand and node == self.value: # Object shorthand - self.parent[self.key.source] = self.G.node_classes.bool_conversion[bool_condition] + self.parent[self.key.source] = self.ctx.node_classes.bool_conversion[bool_condition] else: super().reduce_condition(bool_condition, node) @@ -74,8 +74,8 @@ def reduce_condition(self, bool_condition: bool, node: Editable | None = None) - class TSDict(Dict, HasAttribute): """A typescript dict object. You can use standard operations to operate on this dict (IE len, del, set, get, etc)""" - def __init__(self, ts_node: TSNode, file_node_id: NodeId, G: "CodebaseGraph", parent: Parent, delimiter: str = ",", pair_type: type[Pair] = TSPair) -> None: - super().__init__(ts_node, file_node_id, G, parent, delimiter=delimiter, pair_type=pair_type) + def __init__(self, ts_node: TSNode, file_node_id: NodeId, ctx: "CodebaseContext", parent: Parent, delimiter: str = ",", pair_type: type[Pair] = TSPair) -> None: + super().__init__(ts_node, file_node_id, ctx, parent, delimiter=delimiter, pair_type=pair_type) def __getitem__(self, __key: str) -> TExpression: for pair in self._underlying: @@ -126,7 +126,7 @@ def __setitem__(self, __key: str, __value: TExpression) -> None: break # CASE: {} else: - if not self.G.node_classes.int_dict_key: + if not self.ctx.node_classes.int_dict_key: try: int(__key) __key = f"'{__key}'" diff --git a/src/codegen/sdk/typescript/ts_config.py b/src/codegen/sdk/typescript/ts_config.py index cf0648b7c..4f491fbf4 100644 --- a/src/codegen/sdk/typescript/ts_config.py +++ b/src/codegen/sdk/typescript/ts_config.py @@ -134,12 +134,12 @@ def _precompute_config_values(self): if references is not None: for reference in references: if ref_path := reference.get("path", None): - abs_ref_path = str(self.config_file.G.to_relative(self._relative_to_absolute_directory_path(ref_path))) - if directory := self.config_file.G.get_directory(self.config_file.G.to_absolute(abs_ref_path)): + abs_ref_path = str(self.config_file.ctx.to_relative(self._relative_to_absolute_directory_path(ref_path))) + if directory := self.config_file.ctx.get_directory(self.config_file.ctx.to_absolute(abs_ref_path)): self_references.append((ref_path, directory)) elif ts_config := self.config_parser.get_config(abs_ref_path): self_references.append((ref_path, ts_config.config_file)) - elif file := self.config_file.G.get_file(abs_ref_path): + elif file := self.config_file.ctx.get_file(abs_ref_path): self_references.append((ref_path, file)) self._references = [*self_references] # MAYBE add base references here? This breaks the reference chain though. self._self_references = self_references @@ -164,7 +164,7 @@ def _precompute_import_aliases(self): if self._self_base_url: cleaned_relative_path = os.path.join(self._self_base_url, cleaned_relative_path) formatted_absolute_path = self._relative_to_absolute_directory_path(cleaned_relative_path) - formatted_relative_path = str(self.config_file.G.to_relative(formatted_absolute_path)) + formatted_relative_path = str(self.config_file.ctx.to_relative(formatted_absolute_path)) # Fix absolute path if its base if formatted_relative_path == ".": formatted_relative_path = "" @@ -180,7 +180,7 @@ def _precompute_import_aliases(self): # TODO: THIS ENTIRE PROCESS IS KINDA HACKY. # If the reference is a file, get its directory. if isinstance(reference, File): - reference_dir = self.config_file.G.get_directory(os.path.dirname(reference.filepath)) + reference_dir = self.config_file.ctx.get_directory(os.path.dirname(reference.filepath)) elif isinstance(reference, Directory): reference_dir = reference else: @@ -241,7 +241,7 @@ def _relative_to_absolute_directory_path(self, relative_path: str) -> Path: """ # TODO: This could also use its parent config to resolve the path relative = self.config_file.path.parent / relative_path.strip('"') - return self.config_file.G.to_absolute(relative) + return self.config_file.ctx.to_absolute(relative) def translate_import_path(self, import_path: str) -> str: """Translates an import path to an absolute path using the tsconfig paths. @@ -262,9 +262,9 @@ def translate_import_path(self, import_path: str) -> str: return import_path # Step 1: Try to resolve with import_resolution_overrides - if self.config_file.G.config.feature_flags.import_resolution_overrides: - if path_check := TSConfig._find_matching_path(frozenset(self.config_file.G.config.feature_flags.import_resolution_overrides.keys()), import_path): - to_base = self.config_file.G.config.feature_flags.import_resolution_overrides[path_check] + if self.config_file.ctx.config.feature_flags.import_resolution_overrides: + if path_check := TSConfig._find_matching_path(frozenset(self.config_file.ctx.config.feature_flags.import_resolution_overrides.keys()), import_path): + to_base = self.config_file.ctx.config.feature_flags.import_resolution_overrides[path_check] # Get the remaining path after the matching prefix remaining_path = import_path[len(path_check) :].lstrip("/") @@ -482,4 +482,4 @@ def reference_import_aliases(self) -> dict[str, list[str]]: dict[str, list[str]]: A dictionary where keys are formatted reference paths (e.g. 'module/dist') and values are lists of absolute target paths derived from the referenced tsconfig's rootDirs and outDir settings. """ - return {k: [str(self.config_file.G.to_relative(v)) for v in vs] for k, vs in self._reference_import_aliases.items()} + return {k: [str(self.config_file.ctx.to_relative(v)) for v in vs] for k, vs in self._reference_import_aliases.items()} diff --git a/tests/integration/codemod/test_codemods.py b/tests/integration/codemod/test_codemods.py index beb4012ae..b4f79a365 100644 --- a/tests/integration/codemod/test_codemods.py +++ b/tests/integration/codemod/test_codemods.py @@ -16,7 +16,7 @@ @pytest.mark.timeout(120, func_only=True) def test_codemods_cloned_repos(codemod: Codemod, codebase: Codebase, expected: Path, tmp_path: Path, diff_folder: Path, snapshot: Snapshot) -> None: codemod.execute(codebase) - codebase.commit(codebase.G.config.feature_flags.verify_graph) + codebase.commit(codebase.ctx.config.feature_flags.verify_graph) compare_codebase_diff(codebase=codebase, expected_dir=tmp_path, expected_diff=expected, diff_path=diff_folder, snapshot=snapshot) - if codebase.G.config.feature_flags.verify_graph: + if codebase.ctx.config.feature_flags.verify_graph: codebase.reset() diff --git a/tests/integration/codemod/test_diffs.py b/tests/integration/codemod/test_diffs.py index 5745caef2..1ff224631 100644 --- a/tests/integration/codemod/test_diffs.py +++ b/tests/integration/codemod/test_diffs.py @@ -24,7 +24,7 @@ def test_codemods_diffs(_codebase: Codebase, expected: Path) -> None: def verify_diffs(_codebase): modified = gather_modified_files(_codebase) diffs = [DiffLite.from_git_diff(diff) for diff in _codebase.get_diffs()] - _codebase.G.apply_diffs(diffs) + _codebase.ctx.apply_diffs(diffs) for file in _codebase.files: print_errors(file.filepath, file.content) assert not file.ts_node.has_error diff --git a/tests/integration/codemod/test_verified_codemods.py b/tests/integration/codemod/test_verified_codemods.py index 1b754dd31..2ef6bf93e 100644 --- a/tests/integration/codemod/test_verified_codemods.py +++ b/tests/integration/codemod/test_verified_codemods.py @@ -33,7 +33,7 @@ def test_verified_codemods( # Codebase logging not functioning, creating an empty file to avoid error codebase.create_file(".codemod_logs.txt") # Commit changes - codebase.commit(codebase.G.config.feature_flags.verify_graph) + codebase.commit(codebase.ctx.config.feature_flags.verify_graph) compare_codebase_diff( codebase=codebase, expected_dir=tmp_path, diff --git a/tests/unit/codegen/sdk/codebase/codebase_graph/test_codebase_graph.py b/tests/unit/codegen/sdk/codebase/codebase_graph/test_codebase_graph.py index d61355239..a5e8f5d5f 100644 --- a/tests/unit/codegen/sdk/codebase/codebase_graph/test_codebase_graph.py +++ b/tests/unit/codegen/sdk/codebase/codebase_graph/test_codebase_graph.py @@ -2,7 +2,7 @@ import itertools -from codegen.sdk.codebase.codebase_graph import CodebaseGraph +from codegen.sdk.codebase.codebase_context import CodebaseContext from codegen.sdk.codebase.factory.get_session import get_codebase_session from codegen.sdk.enums import EdgeType @@ -33,8 +33,8 @@ def __init__(self): """ with get_codebase_session(tmpdir=tmpdir, files={"test.py": content}) as codebase: assert codebase is not None - assert isinstance(codebase.G, CodebaseGraph) - # assert set(codebase.G.nodes) == { + assert isinstance(codebase.ctx, CodebaseContext) + # assert set(codebase.ctx.nodes) == { # "test.py::global_var_1:51-67", # "test.py::global_var_2:68-84", # "test.py::MyClass:141-192", @@ -51,9 +51,9 @@ def __init__(self): # "import__z__from__some_file__to__test.py", # "test.py", # } - import_resolution_edges = [edge for edge in codebase.G.edges if edge[2].type == EdgeType.IMPORT_SYMBOL_RESOLUTION] + import_resolution_edges = [edge for edge in codebase.ctx.edges if edge[2].type == EdgeType.IMPORT_SYMBOL_RESOLUTION] file_contains_node_edges = list(itertools.chain.from_iterable(file.get_nodes() for file in codebase.files)) - symbol_usage_edges = [edge for edge in codebase.G.edges if edge[2].type == EdgeType.SYMBOL_USAGE] + symbol_usage_edges = [edge for edge in codebase.ctx.edges if edge[2].type == EdgeType.SYMBOL_USAGE] assert len(import_resolution_edges) == 4 assert len(file_contains_node_edges) == 14 diff --git a/tests/unit/codegen/sdk/codebase/codebase_graph/test_validation.py b/tests/unit/codegen/sdk/codebase/codebase_graph/test_validation.py index da5316dcf..57fc97621 100644 --- a/tests/unit/codegen/sdk/codebase/codebase_graph/test_validation.py +++ b/tests/unit/codegen/sdk/codebase/codebase_graph/test_validation.py @@ -30,7 +30,7 @@ def test_post_init_validation_missing_files(tmpdir) -> None: }, ) as codebase: assert len(codebase.files) == 2 - codebase.G.remove_node(codebase.files[0].node_id) + codebase.ctx.remove_node(codebase.files[0].node_id) uncache_all() # Clear codebase.files cache assert post_init_validation(codebase) == PostInitValidationStatus.MISSING_FILES diff --git a/tests/unit/codegen/sdk/codebase/transaction_manager/test_transaction_mangager_checks.py b/tests/unit/codegen/sdk/codebase/transaction_manager/test_transaction_mangager_checks.py index 807559392..556cb019b 100644 --- a/tests/unit/codegen/sdk/codebase/transaction_manager/test_transaction_mangager_checks.py +++ b/tests/unit/codegen/sdk/codebase/transaction_manager/test_transaction_mangager_checks.py @@ -14,7 +14,7 @@ def test_check_max_preview_time_exceeded(tmpdir): programming_language=ProgrammingLanguage.PYTHON, session_options=SessionOptions(max_seconds=0), ) as codebase: - codebase.G.transaction_manager.check_max_preview_time() + codebase.ctx.transaction_manager.check_max_preview_time() assert str(exc_info.value) == "Max preview time exceeded: True" assert exc_info.value.threshold == 0 @@ -28,7 +28,7 @@ def test_check_max_preview_time_exceeded_set_session_options(tmpdir): ) as codebase: with pytest.raises(MaxPreviewTimeExceeded) as exc_info: codebase.set_session_options(max_seconds=0) - codebase.G.transaction_manager.check_max_preview_time() + codebase.ctx.transaction_manager.check_max_preview_time() assert str(exc_info.value) == "Max preview time exceeded: True" assert exc_info.value.threshold == 0 @@ -42,7 +42,7 @@ def test_check_max_transactions_exceeded(tmpdir): programming_language=ProgrammingLanguage.PYTHON, session_options=SessionOptions(max_transactions=0), ) as codebase: - codebase.G.transaction_manager.check_max_transactions() + codebase.ctx.transaction_manager.check_max_transactions() assert str(exc_info.value) == "Max transactions reached: 0" assert exc_info.value.threshold == 0 @@ -56,7 +56,7 @@ def test_check_max_transactions_exceeded_set_session_options(tmpdir): ) as codebase: with pytest.raises(MaxTransactionsExceeded) as exc_info: codebase.set_session_options(max_transactions=0) - codebase.G.transaction_manager.check_max_transactions() + codebase.ctx.transaction_manager.check_max_transactions() assert str(exc_info.value) == "Max transactions reached: 0" assert exc_info.value.threshold == 0 diff --git a/tests/unit/codegen/sdk/python/autocommit/test_autocommit.py b/tests/unit/codegen/sdk/python/autocommit/test_autocommit.py index 13f56737a..f5dfe151d 100644 --- a/tests/unit/codegen/sdk/python/autocommit/test_autocommit.py +++ b/tests/unit/codegen/sdk/python/autocommit/test_autocommit.py @@ -138,7 +138,7 @@ def a(): pass """ with get_codebase_session(tmpdir=tmpdir, files={file1_name: content1}) as codebase: - autocommit = codebase.G._autocommit + autocommit = codebase.ctx._autocommit file1 = codebase.get_file(file1_name) fun = file1.get_function("a") file1.add_import_from_import_string("import os") @@ -167,7 +167,7 @@ def a(a: int): pass """ with get_codebase_session(tmpdir=tmpdir, files={file1_name: content1}) as codebase: - autocommit = codebase.G._autocommit + autocommit = codebase.ctx._autocommit file1 = codebase.get_file(file1_name) fun = file1.get_function("a") param = fun.parameters[0] @@ -194,7 +194,7 @@ def a(a: int): pass """ with get_codebase_session(tmpdir=tmpdir, files={file1_name: content1}) as codebase: - autocommit = codebase.G._autocommit + autocommit = codebase.ctx._autocommit file1 = codebase.get_file(file1_name) fun = file1.get_function("a") param = fun.parameters[0] @@ -223,7 +223,7 @@ def b(a: int): pass """ with get_codebase_session(tmpdir=tmpdir, files={file1_name: content1}) as codebase: - autocommit = codebase.G._autocommit + autocommit = codebase.ctx._autocommit file1 = codebase.get_file(file1_name) fun = file1.get_function("a") funb = file1.get_function("b") diff --git a/tests/unit/codegen/sdk/python/class_definition/test_class_dependencies.py b/tests/unit/codegen/sdk/python/class_definition/test_class_dependencies.py index b027f000f..0592958ca 100644 --- a/tests/unit/codegen/sdk/python/class_definition/test_class_dependencies.py +++ b/tests/unit/codegen/sdk/python/class_definition/test_class_dependencies.py @@ -60,13 +60,13 @@ def g(tmpdir): assert len(edges) == 4 # =====[ Edge Test ] ===== - edge_data = codebase.G.get_edge_data(f.node_id, A.node_id) + edge_data = codebase.ctx.get_edge_data(f.node_id, A.node_id) types = [edge.usage.kind for edge in edge_data] assert len(types) == 1 assert types[0] == UsageKind.TYPE_ANNOTATION f_body_assignment = f.code_block.statements[0].assignments[0] - edge_data = codebase.G.get_edge_data(f_body_assignment.node_id, A.node_id) + edge_data = codebase.ctx.get_edge_data(f_body_assignment.node_id, A.node_id) types = [edge.usage.kind for edge in edge_data] assert len(types) == 1 assert UsageKind.BODY in types diff --git a/tests/unit/codegen/sdk/python/codebase/test_codebase_create_file.py b/tests/unit/codegen/sdk/python/codebase/test_codebase_create_file.py index e0aed56e7..e7bba526d 100644 --- a/tests/unit/codegen/sdk/python/codebase/test_codebase_create_file.py +++ b/tests/unit/codegen/sdk/python/codebase/test_codebase_create_file.py @@ -65,5 +65,5 @@ def test_codebase_create_then_delete_file(mock_codebase_setup: tuple[Codebase, F assert len(list(list(codebase.files))) == 3 file.remove() - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert not os.path.exists("my_file.py") diff --git a/tests/unit/codegen/sdk/python/codebase/test_codebase_git.py b/tests/unit/codegen/sdk/python/codebase/test_codebase_git.py index 681e39fe2..1c4d72c03 100644 --- a/tests/unit/codegen/sdk/python/codebase/test_codebase_git.py +++ b/tests/unit/codegen/sdk/python/codebase/test_codebase_git.py @@ -17,7 +17,7 @@ def test_codebase_git(tmpdir, commit: bool, sync: bool) -> None: sync_graph=sync, ) as codebase: default_branch = codebase.default_branch - c1 = codebase.G.synced_commit + c1 = codebase.ctx.synced_commit codebase.checkout(branch=other, create_if_missing=True) codebase.get_file("dir/file0.py").insert_after("a = 1") c2 = codebase.git_commit("boop") diff --git a/tests/unit/codegen/sdk/python/codebase/test_codebase_reset.py b/tests/unit/codegen/sdk/python/codebase/test_codebase_reset.py index a848626c6..1aa1c9665 100644 --- a/tests/unit/codegen/sdk/python/codebase/test_codebase_reset.py +++ b/tests/unit/codegen/sdk/python/codebase/test_codebase_reset.py @@ -50,7 +50,7 @@ class mockme: path: str = "mypath" mm = mockme() - codebase.G.all_syncs = [mm] + codebase.ctx.all_syncs = [mm] try: codebase.reset() except Exception as e: @@ -86,8 +86,8 @@ def bar(x): file0 = codebase.get_file("dir/file0.py", optional=True) file2 = codebase.get_file("dir/file2.py", optional=True) - init_nodes = codebase.G.get_nodes() - init_edges = codebase.G.get_edges() + init_nodes = codebase.ctx.get_nodes() + init_edges = codebase.ctx.get_edges() file0.update_filepath("dir/file0_updated.py") codebase.create_file("dir/new_file.py", "some_var = 1") @@ -111,11 +111,11 @@ def bar(x): assert file1.source == file1_content[file0.ts_node.start_byte :] assert file2.source == file2_content[file0.ts_node.start_byte :] - assert len(codebase.G.get_nodes()) == len(init_nodes) - assert set(codebase.G.get_nodes()) == set(init_nodes) - assert set(codebase.G.get_nodes()) == set(codebase.G.old_graph.nodes()) - assert len(codebase.G.get_edges()) == len(init_edges) - assert set(get_edges(codebase.G._graph)) == set(get_edges(codebase.G.old_graph)) + assert len(codebase.ctx.get_nodes()) == len(init_nodes) + assert set(codebase.ctx.get_nodes()) == set(init_nodes) + assert set(codebase.ctx.get_nodes()) == set(codebase.ctx.old_graph.nodes()) + assert len(codebase.ctx.get_edges()) == len(init_edges) + assert set(get_edges(codebase.ctx._graph)) == set(get_edges(codebase.ctx.old_graph)) def test_codebase_reset_gitignore(tmpdir: str) -> None: diff --git a/tests/unit/codegen/sdk/python/detached_symbols/argument/test_argument_remove.py b/tests/unit/codegen/sdk/python/detached_symbols/argument/test_argument_remove.py index cbfe4150f..4a71b334f 100644 --- a/tests/unit/codegen/sdk/python/detached_symbols/argument/test_argument_remove.py +++ b/tests/unit/codegen/sdk/python/detached_symbols/argument/test_argument_remove.py @@ -57,7 +57,7 @@ def test(): assert len(foo_calls) == 2 foo_calls = sorted(foo_calls, key=lambda x: x.ts_node.start_byte) foo_calls[1].args[2].remove() - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() # language=python assert ( file2.content @@ -73,7 +73,7 @@ def test(): """ ) foo_calls[1].args[0].remove() - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() # language=python assert ( file2.content @@ -89,11 +89,11 @@ def test(): ) foo_calls[0].args[2].remove() - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert "foo(1, 2)" in file2.content foo_calls[0].args[1].remove() - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert "foo(1)" in file2.content foo_calls[0].args[0].remove() - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert "foo()" in file2.content diff --git a/tests/unit/codegen/sdk/python/detached_symbols/code_block/test_code_block.py b/tests/unit/codegen/sdk/python/detached_symbols/code_block/test_code_block.py index 3ef552301..98591442a 100644 --- a/tests/unit/codegen/sdk/python/detached_symbols/code_block/test_code_block.py +++ b/tests/unit/codegen/sdk/python/detached_symbols/code_block/test_code_block.py @@ -188,7 +188,7 @@ def foo(x: int, y: str) -> MyClass: assert len(obj_usages) == 1 assert obj_usages[0].source == "obj" obj_usages[0].edit("renamed_obj") - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert "renamed_obj.attr1 = renamed_attribute.obj" in file.content random = code_block.get_local_var_assignment("random") diff --git a/tests/unit/codegen/sdk/python/detached_symbols/decorator/test_decorator_call.py b/tests/unit/codegen/sdk/python/detached_symbols/decorator/test_decorator_call.py index e3c526f2f..636334d42 100644 --- a/tests/unit/codegen/sdk/python/detached_symbols/decorator/test_decorator_call.py +++ b/tests/unit/codegen/sdk/python/detached_symbols/decorator/test_decorator_call.py @@ -10,8 +10,8 @@ class ExampleUserUpload(Resource): def post(self, user_uuid: str): ... """ - with get_codebase_graph_session(tmpdir=tmpdir, files={"decorator.py": content}) as G: - file = G.get_file("decorator.py") + with get_codebase_graph_session(tmpdir=tmpdir, files={"decorator.py": content}) as ctx: + file = ctx.get_file("decorator.py") cls = file.get_class("ExampleUserUpload") assert len(cls.decorators) == 1 decorator = cls.decorators[0] @@ -31,8 +31,8 @@ class DocumentUpload(Resource): def post(self, document_uuid: str): ... """ - with get_codebase_graph_session(tmpdir=tmpdir, files={"decorator.py": content}) as G: - file = G.get_file("decorator.py") + with get_codebase_graph_session(tmpdir=tmpdir, files={"decorator.py": content}) as ctx: + file = ctx.get_file("decorator.py") cls = file.get_class("DocumentUpload") assert len(cls.decorators) == 1 decorator = cls.decorators[0] @@ -49,8 +49,8 @@ class GetUserData(Resource): def post(self) -> Response: ... """ - with get_codebase_graph_session(tmpdir=tmpdir, files={"decorator.py": content}) as G: - file = G.get_file("decorator.py") + with get_codebase_graph_session(tmpdir=tmpdir, files={"decorator.py": content}) as ctx: + file = ctx.get_file("decorator.py") cls = file.get_class("GetUserData") assert len(cls.decorators) == 1 decorator = cls.decorators[0] diff --git a/tests/unit/codegen/sdk/python/detached_symbols/decorator/test_decorator_remove.py b/tests/unit/codegen/sdk/python/detached_symbols/decorator/test_decorator_remove.py index 3059ef5c0..311df273e 100644 --- a/tests/unit/codegen/sdk/python/detached_symbols/decorator/test_decorator_remove.py +++ b/tests/unit/codegen/sdk/python/detached_symbols/decorator/test_decorator_remove.py @@ -22,7 +22,7 @@ def foo(): # Test remove decorator2 foo.decorators[0].remove() - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert "@decorator2" not in file.source diff --git a/tests/unit/codegen/sdk/python/detached_symbols/parameter/test_parameter_remove.py b/tests/unit/codegen/sdk/python/detached_symbols/parameter/test_parameter_remove.py index 9c0d40031..e0e9ac843 100644 --- a/tests/unit/codegen/sdk/python/detached_symbols/parameter/test_parameter_remove.py +++ b/tests/unit/codegen/sdk/python/detached_symbols/parameter/test_parameter_remove.py @@ -23,19 +23,19 @@ def bar(x): # Test remove c foo = file.get_function("foo") foo.get_parameter("c").remove() - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert "def foo(b):" in file.source # Test remove b foo = file.get_function("foo") foo.get_parameter("b").remove() - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert "def foo():" in file.source bar = file.get_function("bar") bar.parameters[0].remove() - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert "def bar():" in file.content @@ -94,7 +94,7 @@ def test(): assert all([len(call.args) == 2 for call in foo.call_sites]) foo.parameters[1].remove() - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() foo = file1.get_function("foo") assert [p.name for p in foo.parameters] == ["b"] @@ -102,7 +102,7 @@ def test(): bar = file1.get_function("bar") bar.parameters[0].remove() - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() bar = file1.get_function("bar") assert bar.parameters == [] diff --git a/tests/unit/codegen/sdk/python/detached_symbols/parameter/test_parameter_rename.py b/tests/unit/codegen/sdk/python/detached_symbols/parameter/test_parameter_rename.py index 32ed6e421..f43cecb8b 100644 --- a/tests/unit/codegen/sdk/python/detached_symbols/parameter/test_parameter_rename.py +++ b/tests/unit/codegen/sdk/python/detached_symbols/parameter/test_parameter_rename.py @@ -38,7 +38,7 @@ def baz(x: int, y: str, z: list[int]) -> str: param = bar.parameters[0] param.set_type_annotation("str") param.rename("y_new") - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() bar = file1.get_function("bar") param = bar.parameters[0] assert param.type == "str" @@ -53,7 +53,7 @@ def baz(x: int, y: str, z: list[int]) -> str: param = baz.parameters[1] param.set_type_annotation("int") param.rename("y_new") - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() baz = file1.get_function("baz") param = baz.parameters[1] assert param.type == "int" diff --git a/tests/unit/codegen/sdk/python/detached_symbols/parameter/test_parameter_set_type_annotation.py b/tests/unit/codegen/sdk/python/detached_symbols/parameter/test_parameter_set_type_annotation.py index d72523017..f8f9fa5c2 100644 --- a/tests/unit/codegen/sdk/python/detached_symbols/parameter/test_parameter_set_type_annotation.py +++ b/tests/unit/codegen/sdk/python/detached_symbols/parameter/test_parameter_set_type_annotation.py @@ -36,7 +36,7 @@ def baz(x: int, y: str, z: list[int]) -> str: bar = file1.get_function("bar") param = bar.parameters[0] param.set_type_annotation("str") - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() bar = file1.get_function("bar") param = bar.parameters[0] assert param.type == "str" @@ -46,7 +46,7 @@ def baz(x: int, y: str, z: list[int]) -> str: baz = file1.get_function("baz") param = baz.parameters[1] param.set_type_annotation("int") - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() baz = file1.get_function("baz") param = baz.parameters[1] assert param.type == "int" diff --git a/tests/unit/codegen/sdk/python/file/test_file_get_import_string.py b/tests/unit/codegen/sdk/python/file/test_file_get_import_string.py index a4f41a466..77e3fb4bd 100644 --- a/tests/unit/codegen/sdk/python/file/test_file_get_import_string.py +++ b/tests/unit/codegen/sdk/python/file/test_file_get_import_string.py @@ -6,8 +6,8 @@ def test_file_get_import_string_no_params(tmpdir) -> None: content = """ age: int = 25; """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.PYTHON, files={"test.py": content}) as G: - file = G.get_file("test.py") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.PYTHON, files={"test.py": content}) as ctx: + file = ctx.get_file("test.py") file_import_string = file.get_import_string() assert file_import_string == "from . import test" diff --git a/tests/unit/codegen/sdk/python/file/test_file_properties.py b/tests/unit/codegen/sdk/python/file/test_file_properties.py index 6f7a2279a..15efb3694 100644 --- a/tests/unit/codegen/sdk/python/file/test_file_properties.py +++ b/tests/unit/codegen/sdk/python/file/test_file_properties.py @@ -40,10 +40,10 @@ def test_file_extension(tmpdir) -> None: def test_file_from_content(tmpdir) -> None: with get_codebase_session(tmpdir=tmpdir, files={"test.py": default_content}) as codebase: - new_file = PyFile.from_content("test_new.py", default_content, codebase.G) + new_file = PyFile.from_content("test_new.py", default_content, codebase.ctx) assert new_file.name == "test_new" assert new_file.content == default_content - assert codebase.G.has_node(new_file.node_id) + assert codebase.ctx.has_node(new_file.node_id) def test_file_from_content_invalid_syntax(tmpdir) -> None: @@ -56,16 +56,16 @@ def calculate_average(numbers) return total / len(numbers """ with get_codebase_session(tmpdir=tmpdir, files={"test.py": default_content}) as codebase: - new_file = PyFile.from_content("test_new.py", content, codebase.G) + new_file = PyFile.from_content("test_new.py", content, codebase.ctx) assert new_file is None def test_file_create_from_filepath(tmpdir) -> None: with get_codebase_session(tmpdir=tmpdir, files={"test.py": default_content}) as codebase: - new_file = PyFile.create_from_filepath("test_new.py", codebase.G) + new_file = PyFile.create_from_filepath("test_new.py", codebase.ctx) assert new_file.name == "test_new" assert new_file.content == "" - assert codebase.G.has_node(new_file.node_id) + assert codebase.ctx.has_node(new_file.node_id) def test_file_content(tmpdir) -> None: diff --git a/tests/unit/codegen/sdk/python/file/test_file_remove.py b/tests/unit/codegen/sdk/python/file/test_file_remove.py index 13fea7f23..94bfe21d5 100644 --- a/tests/unit/codegen/sdk/python/file/test_file_remove.py +++ b/tests/unit/codegen/sdk/python/file/test_file_remove.py @@ -13,18 +13,18 @@ def foo(bar): file = codebase.get_file("test.py") filepath = file.filepath new_filepath = "new_file.py" - new_file = file.create_from_filepath(new_filepath, codebase.G) + new_file = file.create_from_filepath(new_filepath, codebase.ctx) - G = codebase.G - assert G.get_node(file.node_id) == file - assert G.get_node(new_file.node_id) == new_file - assert G.has_node(file.node_id) - assert G.has_node(new_file.node_id) + ctx = codebase.ctx + assert ctx.get_node(file.node_id) == file + assert ctx.get_node(new_file.node_id) == new_file + assert ctx.has_node(file.node_id) + assert ctx.has_node(new_file.node_id) assert os.path.exists(tmpdir / file.filepath) assert os.path.exists(tmpdir / new_file.filepath) # Delete the original file.remove() - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert not os.path.exists(tmpdir / filepath) assert os.path.exists(tmpdir / new_filepath) diff --git a/tests/unit/codegen/sdk/python/file/test_file_reparse.py b/tests/unit/codegen/sdk/python/file/test_file_reparse.py index b3ec166db..7f14c79c4 100644 --- a/tests/unit/codegen/sdk/python/file/test_file_reparse.py +++ b/tests/unit/codegen/sdk/python/file/test_file_reparse.py @@ -17,38 +17,38 @@ def mock_codebase_setup(tmpdir) -> tuple[Codebase, File, File]: def test_file_reparse_rename_global_var(mock_codebase_setup: tuple[Codebase, File, File]) -> None: codebase, file1, file2 = mock_codebase_setup - G = codebase.G - init_nodes = G.get_nodes() - init_edges = G.get_edges() + ctx = codebase.ctx + init_nodes = ctx.get_nodes() + init_edges = ctx.get_edges() assert [x.name for x in file2.classes] == ["MyClass2"] assert [x.name for x in file2.get_class("MyClass2").methods] == ["__init__", "square_plus_constant", "cube_plus_constant", "sin_plus_constant"] file2.get_class("MyClass2").rename("MyClass3") - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert [x.name for x in file2.classes] == ["MyClass3"] assert [x.name for x in file2.get_class("MyClass3").methods] == ["__init__", "square_plus_constant", "cube_plus_constant", "sin_plus_constant"] - assert len(G.nodes) == len(init_nodes) - assert len(G.edges) == len(init_edges) + assert len(ctx.nodes) == len(init_nodes) + assert len(ctx.edges) == len(init_edges) def test_file_reparse_rename_referenced_class(mock_codebase_setup: tuple[Codebase, File, File]) -> None: codebase, file1, file2 = mock_codebase_setup - G = codebase.G - init_nodes = G.get_nodes() - init_edges = G.get_edges() + ctx = codebase.ctx + init_nodes = ctx.get_nodes() + init_edges = ctx.get_edges() assert [x.name for x in file1.classes] == ["MyClass1"] assert [x.name for x in file1.get_class("MyClass1").methods] == ["__init__", "square", "cube", "sin"] symbol_to_rename = file1.get_class("MyClass1") symbol_to_rename.rename("ReferencedClass") - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert [x.name for x in file1.classes] == ["ReferencedClass"] assert [x.name for x in file1.get_class("ReferencedClass").methods] == ["__init__", "square", "cube", "sin"] - assert len(G.nodes) == len(init_nodes) - assert len(G.edges) == len(init_edges) + assert len(ctx.nodes) == len(init_nodes) + assert len(ctx.edges) == len(init_edges) assert "MyClass1" not in file2.source assert "MyClass1" not in file2.content assert "MyClass1" not in file1.source @@ -58,9 +58,9 @@ def test_file_reparse_rename_referenced_class(mock_codebase_setup: tuple[Codebas def test_file_reparse_add_new_import(mock_codebase_setup: tuple[Codebase, File, File]) -> None: codebase, file1, file2 = mock_codebase_setup - G = codebase.G - init_nodes = G.get_nodes() - init_edges = G.get_edges() + ctx = codebase.ctx + init_nodes = ctx.get_nodes() + init_edges = ctx.get_edges() init_file1_imports = file1.imports new_content = file1.content + "\n\n" + "from datetime import datetime" @@ -73,7 +73,7 @@ def test_file_reparse_add_new_import(mock_codebase_setup: tuple[Codebase, File, assert "from datetime import datetime" in file1.source # Assert that the new import has been added an external module as well as new import - nodes_diff = set(G.get_nodes()) - set(init_nodes) + nodes_diff = set(ctx.get_nodes()) - set(init_nodes) external_module = next((x for x in nodes_diff if type(x).__name__ == "ExternalModule" and x.name == "datetime"), None) imp = next((x for x in nodes_diff if type(x).__name__ == "PyImport" and x.name == "datetime"), None) assert len(nodes_diff) == 2 @@ -81,7 +81,7 @@ def test_file_reparse_add_new_import(mock_codebase_setup: tuple[Codebase, File, assert imp is not None # Assert that new edges have been created to incorporate the new import and external module nodes - edges_diff = set(G.get_edges()) - set(init_edges) + edges_diff = set(ctx.get_edges()) - set(init_edges) imp_resolution_edge = next( ((u, v, edge_type, usage_type) for (u, v, edge_type, usage_type) in edges_diff if edge_type == EdgeType.IMPORT_SYMBOL_RESOLUTION and u == imp.node_id and v == external_module.node_id), None ) @@ -91,7 +91,7 @@ def test_file_reparse_add_new_import(mock_codebase_setup: tuple[Codebase, File, def test_file_reparse_move_global_var(mock_codebase_setup: tuple[Codebase, File, File]) -> None: codebase, file1, file2 = mock_codebase_setup - G = codebase.G + ctx = codebase.ctx # Move GLOBAL_CONSTANT_1 from file1 to file2 global_var1 = file1.get_global_var("GLOBAL_CONSTANT_1") @@ -104,7 +104,7 @@ def test_file_reparse_move_global_var(mock_codebase_setup: tuple[Codebase, File, imp_to_remove = file2.get_import("GLOBAL_CONSTANT_1") imp_to_remove.remove() - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert file1.get_symbol("GLOBAL_CONSTANT_1") is None assert file2.get_symbol("GLOBAL_CONSTANT_1") is not None @@ -141,15 +141,15 @@ def bar(x): file1 = codebase.get_file("dir/file1.py") file2 = codebase.get_file("file2.py") - G = codebase.G - init_nodes = G.get_nodes() - init_edges = G.get_edges() + ctx = codebase.ctx + init_nodes = ctx.get_nodes() + init_edges = ctx.get_edges() square_func = file0.get_function("square") square_func.rename("triangle") - assert len(G.get_nodes()) == len(init_nodes) - assert len(G.get_edges()) == len(init_edges) + assert len(ctx.get_nodes()) == len(init_nodes) + assert len(ctx.get_edges()) == len(init_edges) assert "square" not in file0.source assert "square" not in file0.content assert "triangle" in file0.source diff --git a/tests/unit/codegen/sdk/python/function/test_function_remove.py b/tests/unit/codegen/sdk/python/function/test_function_remove.py index f6b76e1cd..664d3ec0b 100644 --- a/tests/unit/codegen/sdk/python/function/test_function_remove.py +++ b/tests/unit/codegen/sdk/python/function/test_function_remove.py @@ -35,7 +35,7 @@ def bar(): codebase.reset() file.get_function("bar").remove() - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() # language=python assert ( file.content diff --git a/tests/unit/codegen/sdk/python/function/test_function_set_docstring.py b/tests/unit/codegen/sdk/python/function/test_function_set_docstring.py index f30d92c73..07482e846 100644 --- a/tests/unit/codegen/sdk/python/function/test_function_set_docstring.py +++ b/tests/unit/codegen/sdk/python/function/test_function_set_docstring.py @@ -45,7 +45,7 @@ def baz(self): foo = file.get_function("foo") foo.docstring.edit_text("This is a another docstring") - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() foo = file.get_function("foo") assert "This is a another docstring" in foo.docstring.text @@ -56,7 +56,7 @@ def baz(self): bar = file.get_function("bar") bar.set_docstring("This is a brand new docstring") - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() bar = file.get_symbol("bar") assert "This is a brand new docstring" in bar.docstring.text @@ -66,7 +66,7 @@ def baz(self): baz = file.get_class("A").get_method("baz") baz.set_docstring(".\nThis is a multi-line docstring\n.") - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() baz = file.get_class("A").get_method("baz") assert "This is a multi-line docstring" in baz.docstring.text @@ -77,7 +77,7 @@ def baz(self): baz = file.get_class("A").get_method("baz") baz.docstring.edit_text(".\nThis is a new multi-line docstring\n.") - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() baz = file.get_class("A").get_method("baz") assert "This is a new multi-line docstring" in baz.docstring.text diff --git a/tests/unit/codegen/sdk/python/global_var/test_global_var_remove.py b/tests/unit/codegen/sdk/python/global_var/test_global_var_remove.py index 6afaa06b0..2078f2e12 100644 --- a/tests/unit/codegen/sdk/python/global_var/test_global_var_remove.py +++ b/tests/unit/codegen/sdk/python/global_var/test_global_var_remove.py @@ -62,7 +62,7 @@ def test_global_var_remove_from_list(tmpdir) -> None: # Test remove a a = file.get_symbol("a") a.remove() - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert "a = 1" not in file.source assert "b = func()" in file.source assert "d = do_something()" in file.source @@ -71,7 +71,7 @@ def test_global_var_remove_from_list(tmpdir) -> None: # Test remove e e = file.get_symbol("e") e.remove() - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert "a = 1" not in file.source assert "b = func()" in file.source assert "d = do_something()" in file.source diff --git a/tests/unit/codegen/sdk/python/import_resolution/test_import_editable.py b/tests/unit/codegen/sdk/python/import_resolution/test_import_editable.py index 4b42ef6c6..bf2eb6834 100644 --- a/tests/unit/codegen/sdk/python/import_resolution/test_import_editable.py +++ b/tests/unit/codegen/sdk/python/import_resolution/test_import_editable.py @@ -36,7 +36,7 @@ def bar(a, b): ) file1.insert_before("import numpy as np\n", fix_indentation=True) - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() # language=python assert ( file1.content diff --git a/tests/unit/codegen/sdk/python/import_resolution/test_import_remove.py b/tests/unit/codegen/sdk/python/import_resolution/test_import_remove.py index d0f218f60..792bc416d 100644 --- a/tests/unit/codegen/sdk/python/import_resolution/test_import_remove.py +++ b/tests/unit/codegen/sdk/python/import_resolution/test_import_remove.py @@ -21,21 +21,21 @@ def test_import_remove_no_usage(tmpdir) -> None: # =====[ Remove b.c ]===== imp = file.get_import("d") imp.remove() - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert "from b.c import d # test two" not in file.content assert imp not in file.imports # =====[ Remove d.f ]===== imp = file.get_import("h") imp.remove() - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert "from d.f import (g as h, i as j) # test three" not in file.content assert "from d.f import (i as j) # test three" in file.content assert imp not in file.imports imp = file.get_import("j") imp.remove() - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert "from d.f" not in file.content @@ -76,7 +76,7 @@ def bar(): codebase.reset() file.imports[0].remove() - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() # language=python assert ( file.content @@ -165,35 +165,35 @@ def test_multi_import_multiple_remove_with_alias(tmpdir) -> None: file.get_import("h").remove() file.get_import("j").remove() file.get_import("y").remove() - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert "from d.f" not in file.content codebase.reset() file.get_import("y").remove() file.get_import("j").remove() file.get_import("h").remove() - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert "from d.f" not in file.content codebase.reset() file.get_import("y").remove() file.get_import("h").remove() file.get_import("j").remove() - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert "from d.f" not in file.content codebase.reset() file.get_import("j").remove() file.get_import("y").remove() file.get_import("h").remove() - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert "from d.f" not in file.content codebase.reset() file.get_import("j").remove() file.get_import("h").remove() file.get_import("y").remove() - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert "from d.f" not in file.content @@ -219,7 +219,7 @@ def test_multi_import_remove_import_from_multi_import(tmpdir) -> None: ) file.get_import("c").remove() - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() # language=python assert ( file.content @@ -230,7 +230,7 @@ def test_multi_import_remove_import_from_multi_import(tmpdir) -> None: ) file.get_import("b").remove() - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() # language=python assert ( file.content @@ -240,7 +240,7 @@ def test_multi_import_remove_import_from_multi_import(tmpdir) -> None: ) file.get_import("x").remove() - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() # language=python assert ( file.content @@ -250,7 +250,7 @@ def test_multi_import_remove_import_from_multi_import(tmpdir) -> None: ) file.get_import("z").remove() - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() # language=python assert ( file.content @@ -260,7 +260,7 @@ def test_multi_import_remove_import_from_multi_import(tmpdir) -> None: ) file.get_import("y").remove() - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert file.content.strip() == "" diff --git a/tests/unit/codegen/sdk/python/import_resolution/test_import_rename.py b/tests/unit/codegen/sdk/python/import_resolution/test_import_rename.py index 8f99a2d10..4a8a32deb 100644 --- a/tests/unit/codegen/sdk/python/import_resolution/test_import_rename.py +++ b/tests/unit/codegen/sdk/python/import_resolution/test_import_rename.py @@ -147,14 +147,14 @@ def test_multi_import_rename_with_alias(tmpdir) -> None: # =====[ Rename b.c ]===== imp = file.get_import("d") imp.rename("ABC") - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert "from b.c import ABC # test two" in file.content assert file.get_import("ABC").symbol_name.source == "ABC" # =====[ Rename a ]===== imp = file.get_import("a") imp.rename("z") - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert "import z # test one" in imp.file.content assert file.get_import("z").symbol_name.source == "z" diff --git a/tests/unit/codegen/sdk/python/import_resolution/test_import_set_import_module.py b/tests/unit/codegen/sdk/python/import_resolution/test_import_set_import_module.py index 623a2837a..b4e917b80 100644 --- a/tests/unit/codegen/sdk/python/import_resolution/test_import_set_import_module.py +++ b/tests/unit/codegen/sdk/python/import_resolution/test_import_set_import_module.py @@ -24,20 +24,20 @@ def test_update_import_module(tmpdir) -> None: # =====[ Rename b.c ]===== imp = file.get_import("d") imp.set_import_module("x.y.z") - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert "from x.y.z import d # test two" in file.content assert file.get_import("d").module.source == "x.y.z" # =====[ Rename d.f ]===== imp = file.get_import("h") imp.set_import_module("x.y.z") - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert "from x.y.z import (g as h, i as j) # test three" in file.content assert file.get_import("h").module.source == "x.y.z" # ===== [ Rename m ]===== imp = file.get_import("m") imp.set_import_module("z") - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert "from z import m # test four" in file.content assert file.get_import("m").module.source == "z" diff --git a/tests/unit/codegen/sdk/python/import_resolution/test_import_set_import_symbol_alias.py b/tests/unit/codegen/sdk/python/import_resolution/test_import_set_import_symbol_alias.py index 5ad882b79..232ecd5a9 100644 --- a/tests/unit/codegen/sdk/python/import_resolution/test_import_set_import_symbol_alias.py +++ b/tests/unit/codegen/sdk/python/import_resolution/test_import_set_import_symbol_alias.py @@ -42,7 +42,7 @@ def test_import_set_import_symbol_alias_from_existing_alias(tmpdir) -> None: imp = file.get_import("d") imp.set_import_symbol_alias("ABC") file = imp.to_file - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() imp = file.get_import("ABC") assert "from b.c import ABC # test two" in file.content assert imp.alias.source == "ABC" @@ -52,7 +52,7 @@ def test_import_set_import_symbol_alias_from_existing_alias(tmpdir) -> None: imp = file.get_import("h") imp.set_import_symbol_alias("XYZ") file = imp.to_file - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() imp = file.get_import("XYZ") assert "from d.f import (g as XYZ, i as j) # test three" in file.content assert imp.symbol_name.source == "g" diff --git a/tests/unit/codegen/sdk/python/statements/attribute/test_attribute_properties.py b/tests/unit/codegen/sdk/python/statements/attribute/test_attribute_properties.py index 01fee6fea..3ab80e2d3 100644 --- a/tests/unit/codegen/sdk/python/statements/attribute/test_attribute_properties.py +++ b/tests/unit/codegen/sdk/python/statements/attribute/test_attribute_properties.py @@ -86,4 +86,4 @@ def __init__(self, x, y, z): assert isinstance(b, PyAttribute) assert isinstance(b, PyAssignmentStatement) assert b.file_node_id == cls.file_node_id - assert b.G == cls.G + assert b.ctx == cls.ctx diff --git a/tests/unit/codegen/sdk/typescript/class_definition/test_class_definition_is_jsx.py b/tests/unit/codegen/sdk/typescript/class_definition/test_class_definition_is_jsx.py index b878f69c8..e11b2138b 100644 --- a/tests/unit/codegen/sdk/typescript/class_definition/test_class_definition_is_jsx.py +++ b/tests/unit/codegen/sdk/typescript/class_definition/test_class_definition_is_jsx.py @@ -8,8 +8,8 @@ class MyClass { constructor() {} } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file_content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file_content}) as ctx: + file = ctx.get_file("test.ts") my_class = file.get_class("MyClass") assert not my_class.is_jsx @@ -21,8 +21,8 @@ class MyClass extends BaseClass { constructor() {} } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file_content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file_content}) as ctx: + file = ctx.get_file("test.ts") my_class = file.get_class("MyClass") assert not my_class.is_jsx @@ -34,8 +34,8 @@ class MyComponent extends React.Component { constructor() {} } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file_content}) as G: - file = G.get_file("test.tsx") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file_content}) as ctx: + file = ctx.get_file("test.tsx") my_component = file.get_class("MyComponent") assert my_component.is_jsx @@ -47,8 +47,8 @@ class MyComponent extends Component { constructor() {} } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file_content}) as G: - file = G.get_file("test.tsx") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file_content}) as ctx: + file = ctx.get_file("test.tsx") my_component = file.get_class("MyComponent") assert my_component.is_jsx @@ -60,8 +60,8 @@ class MyComponent extends React.PureComponent { constructor() {} } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file_content}) as G: - file = G.get_file("test.tsx") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file_content}) as ctx: + file = ctx.get_file("test.tsx") my_component = file.get_class("MyComponent") assert my_component.is_jsx @@ -74,8 +74,8 @@ class MyComponent extends React.Component, Interface1, Interface2 { constructor() {} } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file_content}) as G: - file = G.get_file("test.tsx") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file_content}) as ctx: + file = ctx.get_file("test.tsx") my_component = file.get_class("MyComponent") assert my_component.is_jsx @@ -87,8 +87,8 @@ class MyComponent extends React.Component implements MyInterface { constructor() {} } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file_content}) as G: - file = G.get_file("test.tsx") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file_content}) as ctx: + file = ctx.get_file("test.tsx") my_component = file.get_class("MyComponent") assert my_component.is_jsx @@ -106,7 +106,7 @@ class MyComponent extends mixin(React.Component) { constructor() {} } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file_content}) as G: - file = G.get_file("test.tsx") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file_content}) as ctx: + file = ctx.get_file("test.tsx") my_component = file.get_class("MyComponent") assert my_component.is_jsx diff --git a/tests/unit/codegen/sdk/typescript/class_definition/test_class_dependencies.py b/tests/unit/codegen/sdk/typescript/class_definition/test_class_dependencies.py index fb6cc49e8..a5da206a8 100644 --- a/tests/unit/codegen/sdk/typescript/class_definition/test_class_dependencies.py +++ b/tests/unit/codegen/sdk/typescript/class_definition/test_class_dependencies.py @@ -40,8 +40,8 @@ def test_class_dependencies(tmpdir) -> None: } } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": content}) as G: - file = G.get_file("test.tsx") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": content}) as ctx: + file = ctx.get_file("test.tsx") cls = file.get_class("ExampleClass") deps = cls.dependencies diff --git a/tests/unit/codegen/sdk/typescript/class_definition/test_class_is_exported.py b/tests/unit/codegen/sdk/typescript/class_definition/test_class_is_exported.py index bd2e1eee7..4f169fedd 100644 --- a/tests/unit/codegen/sdk/typescript/class_definition/test_class_is_exported.py +++ b/tests/unit/codegen/sdk/typescript/class_definition/test_class_is_exported.py @@ -28,8 +28,8 @@ class NotExportedClass { } } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") exported_class = file.get_symbol("ExportedClass") assert exported_class.is_exported diff --git a/tests/unit/codegen/sdk/typescript/comment_docstring/test_comment.py b/tests/unit/codegen/sdk/typescript/comment_docstring/test_comment.py index 736c93617..023af08c6 100644 --- a/tests/unit/codegen/sdk/typescript/comment_docstring/test_comment.py +++ b/tests/unit/codegen/sdk/typescript/comment_docstring/test_comment.py @@ -7,8 +7,8 @@ def test_comment_basic(tmpdir) -> None: // this is a test comment const symbol = 1 """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment.source == "// this is a test comment" @@ -20,8 +20,8 @@ def test_comment_block(tmpdir) -> None: /* this is a test comment */ const symbol = 1 """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment.source == "/* this is a test comment */" @@ -32,8 +32,8 @@ def test_comment_no_comment(tmpdir) -> None: content = """ const symbol = 1 """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment is None @@ -45,8 +45,8 @@ def test_comment_multiline(tmpdir) -> None: // that spans multiple lines const symbol = 1 """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment.source == "// this is a test comment\n// that spans multiple lines" @@ -61,8 +61,8 @@ def test_comment_multiline_block(tmpdir) -> None: */ const symbol = 1 """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment.source == "/*\nthis is a test comment\nthat spans multiple lines\n*/" @@ -77,8 +77,8 @@ def test_comment_multiline_block_starred(tmpdir) -> None: */ const symbol = 1 """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment.source == "/**\n * this is a test comment\n * that spans multiple lines\n */" @@ -101,8 +101,8 @@ def test_comment_mixed(tmpdir) -> None: */ const symbol = 1 """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment.source == "// comment 1\n/* comment 2 */\n// comment 3\n// comment 4\n/*\ncomment 5\ncomment 6\n*/\n/*\n * comment 7\n * comment 8\n*/" @@ -116,8 +116,8 @@ def test_comment_weird_spacing(tmpdir) -> None: const symbol = 1 """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment.source == "// this is a test comment\n//that has weird spacing" @@ -130,8 +130,8 @@ def test_comment_weird_spacing_block(tmpdir) -> None: that has weird spacing*/ const symbol = 1 """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment.source == "/*this is a test comment\nthat has weird spacing*/" @@ -144,8 +144,8 @@ def test_comment_weird_spacing_block_starred(tmpdir) -> None: * that has weird spacing */ const symbol = 1 """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment.source == "/* this is a test comment\n* that has weird spacing */" @@ -163,8 +163,8 @@ class A { } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") A = file.get_symbol("A") symbol = A.get_method("symbol") @@ -184,8 +184,8 @@ class A { } } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") A = file.get_symbol("A") symbol = A.get_method("symbol") @@ -205,8 +205,8 @@ class A { } } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") A = file.get_symbol("A") symbol = A.get_method("symbol") @@ -222,8 +222,8 @@ def test_comment_with_spacing(tmpdir) -> None: const symbol = 1 """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment.source == "// this is a test comment\n// that has spacing" @@ -236,8 +236,8 @@ def test_comment_with_spacing_block(tmpdir) -> None: that has spacing */ const symbol = 1 """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment.source == "/* this is a test comment\n that has spacing */" @@ -252,8 +252,8 @@ def test_comment_with_spacing_block_starred(tmpdir) -> None: */ const symbol = 1 """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment.source == "/**\n * this is a test comment\n * that has spacing\n*/" diff --git a/tests/unit/codegen/sdk/typescript/comment_docstring/test_comment_edit.py b/tests/unit/codegen/sdk/typescript/comment_docstring/test_comment_edit.py index 2d3fe535a..f3c8b9786 100644 --- a/tests/unit/codegen/sdk/typescript/comment_docstring/test_comment_edit.py +++ b/tests/unit/codegen/sdk/typescript/comment_docstring/test_comment_edit.py @@ -9,8 +9,8 @@ def test_comment_basic(tmpdir) -> None: // this is a test comment const symbol = 1 """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment.source == "// this is a test comment" @@ -27,8 +27,8 @@ def test_comment_edit_source(tmpdir) -> None: // this is a test comment const symbol = 1 """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}, sync_graph=False) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}, sync_graph=False) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment.source == "// this is a test comment" @@ -45,8 +45,8 @@ def test_comment_block(tmpdir) -> None: /* this is a test comment */ const symbol = 1 """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment.source == "/* this is a test comment */" @@ -63,8 +63,8 @@ def test_comment_multiline(tmpdir) -> None: // that spans multiple lines const symbol = 1 """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment.source == "// this is a test comment\n// that spans multiple lines" @@ -83,8 +83,8 @@ def test_comment_multiline_block(tmpdir) -> None: */ const symbol = 1 """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment.source == "/*\nthis is a test comment\nthat spans multiple lines\n*/" @@ -103,8 +103,8 @@ def test_comment_multiline_block_starred(tmpdir) -> None: */ const symbol = 1 """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment.source == "/**\n * this is a test comment\n * that spans multiple lines\n */" @@ -131,8 +131,8 @@ def test_comment_mixed(tmpdir) -> None: */ const symbol = 1 """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment.source == "// comment 1\n/* comment 2 */\n// comment 3\n// comment 4\n/*\ncomment 5\ncomment 6\n*/\n/*\n * comment 7\n * comment 8\n*/" @@ -154,8 +154,8 @@ class A { } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") A = file.get_symbol("A") symbol = A.get_method("symbol") @@ -179,8 +179,8 @@ class A { } } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") A = file.get_symbol("A") symbol = A.get_method("symbol") @@ -204,8 +204,8 @@ class A { } } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") A = file.get_symbol("A") symbol = A.get_method("symbol") diff --git a/tests/unit/codegen/sdk/typescript/comment_docstring/test_comment_insert_add.py b/tests/unit/codegen/sdk/typescript/comment_docstring/test_comment_insert_add.py index 9dd668ad6..1bd0b62af 100644 --- a/tests/unit/codegen/sdk/typescript/comment_docstring/test_comment_insert_add.py +++ b/tests/unit/codegen/sdk/typescript/comment_docstring/test_comment_insert_add.py @@ -6,8 +6,8 @@ def test_set_comment(tmpdir) -> None: content = """ const symbol = 1 """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment is None @@ -21,8 +21,8 @@ def test_set_comment_with_formatting(tmpdir) -> None: content = """ const symbol = 1 """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment is None @@ -38,8 +38,8 @@ def test_set_comment_with_block_formatting(tmpdir) -> None: content = """ const symbol = 1 """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment is None @@ -55,8 +55,8 @@ def test_set_comment_multiline(tmpdir) -> None: content = """ const symbol = 1 """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment is None @@ -72,8 +72,8 @@ class MyClass { foo() {} } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") my_class = file.get_symbol("MyClass") foo = my_class.get_method("foo") @@ -88,8 +88,8 @@ def test_add_comment(tmpdir) -> None: // this is an existing comment const symbol = 1 """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") symbol.add_comment("this is a new comment") @@ -102,8 +102,8 @@ def test_add_comment_new(tmpdir) -> None: content = """ const symbol = 1 """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") symbol.add_comment("this is a new comment") @@ -117,8 +117,8 @@ def test_add_comment_with_formatting(tmpdir) -> None: // this is an existing comment const symbol = 1 """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") symbol.add_comment("// this is a new comment") @@ -134,8 +134,8 @@ def test_add_comment_with_block_formatting(tmpdir) -> None: // this is an existing comment const symbol = 1 """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") symbol.add_comment("/* this is a new comment */") @@ -152,8 +152,8 @@ def test_add_comment_multiline(tmpdir) -> None: // that spans multiple lines const symbol = 1 """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") symbol.add_comment("this is a new comment\nthat spans multiple lines") @@ -169,8 +169,8 @@ class MyClass { foo() {} } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") my_class = file.get_symbol("MyClass") foo = my_class.get_method("foo") @@ -185,8 +185,8 @@ def test_insert_comment(tmpdir) -> None: // this is a test comment const symbol = 1 """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment.source == "// this is a test comment" @@ -202,8 +202,8 @@ def test_insert_comment_block(tmpdir) -> None: /* this is a test comment */ const symbol = 1 """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment.source == "/* this is a test comment */" @@ -220,8 +220,8 @@ def test_insert_comment_multiline(tmpdir) -> None: // that spans multiple lines const symbol = 1 """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment.source == "// this is a test comment\n// that spans multiple lines" @@ -238,8 +238,8 @@ def test_insert_comment_weird_spacing(tmpdir) -> None: //that has weird spacing const symbol = 1 """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment.source == "// this is a test comment\n//that has weird spacing" @@ -257,8 +257,8 @@ class MyClass { foo() {} } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") my_class = file.get_symbol("MyClass") foo = my_class.get_method("foo") diff --git a/tests/unit/codegen/sdk/typescript/comment_docstring/test_docstring.py b/tests/unit/codegen/sdk/typescript/comment_docstring/test_docstring.py index 8801b664b..30bc5ecef 100644 --- a/tests/unit/codegen/sdk/typescript/comment_docstring/test_docstring.py +++ b/tests/unit/codegen/sdk/typescript/comment_docstring/test_docstring.py @@ -6,8 +6,8 @@ def test_docstring_no_docstring(tmpdir) -> None: content = """ function symbol() {} """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.docstring is None @@ -18,8 +18,8 @@ def test_docstring_noop(tmpdir) -> None: // this is a test docstring function symbol() {} """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.docstring is None @@ -30,8 +30,8 @@ def test_docstring_block(tmpdir) -> None: /* this is a test docstring */ function symbol() {} """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.docstring.source == "/* this is a test docstring */" @@ -44,8 +44,8 @@ def test_docstring_multiline_noop(tmpdir) -> None: // that spans multiple lines function symbol() {} """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.docstring is None @@ -59,8 +59,8 @@ def test_docstring_multiline_block(tmpdir) -> None: */ function symbol() {} """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.docstring.source == "/*\nthis is a test docstring\nthat spans multiple lines\n*/" @@ -75,8 +75,8 @@ def test_docstring_multiline_block_starred(tmpdir) -> None: */ function symbol() {} """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.docstring.source == "/**\n * this is a test docstring\n * that spans multiple lines\n */" @@ -92,8 +92,8 @@ def test_docstring_surrounded_by_comments(tmpdir) -> None: // this is another test comment function symbol() {} """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.docstring.source == "/**\n * this is a test docstring\n */" @@ -111,8 +111,8 @@ def test_docstring_combined(tmpdir) -> None: */ function symbol() {} """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.docstring.source == "/*\n * This is one part of a docstring.\n */\n/*\n * This is another part of a docstring.\n */" @@ -130,8 +130,8 @@ class MyClass { } } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") my_class = file.get_class("MyClass") my_method = my_class.get_method("myMethod") assert my_method.docstring.source == "/**\n * This is a method\n */" @@ -150,8 +150,8 @@ class MyClass { } } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") my_class = file.get_class("MyClass") my_method = my_class.get_method("myMethod") assert my_method.docstring.source == "/**\n * This is a method\n */" @@ -171,8 +171,8 @@ class MyClass { } } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") my_class = file.get_class("MyClass") my_method = my_class.get_method("myMethod") assert my_method.docstring is None @@ -185,8 +185,8 @@ def test_docstring_arrow_function(tmpdir) -> None: */ export const foo = () => {} """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") foo = file.get_symbol("foo") assert foo.docstring.source == "/**\n * This is a docstring\n */" assert foo.docstring.text == "This is a docstring" diff --git a/tests/unit/codegen/sdk/typescript/comment_docstring/test_docstring_edit.py b/tests/unit/codegen/sdk/typescript/comment_docstring/test_docstring_edit.py index cbc4f3d25..875d2c488 100644 --- a/tests/unit/codegen/sdk/typescript/comment_docstring/test_docstring_edit.py +++ b/tests/unit/codegen/sdk/typescript/comment_docstring/test_docstring_edit.py @@ -9,8 +9,8 @@ def test_docstring_block(tmpdir) -> None: /* this is a test docstring */ function symbol() {} """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.docstring.source == "/* this is a test docstring */" @@ -27,8 +27,8 @@ def test_docstring_block_source(tmpdir) -> None: /* this is a test docstring */ function symbol() {} """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}, sync_graph=False) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}, sync_graph=False) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.docstring.source == "/* this is a test docstring */" @@ -49,8 +49,8 @@ def test_docstring_multiline_block(tmpdir) -> None: */ function symbol() {} """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.docstring.source == "/*\nthis is a test docstring\nthat spans multiple lines\n*/" @@ -69,8 +69,8 @@ def test_docstring_multiline_block_starred(tmpdir) -> None: */ function symbol() {} """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.docstring.source == "/**\n * this is a test docstring\n * that spans multiple lines\n */" @@ -90,8 +90,8 @@ def test_docstring_surrounded_by_comments(tmpdir) -> None: // this is another test comment function symbol() {} """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.docstring.source == "/**\n * this is a test docstring\n */" @@ -115,8 +115,8 @@ def test_docstring_combined(tmpdir) -> None: */ function symbol() {} """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.docstring.source == "/*\n * This is one part of a docstring.\n */\n/*\n * This is another part of a docstring.\n */" @@ -133,8 +133,8 @@ def test_docstring_arrow_function(tmpdir) -> None: */ export const foo = () => {} """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") foo = file.get_symbol("foo") assert foo.docstring.source == "/**\n * this is a docstring\n */" assert foo.docstring.text == "this is a docstring" diff --git a/tests/unit/codegen/sdk/typescript/comment_docstring/test_docstring_insert_add.py b/tests/unit/codegen/sdk/typescript/comment_docstring/test_docstring_insert_add.py index 06789354d..106e70ef8 100644 --- a/tests/unit/codegen/sdk/typescript/comment_docstring/test_docstring_insert_add.py +++ b/tests/unit/codegen/sdk/typescript/comment_docstring/test_docstring_insert_add.py @@ -6,8 +6,8 @@ def test_set_docstring(tmpdir) -> None: content = """ export function symbol() {} """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.docstring is None @@ -21,8 +21,8 @@ def test_set_docstring_with_formatting(tmpdir) -> None: content = """ export function symbol() {} """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.docstring is None @@ -36,8 +36,8 @@ def test_set_docstring_multiline(tmpdir) -> None: content = """ function symbol() {} """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.docstring is None @@ -53,8 +53,8 @@ class A { foo() {} } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("A") foo = symbol.get_method("foo") @@ -71,8 +71,8 @@ class A { foo() {} } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("A") foo = symbol.get_method("foo") @@ -88,8 +88,8 @@ def test_insert_docstring_block(tmpdir) -> None: /* this is a test docstring */ function symbol() {} """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.docstring.source == "/* this is a test docstring */" @@ -108,8 +108,8 @@ def test_docstring_multiline_block(tmpdir) -> None: */ function symbol() {} """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.docstring.source == "/*\nthis is a test docstring\nthat spans multiple lines\n*/" @@ -128,8 +128,8 @@ def test_docstring_multiline_block_starred(tmpdir) -> None: */ function symbol() {} """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.docstring.source == "/**\n * this is a test docstring\n * that spans multiple lines\n */" @@ -149,8 +149,8 @@ def test_docstring_surrounded_by_comments(tmpdir) -> None: // this is another test comment function symbol() {} """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.docstring.source == "/**\n * this is a test docstring\n */" @@ -167,8 +167,8 @@ def test_docstring_arrow_function(tmpdir) -> None: content = """ export const foo = () => {} """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") foo = file.get_symbol("foo") foo.set_docstring("this is a new docstring") print(foo.extended.source) diff --git a/tests/unit/codegen/sdk/typescript/comment_docstring/test_inline_comment.py b/tests/unit/codegen/sdk/typescript/comment_docstring/test_inline_comment.py index d40a63259..f532614c1 100644 --- a/tests/unit/codegen/sdk/typescript/comment_docstring/test_inline_comment.py +++ b/tests/unit/codegen/sdk/typescript/comment_docstring/test_inline_comment.py @@ -6,8 +6,8 @@ def test_comment_inline(tmpdir) -> None: content = """ const symbol = 1; // this is an inline comment """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment is None @@ -19,8 +19,8 @@ def test_comment_inline_block(tmpdir) -> None: content = """ const symbol = 1; /* this is an inline comment */ """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment is None diff --git a/tests/unit/codegen/sdk/typescript/comment_docstring/test_inline_comment_edit.py b/tests/unit/codegen/sdk/typescript/comment_docstring/test_inline_comment_edit.py index 6e3934a8f..49c7e0536 100644 --- a/tests/unit/codegen/sdk/typescript/comment_docstring/test_inline_comment_edit.py +++ b/tests/unit/codegen/sdk/typescript/comment_docstring/test_inline_comment_edit.py @@ -6,8 +6,8 @@ def test_comment_inline(tmpdir) -> None: content = """ const symbol = 1; // this is an inline comment """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment is None @@ -23,8 +23,8 @@ def test_comment_inline_source(tmpdir) -> None: content = """ const symbol = 1; // this is an inline comment """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment is None @@ -40,8 +40,8 @@ def test_comment_inline_block(tmpdir) -> None: content = """ const symbol = 1; /* this is an inline comment */ """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment is None diff --git a/tests/unit/codegen/sdk/typescript/comment_docstring/test_inline_comment_insert_add.py b/tests/unit/codegen/sdk/typescript/comment_docstring/test_inline_comment_insert_add.py index dcf5e076c..597c3ce46 100644 --- a/tests/unit/codegen/sdk/typescript/comment_docstring/test_inline_comment_insert_add.py +++ b/tests/unit/codegen/sdk/typescript/comment_docstring/test_inline_comment_insert_add.py @@ -6,8 +6,8 @@ def test_set_comment_inline(tmpdir) -> None: content = """ const symbol = 1; """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment is None @@ -21,8 +21,8 @@ def test_set_comment_inline_with_formatting(tmpdir) -> None: content = """ const symbol = 1; """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment is None @@ -36,8 +36,8 @@ def test_set_comment_inline_with_block_formatting(tmpdir) -> None: content = """ const symbol = 1; """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment is None @@ -51,8 +51,8 @@ def test_insert_comment_inline(tmpdir) -> None: content = """ const symbol = 1; // this is an inline comment """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment is None @@ -68,8 +68,8 @@ def test_insert_comment_inline_block(tmpdir) -> None: content = """ const symbol = 1; /* this is an inline comment */ """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") symbol = file.get_symbol("symbol") assert symbol.comment is None diff --git a/tests/unit/codegen/sdk/typescript/detached_symbols/decorator/test_decorator_call.py b/tests/unit/codegen/sdk/typescript/detached_symbols/decorator/test_decorator_call.py index be1dd82f8..ea63c50d5 100644 --- a/tests/unit/codegen/sdk/typescript/detached_symbols/decorator/test_decorator_call.py +++ b/tests/unit/codegen/sdk/typescript/detached_symbols/decorator/test_decorator_call.py @@ -21,8 +21,8 @@ class TestClass { } } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"decorator.ts": content}) as G: - file = G.get_file("decorator.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"decorator.ts": content}) as ctx: + file = ctx.get_file("decorator.ts") test_class = file.get_class("TestClass") test_method = test_class.get_method("testMethod") diff --git a/tests/unit/codegen/sdk/typescript/detached_symbols/function_call/test_function_call_extended_source.py b/tests/unit/codegen/sdk/typescript/detached_symbols/function_call/test_function_call_extended_source.py index 9b27c5703..fbfd3cd36 100644 --- a/tests/unit/codegen/sdk/typescript/detached_symbols/function_call/test_function_call_extended_source.py +++ b/tests/unit/codegen/sdk/typescript/detached_symbols/function_call/test_function_call_extended_source.py @@ -21,8 +21,8 @@ def test_function_call_extended_source_in_chain(tmpdir) -> None: } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") # Check foo foo = file.get_function("foo") @@ -108,8 +108,8 @@ def test_function_call_extended_source_multiline_statement(tmpdir) -> None: } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") # Check foo foo = file.get_function("foo") diff --git a/tests/unit/codegen/sdk/typescript/detached_symbols/function_call/test_function_call_get_function_definition.py b/tests/unit/codegen/sdk/typescript/detached_symbols/function_call/test_function_call_get_function_definition.py index be2ef6505..de498afcd 100644 --- a/tests/unit/codegen/sdk/typescript/detached_symbols/function_call/test_function_call_get_function_definition.py +++ b/tests/unit/codegen/sdk/typescript/detached_symbols/function_call/test_function_call_get_function_definition.py @@ -20,9 +20,9 @@ def test_function_call_get_function_definition_returns_function(tmpdir) -> None: } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"src.ts": src_file, "dest.ts": dest_file}) as G: - src_file = G.get_file("src.ts") - dest_file = G.get_file("dest.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"src.ts": src_file, "dest.ts": dest_file}) as ctx: + src_file = ctx.get_file("src.ts") + dest_file = ctx.get_file("dest.ts") foo_function = src_file.get_symbol("foo") dest_foo_fcall = dest_file.get_symbol("bar").function_calls[0] assert dest_foo_fcall diff --git a/tests/unit/codegen/sdk/typescript/detached_symbols/function_call/test_function_call_is_awaited.py b/tests/unit/codegen/sdk/typescript/detached_symbols/function_call/test_function_call_is_awaited.py index 8ee567738..ab4c0784f 100644 --- a/tests/unit/codegen/sdk/typescript/detached_symbols/function_call/test_function_call_is_awaited.py +++ b/tests/unit/codegen/sdk/typescript/detached_symbols/function_call/test_function_call_is_awaited.py @@ -11,8 +11,8 @@ def test_function_call_is_awaited_basic(tmpdir) -> None: c(); await d(); """ - with get_codebase_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") assert len(file.function_calls) == 3 # Check if the function calls are awaited @@ -31,8 +31,8 @@ def test_function_call_is_awaited_wrapped(tmpdir) -> None: (d()); await (((e()))); """ - with get_codebase_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") assert len(file.function_calls) == 4 # Check if the function calls are awaited @@ -49,8 +49,8 @@ def test_function_call_is_awaited_nested(tmpdir) -> None: doAsync() // this is unawaited }) """ - with get_codebase_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") assert len(file.function_calls) == 2 # Check if the function calls are awaited @@ -65,8 +65,8 @@ def test_awaited_function_call_is_awaited(tmpdir) -> None: await mainOperation(() => formatData`process ${input} value`) """ - with get_codebase_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") assert len(file.function_calls) == 2 # Check if the function calls are awaited @@ -82,8 +82,8 @@ def test_function_call_is_awaited_nested_return(tmpdir) -> None: return finalInner(); // awaited since it's returned to awaited call }); """ - with get_codebase_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") assert len(file.function_calls) == 3 assert file.function_calls[0].is_awaited # outer assert not file.function_calls[1].is_awaited # inner @@ -99,8 +99,8 @@ def test_function_call_is_awaited_async_callbacks(tmpdir) -> None: return await fourth(); // awaited explicitly }); """ - with get_codebase_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") assert len(file.function_calls) == 4 assert file.function_calls[0].is_awaited # first assert not file.function_calls[1].is_awaited # second @@ -122,8 +122,8 @@ def test_function_call_is_awaited_conditional_returns(tmpdir) -> None: ternaryFalse(); // awaited (implicit return) }); """ - with get_codebase_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") assert len(file.function_calls) == 6 assert file.function_calls[0].is_awaited # outsideFunc assert not file.function_calls[1].is_awaited # insideIf diff --git a/tests/unit/codegen/sdk/typescript/detached_symbols/function_call/test_function_call_predecessor.py b/tests/unit/codegen/sdk/typescript/detached_symbols/function_call/test_function_call_predecessor.py index 8181f9a72..9f1e1d64a 100644 --- a/tests/unit/codegen/sdk/typescript/detached_symbols/function_call/test_function_call_predecessor.py +++ b/tests/unit/codegen/sdk/typescript/detached_symbols/function_call/test_function_call_predecessor.py @@ -21,8 +21,8 @@ def test_function_call_predecessor_single_line(tmpdir) -> None: } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") # Check foo foo = file.get_function("foo") @@ -97,8 +97,8 @@ def test_function_call_predecessor_multiline(tmpdir) -> None: } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") # Check foo foo = file.get_function("foo") diff --git a/tests/unit/codegen/sdk/typescript/file/test_file_add_symbol_from_source.py b/tests/unit/codegen/sdk/typescript/file/test_file_add_symbol_from_source.py index 2c9367fa5..f43642dad 100644 --- a/tests/unit/codegen/sdk/typescript/file/test_file_add_symbol_from_source.py +++ b/tests/unit/codegen/sdk/typescript/file/test_file_add_symbol_from_source.py @@ -17,14 +17,14 @@ def test_add_symbol_from_source(tmpdir) -> None: file.add_symbol_from_source(source="export const c = 1") symbol = file.get_symbol("c") - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert symbol.name == "c" assert isinstance(symbol, Assignment) assert "export const c = 1" in file.content assert symbol.is_exported file.add_symbol_from_source(source="const b = 1") - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() symbol = file.get_symbol("b") assert symbol.name == "b" assert isinstance(symbol, Assignment) @@ -40,7 +40,7 @@ def test_add_symbol_from_source(tmpdir) -> None: """ file.add_symbol_from_source(source=f"export {new_symbol_source}") - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() symbol = file.get_symbol("addSymbolToFile") assert symbol.name == "addSymbolToFile" assert symbol.is_exported diff --git a/tests/unit/codegen/sdk/typescript/file/test_file_get_global_var.py b/tests/unit/codegen/sdk/typescript/file/test_file_get_global_var.py index 893d21f39..9ac0ab377 100644 --- a/tests/unit/codegen/sdk/typescript/file/test_file_get_global_var.py +++ b/tests/unit/codegen/sdk/typescript/file/test_file_get_global_var.py @@ -9,8 +9,8 @@ def test_get_global_var_excludes_component_var(tmpdir) -> None: return <>Hello World; }; """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": ts_code}) as G: - file = G.get_file("test.tsx") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": ts_code}) as ctx: + file = ctx.get_file("test.tsx") # =====[ Count symbols ]===== symbols = file.symbols @@ -38,8 +38,8 @@ def test_get_global_var_excludes_class_var(tmpdir) -> None: }; } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": ts_code}) as G: - file = G.get_file("test.tsx") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": ts_code}) as ctx: + file = ctx.get_file("test.tsx") cls = file.get_class("CopyButton") assert cls is not None assert cls.name == "CopyButton" diff --git a/tests/unit/codegen/sdk/typescript/file/test_file_get_import_string.py b/tests/unit/codegen/sdk/typescript/file/test_file_get_import_string.py index 7b36d1e38..6e7eb5806 100644 --- a/tests/unit/codegen/sdk/typescript/file/test_file_get_import_string.py +++ b/tests/unit/codegen/sdk/typescript/file/test_file_get_import_string.py @@ -9,8 +9,8 @@ def test_file_get_import_string_no_params(tmpdir) -> None: let scores: number[] = [90, 85, 92]; let person: { name: string, age: number } = { name: "Alice", age: 30 }; """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") file_import_string = file.get_import_string() assert file_import_string == "import * as test from 'test'" diff --git a/tests/unit/codegen/sdk/typescript/file/test_file_global_vars.py b/tests/unit/codegen/sdk/typescript/file/test_file_global_vars.py index 7ee0229ba..10cb763eb 100644 --- a/tests/unit/codegen/sdk/typescript/file/test_file_global_vars.py +++ b/tests/unit/codegen/sdk/typescript/file/test_file_global_vars.py @@ -15,8 +15,8 @@ def test_global_vars_gets_exported_global_vars(tmpdir) -> None: "value2", ] as const """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={filename: content}) as G: - file = G.get_file(filename) + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={filename: content}) as ctx: + file = ctx.get_file(filename) # ======[ Global Vars ]===== gvars = file.global_vars diff --git a/tests/unit/codegen/sdk/typescript/file/test_file_graph.py b/tests/unit/codegen/sdk/typescript/file/test_file_graph.py index 0dd436182..25529f71e 100644 --- a/tests/unit/codegen/sdk/typescript/file/test_file_graph.py +++ b/tests/unit/codegen/sdk/typescript/file/test_file_graph.py @@ -12,7 +12,7 @@ def test_graph_has_node_for_existing_file(tmpdir) -> None: with get_codebase_session(tmpdir=tmpdir, files={"test.ts": content}, programming_language=ProgrammingLanguage.TYPESCRIPT) as codebase: file = codebase.get_file("test.ts") - G = codebase.G - assert G.has_node(file.node_id) - assert G.get_node(file.node_id) == file - assert G.has_node(file.node_id) + ctx = codebase.ctx + assert ctx.has_node(file.node_id) + assert ctx.get_node(file.node_id) == file + assert ctx.has_node(file.node_id) diff --git a/tests/unit/codegen/sdk/typescript/file/test_file_imports.py b/tests/unit/codegen/sdk/typescript/file/test_file_imports.py index cd0f6a436..01f87bab0 100644 --- a/tests/unit/codegen/sdk/typescript/file/test_file_imports.py +++ b/tests/unit/codegen/sdk/typescript/file/test_file_imports.py @@ -6,8 +6,8 @@ def test_file_imports_default_import(tmpdir) -> None: file = """ import a from './some_file.js'; """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") imports = file.imports assert len(imports) == 1 assert imports[0].symbol_name.source == "a" @@ -19,8 +19,8 @@ def test_file_imports_named_import(tmpdir) -> None: file = """ import { b, c } from './some_other_file.js'; """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") imports = file.imports assert len(imports) == 2 assert imports[0].symbol_name.source == "b" @@ -35,8 +35,8 @@ def test_file_imports_exports(tmpdir) -> None: file = """ export {a, b} from './some_random_file.js' """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") exports = file.imports # TODO: shouldn't this be called export? assert len(exports) == 2 assert exports[0].symbol_name.source == "a" @@ -51,8 +51,8 @@ def test_file_imports_aliased_import(tmpdir) -> None: file = """ import { a as b } from './some_file.js'; """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") imports = file.imports assert len(imports) == 1 assert imports[0].symbol_name.source == "a" @@ -65,8 +65,8 @@ def test_file_imports_aliased_exports(tmpdir) -> None: file = """ export { a as b } from './some_file.js'; """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") exports = file.imports assert len(exports) == 1 assert exports[0].symbol_name.source == "a" @@ -79,8 +79,8 @@ def test_file_imports_namespace_import(tmpdir) -> None: file = """ import * as React from 'react'; """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") exports = file.imports assert exports[0].symbol_name.source == "* as React" assert exports[0].alias.source == "React" @@ -93,8 +93,8 @@ def test_file_imports_namespace_export(tmpdir) -> None: export * as React from 'react'; """ # TODO: @edward @edo is this correct? - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") exports = file.imports assert len(exports) == 1 assert exports[0].symbol_name.source == "* as React" @@ -115,8 +115,8 @@ def test_file_imports_require_statements(tmpdir) -> None: module.exports = router; """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") assert "router" not in [x.name for x in file.imports] assert "pkg1" in [x.name for x in file.imports] assert "pkg3" in [x.name for x in file.imports] @@ -136,8 +136,8 @@ def test_file_imports_dynamic_imports(tmpdir) -> None: module => module.default, ) """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") assert "module2" in [x.name for x in file.imports] assert "import1" in [x.name for x in file.imports] assert "import2" in [x.name for x in file.imports] diff --git a/tests/unit/codegen/sdk/typescript/file/test_file_symbols.py b/tests/unit/codegen/sdk/typescript/file/test_file_symbols.py index 7152e3ca9..5656c9da4 100644 --- a/tests/unit/codegen/sdk/typescript/file/test_file_symbols.py +++ b/tests/unit/codegen/sdk/typescript/file/test_file_symbols.py @@ -18,8 +18,8 @@ class foo { } } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") symbols = file.symbols assert len(symbols) == 1 assert set(s.name for s in symbols) == {"foo"} @@ -33,8 +33,8 @@ class foo { } } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") symbols = file.symbols assert len(symbols) == 1 assert set(s.name for s in symbols) == {"foo"} @@ -48,8 +48,8 @@ class foo { } } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") symbols = file.symbols assert len(symbols) == 1 assert set(s.name for s in symbols) == {"foo"} @@ -67,8 +67,8 @@ class foo { } } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") symbols = file.symbols assert len(symbols) == 1 assert set(s.name for s in symbols) == {"foo"} @@ -84,8 +84,8 @@ class foo extends bar { } } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") symbols = file.symbols assert len(symbols) == 2 assert set(s.name for s in symbols) == {"foo", "bar"} @@ -101,8 +101,8 @@ class foo extends bar { } } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") # =====[ symbols ]===== symbols = file.symbols @@ -130,8 +130,8 @@ def test_file_symbols_does_not_include_arrow_function(tmpdir) -> None: }) """ # Should not get any functions - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") assert len(file.symbols) == 0 @@ -146,8 +146,8 @@ def test_file_symbols_includes_types(tmpdir) -> None: [key: string]: T; };""" - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") symbols = file.symbols assert len(symbols) == 2 assert symbols[0].name == "Person" diff --git a/tests/unit/codegen/sdk/typescript/file/test_ts_config_properties.py b/tests/unit/codegen/sdk/typescript/file/test_ts_config_properties.py index 17adfebe7..a5a2bde10 100644 --- a/tests/unit/codegen/sdk/typescript/file/test_ts_config_properties.py +++ b/tests/unit/codegen/sdk/typescript/file/test_ts_config_properties.py @@ -62,9 +62,9 @@ def test_file_get_config(tmpdir) -> None: files={parent_file_name: "", child_file_name: "", sibling_file_name: "", config_name: config_content, root_config_name: root_config_content, parent_config_name: parent_config_content}, commit=True, ) as codebase: - config: TSConfig = codebase.G.config_parser.get_config(config_name) - root_config: TSConfig = codebase.G.config_parser.get_config(root_config_name) - parent_config: TSConfig = codebase.G.config_parser.get_config(parent_config_name) + config: TSConfig = codebase.ctx.config_parser.get_config(config_name) + root_config: TSConfig = codebase.ctx.config_parser.get_config(root_config_name) + parent_config: TSConfig = codebase.ctx.config_parser.get_config(parent_config_name) assert config is not None assert config.config_file.filepath == config_name diff --git a/tests/unit/codegen/sdk/typescript/function/test_function_dependencies.py b/tests/unit/codegen/sdk/typescript/function/test_function_dependencies.py index 5ed0d750c..52e799452 100644 --- a/tests/unit/codegen/sdk/typescript/function/test_function_dependencies.py +++ b/tests/unit/codegen/sdk/typescript/function/test_function_dependencies.py @@ -11,8 +11,8 @@ def test_functions_dependencies_async_function_finds_deps(tmpdir) -> None: return a + b + d; }; """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": ts_code}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": ts_code}) as ctx: + file = ctx.get_file("test.ts") # =====[ Test myFunction ]===== my_function = file.get_function("myFunction") @@ -34,8 +34,8 @@ def test_functions_dependencies_generator_function_finds_deps(tmpdir) -> None: yield a + b + d; } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": ts_code}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": ts_code}) as ctx: + file = ctx.get_file("test.ts") # =====[ Test myFunction ]===== my_function = file.get_function("myFunction") @@ -55,8 +55,8 @@ def test_functions_dependencies_arrow_function_finds_deps(tmpdir) -> None: const myFunction = (a: A, b) => a + b + d; """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": ts_code}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": ts_code}) as ctx: + file = ctx.get_file("test.ts") # =====[ Test myFunction ]===== my_function = file.get_function("myFunction") @@ -78,8 +78,8 @@ def test_functions_dependencies_function_expression_finds_deps(tmpdir) -> None: return a + b + d; }; """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": ts_code}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": ts_code}) as ctx: + file = ctx.get_file("test.ts") # =====[ Test myFunction ]===== my_function = file.get_function("myFunction") @@ -101,8 +101,8 @@ def test_functions_dependencies_named_function_finds_deps(tmpdir) -> None: return a + b + d; } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": ts_code}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": ts_code}) as ctx: + file = ctx.get_file("test.ts") # =====[ Test myFunction ]===== my_function = file.get_function("myFunction") @@ -125,8 +125,8 @@ def test_functions_dependencies_finds_function_dep(tmpdir) -> None: bar(); } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": ts_code}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": ts_code}) as ctx: + file = ctx.get_file("test.ts") # =====[ Test bar ]===== bar = file.get_function("bar") @@ -156,8 +156,8 @@ def test_function_dependencies_gets_param_type_annotations(tmpdir) -> None: return a + b + d; }; """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") my_func = file.get_function("myFunc") deps = my_func.dependencies assert len(deps) == 2 diff --git a/tests/unit/codegen/sdk/typescript/function/test_function_function_declaration_docstring.py b/tests/unit/codegen/sdk/typescript/function/test_function_function_declaration_docstring.py index 10b6fea16..aa83691a4 100644 --- a/tests/unit/codegen/sdk/typescript/function/test_function_function_declaration_docstring.py +++ b/tests/unit/codegen/sdk/typescript/function/test_function_function_declaration_docstring.py @@ -29,8 +29,8 @@ def test_function_signature(tmpdir) -> None: } """ # =====[ Dependencies ]===== - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") add_function = file.get_function("add") func_dec_str = add_function.function_signature assert func_dec_str == "function add(a: number, b: number): number" diff --git a/tests/unit/codegen/sdk/typescript/function/test_function_is_exported.py b/tests/unit/codegen/sdk/typescript/function/test_function_is_exported.py index afefa32a8..eccd04f68 100644 --- a/tests/unit/codegen/sdk/typescript/function/test_function_is_exported.py +++ b/tests/unit/codegen/sdk/typescript/function/test_function_is_exported.py @@ -9,8 +9,8 @@ def test_function_named_function_is_exported_should_return_true(tmpdir) -> None: return x } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") add_symbol_to_file = file.get_symbol("add_symbol_to_file") assert add_symbol_to_file.is_exported @@ -26,8 +26,8 @@ def test_function_arrow_function_is_exported_should_return_true(tmpdir) -> None: return arg.equals(a); } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") exported_equals_function = file.get_symbol("exportedEqualsFunction") assert exported_equals_function.is_exported @@ -39,8 +39,8 @@ def test_function_arrow_function_is_exported_should_return_false(tmpdir) -> None return arg.equals(a); } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") exported_equals_function = file.get_symbol("equalsFunction") assert not exported_equals_function.is_exported diff --git a/tests/unit/codegen/sdk/typescript/function/test_function_parameters.py b/tests/unit/codegen/sdk/typescript/function/test_function_parameters.py index f27c5cad3..391c6352b 100644 --- a/tests/unit/codegen/sdk/typescript/function/test_function_parameters.py +++ b/tests/unit/codegen/sdk/typescript/function/test_function_parameters.py @@ -95,8 +95,8 @@ def test_tsx_component_default_params(tmpdir) -> None: return null; } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as G: - file = G.get_file("test.tsx") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as ctx: + file = ctx.get_file("test.tsx") child = file.get_symbol("Child") assert child is not None assert child.is_jsx @@ -145,8 +145,8 @@ def test_tsx_component_parameters(tmpdir) -> None: } } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as G: - file = G.get_file("test.tsx") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as ctx: + file = ctx.get_file("test.tsx") component = file.get_symbol("DefaultLoading") assert component is not None assert component.is_jsx diff --git a/tests/unit/codegen/sdk/typescript/function/test_function_set_docstring.py b/tests/unit/codegen/sdk/typescript/function/test_function_set_docstring.py index b25a5e135..ed2930b12 100644 --- a/tests/unit/codegen/sdk/typescript/function/test_function_set_docstring.py +++ b/tests/unit/codegen/sdk/typescript/function/test_function_set_docstring.py @@ -39,7 +39,7 @@ class A { # Check setting docstring no quotes foo = file.get_symbol("foo") foo.docstring.edit_text("This is a another docstring") - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() foo = file.get_symbol("foo") assert "This is a another docstring" in foo.docstring.text assert "This is a new docstring" not in foo.docstring.text @@ -48,7 +48,7 @@ class A { # Check creating a new docstring bar = file.get_symbol("bar") bar.set_docstring("This is a brand new docstring") - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() bar = file.get_symbol("bar") assert "This is a brand new docstring" in bar.docstring.text assert "return 2;" in bar.extended_source @@ -56,7 +56,7 @@ class A { # Check creating a multi-line docstring baz = file.get_symbol("A").get_method("baz") baz.set_docstring(".\nThis is a multi-line docstring\n.") - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() baz = file.get_symbol("A").get_method("baz") assert " * This is a multi-line docstring" in baz.extended_source assert "This is a multi-line docstring" in baz.docstring.text @@ -65,7 +65,7 @@ class A { # Check modifying a multi-line docstring baz = file.get_symbol("A").get_method("baz") baz.docstring.edit_text(".\nThis is a new multi-line docstring\n.") - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() baz = file.get_symbol("A").get_method("baz") assert " * This is a new multi-line docstring" in baz.extended_source assert "This is a new multi-line docstring" in baz.docstring.text diff --git a/tests/unit/codegen/sdk/typescript/function/test_function_usages.py b/tests/unit/codegen/sdk/typescript/function/test_function_usages.py index ee35da2fc..38e3e5598 100644 --- a/tests/unit/codegen/sdk/typescript/function/test_function_usages.py +++ b/tests/unit/codegen/sdk/typescript/function/test_function_usages.py @@ -188,8 +188,8 @@ def test_function_spread_and_f_string(tmpdir) -> None: return `${child()}` } """ - with get_codebase_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") # =====[ Test dependencies ]===== func = file.get_function("parent1") diff --git a/tests/unit/codegen/sdk/typescript/global_var/test_global_var_dependencies.py b/tests/unit/codegen/sdk/typescript/global_var/test_global_var_dependencies.py index 7592855a8..6c5f248f5 100644 --- a/tests/unit/codegen/sdk/typescript/global_var/test_global_var_dependencies.py +++ b/tests/unit/codegen/sdk/typescript/global_var/test_global_var_dependencies.py @@ -19,8 +19,8 @@ def test_dependencies_gets_symbols_in_same_file(tmpdir) -> None: key: foo, } as const """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={filename: content}) as G: - file = G.get_file(filename) + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={filename: content}) as ctx: + file = ctx.get_file(filename) gvar: TSAssignment = file.get_global_var("bar") deps = gvar.dependencies @@ -37,8 +37,8 @@ def test_dependencies_gets_imports(tmpdir) -> None: ...helper(), ] as const """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={filename: content}) as G: - file = G.get_file(filename) + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={filename: content}) as ctx: + file = ctx.get_file(filename) gvar: TSAssignment = file.get_global_var("values") deps = gvar.dependencies @@ -55,8 +55,8 @@ def test_dependencies_finds_multiple_symbol_deps(tmpdir) -> None: let f = a + b + c; export const g = 6; """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": ts_code}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": ts_code}) as ctx: + file = ctx.get_file("test.ts") # =====[ Count symbols ]===== symbols = file.symbols @@ -78,8 +78,8 @@ def test_global_var_dependencies_value(tmpdir) -> None: Container.SubComponent = Component """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": ts_code}) as G: - file = G.get_file("test.tsx") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": ts_code}) as ctx: + file = ctx.get_file("test.tsx") # =====[ Count symbols ]===== symbol = file.get_symbol("Component") diff --git a/tests/unit/codegen/sdk/typescript/global_var/test_global_var_is_exported.py b/tests/unit/codegen/sdk/typescript/global_var/test_global_var_is_exported.py index edf7eac7b..208ac0b79 100644 --- a/tests/unit/codegen/sdk/typescript/global_var/test_global_var_is_exported.py +++ b/tests/unit/codegen/sdk/typescript/global_var/test_global_var_is_exported.py @@ -6,8 +6,8 @@ def test_is_exported_should_return_true(tmpdir) -> None: ts_code = """ export const g = 6; """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": ts_code}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": ts_code}) as ctx: + file = ctx.get_file("test.ts") g = file.get_global_var("g") assert g.is_exported is True @@ -16,8 +16,8 @@ def test_is_exported_should_return_false(tmpdir) -> None: ts_code = """ const h = 1; """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": ts_code}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": ts_code}) as ctx: + file = ctx.get_file("test.ts") h = file.get_global_var("h") assert h.is_exported is False @@ -26,7 +26,7 @@ def test_is_exported_let(tmpdir) -> None: file = """ export let a = 'c' """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") global_var_a = file.get_symbol("a") assert global_var_a.is_exported diff --git a/tests/unit/codegen/sdk/typescript/global_var/test_global_var_parsing.py b/tests/unit/codegen/sdk/typescript/global_var/test_global_var_parsing.py index a0063d65b..d3c44a985 100644 --- a/tests/unit/codegen/sdk/typescript/global_var/test_global_var_parsing.py +++ b/tests/unit/codegen/sdk/typescript/global_var/test_global_var_parsing.py @@ -10,8 +10,8 @@ def test_parse_global_vars(tmpdir) -> None: const b = 10; var c = d; """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") global_vars = file.global_vars assert len(global_vars) == 3 assert set([x.name for x in global_vars]) == {"a", "b", "c"} @@ -56,8 +56,8 @@ def test_tsx_get_object(tmpdir) -> None: ref: arrowFunction, } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as G: - file = G.get_file("test.tsx") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as ctx: + file = ctx.get_file("test.tsx") # =====[ arrowFunction ]===== arrow_func = file.get_symbol("arrowFunction") @@ -133,7 +133,7 @@ def test_tsx_component_usages(tmpdir) -> None: }, } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as G: - file = G.get_file("test.tsx") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as ctx: + file = ctx.get_file("test.tsx") component = file.get_symbol("TestComponent") assert len(component.symbol_usages) > 0 diff --git a/tests/unit/codegen/sdk/typescript/global_var/test_global_var_special.py b/tests/unit/codegen/sdk/typescript/global_var/test_global_var_special.py index faa8f2814..3a1e79887 100644 --- a/tests/unit/codegen/sdk/typescript/global_var/test_global_var_special.py +++ b/tests/unit/codegen/sdk/typescript/global_var/test_global_var_special.py @@ -10,8 +10,8 @@ def test_global_var_attribute(tmpdir) -> None: A.bar = foo() """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") assert len(file.global_vars) == 2 foo = file.get_function("foo") assert len(foo.symbol_usages) == 1 diff --git a/tests/unit/codegen/sdk/typescript/import_resolution/test_import_resolution_remove.py b/tests/unit/codegen/sdk/typescript/import_resolution/test_import_resolution_remove.py index 08f8fd0f3..764e38450 100644 --- a/tests/unit/codegen/sdk/typescript/import_resolution/test_import_resolution_remove.py +++ b/tests/unit/codegen/sdk/typescript/import_resolution/test_import_resolution_remove.py @@ -22,14 +22,14 @@ def test_remove_import_removes_from_file_imports(tmpdir) -> None: # =====[ Remove b/c ]===== imp = file.get_import("d") imp.remove() - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert "import { d } from 'b/c'; // test two" not in imp.to_file.content assert imp not in imp.to_file.imports # =====[ Remove d/f ]===== imp = file.get_import("g") imp.remove() - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert "import { j as i } from 'd/f'; // test three" in file.content assert imp not in file.imports diff --git a/tests/unit/codegen/sdk/typescript/import_resolution/test_import_resolution_rename.py b/tests/unit/codegen/sdk/typescript/import_resolution/test_import_resolution_rename.py index 8452a3e4c..165ed5915 100644 --- a/tests/unit/codegen/sdk/typescript/import_resolution/test_import_resolution_rename.py +++ b/tests/unit/codegen/sdk/typescript/import_resolution/test_import_resolution_rename.py @@ -25,7 +25,7 @@ def test_rename_import_updates_source(tmpdir) -> None: # =====[ Rename b/c ]===== imp = file.get_import("d") imp.rename("ABC") - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() imp = file.get_import("d") assert "import { ABC } from 'b/c'; // test two" in file.content assert file.get_import("ABC").symbol_name.source == "ABC" @@ -33,6 +33,6 @@ def test_rename_import_updates_source(tmpdir) -> None: # =====[ Rename a ]===== imp = file.get_import("a") imp.rename("z") - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert "import z from 'b'; // test one" in file.content assert file.get_import("z").symbol_name.source == "z" diff --git a/tests/unit/codegen/sdk/typescript/import_resolution/test_import_resolution_set_import_module.py b/tests/unit/codegen/sdk/typescript/import_resolution/test_import_resolution_set_import_module.py index 55451b5b2..5bcc23137 100644 --- a/tests/unit/codegen/sdk/typescript/import_resolution/test_import_resolution_set_import_module.py +++ b/tests/unit/codegen/sdk/typescript/import_resolution/test_import_resolution_set_import_module.py @@ -16,20 +16,20 @@ def test_set_import_module_updates_source(tmpdir) -> None: # =====[ Rename a ]===== file.get_import("a").set_import_module("z") - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert " import a from 'z'; // test one" in file.content assert file.get_import("a").module.source == "'z'" # =====[ Rename b/c ]===== file.get_import("d").set_import_module("x/y/z") - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert " import { d } from 'x/y/z'; // test two" in file.content assert file.get_import("d").module.source == "'x/y/z'" # =====[ Rename d/f ]===== file.get_import("g").set_import_module('"x/y/z"') - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert ' import { h as g, j as i } from "x/y/z"; // test three' in file.content assert file.get_import("g").module.source == '"x/y/z"' @@ -52,24 +52,24 @@ def test_set_import_module_quote_handling(tmpdir) -> None: # Test 1: Normal path should use single quotes (TypeScript standard) file.get_import("normal").set_import_module("new/standard/path") - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert "import normal from 'new/standard/path'; // should convert to single quotes" in file.content assert file.get_import("normal").module.source == "'new/standard/path'" # Test 2: Path with single quote should use double quotes file.get_import("singleQuote").set_import_module("new/don't/break/path") - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert 'import singleQuote from "new/don\'t/break/path"; // should use double quotes' in file.content assert file.get_import("singleQuote").module.source == '"new/don\'t/break/path"' # Test 3: Already quoted path (single quotes) should work file.get_import("alreadyQuoted").set_import_module("'new/quoted/path'") - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert "import alreadyQuoted from 'new/quoted/path'; // should preserve quotes" in file.content assert file.get_import("alreadyQuoted").module.source == "'new/quoted/path'" # Test 4: Already quoted path (double quotes) should work file.get_import("doubleQuoted").set_import_module('"another/quoted/path"') - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert ' import doubleQuoted from "another/quoted/path"; // should convert to single quotes' in file.content assert file.get_import("doubleQuoted").module.source == '"another/quoted/path"' diff --git a/tests/unit/codegen/sdk/typescript/import_resolution/test_import_resolution_set_import_symbol_alias.py b/tests/unit/codegen/sdk/typescript/import_resolution/test_import_resolution_set_import_symbol_alias.py index 6839790d5..5fc9f3d24 100644 --- a/tests/unit/codegen/sdk/typescript/import_resolution/test_import_resolution_set_import_symbol_alias.py +++ b/tests/unit/codegen/sdk/typescript/import_resolution/test_import_resolution_set_import_symbol_alias.py @@ -27,7 +27,7 @@ def test_set_import_symbol_alias_updates_source(tmpdir) -> None: # =====[ Rename b/c ]===== imp = file.get_import("d") imp.set_import_symbol_alias("ABC") - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() imp = file.get_import("ABC") assert "import { ABC } from 'b/c'; // test two" in file.content assert imp.alias.source == "ABC" @@ -37,7 +37,7 @@ def test_set_import_symbol_alias_updates_source(tmpdir) -> None: # =====[ Rename d/f ]===== imp = file.get_import("g") imp.set_import_symbol_alias("XYZ") - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() imp = file.get_import("XYZ") assert "import { h as XYZ, j as i } from 'd/f'; // test three" in file.content assert imp.symbol_name.source == "h" diff --git a/tests/unit/codegen/sdk/typescript/interface/test_interface_attributes.py b/tests/unit/codegen/sdk/typescript/interface/test_interface_attributes.py index e4014a776..8da1cb31c 100644 --- a/tests/unit/codegen/sdk/typescript/interface/test_interface_attributes.py +++ b/tests/unit/codegen/sdk/typescript/interface/test_interface_attributes.py @@ -14,8 +14,8 @@ def test_interface_attributes_finds_correct_number(tmpdir) -> None: age: number; } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") animal = file.get_symbol("Animal") assert len(animal.attributes) == 2 diff --git a/tests/unit/codegen/sdk/typescript/interface/test_interface_dependencies.py b/tests/unit/codegen/sdk/typescript/interface/test_interface_dependencies.py index 7527d31ae..8fd536b67 100644 --- a/tests/unit/codegen/sdk/typescript/interface/test_interface_dependencies.py +++ b/tests/unit/codegen/sdk/typescript/interface/test_interface_dependencies.py @@ -15,8 +15,8 @@ def test_interface_dependencies_includes_extends(tmpdir) -> None: wagTail(): void; } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") symbols = file.symbols assert len(symbols) == 2 assert symbols[0].name == "Animal" @@ -59,8 +59,8 @@ def test_interface_dependencies_includes_implements(tmpdir) -> None: } } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") symbols = file.symbols assert len(symbols) == 3 assert symbols[0].name == "Animal" diff --git a/tests/unit/codegen/sdk/typescript/interface/test_interface_get_attribute.py b/tests/unit/codegen/sdk/typescript/interface/test_interface_get_attribute.py index 522ec4630..53edf1696 100644 --- a/tests/unit/codegen/sdk/typescript/interface/test_interface_get_attribute.py +++ b/tests/unit/codegen/sdk/typescript/interface/test_interface_get_attribute.py @@ -9,8 +9,8 @@ def test_interface_get_attribute_finds_match(tmpdir) -> None: age: number; } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") animal = file.get_symbol("Animal") name_attr = animal.get_attribute("name") assert name_attr diff --git a/tests/unit/codegen/sdk/typescript/interface/test_interface_parents.py b/tests/unit/codegen/sdk/typescript/interface/test_interface_parents.py index 0fa85d31f..9ce406b15 100644 --- a/tests/unit/codegen/sdk/typescript/interface/test_interface_parents.py +++ b/tests/unit/codegen/sdk/typescript/interface/test_interface_parents.py @@ -35,8 +35,8 @@ def test_interfaces_inheritance(tmpdir) -> None: } } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": file}) as ctx: + file = ctx.get_file("test.ts") symbols = file.symbols assert len(symbols) == 3 assert symbols[0].parent_interfaces is None diff --git a/tests/unit/codegen/sdk/typescript/statements/assignment_statement/test_assignment_statement_get_variable_usages.py b/tests/unit/codegen/sdk/typescript/statements/assignment_statement/test_assignment_statement_get_variable_usages.py index 73f9f7551..2f64cb526 100644 --- a/tests/unit/codegen/sdk/typescript/statements/assignment_statement/test_assignment_statement_get_variable_usages.py +++ b/tests/unit/codegen/sdk/typescript/statements/assignment_statement/test_assignment_statement_get_variable_usages.py @@ -40,7 +40,7 @@ class MyClass { assert len(obj_usages) == 1 assert obj_usages[0].source == "obj" obj_usages[0].edit("renamed_obj") - codebase.G.commit_transactions() + codebase.ctx.commit_transactions() assert "renamed_obj.attr1 = renamed_attribute.obj" in file.content diff --git a/tests/unit/codegen/sdk/typescript/statements/attribute/test_attribute_properties.py b/tests/unit/codegen/sdk/typescript/statements/attribute/test_attribute_properties.py index 8a4497fab..008cf08f2 100644 --- a/tests/unit/codegen/sdk/typescript/statements/attribute/test_attribute_properties.py +++ b/tests/unit/codegen/sdk/typescript/statements/attribute/test_attribute_properties.py @@ -95,7 +95,7 @@ class MyClass { assert isinstance(b, TSAttribute) assert isinstance(b, TSAssignmentStatement) assert b.file_node_id == cls.file_node_id - assert b.G == cls.G + assert b.ctx == cls.ctx def test_attribute_from_parent_symbol(tmpdir) -> None: @@ -116,7 +116,7 @@ def test_attribute_from_parent_symbol(tmpdir) -> None: assert isinstance(b, TSAttribute) assert isinstance(b, TSAssignmentStatement) assert b.file_node_id == type.file_node_id - assert b.G == type.G + assert b.ctx == type.ctx def test_ts_attributes_within_function(tmpdir) -> None: diff --git a/tests/unit/codegen/sdk/typescript/tsx/test_tsx_edit.py b/tests/unit/codegen/sdk/typescript/tsx/test_tsx_edit.py index c67cd486c..3ae453ced 100644 --- a/tests/unit/codegen/sdk/typescript/tsx/test_tsx_edit.py +++ b/tests/unit/codegen/sdk/typescript/tsx/test_tsx_edit.py @@ -20,8 +20,8 @@ def test_tsx_component_edit(tmpdir) -> None: ); } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as G: - file = G.get_file("test.tsx") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as ctx: + file = ctx.get_file("test.tsx") greeting = file.get_symbol("FooBar") # Edit the component @@ -29,7 +29,7 @@ def test_tsx_component_edit(tmpdir) -> None: p.insert_before("

My new paragraph

") p.insert_after("

My new paragraph

") p.edit("

My new paragraph

") - G.commit_transactions() + ctx.commit_transactions() # Assert the changes assert "

Hello, {name}!

" in file.source @@ -57,8 +57,8 @@ def test_tsx_component_set_name(tmpdir) -> None: ); } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as G: - file = G.get_file("test.tsx") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as ctx: + file = ctx.get_file("test.tsx") greeting = file.get_symbol("FooBar") # Edit the component @@ -68,7 +68,7 @@ def test_tsx_component_set_name(tmpdir) -> None: p.set_name("h2") img = greeting.get_component("img") img.set_name("a") - G.commit_transactions() + ctx.commit_transactions() # Assert the changes assert "" in file.source @@ -100,8 +100,8 @@ def test_tsx_expression_edit(tmpdir) -> None: ); } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as G: - file = G.get_file("test.tsx") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as ctx: + file = ctx.get_file("test.tsx") greeting = file.get_symbol("FooBar") # Edit the component @@ -114,7 +114,7 @@ def test_tsx_expression_edit(tmpdir) -> None: p = greeting.get_component("p") expression = p.expressions[0] expression.statement.edit("1 + name + 2") - G.commit_transactions() + ctx.commit_transactions() # Assert the changes assert "

Goodbye, {1 + name + 2}!

" in file.source @@ -141,14 +141,14 @@ def test_tsx_param_edit(tmpdir) -> None: ); } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as G: - file = G.get_file("test.tsx") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as ctx: + file = ctx.get_file("test.tsx") greeting = file.get_symbol("FooBar") # Edit the param name = greeting.get_parameter("name") name.rename("newName") - G.commit_transactions() + ctx.commit_transactions() # Assert the changes assert "newName" in file.source @@ -176,8 +176,8 @@ def test_tsx_prop_edit(tmpdir) -> None: ); } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as G: - file = G.get_file("test.tsx") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as ctx: + file = ctx.get_file("test.tsx") greeting = file.get_symbol("FooBar") # Edit the prop @@ -188,7 +188,7 @@ def test_tsx_prop_edit(tmpdir) -> None: prop2 = h1.props[1] prop2.set_name("test2") prop2.set_value("{doAnotherThing()}") - G.commit_transactions() + ctx.commit_transactions() # Assert the changes assert '

Hello, {name}!

' in file.source @@ -211,8 +211,8 @@ def test_tsx_prop_add(tmpdir) -> None: ); } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as G: - file = G.get_file("test.tsx") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as ctx: + file = ctx.get_file("test.tsx") greeting = file.get_symbol("FooBar") # Edit the prop @@ -222,7 +222,7 @@ def test_tsx_prop_add(tmpdir) -> None: prop2 = h1.props[1] prop2.insert_after("test2={doAnotherThing()}", newline=False) h1.add_prop("key3", "{123}") - G.commit_transactions() + ctx.commit_transactions() # Assert the changes assert '

Hello, {name}!

' in file.source @@ -245,15 +245,15 @@ def test_tsx_prop_add_empty(tmpdir) -> None: ); } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as G: - file = G.get_file("test.tsx") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as ctx: + file = ctx.get_file("test.tsx") greeting = file.get_symbol("FooBar") # Edit the prop h1 = greeting.get_component("h1") h1.add_prop("key", '"value"') h1.add_prop("test", "{doAThing()}") - G.commit_transactions() + ctx.commit_transactions() # Assert the changes assert '

Hello, {name}!

' in file.source @@ -276,8 +276,8 @@ def test_tsx_prop_remove(tmpdir) -> None: ); } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as G: - file = G.get_file("test.tsx") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as ctx: + file = ctx.get_file("test.tsx") greeting = file.get_symbol("FooBar") # Edit the prop @@ -286,7 +286,7 @@ def test_tsx_prop_remove(tmpdir) -> None: prop1.remove() prop2 = h1.props[1] prop2.remove() - G.commit_transactions() + ctx.commit_transactions() # Assert the changes assert "

Hello, {name}!

" in file.source @@ -324,13 +324,13 @@ def test_tsx_move_component(tmpdir) -> None: """ new_file_name = "new.tsx" new_file_content = "" - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={original_file_name: original_file_content, new_file_name: new_file_content}) as G: - original_file = G.get_file(original_file_name) + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={original_file_name: original_file_content, new_file_name: new_file_content}) as ctx: + original_file = ctx.get_file(original_file_name) foo_bar = original_file.get_symbol("FooBar") - new_file = G.get_file(new_file_name) + new_file = ctx.get_file(new_file_name) foo_bar.move_to_file(new_file) - G.commit_transactions() + ctx.commit_transactions() assert "export function FooBar" in new_file.content assert "export function MyFooBar" in new_file.content @@ -351,17 +351,17 @@ def test_tsx_wrap(tmpdir) -> None: ); } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as G: - file = G.get_file("test.tsx") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as ctx: + file = ctx.get_file("test.tsx") foo_bar = file.get_symbol("FooBar") # Wrap the div element div = foo_bar.get_component("div") div.wrap('
', "
") - G.commit_transactions() + ctx.commit_transactions() # Assert the changes - new_file = G.get_file("test.tsx") + new_file = ctx.get_file("test.tsx") expected_result = """
diff --git a/tests/unit/codegen/sdk/typescript/tsx/test_tsx_parsing.py b/tests/unit/codegen/sdk/typescript/tsx/test_tsx_parsing.py index 3bebf02f5..0387e5885 100644 --- a/tests/unit/codegen/sdk/typescript/tsx/test_tsx_parsing.py +++ b/tests/unit/codegen/sdk/typescript/tsx/test_tsx_parsing.py @@ -23,8 +23,8 @@ def test_basic_component_parsing(tmpdir) -> None: export default TestComponent; """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as G: - file = G.get_file("test.tsx") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as ctx: + file = ctx.get_file("test.tsx") component = file.get_symbol("TestComponent") assert len(component.parameters) == 1 @@ -57,8 +57,8 @@ def test_component_with_props_destructuring(tmpdir) -> None: ) } """ - with get_codebase_graph_session(tmpdir=tmpdir, files={"test.tsx": content}, programming_language=ProgrammingLanguage.TYPESCRIPT) as G: - file = G.get_file("test.tsx") + with get_codebase_graph_session(tmpdir=tmpdir, files={"test.tsx": content}, programming_language=ProgrammingLanguage.TYPESCRIPT) as ctx: + file = ctx.get_file("test.tsx") component = file.get_function("TestComponent") assert component.is_jsx @@ -90,10 +90,10 @@ def test_tsx_file_type_validation(tmpdir) -> None: } """ files = {ts_file_name: "", tsx_file_name: "", origin_file_name: origin_file_content} - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files=files) as G: - ts_file = G.get_file(ts_file_name) - tsx_file = G.get_file(tsx_file_name) - origin_file = G.get_file(origin_file_name) + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files=files) as ctx: + ts_file = ctx.get_file(ts_file_name) + tsx_file = ctx.get_file(tsx_file_name) + origin_file = ctx.get_file(origin_file_name) test_component = origin_file.get_symbol("TestComponent") @@ -128,8 +128,8 @@ def test_jsx_element_attributes(tmpdir) -> None: } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as G: - file = G.get_file("test.tsx") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as ctx: + file = ctx.get_file("test.tsx") assert len(file.jsx_elements) == 3 component = file.get_symbol("TestComponent") @@ -187,8 +187,8 @@ def test_complex_jsx_expressions(tmpdir) -> None: export default TestComponent; """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as G: - file = G.get_file("test.tsx") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as ctx: + file = ctx.get_file("test.tsx") component = file.get_symbol("TestComponent") assert len(component.jsx_elements) == 7 @@ -243,8 +243,8 @@ def test_nested_jsx_element_parsing(tmpdir) -> None: ); } """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as G: - file = G.get_file("test.tsx") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.tsx": file}) as ctx: + file = ctx.get_file("test.tsx") component = file.get_symbol("TestComponent") assert len(component.jsx_elements) == 3 diff --git a/tests/unit/codegen/sdk/typescript/type/test_type_dependencies.py b/tests/unit/codegen/sdk/typescript/type/test_type_dependencies.py index 2c826650b..434668805 100644 --- a/tests/unit/codegen/sdk/typescript/type/test_type_dependencies.py +++ b/tests/unit/codegen/sdk/typescript/type/test_type_dependencies.py @@ -33,8 +33,8 @@ def test_type_dependencies(tmpdir) -> None: export const animalTypes = ["dog", "cat"] as const; export type AnimalType = typeof animalTypes[number]; """ - with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as G: - file = G.get_file("test.ts") + with get_codebase_graph_session(tmpdir=tmpdir, programming_language=ProgrammingLanguage.TYPESCRIPT, files={"test.ts": content}) as ctx: + file = ctx.get_file("test.ts") # Test basic type dependencies pet_type = file.get_symbol("Pet") diff --git a/tests/unit/skills/implementations/guides/code-quality-metrics/import-loops.py b/tests/unit/skills/implementations/guides/code-quality-metrics/import-loops.py index ce61479ec..517909a0f 100644 --- a/tests/unit/skills/implementations/guides/code-quality-metrics/import-loops.py +++ b/tests/unit/skills/implementations/guides/code-quality-metrics/import-loops.py @@ -88,17 +88,17 @@ class ImportCycleDetectionAndVisualization(Skill, ABC): @staticmethod @skill_impl(test_cases=[ImportCycleDetectionAndVisualizationTest], language=ProgrammingLanguage.PYTHON) def skill_func(codebase: CodebaseType): - G: DiGraph = networkx.DiGraph() + ctx: DiGraph = networkx.DiGraph() # iterate over all imports for pyimport in codebase.imports: # Extract to/from files if pyimport.from_file and pyimport.to_file: # Add nodes and edges to the graph - G.add_edge(pyimport.from_file.file_path, pyimport.to_file.file_path) + ctx.add_edge(pyimport.from_file.file_path, pyimport.to_file.file_path) # Find strongly connected components - strongly_connected_components = list(networkx.strongly_connected_components(G)) + strongly_connected_components = list(networkx.strongly_connected_components(ctx)) # Count the number of cycles (SCCs with more than one node) import_cycles = [scc for scc in strongly_connected_components if len(scc) > 1] @@ -110,7 +110,7 @@ def skill_func(codebase: CodebaseType): cycle_graph: DiGraph = networkx.DiGraph() # Add nodes involved in cycles to the new graph - for cycle in networkx.simple_cycles(G): + for cycle in networkx.simple_cycles(ctx): if len(cycle) > 2: # Add nodes to the cycle graph for node in cycle: diff --git a/uv.lock b/uv.lock index bc93ebae8..d33abcc9b 100644 --- a/uv.lock +++ b/uv.lock @@ -629,6 +629,7 @@ dev = [ { name = "jsbeautifier" }, { name = "jupyterlab" }, { name = "loguru" }, + { name = "modal" }, { name = "mypy", extra = ["faster-cache", "mypyc"] }, { name = "pre-commit" }, { name = "pre-commit-uv" }, @@ -672,7 +673,7 @@ requires-dist = [ { name = "numpy", specifier = ">=2.2.2" }, { name = "openai", specifier = "==1.61.1" }, { name = "pip", specifier = ">=24.3.1" }, - { name = "plotly", specifier = ">=5.24.0,<6.0.0" }, + { name = "plotly", specifier = ">=5.24.0,<7.0.0" }, { name = "psutil", specifier = ">=5.8.0" }, { name = "pydantic", specifier = ">=2.9.2,<3.0.0" }, { name = "pydantic-core", specifier = ">=2.23.4" }, @@ -734,6 +735,7 @@ dev = [ { name = "jsbeautifier", specifier = ">=1.15.1,<2.0.0" }, { name = "jupyterlab", specifier = ">=4.3.5" }, { name = "loguru", specifier = ">=0.7.3" }, + { name = "modal", specifier = ">=0.73.25" }, { name = "mypy", extras = ["mypyc", "faster-cache"], specifier = ">=1.13.0" }, { name = "pre-commit", specifier = ">=4.0.1" }, { name = "pre-commit-uv", specifier = ">=4.1.4" }, @@ -1296,6 +1298,16 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/ac/38/08cc303ddddc4b3d7c628c3039a61a3aae36c241ed01393d00c2fd663473/greenlet-3.1.1-cp313-cp313t-musllinux_1_1_x86_64.whl", hash = "sha256:411f015496fec93c1c8cd4e5238da364e1da7a124bcb293f085bf2860c32c6f6", size = 1142112 }, ] +[[package]] +name = "grpclib" +version = "0.4.7" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "h2" }, + { name = "multidict" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/79/b9/55936e462a5925190d7427e880b3033601d1effd13809b483d13a926061a/grpclib-0.4.7.tar.gz", hash = "sha256:2988ef57c02b22b7a2e8e961792c41ccf97efc2ace91ae7a5b0de03c363823c3", size = 61254 } + [[package]] name = "h11" version = "0.14.0" @@ -1305,6 +1317,19 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/95/04/ff642e65ad6b90db43e668d70ffb6736436c7ce41fcc549f4e9472234127/h11-0.14.0-py3-none-any.whl", hash = "sha256:e3fe4ac4b851c468cc8363d500db52c2ead036020723024a109d37346efaa761", size = 58259 }, ] +[[package]] +name = "h2" +version = "4.2.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "hpack" }, + { name = "hyperframe" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/1b/38/d7f80fd13e6582fb8e0df8c9a653dcc02b03ca34f4d72f34869298c5baf8/h2-4.2.0.tar.gz", hash = "sha256:c8a52129695e88b1a0578d8d2cc6842bbd79128ac685463b887ee278126ad01f", size = 2150682 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/d0/9e/984486f2d0a0bd2b024bf4bc1c62688fcafa9e61991f041fb0e2def4a982/h2-4.2.0-py3-none-any.whl", hash = "sha256:479a53ad425bb29af087f3458a61d30780bc818e4ebcf01f0b536ba916462ed0", size = 60957 }, +] + [[package]] name = "hatch-vcs" version = "0.4.0" @@ -1333,6 +1358,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/08/e7/ae38d7a6dfba0533684e0b2136817d667588ae3ec984c1a4e5df5eb88482/hatchling-1.27.0-py3-none-any.whl", hash = "sha256:d3a2f3567c4f926ea39849cdf924c7e99e6686c9c8e288ae1037c8fa2a5d937b", size = 75794 }, ] +[[package]] +name = "hpack" +version = "4.1.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/2c/48/71de9ed269fdae9c8057e5a4c0aa7402e8bb16f2c6e90b3aa53327b113f8/hpack-4.1.0.tar.gz", hash = "sha256:ec5eca154f7056aa06f196a557655c5b009b382873ac8d1e66e79e87535f1dca", size = 51276 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/07/c6/80c95b1b2b94682a72cbdbfb85b81ae2daffa4291fbfa1b1464502ede10d/hpack-4.1.0-py3-none-any.whl", hash = "sha256:157ac792668d995c657d93111f46b4535ed114f0c9c8d672271bbec7eae1b496", size = 34357 }, +] + [[package]] name = "httpcore" version = "1.0.7" @@ -1410,6 +1444,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/92/75/4bc3e242ad13f2e6c12e0b0401ab2c5e5c6f0d7da37ec69bc808e24e0ccb/humanize-4.11.0-py3-none-any.whl", hash = "sha256:b53caaec8532bcb2fff70c8826f904c35943f8cecaca29d272d9df38092736c0", size = 128055 }, ] +[[package]] +name = "hyperframe" +version = "6.1.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/02/e7/94f8232d4a74cc99514c13a9f995811485a6903d48e5d952771ef6322e30/hyperframe-6.1.0.tar.gz", hash = "sha256:f630908a00854a7adeabd6382b43923a4c4cd4b821fcb527e6ab9e15382a3b08", size = 26566 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/48/30/47d0bf6072f7252e6521f3447ccfa40b421b6824517f82854703d0f5a98b/hyperframe-6.1.0-py3-none-any.whl", hash = "sha256:b03380493a519fce58ea5af42e4a42317bf9bd425596f7a0835ffce80f1a42e5", size = 13007 }, +] + [[package]] name = "identify" version = "2.6.7" @@ -2114,6 +2157,30 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/c6/02/c66bdfdadbb021adb642ca4e8a5ed32ada0b4a3e4b39c5d076d19543452f/mistune-3.1.1-py3-none-any.whl", hash = "sha256:02106ac2aa4f66e769debbfa028509a275069dcffce0dfa578edd7b991ee700a", size = 53696 }, ] +[[package]] +name = "modal" +version = "0.73.31" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "aiohttp" }, + { name = "certifi" }, + { name = "click" }, + { name = "fastapi" }, + { name = "grpclib" }, + { name = "protobuf" }, + { name = "rich" }, + { name = "synchronicity" }, + { name = "toml" }, + { name = "typer" }, + { name = "types-certifi" }, + { name = "types-toml" }, + { name = "typing-extensions" }, + { name = "watchfiles" }, +] +wheels = [ + { url = "https://files.pythonhosted.org/packages/cf/54/4102a1dbea8da32537606c2e084001eee30e0c2ad1dc336bdb48310d8500/modal-0.73.31-py3-none-any.whl", hash = "sha256:03d7dce03729976d6d3ef80cd79be90ffb74e28bbfbb20a60878e61e820e92e6", size = 533251 }, +] + [[package]] name = "multidict" version = "6.1.0" @@ -3563,6 +3630,18 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/e0/f9/0595336914c5619e5f28a1fb793285925a8cd4b432c9da0a987836c7f822/shellingham-1.5.4-py2.py3-none-any.whl", hash = "sha256:7ecfff8f2fd72616f7481040475a65b2bf8af90a56c89140852d1120324e8686", size = 9755 }, ] +[[package]] +name = "sigtools" +version = "4.0.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "attrs" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/5f/db/669ca14166814da187b3087b908ca924cf83f5b504fe23b3859a3ef67d4f/sigtools-4.0.1.tar.gz", hash = "sha256:4b8e135a9cd4d2ea00da670c093372d74e672ba3abb87f4c98d8e73dea54445c", size = 71910 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/1f/91/853dbf6ec096197dba9cd5fd0c836c5fc19142038b7db60ebe6332b1bab1/sigtools-4.0.1-py2.py3-none-any.whl", hash = "sha256:d216b4cf920bbab0fce636ddc429ed8463a5b533d9e1492acb45a2a1bc36ac6c", size = 76419 }, +] + [[package]] name = "six" version = "1.17.0" @@ -3677,6 +3756,19 @@ pytest = [ { name = "pytest" }, ] +[[package]] +name = "synchronicity" +version = "0.9.11" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "sigtools" }, + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/b5/52/f34a9ab6d514e0808d0f572affb360411d596b3439107318c00889277dd6/synchronicity-0.9.11.tar.gz", hash = "sha256:cb5dbbcb43d637e516ae50db05a776da51a705d1e1a9c0e301f6049afc3c2cae", size = 50323 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/f2/d5/7675cd9b8e18f05b9ea261acad5d197fcb8027d2a65b1a750427ec084593/synchronicity-0.9.11-py3-none-any.whl", hash = "sha256:231129654d2f56b1aa148e85ebd8545231be135771f6d2196d414175b1594ef6", size = 36827 }, +] + [[package]] name = "tabulate" version = "0.9.0" @@ -3936,6 +4028,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/d0/cc/0a838ba5ca64dc832aa43f727bd586309846b0ffb2ce52422543e6075e8a/typer-0.15.1-py3-none-any.whl", hash = "sha256:7994fb7b8155b64d3402518560648446072864beefd44aa2dc36972a5972e847", size = 44908 }, ] +[[package]] +name = "types-certifi" +version = "2021.10.8.3" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/52/68/943c3aeaf14624712a0357c4a67814dba5cea36d194f5c764dad7959a00c/types-certifi-2021.10.8.3.tar.gz", hash = "sha256:72cf7798d165bc0b76e1c10dd1ea3097c7063c42c21d664523b928e88b554a4f", size = 2095 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/b5/63/2463d89481e811f007b0e1cd0a91e52e141b47f9de724d20db7b861dcfec/types_certifi-2021.10.8.3-py3-none-any.whl", hash = "sha256:b2d1e325e69f71f7c78e5943d410e650b4707bb0ef32e4ddf3da37f54176e88a", size = 2136 }, +] + [[package]] name = "types-networkx" version = "3.4.2.20241227"