From 1f6c180a534a1ec5c1a310fbe091aeb9a91be3e9 Mon Sep 17 00:00:00 2001 From: jayhack Date: Sun, 10 Aug 2025 20:08:26 -0700 Subject: [PATCH] removed deprecated dics --- .../api-reference/core/Argument.mdx | 513 ------- .../api-reference/core/Assignment.mdx | 716 ---------- .../core/AssignmentStatement.mdx | 458 ------- .../api-reference/core/Attribute.mdx | 583 -------- .../api-reference/core/AwaitExpression.mdx | 442 ------ .../api-reference/core/BinaryExpression.mdx | 438 ------ .../api-reference/core/BlockStatement.mdx | 481 ------- .../api-reference/core/Boolean.mdx | 413 ------ .../api-reference/core/Callable.mdx | 589 -------- .../api-reference/core/CatchStatement.mdx | 485 ------- .../api-reference/core/ChainedAttribute.mdx | 429 ------ docs/_deprecated/api-reference/core/Class.mdx | 1022 -------------- .../api-reference/core/CodeBlock.mdx | 612 --------- .../api-reference/core/CodeOwner.mdx | 153 --- .../api-reference/core/Codebase.mdx | 702 ---------- .../api-reference/core/Comment.mdx | 446 ------ .../api-reference/core/CommentGroup.mdx | 436 ------ .../core/ComparisonExpression.mdx | 438 ------ .../api-reference/core/Decorator.mdx | 467 ------- docs/_deprecated/api-reference/core/Dict.mdx | 417 ------ .../api-reference/core/Directory.mdx | 198 --- .../api-reference/core/Editable.mdx | 407 ------ .../_deprecated/api-reference/core/Export.mdx | 613 --------- .../api-reference/core/ExportStatement.mdx | 433 ------ .../api-reference/core/Exportable.mdx | 577 -------- .../api-reference/core/Expression.mdx | 413 ------ .../api-reference/core/ExpressionGroup.mdx | 419 ------ .../core/ExpressionStatement.mdx | 454 ------- .../api-reference/core/ExternalModule.mdx | 641 --------- docs/_deprecated/api-reference/core/File.mdx | 475 ------- .../api-reference/core/FlagKwargs.mdx | 32 - .../api-reference/core/ForLoopStatement.mdx | 489 ------- .../api-reference/core/Function.mdx | 923 ------------- .../api-reference/core/FunctionCall.mdx | 620 --------- .../api-reference/core/GenericType.mdx | 467 ------- .../api-reference/core/HasBlock.mdx | 469 ------- .../api-reference/core/HasName.mdx | 72 - .../api-reference/core/HasValue.mdx | 43 - .../api-reference/core/IfBlockStatement.mdx | 470 ------- .../_deprecated/api-reference/core/Import.mdx | 656 --------- .../api-reference/core/ImportStatement.mdx | 429 ------ .../api-reference/core/ImportType.mdx | 44 - .../api-reference/core/Importable.mdx | 486 ------- .../api-reference/core/Interface.mdx | 737 ---------- docs/_deprecated/api-reference/core/List.mdx | 394 ------ .../api-reference/core/MessageType.mdx | 32 - .../api-reference/core/MultiExpression.mdx | 417 ------ .../core/MultiLineCollection.mdx | 392 ------ docs/_deprecated/api-reference/core/Name.mdx | 413 ------ .../api-reference/core/NamedType.mdx | 463 ------- .../api-reference/core/NoneType.mdx | 413 ------ .../_deprecated/api-reference/core/Number.mdx | 413 ------ docs/_deprecated/api-reference/core/Pair.mdx | 438 ------ .../api-reference/core/Parameter.mdx | 588 -------- .../core/ParenthesizedExpression.mdx | 474 ------- .../api-reference/core/Placeholder.mdx | 63 - .../api-reference/core/PlaceholderType.mdx | 413 ------ .../api-reference/core/RaiseStatement.mdx | 446 ------ .../api-reference/core/ReturnStatement.mdx | 446 ------ .../api-reference/core/SourceFile.mdx | 873 ------------ docs/_deprecated/api-reference/core/Span.mdx | 28 - .../api-reference/core/Statement.mdx | 425 ------ .../api-reference/core/StatementType.mdx | 96 -- .../_deprecated/api-reference/core/String.mdx | 429 ------ .../api-reference/core/StubPlaceholder.mdx | 65 - .../core/SubscriptExpression.mdx | 421 ------ .../api-reference/core/SwitchCase.mdx | 485 ------- .../api-reference/core/SwitchStatement.mdx | 433 ------ .../_deprecated/api-reference/core/Symbol.mdx | 645 --------- .../api-reference/core/SymbolGroup.mdx | 415 ------ .../api-reference/core/SymbolStatement.mdx | 429 ------ .../api-reference/core/TernaryExpression.mdx | 440 ------ .../api-reference/core/TryCatchStatement.mdx | 485 ------- docs/_deprecated/api-reference/core/Tuple.mdx | 394 ------ .../api-reference/core/TupleType.mdx | 396 ------ docs/_deprecated/api-reference/core/Type.mdx | 413 ------ .../api-reference/core/TypeAlias.mdx | 738 ---------- .../api-reference/core/TypePlaceholder.mdx | 65 - .../api-reference/core/Typeable.mdx | 417 ------ .../api-reference/core/UnaryExpression.mdx | 426 ------ .../api-reference/core/UnionType.mdx | 396 ------ .../_deprecated/api-reference/core/Unpack.mdx | 459 ------- .../api-reference/core/Unwrappable.mdx | 421 ------ .../_deprecated/api-reference/core/Usable.mdx | 526 -------- docs/_deprecated/api-reference/core/Usage.mdx | 40 - .../api-reference/core/UsageKind.mdx | 72 - .../api-reference/core/UsageType.mdx | 36 - docs/_deprecated/api-reference/core/Value.mdx | 413 ------ .../api-reference/core/WhileStatement.mdx | 485 ------- .../api-reference/core/WithStatement.mdx | 503 ------- docs/_deprecated/api-reference/index.mdx | 81 -- .../api-reference/python/PyAssignment.mdx | 838 ------------ .../python/PyAssignmentStatement.mdx | 511 ------- .../api-reference/python/PyAttribute.mdx | 644 --------- .../api-reference/python/PyBlockStatement.mdx | 499 ------- .../api-reference/python/PyBreakStatement.mdx | 425 ------ .../api-reference/python/PyCatchStatement.mdx | 503 ------- .../python/PyChainedAttribute.mdx | 429 ------ .../api-reference/python/PyClass.mdx | 1127 ---------------- .../api-reference/python/PyCodeBlock.mdx | 633 --------- .../api-reference/python/PyComment.mdx | 506 ------- .../api-reference/python/PyCommentGroup.mdx | 453 ------- .../api-reference/python/PyCommentType.mdx | 36 - .../python/PyConditionalExpression.mdx | 440 ------ .../api-reference/python/PyDecorator.mdx | 467 ------- .../api-reference/python/PyFile.mdx | 947 ------------- .../python/PyForLoopStatement.mdx | 507 ------- .../api-reference/python/PyFunction.mdx | 1040 -------------- .../api-reference/python/PyGenericType.mdx | 467 ------- .../api-reference/python/PyHasBlock.mdx | 487 ------- .../python/PyIfBlockStatement.mdx | 470 ------- .../api-reference/python/PyImport.mdx | 691 ---------- .../python/PyImportStatement.mdx | 429 ------ .../api-reference/python/PyMatchCase.mdx | 503 ------- .../api-reference/python/PyMatchStatement.mdx | 433 ------ .../api-reference/python/PyNamedType.mdx | 463 ------- .../api-reference/python/PyParameter.mdx | 611 --------- .../api-reference/python/PyPassStatement.mdx | 425 ------ .../python/PyReturnTypePlaceholder.mdx | 65 - .../api-reference/python/PyString.mdx | 429 ------ .../api-reference/python/PySymbol.mdx | 732 ---------- .../python/PyTryCatchStatement.mdx | 507 ------- .../api-reference/python/PyUnionType.mdx | 396 ------ .../api-reference/python/PyWhileStatement.mdx | 507 ------- .../api-reference/typescript/JSXElement.mdx | 542 -------- .../typescript/JSXExpression.mdx | 434 ------ .../api-reference/typescript/JSXProp.mdx | 488 ------- .../api-reference/typescript/TSArrayType.mdx | 463 ------- .../api-reference/typescript/TSAssignment.mdx | 858 ------------ .../typescript/TSAssignmentStatement.mdx | 458 ------- .../api-reference/typescript/TSAttribute.mdx | 600 --------- .../typescript/TSBlockStatement.mdx | 526 -------- .../typescript/TSCatchStatement.mdx | 530 -------- .../typescript/TSChainedAttribute.mdx | 429 ------ .../api-reference/typescript/TSClass.mdx | 1200 ----------------- .../api-reference/typescript/TSCodeBlock.mdx | 612 --------- .../api-reference/typescript/TSComment.mdx | 502 ------- .../typescript/TSCommentGroup.mdx | 436 ------ .../typescript/TSCommentType.mdx | 32 - .../typescript/TSConditionalType.mdx | 429 ------ .../api-reference/typescript/TSConfig.mdx | 112 -- .../api-reference/typescript/TSDecorator.mdx | 467 ------- .../api-reference/typescript/TSDict.mdx | 417 ------ .../api-reference/typescript/TSEnum.mdx | 884 ------------ .../api-reference/typescript/TSExport.mdx | 728 ---------- .../typescript/TSExpressionType.mdx | 467 ------- .../api-reference/typescript/TSFile.mdx | 1152 ---------------- .../typescript/TSForLoopStatement.mdx | 550 -------- .../api-reference/typescript/TSFunction.mdx | 1143 ---------------- .../typescript/TSFunctionType.mdx | 433 ------ .../typescript/TSGenericType.mdx | 467 ------- .../api-reference/typescript/TSHasBlock.mdx | 514 ------- .../typescript/TSIfBlockStatement.mdx | 470 ------- .../api-reference/typescript/TSImport.mdx | 766 ----------- .../typescript/TSImportStatement.mdx | 429 ------ .../api-reference/typescript/TSInterface.mdx | 895 ------------ .../typescript/TSLabeledStatement.mdx | 483 ------- .../api-reference/typescript/TSLookupType.mdx | 425 ------ .../api-reference/typescript/TSNamedType.mdx | 463 ------- .../api-reference/typescript/TSNamespace.mdx | 990 -------------- .../api-reference/typescript/TSObjectType.mdx | 417 ------ .../api-reference/typescript/TSPair.mdx | 442 ------ .../api-reference/typescript/TSParameter.mdx | 600 --------- .../api-reference/typescript/TSQueryType.mdx | 421 ------ .../typescript/TSReadonlyType.mdx | 421 ------ .../typescript/TSReturnTypePlaceholder.mdx | 65 - .../api-reference/typescript/TSString.mdx | 429 ------ .../api-reference/typescript/TSSwitchCase.mdx | 534 -------- .../typescript/TSSwitchStatement.mdx | 433 ------ .../api-reference/typescript/TSSymbol.mdx | 758 ----------- .../typescript/TSTernaryExpression.mdx | 440 ------ .../typescript/TSTryCatchStatement.mdx | 534 -------- .../api-reference/typescript/TSTypeAlias.mdx | 905 ------------- .../typescript/TSUndefinedType.mdx | 413 ------ .../api-reference/typescript/TSUnionType.mdx | 396 ------ .../typescript/TSWhileStatement.mdx | 530 -------- .../building-with-codegen/at-a-glance.mdx | 148 -- .../calling-out-to-llms.mdx | 233 ---- .../building-with-codegen/class-api.mdx | 175 --- .../codebase-visualization.mdx | 275 ---- .../codegen-with-wsl.mdx | 76 -- .../building-with-codegen/collections.mdx | 100 -- .../comments-and-docstrings.mdx | 214 --- .../commit-and-reset.mdx | 63 - .../dependencies-and-usages.mdx | 260 ---- .../building-with-codegen/dot-codegen.mdx | 129 -- .../editables-and-behaviors.mdx | 112 -- .../building-with-codegen/exports.mdx | 209 --- .../external-modules.mdx | 119 -- .../files-and-directories.mdx | 312 ----- .../flagging-symbols.mdx | 67 - .../function-calls-and-callsites.mdx | 243 ---- .../function-decorator.mdx | 52 - .../building-with-codegen/git-operations.mdx | 72 - .../building-with-codegen/imports.mdx | 175 --- .../inheritable-behaviors.mdx | 104 -- .../language-support.mdx | 111 -- .../building-with-codegen/local-variables.mdx | 65 - .../building-with-codegen/moving-symbols.mdx | 69 - .../parsing-codebases.mdx | 128 -- .../building-with-codegen/react-and-jsx.mdx | 140 -- .../reducing-conditions.mdx | 277 ---- .../reusable-codemods.mdx | 120 -- .../semantic-code-search.mdx | 133 -- .../statements-and-code-blocks.mdx | 335 ----- .../building-with-codegen/symbol-api.mdx | 116 -- .../the-editable-api.mdx | 170 --- .../traversing-the-call-graph.mdx | 152 --- .../type-annotations.mdx | 177 --- .../variable-assignments.mdx | 84 -- docs/_deprecated/cli/about.mdx | 61 - docs/_deprecated/cli/create.mdx | 90 -- docs/_deprecated/cli/expert.mdx | 61 - docs/_deprecated/cli/init.mdx | 114 -- docs/_deprecated/cli/login.mdx | 85 -- docs/_deprecated/cli/notebook.mdx | 74 - docs/_deprecated/cli/reset.mdx | 46 - docs/_deprecated/cli/run.mdx | 65 - docs/_deprecated/cli/update.mdx | 67 - docs/_deprecated/graph-sitter/about.mdx | 72 - .../graph-sitter/advanced-settings.mdx | 404 ------ docs/_deprecated/graph-sitter/community.mdx | 48 - docs/_deprecated/graph-sitter/faq.mdx | 58 - .../graph-sitter/getting-started.mdx | 342 ----- .../graph-sitter/guiding-principles.mdx | 75 -- .../_deprecated/graph-sitter/how-it-works.mdx | 89 -- docs/_deprecated/graph-sitter/ide-usage.mdx | 178 --- .../_deprecated/graph-sitter/installation.mdx | 125 -- docs/_deprecated/graph-sitter/overview.mdx | 159 --- .../_deprecated/graph-sitter/work-with-ai.mdx | 86 -- docs/_deprecated/tutorials/at-a-glance.mdx | 150 --- docs/_deprecated/tutorials/attributions.mdx | 191 --- docs/_deprecated/tutorials/build-mcp.mdx | 75 -- .../codebase-analytics-dashboard.mdx | 157 --- .../tutorials/codebase-visualization.mdx | 398 ------ .../tutorials/converting-default-exports.mdx | 172 --- .../tutorials/creating-documentation.mdx | 213 --- .../tutorials/deep-code-research.mdx | 215 --- .../tutorials/deleting-dead-code.mdx | 113 -- .../fixing-import-loops-in-pytorch.mdx | 276 ---- .../tutorials/flask-to-fastapi.mdx | 217 --- .../tutorials/increase-type-coverage.mdx | 122 -- .../tutorials/manage-feature-flags.mdx | 157 --- .../tutorials/managing-typescript-exports.mdx | 323 ----- docs/_deprecated/tutorials/migrating-apis.mdx | 209 --- docs/_deprecated/tutorials/modularity.mdx | 202 --- docs/_deprecated/tutorials/neo4j-graph.mdx | 93 -- .../tutorials/organize-your-codebase.mdx | 257 ---- .../preparing-your-codebase-for-ai.mdx | 179 --- .../tutorials/promise-to-async-await.mdx | 274 ---- .../tutorials/python2-to-python3.mdx | 256 ---- .../tutorials/react-modernization.mdx | 322 ----- docs/_deprecated/tutorials/slack-bot.mdx | 217 --- .../tutorials/sqlalchemy-1.6-to-2.0.mdx | 126 -- docs/_deprecated/tutorials/training-data.mdx | 202 --- .../tutorials/unittest-to-pytest.mdx | 210 --- docs/capabilities/interrupts.mdx | 16 +- docs/gen/capabilities.mdx | 102 -- docs/gen/faq.mdx | 18 - docs/gen/integrations.mdx | 49 - docs/gen/introduction.mdx | 43 - docs/graph-sitter/about.mdx | 72 - docs/graph-sitter/advanced-settings.mdx | 404 ------ docs/graph-sitter/community.mdx | 48 - docs/graph-sitter/faq.mdx | 58 - docs/graph-sitter/getting-started.mdx | 342 ----- docs/graph-sitter/guiding-principles.mdx | 75 -- docs/graph-sitter/how-it-works.mdx | 89 -- docs/graph-sitter/ide-usage.mdx | 178 --- docs/graph-sitter/installation.mdx | 125 -- docs/graph-sitter/overview.mdx | 159 --- docs/graph-sitter/work-with-ai.mdx | 86 -- docs/integrations/mcp.mdx | 7 + docs/use-cases/I. Upgrading APIs.md | 0 .../II. Improving Codebase Modularity.md | 0 .../use-cases/III. Improving Type Coverage.md | 0 .../IV. Analyzing Critical Code Paths.md | 0 277 files changed, 18 insertions(+), 99407 deletions(-) delete mode 100644 docs/_deprecated/api-reference/core/Argument.mdx delete mode 100644 docs/_deprecated/api-reference/core/Assignment.mdx delete mode 100644 docs/_deprecated/api-reference/core/AssignmentStatement.mdx delete mode 100644 docs/_deprecated/api-reference/core/Attribute.mdx delete mode 100644 docs/_deprecated/api-reference/core/AwaitExpression.mdx delete mode 100644 docs/_deprecated/api-reference/core/BinaryExpression.mdx delete mode 100644 docs/_deprecated/api-reference/core/BlockStatement.mdx delete mode 100644 docs/_deprecated/api-reference/core/Boolean.mdx delete mode 100644 docs/_deprecated/api-reference/core/Callable.mdx delete mode 100644 docs/_deprecated/api-reference/core/CatchStatement.mdx delete mode 100644 docs/_deprecated/api-reference/core/ChainedAttribute.mdx delete mode 100644 docs/_deprecated/api-reference/core/Class.mdx delete mode 100644 docs/_deprecated/api-reference/core/CodeBlock.mdx delete mode 100644 docs/_deprecated/api-reference/core/CodeOwner.mdx delete mode 100644 docs/_deprecated/api-reference/core/Codebase.mdx delete mode 100644 docs/_deprecated/api-reference/core/Comment.mdx delete mode 100644 docs/_deprecated/api-reference/core/CommentGroup.mdx delete mode 100644 docs/_deprecated/api-reference/core/ComparisonExpression.mdx delete mode 100644 docs/_deprecated/api-reference/core/Decorator.mdx delete mode 100644 docs/_deprecated/api-reference/core/Dict.mdx delete mode 100644 docs/_deprecated/api-reference/core/Directory.mdx delete mode 100644 docs/_deprecated/api-reference/core/Editable.mdx delete mode 100644 docs/_deprecated/api-reference/core/Export.mdx delete mode 100644 docs/_deprecated/api-reference/core/ExportStatement.mdx delete mode 100644 docs/_deprecated/api-reference/core/Exportable.mdx delete mode 100644 docs/_deprecated/api-reference/core/Expression.mdx delete mode 100644 docs/_deprecated/api-reference/core/ExpressionGroup.mdx delete mode 100644 docs/_deprecated/api-reference/core/ExpressionStatement.mdx delete mode 100644 docs/_deprecated/api-reference/core/ExternalModule.mdx delete mode 100644 docs/_deprecated/api-reference/core/File.mdx delete mode 100644 docs/_deprecated/api-reference/core/FlagKwargs.mdx delete mode 100644 docs/_deprecated/api-reference/core/ForLoopStatement.mdx delete mode 100644 docs/_deprecated/api-reference/core/Function.mdx delete mode 100644 docs/_deprecated/api-reference/core/FunctionCall.mdx delete mode 100644 docs/_deprecated/api-reference/core/GenericType.mdx delete mode 100644 docs/_deprecated/api-reference/core/HasBlock.mdx delete mode 100644 docs/_deprecated/api-reference/core/HasName.mdx delete mode 100644 docs/_deprecated/api-reference/core/HasValue.mdx delete mode 100644 docs/_deprecated/api-reference/core/IfBlockStatement.mdx delete mode 100644 docs/_deprecated/api-reference/core/Import.mdx delete mode 100644 docs/_deprecated/api-reference/core/ImportStatement.mdx delete mode 100644 docs/_deprecated/api-reference/core/ImportType.mdx delete mode 100644 docs/_deprecated/api-reference/core/Importable.mdx delete mode 100644 docs/_deprecated/api-reference/core/Interface.mdx delete mode 100644 docs/_deprecated/api-reference/core/List.mdx delete mode 100644 docs/_deprecated/api-reference/core/MessageType.mdx delete mode 100644 docs/_deprecated/api-reference/core/MultiExpression.mdx delete mode 100644 docs/_deprecated/api-reference/core/MultiLineCollection.mdx delete mode 100644 docs/_deprecated/api-reference/core/Name.mdx delete mode 100644 docs/_deprecated/api-reference/core/NamedType.mdx delete mode 100644 docs/_deprecated/api-reference/core/NoneType.mdx delete mode 100644 docs/_deprecated/api-reference/core/Number.mdx delete mode 100644 docs/_deprecated/api-reference/core/Pair.mdx delete mode 100644 docs/_deprecated/api-reference/core/Parameter.mdx delete mode 100644 docs/_deprecated/api-reference/core/ParenthesizedExpression.mdx delete mode 100644 docs/_deprecated/api-reference/core/Placeholder.mdx delete mode 100644 docs/_deprecated/api-reference/core/PlaceholderType.mdx delete mode 100644 docs/_deprecated/api-reference/core/RaiseStatement.mdx delete mode 100644 docs/_deprecated/api-reference/core/ReturnStatement.mdx delete mode 100644 docs/_deprecated/api-reference/core/SourceFile.mdx delete mode 100644 docs/_deprecated/api-reference/core/Span.mdx delete mode 100644 docs/_deprecated/api-reference/core/Statement.mdx delete mode 100644 docs/_deprecated/api-reference/core/StatementType.mdx delete mode 100644 docs/_deprecated/api-reference/core/String.mdx delete mode 100644 docs/_deprecated/api-reference/core/StubPlaceholder.mdx delete mode 100644 docs/_deprecated/api-reference/core/SubscriptExpression.mdx delete mode 100644 docs/_deprecated/api-reference/core/SwitchCase.mdx delete mode 100644 docs/_deprecated/api-reference/core/SwitchStatement.mdx delete mode 100644 docs/_deprecated/api-reference/core/Symbol.mdx delete mode 100644 docs/_deprecated/api-reference/core/SymbolGroup.mdx delete mode 100644 docs/_deprecated/api-reference/core/SymbolStatement.mdx delete mode 100644 docs/_deprecated/api-reference/core/TernaryExpression.mdx delete mode 100644 docs/_deprecated/api-reference/core/TryCatchStatement.mdx delete mode 100644 docs/_deprecated/api-reference/core/Tuple.mdx delete mode 100644 docs/_deprecated/api-reference/core/TupleType.mdx delete mode 100644 docs/_deprecated/api-reference/core/Type.mdx delete mode 100644 docs/_deprecated/api-reference/core/TypeAlias.mdx delete mode 100644 docs/_deprecated/api-reference/core/TypePlaceholder.mdx delete mode 100644 docs/_deprecated/api-reference/core/Typeable.mdx delete mode 100644 docs/_deprecated/api-reference/core/UnaryExpression.mdx delete mode 100644 docs/_deprecated/api-reference/core/UnionType.mdx delete mode 100644 docs/_deprecated/api-reference/core/Unpack.mdx delete mode 100644 docs/_deprecated/api-reference/core/Unwrappable.mdx delete mode 100644 docs/_deprecated/api-reference/core/Usable.mdx delete mode 100644 docs/_deprecated/api-reference/core/Usage.mdx delete mode 100644 docs/_deprecated/api-reference/core/UsageKind.mdx delete mode 100644 docs/_deprecated/api-reference/core/UsageType.mdx delete mode 100644 docs/_deprecated/api-reference/core/Value.mdx delete mode 100644 docs/_deprecated/api-reference/core/WhileStatement.mdx delete mode 100644 docs/_deprecated/api-reference/core/WithStatement.mdx delete mode 100644 docs/_deprecated/api-reference/index.mdx delete mode 100644 docs/_deprecated/api-reference/python/PyAssignment.mdx delete mode 100644 docs/_deprecated/api-reference/python/PyAssignmentStatement.mdx delete mode 100644 docs/_deprecated/api-reference/python/PyAttribute.mdx delete mode 100644 docs/_deprecated/api-reference/python/PyBlockStatement.mdx delete mode 100644 docs/_deprecated/api-reference/python/PyBreakStatement.mdx delete mode 100644 docs/_deprecated/api-reference/python/PyCatchStatement.mdx delete mode 100644 docs/_deprecated/api-reference/python/PyChainedAttribute.mdx delete mode 100644 docs/_deprecated/api-reference/python/PyClass.mdx delete mode 100644 docs/_deprecated/api-reference/python/PyCodeBlock.mdx delete mode 100644 docs/_deprecated/api-reference/python/PyComment.mdx delete mode 100644 docs/_deprecated/api-reference/python/PyCommentGroup.mdx delete mode 100644 docs/_deprecated/api-reference/python/PyCommentType.mdx delete mode 100644 docs/_deprecated/api-reference/python/PyConditionalExpression.mdx delete mode 100644 docs/_deprecated/api-reference/python/PyDecorator.mdx delete mode 100644 docs/_deprecated/api-reference/python/PyFile.mdx delete mode 100644 docs/_deprecated/api-reference/python/PyForLoopStatement.mdx delete mode 100644 docs/_deprecated/api-reference/python/PyFunction.mdx delete mode 100644 docs/_deprecated/api-reference/python/PyGenericType.mdx delete mode 100644 docs/_deprecated/api-reference/python/PyHasBlock.mdx delete mode 100644 docs/_deprecated/api-reference/python/PyIfBlockStatement.mdx delete mode 100644 docs/_deprecated/api-reference/python/PyImport.mdx delete mode 100644 docs/_deprecated/api-reference/python/PyImportStatement.mdx delete mode 100644 docs/_deprecated/api-reference/python/PyMatchCase.mdx delete mode 100644 docs/_deprecated/api-reference/python/PyMatchStatement.mdx delete mode 100644 docs/_deprecated/api-reference/python/PyNamedType.mdx delete mode 100644 docs/_deprecated/api-reference/python/PyParameter.mdx delete mode 100644 docs/_deprecated/api-reference/python/PyPassStatement.mdx delete mode 100644 docs/_deprecated/api-reference/python/PyReturnTypePlaceholder.mdx delete mode 100644 docs/_deprecated/api-reference/python/PyString.mdx delete mode 100644 docs/_deprecated/api-reference/python/PySymbol.mdx delete mode 100644 docs/_deprecated/api-reference/python/PyTryCatchStatement.mdx delete mode 100644 docs/_deprecated/api-reference/python/PyUnionType.mdx delete mode 100644 docs/_deprecated/api-reference/python/PyWhileStatement.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/JSXElement.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/JSXExpression.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/JSXProp.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSArrayType.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSAssignment.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSAssignmentStatement.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSAttribute.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSBlockStatement.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSCatchStatement.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSChainedAttribute.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSClass.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSCodeBlock.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSComment.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSCommentGroup.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSCommentType.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSConditionalType.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSConfig.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSDecorator.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSDict.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSEnum.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSExport.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSExpressionType.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSFile.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSForLoopStatement.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSFunction.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSFunctionType.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSGenericType.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSHasBlock.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSIfBlockStatement.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSImport.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSImportStatement.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSInterface.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSLabeledStatement.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSLookupType.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSNamedType.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSNamespace.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSObjectType.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSPair.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSParameter.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSQueryType.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSReadonlyType.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSReturnTypePlaceholder.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSString.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSSwitchCase.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSSwitchStatement.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSSymbol.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSTernaryExpression.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSTryCatchStatement.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSTypeAlias.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSUndefinedType.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSUnionType.mdx delete mode 100644 docs/_deprecated/api-reference/typescript/TSWhileStatement.mdx delete mode 100644 docs/_deprecated/building-with-codegen/at-a-glance.mdx delete mode 100644 docs/_deprecated/building-with-codegen/calling-out-to-llms.mdx delete mode 100644 docs/_deprecated/building-with-codegen/class-api.mdx delete mode 100644 docs/_deprecated/building-with-codegen/codebase-visualization.mdx delete mode 100644 docs/_deprecated/building-with-codegen/codegen-with-wsl.mdx delete mode 100644 docs/_deprecated/building-with-codegen/collections.mdx delete mode 100644 docs/_deprecated/building-with-codegen/comments-and-docstrings.mdx delete mode 100644 docs/_deprecated/building-with-codegen/commit-and-reset.mdx delete mode 100644 docs/_deprecated/building-with-codegen/dependencies-and-usages.mdx delete mode 100644 docs/_deprecated/building-with-codegen/dot-codegen.mdx delete mode 100644 docs/_deprecated/building-with-codegen/editables-and-behaviors.mdx delete mode 100644 docs/_deprecated/building-with-codegen/exports.mdx delete mode 100644 docs/_deprecated/building-with-codegen/external-modules.mdx delete mode 100644 docs/_deprecated/building-with-codegen/files-and-directories.mdx delete mode 100644 docs/_deprecated/building-with-codegen/flagging-symbols.mdx delete mode 100644 docs/_deprecated/building-with-codegen/function-calls-and-callsites.mdx delete mode 100644 docs/_deprecated/building-with-codegen/function-decorator.mdx delete mode 100644 docs/_deprecated/building-with-codegen/git-operations.mdx delete mode 100644 docs/_deprecated/building-with-codegen/imports.mdx delete mode 100644 docs/_deprecated/building-with-codegen/inheritable-behaviors.mdx delete mode 100644 docs/_deprecated/building-with-codegen/language-support.mdx delete mode 100644 docs/_deprecated/building-with-codegen/local-variables.mdx delete mode 100644 docs/_deprecated/building-with-codegen/moving-symbols.mdx delete mode 100644 docs/_deprecated/building-with-codegen/parsing-codebases.mdx delete mode 100644 docs/_deprecated/building-with-codegen/react-and-jsx.mdx delete mode 100644 docs/_deprecated/building-with-codegen/reducing-conditions.mdx delete mode 100644 docs/_deprecated/building-with-codegen/reusable-codemods.mdx delete mode 100644 docs/_deprecated/building-with-codegen/semantic-code-search.mdx delete mode 100644 docs/_deprecated/building-with-codegen/statements-and-code-blocks.mdx delete mode 100644 docs/_deprecated/building-with-codegen/symbol-api.mdx delete mode 100644 docs/_deprecated/building-with-codegen/the-editable-api.mdx delete mode 100644 docs/_deprecated/building-with-codegen/traversing-the-call-graph.mdx delete mode 100644 docs/_deprecated/building-with-codegen/type-annotations.mdx delete mode 100644 docs/_deprecated/building-with-codegen/variable-assignments.mdx delete mode 100644 docs/_deprecated/cli/about.mdx delete mode 100644 docs/_deprecated/cli/create.mdx delete mode 100644 docs/_deprecated/cli/expert.mdx delete mode 100644 docs/_deprecated/cli/init.mdx delete mode 100644 docs/_deprecated/cli/login.mdx delete mode 100644 docs/_deprecated/cli/notebook.mdx delete mode 100644 docs/_deprecated/cli/reset.mdx delete mode 100644 docs/_deprecated/cli/run.mdx delete mode 100644 docs/_deprecated/cli/update.mdx delete mode 100644 docs/_deprecated/graph-sitter/about.mdx delete mode 100644 docs/_deprecated/graph-sitter/advanced-settings.mdx delete mode 100644 docs/_deprecated/graph-sitter/community.mdx delete mode 100644 docs/_deprecated/graph-sitter/faq.mdx delete mode 100644 docs/_deprecated/graph-sitter/getting-started.mdx delete mode 100644 docs/_deprecated/graph-sitter/guiding-principles.mdx delete mode 100644 docs/_deprecated/graph-sitter/how-it-works.mdx delete mode 100644 docs/_deprecated/graph-sitter/ide-usage.mdx delete mode 100644 docs/_deprecated/graph-sitter/installation.mdx delete mode 100644 docs/_deprecated/graph-sitter/overview.mdx delete mode 100644 docs/_deprecated/graph-sitter/work-with-ai.mdx delete mode 100644 docs/_deprecated/tutorials/at-a-glance.mdx delete mode 100644 docs/_deprecated/tutorials/attributions.mdx delete mode 100644 docs/_deprecated/tutorials/build-mcp.mdx delete mode 100644 docs/_deprecated/tutorials/codebase-analytics-dashboard.mdx delete mode 100644 docs/_deprecated/tutorials/codebase-visualization.mdx delete mode 100644 docs/_deprecated/tutorials/converting-default-exports.mdx delete mode 100644 docs/_deprecated/tutorials/creating-documentation.mdx delete mode 100644 docs/_deprecated/tutorials/deep-code-research.mdx delete mode 100644 docs/_deprecated/tutorials/deleting-dead-code.mdx delete mode 100644 docs/_deprecated/tutorials/fixing-import-loops-in-pytorch.mdx delete mode 100644 docs/_deprecated/tutorials/flask-to-fastapi.mdx delete mode 100644 docs/_deprecated/tutorials/increase-type-coverage.mdx delete mode 100644 docs/_deprecated/tutorials/manage-feature-flags.mdx delete mode 100644 docs/_deprecated/tutorials/managing-typescript-exports.mdx delete mode 100644 docs/_deprecated/tutorials/migrating-apis.mdx delete mode 100644 docs/_deprecated/tutorials/modularity.mdx delete mode 100644 docs/_deprecated/tutorials/neo4j-graph.mdx delete mode 100644 docs/_deprecated/tutorials/organize-your-codebase.mdx delete mode 100644 docs/_deprecated/tutorials/preparing-your-codebase-for-ai.mdx delete mode 100644 docs/_deprecated/tutorials/promise-to-async-await.mdx delete mode 100644 docs/_deprecated/tutorials/python2-to-python3.mdx delete mode 100644 docs/_deprecated/tutorials/react-modernization.mdx delete mode 100644 docs/_deprecated/tutorials/slack-bot.mdx delete mode 100644 docs/_deprecated/tutorials/sqlalchemy-1.6-to-2.0.mdx delete mode 100644 docs/_deprecated/tutorials/training-data.mdx delete mode 100644 docs/_deprecated/tutorials/unittest-to-pytest.mdx delete mode 100644 docs/gen/capabilities.mdx delete mode 100644 docs/gen/faq.mdx delete mode 100644 docs/gen/integrations.mdx delete mode 100644 docs/gen/introduction.mdx delete mode 100644 docs/graph-sitter/about.mdx delete mode 100644 docs/graph-sitter/advanced-settings.mdx delete mode 100644 docs/graph-sitter/community.mdx delete mode 100644 docs/graph-sitter/faq.mdx delete mode 100644 docs/graph-sitter/getting-started.mdx delete mode 100644 docs/graph-sitter/guiding-principles.mdx delete mode 100644 docs/graph-sitter/how-it-works.mdx delete mode 100644 docs/graph-sitter/ide-usage.mdx delete mode 100644 docs/graph-sitter/installation.mdx delete mode 100644 docs/graph-sitter/overview.mdx delete mode 100644 docs/graph-sitter/work-with-ai.mdx delete mode 100644 docs/use-cases/I. Upgrading APIs.md delete mode 100644 docs/use-cases/II. Improving Codebase Modularity.md delete mode 100644 docs/use-cases/III. Improving Type Coverage.md delete mode 100644 docs/use-cases/IV. Analyzing Critical Code Paths.md diff --git a/docs/_deprecated/api-reference/core/Argument.mdx b/docs/_deprecated/api-reference/core/Argument.mdx deleted file mode 100644 index 81e631e90..000000000 --- a/docs/_deprecated/api-reference/core/Argument.mdx +++ /dev/null @@ -1,513 +0,0 @@ ---- -title: "Argument" -sidebarTitle: "Argument" -icon: "" -description: "Represents an argument passed into a FunctionCall." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[HasValue](/api-reference/core/HasValue), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of function calls present in the value of this argument." /> - -### index - -int } description="Returns the zero-based index of this argument within its parent function call." /> - -### is_named - -bool } description="Determines if an argument is being passed as a named keyword argument." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### type - -str } description="Gets the `Tree-sitter` type of the argument's value node." /> - -### value - -Expression | None } description="Gets the value node of the object." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_keyword -Converts an unnamed argument to a named argument by adding a keyword. - - - -str } - description="The keyword name to be added to the argument." - defaultValue="" -/> - - - -None } description=""/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ Argument ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ Argument ] } description=""/> - - -### get_name -Returns the name node of the object. - - - -Name | ChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ Argument ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Sets the name of an object and updates all its usages. - - - -str } - description="The new name to assign to the object." - defaultValue="" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### set_value -Sets the value of the node's value Expression. - - - -str } - description="The new value to set." - defaultValue="" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/core/Assignment.mdx b/docs/_deprecated/api-reference/core/Assignment.mdx deleted file mode 100644 index a4b929ab8..000000000 --- a/docs/_deprecated/api-reference/core/Assignment.mdx +++ /dev/null @@ -1,716 +0,0 @@ ---- -title: "Assignment" -sidebarTitle: "Assignment" -icon: "" -description: "Represents an assignment for a single variable within an assignment statement. Example: ```typescript var z var z = 5 ```" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[HasValue](/api-reference/core/HasValue), [Typeable](/api-reference/core/Typeable), [Symbol](/api-reference/core/Symbol), [Usable](/api-reference/core/Usable), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName) - -## Attributes - -### comment - -CommentGroup | None } description="Returns the comment group associated with the symbol, if any." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_nodes - -list[ Editable ] } description="Returns a list of Editable nodes associated with this symbol, including extended symbols." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### index - -int } description="Returns the index of the assignment statement in its parent's code block." /> - -### inline_comment - -CommentGroup | None } description="Returns the inline comment group associated with the symbol, if any." /> - -### is_local_variable - -bool } description="Determines if an assignment represents a local variable in the current scope." /> - -### is_typed - -bool } description="Indicates if a node has an explicit type annotation." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Returns the source code of the symbol." /> - -### symbol_type - - } description="The type of symbol, set to SymbolType.GlobalVar." /> - -### type - -Type | TypePlaceholder [ Assignment ] } description="The type annotation associated with this node" /> - -### value - -Expression | None } description="Gets the value node of the object." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_comment -Adds a comment to the symbol. - - - -str } - description="The comment text to add." - defaultValue="" -/> - - - -None } description=""/> - - -### add_keyword -Insert a keyword in the appropriate place before this symbol if it doesn't already exist. - - - -str } - description="The keyword to be inserted. Must be a valid keyword in the language context." - defaultValue="" -/> - - - -None } description=""/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ Symbol , Import ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this node with new_src. - - - -str } - description="The new source code to replace the current source with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, prevents duplicate edits. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ Assignment ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ Assignment ] } description=""/> - - -### get_name -Returns the name node of the object. - - - -Name | ChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ Assignment ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before the current symbol node in the Abstract Syntax Tree. - - - -str } - description="The source code text to insert." - defaultValue="" -/> -bool } - description="Whether to adjust the indentation of new_src to match current text. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after insertion. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to remove duplicate insertions. Defaults to True." - defaultValue="True" -/> -bool } - description="Whether to insert before extended nodes like comments and decorators. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### local_usages -Retrieves all usages of the assigned variable within its code block scope. - - - -list[ Editable [ Statement ]] } description="A sorted list of statement nodes where the variable is used."/> - - -### move_to_file -Moves the given symbol to a new file and updates its imports and references. - - - -SourceFile } - description="The destination file to move the symbol to." - defaultValue="" -/> -bool } - description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." - defaultValue="True" -/> -str } - description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." - defaultValue=""update_all_imports"" -/> - - - -None } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Simplifies an assignment expression by reducing it based on a boolean condition and updating all the usages. - - - -bool } - description="The boolean value to reduce the condition to." - defaultValue="" -/> - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Renames a symbol and updates all its references in the codebase. - - - -str } - description="The new name for the symbol." - defaultValue="" -/> -int } - description="Priority of the edit operation. Defaults to 0." - defaultValue="0" -/> - - - -tuple[NodeId, NodeId] } description="A tuple containing the file node ID and the new node ID of the renamed symbol."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_comment -Sets a comment to the symbol. - - - -str } - description="The comment text to set." - defaultValue="" -/> - - - -None } description=""/> - - -### set_inline_comment -Sets an inline comment to the symbol. - - - -str } - description="The text of the inline comment to be added or updated." - defaultValue="" -/> - - - -None } description=""/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### set_type_annotation -Adds or updates a type annotation for the current assignment. - - - -str } - description="The type annotation to be added or updated." - defaultValue="" -/> - - - -None } description=""/> - - -### set_value -Sets the value of an assignment expression. - - - -str } - description="The source code string representing the new value to be assigned." - defaultValue="" -/> - - - -None } description=""/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ Import | Symbol | TSExport ] } description="A list of symbols that use or import the exportable object."/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/core/AssignmentStatement.mdx b/docs/_deprecated/api-reference/core/AssignmentStatement.mdx deleted file mode 100644 index ed3370589..000000000 --- a/docs/_deprecated/api-reference/core/AssignmentStatement.mdx +++ /dev/null @@ -1,458 +0,0 @@ ---- -title: "AssignmentStatement" -sidebarTitle: "AssignmentStatement" -icon: "" -description: "A class that represents an assignment statement in a codebase, such as `x = 1`, `a, b = 1, 2`, `const {a: b} = myFunc(),`, etc. This includes potentially multiple Assignments via `statement.assignments`, which represent each assignment of a value to a variable within this statement. For example, assigning to a destructured object, or assigning multiple values to multiple variables in a single statement." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[HasValue](/api-reference/core/HasValue), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### assignments - -list[ Assignment ] } description="A list of assignments within the statement." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### left - -Expression [ Assignment ] } description="The left-hand side expression of the first assignment." /> - -### nested_code_blocks - -list[ Editable ] } description="Returns all nested code blocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ AssignmentStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### right - -Expression [ Assignment ] | None } description="The right-hand side expression of the first assignment, or None if not applicable." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### value - -Expression | None } description="Gets the value node of the object." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ AssignmentStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ AssignmentStatement ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ AssignmentStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_value -Sets the value of the node's value Expression. - - - -str } - description="The new value to set." - defaultValue="" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/core/Attribute.mdx b/docs/_deprecated/api-reference/core/Attribute.mdx deleted file mode 100644 index e693c396f..000000000 --- a/docs/_deprecated/api-reference/core/Attribute.mdx +++ /dev/null @@ -1,583 +0,0 @@ ---- -title: "Attribute" -sidebarTitle: "Attribute" -icon: "" -description: "Abstract representation of an attribute on a class definition." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Usable](/api-reference/core/Usable), [AssignmentStatement](/api-reference/core/AssignmentStatement), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [HasValue](/api-reference/core/HasValue), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName) - -## Attributes - -### assignment - -Assignment } description="The assignment associated with the attribute." /> - -### assignments - -list[ Assignment ] } description="A list of assignments within the statement." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### is_optional - -bool } description="Returns whether the attribute is optional." /> - -### is_private - -bool } description="Indicates whether the attribute is private." /> - -### left - -Expression [ Assignment ] } description="The left-hand side expression of the first assignment." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### nested_code_blocks - -list[ Editable ] } description="Returns all nested code blocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ Attribute ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### right - -Expression [ Assignment ] | None } description="The right-hand side expression of the first assignment, or None if not applicable." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### value - -Expression | None } description="Gets the value node of the object." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ Symbol , Import ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ Attribute ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ Attribute ] } description=""/> - - -### get_name -Returns the name node of the object. - - - -Name | ChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ Attribute ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Renames a symbol and updates all its references in the codebase. - - - -str } - description="The new name for the symbol." - defaultValue="" -/> -int } - description="Priority of the edit operation. Defaults to 0." - defaultValue="0" -/> - - - -tuple[NodeId, NodeId] } description="A tuple containing the file node ID and the new node ID of the renamed symbol."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### set_value -Sets the value of a node's assignment. - - - -str } - description="The new value to set for the assignment." - defaultValue="" -/> - - - -None } description=""/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ Import | Symbol | TSExport ] } description="A list of symbols that use or import the exportable object."/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/core/AwaitExpression.mdx b/docs/_deprecated/api-reference/core/AwaitExpression.mdx deleted file mode 100644 index 53d2a133b..000000000 --- a/docs/_deprecated/api-reference/core/AwaitExpression.mdx +++ /dev/null @@ -1,442 +0,0 @@ ---- -title: "AwaitExpression" -sidebarTitle: "AwaitExpression" -icon: "" -description: "An awaited expression, only found in asynchronous contexts, e.g. await(foo(bar))" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[HasValue](/api-reference/core/HasValue), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Gets all function calls within the await expression." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### value - -Expression | None } description="Gets the value node of the object." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ AwaitExpression ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ AwaitExpression ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ AwaitExpression ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### resolve -Resolves the wrapper expression and returns the first concrete expression. - - - -Expression } description=""/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_value -Sets the value of the node's value Expression. - - - -str } - description="The new value to set." - defaultValue="" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/core/BinaryExpression.mdx b/docs/_deprecated/api-reference/core/BinaryExpression.mdx deleted file mode 100644 index 2860ccbce..000000000 --- a/docs/_deprecated/api-reference/core/BinaryExpression.mdx +++ /dev/null @@ -1,438 +0,0 @@ ---- -title: "BinaryExpression" -sidebarTitle: "BinaryExpression" -icon: "" -description: "Represents binary expressions, e.g. all of +,-,*,/, as well as boolean operations (and, or) etc." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### elements - -list[ Expression [ BinaryExpression ]] } description="Returns all elements in a binary expression chain." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### left - -Expression [ BinaryExpression ] | None } description="The left operand of the binary expression." /> - -### operators - -list[ ExpressionGroup [ Expression [ BinaryExpression ], BinaryExpression ]] } description="Returns a list of operators in a chain of binary operations." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### right - -Expression [ BinaryExpression ] | None } description="The right operand of the binary expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ BinaryExpression ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ BinaryExpression ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ BinaryExpression ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Simplifies a binary expression by reducing it based on a boolean condition. - - - -bool } - description="The boolean value to reduce the condition to." - defaultValue="" -/> - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/core/BlockStatement.mdx b/docs/_deprecated/api-reference/core/BlockStatement.mdx deleted file mode 100644 index 12b627e7b..000000000 --- a/docs/_deprecated/api-reference/core/BlockStatement.mdx +++ /dev/null @@ -1,481 +0,0 @@ ---- -title: "BlockStatement" -sidebarTitle: "BlockStatement" -icon: "" -description: "Statement which contains a block." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[HasBlock](/api-reference/core/HasBlock), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### code_block - -CodeBlock | None } description="The code block contained within the statement, if it exists." /> - -### decorators - -list[ Decorator ] } description="Returns list of all decorators on this Symbol." /> - -### docstring - -CommentGroup | None } description="Retrieves the docstring of the expression." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Gets all function calls within the statement's code block." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### is_decorated - -bool } description="Check if the symbol has decorators." /> - -### nested_code_blocks - -list[ CodeBlock ] } description="Returns all nested CodeBlocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ BlockStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ BlockStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ BlockStatement ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ BlockStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_docstring -Sets or updates the docstring for the current entity. - - - -str } - description="The new docstring content to set." - defaultValue="" -/> - - - -None } description="This method doesn't return anything."/> - - - diff --git a/docs/_deprecated/api-reference/core/Boolean.mdx b/docs/_deprecated/api-reference/core/Boolean.mdx deleted file mode 100644 index 0b9d15e22..000000000 --- a/docs/_deprecated/api-reference/core/Boolean.mdx +++ /dev/null @@ -1,413 +0,0 @@ ---- -title: "Boolean" -sidebarTitle: "Boolean" -icon: "" -description: "A boolean value eg. True, False" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ Boolean ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ Boolean ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ Boolean ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/core/Callable.mdx b/docs/_deprecated/api-reference/core/Callable.mdx deleted file mode 100644 index 6c6ba9657..000000000 --- a/docs/_deprecated/api-reference/core/Callable.mdx +++ /dev/null @@ -1,589 +0,0 @@ ---- -title: "Callable" -sidebarTitle: "Callable" -icon: "" -description: "Any symbol that can be invoked with arguments eg. Function, Class, Decorator, ExternalModule" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Usable](/api-reference/core/Usable), [Importable](/api-reference/core/Importable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName), [Editable](/api-reference/core/Editable) - -## Attributes - -### call_sites - -list[ FunctionCall ] } description="Returns all call sites (invocations) of this callable in the codebase." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parameters - -SymbolGroup [ Parameter , Callable ] | list[ Parameter ] } description="Retrieves all parameters of a callable symbol." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### return_type - -Type | Placeholder [ Callable ] } description="The type of value returned by the callable, or a placeholder." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ Symbol , Import ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ Callable ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ Callable ] } description=""/> - - -### get_name -Returns the name node of the object. - - - -Name | ChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_parameter -Gets a specific parameter from the callable's parameters list by name. - - - -str } - description="The name of the parameter to retrieve." - defaultValue="" -/> - - - -Parameter | None } description="The parameter with the specified name, or None if no parameter with that name exists or if there are no parameters."/> - - -### get_parameter_by_index -Returns the parameter at the given index. - - - -int } - description="The index of the parameter to retrieve." - defaultValue="" -/> - - - -Parameter | None } description="The parameter at the specified index, or None if the parameter list is empty or the index does not exist."/> - - -### get_parameter_by_type -Retrieves a parameter from the callable by its type. - - - -Symbol } - description="The type to search for." - defaultValue="" -/> - - - -Parameter | None } description="The parameter with the specified type, or None if no parameter is found or if the callable has no parameters."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ Callable ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Renames a symbol and updates all its references in the codebase. - - - -str } - description="The new name for the symbol." - defaultValue="" -/> -int } - description="Priority of the edit operation. Defaults to 0." - defaultValue="0" -/> - - - -tuple[NodeId, NodeId] } description="A tuple containing the file node ID and the new node ID of the renamed symbol."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ Import | Symbol | TSExport ] } description="A list of symbols that use or import the exportable object."/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/core/CatchStatement.mdx b/docs/_deprecated/api-reference/core/CatchStatement.mdx deleted file mode 100644 index 3c0f262da..000000000 --- a/docs/_deprecated/api-reference/core/CatchStatement.mdx +++ /dev/null @@ -1,485 +0,0 @@ ---- -title: "CatchStatement" -sidebarTitle: "CatchStatement" -icon: "" -description: "Abstract representation catch clause." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[BlockStatement](/api-reference/core/BlockStatement), [Statement](/api-reference/core/Statement), [HasBlock](/api-reference/core/HasBlock), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### code_block - -CodeBlock | None } description="The code block contained within the statement, if it exists." /> - -### condition - -Expression [ CatchStatement ] | None } description="The condition which triggers this clause" /> - -### decorators - -list[ Decorator ] } description="Returns list of all decorators on this Symbol." /> - -### docstring - -CommentGroup | None } description="Retrieves the docstring of the expression." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Gets all function calls within the statement's code block." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### is_decorated - -bool } description="Check if the symbol has decorators." /> - -### nested_code_blocks - -list[ CodeBlock ] } description="Returns all nested CodeBlocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ CatchStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ CatchStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ CatchStatement ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ CatchStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_docstring -Sets or updates the docstring for the current entity. - - - -str } - description="The new docstring content to set." - defaultValue="" -/> - - - -None } description="This method doesn't return anything."/> - - - diff --git a/docs/_deprecated/api-reference/core/ChainedAttribute.mdx b/docs/_deprecated/api-reference/core/ChainedAttribute.mdx deleted file mode 100644 index aabf6e261..000000000 --- a/docs/_deprecated/api-reference/core/ChainedAttribute.mdx +++ /dev/null @@ -1,429 +0,0 @@ ---- -title: "ChainedAttribute" -sidebarTitle: "ChainedAttribute" -icon: "" -description: "An attribute of an object. (IE a method on a class, a function from a module, etc) Examples: A.method()" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### attribute - -Attribute } description="Gets the attribute being accessed in a chained attribute expression." /> - -### attribute_chain - -list[ FunctionCall | Name ] } description="Returns a list of elements in a chained attribute expression." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str } description="Returns the full name of the attribute, including the object expression." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### object - -Object } description="Returns the object that contains the attribute being looked up." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ ChainedAttribute ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ ChainedAttribute ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ ChainedAttribute ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/core/Class.mdx b/docs/_deprecated/api-reference/core/Class.mdx deleted file mode 100644 index 1cd5f75e2..000000000 --- a/docs/_deprecated/api-reference/core/Class.mdx +++ /dev/null @@ -1,1022 +0,0 @@ ---- -title: "Class" -sidebarTitle: "Class" -icon: "" -description: "Abstract representation of a Class definition." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[HasBlock](/api-reference/core/HasBlock), [Callable](/api-reference/core/Callable), [Expression](/api-reference/core/Expression), [Usable](/api-reference/core/Usable), [Symbol](/api-reference/core/Symbol), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [HasName](/api-reference/core/HasName) - -## Attributes - -### call_sites - -list[ FunctionCall ] } description="Returns all call sites (invocations) of this callable in the codebase." /> - -### code_block - -CodeBlock } description="The block of code associated with the code object." /> - -### comment - -CommentGroup | None } description="Returns the comment group associated with the symbol, if any." /> - -### constructor - -Function | None } description="Returns the constructor method for this class." /> - -### decorators - -list[ Decorator ] } description="Returns list of all decorators on this Symbol." /> - -### docstring - -CommentGroup | None } description="Retrieves the docstring of the expression." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_nodes - -list[ Editable ] } description="Returns a list of Editable nodes associated with this symbol, including extended symbols." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns all function calls within the code block and its decorators." /> - -### inline_comment - -CommentGroup | None } description="Returns the inline comment group associated with the symbol, if any." /> - -### is_decorated - -bool } description="Check if the symbol has decorators." /> - -### is_subclass - -bool } description="Indicates whether the current class is a subclass of another class." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### nested_classes - -list[ Class ] } description="Retrieves the nested classes defined within this class." /> - -### parameters - -SymbolGroup [ Parameter , Class ] | list[ Parameter ] } description="Retrieves all parameters of a callable symbol." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_class_names - -list[ Name | ChainedAttribute ] } description="Returns a list of the parent class names that this class inherits from." /> - -### parent_classes - -Parents[ Type , Class ] | None } description="The parent classes of this class, if any." /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### return_type - -Type | Placeholder [ Class ] } description="The type of value returned by the callable, or a placeholder." /> - -### source - -str } description="Returns the source code of the symbol." /> - -### symbol_type - - } description="The type of symbol, set to SymbolType.Class." /> - -### type_parameters - -TypeParameters[ Type , Class ] | None } description="The type parameters of the symbol, if any." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_attribute -Adds an attribute to a class from another class. - - - -Attribute } - description="The attribute to add to the class." - defaultValue="" -/> -bool, optional } - description="Whether to include the attribute's dependencies. If True, adds any necessary imports to the class's file. Defaults to False." - defaultValue="False" -/> - - - -None } description=""/> - - -### add_attribute_from_source -Adds an attribute to a class from raw source code, placing it in a specific location - - - -str } - description="The source code of the attribute to be added." - defaultValue="" -/> - - - -None } description=""/> - - -### add_comment -Adds a comment to the symbol. - - - -str } - description="The comment text to add." - defaultValue="" -/> - - - -None } description=""/> - - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### add_keyword -Insert a keyword in the appropriate place before this symbol if it doesn't already exist. - - - -str } - description="The keyword to be inserted. Must be a valid keyword in the language context." - defaultValue="" -/> - - - -None } description=""/> - - -### add_source -Add a block of source code to the bottom of a class definition. - - - -str } - description="The source code to be added to the class definition. The code should be properly formatted" - defaultValue="" -/> - - - -None } description=""/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### attributes -Retrieves all attributes from this Class including those from its superclasses up to a - - - -int | None } - description="The maximum depth of superclass traversal. None means no limit, 0 means only this class." - defaultValue="0" -/> -bool } - description="Whether to include private attributes. Defaults to True." - defaultValue="True" -/> - - - -list[ Attribute ] } description="A list of unique attributes from this class and its superclasses. If an attribute is defined in multiple classes, the first definition encountered is used."/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ Symbol , Import ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this node with new_src. - - - -str } - description="The new source code to replace the current source with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, prevents duplicate edits. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ Class ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ Class ] } description=""/> - - -### get_attribute -Returns a specific attribute by name. - - - -str } - description="The name of the attribute to search for." - defaultValue="" -/> - - - -Attribute | None } description="The matching attribute if found, None otherwise. If multiple attributes with the same name exist in the inheritance hierarchy, returns the first one found."/> - - -### get_method -Returns a specific method by name from the class or any of its superclasses. - - - -str } - description="The name of the method to find." - defaultValue="" -/> - - - -Function | None } description="The method if found, None otherwise."/> - - -### get_name -Returns the name node of the object. - - - -Name | ChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_nested_class -Returns a nested class by name from the current class. - - - -str } - description="The name of the nested class to find." - defaultValue="" -/> - - - -Class | None } description="The nested class if found, None otherwise."/> - - -### get_parameter -Gets a specific parameter from the callable's parameters list by name. - - - -str } - description="The name of the parameter to retrieve." - defaultValue="" -/> - - - -Parameter | None } description="The parameter with the specified name, or None if no parameter with that name exists or if there are no parameters."/> - - -### get_parameter_by_index -Returns the parameter at the given index. - - - -int } - description="The index of the parameter to retrieve." - defaultValue="" -/> - - - -Parameter | None } description="The parameter at the specified index, or None if the parameter list is empty or the index does not exist."/> - - -### get_parameter_by_type -Retrieves a parameter from the callable by its type. - - - -Symbol } - description="The type to search for." - defaultValue="" -/> - - - -Parameter | None } description="The parameter with the specified type, or None if no parameter is found or if the callable has no parameters."/> - - -### get_parent_class -Returns the parent class node with the specified name. - - - -str } - description="The name of the parent class to find." - defaultValue="" -/> - - - -Editable | None } description="The matching parent class node, or None if no match is found."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ Class ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before the current symbol node in the Abstract Syntax Tree. - - - -str } - description="The source code text to insert." - defaultValue="" -/> -bool } - description="Whether to adjust the indentation of new_src to match current text. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after insertion. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to remove duplicate insertions. Defaults to True." - defaultValue="True" -/> -bool } - description="Whether to insert before extended nodes like comments and decorators. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_subclass_of -Checks if the class inherits from a specified parent class. - - - -str | Class } - description="The parent class to check for. Can be specified either as a class name string or Class object." - defaultValue="" -/> -int | None } - description="Maximum inheritance depth to search. None means no limit." - defaultValue="None" -/> - - - -bool } description="True if this class inherits from the parent class, False otherwise."/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### methods -Retrieves all methods that exist on this Class, including methods from superclasses, with - - - -int | None, optional } - description="Include parent classes up to max_depth. None means no limit, 0 means only current class. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to include private methods. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to include magic methods. Defaults to False." - defaultValue="True" -/> - - - -list[ Function ] | MultiLineCollection [ Function , Class ] } description=""/> - - -### move_to_file -Moves the given symbol to a new file and updates its imports and references. - - - -SourceFile } - description="The destination file to move the symbol to." - defaultValue="" -/> -bool } - description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." - defaultValue="True" -/> -str } - description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." - defaultValue=""update_all_imports"" -/> - - - -None } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Renames a symbol and updates all its references in the codebase. - - - -str } - description="The new name for the symbol." - defaultValue="" -/> -int } - description="Priority of the edit operation. Defaults to 0." - defaultValue="0" -/> - - - -tuple[NodeId, NodeId] } description="A tuple containing the file node ID and the new node ID of the renamed symbol."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_comment -Sets a comment to the symbol. - - - -str } - description="The comment text to set." - defaultValue="" -/> - - - -None } description=""/> - - -### set_docstring -Sets or updates the docstring for the current entity. - - - -str } - description="The new docstring content to set." - defaultValue="" -/> - - - -None } description="This method doesn't return anything."/> - - -### set_inline_comment -Sets an inline comment to the symbol. - - - -str } - description="The text of the inline comment to be added or updated." - defaultValue="" -/> - - - -None } description=""/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### subclasses -Returns all classes which subclass this class. - - - -int | None, optional } - description="Maximum inheritance depth to search. If None, searches all depths. Defaults to None." - defaultValue="None" -/> - - - -list[ Class ] } description="A list of Class objects that inherit from this class."/> - - -### superclasses -Returns a list of all classes that this class extends, up to max_depth. - - - -int | None } - description="The maximum depth to traverse up the inheritance tree. If None, traverses the entire tree." - defaultValue="None" -/> - - - -list[ Class | ExternalModule | TSInterface ] } description="A list of all superclass symbols in MRO order, up to max_depth. Returns an empty list if the class has no parent classes."/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ Import | Symbol | TSExport ] } description="A list of symbols that use or import the exportable object."/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/core/CodeBlock.mdx b/docs/_deprecated/api-reference/core/CodeBlock.mdx deleted file mode 100644 index 541396c5a..000000000 --- a/docs/_deprecated/api-reference/core/CodeBlock.mdx +++ /dev/null @@ -1,612 +0,0 @@ ---- -title: "CodeBlock" -sidebarTitle: "CodeBlock" -icon: "" -description: "Container class for a list of code Statements that share an indentation level, e.g. a function body or class body. Enables various types of queries and operations on the code block." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### assignment_statements - -list[ AssignmentStatement [ CodeBlock , Assignment ]] } description="Returns list of top level assignment statements in the code block." /> - -### assignments - -list[ Assignment [ Editable , CodeBlock ]] } description="Returns all assignments in the code block across all nesting levels." /> - -### attributes - -list[ Attribute [ Editable , CodeBlock ]] } description="Returns a list of top level class attribute statements in the code block." /> - -### comments - -list[ Comment [ Editable , CodeBlock ]] } description="Gets list of top level comments in the code block." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls in the code block." /> - -### if_blocks - -list[ IfBlockStatement [ CodeBlock ]] } description="Returns a list of top level if statements in the code block." /> - -### level - -int } description="The indentation level of the code block." /> - -### local_var_assignments - -list[ Assignment [ Editable , CodeBlock ]] } description="Returns all local variable assignment in the code block, for all nest levels." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_block - -CodeBlock | None } description="The parent code block containing this block, or None if it is a top-level block." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### return_statements - -list[ ReturnStatement [ CodeBlock ]] } description="Gets all return statements at the top level of the code block." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### statements - -MultiLineCollection [ Statement , CodeBlock ] } description="Gets a view of the top-level statements in the code block." /> - -### symbol_statements - -list[ SymbolStatement ] } description="Returns list of top level symbol statements in the code block." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ CodeBlock ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ CodeBlock ] } description=""/> - - -### get_assignments -Returns a list of assignments with the specified variable name. - - - -str } - description="The name of the variable to find assignments for." - defaultValue="" -/> - - - -list[ Assignment [ Editable , CodeBlock ]] } description="A list of Assignment objects that match the variable name."/> - - -### get_attributes -Returns attributes from the code block, with the option to include or exclude private - - - -bool } - description="Whether to include private attributes in the returned list. If True, returns both private and" - defaultValue="" -/> - - - -list[ Attribute [ Editable , CodeBlock ]] } description="A list of attribute statements matching the privacy criteria."/> - - -### get_comment -Gets the first comment statement containing a specific text string. - - - -str } - description="The text string to search for within comment statements." - defaultValue="" -/> - - - -Comment [ Editable , CodeBlock ] | None } description="The first comment statement containing the search text, or None if no matching comment is found."/> - - -### get_local_var_assignment -Returns the first code statement that assigns a local variable with the specified name. - - - -str } - description="The name of the local variable to search for." - defaultValue="" -/> - - - -Assignment [ Editable , CodeBlock ] | None } description="The first matching local variable assignment, or None if no match is found."/> - - -### get_local_var_assignments -Returns all instances of local variable assignments that match the specified variable - - - -str } - description="The name of the local variable to search for." - defaultValue="" -/> -bool, optional } - description="If True, matches variables whose names contain var_name." - defaultValue="False" -/> - - - -list[ Assignment [ Editable , CodeBlock ]] } description="List of Assignment objects representing local variable assignments that match the specified name criteria."/> - - -### get_statements -Returns all statements of a given type up to the specified block level. - - - -StatementType | None } - description="The type of statements to return. If None, returns all statement types." - defaultValue="None" -/> -int | None } - description="The maximum block depth level to search. If None, searches all levels." - defaultValue="None" -/> - - - -list[ Statement [ CodeBlock ]] } description=""/> - - -### get_variable_usages -Returns all instances of variable usages in a code block. - - - -str } - description="The name of the variable to search for." - defaultValue="" -/> -bool } - description="When True, matches on variable names that contain var_name. When False (default), only matches exact variable names." - defaultValue="False" -/> - - - -list[ Editable [ CodeBlock ]] } description="A sorted list of variable usage instances as Editable objects."/> - - -### indent -Adjusts the indentation level of the entire code block. - - - -int } - description="The number of indentation levels to adjust. Positive values indent right, negative values indent left." - defaultValue="" -/> - - - -None } description=""/> - - -### insert_after -Inserts source code at the bottom of the code block. - - - -str } - description="The source code to insert." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of the inserted code. Defaults to True." - defaultValue="True" -/> -bool } - description="Whether to add a newline before the inserted code. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts new source code at the top of the code block. - - - -str } - description="The source code to insert at the top of the code block." - defaultValue="" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename_variable_usages -Renames all instances of variable usages in the code block. - - - -str } - description="The current name of the variable to rename." - defaultValue="" -/> -str } - description="The new name to give the variable." - defaultValue="" -/> -bool } - description="When True, matches variables containing old_var_name. When False, only exact matches. Defaults to False." - defaultValue="False" -/> - - - -None } description="This method mutates the code block in place."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### unwrap -Extracts a code block from its parent wrapper container by removing the wrapping - - - -None } description=""/> - - -### wrap -Wraps a code block with a statement and indents it. - - - -str } - description="The source code to insert before the block." - defaultValue="" -/> -str } - description="The source code to insert after the block. Defaults to an empty string." - defaultValue="""" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/core/CodeOwner.mdx b/docs/_deprecated/api-reference/core/CodeOwner.mdx deleted file mode 100644 index 033f40e6b..000000000 --- a/docs/_deprecated/api-reference/core/CodeOwner.mdx +++ /dev/null @@ -1,153 +0,0 @@ ---- -title: "CodeOwner" -sidebarTitle: "CodeOwner" -icon: "" -description: "CodeOwner is a class that represents a code owner in a codebase. It is used to iterate over all files that are owned by a specific owner." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - - -## Attributes - -### classes - -list[ Class ] } description="Get a recursive list of all classes in files container." /> - -### exports - -list[ TSExport ] } description="Get a recursive list of all exports in files container." /> - -### files_source - -Callable [FilesParam, Iterable[TFile]] } description="A callable that returns an iterable of all files in the codebase." /> - -### functions - -list[ Function ] } description="Get a recursive list of all functions in files container." /> - -### global_vars - -list[ Assignment ] } description="Get a recursive list of all global variables in files container." /> - -### import_statements - -list[ ImportStatement ] } description="Get a recursive list of all import statements in files container." /> - -### imports - -list[ Import ] } description="Get a recursive list of all imports in files container." /> - -### name - -str } description="The name of the code owner." /> - -### owner_type - -Literal[USERNAME, TEAM, EMAIL] } description="The type of the owner (USERNAME, TEAM, EMAIL)." /> - -### owner_value - -str } description="The value of the owner." /> - -### symbols - -list[ Symbol ] } description="Get a recursive list of all symbols in files container." /> - - -## Methods - -### files -Recursively iterate over all files in the codebase that are owned by the current code owner. - - - -Iterable[TFile] } description=""/> - - -### from_parser -Create a list of CodeOwner objects from a CodeOwnersParser. - - - -CodeOwnersParser } - description="The CodeOwnersParser to use." - defaultValue="" -/> -Callable [FilesParam, Iterable[TFile]] } - description="A callable that returns an iterable of all files in the codebase." - defaultValue="" -/> - - - -list[ CodeOwner ] } description="A list of CodeOwner objects."/> - - -### get_class -Get a class by name in files container. - - - -Class | None } description=""/> - - -### get_export -Get an export by name in files container (supports only typescript). - - - -TSExport | None } description=""/> - - -### get_function -Get a function by name in files container. - - - -Function | None } description=""/> - - -### get_global_var -Get a global variable by name in files container. - - - -Assignment | None } description=""/> - - -### get_import -Get an import by name in files container. - - - -Import | None } description=""/> - - -### get_import_statement -Get an import statement by name in files container. - - - -ImportStatement | None } description=""/> - - -### get_symbol -Get a symbol by name in files container. - - - -Symbol | None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/core/Codebase.mdx b/docs/_deprecated/api-reference/core/Codebase.mdx deleted file mode 100644 index 339a6c71f..000000000 --- a/docs/_deprecated/api-reference/core/Codebase.mdx +++ /dev/null @@ -1,702 +0,0 @@ ---- -title: "Codebase" -sidebarTitle: "Codebase" -icon: "" -description: "This class provides the main entrypoint for most programs to analyzing and manipulating codebases." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - - -## Attributes - -### classes - -list[ Class ] } description="List of all Classes in the codebase." /> - -### codeowners - -list[ CodeOwner [ SourceFile ]] } description="List all CodeOnwers in the codebase." /> - -### current_commit - -GitCommit | None } description="Returns the current Git commit that is checked out in the repository." /> - -### default_branch - -str } description="The default branch of this repository." /> - -### directories - -list[ Directory ] } description="List all directories in the codebase." /> - -### exports - -list[ TSExport ] } description="Returns a list of all Export nodes in the codebase." /> - -### external_modules - -list[ ExternalModule ] } description="Returns a list of all external modules in the codebase." /> - -### functions - -list[ Function ] } description="List of all Functions in the codebase." /> - -### github - -RepoOperator } description="Access GitHub operations through the repo operator." /> - -### global_vars - -list[ Assignment ] } description="List of all GlobalVars in the codebase." /> - -### imports - -list[ Import ] } description="Returns a list of all Import nodes in the codebase." /> - -### interfaces - -list[ TSInterface ] } description="Retrieves all interfaces in the codebase." /> - -### language - -ProgrammingLanguage } description="The programming language of the repository." /> - -### name - -str } description="The name of the repository." /> - -### repo_path - -Path } description="The path to the repository." /> - -### symbols - -list[ Symbol ] } description="List of all top-level Symbols (Classes, Functions, etc.) in the codebase. Excludes Class" /> - -### types - -list[ TSTypeAlias ] } description="List of all Types in the codebase (Typescript only)." /> - - -## Methods - -### ai -Generates a response from the AI based on the provided prompt, target, and context. - - - -str } - description="The text prompt to send to the AI." - defaultValue="" -/> -Editable | None } - description="An optional editable object (like a function, class, etc.) that provides the main focus for the AI's response." - defaultValue="None" -/> -Editable | list[ Editable ] | dict[str, Editable | list[ Editable ]] | None } - description="Additional context to help inform the AI's response." - defaultValue="None" -/> -str } - description="The AI model to use for generating the response. Defaults to "gpt-4o"." - defaultValue=""gpt-4o"" -/> - - - -str } description="The generated response from the AI."/> - - -### checkout -Checks out a git branch or commit and syncs the codebase graph to the new state. - - - -str | GitCommit | None } - description="Hash or GitCommit object to checkout. Cannot be used with branch." - defaultValue="None" -/> -str | None } - description="Name of branch to checkout. Cannot be used with commit." - defaultValue="None" -/> -bool } - description="If True, creates the branch if it doesn't exist. Defaults to False." - defaultValue="False" -/> -bool } - description="If True, attempts to pull from remote when checking out branch. Defaults to False." - defaultValue="False" -/> - - - -CheckoutResult } description="The result of the checkout operation."/> - - -### commit -Commits all staged changes to the codebase graph and synchronizes the graph with the filesystem if specified. - - - -bool } - description="Whether to synchronize the graph after committing changes. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### create_directory -Creates a directory at the specified path. - - - -str } - description="The path where the directory should be created." - defaultValue="" -/> -bool } - description="If True, don't raise an error if the directory already exists. Defaults to False." - defaultValue="False" -/> -bool } - description="If True, create any necessary parent directories. Defaults to False." - defaultValue="False" -/> - - - -None } description=""/> - - -### create_file -Creates a new file in the codebase with specified content. - - - -str } - description="The path where the file should be created." - defaultValue="" -/> -str } - description="The content of the file to be created. Defaults to empty string." - defaultValue="""" -/> -bool } - description="Whether to sync the graph after creating the file. Defaults to True." - defaultValue="True" -/> - - - -SourceFile } description="The newly created file object."/> - - -### create_pr -Creates a pull request from the current branch to the repository's default branch. - - - -str } - description="The title for the pull request" - defaultValue="" -/> -str } - description="The description/body text for the pull request" - defaultValue="" -/> - - - -PullRequest } description="The created GitHub pull request object"/> - - -### create_pr_comment -Create a comment on a pull request - - - -None } description=""/> - - -### create_pr_review_comment -Create a review comment on a pull request. - - - -None } description=""/> - - -### files -A list property that returns all files in the codebase. - - - -list[ SourceFile ] | list[ File ] } description="A sorted list of source files in the codebase."/> - - -### find_by_span -Finds editable objects that overlap with the given source code span. - - - -Span } - description="The span object containing the filepath and byte range to search within." - defaultValue="" -/> - - - -list[ Editable ] } description="A list of Editable objects that overlap with the given span."/> - - -### from_files -Creates a Codebase instance from multiple files. - - - -Codebase } description="A Codebase instance initialized with the provided files"/> - - -### from_repo -Fetches a codebase from GitHub and returns a Codebase instance. - - - -str } - description="The name of the repository in format "owner/repo"" - defaultValue="" -/> -Optional[str] } - description="The directory to clone the repo into. Defaults to /tmp/codegen" - defaultValue=""/tmp/codegen"" -/> -Optional[str] } - description="The specific commit hash to clone. Defaults to HEAD" - defaultValue="None" -/> -bool } - description="Whether to do a shallow clone. Defaults to True" - defaultValue="" -/> -Literal["python", "typescript"] | ProgrammingLanguage | None } - description="The programming language of the repo. Defaults to None." - defaultValue="" -/> -CodebaseConfig } - description="Configuration for the codebase. Defaults to pre-defined defaults if None." - defaultValue="" -/> -SecretsConfig } - description="Configuration for the secrets. Defaults to empty values if None." - defaultValue="" -/> - - - -Codebase } description="A Codebase instance initialized with the cloned repository"/> - - -### from_string -Creates a Codebase instance from a string of code. - - - -Codebase } description="A Codebase instance initialized with the provided code Example: >>> # Python code >>> code = "def add(a, b): return a + b" >>> codebase = Codebase.from_string(code, language="python") >>> # TypeScript code >>> code = "function add(a: number, b: number): number { return a + b; }" >>> codebase = Codebase.from_string(code, language="typescript")"/> - - -### get_class -Returns a class that matches the given name. - - - -str } - description="The name of the class to find." - defaultValue="" -/> -bool } - description="If True, return None when class is not found instead of raising ValueError. Defaults to False." - defaultValue="False" -/> - - - -Class | None } description="The class with the given name, or None if optional=True and class not found."/> - - -### get_directory -Returns Directory by `dir_path`, or full path to the directory from codebase root. - - - -str } - description="The path to the directory to retrieve." - defaultValue="" -/> -bool } - description="If True, return None when directory is not found. If False, raise ValueError." - defaultValue="False" -/> - - - -Directory | None } description="The Directory object if found, None if optional=True and directory not found."/> - - -### get_file -Retrieves a file from the codebase by its filepath. - - - -str } - description="The path to the file, relative to the codebase root." - defaultValue="" -/> -bool } - description="If True, return None if file not found. If False, raise ValueError." - defaultValue="False" -/> -bool } - description="If True, ignore case when checking for file existence. Defaults to False." - defaultValue="False" -/> - - - -SourceFile | None } description="The source file if found, None if optional=True and file not found."/> - - -### get_function -Retrieves a function from the codebase by its name. - - - -str } - description="The name of the function to retrieve." - defaultValue="" -/> -bool } - description="If True, returns None when function is not found instead of raising ValueError." - defaultValue="False" -/> - - - -Function | None } description="The matching function if found. If optional=True and no match is found, returns None."/> - - -### get_modified_symbols_in_pr -Get all modified symbols in a pull request - - - -tuple[str, dict[str, str], list[str], str] } description=""/> - - -### get_relative_path -Calculates a relative path from one file to another, removing the extension from the target file. - - - -str } - description="The file path from which the relative path will be computed." - defaultValue="" -/> -str } - description="The file path (whose extension will be removed) to which the relative path will be computed." - defaultValue="" -/> - - - -str } description="The relative path from `from_file` to `to_file` (with the extension removed from `to_file`)."/> - - -### get_symbol -Returns a Symbol by name from the codebase. - - - -str } - description="The name of the symbol to find." - defaultValue="" -/> -bool } - description="If True, returns None when symbol is not found. If False, raises ValueError. Defaults to False." - defaultValue="False" -/> - - - -Symbol | None } description="The matched Symbol if found, None if not found and optional=True."/> - - -### get_symbols -Retrieves all symbols in the codebase that match the given symbol name. - - - -str } - description="The name of the symbols to retrieve." - defaultValue="" -/> - - - -list[ Symbol ] } description="A list of Symbol objects that match the given name, sorted alphabetically."/> - - -### git_commit -Stages + commits all changes to the codebase and git. - - - -str } - description="The commit message" - defaultValue="" -/> -bool } - description="Whether to verify the commit before committing. Defaults to False." - defaultValue="False" -/> - - - -GitCommit | None } description="The commit object if changes were committed, None otherwise."/> - - -### has_directory -Returns a boolean indicating if a directory exists in the codebase. - - - -str } - description="The path to the directory to check for, relative to the codebase root." - defaultValue="" -/> - - - -bool } description="True if the directory exists in the codebase, False otherwise."/> - - -### has_file -Determines if a file exists in the codebase. - - - -str } - description="The filepath to check for existence." - defaultValue="" -/> -bool } - description="If True, ignore case when checking for file existence. Defaults to False." - defaultValue="False" -/> - - - -bool } description="True if the file exists in the codebase, False otherwise."/> - - -### has_symbol -Returns whether a symbol exists in the codebase. - - - -str } - description="The name of the symbol to look for." - defaultValue="" -/> - - - -bool } description="True if a symbol with the given name exists in the codebase, False otherwise."/> - - -### reset -Resets the codebase by - - - -None } description=""/> - - -### set_ai_key -Sets the OpenAI key for the current Codebase instance. - - - -None } description=""/> - - -### set_session_options -Sets the session options for the current codebase. - - - -int, optional } - description="The maximum number of transactions" - defaultValue="" -/> -int, optional } - description="The maximum duration in seconds for a session" - defaultValue="" -/> -int, optional } - description="The maximum number of AI requests" - defaultValue="" -/> - - - -None } description=""/> - - -### should_fix -Returns True if the flag should be fixed based on the current mode and active group. - - - -CodeFlag } - description="The code flag to check." - defaultValue="" -/> - - - -bool } description="True if the flag should be fixed, False if it should be ignored. Returns False in find mode. Returns True if no active group is set. Returns True if the flag's hash exists in the active group hashes."/> - - -### visualize -Visualizes a NetworkX graph or Plotly figure. - - - -Graph | go.Figure } - description="A NetworkX graph or Plotly figure to visualize" - defaultValue="" -/> -Editable | str | int | None } - description="The root node to visualize around. When specified, the visualization will be centered on this node. Defaults to None." - defaultValue="None" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/core/Comment.mdx b/docs/_deprecated/api-reference/core/Comment.mdx deleted file mode 100644 index eb8e4abce..000000000 --- a/docs/_deprecated/api-reference/core/Comment.mdx +++ /dev/null @@ -1,446 +0,0 @@ ---- -title: "Comment" -sidebarTitle: "Comment" -icon: "" -description: "Abstract representation of comment statements." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### nested_code_blocks - -list[ CodeBlock ] } description="Returns a list of nested code blocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ Comment ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### text - -str } description="Returns the text content of the comment." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### edit_text -Replace the text of a comment with new text. - - - -str } - description="The new text content to replace the existing comment text." - defaultValue="" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ Comment ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ Comment ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ Comment ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/core/CommentGroup.mdx b/docs/_deprecated/api-reference/core/CommentGroup.mdx deleted file mode 100644 index da3944300..000000000 --- a/docs/_deprecated/api-reference/core/CommentGroup.mdx +++ /dev/null @@ -1,436 +0,0 @@ ---- -title: "CommentGroup" -sidebarTitle: "CommentGroup" -icon: "" -description: "A group of comments that form a larger comment block." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[SymbolGroup](/api-reference/core/SymbolGroup), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### next_named_sibling - -Editable | None } description="Returns the next named sibling of the last symbol in the group." /> - -### next_sibling - -Editable | None } description="Returns the next sibling of the last symbol in the symbol group." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### source - -str } description="Returns the concatenated source code of all symbols in the group." /> - -### symbols - -list[ Editable ] } description="Returns the list of symbols in the group." /> - -### text - -str } description="Return the text content of all comments in the comment block." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this node with new text. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool, optional } - description="Adjusts the indentation of new_src to match the current text's indentation. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the edit operation. Higher priority edits take precedence. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Prevents duplicate edits at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### edit_text -Replace the text content of a comment group with new text. - - - -str } - description="The new text content to replace the existing comment text." - defaultValue="" -/> - - - -None } description=""/> - - -### find -Search for substrings in the given symbols that match `strings_to_match`. - - - -list[str] | str } - description="The string or list of strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes that exactly match the query." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable objects representing each match found."/> - - -### find_string_literals -Search for string literals matching given strings in the SymbolGroup. - - - -list[str] } - description="List of strings to search for in string literals." - defaultValue="" -/> -bool, optional } - description="If True, performs fuzzy matching instead of exact matching." - defaultValue="False" -/> - - - -list[ Editable ] } description="List of Editable nodes representing the matching string literals found within the symbols."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ CommentGroup ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ CommentGroup ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts source code after this node in the codebase. - - - -str } - description="The source code to insert." - defaultValue="" -/> -bool, optional } - description="Adjust indentation to match current text." - defaultValue="False" -/> -bool, optional } - description="Add a newline before the inserted code." - defaultValue="True" -/> -int, optional } - description="Priority of the edit operation." - defaultValue="0" -/> -bool, optional } - description="Deduplicate identical edits." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts source code before this symbol group. - - - -str } - description="The source code to insert." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of the inserted code to match the current code. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline after the inserted code. Defaults to True." - defaultValue="True" -/> -int, optional } - description="The priority of this edit operation. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to prevent duplicate insertions of the same code. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Removes this node and its related extended nodes from the codebase. - - - -bool, optional } - description="Whether to delete related extended nodes like decorators and comments. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority level of the removal operation. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate removal operations. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Replaces all instances of a string with a new string in all symbols within the group. - - - -str } - description="The string to be replaced." - defaultValue="" -/> -str } - description="The string to replace with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="Number of replacements made."/> - - -### search -Searches for regex matches in the codebase. - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool, optional } - description="Whether to include string literals in the search. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to include comments in the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects representing matched text nodes in the codebase."/> - - - diff --git a/docs/_deprecated/api-reference/core/ComparisonExpression.mdx b/docs/_deprecated/api-reference/core/ComparisonExpression.mdx deleted file mode 100644 index 50933fb62..000000000 --- a/docs/_deprecated/api-reference/core/ComparisonExpression.mdx +++ /dev/null @@ -1,438 +0,0 @@ ---- -title: "ComparisonExpression" -sidebarTitle: "ComparisonExpression" -icon: "" -description: "Any comparison expression in the code. Includes all set of `<`, `<=`, `>`, `>=`, `==`, `!=` etc." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[BinaryExpression](/api-reference/core/BinaryExpression), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### elements - -list[ Expression [ ComparisonExpression ]] } description="Returns a list of expressions for named child nodes." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### left - -Expression [ ComparisonExpression ] | None } description="The left operand of the binary expression." /> - -### operators - -list[ ExpressionGroup [ Expression [ ComparisonExpression ], ComparisonExpression ]] } description="Returns a list of operator expressions in a comparison expression." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### right - -Expression [ ComparisonExpression ] | None } description="The right operand of the binary expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ ComparisonExpression ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ ComparisonExpression ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ ComparisonExpression ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Simplifies a binary expression by reducing it based on a boolean condition. - - - -bool } - description="The boolean value to reduce the condition to." - defaultValue="" -/> - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/core/Decorator.mdx b/docs/_deprecated/api-reference/core/Decorator.mdx deleted file mode 100644 index 88548faba..000000000 --- a/docs/_deprecated/api-reference/core/Decorator.mdx +++ /dev/null @@ -1,467 +0,0 @@ ---- -title: "Decorator" -sidebarTitle: "Decorator" -icon: "" -description: "Abstract representation of a Decorator." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName), [Editable](/api-reference/core/Editable) - -## Attributes - -### call - -FunctionCall | None } description="Returns any function call made by this decorator." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ Decorator ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ Decorator ] } description=""/> - - -### get_name -Returns the name node of the object. - - - -Name | ChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ Decorator ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Sets the name of an object and updates all its usages. - - - -str } - description="The new name to assign to the object." - defaultValue="" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/core/Dict.mdx b/docs/_deprecated/api-reference/core/Dict.mdx deleted file mode 100644 index da00bfca6..000000000 --- a/docs/_deprecated/api-reference/core/Dict.mdx +++ /dev/null @@ -1,417 +0,0 @@ ---- -title: "Dict" -sidebarTitle: "Dict" -icon: "" -description: "Represents a dict (object) literal the source code." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### unpack - -Unpack [ Dict ] | None } description="An optional unpacking element, if present." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ Dict ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ Dict ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ Dict ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/core/Directory.mdx b/docs/_deprecated/api-reference/core/Directory.mdx deleted file mode 100644 index 1ec1dfc1b..000000000 --- a/docs/_deprecated/api-reference/core/Directory.mdx +++ /dev/null @@ -1,198 +0,0 @@ ---- -title: "Directory" -sidebarTitle: "Directory" -icon: "" -description: "Directory representation for codebase. GraphSitter abstraction of a file directory that can be used to look for files and symbols within a specific directory." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - - -## Attributes - -### classes - -list[ Class ] } description="Get a recursive list of all classes in files container." /> - -### dirpath - -str } description="Relative path of the directory." /> - -### exports - -list[ TSExport ] } description="Get a recursive list of all exports in files container." /> - -### file_names - -list[str] } description="Get a list of all file names in the directory." /> - -### functions - -list[ Function ] } description="Get a recursive list of all functions in files container." /> - -### global_vars - -list[ Assignment ] } description="Get a recursive list of all global variables in files container." /> - -### import_statements - -list[ ImportStatement ] } description="Get a recursive list of all import statements in files container." /> - -### imports - -list[ Import ] } description="Get a recursive list of all imports in files container." /> - -### item_names - -list[str] } description="Get a list of all file and subdirectory names in the directory." /> - -### name - -str } description="Get the base name of the directory's path." /> - -### parent - -Directory | None } description="Get the parent directory of the current directory." /> - -### path - -Path } description="Absolute path of the directory." /> - -### symbols - -list[ Symbol ] } description="Get a recursive list of all symbols in files container." /> - -### tree - -list[ Directory | TFile] } description="Get a recursive list of all files and subdirectories in the directory." /> - - -## Methods - -### files -Gets a list of all top level files in the directory. - - - -list[TFile] } description="A sorted list of source files in the codebase."/> - - -### get_class -Get a class by name in files container. - - - -Class | None } description=""/> - - -### get_export -Get an export by name in files container (supports only typescript). - - - -TSExport | None } description=""/> - - -### get_file -Get a file by its name relative to the directory. - - - -TFile | None } description=""/> - - -### get_function -Get a function by name in files container. - - - -Function | None } description=""/> - - -### get_global_var -Get a global variable by name in files container. - - - -Assignment | None } description=""/> - - -### get_import -Get an import by name in files container. - - - -Import | None } description=""/> - - -### get_import_statement -Get an import statement by name in files container. - - - -ImportStatement | None } description=""/> - - -### get_subdirectory -Get a subdirectory by its name (relative to the directory). - - - -Directory | None } description=""/> - - -### get_symbol -Get a symbol by name in files container. - - - -Symbol | None } description=""/> - - -### items -Get a list of all files and subdirectories in the directory. - - - -list[ Directory | TFile] } description="A sorted list of files and subdirectories in the directory."/> - - -### remove -Remove all the files in the files container. - - - -None } description=""/> - - -### rename -Rename the directory. - - - -None } description=""/> - - -### subdirectories -Get a list of all top level subdirectories in the directory. - - - -list[ Directory ] } description="A sorted list of subdirectories in the directory."/> - - -### update_filepath -Update the filepath of the directory and its contained files. - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/core/Editable.mdx b/docs/_deprecated/api-reference/core/Editable.mdx deleted file mode 100644 index 32a338214..000000000 --- a/docs/_deprecated/api-reference/core/Editable.mdx +++ /dev/null @@ -1,407 +0,0 @@ ---- -title: "Editable" -sidebarTitle: "Editable" -icon: "" -description: "An editable instance is an abstract text representation of any text in a file." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ Editable ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ Editable ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ Editable ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/core/Export.mdx b/docs/_deprecated/api-reference/core/Export.mdx deleted file mode 100644 index 1778f3841..000000000 --- a/docs/_deprecated/api-reference/core/Export.mdx +++ /dev/null @@ -1,613 +0,0 @@ ---- -title: "Export" -sidebarTitle: "Export" -icon: "" -description: "Represents a single symbol being exported." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Exportable](/api-reference/core/Exportable), [Usable](/api-reference/core/Usable), [Importable](/api-reference/core/Importable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName), [Editable](/api-reference/core/Editable) - -## Attributes - -### export - -TSExport | None } description="Returns the export object that exports this symbol." /> - -### export_statement - -ExportStatement } description="The statement representing the export." /> - -### exported_name - -str | None } description="Retrieves the exported name of a symbol from its file." /> - -### exported_symbol - -Exportable | None } description="Returns the symbol, file, or import being exported from this export object." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### is_exported - -bool } description="Indicates if the symbol is exported from its defining file." /> - -### is_reexported - -bool } description="Determines if the symbol is re-exported from a different file." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_symbol - -Exportable | None } description="Returns the resolved symbol for an export." /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ Symbol , Import ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ Export ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ Export ] } description=""/> - - -### get_import_string -Returns the import string for a symbol. - - - -str | None } - description="Optional alias for the symbol." - defaultValue="None" -/> -str | None } - description="Optional module name to import from." - defaultValue="None" -/> -ImportType } - description="Type of import to generate." - defaultValue="ImportType.UNKNOWN" -/> -bool } - description="Indicates if it's a type-only import." - defaultValue="False" -/> - - - -str } description="The formatted import string."/> - - -### get_name -Returns the name node of the object. - - - -Name | ChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ Export ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_aliased -Determines if the Export object is aliased. - - - -bool } description="True if the exported symbol has a different name than the name it is exported as, False otherwise."/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_module_export -Determines if the export is a module-level export. - - - -bool } description="True if the export is a module-level export, False otherwise."/> - - -### is_named_export -Determines if the export is named or default. - - - -bool } description="True if the export is named, False if it is default."/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Renames a symbol and updates all its references in the codebase. - - - -str } - description="The new name for the symbol." - defaultValue="" -/> -int } - description="Priority of the edit operation. Defaults to 0." - defaultValue="0" -/> - - - -tuple[NodeId, NodeId] } description="A tuple containing the file node ID and the new node ID of the renamed symbol."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ Import | Symbol | TSExport ] } description="A list of symbols that use or import the exportable object."/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/core/ExportStatement.mdx b/docs/_deprecated/api-reference/core/ExportStatement.mdx deleted file mode 100644 index b05118b0c..000000000 --- a/docs/_deprecated/api-reference/core/ExportStatement.mdx +++ /dev/null @@ -1,433 +0,0 @@ ---- -title: "ExportStatement" -sidebarTitle: "ExportStatement" -icon: "" -description: "Abstract representation of a single export statement that appears in a file. One export statement can export multiple symbols from a single source." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### exports - -Collection[ TSExport , ExportStatement ] } description="A list of the individual exports this statement represents" /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### nested_code_blocks - -list[ Editable ] } description="Returns all nested code blocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ ExportStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### reexports - -list[ TSExport ] } description="Retrieves a list of re-exported symbols from this export statement." /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ ExportStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ ExportStatement ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ ExportStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/core/Exportable.mdx b/docs/_deprecated/api-reference/core/Exportable.mdx deleted file mode 100644 index 0e001c4df..000000000 --- a/docs/_deprecated/api-reference/core/Exportable.mdx +++ /dev/null @@ -1,577 +0,0 @@ ---- -title: "Exportable" -sidebarTitle: "Exportable" -icon: "" -description: "An interface for any node object that can be exported eg. Class, class name, top-level functions, imports" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Usable](/api-reference/core/Usable), [Importable](/api-reference/core/Importable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName), [Editable](/api-reference/core/Editable) - -## Attributes - -### export - -TSExport | None } description="Returns the export object that exports this symbol." /> - -### exported_name - -str | None } description="Retrieves the exported name of a symbol from its file." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### is_exported - -bool } description="Indicates if the symbol is exported from its defining file." /> - -### is_reexported - -bool } description="Determines if the symbol is re-exported from a different file." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ Symbol , Import ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ Exportable ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ Exportable ] } description=""/> - - -### get_import_string -Returns the import string for a symbol. - - - -str | None } - description="Optional alias for the symbol." - defaultValue="None" -/> -str | None } - description="Optional module name to import from." - defaultValue="None" -/> -ImportType } - description="Type of import to generate." - defaultValue="ImportType.UNKNOWN" -/> -bool } - description="Indicates if it's a type-only import." - defaultValue="False" -/> - - - -str } description="The formatted import string."/> - - -### get_name -Returns the name node of the object. - - - -Name | ChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ Exportable ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Renames a symbol and updates all its references in the codebase. - - - -str } - description="The new name for the symbol." - defaultValue="" -/> -int } - description="Priority of the edit operation. Defaults to 0." - defaultValue="0" -/> - - - -tuple[NodeId, NodeId] } description="A tuple containing the file node ID and the new node ID of the renamed symbol."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ Import | Symbol | TSExport ] } description="A list of symbols that use or import the exportable object."/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/core/Expression.mdx b/docs/_deprecated/api-reference/core/Expression.mdx deleted file mode 100644 index d9d3dc599..000000000 --- a/docs/_deprecated/api-reference/core/Expression.mdx +++ /dev/null @@ -1,413 +0,0 @@ ---- -title: "Expression" -sidebarTitle: "Expression" -icon: "" -description: "Represents an arbitrary Expression, such as List, Dict, Binary Expression, String." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ Expression ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ Expression ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ Expression ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/core/ExpressionGroup.mdx b/docs/_deprecated/api-reference/core/ExpressionGroup.mdx deleted file mode 100644 index f3f37763a..000000000 --- a/docs/_deprecated/api-reference/core/ExpressionGroup.mdx +++ /dev/null @@ -1,419 +0,0 @@ ---- -title: "ExpressionGroup" -sidebarTitle: "ExpressionGroup" -icon: "" -description: "Group of contiguous set of expressions." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[SymbolGroup](/api-reference/core/SymbolGroup), [Editable](/api-reference/core/Editable) - -## Attributes - -### expressions - -list[ Expression ] } description="Returns all expressions in the group." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns all function calls within the expression group." /> - -### next_named_sibling - -Editable | None } description="Returns the next named sibling of the last symbol in the group." /> - -### next_sibling - -Editable | None } description="Returns the next sibling of the last symbol in the symbol group." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### source - -str } description="Returns the source code of the symbol group." /> - -### symbols - -list[ Editable ] } description="Returns the list of symbols in the group." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this node with new text. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool, optional } - description="Adjusts the indentation of new_src to match the current text's indentation. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the edit operation. Higher priority edits take precedence. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Prevents duplicate edits at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Search for substrings in the given symbols that match `strings_to_match`. - - - -list[str] | str } - description="The string or list of strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes that exactly match the query." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable objects representing each match found."/> - - -### find_string_literals -Search for string literals matching given strings in the SymbolGroup. - - - -list[str] } - description="List of strings to search for in string literals." - defaultValue="" -/> -bool, optional } - description="If True, performs fuzzy matching instead of exact matching." - defaultValue="False" -/> - - - -list[ Editable ] } description="List of Editable nodes representing the matching string literals found within the symbols."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ ExpressionGroup ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ ExpressionGroup ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts source code after this node in the codebase. - - - -str } - description="The source code to insert." - defaultValue="" -/> -bool, optional } - description="Adjust indentation to match current text." - defaultValue="False" -/> -bool, optional } - description="Add a newline before the inserted code." - defaultValue="True" -/> -int, optional } - description="Priority of the edit operation." - defaultValue="0" -/> -bool, optional } - description="Deduplicate identical edits." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts source code before this symbol group. - - - -str } - description="The source code to insert." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of the inserted code to match the current code. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline after the inserted code. Defaults to True." - defaultValue="True" -/> -int, optional } - description="The priority of this edit operation. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to prevent duplicate insertions of the same code. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Removes this node and its related extended nodes from the codebase. - - - -bool, optional } - description="Whether to delete related extended nodes like decorators and comments. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority level of the removal operation. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate removal operations. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Replaces all instances of a string with a new string in all symbols within the group. - - - -str } - description="The string to be replaced." - defaultValue="" -/> -str } - description="The string to replace with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="Number of replacements made."/> - - -### search -Searches for regex matches in the codebase. - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool, optional } - description="Whether to include string literals in the search. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to include comments in the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects representing matched text nodes in the codebase."/> - - - diff --git a/docs/_deprecated/api-reference/core/ExpressionStatement.mdx b/docs/_deprecated/api-reference/core/ExpressionStatement.mdx deleted file mode 100644 index 5a326e433..000000000 --- a/docs/_deprecated/api-reference/core/ExpressionStatement.mdx +++ /dev/null @@ -1,454 +0,0 @@ ---- -title: "ExpressionStatement" -sidebarTitle: "ExpressionStatement" -icon: "" -description: "Abstract representation of any expression statements that resolves to an expression. In some languages without a statement delimiter, expression statement and the enclosed expression looks the same in text. For example, in Python: ```python x = 1 ``` The above code is an expression statement, but its expression value is an assignment. In Typescript: ```typescript x = 1; ``` The above code is also an expression statement, but its expression value is an assignment excluding the semicolon." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[HasValue](/api-reference/core/HasValue), [Statement](/api-reference/core/Statement), [Editable](/api-reference/core/Editable), [Expression](/api-reference/core/Expression) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Get all function calls contained within this expression statement." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### nested_code_blocks - -list[ Editable ] } description="Returns all nested code blocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ ExpressionStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### value - -Expression | None } description="Gets the value node of the object." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ ExpressionStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ ExpressionStatement ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ ExpressionStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### resolve -Resolves the wrapper expression and returns the first concrete expression. - - - -Expression } description=""/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_value -Sets the value of the node's value Expression. - - - -str } - description="The new value to set." - defaultValue="" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/core/ExternalModule.mdx b/docs/_deprecated/api-reference/core/ExternalModule.mdx deleted file mode 100644 index 69fba4120..000000000 --- a/docs/_deprecated/api-reference/core/ExternalModule.mdx +++ /dev/null @@ -1,641 +0,0 @@ ---- -title: "ExternalModule" -sidebarTitle: "ExternalModule" -icon: "" -description: "Represents an external module, like `datetime`, that can be referenced. These are only added to the graph during import resolution and will not exist in a local file's subgraph. This is because we don't know what an import is referencing or resolves to until we see the full codebase." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Callable](/api-reference/core/Callable), [Usable](/api-reference/core/Usable), [Importable](/api-reference/core/Importable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName), [Editable](/api-reference/core/Editable) - -## Attributes - -### call_sites - -list[ FunctionCall ] } description="Returns all call sites (invocations) of this callable in the codebase." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -None } description="File property for ExternalModule class." /> - -### filepath - -str } description="Returns the filepath of the module." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parameters - -list[ Parameter ] } description="Returns list of named parameters from an external function symbol." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### return_type - -Type | Placeholder [ ExternalModule ] } description="The type of value returned by the callable, or a placeholder." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ Symbol , Import ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ ExternalModule ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ ExternalModule ] } description=""/> - - -### from_import -Creates an ExternalModule instance from an Import instance. - - - -Import } - description="An Import instance containing the module information." - defaultValue="" -/> - - - -ExternalModule } description="A new ExternalModule instance representing the external module."/> - - -### get_import_string -Returns the import string used to import this module. - - - -str | None, optional } - description="An alternative name for the imported module." - defaultValue="None" -/> -str | None, optional } - description="The module from which to import." - defaultValue="None" -/> -ImportType , optional } - description="The type of import to generate. Defaults to ImportType.UNKNOWN." - defaultValue="ImportType.UNKNOWN" -/> -bool, optional } - description="Whether this is a type import. Defaults to False." - defaultValue="False" -/> - - - -str } description="The import string that can be used to import this module."/> - - -### get_name -Returns the name node of the object. - - - -Name | ChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_parameter -Gets a specific parameter from the callable's parameters list by name. - - - -str } - description="The name of the parameter to retrieve." - defaultValue="" -/> - - - -Parameter | None } description="The parameter with the specified name, or None if no parameter with that name exists or if there are no parameters."/> - - -### get_parameter_by_index -Returns the parameter at the given index. - - - -int } - description="The index of the parameter to retrieve." - defaultValue="" -/> - - - -Parameter | None } description="The parameter at the specified index, or None if the parameter list is empty or the index does not exist."/> - - -### get_parameter_by_type -Retrieves a parameter from the callable by its type. - - - -Symbol } - description="The type to search for." - defaultValue="" -/> - - - -Parameter | None } description="The parameter with the specified type, or None if no parameter is found or if the callable has no parameters."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ ExternalModule ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Renames a symbol and updates all its references in the codebase. - - - -str } - description="The new name for the symbol." - defaultValue="" -/> -int } - description="Priority of the edit operation. Defaults to 0." - defaultValue="0" -/> - - - -tuple[NodeId, NodeId] } description="A tuple containing the file node ID and the new node ID of the renamed symbol."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ Import | Symbol | TSExport ] } description="A list of symbols that use or import the exportable object."/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/core/File.mdx b/docs/_deprecated/api-reference/core/File.mdx deleted file mode 100644 index 5c05e52b7..000000000 --- a/docs/_deprecated/api-reference/core/File.mdx +++ /dev/null @@ -1,475 +0,0 @@ ---- -title: "File" -sidebarTitle: "File" -icon: "" -description: "Represents a generic file. Could represent a source file or a non-code file such as a markdown file or image file." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Editable](/api-reference/core/Editable) - -## Attributes - -### content - -str } description="Returns the content of the file as a UTF-8 encoded string." /> - -### directory - -Directory | None } description="Returns the directory that contains this file." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### extension - -str } description="Returns the file extension." /> - -### file - -File } description="A property that returns the file object for non-source files." /> - -### file_path - -str } description="The relative file path as a string." /> - -### filepath - -str } description="Retrieves the file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### is_binary - -bool } description="Indicates whether the file contains binary data." /> - -### name - -str } description="The name of the file." /> - -### owners - -set[str] } description="Returns the CODEOWNERS of the file." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### path - -Path } description="The absolute path of the file as a Path object." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### start_byte - -int } description="Returns the starting byte position of a file in its content." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this file with new_src. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of new_src to match the current" - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are" - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ File ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ File ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ File ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parse -Parses the file representation into the graph. - - - -CodebaseContext } - description="The codebase context that the file belongs to." - defaultValue="" -/> - - - -None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Removes the file from the file system and graph. - - - -None } description=""/> - - -### rename -Renames the file to the specified name, preserving the file extension. - - - -str } - description="The new name for the file. If the new name includes the file extension, it will be used as-is." - defaultValue="" -/> - - - -None } description=""/> - - -### replace -Replace occurrences of text in the file. - - - -str } - description="The text to be replaced." - defaultValue="" -/> -str } - description="The text to replace with." - defaultValue="" -/> -int } - description="Maximum number of replacements to make. -1 means replace all occurrences." - defaultValue="-1" -/> -bool } - description="If True, treat 'old' as a regular expression pattern." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are" - defaultValue="0" -/> - - - -int } description="List of affected Editable objects. For non-source files, always returns an empty list since they don't have Editable sub-components."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### update_filepath -Updates the file path and inbound imports of a file. - - - -str } - description="The new file path to rename the file to." - defaultValue="" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/core/FlagKwargs.mdx b/docs/_deprecated/api-reference/core/FlagKwargs.mdx deleted file mode 100644 index 7bdc07278..000000000 --- a/docs/_deprecated/api-reference/core/FlagKwargs.mdx +++ /dev/null @@ -1,32 +0,0 @@ ---- -title: "FlagKwargs" -sidebarTitle: "FlagKwargs" -icon: "" -description: "Kwargs for the flag_instance method of the Codebase class." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - - -## Attributes - -### message - -ReadOnly[str | None] } description="The message to be displayed in the diff preview or posted as a comment on the PR." /> - -### message_recipient - -ReadOnly[str | None] } description="The recipient of the message." /> - -### message_type - -ReadOnly[ MessageType ] } description="Where the message will be sent (CODEGEN, GITHUB, SLACK)" /> - - - diff --git a/docs/_deprecated/api-reference/core/ForLoopStatement.mdx b/docs/_deprecated/api-reference/core/ForLoopStatement.mdx deleted file mode 100644 index 307080414..000000000 --- a/docs/_deprecated/api-reference/core/ForLoopStatement.mdx +++ /dev/null @@ -1,489 +0,0 @@ ---- -title: "ForLoopStatement" -sidebarTitle: "ForLoopStatement" -icon: "" -description: "Abstract representation of the for loop." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[HasBlock](/api-reference/core/HasBlock), [BlockStatement](/api-reference/core/BlockStatement), [Expression](/api-reference/core/Expression), [Statement](/api-reference/core/Statement), [Editable](/api-reference/core/Editable) - -## Attributes - -### code_block - -CodeBlock } description="The block of code associated with the code object." /> - -### decorators - -list[ Decorator ] } description="Returns list of all decorators on this Symbol." /> - -### docstring - -CommentGroup | None } description="Retrieves the docstring of the expression." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns all function calls within the code block and its decorators." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### is_decorated - -bool } description="Check if the symbol has decorators." /> - -### item - -Expression [ ForLoopStatement ] | None } description="The item being iterated over, if applicable." /> - -### iterable - -Expression [ ForLoopStatement ] } description="The iterable expression that the loop iterates over." /> - -### nested_code_blocks - -list[ CodeBlock ] } description="Returns all nested CodeBlocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ ForLoopStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ ForLoopStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ ForLoopStatement ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ ForLoopStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_docstring -Sets or updates the docstring for the current entity. - - - -str } - description="The new docstring content to set." - defaultValue="" -/> - - - -None } description="This method doesn't return anything."/> - - - diff --git a/docs/_deprecated/api-reference/core/Function.mdx b/docs/_deprecated/api-reference/core/Function.mdx deleted file mode 100644 index bd9ca4b79..000000000 --- a/docs/_deprecated/api-reference/core/Function.mdx +++ /dev/null @@ -1,923 +0,0 @@ ---- -title: "Function" -sidebarTitle: "Function" -icon: "" -description: "Abstract representation of a Function." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[HasBlock](/api-reference/core/HasBlock), [Callable](/api-reference/core/Callable), [Symbol](/api-reference/core/Symbol), [Editable](/api-reference/core/Editable), [Expression](/api-reference/core/Expression), [Usable](/api-reference/core/Usable), [Importable](/api-reference/core/Importable), [HasName](/api-reference/core/HasName) - -## Attributes - -### call_sites - -list[ FunctionCall ] } description="Returns all call sites (invocations) of this callable in the codebase." /> - -### code_block - -CodeBlock } description="The block of code associated with the code object." /> - -### comment - -CommentGroup | None } description="Returns the comment group associated with the symbol, if any." /> - -### decorators - -list[ Decorator ] } description="Returns list of all decorators on this Symbol." /> - -### docstring - -CommentGroup | None } description="Retrieves the docstring of the expression." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_nodes - -list[ Editable ] } description="Returns a list of Editable nodes associated with this symbol, including extended symbols." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Gets all function calls within the function and its parameters." /> - -### function_signature - -str } description="Returns the signature of the function as a string." /> - -### inferred_return_type - -str | None } description="Gets the inferred type of the function from the language's native language engine / compiler." /> - -### inline_comment - -CommentGroup | None } description="Returns the inline comment group associated with the symbol, if any." /> - -### is_async - -bool } description="Returns True if the function is asynchronous." /> - -### is_constructor - -bool } description="Determines if the current function is a constructor method." /> - -### is_decorated - -bool } description="Check if the symbol has decorators." /> - -### is_magic - -bool } description="Returns True if function is a magic method." /> - -### is_method - -bool } description="Returns whether the function is a method of a class." /> - -### is_overload - -bool } description="Indicates whether the function is an overloaded function in a multi-function definition." /> - -### is_private - -bool } description="Determines if a function has a private access modifier." /> - -### is_property - -bool } description="Returns whether this function is a property." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### nested_functions - -list[ Function ] } description="Returns a list of nested functions defined within this function's code block." /> - -### parameters - -SymbolGroup [ Parameter , Function ] | list[ Parameter ] } description="Retrieves all parameters of a callable symbol." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### return_statements - -list[ ReturnStatement ] } description="Returns a list of all return statements within this function's body." /> - -### return_type - -Type | Placeholder [ Function ] } description="The type of value returned by the callable, or a placeholder." /> - -### source - -str } description="Returns the source code of the symbol." /> - -### symbol_type - - } description="The type of symbol, set to SymbolType.Function." /> - -### type_parameters - -TypeParameters[ Type , Function ] | None } description="The type parameters of the symbol, if any." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_comment -Adds a comment to the symbol. - - - -str } - description="The comment text to add." - defaultValue="" -/> - - - -None } description=""/> - - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### add_keyword -Insert a keyword in the appropriate place before this symbol if it doesn't already exist. - - - -str } - description="The keyword to be inserted. Must be a valid keyword in the language context." - defaultValue="" -/> - - - -None } description=""/> - - -### add_statements -Adds statements to the end of a function body. - - - -str } - description="The lines of code to be added at the end of the function body." - defaultValue="" -/> - - - -None } description=""/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### asyncify -Modifies the function to be asynchronous. - - - -None } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ Symbol , Import ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this node with new_src. - - - -str } - description="The new source code to replace the current source with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, prevents duplicate edits. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ Function ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ Function ] } description=""/> - - -### get_name -Returns the name node of the object. - - - -Name | ChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_parameter -Gets a specific parameter from the callable's parameters list by name. - - - -str } - description="The name of the parameter to retrieve." - defaultValue="" -/> - - - -Parameter | None } description="The parameter with the specified name, or None if no parameter with that name exists or if there are no parameters."/> - - -### get_parameter_by_index -Returns the parameter at the given index. - - - -int } - description="The index of the parameter to retrieve." - defaultValue="" -/> - - - -Parameter | None } description="The parameter at the specified index, or None if the parameter list is empty or the index does not exist."/> - - -### get_parameter_by_type -Retrieves a parameter from the callable by its type. - - - -Symbol } - description="The type to search for." - defaultValue="" -/> - - - -Parameter | None } description="The parameter with the specified type, or None if no parameter is found or if the callable has no parameters."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ Function ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before the current symbol node in the Abstract Syntax Tree. - - - -str } - description="The source code text to insert." - defaultValue="" -/> -bool } - description="Whether to adjust the indentation of new_src to match current text. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after insertion. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to remove duplicate insertions. Defaults to True." - defaultValue="True" -/> -bool } - description="Whether to insert before extended nodes like comments and decorators. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_statements -Inserts lines of code into the function body at the specified index. - - - -str } - description="The code lines to insert into the function body." - defaultValue="" -/> -int, optional } - description="The position in the function body where the lines should be inserted. Defaults to 0." - defaultValue="0" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### move_to_file -Moves the given symbol to a new file and updates its imports and references. - - - -SourceFile } - description="The destination file to move the symbol to." - defaultValue="" -/> -bool } - description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." - defaultValue="True" -/> -str } - description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." - defaultValue=""update_all_imports"" -/> - - - -None } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### prepend_statements -Prepends the provided code to the beginning of the function body. - - - -str } - description="The code to be prepended to the function body." - defaultValue="" -/> - - - -None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Renames a symbol and updates all its references in the codebase. - - - -str } - description="The new name for the symbol." - defaultValue="" -/> -int } - description="Priority of the edit operation. Defaults to 0." - defaultValue="0" -/> - - - -tuple[NodeId, NodeId] } description="A tuple containing the file node ID and the new node ID of the renamed symbol."/> - - -### rename_local_variable -Renames a local variable and all its usages within a function body. - - - -str } - description="The current name of the local variable to be renamed." - defaultValue="" -/> -str } - description="The new name to give to the local variable." - defaultValue="" -/> -bool, optional } - description="If True, matches variable names that contain old_var_name. Defaults to False." - defaultValue="False" -/> - - - -None } description="The method modifies the AST in place."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_comment -Sets a comment to the symbol. - - - -str } - description="The comment text to set." - defaultValue="" -/> - - - -None } description=""/> - - -### set_docstring -Sets or updates the docstring for the current entity. - - - -str } - description="The new docstring content to set." - defaultValue="" -/> - - - -None } description="This method doesn't return anything."/> - - -### set_inline_comment -Sets an inline comment to the symbol. - - - -str } - description="The text of the inline comment to be added or updated." - defaultValue="" -/> - - - -None } description=""/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### set_return_type -Sets the return type annotation for the function. - - - -str } - description="The new return type annotation to be set. Use an empty string to remove" - defaultValue="" -/> - - - -None } description=""/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ Import | Symbol | TSExport ] } description="A list of symbols that use or import the exportable object."/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/core/FunctionCall.mdx b/docs/_deprecated/api-reference/core/FunctionCall.mdx deleted file mode 100644 index 1ad0dc975..000000000 --- a/docs/_deprecated/api-reference/core/FunctionCall.mdx +++ /dev/null @@ -1,620 +0,0 @@ ---- -title: "FunctionCall" -sidebarTitle: "FunctionCall" -icon: "" -description: "Abstract representation of a function invocation, e.g. in Python: ``` def f(): g() # FunctionCall ```" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName), [Editable](/api-reference/core/Editable) - -## Attributes - -### args - -Collection[ Argument , FunctionCall ] } description="Returns a list of arguments passed into the function invocation." /> - -### attribute_chain - -list[ FunctionCall | Name ] } description="Returns a list of elements in the chainedAttribute that the function call belongs in." /> - -### base - -Editable | None } description="Returns the base object of this function call chain." /> - -### call_chain - -list[ FunctionCall ] } description="Returns a list of all function calls in this function call chain, including this call. Does not include calls made after this one." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this function call." /> - -### function_definition - -Callable | None } description="Returns the resolved function definition that is being called." /> - -### function_definitions - -list[ Callable ] } description="Returns a list of callable objects that could potentially be the target of this function" /> - -### is_awaited - -bool } description="Determine if this function call is ultimately awaited in the TypeScript AST." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Retrieves the parent function of the current function call." /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### predecessor - -FunctionCall [ Editable ] | None } description="Returns the previous function call in a function call chain." /> - -### promise_chain - -TSPromiseChain | None } description="Return the promise chain associated with this function call, if a then call is found." /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Gets the source code representation of this FunctionCall." /> - -### successor - -FunctionCall [ Editable ] | None } description="Returns the next function call in a function call chain." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### asyncify -Converts the function call to an async function call by wrapping it with 'await'. - - - -None } description=""/> - - -### convert_args_to_kwargs -Converts positional arguments in a function call to keyword arguments. - - - -int } - description="Number of leading positional arguments to exclude from conversion. Defaults to 0." - defaultValue="0" -/> - - - -None } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ FunctionCall ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ FunctionCall ] } description=""/> - - -### from_usage -Creates a FunctionCall object from an Editable instance that represents a function call. - - - -Editable [ Editable ] } - description="The Editable node that potentially represents a function call." - defaultValue="" -/> -Editable | None } - description="The parent node for the new FunctionCall. If None, uses the parent from the input node." - defaultValue="None" -/> - - - -FunctionCall | None } description="A new FunctionCall object if the input node represents a function call, None otherwise."/> - - -### get_arg_by_index -Returns the Argument with the given index from the function call's argument list. - - - -int } - description="The index of the argument to retrieve." - defaultValue="" -/> - - - -Argument | None } description="The Argument object at the specified index, or None if the index is out of bounds."/> - - -### get_arg_by_parameter_name -Returns an argument by its parameter name. - - - -str } - description="The name of the parameter to search for." - defaultValue="" -/> - - - -Argument | None } description="The matching argument if found, None otherwise."/> - - -### get_name -Returns the name node of the object. - - - -Name | ChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ FunctionCall ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Removes a node and optionally its related extended nodes. - - - -bool, optional } - description="Whether to delete associated formatting nodes. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority level for the removal operation. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical removals. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Sets the name of an object and updates all its usages. - - - -str } - description="The new name to assign to the object." - defaultValue="" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_kwarg -Set a keyword argument in a function call. - - - -str } - description="The name of the parameter/argument to set." - defaultValue="" -/> -str } - description="The value to set the argument to." - defaultValue="" -/> -bool, optional } - description="If True, creates a new keyword argument if it doesn't exist. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="If True, modifies the value of existing argument. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/core/GenericType.mdx b/docs/_deprecated/api-reference/core/GenericType.mdx deleted file mode 100644 index c7e1cd50e..000000000 --- a/docs/_deprecated/api-reference/core/GenericType.mdx +++ /dev/null @@ -1,467 +0,0 @@ ---- -title: "GenericType" -sidebarTitle: "GenericType" -icon: "" -description: "Abstract representation of the generic types of the programming language." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[NamedType](/api-reference/core/NamedType), [HasName](/api-reference/core/HasName), [Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parameters - -Collection[ Type , GenericType ] } description="Retrieves the generic type parameters associated with this type." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ GenericType ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ GenericType ] } description=""/> - - -### get_name -Returns the name node of the object. - - - -Name | ChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ GenericType ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Sets the name of an object and updates all its usages. - - - -str } - description="The new name to assign to the object." - defaultValue="" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/core/HasBlock.mdx b/docs/_deprecated/api-reference/core/HasBlock.mdx deleted file mode 100644 index ec8d86d46..000000000 --- a/docs/_deprecated/api-reference/core/HasBlock.mdx +++ /dev/null @@ -1,469 +0,0 @@ ---- -title: "HasBlock" -sidebarTitle: "HasBlock" -icon: "" -description: "An interface for any code object that has a block of code, e.g. a function, class, etc." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### code_block - -CodeBlock } description="The block of code associated with the code object." /> - -### decorators - -list[ Decorator ] } description="Returns list of all decorators on this Symbol." /> - -### docstring - -CommentGroup | None } description="Retrieves the docstring of the expression." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns all function calls within the code block and its decorators." /> - -### is_decorated - -bool } description="Check if the symbol has decorators." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ HasBlock ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ HasBlock ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ HasBlock ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_docstring -Sets or updates the docstring for the current entity. - - - -str } - description="The new docstring content to set." - defaultValue="" -/> - - - -None } description="This method doesn't return anything."/> - - - diff --git a/docs/_deprecated/api-reference/core/HasName.mdx b/docs/_deprecated/api-reference/core/HasName.mdx deleted file mode 100644 index fafe35431..000000000 --- a/docs/_deprecated/api-reference/core/HasName.mdx +++ /dev/null @@ -1,72 +0,0 @@ ---- -title: "HasName" -sidebarTitle: "HasName" -icon: "" -description: "An interface for any node object that has a name." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - - -## Attributes - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - - -## Methods - -### get_name -Returns the name node of the object. - - - -Name | ChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### rename -Sets the name of an object and updates all its usages. - - - -str } - description="The new name to assign to the object." - defaultValue="" -/> - - - -None } description=""/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/core/HasValue.mdx b/docs/_deprecated/api-reference/core/HasValue.mdx deleted file mode 100644 index 07428e937..000000000 --- a/docs/_deprecated/api-reference/core/HasValue.mdx +++ /dev/null @@ -1,43 +0,0 @@ ---- -title: "HasValue" -sidebarTitle: "HasValue" -icon: "" -description: "An interface for any node object that has a value." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - - -## Attributes - -### value - -Expression | None } description="Gets the value node of the object." /> - - -## Methods - -### set_value -Sets the value of the node's value Expression. - - - -str } - description="The new value to set." - defaultValue="" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/core/IfBlockStatement.mdx b/docs/_deprecated/api-reference/core/IfBlockStatement.mdx deleted file mode 100644 index e575ed670..000000000 --- a/docs/_deprecated/api-reference/core/IfBlockStatement.mdx +++ /dev/null @@ -1,470 +0,0 @@ ---- -title: "IfBlockStatement" -sidebarTitle: "IfBlockStatement" -icon: "" -description: "Abstract representation of the if/elif/else if/else statement block. For example, if there is a code block like: if condition1: block1 elif condition2: block2 else: block3 This class represents the entire block, including the conditions and nested code blocks." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### alternative_blocks - -list[ IfBlockStatement ] } description="Returns a list of alternative if/elif/else blocks for the current block." /> - -### condition - -Expression [ IfBlockStatement ] | None } description="The condition expression for the if block. None if the block is an else block." /> - -### consequence_block - -CodeBlock } description="The code block that is executed if the condition is True." /> - -### else_statement - -IfBlockStatement | None } description="Returns the else block within the if-statement." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns all function calls within the if block statement and its alternative blocks." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### is_elif_statement - -bool } description="Indicates whether the current block is an elif block." /> - -### is_else_statement - -bool } description="Indicates if the current block is an else block in an if/else statement chain." /> - -### is_if_statement - -bool } description="Returns whether the current block is an if block." /> - -### nested_code_blocks - -list[ CodeBlock ] } description="Returns all nested code blocks within an if/elif/else statement block." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ IfBlockStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### elif_statements -Returns all elif blocks within the if block. - - - -list[ IfBlockStatement ] } description="A list of elif block statements. Empty list if no elif blocks exist."/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ IfBlockStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ IfBlockStatement ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ IfBlockStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Simplifies a conditional block by reducing its condition to a boolean value. - - - -bool } - description="The boolean value to reduce the condition to." - defaultValue="" -/> - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/core/Import.mdx b/docs/_deprecated/api-reference/core/Import.mdx deleted file mode 100644 index f1c300fc8..000000000 --- a/docs/_deprecated/api-reference/core/Import.mdx +++ /dev/null @@ -1,656 +0,0 @@ ---- -title: "Import" -sidebarTitle: "Import" -icon: "" -description: "Represents a single symbol being imported." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Usable](/api-reference/core/Usable), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName) - -## Attributes - -### alias - -Editable | None } description="The alias of the imported symbol, if one exists." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### from_file - -SourceFile | None } description="Returns the SourceFile that an Import is importing from." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### import_specifier - -Editable } description="Returns the specific editable text representation of the import identifier within the" /> - -### import_statement - -ImportStatement } description="The statement that this import is part of." /> - -### import_type - -ImportType } description="The type of import, indicating how the symbol is imported." /> - -### imported_exports - -list[ Exportable ] } description="Returns the enumerated list of symbols imported from a module import." /> - -### imported_symbol - -Symbol | ExternalModule | SourceFile | Import | None } description="Returns the symbol directly being imported, including an indirect import and an External" /> - -### is_dynamic - -bool } description="Determines if this import is dynamically loaded based on its parent symbol." /> - -### module - -Editable | None } description="The module from which the symbol is being imported, if applicable." /> - -### name - -str | None } description="Returns the name or alias of the symbol being imported." /> - -### namespace - -str | None } description="Returns the namespace prefix that must be used with dot notation to reference the" /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_symbol - -Symbol | ExternalModule | SourceFile | None } description="Returns the symbol, source file, or external module that this import ultimately resolves" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### symbol_name - -Editable | None } description="The name of the symbol being imported. For instance import a as b has a symbol_name of a." /> - -### to_file - -SourceFile } description="SourceFile that this import resides in." /> - -### to_file_id - -NodeId } description="The node ID of the file to which this import belongs." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ Symbol , Import ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ Import ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ Import ] } description=""/> - - -### get_name -Returns the name node of the object. - - - -Name | ChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ Import ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_aliased_import -Returns True if this import is aliased. - - - -bool } description="True if the import has an alias different from its original name, False otherwise."/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_module_import -Returns True if this import is importing an entire module/file. - - - -bool } description="True if this import represents a module/file import, False if it represents a symbol import."/> - - -### is_reexport -Returns true if the Import object is also an Export object. - - - -bool } description="True if the import is re-exported, False otherwise."/> - - -### is_symbol_import -Returns True if this import is importing a symbol rather than a module. - - - -bool } description="True if this import is a symbol import, False if it is a module import."/> - - -### is_wildcard_import -Returns True if the import symbol is a wildcard import. - - - -bool } description="True if this is a wildcard import, False otherwise."/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Remove this import from the import statement. - - - -bool, optional } - description="Whether to delete any associated formatting. Defaults to True." - defaultValue="True" -/> -int, optional } - description="The priority of the operation. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate imports. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Renames the import symbol and updates all its usages throughout the codebase. - - - -str } - description="The new name to give the imported symbol." - defaultValue="" -/> -int, optional } - description="Priority of the rename operation. Defaults to 0." - defaultValue="0" -/> - - - -tuple[NodeId, NodeId] } description="A tuple containing (file_node_id, new_import_node_id)."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_import_module -Sets the module of an import. - - - -str } - description="The new module path to import from." - defaultValue="" -/> - - - -None } description=""/> - - -### set_import_symbol_alias -Sets alias or name of an import at the declaration level. - - - -str } - description="The new name to use for the imported symbol." - defaultValue="" -/> - - - -None } description=""/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ Import | Symbol | TSExport ] } description="A list of symbols that use or import the exportable object."/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/core/ImportStatement.mdx b/docs/_deprecated/api-reference/core/ImportStatement.mdx deleted file mode 100644 index f2976d5ed..000000000 --- a/docs/_deprecated/api-reference/core/ImportStatement.mdx +++ /dev/null @@ -1,429 +0,0 @@ ---- -title: "ImportStatement" -sidebarTitle: "ImportStatement" -icon: "" -description: "Abstract representation of a single import statement that appears in a file. One import statement can import multiple symbols from a single source." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### imports - -Collection[ Import , ImportStatement ] } description="A collection of the individual imports this statement represents" /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### nested_code_blocks - -list[ Editable ] } description="Returns all nested code blocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ ImportStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ ImportStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ ImportStatement ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ ImportStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/core/ImportType.mdx b/docs/_deprecated/api-reference/core/ImportType.mdx deleted file mode 100644 index dd302f974..000000000 --- a/docs/_deprecated/api-reference/core/ImportType.mdx +++ /dev/null @@ -1,44 +0,0 @@ ---- -title: "ImportType" -sidebarTitle: "ImportType" -icon: "" -description: "Import types for each import object. Determines what the import resolves to, and what symbols are imported." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - - -## Attributes - -### DEFAULT_EXPORT - - } description="Imports all default exports. Resolves to the file." /> - -### MODULE - - } description="Imports the module, not doesn't actually allow access to any of the exports" /> - -### NAMED_EXPORT - - } description="Imports a named export. Resolves to the symbol export." /> - -### SIDE_EFFECT - - } description="Imports the module, not doesn't actually allow access to any of the exports" /> - -### UNKNOWN - - } description="Unknown import type." /> - -### WILDCARD - - } description="Imports all named exports, and default exports as `default`. Resolves to the file." /> - - - diff --git a/docs/_deprecated/api-reference/core/Importable.mdx b/docs/_deprecated/api-reference/core/Importable.mdx deleted file mode 100644 index f3b636a9f..000000000 --- a/docs/_deprecated/api-reference/core/Importable.mdx +++ /dev/null @@ -1,486 +0,0 @@ ---- -title: "Importable" -sidebarTitle: "Importable" -icon: "" -description: "An interface for any node object that can import (or reference) an exportable symbol eg. All nodes that are on the graph must inherit from here Class, function, imports, exports, etc." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ Symbol , Import ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ Importable ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ Importable ] } description=""/> - - -### get_name -Returns the name node of the object. - - - -Name | ChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ Importable ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Sets the name of an object and updates all its usages. - - - -str } - description="The new name to assign to the object." - defaultValue="" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/core/Interface.mdx b/docs/_deprecated/api-reference/core/Interface.mdx deleted file mode 100644 index 29df4cbc6..000000000 --- a/docs/_deprecated/api-reference/core/Interface.mdx +++ /dev/null @@ -1,737 +0,0 @@ ---- -title: "Interface" -sidebarTitle: "Interface" -icon: "" -description: "Abstract representation of an Interface class." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[HasBlock](/api-reference/core/HasBlock), [Expression](/api-reference/core/Expression), [Symbol](/api-reference/core/Symbol), [Editable](/api-reference/core/Editable), [Usable](/api-reference/core/Usable), [Importable](/api-reference/core/Importable), [HasName](/api-reference/core/HasName) - -## Attributes - -### attributes - -list[ Attribute ] } description="List of attributes defined in this Interface." /> - -### code_block - -CodeBlock } description="The block of code associated with the code object." /> - -### comment - -CommentGroup | None } description="Returns the comment group associated with the symbol, if any." /> - -### decorators - -list[ Decorator ] } description="Returns list of all decorators on this Symbol." /> - -### docstring - -CommentGroup | None } description="Retrieves the docstring of the expression." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_nodes - -list[ Editable ] } description="Returns a list of Editable nodes associated with this symbol, including extended symbols." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns all function calls within the code block and its decorators." /> - -### inline_comment - -CommentGroup | None } description="Returns the inline comment group associated with the symbol, if any." /> - -### is_decorated - -bool } description="Check if the symbol has decorators." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_interfaces - -Parents[ Type , Interface ] | None } description="All the interfaces that this interface extends." /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Returns the source code of the symbol." /> - -### symbol_type - - } description="The type of the symbol." /> - -### type_parameters - -TypeParameters[ Type , Interface ] | None } description="The type parameters of the symbol, if any." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_comment -Adds a comment to the symbol. - - - -str } - description="The comment text to add." - defaultValue="" -/> - - - -None } description=""/> - - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### add_keyword -Insert a keyword in the appropriate place before this symbol if it doesn't already exist. - - - -str } - description="The keyword to be inserted. Must be a valid keyword in the language context." - defaultValue="" -/> - - - -None } description=""/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ Symbol , Import ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this node with new_src. - - - -str } - description="The new source code to replace the current source with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, prevents duplicate edits. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### extends -Returns True if the interface implements the given parent interface. - - - -bool } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ Interface ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ Interface ] } description=""/> - - -### get_attribute -Returns the attribute with the given name, if it exists. - - - -Attribute | None } description=""/> - - -### get_name -Returns the name node of the object. - - - -Name | ChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ Interface ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### implementations -Returns all classes and interfaces that implement a given interface. - - - -list[ TSInterface | Class ] } description=""/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before the current symbol node in the Abstract Syntax Tree. - - - -str } - description="The source code text to insert." - defaultValue="" -/> -bool } - description="Whether to adjust the indentation of new_src to match current text. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after insertion. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to remove duplicate insertions. Defaults to True." - defaultValue="True" -/> -bool } - description="Whether to insert before extended nodes like comments and decorators. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### move_to_file -Moves the given symbol to a new file and updates its imports and references. - - - -SourceFile } - description="The destination file to move the symbol to." - defaultValue="" -/> -bool } - description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." - defaultValue="True" -/> -str } - description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." - defaultValue=""update_all_imports"" -/> - - - -None } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Renames a symbol and updates all its references in the codebase. - - - -str } - description="The new name for the symbol." - defaultValue="" -/> -int } - description="Priority of the edit operation. Defaults to 0." - defaultValue="0" -/> - - - -tuple[NodeId, NodeId] } description="A tuple containing the file node ID and the new node ID of the renamed symbol."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_comment -Sets a comment to the symbol. - - - -str } - description="The comment text to set." - defaultValue="" -/> - - - -None } description=""/> - - -### set_docstring -Sets or updates the docstring for the current entity. - - - -str } - description="The new docstring content to set." - defaultValue="" -/> - - - -None } description="This method doesn't return anything."/> - - -### set_inline_comment -Sets an inline comment to the symbol. - - - -str } - description="The text of the inline comment to be added or updated." - defaultValue="" -/> - - - -None } description=""/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ Import | Symbol | TSExport ] } description="A list of symbols that use or import the exportable object."/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/core/List.mdx b/docs/_deprecated/api-reference/core/List.mdx deleted file mode 100644 index 1a55e3b5a..000000000 --- a/docs/_deprecated/api-reference/core/List.mdx +++ /dev/null @@ -1,394 +0,0 @@ ---- -title: "List" -sidebarTitle: "List" -icon: "" -description: "A list object. You can use standard operations to operate on this list (IE len, del, append, insert, etc)" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable), [SymbolGroup](/api-reference/core/SymbolGroup) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Get the source code content of the node." /> - -### symbols - -list[ Editable ] } description="Returns the list of symbols in the group." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Edit the source for this Collection instance. - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ List ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ List ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ List ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### index -Return the index of the first occurrence of value. - - - -int } description=""/> - - -### insert -Adds `value` to the container that this node represents - - - -None } description=""/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Removes an element from a Collection. - - - -Editable | None } - description="The element to remove from the Collection. If None, delegates to parent class." - defaultValue="None" -/> - - - -None } description="This method doesn't return anything."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/core/MessageType.mdx b/docs/_deprecated/api-reference/core/MessageType.mdx deleted file mode 100644 index e6664f13a..000000000 --- a/docs/_deprecated/api-reference/core/MessageType.mdx +++ /dev/null @@ -1,32 +0,0 @@ ---- -title: "MessageType" -sidebarTitle: "MessageType" -icon: "" -description: "Destination of the message" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - - -## Attributes - -### CODEGEN - - } description="Rendered in the diff preview" /> - -### GITHUB - - } description="Posted as a comment on the PR" /> - -### SLACK - - } description="Sent over slack" /> - - - diff --git a/docs/_deprecated/api-reference/core/MultiExpression.mdx b/docs/_deprecated/api-reference/core/MultiExpression.mdx deleted file mode 100644 index 57c1e1294..000000000 --- a/docs/_deprecated/api-reference/core/MultiExpression.mdx +++ /dev/null @@ -1,417 +0,0 @@ ---- -title: "MultiExpression" -sidebarTitle: "MultiExpression" -icon: "" -description: "Represents an group of Expressions, such as List, Dict, Binary Expression, String." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### expressions - -list[ Expression ] } description="A list of expressions contained within the MultiExpression." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ MultiExpression ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ MultiExpression ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ MultiExpression ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/core/MultiLineCollection.mdx b/docs/_deprecated/api-reference/core/MultiLineCollection.mdx deleted file mode 100644 index 026728c39..000000000 --- a/docs/_deprecated/api-reference/core/MultiLineCollection.mdx +++ /dev/null @@ -1,392 +0,0 @@ ---- -title: "MultiLineCollection" -sidebarTitle: "MultiLineCollection" -icon: "" -description: "A list containing multi-line objects. Example: A list of function definitions, class definitions You can use standard operations to operate on this list (IE len, del, append, insert, etc)" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[SymbolGroup](/api-reference/core/SymbolGroup), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### next_named_sibling - -Editable | None } description="Returns the next named sibling of the last symbol in the group." /> - -### next_sibling - -Editable | None } description="Returns the next sibling of the last symbol in the symbol group." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### source - -str } description="Get the source code content of the node." /> - -### symbols - -list[ Editable ] } description="Returns the list of symbols in the group." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Edit the source for this Collection instance. - - - -None } description=""/> - - -### find -Search for substrings in the given symbols that match `strings_to_match`. - - - -list[str] | str } - description="The string or list of strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes that exactly match the query." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable objects representing each match found."/> - - -### find_string_literals -Search for string literals matching given strings in the SymbolGroup. - - - -list[str] } - description="List of strings to search for in string literals." - defaultValue="" -/> -bool, optional } - description="If True, performs fuzzy matching instead of exact matching." - defaultValue="False" -/> - - - -list[ Editable ] } description="List of Editable nodes representing the matching string literals found within the symbols."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ MultiLineCollection ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ MultiLineCollection ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### index -Return the index of the first occurrence of value. - - - -int } description=""/> - - -### insert -Adds `value` to the container that this node represents - - - -None } description=""/> - - -### insert_after -Inserts source code after this node in the codebase. - - - -str } - description="The source code to insert." - defaultValue="" -/> -bool, optional } - description="Adjust indentation to match current text." - defaultValue="False" -/> -bool, optional } - description="Add a newline before the inserted code." - defaultValue="True" -/> -int, optional } - description="Priority of the edit operation." - defaultValue="0" -/> -bool, optional } - description="Deduplicate identical edits." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts source code before this symbol group. - - - -str } - description="The source code to insert." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of the inserted code to match the current code. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline after the inserted code. Defaults to True." - defaultValue="True" -/> -int, optional } - description="The priority of this edit operation. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to prevent duplicate insertions of the same code. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Removes an element from a Collection. - - - -Editable | None } - description="The element to remove from the Collection. If None, delegates to parent class." - defaultValue="None" -/> - - - -None } description="This method doesn't return anything."/> - - -### replace -Replaces all instances of a string with a new string in all symbols within the group. - - - -str } - description="The string to be replaced." - defaultValue="" -/> -str } - description="The string to replace with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="Number of replacements made."/> - - -### search -Searches for regex matches in the codebase. - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool, optional } - description="Whether to include string literals in the search. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to include comments in the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects representing matched text nodes in the codebase."/> - - - diff --git a/docs/_deprecated/api-reference/core/Name.mdx b/docs/_deprecated/api-reference/core/Name.mdx deleted file mode 100644 index 798205682..000000000 --- a/docs/_deprecated/api-reference/core/Name.mdx +++ /dev/null @@ -1,413 +0,0 @@ ---- -title: "Name" -sidebarTitle: "Name" -icon: "" -description: "Editable attribute on any given code objects that has a name. For example, function, classes, global variable, interfaces, attributes, parameters are all composed of a name." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ Name ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ Name ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ Name ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/core/NamedType.mdx b/docs/_deprecated/api-reference/core/NamedType.mdx deleted file mode 100644 index ec98d7452..000000000 --- a/docs/_deprecated/api-reference/core/NamedType.mdx +++ /dev/null @@ -1,463 +0,0 @@ ---- -title: "NamedType" -sidebarTitle: "NamedType" -icon: "" -description: "An abstract representation of a named type." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[HasName](/api-reference/core/HasName), [Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ NamedType ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ NamedType ] } description=""/> - - -### get_name -Returns the name node of the object. - - - -Name | ChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ NamedType ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Sets the name of an object and updates all its usages. - - - -str } - description="The new name to assign to the object." - defaultValue="" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/core/NoneType.mdx b/docs/_deprecated/api-reference/core/NoneType.mdx deleted file mode 100644 index c50d6240b..000000000 --- a/docs/_deprecated/api-reference/core/NoneType.mdx +++ /dev/null @@ -1,413 +0,0 @@ ---- -title: "NoneType" -sidebarTitle: "NoneType" -icon: "" -description: "Represents a None or Null object." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ NoneType ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ NoneType ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ NoneType ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/core/Number.mdx b/docs/_deprecated/api-reference/core/Number.mdx deleted file mode 100644 index 24eed652c..000000000 --- a/docs/_deprecated/api-reference/core/Number.mdx +++ /dev/null @@ -1,413 +0,0 @@ ---- -title: "Number" -sidebarTitle: "Number" -icon: "" -description: "A number value. eg. 1, 2.0, 3.14" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ Number ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ Number ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ Number ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/core/Pair.mdx b/docs/_deprecated/api-reference/core/Pair.mdx deleted file mode 100644 index cb6d4b12c..000000000 --- a/docs/_deprecated/api-reference/core/Pair.mdx +++ /dev/null @@ -1,438 +0,0 @@ ---- -title: "Pair" -sidebarTitle: "Pair" -icon: "" -description: "An abstract representation of a key, value pair belonging to a `Dict`." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[HasValue](/api-reference/core/HasValue), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### key - -Expression } description="The key expression of the pair, expected to be of type TExpression." /> - -### name - -str } description="Returns the source text of the key expression in the pair." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### source - -str } description="Text representation of the Editable instance." /> - -### value - -Expression | None } description="Gets the value node of the object." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ Pair ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ Pair ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ Pair ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_value -Sets the value of the node's value Expression. - - - -str } - description="The new value to set." - defaultValue="" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/core/Parameter.mdx b/docs/_deprecated/api-reference/core/Parameter.mdx deleted file mode 100644 index 7e5849368..000000000 --- a/docs/_deprecated/api-reference/core/Parameter.mdx +++ /dev/null @@ -1,588 +0,0 @@ ---- -title: "Parameter" -sidebarTitle: "Parameter" -icon: "" -description: "Abstract representation of a parameter in a Function definition." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[HasValue](/api-reference/core/HasValue), [Expression](/api-reference/core/Expression), [Typeable](/api-reference/core/Typeable), [Usable](/api-reference/core/Usable), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [HasName](/api-reference/core/HasName) - -## Attributes - -### default - -str | None } description="Returns the default value of a parameter if one exists." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### index - -int } description="Returns the 0-based index of this parameter within its parent function's parameter list." /> - -### is_optional - -bool } description="Returns whether the parameter is optional in its function definition." /> - -### is_typed - -bool } description="Indicates if a node has an explicit type annotation." /> - -### is_variadic - -bool } description="Returns whether the parameter is a variadic parameter." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### type - -Type | TypePlaceholder [ Parameter ] } description="The type annotation associated with this node" /> - -### value - -Expression | None } description="Gets the value node of the object." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ Symbol , Import ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ Parameter ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ Parameter ] } description=""/> - - -### get_name -Returns the name node of the object. - - - -Name | ChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ Parameter ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Removes the parameter from the function definition and all its call sites. - - - -bool, optional } - description="Whether to delete formatting around the parameter. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority level for the removal operation. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate removal operations. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Renames a parameter in a function definition and updates all related references. - - - -str } - description="The new name for the parameter." - defaultValue="" -/> -int, optional } - description="The priority of the edit operation. Defaults to 0." - defaultValue="0" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### set_type_annotation -Sets the type annotation for this parameter. - - - -str } - description="The type annotation to set for the parameter." - defaultValue="" -/> - - - -None } description=""/> - - -### set_value -Sets the value of the node's value Expression. - - - -str } - description="The new value to set." - defaultValue="" -/> - - - -None } description=""/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ Import | Symbol | TSExport ] } description="A list of symbols that use or import the exportable object."/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/core/ParenthesizedExpression.mdx b/docs/_deprecated/api-reference/core/ParenthesizedExpression.mdx deleted file mode 100644 index 0ba5da6ae..000000000 --- a/docs/_deprecated/api-reference/core/ParenthesizedExpression.mdx +++ /dev/null @@ -1,474 +0,0 @@ ---- -title: "ParenthesizedExpression" -sidebarTitle: "ParenthesizedExpression" -icon: "" -description: "An expression surrounded in a set of parenthesis. Example: ```typescript (5 + 5) ```" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[HasValue](/api-reference/core/HasValue), [Unwrappable](/api-reference/core/Unwrappable), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Retrieves a list of function calls within a parenthesized expression." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### value - -Expression | None } description="Gets the value node of the object." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ ParenthesizedExpression ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ ParenthesizedExpression ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ ParenthesizedExpression ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Simplifies an expression based on a boolean condition. - - - -bool } - description="The boolean value to reduce the condition to." - defaultValue="" -/> -Editable } - description="The node to be simplified." - defaultValue="" -/> - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### resolve -Resolves the wrapper expression and returns the first concrete expression. - - - -Expression } description=""/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_value -Sets the value of the node's value Expression. - - - -str } - description="The new value to set." - defaultValue="" -/> - - - -None } description=""/> - - -### unwrap -Removes the parentheses from a parenthesized expression node. - - - -Expression | None, optional } - description="The node to unwrap. Defaults to None." - defaultValue="None" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/core/Placeholder.mdx b/docs/_deprecated/api-reference/core/Placeholder.mdx deleted file mode 100644 index 8f2401f42..000000000 --- a/docs/_deprecated/api-reference/core/Placeholder.mdx +++ /dev/null @@ -1,63 +0,0 @@ ---- -title: "Placeholder" -sidebarTitle: "Placeholder" -icon: "" -description: "A placeholder for a node that does not exist yet. Use bool checks (ie is node) to check if the node exists. You can call edit to replace the placeholder with a real node and it will automatically insert formatting." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - - - -## Methods - -### edit -Replaces the content of a placeholder node with new source code. - - - -str } - description="The new source code to replace the placeholder with." - defaultValue="" -/> -bool, optional } - description="Whether to automatically fix the" - defaultValue="False" -/> -int, optional } - description="Priority value for conflict resolution." - defaultValue="0" -/> -bool, optional } - description="Whether to prevent duplicate insertions." - defaultValue="True" -/> - - - -None } description=""/> - - -### remove -Removes this element from its parent container. - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/core/PlaceholderType.mdx b/docs/_deprecated/api-reference/core/PlaceholderType.mdx deleted file mode 100644 index a846e47cd..000000000 --- a/docs/_deprecated/api-reference/core/PlaceholderType.mdx +++ /dev/null @@ -1,413 +0,0 @@ ---- -title: "PlaceholderType" -sidebarTitle: "PlaceholderType" -icon: "" -description: "Represents a type that has not been implemented yet." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ PlaceholderType ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ PlaceholderType ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ PlaceholderType ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/core/RaiseStatement.mdx b/docs/_deprecated/api-reference/core/RaiseStatement.mdx deleted file mode 100644 index 7ae9a97b6..000000000 --- a/docs/_deprecated/api-reference/core/RaiseStatement.mdx +++ /dev/null @@ -1,446 +0,0 @@ ---- -title: "RaiseStatement" -sidebarTitle: "RaiseStatement" -icon: "" -description: "Abstract representation of raise statements, e.g. in Python: Example: def f(x): raise ValueError()" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[HasValue](/api-reference/core/HasValue), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Gets function calls within a raise statement's value expression." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### nested_code_blocks - -list[ Editable ] } description="Returns all nested code blocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ RaiseStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### value - -Expression | None } description="Gets the value node of the object." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ RaiseStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ RaiseStatement ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ RaiseStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_value -Sets the value of the node's value Expression. - - - -str } - description="The new value to set." - defaultValue="" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/core/ReturnStatement.mdx b/docs/_deprecated/api-reference/core/ReturnStatement.mdx deleted file mode 100644 index f507516c2..000000000 --- a/docs/_deprecated/api-reference/core/ReturnStatement.mdx +++ /dev/null @@ -1,446 +0,0 @@ ---- -title: "ReturnStatement" -sidebarTitle: "ReturnStatement" -icon: "" -description: "Abstract representation of return statements, e.g. in Python: Example: def f(x): if x: return x**2 # ReturnStatement else: return 1 # ReturnStatement" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[HasValue](/api-reference/core/HasValue), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of function calls contained within this return statement." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### nested_code_blocks - -list[ Editable ] } description="Returns all nested code blocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ ReturnStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### value - -Expression | None } description="Gets the value node of the object." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ ReturnStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ ReturnStatement ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ ReturnStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_value -Sets the value of the node's value Expression. - - - -str } - description="The new value to set." - defaultValue="" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/core/SourceFile.mdx b/docs/_deprecated/api-reference/core/SourceFile.mdx deleted file mode 100644 index 3f4ea0d42..000000000 --- a/docs/_deprecated/api-reference/core/SourceFile.mdx +++ /dev/null @@ -1,873 +0,0 @@ ---- -title: "SourceFile" -sidebarTitle: "SourceFile" -icon: "" -description: "Represents a file with source code in the codebase. Enables creating, reading, updating, and deleting files and searching through their contents, etc." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Usable](/api-reference/core/Usable), [HasBlock](/api-reference/core/HasBlock), [File](/api-reference/core/File), [Importable](/api-reference/core/Importable), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable), [HasName](/api-reference/core/HasName) - -## Attributes - -### classes - -list[ Class ] } description="Returns all Classes in the file." /> - -### code_block - -CodeBlock } description="Represents the block of code contained in the file." /> - -### content - -str } description="Returns the content of the file as a UTF-8 encoded string." /> - -### decorators - -list[ Decorator ] } description="Returns list of all decorators on this Symbol." /> - -### directory - -Directory | None } description="Returns the directory that contains this file." /> - -### docstring - -CommentGroup | None } description="Retrieves the docstring of the expression." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### extension - -str } description="Returns the file extension." /> - -### file - -SourceFile } description="A property that returns the file object for non-source files." /> - -### file_path - -str } description="The relative file path as a string." /> - -### filepath - -str } description="Retrieves the file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns all function calls within the code block and its decorators." /> - -### functions - -list[ Function ] } description="Returns all Functions in the file." /> - -### global_vars - -list[ Assignment ] } description="Returns all GlobalVars in the file." /> - -### import_module_name - -str } description="Returns the module name that this file gets imported as." /> - -### import_statements - -list[ ImportStatement ] } description="Returns all ImportStatements in the file, where each import statement can contain" /> - -### importers - -list[ Import ] } description="Returns all imports that directly imports this file as a module." /> - -### imports - -list[ Import ] } description="List of all Imports in this file." /> - -### inbound_imports - -list[ Import ] } description="Returns all imports that are importing symbols contained in this file." /> - -### is_binary - -bool } description="Indicates whether the file contains binary data." /> - -### is_decorated - -bool } description="Check if the symbol has decorators." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### owners - -set[str] } description="Returns the CODEOWNERS of the file." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### path - -Path } description="The absolute path of the file as a Path object." /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### start_byte - -int } description="Returns the starting byte position of a file in its content." /> - -### symbols_sorted_topologically - -list[ Symbol ] } description="Returns all Symbols in the file, sorted topologically (parents first). Robust to" /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### add_import -Adds an import to the file. - - - -Symbol | str } - description="Either a Symbol to import or a string representation of an import statement." - defaultValue="" -/> -str | None } - description="Optional alias for the imported symbol. Only used when imp is a Symbol. Defaults to None." - defaultValue="None" -/> -ImportType } - description="The type of import to use. Only used when imp is a Symbol. Defaults to ImportType.UNKNOWN." - defaultValue="ImportType.UNKNOWN" -/> -bool } - description="Whether this is a type-only import. Only used when imp is a Symbol. Defaults to False." - defaultValue="False" -/> - - - -Import | None } description="The existing import for the symbol if found, otherwise None."/> - - -### add_symbol -Adds `symbol` to the file. - - - -Symbol } - description="The symbol to add to the file." - defaultValue="" -/> -bool, optional } - description="Whether to export the symbol. Defaults to True." - defaultValue="True" -/> - - - -Symbol | None } description="The existing symbol if it already exists in the file or None if it was added."/> - - -### add_symbol_from_source -Adds a symbol to a file from a string representation. - - - -str } - description="String representation of the symbol to be added. This should be valid source code for" - defaultValue="" -/> - - - -None } description="The symbol is added directly to the file's content."/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ Symbol , Import ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this file with new_src. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of new_src to match the current" - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are" - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_by_byte_range -Finds all editable objects that overlap with the given byte range in the file. - - - -Range } - description="The byte range to search within the file." - defaultValue="" -/> - - - -list[ Editable ] } description="A list of all Editable objects that overlap with the given range."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ SourceFile ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ SourceFile ] } description=""/> - - -### get_class -Returns a specific Class by full name. Returns None if not found. - - - -str } - description="The full name of the class to search for." - defaultValue="" -/> - - - -Class | None } description="The matching Class object if found, None otherwise."/> - - -### get_function -Returns a specific Function by name. - - - -str } - description="The name of the function to find." - defaultValue="" -/> - - - -Function | None } description="The matching Function object if found, None otherwise."/> - - -### get_global_var -Returns a specific global var by name. Returns None if not found. - - - -str } - description="The name of the global variable to find." - defaultValue="" -/> - - - -Assignment | None } description="The global variable if found, None otherwise."/> - - -### get_import -Returns the import with matching alias. Returns None if not found. - - - -str } - description="The alias name to search for. This can match either the direct import name or the aliased name." - defaultValue="" -/> - - - -Import | None } description="The import statement with the matching alias if found, None otherwise."/> - - -### get_name -Returns the name node of the object. - - - -Name | ChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_symbol -Gets a symbol by its name from the file. - - - -str } - description="The name of the symbol to find." - defaultValue="" -/> - - - -Symbol | None } description="The found symbol, or None if not found."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ SourceFile ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### has_import -Returns True if the file has an import with the given alias. - - - -str } - description="The alias to check for in the import statements." - defaultValue="" -/> - - - -bool } description="True if an import with the given alias exists, False otherwise."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Removes the file from the file system and graph. - - - -None } description=""/> - - -### remove_unused_exports -Removes unused exports from the file. - - - -None } description=""/> - - -### rename -Renames a symbol and updates all its references in the codebase. - - - -str } - description="The new name for the symbol." - defaultValue="" -/> -int } - description="Priority of the edit operation. Defaults to 0." - defaultValue="0" -/> - - - -tuple[NodeId, NodeId] } description="A tuple containing the file node ID and the new node ID of the renamed symbol."/> - - -### replace -Replace occurrences of text in the file. - - - -str } - description="The text to be replaced." - defaultValue="" -/> -str } - description="The text to replace with." - defaultValue="" -/> -int } - description="Maximum number of replacements to make. -1 means replace all occurrences." - defaultValue="-1" -/> -bool } - description="If True, treat 'old' as a regular expression pattern." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are" - defaultValue="0" -/> - - - -int } description="List of affected Editable objects. For non-source files, always returns an empty list since they don't have Editable sub-components."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_docstring -Sets or updates the docstring for the current entity. - - - -str } - description="The new docstring content to set." - defaultValue="" -/> - - - -None } description="This method doesn't return anything."/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### symbol_can_be_added -Checks if the file type supports adding the given symbol. - - - -Symbol } - description="The symbol to check for add compatibility." - defaultValue="" -/> - - - -bool } description="True if the symbol can be added to this file type, False otherwise."/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ Import | Symbol | TSExport ] } description="A list of symbols that use or import the exportable object."/> - - -### symbols -Returns all Symbols in the file, sorted by position in the file. - - - -list[ Symbol | Class | Function | Assignment | TSInterface ] } description="A list of all top-level symbols in the file, sorted by their position in the file. Symbols can be one of the following types: - Symbol: Base symbol class - TClass: Class definition - TFunction: Function definition - TGlobalVar: Global variable assignment - TInterface: Interface definition"/> - - -### update_filepath -Renames the file and updates all imports to point to the new location. - - - -str } - description="The new filepath to move the file to." - defaultValue="" -/> - - - -None } description=""/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/core/Span.mdx b/docs/_deprecated/api-reference/core/Span.mdx deleted file mode 100644 index 2b4e08752..000000000 --- a/docs/_deprecated/api-reference/core/Span.mdx +++ /dev/null @@ -1,28 +0,0 @@ ---- -title: "Span" -sidebarTitle: "Span" -icon: "" -description: "Range within the codebase" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - - -## Attributes - -### filepath - -str } description="The path to the file associated with the range." /> - -### range - -RangeAdapter } description="Adapter for the range within the codebase." /> - - - diff --git a/docs/_deprecated/api-reference/core/Statement.mdx b/docs/_deprecated/api-reference/core/Statement.mdx deleted file mode 100644 index b103c92c6..000000000 --- a/docs/_deprecated/api-reference/core/Statement.mdx +++ /dev/null @@ -1,425 +0,0 @@ ---- -title: "Statement" -sidebarTitle: "Statement" -icon: "" -description: "Represents a single code statement, e.g. a function definition, an assignment, an if/else statement, etc." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### nested_code_blocks - -list[ Editable ] } description="Returns all nested code blocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ Statement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ Statement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ Statement ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ Statement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/core/StatementType.mdx b/docs/_deprecated/api-reference/core/StatementType.mdx deleted file mode 100644 index 96f065b59..000000000 --- a/docs/_deprecated/api-reference/core/StatementType.mdx +++ /dev/null @@ -1,96 +0,0 @@ ---- -title: "StatementType" -sidebarTitle: "StatementType" -icon: "" -description: "Enum representing the different types of statements that can be parsed." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - - -## Attributes - -### ASSIGNMENT - - } description="Represents an assignment expression." /> - -### BREAK_STATEMENT - - } description="Represents a break statement." /> - -### CLASS_ATTRIBUTE - - } description="Represents a class attribute." /> - -### COMMENT - - } description="Represents a comment statement." /> - -### EXPORT_STATEMENT - - } description="Represents an export statement." /> - -### EXPRESSION_STATEMENT - - } description="Represents an expression statement." /> - -### FOR_LOOP_STATEMENT - - } description="Represents a for loop statement." /> - -### IF_BLOCK_STATEMENT - - } description="Represents an if block statement." /> - -### IMPORT_STATEMENT - - } description="Represents an import statement." /> - -### LABELED_STATEMENT - - } description="Represents a labeled statement." /> - -### PASS_STATEMENT - - } description="Represents a pass statement." /> - -### RAISE_STATEMENT - - } description="Represents a raise statement." /> - -### RETURN_STATEMENT - - } description="Represents a return statement." /> - -### SWITCH_STATEMENT - - } description="Represents a switch statement." /> - -### SYMBOL_STATEMENT - - } description="Represents a symbol statement." /> - -### TRY_CATCH_STATEMENT - - } description="Represents a try-catch statement." /> - -### UNSPECIFIED - - } description="Represents any unparsed code snippet or graph node statements." /> - -### WHILE_STATEMENT - - } description="Represents a while statement." /> - -### WITH_STATEMENT - - } description="Represents a with statement." /> - - - diff --git a/docs/_deprecated/api-reference/core/String.mdx b/docs/_deprecated/api-reference/core/String.mdx deleted file mode 100644 index 4f8e8c378..000000000 --- a/docs/_deprecated/api-reference/core/String.mdx +++ /dev/null @@ -1,429 +0,0 @@ ---- -title: "String" -sidebarTitle: "String" -icon: "" -description: "GraphSitter representation of String." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### content - -str } description="The content of the string" /> - -### content_nodes - -Collection[ Expression [ Editable ], String ] } description="A collection of string fragments and escape sequences in TS, or a single string content in Python." /> - -### expressions - -list[ Expression [ Editable ]] } description="Embedded expressions in the string, only applicable for templated or formatted strings." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - -### with_quotes - -str } description="Retrieves the string representation with quotation marks." /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ String ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ String ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ String ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/core/StubPlaceholder.mdx b/docs/_deprecated/api-reference/core/StubPlaceholder.mdx deleted file mode 100644 index 3d2ef80e5..000000000 --- a/docs/_deprecated/api-reference/core/StubPlaceholder.mdx +++ /dev/null @@ -1,65 +0,0 @@ ---- -title: "StubPlaceholder" -sidebarTitle: "StubPlaceholder" -icon: "" -description: "A placeholder for a stub that does not exist. Can be populated using the `edit` method." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Placeholder](/api-reference/core/Placeholder) - - -## Methods - -### edit -Edits the source code of this placeholder node. - - - -str } - description="The new source code to replace the current source code." - defaultValue="" -/> -bool, optional } - description="Whether to automatically fix the indentation of the new source code. Defaults to False." - defaultValue="False" -/> -int, optional } - description="The priority of this edit operation. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate this edit against other pending edits. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### remove -Removes this element from its parent container. - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/core/SubscriptExpression.mdx b/docs/_deprecated/api-reference/core/SubscriptExpression.mdx deleted file mode 100644 index bf69eba81..000000000 --- a/docs/_deprecated/api-reference/core/SubscriptExpression.mdx +++ /dev/null @@ -1,421 +0,0 @@ ---- -title: "SubscriptExpression" -sidebarTitle: "SubscriptExpression" -icon: "" -description: "Indexing onto an object (Aka using brackets on an object) Examples: A[]" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### indices - -list[ Expression ] } description="A list of indices used for indexing the object." /> - -### object - -Object } description="The object being indexed." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ SubscriptExpression ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ SubscriptExpression ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ SubscriptExpression ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/core/SwitchCase.mdx b/docs/_deprecated/api-reference/core/SwitchCase.mdx deleted file mode 100644 index a179a8071..000000000 --- a/docs/_deprecated/api-reference/core/SwitchCase.mdx +++ /dev/null @@ -1,485 +0,0 @@ ---- -title: "SwitchCase" -sidebarTitle: "SwitchCase" -icon: "" -description: "Abstract representation for a switch case." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[BlockStatement](/api-reference/core/BlockStatement), [Statement](/api-reference/core/Statement), [HasBlock](/api-reference/core/HasBlock), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### code_block - -CodeBlock | None } description="The code block contained within the statement, if it exists." /> - -### condition - -Expression [ SwitchCase ] | None } description="The condition which triggers this case" /> - -### decorators - -list[ Decorator ] } description="Returns list of all decorators on this Symbol." /> - -### docstring - -CommentGroup | None } description="Retrieves the docstring of the expression." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Gets all function calls within the statement's code block." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### is_decorated - -bool } description="Check if the symbol has decorators." /> - -### nested_code_blocks - -list[ CodeBlock ] } description="Returns all nested CodeBlocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ SwitchCase ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ SwitchCase ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ SwitchCase ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ SwitchCase ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_docstring -Sets or updates the docstring for the current entity. - - - -str } - description="The new docstring content to set." - defaultValue="" -/> - - - -None } description="This method doesn't return anything."/> - - - diff --git a/docs/_deprecated/api-reference/core/SwitchStatement.mdx b/docs/_deprecated/api-reference/core/SwitchStatement.mdx deleted file mode 100644 index e41f2a33e..000000000 --- a/docs/_deprecated/api-reference/core/SwitchStatement.mdx +++ /dev/null @@ -1,433 +0,0 @@ ---- -title: "SwitchStatement" -sidebarTitle: "SwitchStatement" -icon: "" -description: "Abstract representation of the switch statement." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### cases - -list[ SwitchCase ] } description="A list of switch cases." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns all function calls within the switch statement." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### nested_code_blocks - -list[ CodeBlock ] } description="Returns all nested CodeBlocks within the switch statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ SwitchStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### value - -Expression [ SwitchStatement ] } description="The value to switch on." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ SwitchStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ SwitchStatement ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ SwitchStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/core/Symbol.mdx b/docs/_deprecated/api-reference/core/Symbol.mdx deleted file mode 100644 index c1faa2df8..000000000 --- a/docs/_deprecated/api-reference/core/Symbol.mdx +++ /dev/null @@ -1,645 +0,0 @@ ---- -title: "Symbol" -sidebarTitle: "Symbol" -icon: "" -description: "Abstract representation of a Symbol in a Codebase. A Symbol is a top-level entity in a file, e.g. a Function, Class, GlobalVariable, etc." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Usable](/api-reference/core/Usable), [Importable](/api-reference/core/Importable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName), [Editable](/api-reference/core/Editable) - -## Attributes - -### comment - -CommentGroup | None } description="Returns the comment group associated with the symbol, if any." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_nodes - -list[ Editable ] } description="Returns a list of Editable nodes associated with this symbol, including extended symbols." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### inline_comment - -CommentGroup | None } description="Returns the inline comment group associated with the symbol, if any." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Returns the source code of the symbol." /> - -### symbol_type - -SymbolType } description="The type of the symbol." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_comment -Adds a comment to the symbol. - - - -str } - description="The comment text to add." - defaultValue="" -/> - - - -None } description=""/> - - -### add_keyword -Insert a keyword in the appropriate place before this symbol if it doesn't already exist. - - - -str } - description="The keyword to be inserted. Must be a valid keyword in the language context." - defaultValue="" -/> - - - -None } description=""/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ Symbol , Import ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this node with new_src. - - - -str } - description="The new source code to replace the current source with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, prevents duplicate edits. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ Symbol ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ Symbol ] } description=""/> - - -### get_name -Returns the name node of the object. - - - -Name | ChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ Symbol ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before the current symbol node in the Abstract Syntax Tree. - - - -str } - description="The source code text to insert." - defaultValue="" -/> -bool } - description="Whether to adjust the indentation of new_src to match current text. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after insertion. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to remove duplicate insertions. Defaults to True." - defaultValue="True" -/> -bool } - description="Whether to insert before extended nodes like comments and decorators. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### move_to_file -Moves the given symbol to a new file and updates its imports and references. - - - -SourceFile } - description="The destination file to move the symbol to." - defaultValue="" -/> -bool } - description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." - defaultValue="True" -/> -str } - description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." - defaultValue=""update_all_imports"" -/> - - - -None } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Renames a symbol and updates all its references in the codebase. - - - -str } - description="The new name for the symbol." - defaultValue="" -/> -int } - description="Priority of the edit operation. Defaults to 0." - defaultValue="0" -/> - - - -tuple[NodeId, NodeId] } description="A tuple containing the file node ID and the new node ID of the renamed symbol."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_comment -Sets a comment to the symbol. - - - -str } - description="The comment text to set." - defaultValue="" -/> - - - -None } description=""/> - - -### set_inline_comment -Sets an inline comment to the symbol. - - - -str } - description="The text of the inline comment to be added or updated." - defaultValue="" -/> - - - -None } description=""/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ Import | Symbol | TSExport ] } description="A list of symbols that use or import the exportable object."/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/core/SymbolGroup.mdx b/docs/_deprecated/api-reference/core/SymbolGroup.mdx deleted file mode 100644 index 541f911c4..000000000 --- a/docs/_deprecated/api-reference/core/SymbolGroup.mdx +++ /dev/null @@ -1,415 +0,0 @@ ---- -title: "SymbolGroup" -sidebarTitle: "SymbolGroup" -icon: "" -description: "These are groups of symbols that form some kind of logical grouping, like a class or module, that do not follow the traditional tree structure." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### next_named_sibling - -Editable | None } description="Returns the next named sibling of the last symbol in the group." /> - -### next_sibling - -Editable | None } description="Returns the next sibling of the last symbol in the symbol group." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### source - -str } description="Returns the concatenated source code of all symbols in the group." /> - -### symbols - -list[ Editable ] } description="Returns the list of symbols in the group." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this node with new text. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool, optional } - description="Adjusts the indentation of new_src to match the current text's indentation. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the edit operation. Higher priority edits take precedence. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Prevents duplicate edits at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Search for substrings in the given symbols that match `strings_to_match`. - - - -list[str] | str } - description="The string or list of strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes that exactly match the query." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable objects representing each match found."/> - - -### find_string_literals -Search for string literals matching given strings in the SymbolGroup. - - - -list[str] } - description="List of strings to search for in string literals." - defaultValue="" -/> -bool, optional } - description="If True, performs fuzzy matching instead of exact matching." - defaultValue="False" -/> - - - -list[ Editable ] } description="List of Editable nodes representing the matching string literals found within the symbols."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ SymbolGroup ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ SymbolGroup ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts source code after this node in the codebase. - - - -str } - description="The source code to insert." - defaultValue="" -/> -bool, optional } - description="Adjust indentation to match current text." - defaultValue="False" -/> -bool, optional } - description="Add a newline before the inserted code." - defaultValue="True" -/> -int, optional } - description="Priority of the edit operation." - defaultValue="0" -/> -bool, optional } - description="Deduplicate identical edits." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts source code before this symbol group. - - - -str } - description="The source code to insert." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of the inserted code to match the current code. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline after the inserted code. Defaults to True." - defaultValue="True" -/> -int, optional } - description="The priority of this edit operation. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to prevent duplicate insertions of the same code. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Removes this node and its related extended nodes from the codebase. - - - -bool, optional } - description="Whether to delete related extended nodes like decorators and comments. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority level of the removal operation. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate removal operations. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Replaces all instances of a string with a new string in all symbols within the group. - - - -str } - description="The string to be replaced." - defaultValue="" -/> -str } - description="The string to replace with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="Number of replacements made."/> - - -### search -Searches for regex matches in the codebase. - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool, optional } - description="Whether to include string literals in the search. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to include comments in the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects representing matched text nodes in the codebase."/> - - - diff --git a/docs/_deprecated/api-reference/core/SymbolStatement.mdx b/docs/_deprecated/api-reference/core/SymbolStatement.mdx deleted file mode 100644 index 27af480ea..000000000 --- a/docs/_deprecated/api-reference/core/SymbolStatement.mdx +++ /dev/null @@ -1,429 +0,0 @@ ---- -title: "SymbolStatement" -sidebarTitle: "SymbolStatement" -icon: "" -description: "A statement that represents a symbol definition in a codeblock. Examples include: - a function definition, class definition, global variable assignment" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns all function calls contained within the symbol associated with this statement." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### nested_code_blocks - -list[ Editable ] } description="Returns all nested code blocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ SymbolStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### symbol - -Editable } description="The symbol associated with this statement, representing a code element." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ SymbolStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ SymbolStatement ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ SymbolStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/core/TernaryExpression.mdx b/docs/_deprecated/api-reference/core/TernaryExpression.mdx deleted file mode 100644 index 0094efbf9..000000000 --- a/docs/_deprecated/api-reference/core/TernaryExpression.mdx +++ /dev/null @@ -1,440 +0,0 @@ ---- -title: "TernaryExpression" -sidebarTitle: "TernaryExpression" -icon: "" -description: "Any ternary expression in the code where a condition will determine branched execution." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### alternative - -Expression [ TernaryExpression ] | None } description="The expression to execute if the condition is false." /> - -### condition - -Expression [ TernaryExpression ] | None } description="The condition expression that determines which branch to execute." /> - -### consequence - -Expression [ TernaryExpression ] | None } description="The expression to execute if the condition is true." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TernaryExpression ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TernaryExpression ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TernaryExpression ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Simplifies a ternary expression based on a boolean condition. - - - -bool } - description="The boolean value to reduce the condition to. If True, keeps the consequence branch. If False, keeps the alternative branch." - defaultValue="" -/> -Editable | None, optional } - description="The node to be edited. Defaults to None." - defaultValue="None" -/> - - - -None } description="Modifies the ternary expression in place."/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/core/TryCatchStatement.mdx b/docs/_deprecated/api-reference/core/TryCatchStatement.mdx deleted file mode 100644 index cb5c24d83..000000000 --- a/docs/_deprecated/api-reference/core/TryCatchStatement.mdx +++ /dev/null @@ -1,485 +0,0 @@ ---- -title: "TryCatchStatement" -sidebarTitle: "TryCatchStatement" -icon: "" -description: "Abstract representation of the try catch statement block." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[HasBlock](/api-reference/core/HasBlock), [BlockStatement](/api-reference/core/BlockStatement), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### code_block - -CodeBlock } description="The block of code associated with the code object." /> - -### decorators - -list[ Decorator ] } description="Returns list of all decorators on this Symbol." /> - -### docstring - -CommentGroup | None } description="Retrieves the docstring of the expression." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### finalizer - -BlockStatement | None } description="The code block executed regardless of if an exception is thrown or not" /> - -### function_calls - -list[ FunctionCall ] } description="Returns all function calls within the code block and its decorators." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### is_decorated - -bool } description="Check if the symbol has decorators." /> - -### nested_code_blocks - -list[ CodeBlock ] } description="Returns all nested CodeBlocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ TryCatchStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TryCatchStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TryCatchStatement ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TryCatchStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_docstring -Sets or updates the docstring for the current entity. - - - -str } - description="The new docstring content to set." - defaultValue="" -/> - - - -None } description="This method doesn't return anything."/> - - - diff --git a/docs/_deprecated/api-reference/core/Tuple.mdx b/docs/_deprecated/api-reference/core/Tuple.mdx deleted file mode 100644 index db02f3186..000000000 --- a/docs/_deprecated/api-reference/core/Tuple.mdx +++ /dev/null @@ -1,394 +0,0 @@ ---- -title: "Tuple" -sidebarTitle: "Tuple" -icon: "" -description: "A tuple object. You can use standard operations to operate on this list (IE len, del, append, insert, etc)" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable), [SymbolGroup](/api-reference/core/SymbolGroup) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Get the source code content of the node." /> - -### symbols - -list[ Editable ] } description="Returns the list of symbols in the group." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Edit the source for this Collection instance. - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ Tuple ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ Tuple ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ Tuple ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### index -Return the index of the first occurrence of value. - - - -int } description=""/> - - -### insert -Adds `value` to the container that this node represents - - - -None } description=""/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Removes an element from a Collection. - - - -Editable | None } - description="The element to remove from the Collection. If None, delegates to parent class." - defaultValue="None" -/> - - - -None } description="This method doesn't return anything."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/core/TupleType.mdx b/docs/_deprecated/api-reference/core/TupleType.mdx deleted file mode 100644 index c29035f83..000000000 --- a/docs/_deprecated/api-reference/core/TupleType.mdx +++ /dev/null @@ -1,396 +0,0 @@ ---- -title: "TupleType" -sidebarTitle: "TupleType" -icon: "" -description: "An abstract representation of a tuple type. For example `[number, number]`." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [SymbolGroup](/api-reference/core/SymbolGroup), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### next_named_sibling - -Editable | None } description="Returns the next named sibling of the last symbol in the group." /> - -### next_sibling - -Editable | None } description="Returns the next sibling of the last symbol in the symbol group." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Get the source code content of the node." /> - -### symbols - -list[ Editable ] } description="Returns the list of symbols in the group." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Edit the source for this Collection instance. - - - -None } description=""/> - - -### find -Search for substrings in the given symbols that match `strings_to_match`. - - - -list[str] | str } - description="The string or list of strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes that exactly match the query." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable objects representing each match found."/> - - -### find_string_literals -Search for string literals matching given strings in the SymbolGroup. - - - -list[str] } - description="List of strings to search for in string literals." - defaultValue="" -/> -bool, optional } - description="If True, performs fuzzy matching instead of exact matching." - defaultValue="False" -/> - - - -list[ Editable ] } description="List of Editable nodes representing the matching string literals found within the symbols."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TupleType ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TupleType ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### index -Return the index of the first occurrence of value. - - - -int } description=""/> - - -### insert -Adds `value` to the container that this node represents - - - -None } description=""/> - - -### insert_after -Inserts source code after this node in the codebase. - - - -str } - description="The source code to insert." - defaultValue="" -/> -bool, optional } - description="Adjust indentation to match current text." - defaultValue="False" -/> -bool, optional } - description="Add a newline before the inserted code." - defaultValue="True" -/> -int, optional } - description="Priority of the edit operation." - defaultValue="0" -/> -bool, optional } - description="Deduplicate identical edits." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts source code before this symbol group. - - - -str } - description="The source code to insert." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of the inserted code to match the current code. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline after the inserted code. Defaults to True." - defaultValue="True" -/> -int, optional } - description="The priority of this edit operation. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to prevent duplicate insertions of the same code. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Removes an element from a Collection. - - - -Editable | None } - description="The element to remove from the Collection. If None, delegates to parent class." - defaultValue="None" -/> - - - -None } description="This method doesn't return anything."/> - - -### replace -Replaces all instances of a string with a new string in all symbols within the group. - - - -str } - description="The string to be replaced." - defaultValue="" -/> -str } - description="The string to replace with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="Number of replacements made."/> - - -### search -Searches for regex matches in the codebase. - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool, optional } - description="Whether to include string literals in the search. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to include comments in the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects representing matched text nodes in the codebase."/> - - - diff --git a/docs/_deprecated/api-reference/core/Type.mdx b/docs/_deprecated/api-reference/core/Type.mdx deleted file mode 100644 index eea866692..000000000 --- a/docs/_deprecated/api-reference/core/Type.mdx +++ /dev/null @@ -1,413 +0,0 @@ ---- -title: "Type" -sidebarTitle: "Type" -icon: "" -description: "Abstract representation of a type Used to store the types of variables, parameters, or return values in functions, classes, etc." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ Type ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ Type ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ Type ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/core/TypeAlias.mdx b/docs/_deprecated/api-reference/core/TypeAlias.mdx deleted file mode 100644 index 9f8632690..000000000 --- a/docs/_deprecated/api-reference/core/TypeAlias.mdx +++ /dev/null @@ -1,738 +0,0 @@ ---- -title: "TypeAlias" -sidebarTitle: "TypeAlias" -icon: "" -description: "Abstract representation of a Type object. Only applicable for some programming languages like TypeScript." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[HasValue](/api-reference/core/HasValue), [HasBlock](/api-reference/core/HasBlock), [Symbol](/api-reference/core/Symbol), [Expression](/api-reference/core/Expression), [Usable](/api-reference/core/Usable), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [HasName](/api-reference/core/HasName) - -## Attributes - -### attributes - -list[ Attribute ] } description="List of expressions defined in this Type object." /> - -### code_block - -CodeBlock } description="The code block associated with this type alias." /> - -### comment - -CommentGroup | None } description="Returns the comment group associated with the symbol, if any." /> - -### decorators - -list[ Decorator ] } description="Returns list of all decorators on this Symbol." /> - -### docstring - -CommentGroup | None } description="Retrieves the docstring of the expression." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_nodes - -list[ Editable ] } description="Returns a list of Editable nodes associated with this symbol, including extended symbols." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns all function calls within the code block and its decorators." /> - -### inline_comment - -CommentGroup | None } description="Returns the inline comment group associated with the symbol, if any." /> - -### is_decorated - -bool } description="Check if the symbol has decorators." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Returns the source code of the symbol." /> - -### symbol_type - - } description="The type of symbol, set to SymbolType.Interface." /> - -### type_parameters - -TypeParameters[ Type , TypeAlias ] | None } description="The type parameters of the symbol, if any." /> - -### value - -Expression | None } description="Gets the value node of the object." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_comment -Adds a comment to the symbol. - - - -str } - description="The comment text to add." - defaultValue="" -/> - - - -None } description=""/> - - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### add_keyword -Insert a keyword in the appropriate place before this symbol if it doesn't already exist. - - - -str } - description="The keyword to be inserted. Must be a valid keyword in the language context." - defaultValue="" -/> - - - -None } description=""/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ Symbol , Import ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this node with new_src. - - - -str } - description="The new source code to replace the current source with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, prevents duplicate edits. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TypeAlias ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TypeAlias ] } description=""/> - - -### get_attribute -Get attribute by name. - - - -Attribute | None } description=""/> - - -### get_name -Returns the name node of the object. - - - -Name | ChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TypeAlias ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before the current symbol node in the Abstract Syntax Tree. - - - -str } - description="The source code text to insert." - defaultValue="" -/> -bool } - description="Whether to adjust the indentation of new_src to match current text. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after insertion. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to remove duplicate insertions. Defaults to True." - defaultValue="True" -/> -bool } - description="Whether to insert before extended nodes like comments and decorators. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### move_to_file -Moves the given symbol to a new file and updates its imports and references. - - - -SourceFile } - description="The destination file to move the symbol to." - defaultValue="" -/> -bool } - description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." - defaultValue="True" -/> -str } - description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." - defaultValue=""update_all_imports"" -/> - - - -None } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Renames a symbol and updates all its references in the codebase. - - - -str } - description="The new name for the symbol." - defaultValue="" -/> -int } - description="Priority of the edit operation. Defaults to 0." - defaultValue="0" -/> - - - -tuple[NodeId, NodeId] } description="A tuple containing the file node ID and the new node ID of the renamed symbol."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_comment -Sets a comment to the symbol. - - - -str } - description="The comment text to set." - defaultValue="" -/> - - - -None } description=""/> - - -### set_docstring -Sets or updates the docstring for the current entity. - - - -str } - description="The new docstring content to set." - defaultValue="" -/> - - - -None } description="This method doesn't return anything."/> - - -### set_inline_comment -Sets an inline comment to the symbol. - - - -str } - description="The text of the inline comment to be added or updated." - defaultValue="" -/> - - - -None } description=""/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### set_value -Sets the value of the node's value Expression. - - - -str } - description="The new value to set." - defaultValue="" -/> - - - -None } description=""/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ Import | Symbol | TSExport ] } description="A list of symbols that use or import the exportable object."/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/core/TypePlaceholder.mdx b/docs/_deprecated/api-reference/core/TypePlaceholder.mdx deleted file mode 100644 index dc6a6dd91..000000000 --- a/docs/_deprecated/api-reference/core/TypePlaceholder.mdx +++ /dev/null @@ -1,65 +0,0 @@ ---- -title: "TypePlaceholder" -sidebarTitle: "TypePlaceholder" -icon: "" -description: "A placeholder for a Type node that does not exist. Can be populated using the `edit` method." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Placeholder](/api-reference/core/Placeholder) - - -## Methods - -### edit -Edits the type annotation of a placeholder node. - - - -str } - description="The new type annotation text to be inserted." - defaultValue="" -/> -bool, optional } - description="Whether to fix the indentation of the new source." - defaultValue="False" -/> -int, optional } - description="Priority of the edit operation." - defaultValue="0" -/> -bool, optional } - description="Whether to remove duplicate edits." - defaultValue="True" -/> - - - -None } description=""/> - - -### remove -Removes this element from its parent container. - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/core/Typeable.mdx b/docs/_deprecated/api-reference/core/Typeable.mdx deleted file mode 100644 index 2c1d99f37..000000000 --- a/docs/_deprecated/api-reference/core/Typeable.mdx +++ /dev/null @@ -1,417 +0,0 @@ ---- -title: "Typeable" -sidebarTitle: "Typeable" -icon: "" -description: "An interface for any node object that can be typed, eg. function parameters, variables, etc." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### is_typed - -bool } description="Indicates if a node has an explicit type annotation." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### source - -str } description="Text representation of the Editable instance." /> - -### type - -Type | TypePlaceholder [ Typeable ] } description="The type annotation associated with this node" /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ Typeable ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ Typeable ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ Typeable ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/core/UnaryExpression.mdx b/docs/_deprecated/api-reference/core/UnaryExpression.mdx deleted file mode 100644 index 2d609d44c..000000000 --- a/docs/_deprecated/api-reference/core/UnaryExpression.mdx +++ /dev/null @@ -1,426 +0,0 @@ ---- -title: "UnaryExpression" -sidebarTitle: "UnaryExpression" -icon: "" -description: "Unary expression which is a single operation on a single operand. eg. -5, !true." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### argument - -Expression [ UnaryExpression ] } description="The argument of the unary expression" /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ UnaryExpression ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ UnaryExpression ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ UnaryExpression ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Simplifies a unary expression by reducing it based on a boolean condition. - - - -bool } - description="The boolean value to reduce the condition to." - defaultValue="" -/> - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/core/UnionType.mdx b/docs/_deprecated/api-reference/core/UnionType.mdx deleted file mode 100644 index 3dbf5f3ee..000000000 --- a/docs/_deprecated/api-reference/core/UnionType.mdx +++ /dev/null @@ -1,396 +0,0 @@ ---- -title: "UnionType" -sidebarTitle: "UnionType" -icon: "" -description: "An abstract representation of a union type. For example `str | None` or `string | number`." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [SymbolGroup](/api-reference/core/SymbolGroup), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### next_named_sibling - -Editable | None } description="Returns the next named sibling of the last symbol in the group." /> - -### next_sibling - -Editable | None } description="Returns the next sibling of the last symbol in the symbol group." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Get the source code content of the node." /> - -### symbols - -list[ Editable ] } description="Returns the list of symbols in the group." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Edit the source for this Collection instance. - - - -None } description=""/> - - -### find -Search for substrings in the given symbols that match `strings_to_match`. - - - -list[str] | str } - description="The string or list of strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes that exactly match the query." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable objects representing each match found."/> - - -### find_string_literals -Search for string literals matching given strings in the SymbolGroup. - - - -list[str] } - description="List of strings to search for in string literals." - defaultValue="" -/> -bool, optional } - description="If True, performs fuzzy matching instead of exact matching." - defaultValue="False" -/> - - - -list[ Editable ] } description="List of Editable nodes representing the matching string literals found within the symbols."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ UnionType ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ UnionType ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### index -Return the index of the first occurrence of value. - - - -int } description=""/> - - -### insert -Adds `value` to the container that this node represents - - - -None } description=""/> - - -### insert_after -Inserts source code after this node in the codebase. - - - -str } - description="The source code to insert." - defaultValue="" -/> -bool, optional } - description="Adjust indentation to match current text." - defaultValue="False" -/> -bool, optional } - description="Add a newline before the inserted code." - defaultValue="True" -/> -int, optional } - description="Priority of the edit operation." - defaultValue="0" -/> -bool, optional } - description="Deduplicate identical edits." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts source code before this symbol group. - - - -str } - description="The source code to insert." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of the inserted code to match the current code. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline after the inserted code. Defaults to True." - defaultValue="True" -/> -int, optional } - description="The priority of this edit operation. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to prevent duplicate insertions of the same code. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Removes an element from a Collection. - - - -Editable | None } - description="The element to remove from the Collection. If None, delegates to parent class." - defaultValue="None" -/> - - - -None } description="This method doesn't return anything."/> - - -### replace -Replaces all instances of a string with a new string in all symbols within the group. - - - -str } - description="The string to be replaced." - defaultValue="" -/> -str } - description="The string to replace with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="Number of replacements made."/> - - -### search -Searches for regex matches in the codebase. - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool, optional } - description="Whether to include string literals in the search. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to include comments in the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects representing matched text nodes in the codebase."/> - - - diff --git a/docs/_deprecated/api-reference/core/Unpack.mdx b/docs/_deprecated/api-reference/core/Unpack.mdx deleted file mode 100644 index f76a0b397..000000000 --- a/docs/_deprecated/api-reference/core/Unpack.mdx +++ /dev/null @@ -1,459 +0,0 @@ ---- -title: "Unpack" -sidebarTitle: "Unpack" -icon: "" -description: "Unpacking of an iterable. Example: ```python [a, *b] ```" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[HasValue](/api-reference/core/HasValue), [Unwrappable](/api-reference/core/Unwrappable), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### value - -Expression | None } description="Gets the value node of the object." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ Unpack ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ Unpack ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ Unpack ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### resolve -Resolves the wrapper expression and returns the first concrete expression. - - - -Expression } description=""/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_value -Sets the value of the node's value Expression. - - - -str } - description="The new value to set." - defaultValue="" -/> - - - -None } description=""/> - - -### unwrap -Unwraps a node's content into its parent node. - - - -Expression | None } - description="The node to unwrap. If None, uses the instance's value node." - defaultValue="None" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/core/Unwrappable.mdx b/docs/_deprecated/api-reference/core/Unwrappable.mdx deleted file mode 100644 index 297c8cbca..000000000 --- a/docs/_deprecated/api-reference/core/Unwrappable.mdx +++ /dev/null @@ -1,421 +0,0 @@ ---- -title: "Unwrappable" -sidebarTitle: "Unwrappable" -icon: "" -description: "An abstract representation of an expression that can be unwrapped. Expressions that can be unwrapped include binary expressions and ternary expressions." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ Unwrappable ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ Unwrappable ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ Unwrappable ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### unwrap -Unwrap this expression, removing parenthesis and other syntax elements while maintaining the function of the code. - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/core/Usable.mdx b/docs/_deprecated/api-reference/core/Usable.mdx deleted file mode 100644 index 2a61b45d9..000000000 --- a/docs/_deprecated/api-reference/core/Usable.mdx +++ /dev/null @@ -1,526 +0,0 @@ ---- -title: "Usable" -sidebarTitle: "Usable" -icon: "" -description: "An interface for any node object that can be referenced by another node." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Importable](/api-reference/core/Importable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ Symbol , Import ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ Usable ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ Usable ] } description=""/> - - -### get_name -Returns the name node of the object. - - - -Name | ChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ Usable ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Renames a symbol and updates all its references in the codebase. - - - -str } - description="The new name for the symbol." - defaultValue="" -/> -int } - description="Priority of the edit operation. Defaults to 0." - defaultValue="0" -/> - - - -tuple[NodeId, NodeId] } description="A tuple containing the file node ID and the new node ID of the renamed symbol."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ Import | Symbol | TSExport ] } description="A list of symbols that use or import the exportable object."/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/core/Usage.mdx b/docs/_deprecated/api-reference/core/Usage.mdx deleted file mode 100644 index 25c0f5e79..000000000 --- a/docs/_deprecated/api-reference/core/Usage.mdx +++ /dev/null @@ -1,40 +0,0 @@ ---- -title: "Usage" -sidebarTitle: "Usage" -icon: "" -description: "A reference to an exportable object in a file." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - - -## Attributes - -### imported_by - -Import | None } description="The import statement that brought this symbol into scope, or None if not imported" /> - -### kind - -UsageKind } description="Where this symbol was used (IE: in a type parameter or in the body of the class, etc)" /> - -### match - -Name | ChainedAttribute | FunctionCall } description="The exact match of the usage" /> - -### usage_symbol - -Import | Symbol | TSExport | SourceFile } description="The symbol this object is used in" /> - -### usage_type - -UsageType } description="How this symbol was used" /> - - - diff --git a/docs/_deprecated/api-reference/core/UsageKind.mdx b/docs/_deprecated/api-reference/core/UsageKind.mdx deleted file mode 100644 index b71860ec2..000000000 --- a/docs/_deprecated/api-reference/core/UsageKind.mdx +++ /dev/null @@ -1,72 +0,0 @@ ---- -title: "UsageKind" -sidebarTitle: "UsageKind" -icon: "" -description: "SymbolUsageType is an enumeration class that defines different types of symbol usage within Python code." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - - -## Attributes - -### BODY - - } description="Usage within the body of a function/method." /> - -### DECORATOR - - } description="Usage within a decorator." /> - -### DEFAULT_VALUE - - } description="Represents a default value in a function/method parameter." /> - -### EXPORTED_SYMBOL - - } description="Used in an export statement." /> - -### EXPORTED_WILDCARD - - } description="Re-exported by a wildcard export." /> - -### GENERIC - - } description="Used as a type parameter to another type." /> - -### IMPORTED - - } description="Imported with an import statement." /> - -### IMPORTED_WILDCARD - - } description="Imported with a wildcard import statement." /> - -### RETURN_TYPE - - } description="Used as a return type annotation." /> - -### SUBCLASS - - } description="Used in symbol inheritance." /> - -### TYPED_PARAMETER - - } description="Used as a typed parameter in a function/method." /> - -### TYPE_ANNOTATION - - } description="Used as a type annotation on a parameter or assignment statement." /> - -### TYPE_DEFINITION - - } description="Used in a type alias." /> - - - diff --git a/docs/_deprecated/api-reference/core/UsageType.mdx b/docs/_deprecated/api-reference/core/UsageType.mdx deleted file mode 100644 index 4455a7ecd..000000000 --- a/docs/_deprecated/api-reference/core/UsageType.mdx +++ /dev/null @@ -1,36 +0,0 @@ ---- -title: "UsageType" -sidebarTitle: "UsageType" -icon: "" -description: "Describes how a symbol is used elsewhere. Used in conjunction with get_usages" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - - -## Attributes - -### ALIASED - - } description="Aliased indirect usages" /> - -### CHAINED - - } description="Chained references (ie: module.foo)" /> - -### DIRECT - - } description="Direct imports and usages within the same file" /> - -### INDIRECT - - } description=" Indirect usages with the same name" /> - - - diff --git a/docs/_deprecated/api-reference/core/Value.mdx b/docs/_deprecated/api-reference/core/Value.mdx deleted file mode 100644 index 5dc12a5fc..000000000 --- a/docs/_deprecated/api-reference/core/Value.mdx +++ /dev/null @@ -1,413 +0,0 @@ ---- -title: "Value" -sidebarTitle: "Value" -icon: "" -description: "Editable attribute on code objects that has a value. For example, Functions, Classes, Assignments, Interfaces, Expressions, Arguments and Parameters all have values. See also HasValue." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ Value ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ Value ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ Value ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/core/WhileStatement.mdx b/docs/_deprecated/api-reference/core/WhileStatement.mdx deleted file mode 100644 index cb968e554..000000000 --- a/docs/_deprecated/api-reference/core/WhileStatement.mdx +++ /dev/null @@ -1,485 +0,0 @@ ---- -title: "WhileStatement" -sidebarTitle: "WhileStatement" -icon: "" -description: "Abstract representation of the while statement block." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[HasBlock](/api-reference/core/HasBlock), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### code_block - -CodeBlock } description="The code block that represents the body of the while statement." /> - -### condition - -Expression [ WhileStatement ] } description="The condition expression of the while statement." /> - -### decorators - -list[ Decorator ] } description="Returns list of all decorators on this Symbol." /> - -### docstring - -CommentGroup | None } description="Retrieves the docstring of the expression." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -SourceFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns all function calls within the while statement block." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### is_decorated - -bool } description="Check if the symbol has decorators." /> - -### nested_code_blocks - -list[ CodeBlock ] } description="Returns all nested CodeBlocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ WhileStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -Class | None } description="Find the class this node is contained in" /> - -### parent_function - -Function | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ WhileStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ WhileStatement ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ WhileStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_docstring -Sets or updates the docstring for the current entity. - - - -str } - description="The new docstring content to set." - defaultValue="" -/> - - - -None } description="This method doesn't return anything."/> - - - diff --git a/docs/_deprecated/api-reference/core/WithStatement.mdx b/docs/_deprecated/api-reference/core/WithStatement.mdx deleted file mode 100644 index 12a8ee11f..000000000 --- a/docs/_deprecated/api-reference/core/WithStatement.mdx +++ /dev/null @@ -1,503 +0,0 @@ ---- -title: "WithStatement" -sidebarTitle: "WithStatement" -icon: "" -description: "Pythons implementation of the with statement. Examples: with feature_flag_enabled(...): # code block with open(\"file.txt\") as file: # code block with (context_manager1 as var1, context_manager2 as var2, context_manager3 as var3): # code block" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[PyHasBlock](/api-reference/python/PyHasBlock), [Statement](/api-reference/core/Statement), [HasBlock](/api-reference/core/HasBlock), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### clause - -ExpressionGroup } description="The expression of the with clause." /> - -### code_block - -PyCodeBlock [ WithStatement ] } description="The code block of the with statement." /> - -### decorators - -list[ PyDecorator ] } description="Returns a list of decorators associated with this symbol." /> - -### docstring - -PyCommentGroup | None } description="Gets the function's docstring." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -PyFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns all function calls in the code block and within the with clause." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### is_decorated - -bool } description="Returns whether the symbol is decorated with decorators." /> - -### nested_code_blocks - -list[ PyCodeBlock ] } description="Returns all nested code blocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ WithStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -PyClass | None } description="Find the class this node is contained in" /> - -### parent_function - -PyFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ WithStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ WithStatement ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ WithStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_docstring -Sets or updates a docstring for a Python function or class. - - - -str } - description="The docstring content to set." - defaultValue="" -/> -bool, optional } - description="Whether to format the text into a proper docstring format. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to clean and normalize the docstring format before insertion. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to force single-line comments to be converted to multi-line format. Defaults to False." - defaultValue="False" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/index.mdx b/docs/_deprecated/api-reference/index.mdx deleted file mode 100644 index b674d0941..000000000 --- a/docs/_deprecated/api-reference/index.mdx +++ /dev/null @@ -1,81 +0,0 @@ ---- -title: "API Reference" -sidebarTitle: "Overview" -icon: "book-bookmark" -iconType: "solid" ---- - -Welcome to the Codegen API reference. This documentation covers the core classes and functions available in Codegen. - -## Core Classes - - - - The main entry point for analyzing and transforming code. Provides access to - files, functions, and the call graph. - - - Work with source files, their ASTs, and manage imports/exports. - - - Represents a function in your codebase. Analyze parameters, return types, - and call sites. - - - Represents a symbol in your codebase, includes functions, classes, and more. - - - -## Language Support - - - - Python-specific APIs and utilities for working with Python codebases. - - - TypeScript and JavaScript support, including React component analysis. - - - -## Common Operations - -### Code Analysis - -- [Finding Functions](/api-reference/core/Codebase#get-function) -- [Analyzing Dependencies](/api-reference/core/Symbol#dependencies) -- [Analyzing Usages](/api-reference/core/Symbol#usages) - -### Code Transformation - -- [Editing Files](/api-reference/core/File#edit) -- [Managing Imports](/api-reference/core/SourceFile#add-import-from-import-string) -- [Renaming Symbols](/api-reference/core/Symbol#set-name) -- [Managing Return Types](/api-reference/core/Function#set-return-type) -- [Moving Code](/api-reference/core/Symbol#move-to-file) - -### React & TypeScript - -- [JSX Components](/api-reference/typescript/JSXElement) -- [Props & State](/api-reference/typescript/JSXProp) -- [Type Aliases](/api-reference/typescript/TSTypeAlias) - - - Each class and function includes detailed examples and common use cases. Use - the sidebar navigation to explore specific APIs. - - -## Getting Started - -If you're new to Codegen, we recommend: - -1. Following the [Getting Started](/introduction/getting-started) guide -2. Exploring the [Tutorials](/tutorials/at-a-glance) -3. Looking at example codemods in our [GitHub repository](https://github.com/codegen-sh/codegen-sdk/tree/main/examples) - - - Use the search bar (⌘ K) to quickly find specific APIs and functionality. - diff --git a/docs/_deprecated/api-reference/python/PyAssignment.mdx b/docs/_deprecated/api-reference/python/PyAssignment.mdx deleted file mode 100644 index c791e6655..000000000 --- a/docs/_deprecated/api-reference/python/PyAssignment.mdx +++ /dev/null @@ -1,838 +0,0 @@ ---- -title: "PyAssignment" -sidebarTitle: "PyAssignment" -icon: "" -description: "An abstract representation of a assignment in python. This includes assignments of variables to functions, other variables, class instantiations, etc." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[PySymbol](/api-reference/python/PySymbol), [Assignment](/api-reference/core/Assignment), [Symbol](/api-reference/core/Symbol), [HasValue](/api-reference/core/HasValue), [Typeable](/api-reference/core/Typeable), [Usable](/api-reference/core/Usable), [Importable](/api-reference/core/Importable), [Editable](/api-reference/core/Editable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName) - -## Attributes - -### comment - -PyCommentGroup | None } description="Returns the comment group associated with the symbol." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_nodes - -list[ Editable ] } description="Returns a list of Editable nodes associated with this symbol, including extended symbols." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -PyFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### index - -int } description="Returns the index of the assignment statement in its parent's code block." /> - -### inline_comment - -PyCommentGroup | None } description="A property that retrieves the inline comment group associated with a symbol." /> - -### is_exported - -bool } description="Indicates whether a Python symbol is exported." /> - -### is_local_variable - -bool } description="Determines if an assignment represents a local variable in the current scope." /> - -### is_typed - -bool } description="Indicates if a node has an explicit type annotation." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -PyClass | None } description="Find the class this node is contained in" /> - -### parent_function - -PyFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Returns the source code of the symbol." /> - -### symbol_type - - } description="The type of symbol, set to SymbolType.GlobalVar." /> - -### type - -Type | TypePlaceholder [ PyAssignment ] } description="The type annotation associated with this node" /> - -### value - -Expression | None } description="Gets the value node of the object." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_comment -Adds a new comment to the symbol. - - - -str } - description="The comment text to be added." - defaultValue="" -/> -bool } - description="Whether to automatically format the text into a proper comment format." - defaultValue="True" -/> -bool } - description="Whether to clean and normalize the comment text before adding." - defaultValue="True" -/> -PyCommentType } - description="The style of comment to add (e.g., single-line, multi-line)." - defaultValue="PyCommentType.SINGLE_LINE" -/> - - - -None } description=""/> - - -### add_keyword -Insert a keyword in the appropriate place before this symbol if it doesn't already exist. - - - -str } - description="The keyword to be inserted. Must be a valid keyword in the language context." - defaultValue="" -/> - - - -None } description=""/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ PySymbol , PyImport ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this node with new_src. - - - -str } - description="The new source code to replace the current source with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, prevents duplicate edits. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ PyAssignment ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Flags a Python symbol by adding a flag comment and returning a CodeFlag. - - - -CodeFlag[ PyAssignment ] } description="The code flag object for tracking purposes"/> - - -### from_named_expression -Creates a MultiExpression from a Python named expression. - - - -TSNode } - description="The TreeSitter node representing the named expression." - defaultValue="" -/> -NodeId } - description="The identifier of the file containing this node." - defaultValue="" -/> -CodebaseContext } - description="The codebase context instance." - defaultValue="" -/> -Editable } - description="The parent node that contains this expression." - defaultValue="" -/> - - - -MultiExpression [ PyAssignmentStatement , PyAssignment ] } description="A MultiExpression containing the assignments created from the named expression."/> - - -### get_import_string -Generates an import string for a Python symbol. - - - -str | None } - description="Optional alias name for the import. If provided and different from symbol name, creates aliased import." - defaultValue="None" -/> -str | None } - description="Optional module name to import from. If not provided, uses the symbol's file's module name." - defaultValue="None" -/> -ImportType } - description="Type of import to generate. If WILDCARD, generates star import. Defaults to UNKNOWN." - defaultValue="ImportType.UNKNOWN" -/> -bool } - description="Whether this is a type import. Currently unused. Defaults to False." - defaultValue="False" -/> - - - -str } description="The formatted import string. Will be one of: - "from {module} import * as {file_name}" (for WILDCARD imports) - "from {module} import {name} as {alias}" (for aliased imports) - "from {module} import {name}" (for standard imports)"/> - - -### get_name -Returns the name node of the object. - - - -Name | PyChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ PyAssignment ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before the current symbol node in the Abstract Syntax Tree. - - - -str } - description="The source code text to insert." - defaultValue="" -/> -bool } - description="Whether to adjust the indentation of new_src to match current text. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after insertion. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to remove duplicate insertions. Defaults to True." - defaultValue="True" -/> -bool } - description="Whether to insert before extended nodes like comments and decorators. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### local_usages -Retrieves all usages of the assigned variable within its code block scope. - - - -list[ Editable [ Statement ]] } description="A sorted list of statement nodes where the variable is used."/> - - -### move_to_file -Moves the given symbol to a new file and updates its imports and references. - - - -PyFile } - description="The destination file to move the symbol to." - defaultValue="" -/> -bool } - description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." - defaultValue="True" -/> -str } - description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." - defaultValue=""update_all_imports"" -/> - - - -None } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Simplifies an assignment expression by reducing it based on a boolean condition and updating all the usages. - - - -bool } - description="The boolean value to reduce the condition to." - defaultValue="" -/> - - - -None } description=""/> - - -### remove -Deletes this assignment and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Renames a symbol and updates all its references in the codebase. - - - -str } - description="The new name for the symbol." - defaultValue="" -/> -int } - description="Priority of the edit operation. Defaults to 0." - defaultValue="0" -/> - - - -tuple[NodeId, NodeId] } description="A tuple containing the file node ID and the new node ID of the renamed symbol."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_comment -Sets a comment for the Python symbol. - - - -str } - description="The comment text to be added or set." - defaultValue="" -/> -bool, optional } - description="If True, automatically formats the text as a comment." - defaultValue="True" -/> -bool, optional } - description="If True, cleans the format of the comment before" - defaultValue="True" -/> -PyCommentType , optional } - description="Type of comment to add (e.g., single line," - defaultValue="PyCommentType.SINGLE_LINE" -/> - - - -None } description="This method modifies the symbol's comment in place."/> - - -### set_inline_comment -Sets an inline comment to the symbol. - - - -str } - description="The inline comment text to add." - defaultValue="" -/> -bool, optional } - description="If True, formats the text into a proper inline" - defaultValue="True" -/> -bool, optional } - description="If True, cleans the comment text before insertion" - defaultValue="True" -/> - - - -None } description=""/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### set_type_annotation -Adds or updates a type annotation for the current assignment. - - - -str } - description="The type annotation to be added or updated." - defaultValue="" -/> - - - -None } description=""/> - - -### set_value -Sets the value of an assignment expression. - - - -str } - description="The source code string representing the new value to be assigned." - defaultValue="" -/> - - - -None } description=""/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ PyImport | PySymbol | Export ] } description="A list of symbols that use or import the exportable object."/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/python/PyAssignmentStatement.mdx b/docs/_deprecated/api-reference/python/PyAssignmentStatement.mdx deleted file mode 100644 index d7e32a31a..000000000 --- a/docs/_deprecated/api-reference/python/PyAssignmentStatement.mdx +++ /dev/null @@ -1,511 +0,0 @@ ---- -title: "PyAssignmentStatement" -sidebarTitle: "PyAssignmentStatement" -icon: "" -description: "A class that represents a Python assignment statement in a codebase, such as `x = 1` or `a, b = 1, 2`. This includes potentially multiple Assignments via `statement.assignments`, which represent each assignment of a value to a variable within this statement." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[AssignmentStatement](/api-reference/core/AssignmentStatement), [HasValue](/api-reference/core/HasValue), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### assignments - -list[ PyAssignment ] } description="A list of assignments within the statement." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -PyFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### left - -Expression [ PyAssignment ] } description="The left-hand side expression of the first assignment." /> - -### nested_code_blocks - -list[ Editable ] } description="Returns all nested code blocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ PyAssignmentStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -PyClass | None } description="Find the class this node is contained in" /> - -### parent_function - -PyFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### right - -Expression [ PyAssignment ] | None } description="The right-hand side expression of the first assignment, or None if not applicable." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### value - -Expression | None } description="Gets the value node of the object." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ PyAssignmentStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ PyAssignmentStatement ] } description=""/> - - -### from_assignment -Creates a PyAssignmentStatement instance from a TreeSitter assignment node. - - - -TSNode } - description="The TreeSitter node representing the entire statement." - defaultValue="" -/> -NodeId } - description="The ID of the file containing this node." - defaultValue="" -/> -CodebaseContext } - description="The codebase context instance." - defaultValue="" -/> -PyHasBlock } - description="The parent block containing this statement." - defaultValue="" -/> -PyCodeBlock } - description="The code block containing this statement." - defaultValue="" -/> -int } - description="The position of this statement within its code block." - defaultValue="" -/> -TSNode } - description="The TreeSitter node representing the assignment operation." - defaultValue="" -/> - - - -PyAssignmentStatement } description="A new assignment statement instance, either PyAttribute or PyAssignmentStatement."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ PyAssignmentStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_value -Sets the value of the node's value Expression. - - - -str } - description="The new value to set." - defaultValue="" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/python/PyAttribute.mdx b/docs/_deprecated/api-reference/python/PyAttribute.mdx deleted file mode 100644 index 997fddd52..000000000 --- a/docs/_deprecated/api-reference/python/PyAttribute.mdx +++ /dev/null @@ -1,644 +0,0 @@ ---- -title: "PyAttribute" -sidebarTitle: "PyAttribute" -icon: "" -description: "Python implementation of Attribute detached symbol." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[PyAssignmentStatement](/api-reference/python/PyAssignmentStatement), [Attribute](/api-reference/core/Attribute), [AssignmentStatement](/api-reference/core/AssignmentStatement), [Usable](/api-reference/core/Usable), [HasValue](/api-reference/core/HasValue), [Statement](/api-reference/core/Statement), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName) - -## Attributes - -### assignment - -PyAssignment } description="The assignment associated with the attribute." /> - -### assignments - -list[ PyAssignment ] } description="A list of assignments within the statement." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -PyFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### is_optional - -bool } description="Check if the attribute is optional." /> - -### is_private - -bool } description="Determines if this attribute is private by checking if its name starts with an underscore." /> - -### left - -Expression [ PyAssignment ] } description="The left-hand side expression of the first assignment." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### nested_code_blocks - -list[ Editable ] } description="Returns all nested code blocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ PyAttribute ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -PyClass | None } description="Find the class this node is contained in" /> - -### parent_function - -PyFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### right - -Expression [ PyAssignment ] | None } description="The right-hand side expression of the first assignment, or None if not applicable." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### value - -Expression | None } description="Gets the value node of the object." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ PySymbol , PyImport ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ PyAttribute ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ PyAttribute ] } description=""/> - - -### from_assignment -Creates a PyAssignmentStatement instance from a TreeSitter assignment node. - - - -TSNode } - description="The TreeSitter node representing the entire statement." - defaultValue="" -/> -NodeId } - description="The ID of the file containing this node." - defaultValue="" -/> -CodebaseContext } - description="The codebase context instance." - defaultValue="" -/> -PyHasBlock } - description="The parent block containing this statement." - defaultValue="" -/> -PyCodeBlock } - description="The code block containing this statement." - defaultValue="" -/> -int } - description="The position of this statement within its code block." - defaultValue="" -/> -TSNode } - description="The TreeSitter node representing the assignment operation." - defaultValue="" -/> - - - -PyAssignmentStatement } description="A new assignment statement instance, either PyAttribute or PyAssignmentStatement."/> - - -### get_name -Returns the name node of the object. - - - -Name | PyChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ PyAttribute ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### local_usages -Returns all instances where this attribute is used within its parent code block. - - - -list[ Editable [ PyAttribute ]] } description="A sorted list of unique attribute references. Each reference is an Editable object representing a usage of this attribute."/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Renames a symbol and updates all its references in the codebase. - - - -str } - description="The new name for the symbol." - defaultValue="" -/> -int } - description="Priority of the edit operation. Defaults to 0." - defaultValue="0" -/> - - - -tuple[NodeId, NodeId] } description="A tuple containing the file node ID and the new node ID of the renamed symbol."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### set_value -Sets the value of a node's assignment. - - - -str } - description="The new value to set for the assignment." - defaultValue="" -/> - - - -None } description=""/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ PyImport | PySymbol | Export ] } description="A list of symbols that use or import the exportable object."/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/python/PyBlockStatement.mdx b/docs/_deprecated/api-reference/python/PyBlockStatement.mdx deleted file mode 100644 index 03d85ea69..000000000 --- a/docs/_deprecated/api-reference/python/PyBlockStatement.mdx +++ /dev/null @@ -1,499 +0,0 @@ ---- -title: "PyBlockStatement" -sidebarTitle: "PyBlockStatement" -icon: "" -description: "Statement which contains a block." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[PyHasBlock](/api-reference/python/PyHasBlock), [BlockStatement](/api-reference/core/BlockStatement), [HasBlock](/api-reference/core/HasBlock), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### code_block - -PyCodeBlock | None } description="The code block contained within the statement, if it exists." /> - -### decorators - -list[ PyDecorator ] } description="Returns a list of decorators associated with this symbol." /> - -### docstring - -PyCommentGroup | None } description="Gets the function's docstring." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -PyFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Gets all function calls within the statement's code block." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### is_decorated - -bool } description="Returns whether the symbol is decorated with decorators." /> - -### nested_code_blocks - -list[ PyCodeBlock ] } description="Returns all nested CodeBlocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ PyBlockStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -PyClass | None } description="Find the class this node is contained in" /> - -### parent_function - -PyFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ PyBlockStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ PyBlockStatement ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ PyBlockStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_docstring -Sets or updates a docstring for a Python function or class. - - - -str } - description="The docstring content to set." - defaultValue="" -/> -bool, optional } - description="Whether to format the text into a proper docstring format. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to clean and normalize the docstring format before insertion. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to force single-line comments to be converted to multi-line format. Defaults to False." - defaultValue="False" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/python/PyBreakStatement.mdx b/docs/_deprecated/api-reference/python/PyBreakStatement.mdx deleted file mode 100644 index 9a2e63bec..000000000 --- a/docs/_deprecated/api-reference/python/PyBreakStatement.mdx +++ /dev/null @@ -1,425 +0,0 @@ ---- -title: "PyBreakStatement" -sidebarTitle: "PyBreakStatement" -icon: "" -description: "An abstract representation of a python break statement." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -PyFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### nested_code_blocks - -list[ Editable ] } description="Returns all nested code blocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ PyBreakStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -PyClass | None } description="Find the class this node is contained in" /> - -### parent_function - -PyFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ PyBreakStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ PyBreakStatement ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ PyBreakStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/python/PyCatchStatement.mdx b/docs/_deprecated/api-reference/python/PyCatchStatement.mdx deleted file mode 100644 index 19a560d9b..000000000 --- a/docs/_deprecated/api-reference/python/PyCatchStatement.mdx +++ /dev/null @@ -1,503 +0,0 @@ ---- -title: "PyCatchStatement" -sidebarTitle: "PyCatchStatement" -icon: "" -description: "Python catch clause." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[PyBlockStatement](/api-reference/python/PyBlockStatement), [CatchStatement](/api-reference/core/CatchStatement), [PyHasBlock](/api-reference/python/PyHasBlock), [BlockStatement](/api-reference/core/BlockStatement), [HasBlock](/api-reference/core/HasBlock), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### code_block - -PyCodeBlock | None } description="The code block contained within the statement, if it exists." /> - -### condition - -Expression [ PyCatchStatement ] | None } description="The condition which triggers this clause" /> - -### decorators - -list[ PyDecorator ] } description="Returns a list of decorators associated with this symbol." /> - -### docstring - -PyCommentGroup | None } description="Gets the function's docstring." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -PyFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Gets all function calls within the statement's code block." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### is_decorated - -bool } description="Returns whether the symbol is decorated with decorators." /> - -### nested_code_blocks - -list[ PyCodeBlock ] } description="Returns all nested CodeBlocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ PyCatchStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -PyClass | None } description="Find the class this node is contained in" /> - -### parent_function - -PyFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ PyCatchStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ PyCatchStatement ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ PyCatchStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_docstring -Sets or updates a docstring for a Python function or class. - - - -str } - description="The docstring content to set." - defaultValue="" -/> -bool, optional } - description="Whether to format the text into a proper docstring format. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to clean and normalize the docstring format before insertion. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to force single-line comments to be converted to multi-line format. Defaults to False." - defaultValue="False" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/python/PyChainedAttribute.mdx b/docs/_deprecated/api-reference/python/PyChainedAttribute.mdx deleted file mode 100644 index 218658332..000000000 --- a/docs/_deprecated/api-reference/python/PyChainedAttribute.mdx +++ /dev/null @@ -1,429 +0,0 @@ ---- -title: "PyChainedAttribute" -sidebarTitle: "PyChainedAttribute" -icon: "" -description: "Abstract representation of a python chained attribute. This includes methods of python classes and module functions." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[ChainedAttribute](/api-reference/core/ChainedAttribute), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### attribute - -PyAttribute } description="Gets the attribute being accessed in a chained attribute expression." /> - -### attribute_chain - -list[ FunctionCall | Name ] } description="Returns a list of elements in a chained attribute expression." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -PyFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str } description="Returns the full name of the attribute, including the object expression." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### object - -Object } description="Returns the object that contains the attribute being looked up." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -PyClass | None } description="Find the class this node is contained in" /> - -### parent_function - -PyFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ PyChainedAttribute ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ PyChainedAttribute ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ PyChainedAttribute ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/python/PyClass.mdx b/docs/_deprecated/api-reference/python/PyClass.mdx deleted file mode 100644 index dee8ebc11..000000000 --- a/docs/_deprecated/api-reference/python/PyClass.mdx +++ /dev/null @@ -1,1127 +0,0 @@ ---- -title: "PyClass" -sidebarTitle: "PyClass" -icon: "" -description: "Extends Class for Python codebases" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[PyHasBlock](/api-reference/python/PyHasBlock), [PySymbol](/api-reference/python/PySymbol), [Class](/api-reference/core/Class), [HasBlock](/api-reference/core/HasBlock), [Symbol](/api-reference/core/Symbol), [Callable](/api-reference/core/Callable), [Expression](/api-reference/core/Expression), [Usable](/api-reference/core/Usable), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [HasName](/api-reference/core/HasName) - -## Attributes - -### call_sites - -list[ FunctionCall ] } description="Returns all call sites (invocations) of this callable in the codebase." /> - -### code_block - -PyCodeBlock } description="The block of code associated with the code object." /> - -### comment - -PyCommentGroup | None } description="Retrieves the comment group associated with a Python symbol." /> - -### constructor - -PyFunction | None } description="Returns the constructor method for this class." /> - -### decorators - -list[ PyDecorator ] } description="Returns a list of decorators associated with this symbol." /> - -### docstring - -PyCommentGroup | None } description="Gets the function's docstring." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_nodes - -list[ Editable ] } description="Returns a list of Editable nodes associated with this symbol, including extended symbols." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -PyFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns all function calls within the code block and its decorators." /> - -### inline_comment - -PyCommentGroup | None } description="Returns the inline comment group associated with this symbol." /> - -### is_decorated - -bool } description="Returns whether the symbol is decorated with decorators." /> - -### is_exported - -bool } description="Indicates whether a Python symbol is exported." /> - -### is_subclass - -bool } description="Indicates whether the current class is a subclass of another class." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### nested_classes - -list[ PyClass ] } description="Retrieves the nested classes defined within this class." /> - -### parameters - -SymbolGroup [ PyParameter , PyClass ] | list[ PyParameter ] } description="Retrieves all parameters of a callable symbol." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -PyClass | None } description="Find the class this node is contained in" /> - -### parent_class_names - -list[ Name | PyChainedAttribute ] } description="Returns a list of the parent class names that this class inherits from." /> - -### parent_classes - -Parents[ Type , PyClass ] | None } description="The parent classes of this class, if any." /> - -### parent_function - -PyFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### return_type - -Type | Placeholder [ PyClass ] } description="The type of value returned by the callable, or a placeholder." /> - -### source - -str } description="Returns the source code of the symbol." /> - -### symbol_type - - } description="The type of symbol, set to SymbolType.Class." /> - -### type_parameters - -TypeParameters[ Type , PyClass ] | None } description="The type parameters of the symbol, if any." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_attribute -Adds an attribute to a class from another class. - - - -PyAttribute } - description="The attribute to add to the class." - defaultValue="" -/> -bool, optional } - description="Whether to include the attribute's dependencies. If True, adds any necessary imports to the class's file. Defaults to False." - defaultValue="False" -/> - - - -None } description=""/> - - -### add_attribute_from_source -Adds an attribute to a class from raw source code, placing it in a specific location - - - -str } - description="The source code of the attribute to be added." - defaultValue="" -/> - - - -None } description=""/> - - -### add_comment -Adds a new comment to the symbol. - - - -str } - description="The comment text to be added." - defaultValue="" -/> -bool } - description="Whether to automatically format the text into a proper comment format." - defaultValue="True" -/> -bool } - description="Whether to clean and normalize the comment text before adding." - defaultValue="True" -/> -PyCommentType } - description="The style of comment to add (e.g., single-line, multi-line)." - defaultValue="PyCommentType.SINGLE_LINE" -/> - - - -None } description=""/> - - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### add_keyword -Insert a keyword in the appropriate place before this symbol if it doesn't already exist. - - - -str } - description="The keyword to be inserted. Must be a valid keyword in the language context." - defaultValue="" -/> - - - -None } description=""/> - - -### add_source -Adds source code to the class definition. - - - -str } - description="The source code to be added to the class definition. If the source doesn't" - defaultValue="" -/> - - - -None } description=""/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### attributes -Retrieves all attributes from this Class including those from its superclasses up to a - - - -int | None } - description="The maximum depth of superclass traversal. None means no limit, 0 means only this class." - defaultValue="0" -/> -bool } - description="Whether to include private attributes. Defaults to True." - defaultValue="True" -/> - - - -list[ PyAttribute ] } description="A list of unique attributes from this class and its superclasses. If an attribute is defined in multiple classes, the first definition encountered is used."/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ PySymbol , PyImport ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this node with new_src. - - - -str } - description="The new source code to replace the current source with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, prevents duplicate edits. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ PyClass ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Flags a Python symbol by adding a flag comment and returning a CodeFlag. - - - -CodeFlag[ PyClass ] } description="The code flag object for tracking purposes"/> - - -### get_attribute -Returns a specific attribute by name. - - - -str } - description="The name of the attribute to search for." - defaultValue="" -/> - - - -PyAttribute | None } description="The matching attribute if found, None otherwise. If multiple attributes with the same name exist in the inheritance hierarchy, returns the first one found."/> - - -### get_import_string -Generates an import string for a Python symbol. - - - -str | None } - description="Optional alias name for the import. If provided and different from symbol name, creates aliased import." - defaultValue="None" -/> -str | None } - description="Optional module name to import from. If not provided, uses the symbol's file's module name." - defaultValue="None" -/> -ImportType } - description="Type of import to generate. If WILDCARD, generates star import. Defaults to UNKNOWN." - defaultValue="ImportType.UNKNOWN" -/> -bool } - description="Whether this is a type import. Currently unused. Defaults to False." - defaultValue="False" -/> - - - -str } description="The formatted import string. Will be one of: - "from {module} import * as {file_name}" (for WILDCARD imports) - "from {module} import {name} as {alias}" (for aliased imports) - "from {module} import {name}" (for standard imports)"/> - - -### get_method -Returns a specific method by name from the class or any of its superclasses. - - - -str } - description="The name of the method to find." - defaultValue="" -/> - - - -PyFunction | None } description="The method if found, None otherwise."/> - - -### get_name -Returns the name node of the object. - - - -Name | PyChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_nested_class -Returns a nested class by name from the current class. - - - -str } - description="The name of the nested class to find." - defaultValue="" -/> - - - -PyClass | None } description="The nested class if found, None otherwise."/> - - -### get_parameter -Gets a specific parameter from the callable's parameters list by name. - - - -str } - description="The name of the parameter to retrieve." - defaultValue="" -/> - - - -PyParameter | None } description="The parameter with the specified name, or None if no parameter with that name exists or if there are no parameters."/> - - -### get_parameter_by_index -Returns the parameter at the given index. - - - -int } - description="The index of the parameter to retrieve." - defaultValue="" -/> - - - -PyParameter | None } description="The parameter at the specified index, or None if the parameter list is empty or the index does not exist."/> - - -### get_parameter_by_type -Retrieves a parameter from the callable by its type. - - - -PySymbol } - description="The type to search for." - defaultValue="" -/> - - - -PyParameter | None } description="The parameter with the specified type, or None if no parameter is found or if the callable has no parameters."/> - - -### get_parent_class -Returns the parent class node with the specified name. - - - -str } - description="The name of the parent class to find." - defaultValue="" -/> - - - -Editable | None } description="The matching parent class node, or None if no match is found."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ PyClass ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before the current symbol node in the Abstract Syntax Tree. - - - -str } - description="The source code text to insert." - defaultValue="" -/> -bool } - description="Whether to adjust the indentation of new_src to match current text. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after insertion. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to remove duplicate insertions. Defaults to True." - defaultValue="True" -/> -bool } - description="Whether to insert before extended nodes like comments and decorators. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_subclass_of -Checks if the class inherits from a specified parent class. - - - -str | PyClass } - description="The parent class to check for. Can be specified either as a class name string or Class object." - defaultValue="" -/> -int | None } - description="Maximum inheritance depth to search. None means no limit." - defaultValue="None" -/> - - - -bool } description="True if this class inherits from the parent class, False otherwise."/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### methods -Retrieves all methods that exist on this Class, including methods from superclasses, with - - - -int | None, optional } - description="Include parent classes up to max_depth. None means no limit, 0 means only current class. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to include private methods. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to include magic methods. Defaults to False." - defaultValue="True" -/> - - - -list[ PyFunction ] | MultiLineCollection [ PyFunction , PyClass ] } description=""/> - - -### move_to_file -Moves the given symbol to a new file and updates its imports and references. - - - -PyFile } - description="The destination file to move the symbol to." - defaultValue="" -/> -bool } - description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." - defaultValue="True" -/> -str } - description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." - defaultValue=""update_all_imports"" -/> - - - -None } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Renames a symbol and updates all its references in the codebase. - - - -str } - description="The new name for the symbol." - defaultValue="" -/> -int } - description="Priority of the edit operation. Defaults to 0." - defaultValue="0" -/> - - - -tuple[NodeId, NodeId] } description="A tuple containing the file node ID and the new node ID of the renamed symbol."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_comment -Sets a comment for the Python symbol. - - - -str } - description="The comment text to be added or set." - defaultValue="" -/> -bool, optional } - description="If True, automatically formats the text as a comment." - defaultValue="True" -/> -bool, optional } - description="If True, cleans the format of the comment before" - defaultValue="True" -/> -PyCommentType , optional } - description="Type of comment to add (e.g., single line," - defaultValue="PyCommentType.SINGLE_LINE" -/> - - - -None } description="This method modifies the symbol's comment in place."/> - - -### set_docstring -Sets or updates a docstring for a Python function or class. - - - -str } - description="The docstring content to set." - defaultValue="" -/> -bool, optional } - description="Whether to format the text into a proper docstring format. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to clean and normalize the docstring format before insertion. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to force single-line comments to be converted to multi-line format. Defaults to False." - defaultValue="False" -/> - - - -None } description=""/> - - -### set_inline_comment -Sets an inline comment to the symbol. - - - -str } - description="The inline comment text to add." - defaultValue="" -/> -bool, optional } - description="If True, formats the text into a proper inline" - defaultValue="True" -/> -bool, optional } - description="If True, cleans the comment text before insertion" - defaultValue="True" -/> - - - -None } description=""/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### subclasses -Returns all classes which subclass this class. - - - -int | None, optional } - description="Maximum inheritance depth to search. If None, searches all depths. Defaults to None." - defaultValue="None" -/> - - - -list[ PyClass ] } description="A list of Class objects that inherit from this class."/> - - -### superclasses -Returns a list of all classes that this class extends, up to max_depth. - - - -int | None } - description="The maximum depth to traverse up the inheritance tree. If None, traverses the entire tree." - defaultValue="None" -/> - - - -list[ PyClass | ExternalModule | Interface ] } description="A list of all superclass symbols in MRO order, up to max_depth. Returns an empty list if the class has no parent classes."/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ PyImport | PySymbol | Export ] } description="A list of symbols that use or import the exportable object."/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/python/PyCodeBlock.mdx b/docs/_deprecated/api-reference/python/PyCodeBlock.mdx deleted file mode 100644 index 904f9f31a..000000000 --- a/docs/_deprecated/api-reference/python/PyCodeBlock.mdx +++ /dev/null @@ -1,633 +0,0 @@ ---- -title: "PyCodeBlock" -sidebarTitle: "PyCodeBlock" -icon: "" -description: "Extends CodeBlock for Python codebases." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[CodeBlock](/api-reference/core/CodeBlock), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### assignment_statements - -list[ PyAssignmentStatement [ PyCodeBlock , PyAssignment ]] } description="Returns list of top level assignment statements in the code block." /> - -### assignments - -list[ PyAssignment [ Editable , PyCodeBlock ]] } description="Returns all assignments in the code block across all nesting levels." /> - -### attributes - -list[ PyAttribute [ Editable , PyCodeBlock ]] } description="Returns a list of top level class attribute statements in the code block." /> - -### comments - -list[ PyComment [ Editable , PyCodeBlock ]] } description="Gets list of top level comments in the code block." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -PyFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls in the code block." /> - -### if_blocks - -list[ PyIfBlockStatement [ PyCodeBlock ]] } description="Returns a list of top level if statements in the code block." /> - -### level - -int } description="The indentation level of the code block." /> - -### local_var_assignments - -list[ PyAssignment [ Editable , PyCodeBlock ]] } description="Returns all local variable assignment in the code block, for all nest levels." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_block - -PyCodeBlock | None } description="The parent code block containing this block, or None if it is a top-level block." /> - -### parent_class - -PyClass | None } description="Find the class this node is contained in" /> - -### parent_function - -PyFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### return_statements - -list[ ReturnStatement [ PyCodeBlock ]] } description="Gets all return statements at the top level of the code block." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### statements - -MultiLineCollection [ Statement , PyCodeBlock ] } description="Gets a view of the top-level statements in the code block." /> - -### symbol_statements - -list[ SymbolStatement ] } description="Returns list of top level symbol statements in the code block." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - -### with_statements - -list[ WithStatement ] } description="Returns a list of all 'with' statements within the code block." /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ PyCodeBlock ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ PyCodeBlock ] } description=""/> - - -### get_assignments -Returns a list of assignments with the specified variable name. - - - -str } - description="The name of the variable to find assignments for." - defaultValue="" -/> - - - -list[ PyAssignment [ Editable , PyCodeBlock ]] } description="A list of Assignment objects that match the variable name."/> - - -### get_attributes -Returns attributes from the code block, with the option to include or exclude private - - - -bool } - description="Whether to include private attributes in the returned list. If True, returns both private and" - defaultValue="" -/> - - - -list[ PyAttribute [ Editable , PyCodeBlock ]] } description="A list of attribute statements matching the privacy criteria."/> - - -### get_comment -Gets the first comment statement containing a specific text string. - - - -str } - description="The text string to search for within comment statements." - defaultValue="" -/> - - - -PyComment [ Editable , PyCodeBlock ] | None } description="The first comment statement containing the search text, or None if no matching comment is found."/> - - -### get_local_var_assignment -Returns the first code statement that assigns a local variable with the specified name. - - - -str } - description="The name of the local variable to search for." - defaultValue="" -/> - - - -PyAssignment [ Editable , PyCodeBlock ] | None } description="The first matching local variable assignment, or None if no match is found."/> - - -### get_local_var_assignments -Returns all instances of local variable assignments that match the specified variable - - - -str } - description="The name of the local variable to search for." - defaultValue="" -/> -bool, optional } - description="If True, matches variables whose names contain var_name." - defaultValue="False" -/> - - - -list[ PyAssignment [ Editable , PyCodeBlock ]] } description="List of Assignment objects representing local variable assignments that match the specified name criteria."/> - - -### get_statements -Returns all statements of a given type up to the specified block level. - - - -StatementType | None } - description="The type of statements to return. If None, returns all statement types." - defaultValue="None" -/> -int | None } - description="The maximum block depth level to search. If None, searches all levels." - defaultValue="None" -/> - - - -list[ Statement [ PyCodeBlock ]] } description=""/> - - -### get_variable_usages -Returns all instances of variable usages in a code block. - - - -str } - description="The name of the variable to search for." - defaultValue="" -/> -bool } - description="When True, matches on variable names that contain var_name. When False (default), only matches exact variable names." - defaultValue="False" -/> - - - -list[ Editable [ PyCodeBlock ]] } description="A sorted list of variable usage instances as Editable objects."/> - - -### get_with_statements -Gets with statements at a specific block level. - - - -int } - description="The block level to filter by. 0 represents the top level." - defaultValue="" -/> - - - -list[ WithStatement ] } description="A list of WithStatement objects at the specified block level."/> - - -### indent -Adjusts the indentation level of the entire code block. - - - -int } - description="The number of indentation levels to adjust. Positive values indent right, negative values indent left." - defaultValue="" -/> - - - -None } description=""/> - - -### insert_after -Inserts source code at the bottom of the code block. - - - -str } - description="The source code to insert." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of the inserted code. Defaults to True." - defaultValue="True" -/> -bool } - description="Whether to add a newline before the inserted code. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts new source code at the top of the code block. - - - -str } - description="The source code to insert at the top of the code block." - defaultValue="" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename_variable_usages -Renames all instances of variable usages in the code block. - - - -str } - description="The current name of the variable to rename." - defaultValue="" -/> -str } - description="The new name to give the variable." - defaultValue="" -/> -bool } - description="When True, matches variables containing old_var_name. When False, only exact matches. Defaults to False." - defaultValue="False" -/> - - - -None } description="This method mutates the code block in place."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### unwrap -Extracts a code block from its parent wrapper container by removing the wrapping - - - -None } description=""/> - - -### wrap -Wraps a code block with a statement and indents it. - - - -str } - description="The source code to insert before the block." - defaultValue="" -/> -str } - description="The source code to insert after the block. Defaults to an empty string." - defaultValue="""" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/python/PyComment.mdx b/docs/_deprecated/api-reference/python/PyComment.mdx deleted file mode 100644 index 596fa4560..000000000 --- a/docs/_deprecated/api-reference/python/PyComment.mdx +++ /dev/null @@ -1,506 +0,0 @@ ---- -title: "PyComment" -sidebarTitle: "PyComment" -icon: "" -description: "Abstract representation of python comments" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Comment](/api-reference/core/Comment), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### comment_type - -PyCommentType } description="Determines the type of Python comment based on its syntax." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -PyFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### google_style - -bool } description="Determines if a Python docstring follows Google style formatting." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### nested_code_blocks - -list[ PyCodeBlock ] } description="Returns a list of nested code blocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ PyComment ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -PyClass | None } description="Find the class this node is contained in" /> - -### parent_function - -PyFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### text - -str } description="Returns the text content of the comment." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### clean_comment -Cleans a comment block by removing comment symbols, leading/trailing whitespace, and standardizing indentation. - - - -str } - description="The raw comment block to be cleaned. Can be a single-line comment or multi-line docstring." - defaultValue="" -/> - - - -str } description="The cleaned comment text with comment symbols and excess whitespace removed."/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### edit_text -Replace the text of a comment with new text. - - - -str } - description="The new text content to replace the existing comment text." - defaultValue="" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ PyComment ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ PyComment ] } description=""/> - - -### generate_comment -Converts text content into a Python comment block. - - - -str } - description="The text content to be converted into a comment." - defaultValue="" -/> -PyCommentType } - description="The type of comment to generate (SINGLE_LINE, MULTI_LINE_QUOTE, or MULTI_LINE_DOUBLE_QUOTE)." - defaultValue="" -/> -bool, optional } - description="When True, forces multi-line format even for single-line content. Defaults to False." - defaultValue="" -/> -bool, optional } - description="When True, formats multi-line comments in Google style without newline after opening quotes. Defaults to True." - defaultValue="" -/> - - - -str } description="The formatted comment block with appropriate comment syntax."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ PyComment ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/python/PyCommentGroup.mdx b/docs/_deprecated/api-reference/python/PyCommentGroup.mdx deleted file mode 100644 index 3c87254b2..000000000 --- a/docs/_deprecated/api-reference/python/PyCommentGroup.mdx +++ /dev/null @@ -1,453 +0,0 @@ ---- -title: "PyCommentGroup" -sidebarTitle: "PyCommentGroup" -icon: "" -description: "A group of related symbols that represent a comment or docstring in Python For example: ``` # Comment 1 # Comment 2 # Comment 3 ``` would be 3 individual comments (accessible via `symbols`), but together they form a `CommentGroup` (accessible via `self`)." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[CommentGroup](/api-reference/core/CommentGroup), [SymbolGroup](/api-reference/core/SymbolGroup), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -PyFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### next_named_sibling - -Editable | None } description="Returns the next named sibling of the last symbol in the group." /> - -### next_sibling - -Editable | None } description="Returns the next sibling of the last symbol in the symbol group." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -PyClass | None } description="Find the class this node is contained in" /> - -### parent_function - -PyFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### source - -str } description="Returns the concatenated source code of all symbols in the group." /> - -### symbols - -list[ Editable ] } description="Returns the list of symbols in the group." /> - -### text - -str } description="Return the text content of all comments in the comment block." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this node with new text. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool, optional } - description="Adjusts the indentation of new_src to match the current text's indentation. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the edit operation. Higher priority edits take precedence. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Prevents duplicate edits at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### edit_text -Replace the text content of a comment group with new text. - - - -str } - description="The new text content to replace the existing comment text." - defaultValue="" -/> - - - -None } description=""/> - - -### find -Search for substrings in the given symbols that match `strings_to_match`. - - - -list[str] | str } - description="The string or list of strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes that exactly match the query." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable objects representing each match found."/> - - -### find_string_literals -Search for string literals matching given strings in the SymbolGroup. - - - -list[str] } - description="List of strings to search for in string literals." - defaultValue="" -/> -bool, optional } - description="If True, performs fuzzy matching instead of exact matching." - defaultValue="False" -/> - - - -list[ Editable ] } description="List of Editable nodes representing the matching string literals found within the symbols."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ PyCommentGroup ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ PyCommentGroup ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts source code after this node in the codebase. - - - -str } - description="The source code to insert." - defaultValue="" -/> -bool, optional } - description="Adjust indentation to match current text." - defaultValue="False" -/> -bool, optional } - description="Add a newline before the inserted code." - defaultValue="True" -/> -int, optional } - description="Priority of the edit operation." - defaultValue="0" -/> -bool, optional } - description="Deduplicate identical edits." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts source code before this symbol group. - - - -str } - description="The source code to insert." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of the inserted code to match the current code. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline after the inserted code. Defaults to True." - defaultValue="True" -/> -int, optional } - description="The priority of this edit operation. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to prevent duplicate insertions of the same code. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Removes this node and its related extended nodes from the codebase. - - - -bool, optional } - description="Whether to delete related extended nodes like decorators and comments. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority level of the removal operation. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate removal operations. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Replaces all instances of a string with a new string in all symbols within the group. - - - -str } - description="The string to be replaced." - defaultValue="" -/> -str } - description="The string to replace with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="Number of replacements made."/> - - -### search -Searches for regex matches in the codebase. - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool, optional } - description="Whether to include string literals in the search. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to include comments in the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects representing matched text nodes in the codebase."/> - - -### to_google_docstring -Convert a comment group into a Google-style docstring. - - - -PyFunction } - description="The Python function whose signature will be used to extract parameter and return type information." - defaultValue="" -/> - - - -str } description="A formatted Google-style docstring string that includes the function's description, parameters, and return value information."/> - - - diff --git a/docs/_deprecated/api-reference/python/PyCommentType.mdx b/docs/_deprecated/api-reference/python/PyCommentType.mdx deleted file mode 100644 index 4b0d49780..000000000 --- a/docs/_deprecated/api-reference/python/PyCommentType.mdx +++ /dev/null @@ -1,36 +0,0 @@ ---- -title: "PyCommentType" -sidebarTitle: "PyCommentType" -icon: "" -description: "Enum representing different types of comments." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - - -## Attributes - -### MULTI_LINE_DOUBLE_QUOTE - - } description="Represents a multi-line comment using double quotes." /> - -### MULTI_LINE_QUOTE - - } description="Represents a multi-line comment using single quotes." /> - -### SINGLE_LINE - - } description="Represents a single line comment." /> - -### UNKNOWN - - } description="Represents an unknown type of comment." /> - - - diff --git a/docs/_deprecated/api-reference/python/PyConditionalExpression.mdx b/docs/_deprecated/api-reference/python/PyConditionalExpression.mdx deleted file mode 100644 index a5436bdcb..000000000 --- a/docs/_deprecated/api-reference/python/PyConditionalExpression.mdx +++ /dev/null @@ -1,440 +0,0 @@ ---- -title: "PyConditionalExpression" -sidebarTitle: "PyConditionalExpression" -icon: "" -description: "Conditional Expressions (A if condition else B)" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[TernaryExpression](/api-reference/core/TernaryExpression), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### alternative - -Expression [ PyConditionalExpression ] | None } description="The expression to execute if the condition is false." /> - -### condition - -Expression [ PyConditionalExpression ] | None } description="The condition expression that determines which branch to execute." /> - -### consequence - -Expression [ PyConditionalExpression ] | None } description="The expression to execute if the condition is true." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -PyFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -PyClass | None } description="Find the class this node is contained in" /> - -### parent_function - -PyFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ PyConditionalExpression ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ PyConditionalExpression ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ PyConditionalExpression ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Simplifies a ternary expression based on a boolean condition. - - - -bool } - description="The boolean value to reduce the condition to. If True, keeps the consequence branch. If False, keeps the alternative branch." - defaultValue="" -/> -Editable | None, optional } - description="The node to be edited. Defaults to None." - defaultValue="None" -/> - - - -None } description="Modifies the ternary expression in place."/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/python/PyDecorator.mdx b/docs/_deprecated/api-reference/python/PyDecorator.mdx deleted file mode 100644 index 569598c31..000000000 --- a/docs/_deprecated/api-reference/python/PyDecorator.mdx +++ /dev/null @@ -1,467 +0,0 @@ ---- -title: "PyDecorator" -sidebarTitle: "PyDecorator" -icon: "" -description: "Extends Decorators for Python codebases." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Decorator](/api-reference/core/Decorator), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName), [Editable](/api-reference/core/Editable) - -## Attributes - -### call - -FunctionCall | None } description="Gets the function call node from the decorator if the decorator is a call." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -PyFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -PyClass | None } description="Find the class this node is contained in" /> - -### parent_function - -PyFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ PyDecorator ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ PyDecorator ] } description=""/> - - -### get_name -Returns the name node of the object. - - - -Name | PyChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ PyDecorator ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Sets the name of an object and updates all its usages. - - - -str } - description="The new name to assign to the object." - defaultValue="" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/python/PyFile.mdx b/docs/_deprecated/api-reference/python/PyFile.mdx deleted file mode 100644 index 5d9bd1376..000000000 --- a/docs/_deprecated/api-reference/python/PyFile.mdx +++ /dev/null @@ -1,947 +0,0 @@ ---- -title: "PyFile" -sidebarTitle: "PyFile" -icon: "" -description: "SourceFile representation for Python codebase" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[PyHasBlock](/api-reference/python/PyHasBlock), [SourceFile](/api-reference/core/SourceFile), [HasBlock](/api-reference/core/HasBlock), [Usable](/api-reference/core/Usable), [File](/api-reference/core/File), [Expression](/api-reference/core/Expression), [Importable](/api-reference/core/Importable), [Editable](/api-reference/core/Editable), [HasName](/api-reference/core/HasName) - -## Attributes - -### classes - -list[ PyClass ] } description="Returns all Classes in the file." /> - -### code_block - -PyCodeBlock } description="Represents the block of code contained in the file." /> - -### content - -str } description="Returns the content of the file as a UTF-8 encoded string." /> - -### decorators - -list[ PyDecorator ] } description="Returns a list of decorators associated with this symbol." /> - -### directory - -Directory | None } description="Returns the directory that contains this file." /> - -### docstring - -PyCommentGroup | None } description="Gets the function's docstring." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### extension - -str } description="Returns the file extension." /> - -### file - -PyFile } description="A property that returns the file object for non-source files." /> - -### file_path - -str } description="The relative file path as a string." /> - -### filepath - -str } description="Retrieves the file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns all function calls within the code block and its decorators." /> - -### functions - -list[ PyFunction ] } description="Returns all Functions in the file." /> - -### global_vars - -list[ PyAssignment ] } description="Returns all GlobalVars in the file." /> - -### import_module_name - -str } description="Returns the module name that this file gets imported as." /> - -### import_statements - -list[ PyImportStatement ] } description="Returns all ImportStatements in the file, where each import statement can contain" /> - -### importers - -list[ PyImport ] } description="Returns all imports that directly imports this file as a module." /> - -### imports - -list[ PyImport ] } description="List of all Imports in this file." /> - -### inbound_imports - -list[ PyImport ] } description="Returns all imports that are importing symbols contained in this file." /> - -### is_binary - -bool } description="Indicates whether the file contains binary data." /> - -### is_decorated - -bool } description="Returns whether the symbol is decorated with decorators." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### owners - -set[str] } description="Returns the CODEOWNERS of the file." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -PyClass | None } description="Find the class this node is contained in" /> - -### parent_function - -PyFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### path - -Path } description="The absolute path of the file as a Path object." /> - -### programming_language - - } description="The programming language of the file. Set to ProgrammingLanguage.PYTHON." /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### start_byte - -int } description="Returns the starting byte position of a file in its content." /> - -### symbols_sorted_topologically - -list[ PySymbol ] } description="Returns all Symbols in the file, sorted topologically (parents first). Robust to" /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### add_import -Adds an import to the file. - - - -PySymbol | str } - description="Either a Symbol to import or a string representation of an import statement." - defaultValue="" -/> -str | None } - description="Optional alias for the imported symbol. Only used when imp is a Symbol. Defaults to None." - defaultValue="None" -/> -ImportType } - description="The type of import to use. Only used when imp is a Symbol. Defaults to ImportType.UNKNOWN." - defaultValue="ImportType.UNKNOWN" -/> -bool } - description="Whether this is a type-only import. Only used when imp is a Symbol. Defaults to False." - defaultValue="False" -/> - - - -PyImport | None } description="The existing import for the symbol if found, otherwise None."/> - - -### add_symbol -Adds `symbol` to the file. - - - -PySymbol } - description="The symbol to add to the file." - defaultValue="" -/> -bool, optional } - description="Whether to export the symbol. Defaults to True." - defaultValue="True" -/> - - - -PySymbol | None } description="The existing symbol if it already exists in the file or None if it was added."/> - - -### add_symbol_from_source -Adds a symbol to a file from a string representation. - - - -str } - description="String representation of the symbol to be added. This should be valid source code for" - defaultValue="" -/> - - - -None } description="The symbol is added directly to the file's content."/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ PySymbol , PyImport ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this file with new_src. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of new_src to match the current" - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are" - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_by_byte_range -Finds all editable objects that overlap with the given byte range in the file. - - - -Range } - description="The byte range to search within the file." - defaultValue="" -/> - - - -list[ Editable ] } description="A list of all Editable objects that overlap with the given range."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ PyFile ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ PyFile ] } description=""/> - - -### get_class -Returns a specific Class by full name. Returns None if not found. - - - -str } - description="The full name of the class to search for." - defaultValue="" -/> - - - -PyClass | None } description="The matching Class object if found, None otherwise."/> - - -### get_extensions -Returns the file extensions associated with Python files. - - - -list[str] } description="A list containing '.py' as the only Python file extension."/> - - -### get_function -Returns a specific Function by name. - - - -str } - description="The name of the function to find." - defaultValue="" -/> - - - -PyFunction | None } description="The matching Function object if found, None otherwise."/> - - -### get_global_var -Returns a specific global var by name. Returns None if not found. - - - -str } - description="The name of the global variable to find." - defaultValue="" -/> - - - -PyAssignment | None } description="The global variable if found, None otherwise."/> - - -### get_import -Returns the import with matching alias. Returns None if not found. - - - -str } - description="The alias name to search for. This can match either the direct import name or the aliased name." - defaultValue="" -/> - - - -PyImport | None } description="The import statement with the matching alias if found, None otherwise."/> - - -### get_import_insert_index -Determines the index position where a new import statement should be inserted in a Python file. - - - -str } - description="The import statement to be inserted." - defaultValue="" -/> - - - -int | None } description="The index where the import should be inserted. Returns 0 for future imports or if there are no existing imports after future imports. Returns None if there are no imports in the file."/> - - -### get_import_string -Generates an import string for a symbol. - - - -str | None, optional } - description="Alias to use for the imported symbol. Defaults to None." - defaultValue="None" -/> -str | None, optional } - description="Module path to import from. If None, uses module name from source. Defaults to None." - defaultValue="None" -/> -ImportType , optional } - description="Type of import statement to generate. Defaults to ImportType.UNKNOWN." - defaultValue="ImportType.UNKNOWN" -/> -bool, optional } - description="Whether this is a type import. Currently unused. Defaults to False." - defaultValue="False" -/> - - - -str } description="A formatted import string in the form of 'from {module} import {symbol}' with optional alias or wildcard syntax."/> - - -### get_name -Returns the name node of the object. - - - -Name | PyChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_symbol -Gets a symbol by its name from the file. - - - -str } - description="The name of the symbol to find." - defaultValue="" -/> - - - -PySymbol | None } description="The found symbol, or None if not found."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ PyFile ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### has_import -Returns True if the file has an import with the given alias. - - - -str } - description="The alias to check for in the import statements." - defaultValue="" -/> - - - -bool } description="True if an import with the given alias exists, False otherwise."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Removes the file from the file system and graph. - - - -None } description=""/> - - -### rename -Renames a symbol and updates all its references in the codebase. - - - -str } - description="The new name for the symbol." - defaultValue="" -/> -int } - description="Priority of the edit operation. Defaults to 0." - defaultValue="0" -/> - - - -tuple[NodeId, NodeId] } description="A tuple containing the file node ID and the new node ID of the renamed symbol."/> - - -### replace -Replace occurrences of text in the file. - - - -str } - description="The text to be replaced." - defaultValue="" -/> -str } - description="The text to replace with." - defaultValue="" -/> -int } - description="Maximum number of replacements to make. -1 means replace all occurrences." - defaultValue="-1" -/> -bool } - description="If True, treat 'old' as a regular expression pattern." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are" - defaultValue="0" -/> - - - -int } description="List of affected Editable objects. For non-source files, always returns an empty list since they don't have Editable sub-components."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_docstring -Sets or updates a docstring for a Python function or class. - - - -str } - description="The docstring content to set." - defaultValue="" -/> -bool, optional } - description="Whether to format the text into a proper docstring format. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to clean and normalize the docstring format before insertion. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to force single-line comments to be converted to multi-line format. Defaults to False." - defaultValue="False" -/> - - - -None } description=""/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### symbol_can_be_added -Checks if a Python symbol can be added to this Python source file. - - - -PySymbol } - description="The Python symbol to check for compatibility with this file." - defaultValue="" -/> - - - -bool } description="Always returns True as Python files can contain any Python symbol type."/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ PyImport | PySymbol | Export ] } description="A list of symbols that use or import the exportable object."/> - - -### symbols -Returns all Symbols in the file, sorted by position in the file. - - - -list[ PySymbol | PyClass | PyFunction | PyAssignment | Interface ] } description="A list of all top-level symbols in the file, sorted by their position in the file. Symbols can be one of the following types: - Symbol: Base symbol class - TClass: Class definition - TFunction: Function definition - TGlobalVar: Global variable assignment - TInterface: Interface definition"/> - - -### update_filepath -Renames the file and updates all imports to point to the new location. - - - -str } - description="The new filepath to move the file to." - defaultValue="" -/> - - - -None } description=""/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/python/PyForLoopStatement.mdx b/docs/_deprecated/api-reference/python/PyForLoopStatement.mdx deleted file mode 100644 index 3a845b8f6..000000000 --- a/docs/_deprecated/api-reference/python/PyForLoopStatement.mdx +++ /dev/null @@ -1,507 +0,0 @@ ---- -title: "PyForLoopStatement" -sidebarTitle: "PyForLoopStatement" -icon: "" -description: "Abstract representation of the for loop in Python" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[PyBlockStatement](/api-reference/python/PyBlockStatement), [ForLoopStatement](/api-reference/core/ForLoopStatement), [PyHasBlock](/api-reference/python/PyHasBlock), [BlockStatement](/api-reference/core/BlockStatement), [HasBlock](/api-reference/core/HasBlock), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### code_block - -PyCodeBlock | None } description="The code block contained within the statement, if it exists." /> - -### decorators - -list[ PyDecorator ] } description="Returns a list of decorators associated with this symbol." /> - -### docstring - -PyCommentGroup | None } description="Gets the function's docstring." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -PyFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Gets all function calls within this for loop statement." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### is_decorated - -bool } description="Returns whether the symbol is decorated with decorators." /> - -### item - -Expression [ PyForLoopStatement ] } description="An item in the iterable object" /> - -### iterable - -Expression [ PyForLoopStatement ] } description="The iterable that is being iterated over" /> - -### nested_code_blocks - -list[ PyCodeBlock ] } description="Returns all nested CodeBlocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ PyForLoopStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -PyClass | None } description="Find the class this node is contained in" /> - -### parent_function - -PyFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ PyForLoopStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ PyForLoopStatement ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ PyForLoopStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_docstring -Sets or updates a docstring for a Python function or class. - - - -str } - description="The docstring content to set." - defaultValue="" -/> -bool, optional } - description="Whether to format the text into a proper docstring format. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to clean and normalize the docstring format before insertion. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to force single-line comments to be converted to multi-line format. Defaults to False." - defaultValue="False" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/python/PyFunction.mdx b/docs/_deprecated/api-reference/python/PyFunction.mdx deleted file mode 100644 index d1b488750..000000000 --- a/docs/_deprecated/api-reference/python/PyFunction.mdx +++ /dev/null @@ -1,1040 +0,0 @@ ---- -title: "PyFunction" -sidebarTitle: "PyFunction" -icon: "" -description: "Extends Function for Python codebases." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[PyHasBlock](/api-reference/python/PyHasBlock), [PySymbol](/api-reference/python/PySymbol), [Function](/api-reference/core/Function), [HasBlock](/api-reference/core/HasBlock), [Symbol](/api-reference/core/Symbol), [Callable](/api-reference/core/Callable), [Expression](/api-reference/core/Expression), [Usable](/api-reference/core/Usable), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [HasName](/api-reference/core/HasName) - -## Attributes - -### body - -str } description="Returns the body of the function as a string." /> - -### call_sites - -list[ FunctionCall ] } description="Returns all call sites (invocations) of this callable in the codebase." /> - -### code_block - -PyCodeBlock } description="The block of code associated with the code object." /> - -### comment - -PyCommentGroup | None } description="Retrieves the comment group associated with a Python symbol." /> - -### decorators - -list[ PyDecorator ] } description="Returns a list of decorators associated with this symbol." /> - -### docstring - -PyCommentGroup | None } description="Gets the function's docstring." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_nodes - -list[ Editable ] } description="Returns a list of Editable nodes associated with this symbol, including extended symbols." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -PyFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Gets all function calls within the function and its parameters." /> - -### function_signature - -str } description="Returns the function signature as a string." /> - -### inferred_return_type - -str | None } description="Gets the inferred type of the function from the language's native language engine / compiler." /> - -### inline_comment - -PyCommentGroup | None } description="Returns the inline comment group associated with this symbol." /> - -### is_async - -bool } description="Returns True if the function is asynchronous." /> - -### is_class_method - -bool } description="Indicates whether the current function is decorated with @classmethod." /> - -### is_constructor - -bool } description="Determines if the current function is a constructor method." /> - -### is_decorated - -bool } description="Returns whether the symbol is decorated with decorators." /> - -### is_exported - -bool } description="Indicates whether a Python symbol is exported." /> - -### is_magic - -bool } description="Determines if a method is a magic method." /> - -### is_method - -bool } description="Returns whether the function is a method of a class." /> - -### is_overload - -bool } description="Determines whether a function is decorated with an overload decorator." /> - -### is_private - -bool } description="Determines if a method is a private method." /> - -### is_property - -bool } description="Determines if the function is a property." /> - -### is_static_method - -bool } description="Determines if the function is a static method." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### nested_functions - -list[ PyFunction ] } description="Returns a list of nested functions defined within this function's code block." /> - -### parameters - -SymbolGroup [ PyParameter , PyFunction ] | list[ PyParameter ] } description="Retrieves all parameters of a callable symbol." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -PyClass | None } description="Find the class this node is contained in" /> - -### parent_function - -PyFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### return_statements - -list[ ReturnStatement ] } description="Returns a list of all return statements within this function's body." /> - -### return_type - -Type | Placeholder [ PyFunction ] } description="The type of value returned by the callable, or a placeholder." /> - -### source - -str } description="Returns the source code of the symbol." /> - -### symbol_type - - } description="The type of symbol, set to SymbolType.Function." /> - -### type_parameters - -TypeParameters[ Type , PyFunction ] | None } description="The type parameters of the symbol, if any." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_comment -Adds a new comment to the symbol. - - - -str } - description="The comment text to be added." - defaultValue="" -/> -bool } - description="Whether to automatically format the text into a proper comment format." - defaultValue="True" -/> -bool } - description="Whether to clean and normalize the comment text before adding." - defaultValue="True" -/> -PyCommentType } - description="The style of comment to add (e.g., single-line, multi-line)." - defaultValue="PyCommentType.SINGLE_LINE" -/> - - - -None } description=""/> - - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### add_keyword -Insert a keyword in the appropriate place before this symbol if it doesn't already exist. - - - -str } - description="The keyword to be inserted. Must be a valid keyword in the language context." - defaultValue="" -/> - - - -None } description=""/> - - -### add_statements -Adds statements to the end of a function body. - - - -str } - description="The lines of code to be added at the end of the function body." - defaultValue="" -/> - - - -None } description=""/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### asyncify -Modifies the function to be asynchronous. - - - -None } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ PySymbol , PyImport ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this node with new_src. - - - -str } - description="The new source code to replace the current source with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, prevents duplicate edits. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ PyFunction ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Flags a Python symbol by adding a flag comment and returning a CodeFlag. - - - -CodeFlag[ PyFunction ] } description="The code flag object for tracking purposes"/> - - -### get_import_string -Generates an import string for a Python symbol. - - - -str | None } - description="Optional alias name for the import. If provided and different from symbol name, creates aliased import." - defaultValue="None" -/> -str | None } - description="Optional module name to import from. If not provided, uses the symbol's file's module name." - defaultValue="None" -/> -ImportType } - description="Type of import to generate. If WILDCARD, generates star import. Defaults to UNKNOWN." - defaultValue="ImportType.UNKNOWN" -/> -bool } - description="Whether this is a type import. Currently unused. Defaults to False." - defaultValue="False" -/> - - - -str } description="The formatted import string. Will be one of: - "from {module} import * as {file_name}" (for WILDCARD imports) - "from {module} import {name} as {alias}" (for aliased imports) - "from {module} import {name}" (for standard imports)"/> - - -### get_name -Returns the name node of the object. - - - -Name | PyChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_parameter -Gets a specific parameter from the callable's parameters list by name. - - - -str } - description="The name of the parameter to retrieve." - defaultValue="" -/> - - - -PyParameter | None } description="The parameter with the specified name, or None if no parameter with that name exists or if there are no parameters."/> - - -### get_parameter_by_index -Returns the parameter at the given index. - - - -int } - description="The index of the parameter to retrieve." - defaultValue="" -/> - - - -PyParameter | None } description="The parameter at the specified index, or None if the parameter list is empty or the index does not exist."/> - - -### get_parameter_by_type -Retrieves a parameter from the callable by its type. - - - -PySymbol } - description="The type to search for." - defaultValue="" -/> - - - -PyParameter | None } description="The parameter with the specified type, or None if no parameter is found or if the callable has no parameters."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ PyFunction ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before the current symbol node in the Abstract Syntax Tree. - - - -str } - description="The source code text to insert." - defaultValue="" -/> -bool } - description="Whether to adjust the indentation of new_src to match current text. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after insertion. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to remove duplicate insertions. Defaults to True." - defaultValue="True" -/> -bool } - description="Whether to insert before extended nodes like comments and decorators. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_statements -Inserts lines of code into the function body at the specified index. - - - -str } - description="The code lines to insert into the function body." - defaultValue="" -/> -int, optional } - description="The position in the function body where the lines should be inserted. Defaults to 0." - defaultValue="0" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### move_to_file -Moves the given symbol to a new file and updates its imports and references. - - - -PyFile } - description="The destination file to move the symbol to." - defaultValue="" -/> -bool } - description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." - defaultValue="True" -/> -str } - description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." - defaultValue=""update_all_imports"" -/> - - - -None } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### prepend_statements -Prepends statements to the start of the function body. - - - -str } - description="The code statements to prepend to the function body." - defaultValue="" -/> - - - -None } description="This method modifies the function in place."/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Renames a symbol and updates all its references in the codebase. - - - -str } - description="The new name for the symbol." - defaultValue="" -/> -int } - description="Priority of the edit operation. Defaults to 0." - defaultValue="0" -/> - - - -tuple[NodeId, NodeId] } description="A tuple containing the file node ID and the new node ID of the renamed symbol."/> - - -### rename_local_variable -Renames a local variable and all its usages within a function body. - - - -str } - description="The current name of the local variable to be renamed." - defaultValue="" -/> -str } - description="The new name to give to the local variable." - defaultValue="" -/> -bool, optional } - description="If True, matches variable names that contain old_var_name. Defaults to False." - defaultValue="False" -/> - - - -None } description="The method modifies the AST in place."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_comment -Sets a comment for the Python symbol. - - - -str } - description="The comment text to be added or set." - defaultValue="" -/> -bool, optional } - description="If True, automatically formats the text as a comment." - defaultValue="True" -/> -bool, optional } - description="If True, cleans the format of the comment before" - defaultValue="True" -/> -PyCommentType , optional } - description="Type of comment to add (e.g., single line," - defaultValue="PyCommentType.SINGLE_LINE" -/> - - - -None } description="This method modifies the symbol's comment in place."/> - - -### set_docstring -Sets or updates a docstring for a Python function or class. - - - -str } - description="The docstring content to set." - defaultValue="" -/> -bool, optional } - description="Whether to format the text into a proper docstring format. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to clean and normalize the docstring format before insertion. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to force single-line comments to be converted to multi-line format. Defaults to False." - defaultValue="False" -/> - - - -None } description=""/> - - -### set_inline_comment -Sets an inline comment to the symbol. - - - -str } - description="The inline comment text to add." - defaultValue="" -/> -bool, optional } - description="If True, formats the text into a proper inline" - defaultValue="True" -/> -bool, optional } - description="If True, cleans the comment text before insertion" - defaultValue="True" -/> - - - -None } description=""/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### set_return_type -Sets or modifies the return type annotation of a function. - - - -str } - description="The new return type annotation to set. Provide an empty string to remove the return type annotation." - defaultValue="" -/> - - - -None } description=""/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ PyImport | PySymbol | Export ] } description="A list of symbols that use or import the exportable object."/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/python/PyGenericType.mdx b/docs/_deprecated/api-reference/python/PyGenericType.mdx deleted file mode 100644 index f30cfb65a..000000000 --- a/docs/_deprecated/api-reference/python/PyGenericType.mdx +++ /dev/null @@ -1,467 +0,0 @@ ---- -title: "PyGenericType" -sidebarTitle: "PyGenericType" -icon: "" -description: "Generic python type. Examples: list[int]" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[PyNamedType](/api-reference/python/PyNamedType), [GenericType](/api-reference/core/GenericType), [NamedType](/api-reference/core/NamedType), [HasName](/api-reference/core/HasName), [Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -PyFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parameters - -Collection[ Type , PyGenericType ] } description="Retrieves the generic type parameters associated with this type." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -PyClass | None } description="Find the class this node is contained in" /> - -### parent_function - -PyFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ PyGenericType ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ PyGenericType ] } description=""/> - - -### get_name -Returns the name node of the object. - - - -Name | PyChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ PyGenericType ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Sets the name of an object and updates all its usages. - - - -str } - description="The new name to assign to the object." - defaultValue="" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/python/PyHasBlock.mdx b/docs/_deprecated/api-reference/python/PyHasBlock.mdx deleted file mode 100644 index 59527f2c2..000000000 --- a/docs/_deprecated/api-reference/python/PyHasBlock.mdx +++ /dev/null @@ -1,487 +0,0 @@ ---- -title: "PyHasBlock" -sidebarTitle: "PyHasBlock" -icon: "" -description: "Extends HasBlock for Python codebases." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[HasBlock](/api-reference/core/HasBlock), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### code_block - -PyCodeBlock } description="The block of code associated with the code object." /> - -### decorators - -list[ PyDecorator ] } description="Returns a list of decorators associated with this symbol." /> - -### docstring - -PyCommentGroup | None } description="Gets the function's docstring." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -PyFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns all function calls within the code block and its decorators." /> - -### is_decorated - -bool } description="Returns whether the symbol is decorated with decorators." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -PyClass | None } description="Find the class this node is contained in" /> - -### parent_function - -PyFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ PyHasBlock ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ PyHasBlock ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ PyHasBlock ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_docstring -Sets or updates a docstring for a Python function or class. - - - -str } - description="The docstring content to set." - defaultValue="" -/> -bool, optional } - description="Whether to format the text into a proper docstring format. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to clean and normalize the docstring format before insertion. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to force single-line comments to be converted to multi-line format. Defaults to False." - defaultValue="False" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/python/PyIfBlockStatement.mdx b/docs/_deprecated/api-reference/python/PyIfBlockStatement.mdx deleted file mode 100644 index 79fd5f33c..000000000 --- a/docs/_deprecated/api-reference/python/PyIfBlockStatement.mdx +++ /dev/null @@ -1,470 +0,0 @@ ---- -title: "PyIfBlockStatement" -sidebarTitle: "PyIfBlockStatement" -icon: "" -description: "Pythons implementation of the if/elif/else statement block. For example, if there is a code block like: if condition1: block1 elif condition2: block2 else: block3 This class represents the entire block, including the conditions and nested code blocks." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[IfBlockStatement](/api-reference/core/IfBlockStatement), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### alternative_blocks - -list[ PyIfBlockStatement ] } description="Returns a list of alternative if/elif/else blocks for the current block." /> - -### condition - -Expression [ PyIfBlockStatement ] | None } description="The condition expression for the if block. None if the block is an else block." /> - -### consequence_block - -PyCodeBlock } description="The code block that is executed if the condition is True." /> - -### else_statement - -PyIfBlockStatement | None } description="Returns the else block within the if-statement." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -PyFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns all function calls within the if block statement and its alternative blocks." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### is_elif_statement - -bool } description="Determines if the current block is an 'elif' clause." /> - -### is_else_statement - -bool } description="Determines if the current block is an else block." /> - -### is_if_statement - -bool } description="Check if the current block is an if statement." /> - -### nested_code_blocks - -list[ PyCodeBlock ] } description="Returns all nested code blocks within an if/elif/else statement block." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ PyIfBlockStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -PyClass | None } description="Find the class this node is contained in" /> - -### parent_function - -PyFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### elif_statements -Returns all elif blocks within the if block. - - - -list[ PyIfBlockStatement ] } description="A list of elif block statements. Empty list if no elif blocks exist."/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ PyIfBlockStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ PyIfBlockStatement ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ PyIfBlockStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Simplifies a conditional block by reducing its condition to a boolean value. - - - -bool } - description="The boolean value to reduce the condition to." - defaultValue="" -/> - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/python/PyImport.mdx b/docs/_deprecated/api-reference/python/PyImport.mdx deleted file mode 100644 index 89e77701e..000000000 --- a/docs/_deprecated/api-reference/python/PyImport.mdx +++ /dev/null @@ -1,691 +0,0 @@ ---- -title: "PyImport" -sidebarTitle: "PyImport" -icon: "" -description: "Extends Import for Python codebases." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Import](/api-reference/core/Import), [Usable](/api-reference/core/Usable), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName) - -## Attributes - -### alias - -Editable | None } description="The alias of the imported symbol, if one exists." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -PyFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### from_file - -PyFile | None } description="Returns the SourceFile that an Import is importing from." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### import_specifier - -Editable } description="Retrieves the import specifier node for this import." /> - -### import_statement - -PyImportStatement } description="The statement that this import is part of." /> - -### import_type - -ImportType } description="The type of import, indicating how the symbol is imported." /> - -### imported_exports - -list[ Exportable ] } description="Returns a list of exports from an import statement." /> - -### imported_symbol - -PySymbol | ExternalModule | PyFile | PyImport | None } description="Returns the symbol directly being imported, including an indirect import and an External" /> - -### is_dynamic - -bool } description="Determines if this import is dynamically loaded based on its parent symbol." /> - -### module - -Editable | None } description="The module from which the symbol is being imported, if applicable." /> - -### name - -str | None } description="Returns the name or alias of the symbol being imported." /> - -### namespace - -str | None } description="Returns the namespace of the import if it imports a file, or None otherwise." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -PyClass | None } description="Find the class this node is contained in" /> - -### parent_function - -PyFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_symbol - -PySymbol | ExternalModule | PyFile | None } description="Returns the symbol, source file, or external module that this import ultimately resolves" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### symbol_name - -Editable | None } description="The name of the symbol being imported. For instance import a as b has a symbol_name of a." /> - -### to_file - -PyFile } description="SourceFile that this import resides in." /> - -### to_file_id - -NodeId } description="The node ID of the file to which this import belongs." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ PySymbol , PyImport ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ PyImport ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ PyImport ] } description=""/> - - -### get_import_string -Generates an import string for a Python import statement. - - - -str | None } - description="Optional alias name for the imported symbol." - defaultValue="None" -/> -str | None } - description="Optional module name to import from. If not provided, uses the file's import module name." - defaultValue="None" -/> -ImportType } - description="Type of import to generate. Defaults to UNKNOWN." - defaultValue="ImportType.UNKNOWN" -/> -bool } - description="Whether this is a type import. Defaults to False." - defaultValue="False" -/> - - - -str } description="A formatted import statement string."/> - - -### get_name -Returns the name node of the object. - - - -Name | PyChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ PyImport ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_aliased_import -Returns True if this import is aliased. - - - -bool } description="True if the import has an alias different from its original name, False otherwise."/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_module_import -Determines if the import is a module-level or wildcard import. - - - -bool } description="True if the import is a module-level or wildcard import, False otherwise."/> - - -### is_reexport -Returns true if the Import object is also an Export object. - - - -bool } description="True if the import is re-exported, False otherwise."/> - - -### is_symbol_import -Returns True if this import is importing a symbol rather than a module. - - - -bool } description="True if this import is a symbol import, False if it is a module import."/> - - -### is_wildcard_import -Returns True if the import symbol is a wildcard import. - - - -bool } description="True if this is a wildcard import, False otherwise."/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Remove this import from the import statement. - - - -bool, optional } - description="Whether to delete any associated formatting. Defaults to True." - defaultValue="True" -/> -int, optional } - description="The priority of the operation. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate imports. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Renames the import symbol and updates all its usages throughout the codebase. - - - -str } - description="The new name to give the imported symbol." - defaultValue="" -/> -int, optional } - description="Priority of the rename operation. Defaults to 0." - defaultValue="0" -/> - - - -tuple[NodeId, NodeId] } description="A tuple containing (file_node_id, new_import_node_id)."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_import_module -Sets the module of an import. - - - -str } - description="The new module path to import from." - defaultValue="" -/> - - - -None } description=""/> - - -### set_import_symbol_alias -Sets alias or name of an import at the declaration level. - - - -str } - description="The new name to use for the imported symbol." - defaultValue="" -/> - - - -None } description=""/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ PyImport | PySymbol | Export ] } description="A list of symbols that use or import the exportable object."/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/python/PyImportStatement.mdx b/docs/_deprecated/api-reference/python/PyImportStatement.mdx deleted file mode 100644 index 5509a182d..000000000 --- a/docs/_deprecated/api-reference/python/PyImportStatement.mdx +++ /dev/null @@ -1,429 +0,0 @@ ---- -title: "PyImportStatement" -sidebarTitle: "PyImportStatement" -icon: "" -description: "An abstract representation of a python import statement." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[ImportStatement](/api-reference/core/ImportStatement), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -PyFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### imports - -Collection[ PyImport , PyImportStatement ] } description="A collection of the individual imports this statement represents" /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### nested_code_blocks - -list[ Editable ] } description="Returns all nested code blocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ PyImportStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -PyClass | None } description="Find the class this node is contained in" /> - -### parent_function - -PyFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ PyImportStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ PyImportStatement ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ PyImportStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/python/PyMatchCase.mdx b/docs/_deprecated/api-reference/python/PyMatchCase.mdx deleted file mode 100644 index 53b587218..000000000 --- a/docs/_deprecated/api-reference/python/PyMatchCase.mdx +++ /dev/null @@ -1,503 +0,0 @@ ---- -title: "PyMatchCase" -sidebarTitle: "PyMatchCase" -icon: "" -description: "Python match case." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[PyBlockStatement](/api-reference/python/PyBlockStatement), [SwitchCase](/api-reference/core/SwitchCase), [PyHasBlock](/api-reference/python/PyHasBlock), [BlockStatement](/api-reference/core/BlockStatement), [HasBlock](/api-reference/core/HasBlock), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### code_block - -PyCodeBlock | None } description="The code block contained within the statement, if it exists." /> - -### condition - -Expression [ PyMatchCase ] | None } description="The condition which triggers this case" /> - -### decorators - -list[ PyDecorator ] } description="Returns a list of decorators associated with this symbol." /> - -### docstring - -PyCommentGroup | None } description="Gets the function's docstring." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -PyFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Gets all function calls within the statement's code block." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### is_decorated - -bool } description="Returns whether the symbol is decorated with decorators." /> - -### nested_code_blocks - -list[ PyCodeBlock ] } description="Returns all nested CodeBlocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ PyMatchCase ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -PyClass | None } description="Find the class this node is contained in" /> - -### parent_function - -PyFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ PyMatchCase ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ PyMatchCase ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ PyMatchCase ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_docstring -Sets or updates a docstring for a Python function or class. - - - -str } - description="The docstring content to set." - defaultValue="" -/> -bool, optional } - description="Whether to format the text into a proper docstring format. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to clean and normalize the docstring format before insertion. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to force single-line comments to be converted to multi-line format. Defaults to False." - defaultValue="False" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/python/PyMatchStatement.mdx b/docs/_deprecated/api-reference/python/PyMatchStatement.mdx deleted file mode 100644 index d2dde6ce6..000000000 --- a/docs/_deprecated/api-reference/python/PyMatchStatement.mdx +++ /dev/null @@ -1,433 +0,0 @@ ---- -title: "PyMatchStatement" -sidebarTitle: "PyMatchStatement" -icon: "" -description: "Abstract representation of the match block" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[SwitchStatement](/api-reference/core/SwitchStatement), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### cases - -list[ SwitchCase ] } description="A list of switch cases." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -PyFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns all function calls within the switch statement." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### nested_code_blocks - -list[ PyCodeBlock ] } description="Returns all nested CodeBlocks within the switch statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ PyMatchStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -PyClass | None } description="Find the class this node is contained in" /> - -### parent_function - -PyFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### value - -Expression [ PyMatchStatement ] } description="The value to switch on." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ PyMatchStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ PyMatchStatement ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ PyMatchStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/python/PyNamedType.mdx b/docs/_deprecated/api-reference/python/PyNamedType.mdx deleted file mode 100644 index 4d09820fd..000000000 --- a/docs/_deprecated/api-reference/python/PyNamedType.mdx +++ /dev/null @@ -1,463 +0,0 @@ ---- -title: "PyNamedType" -sidebarTitle: "PyNamedType" -icon: "" -description: "Named python type Examples: int,str (builtin types) Path (classes)" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[NamedType](/api-reference/core/NamedType), [HasName](/api-reference/core/HasName), [Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -PyFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -PyClass | None } description="Find the class this node is contained in" /> - -### parent_function - -PyFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ PyNamedType ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ PyNamedType ] } description=""/> - - -### get_name -Returns the name node of the object. - - - -Name | PyChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ PyNamedType ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Sets the name of an object and updates all its usages. - - - -str } - description="The new name to assign to the object." - defaultValue="" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/python/PyParameter.mdx b/docs/_deprecated/api-reference/python/PyParameter.mdx deleted file mode 100644 index 3379c8229..000000000 --- a/docs/_deprecated/api-reference/python/PyParameter.mdx +++ /dev/null @@ -1,611 +0,0 @@ ---- -title: "PyParameter" -sidebarTitle: "PyParameter" -icon: "" -description: "Extends Parameter for Python codebases." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Parameter](/api-reference/core/Parameter), [HasValue](/api-reference/core/HasValue), [Expression](/api-reference/core/Expression), [Typeable](/api-reference/core/Typeable), [Usable](/api-reference/core/Usable), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [HasName](/api-reference/core/HasName) - -## Attributes - -### default - -str | None } description="Returns the default value of a parameter if one exists." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -PyFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### index - -int } description="Returns the 0-based index of this parameter within its parent function's parameter list." /> - -### is_optional - -bool } description="Determines if the parameter is optional in Python code." /> - -### is_typed - -bool } description="Indicates if a node has an explicit type annotation." /> - -### is_variadic - -bool } description="Determines if a parameter is a variadic parameter." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -PyClass | None } description="Find the class this node is contained in" /> - -### parent_function - -PyFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### type - -Type | TypePlaceholder [ PyParameter ] } description="The type annotation associated with this node" /> - -### value - -Expression | None } description="Gets the value node of the object." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_trailing_comment -Add a trailing comment to a parameter in a function signature. - - - -str } - description="The comment text to be added after the parameter." - defaultValue="" -/> - - - -None } description=""/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ PySymbol , PyImport ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ PyParameter ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ PyParameter ] } description=""/> - - -### get_name -Returns the name node of the object. - - - -Name | PyChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ PyParameter ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Removes the parameter from the function definition and all its call sites. - - - -bool, optional } - description="Whether to delete formatting around the parameter. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority level for the removal operation. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate removal operations. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Renames a parameter in a function definition and updates all related references. - - - -str } - description="The new name for the parameter." - defaultValue="" -/> -int, optional } - description="The priority of the edit operation. Defaults to 0." - defaultValue="0" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### set_type_annotation -Sets the type annotation of a parameter. - - - -str } - description="The type annotation to set for the parameter." - defaultValue="" -/> -str, optional } - description="A comment to include with the type annotation. Defaults to ""." - defaultValue="""" -/> - - - -None } description="Use `type.edit` instead."/> - - -### set_value -Sets the value of the node's value Expression. - - - -str } - description="The new value to set." - defaultValue="" -/> - - - -None } description=""/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ PyImport | PySymbol | Export ] } description="A list of symbols that use or import the exportable object."/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/python/PyPassStatement.mdx b/docs/_deprecated/api-reference/python/PyPassStatement.mdx deleted file mode 100644 index 3801abfe6..000000000 --- a/docs/_deprecated/api-reference/python/PyPassStatement.mdx +++ /dev/null @@ -1,425 +0,0 @@ ---- -title: "PyPassStatement" -sidebarTitle: "PyPassStatement" -icon: "" -description: "An abstract representation of a python pass statement." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -PyFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### nested_code_blocks - -list[ Editable ] } description="Returns all nested code blocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ PyPassStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -PyClass | None } description="Find the class this node is contained in" /> - -### parent_function - -PyFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ PyPassStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ PyPassStatement ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ PyPassStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/python/PyReturnTypePlaceholder.mdx b/docs/_deprecated/api-reference/python/PyReturnTypePlaceholder.mdx deleted file mode 100644 index 76d3849e5..000000000 --- a/docs/_deprecated/api-reference/python/PyReturnTypePlaceholder.mdx +++ /dev/null @@ -1,65 +0,0 @@ ---- -title: "PyReturnTypePlaceholder" -sidebarTitle: "PyReturnTypePlaceholder" -icon: "" -description: "A placeholder for a python return type that does not exist. Can be populated using the `edit` method." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Placeholder](/api-reference/core/Placeholder) - - -## Methods - -### edit -Edits or creates a return type annotation for a method or function. - - - -str } - description="The new return type annotation text to be added." - defaultValue="" -/> -bool, optional } - description="Whether to fix the indentation of the new source. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the edit operation. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate the edit operation. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### remove -Removes this element from its parent container. - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/python/PyString.mdx b/docs/_deprecated/api-reference/python/PyString.mdx deleted file mode 100644 index 4d451bb38..000000000 --- a/docs/_deprecated/api-reference/python/PyString.mdx +++ /dev/null @@ -1,429 +0,0 @@ ---- -title: "PyString" -sidebarTitle: "PyString" -icon: "" -description: "An abstract representation of a python string." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[String](/api-reference/core/String), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### content - -str } description="The content of the string" /> - -### content_nodes - -Collection[ Expression [ Editable ], PyString ] } description="A collection of string fragments and escape sequences in TS, or a single string content in Python." /> - -### expressions - -list[ Expression [ Editable ]] } description="Embedded expressions in the string, only applicable for templated or formatted strings." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -PyFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -PyClass | None } description="Find the class this node is contained in" /> - -### parent_function - -PyFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - -### with_quotes - -str } description="Retrieves the string representation with quotation marks." /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ PyString ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ PyString ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ PyString ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/python/PySymbol.mdx b/docs/_deprecated/api-reference/python/PySymbol.mdx deleted file mode 100644 index 0bf20c7d8..000000000 --- a/docs/_deprecated/api-reference/python/PySymbol.mdx +++ /dev/null @@ -1,732 +0,0 @@ ---- -title: "PySymbol" -sidebarTitle: "PySymbol" -icon: "" -description: "Extends `Symbol` for Python codebases." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Symbol](/api-reference/core/Symbol), [Usable](/api-reference/core/Usable), [Importable](/api-reference/core/Importable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName), [Editable](/api-reference/core/Editable) - -## Attributes - -### comment - -PyCommentGroup | None } description="Retrieves the comment group associated with a Python symbol." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_nodes - -list[ Editable ] } description="Returns a list of Editable nodes associated with this symbol, including extended symbols." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -PyFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### inline_comment - -PyCommentGroup | None } description="Returns the inline comment group associated with this symbol." /> - -### is_exported - -bool } description="Indicates whether a Python symbol is exported." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -PyClass | None } description="Find the class this node is contained in" /> - -### parent_function - -PyFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Returns the source code of the symbol." /> - -### symbol_type - -SymbolType } description="The type of the symbol." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_comment -Adds a new comment to the symbol. - - - -str } - description="The comment text to be added." - defaultValue="" -/> -bool } - description="Whether to automatically format the text into a proper comment format." - defaultValue="True" -/> -bool } - description="Whether to clean and normalize the comment text before adding." - defaultValue="True" -/> -PyCommentType } - description="The style of comment to add (e.g., single-line, multi-line)." - defaultValue="PyCommentType.SINGLE_LINE" -/> - - - -None } description=""/> - - -### add_keyword -Insert a keyword in the appropriate place before this symbol if it doesn't already exist. - - - -str } - description="The keyword to be inserted. Must be a valid keyword in the language context." - defaultValue="" -/> - - - -None } description=""/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ PySymbol , PyImport ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this node with new_src. - - - -str } - description="The new source code to replace the current source with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, prevents duplicate edits. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ PySymbol ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Flags a Python symbol by adding a flag comment and returning a CodeFlag. - - - -CodeFlag[ PySymbol ] } description="The code flag object for tracking purposes"/> - - -### get_import_string -Generates an import string for a Python symbol. - - - -str | None } - description="Optional alias name for the import. If provided and different from symbol name, creates aliased import." - defaultValue="None" -/> -str | None } - description="Optional module name to import from. If not provided, uses the symbol's file's module name." - defaultValue="None" -/> -ImportType } - description="Type of import to generate. If WILDCARD, generates star import. Defaults to UNKNOWN." - defaultValue="ImportType.UNKNOWN" -/> -bool } - description="Whether this is a type import. Currently unused. Defaults to False." - defaultValue="False" -/> - - - -str } description="The formatted import string. Will be one of: - "from {module} import * as {file_name}" (for WILDCARD imports) - "from {module} import {name} as {alias}" (for aliased imports) - "from {module} import {name}" (for standard imports)"/> - - -### get_name -Returns the name node of the object. - - - -Name | PyChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ PySymbol ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before the current symbol node in the Abstract Syntax Tree. - - - -str } - description="The source code text to insert." - defaultValue="" -/> -bool } - description="Whether to adjust the indentation of new_src to match current text. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after insertion. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to remove duplicate insertions. Defaults to True." - defaultValue="True" -/> -bool } - description="Whether to insert before extended nodes like comments and decorators. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### move_to_file -Moves the given symbol to a new file and updates its imports and references. - - - -PyFile } - description="The destination file to move the symbol to." - defaultValue="" -/> -bool } - description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." - defaultValue="True" -/> -str } - description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." - defaultValue=""update_all_imports"" -/> - - - -None } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Renames a symbol and updates all its references in the codebase. - - - -str } - description="The new name for the symbol." - defaultValue="" -/> -int } - description="Priority of the edit operation. Defaults to 0." - defaultValue="0" -/> - - - -tuple[NodeId, NodeId] } description="A tuple containing the file node ID and the new node ID of the renamed symbol."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_comment -Sets a comment for the Python symbol. - - - -str } - description="The comment text to be added or set." - defaultValue="" -/> -bool, optional } - description="If True, automatically formats the text as a comment." - defaultValue="True" -/> -bool, optional } - description="If True, cleans the format of the comment before" - defaultValue="True" -/> -PyCommentType , optional } - description="Type of comment to add (e.g., single line," - defaultValue="PyCommentType.SINGLE_LINE" -/> - - - -None } description="This method modifies the symbol's comment in place."/> - - -### set_inline_comment -Sets an inline comment to the symbol. - - - -str } - description="The inline comment text to add." - defaultValue="" -/> -bool, optional } - description="If True, formats the text into a proper inline" - defaultValue="True" -/> -bool, optional } - description="If True, cleans the comment text before insertion" - defaultValue="True" -/> - - - -None } description=""/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ PyImport | PySymbol | Export ] } description="A list of symbols that use or import the exportable object."/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/python/PyTryCatchStatement.mdx b/docs/_deprecated/api-reference/python/PyTryCatchStatement.mdx deleted file mode 100644 index 80f5a19c3..000000000 --- a/docs/_deprecated/api-reference/python/PyTryCatchStatement.mdx +++ /dev/null @@ -1,507 +0,0 @@ ---- -title: "PyTryCatchStatement" -sidebarTitle: "PyTryCatchStatement" -icon: "" -description: "Abstract representation of the try/catch/finally block in Python." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[PyBlockStatement](/api-reference/python/PyBlockStatement), [TryCatchStatement](/api-reference/core/TryCatchStatement), [PyHasBlock](/api-reference/python/PyHasBlock), [BlockStatement](/api-reference/core/BlockStatement), [HasBlock](/api-reference/core/HasBlock), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### code_block - -PyCodeBlock | None } description="The code block contained within the statement, if it exists." /> - -### decorators - -list[ PyDecorator ] } description="Returns a list of decorators associated with this symbol." /> - -### docstring - -PyCommentGroup | None } description="Gets the function's docstring." /> - -### except_clauses - -list[ PyCatchStatement [ PyTryCatchStatement ]] } description="The exception handlers." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -PyFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### finalizer - -PyBlockStatement | None } description="The code block executed regardless of if an exception is thrown or not" /> - -### function_calls - -list[ FunctionCall ] } description="Gets a list of all function calls contained within the try-catch statement." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### is_decorated - -bool } description="Returns whether the symbol is decorated with decorators." /> - -### nested_code_blocks - -list[ PyCodeBlock ] } description="Returns all CodeBlocks nested within this try-catch statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ PyTryCatchStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -PyClass | None } description="Find the class this node is contained in" /> - -### parent_function - -PyFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ PyTryCatchStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ PyTryCatchStatement ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ PyTryCatchStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_docstring -Sets or updates a docstring for a Python function or class. - - - -str } - description="The docstring content to set." - defaultValue="" -/> -bool, optional } - description="Whether to format the text into a proper docstring format. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to clean and normalize the docstring format before insertion. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to force single-line comments to be converted to multi-line format. Defaults to False." - defaultValue="False" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/python/PyUnionType.mdx b/docs/_deprecated/api-reference/python/PyUnionType.mdx deleted file mode 100644 index 7e704fba1..000000000 --- a/docs/_deprecated/api-reference/python/PyUnionType.mdx +++ /dev/null @@ -1,396 +0,0 @@ ---- -title: "PyUnionType" -sidebarTitle: "PyUnionType" -icon: "" -description: "Union type Examples: str | int" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[UnionType](/api-reference/core/UnionType), [Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [SymbolGroup](/api-reference/core/SymbolGroup), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -PyFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### next_named_sibling - -Editable | None } description="Returns the next named sibling of the last symbol in the group." /> - -### next_sibling - -Editable | None } description="Returns the next sibling of the last symbol in the symbol group." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -PyClass | None } description="Find the class this node is contained in" /> - -### parent_function - -PyFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Get the source code content of the node." /> - -### symbols - -list[ Editable ] } description="Returns the list of symbols in the group." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Edit the source for this Collection instance. - - - -None } description=""/> - - -### find -Search for substrings in the given symbols that match `strings_to_match`. - - - -list[str] | str } - description="The string or list of strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes that exactly match the query." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable objects representing each match found."/> - - -### find_string_literals -Search for string literals matching given strings in the SymbolGroup. - - - -list[str] } - description="List of strings to search for in string literals." - defaultValue="" -/> -bool, optional } - description="If True, performs fuzzy matching instead of exact matching." - defaultValue="False" -/> - - - -list[ Editable ] } description="List of Editable nodes representing the matching string literals found within the symbols."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ PyUnionType ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ PyUnionType ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### index -Return the index of the first occurrence of value. - - - -int } description=""/> - - -### insert -Adds `value` to the container that this node represents - - - -None } description=""/> - - -### insert_after -Inserts source code after this node in the codebase. - - - -str } - description="The source code to insert." - defaultValue="" -/> -bool, optional } - description="Adjust indentation to match current text." - defaultValue="False" -/> -bool, optional } - description="Add a newline before the inserted code." - defaultValue="True" -/> -int, optional } - description="Priority of the edit operation." - defaultValue="0" -/> -bool, optional } - description="Deduplicate identical edits." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts source code before this symbol group. - - - -str } - description="The source code to insert." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of the inserted code to match the current code. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline after the inserted code. Defaults to True." - defaultValue="True" -/> -int, optional } - description="The priority of this edit operation. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to prevent duplicate insertions of the same code. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Removes an element from a Collection. - - - -Editable | None } - description="The element to remove from the Collection. If None, delegates to parent class." - defaultValue="None" -/> - - - -None } description="This method doesn't return anything."/> - - -### replace -Replaces all instances of a string with a new string in all symbols within the group. - - - -str } - description="The string to be replaced." - defaultValue="" -/> -str } - description="The string to replace with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="Number of replacements made."/> - - -### search -Searches for regex matches in the codebase. - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool, optional } - description="Whether to include string literals in the search. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to include comments in the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects representing matched text nodes in the codebase."/> - - - diff --git a/docs/_deprecated/api-reference/python/PyWhileStatement.mdx b/docs/_deprecated/api-reference/python/PyWhileStatement.mdx deleted file mode 100644 index ce65d063d..000000000 --- a/docs/_deprecated/api-reference/python/PyWhileStatement.mdx +++ /dev/null @@ -1,507 +0,0 @@ ---- -title: "PyWhileStatement" -sidebarTitle: "PyWhileStatement" -icon: "" -description: "An abstract representation of a python while statement." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[PyHasBlock](/api-reference/python/PyHasBlock), [WhileStatement](/api-reference/core/WhileStatement), [HasBlock](/api-reference/core/HasBlock), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### code_block - -PyCodeBlock } description="The code block that represents the body of the while statement." /> - -### condition - -Expression [ PyWhileStatement ] } description="The condition expression of the while statement." /> - -### decorators - -list[ PyDecorator ] } description="Returns a list of decorators associated with this symbol." /> - -### docstring - -PyCommentGroup | None } description="Gets the function's docstring." /> - -### else_statement - -PyIfBlockStatement [ PyCodeBlock [ PyWhileStatement ]] | None } description="the statement that will run if the while loop completes, if any." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -PyFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns all function calls within the while statement and its else block." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### is_decorated - -bool } description="Returns whether the symbol is decorated with decorators." /> - -### nested_code_blocks - -list[ PyCodeBlock ] } description="Returns a list of all code blocks nested within the while statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ PyWhileStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -PyClass | None } description="Find the class this node is contained in" /> - -### parent_function - -PyFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ PyWhileStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ PyWhileStatement ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ PyWhileStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_docstring -Sets or updates a docstring for a Python function or class. - - - -str } - description="The docstring content to set." - defaultValue="" -/> -bool, optional } - description="Whether to format the text into a proper docstring format. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to clean and normalize the docstring format before insertion. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to force single-line comments to be converted to multi-line format. Defaults to False." - defaultValue="False" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/typescript/JSXElement.mdx b/docs/_deprecated/api-reference/typescript/JSXElement.mdx deleted file mode 100644 index 0b9ddc9d9..000000000 --- a/docs/_deprecated/api-reference/typescript/JSXElement.mdx +++ /dev/null @@ -1,542 +0,0 @@ ---- -title: "JSXElement" -sidebarTitle: "JSXElement" -icon: "" -description: "Abstract representation of TSX/JSX elements, e.g. ``. This allows for many React-specific modifications, like adding props, changing the name, etc." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName), [Editable](/api-reference/core/Editable) - -## Attributes - -### attributes - -list[ JSXProp ] } description="Returns all JSXProp on this JSXElement, an alias for JSXElement.props." /> - -### expressions - -list[ JSXExpression ] } description="Gets all JSX expressions within the JSX element." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### jsx_elements - -list[ JSXElement ] } description="Returns a list of JSX elements nested within the current element." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### props - -list[ JSXProp ] } description="Retrieves all JSXProps (attributes) from a JSX element." /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_prop -Adds a new prop to a JSXElement. - - - -str } - description="The name of the prop to add." - defaultValue="" -/> -str } - description="The value of the prop to add." - defaultValue="" -/> - - - -None } description=""/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ JSXElement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ JSXElement ] } description=""/> - - -### get_name -Returns the name node of the object. - - - -Name | TSChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_prop -Returns the JSXProp with the given name from the JSXElement. - - - -str } - description="The name of the prop to find." - defaultValue="" -/> - - - -JSXProp | None } description="The matching JSXProp object if found, None if not found."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ JSXElement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Sets the name of an object and updates all its usages. - - - -str } - description="The new name to assign to the object." - defaultValue="" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_name -Sets the name of a JSXElement by modifying both opening and closing tags. - - - -str } - description="The new name to set for the JSX element." - defaultValue="" -/> - - - -None } description="The method modifies the JSXElement in place."/> - - -### wrap -Wraps the current JSXElement with the provided opening and closing tags, properly handling indentation. - - - -str } - description="The opening JSX tag to wrap around the current element (e.g. `
`)" - defaultValue="" -/> -str } - description="The closing JSX tag to wrap around the current element (e.g. `
`)" - defaultValue="" -/> -
- - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/typescript/JSXExpression.mdx b/docs/_deprecated/api-reference/typescript/JSXExpression.mdx deleted file mode 100644 index 7eca323fa..000000000 --- a/docs/_deprecated/api-reference/typescript/JSXExpression.mdx +++ /dev/null @@ -1,434 +0,0 @@ ---- -title: "JSXExpression" -sidebarTitle: "JSXExpression" -icon: "" -description: "Abstract representation of TSX/JSX expression" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Unwrappable](/api-reference/core/Unwrappable), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### statement - -Editable [ JSXExpression ] | None } description="Returns the editable component of this JSX expression." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ JSXExpression ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ JSXExpression ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ JSXExpression ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Simplifies a JSX expression by reducing it based on a boolean condition. - - - -bool } - description="The boolean value to reduce the condition to." - defaultValue="" -/> - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### unwrap -Removes the brackets from a JSX expression. - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/typescript/JSXProp.mdx b/docs/_deprecated/api-reference/typescript/JSXProp.mdx deleted file mode 100644 index 28b299f4a..000000000 --- a/docs/_deprecated/api-reference/typescript/JSXProp.mdx +++ /dev/null @@ -1,488 +0,0 @@ ---- -title: "JSXProp" -sidebarTitle: "JSXProp" -icon: "" -description: "Abstract representation of TSX/JSX prop, e.g ``." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[HasValue](/api-reference/core/HasValue), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName), [Editable](/api-reference/core/Editable) - -## Attributes - -### expression - -JSXExpression | None } description="Retrieves the JSX expression associated with this JSX prop." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### value - -Expression | None } description="Gets the value node of the object." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ JSXProp ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ JSXProp ] } description=""/> - - -### get_name -Returns the name node of the object. - - - -Name | TSChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ JSXProp ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts source code after a JSX prop in a TypeScript/JSX file. - - - -str } - description="The source code to insert after the prop." - defaultValue="" -/> -bool, optional } - description="Whether to fix the indentation of the inserted code. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline after the inserted code. Defaults to True." - defaultValue="True" -/> -int, optional } - description="The priority of the insertion. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to prevent duplicate insertions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Insert a new source code string before a JSX prop in a React component. - - - -str } - description="The source code string to insert before the prop." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of the inserted code. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline after the inserted code. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of this insertion relative to others. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to avoid duplicate insertions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Sets the name of an object and updates all its usages. - - - -str } - description="The new name to assign to the object." - defaultValue="" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### set_value -Sets the value of the node's value Expression. - - - -str } - description="The new value to set." - defaultValue="" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSArrayType.mdx b/docs/_deprecated/api-reference/typescript/TSArrayType.mdx deleted file mode 100644 index 4e8d9e5cc..000000000 --- a/docs/_deprecated/api-reference/typescript/TSArrayType.mdx +++ /dev/null @@ -1,463 +0,0 @@ ---- -title: "TSArrayType" -sidebarTitle: "TSArrayType" -icon: "" -description: "Array type Examples: string[]" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[TSNamedType](/api-reference/typescript/TSNamedType), [NamedType](/api-reference/core/NamedType), [HasName](/api-reference/core/HasName), [Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSArrayType ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSArrayType ] } description=""/> - - -### get_name -Returns the name node of the object. - - - -Name | TSChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSArrayType ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Sets the name of an object and updates all its usages. - - - -str } - description="The new name to assign to the object." - defaultValue="" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSAssignment.mdx b/docs/_deprecated/api-reference/typescript/TSAssignment.mdx deleted file mode 100644 index ceee6b6a9..000000000 --- a/docs/_deprecated/api-reference/typescript/TSAssignment.mdx +++ /dev/null @@ -1,858 +0,0 @@ ---- -title: "TSAssignment" -sidebarTitle: "TSAssignment" -icon: "" -description: "A class representing TypeScript assignments, including variable declarations and property assignments. Handles various types of TypeScript assignments including variable declarators, assignment expressions, augmented assignments, property signatures, and public field definitions. It provides functionality for manipulating assignments and managing their associated types and comments." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[TSSymbol](/api-reference/typescript/TSSymbol), [Assignment](/api-reference/core/Assignment), [Exportable](/api-reference/core/Exportable), [Symbol](/api-reference/core/Symbol), [HasValue](/api-reference/core/HasValue), [Typeable](/api-reference/core/Typeable), [Usable](/api-reference/core/Usable), [Importable](/api-reference/core/Importable), [Editable](/api-reference/core/Editable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName) - -## Attributes - -### comment - -TSCommentGroup | None } description="Retrieves the comment group associated with the symbol." /> - -### export - -TSExport | None } description="Returns the export object that exports this symbol." /> - -### exported_name - -str | None } description="Retrieves the exported name of a symbol from its file." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_nodes - -list[ Editable ] } description="Returns the list of nodes associated with this symbol including extended nodes." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### has_semicolon - -bool } description="Checks whether the current symbol has a semicolon at the end." /> - -### index - -int } description="Returns the index of the assignment statement in its parent's code block." /> - -### inline_comment - -TSCommentGroup | None } description="Property that retrieves the inline comment group associated with the symbol." /> - -### is_exported - -bool } description="Indicates if the symbol is exported from its defining file." /> - -### is_local_variable - -bool } description="Determines if an assignment represents a local variable in the current scope." /> - -### is_reexported - -bool } description="Determines if the symbol is re-exported from a different file." /> - -### is_typed - -bool } description="Indicates if a node has an explicit type annotation." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### semicolon_node - -Editable | None } description="Retrieves the semicolon node associated with a TypeScript symbol." /> - -### source - -str } description="Returns the source code of the symbol." /> - -### symbol_type - - } description="The type of symbol, set to SymbolType.GlobalVar." /> - -### type - -Type | TypePlaceholder [ TSAssignment ] } description="The type annotation associated with this node" /> - -### value - -Expression | None } description="Gets the value node of the object." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_comment -Adds a new comment to the symbol. - - - -str } - description="The comment text to be added." - defaultValue="" -/> -bool } - description="Whether to automatically format the text into a comment style. Defaults to True." - defaultValue="True" -/> -bool } - description="Whether to clean the format of the comment before inserting. Defaults to True." - defaultValue="True" -/> -TSCommentType } - description="Type of comment to add. Defaults to TSCommentType.DOUBLE_SLASH." - defaultValue="TSCommentType.DOUBLE_SLASH" -/> - - - -None } description=""/> - - -### add_keyword -Insert a keyword in the appropriate place before this symbol if it doesn't already exist. - - - -str } - description="The keyword to be inserted. Must be a valid keyword in the language context." - defaultValue="" -/> - - - -None } description=""/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ TSSymbol , TSImport ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this node with new_src. - - - -str } - description="The new source code to replace the current source with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, prevents duplicate edits. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSAssignment ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Flags a TypeScript symbol by adding a flag comment and returning a CodeFlag. - - - -CodeFlag[ TSAssignment ] } description="The code flag object for tracking purposes"/> - - -### from_named_expression -Creates a MultiExpression object from a TypeScript named expression node. - - - -TSNode } - description="The TypeScript node representing the named expression." - defaultValue="" -/> -NodeId } - description="The unique identifier for the file containing this node." - defaultValue="" -/> -CodebaseContext } - description="The graph representation of the codebase." - defaultValue="" -/> -Editable } - description="The parent node containing this expression." - defaultValue="" -/> - - - -MultiExpression [ TSAssignmentStatement , TSAssignment ] } description="A MultiExpression object containing the constructed assignments."/> - - -### get_import_string -Generates the appropriate import string for a symbol. - - - -str | None, optional } - description="The alias to use for the imported symbol. Defaults to None." - defaultValue="None" -/> -str | None, optional } - description="The module to import from. If None, uses the file's import module name." - defaultValue="None" -/> -ImportType , optional } - description="The type of import to generate (e.g., WILDCARD). Defaults to" - defaultValue="ImportType.UNKNOWN" -/> -bool, optional } - description="Whether this is a type-only import. Defaults to False." - defaultValue="False" -/> - - - -str } description="A formatted import statement string."/> - - -### get_name -Returns the name node of the object. - - - -Name | TSChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSAssignment ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before the current symbol node in the Abstract Syntax Tree. - - - -str } - description="The source code text to insert." - defaultValue="" -/> -bool } - description="Whether to adjust the indentation of new_src to match current text. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after insertion. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to remove duplicate insertions. Defaults to True." - defaultValue="True" -/> -bool } - description="Whether to insert before extended nodes like comments and decorators. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### local_usages -Retrieves all usages of the assigned variable within its code block scope. - - - -list[ Editable [ Statement ]] } description="A sorted list of statement nodes where the variable is used."/> - - -### move_to_file -Moves the given symbol to a new file and updates its imports and references. - - - -TSFile } - description="The destination file to move the symbol to." - defaultValue="" -/> -bool } - description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." - defaultValue="True" -/> -str } - description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." - defaultValue=""update_all_imports"" -/> - - - -None } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Simplifies an assignment expression by reducing it based on a boolean condition and updating all the usages. - - - -bool } - description="The boolean value to reduce the condition to." - defaultValue="" -/> - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Renames a symbol and updates all its references in the codebase. - - - -str } - description="The new name for the symbol." - defaultValue="" -/> -int } - description="Priority of the edit operation. Defaults to 0." - defaultValue="0" -/> - - - -tuple[NodeId, NodeId] } description="A tuple containing the file node ID and the new node ID of the renamed symbol."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_comment -Sets a comment to the symbol. - - - -str } - description="The comment text to be added." - defaultValue="" -/> -bool, optional } - description="Whether to automatically format the text into a comment syntax." - defaultValue="True" -/> -bool, optional } - description="Whether to clean the format of the comment before inserting." - defaultValue="True" -/> -TSCommentType , optional } - description="The style of comment to add." - defaultValue="TSCommentType.DOUBLE_SLASH" -/> - - - -None } description=""/> - - -### set_inline_comment -Sets an inline comment for an assignment node. - - - -str } - description="The comment text to set." - defaultValue="" -/> -bool, optional } - description="Whether to automatically format the comment. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to clean existing formatting. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### set_type_annotation -Adds or updates a type annotation for the current assignment. - - - -str } - description="The type annotation to be added or updated." - defaultValue="" -/> - - - -None } description=""/> - - -### set_value -Sets the value of an assignment expression. - - - -str } - description="The source code string representing the new value to be assigned." - defaultValue="" -/> - - - -None } description=""/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ TSImport | TSSymbol | TSExport ] } description="A list of symbols that use or import the exportable object."/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSAssignmentStatement.mdx b/docs/_deprecated/api-reference/typescript/TSAssignmentStatement.mdx deleted file mode 100644 index 2213aaae1..000000000 --- a/docs/_deprecated/api-reference/typescript/TSAssignmentStatement.mdx +++ /dev/null @@ -1,458 +0,0 @@ ---- -title: "TSAssignmentStatement" -sidebarTitle: "TSAssignmentStatement" -icon: "" -description: "A class that represents a TypeScript assignment statement in a codebase, such as `const x = 1` or `const { a: b } = myFunc()`." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[AssignmentStatement](/api-reference/core/AssignmentStatement), [HasValue](/api-reference/core/HasValue), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### assignments - -list[ TSAssignment ] } description="A list of assignments within the statement." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### left - -Expression [ TSAssignment ] } description="The left-hand side expression of the first assignment." /> - -### nested_code_blocks - -list[ Editable ] } description="Returns all nested code blocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ TSAssignmentStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### right - -Expression [ TSAssignment ] | None } description="The right-hand side expression of the first assignment, or None if not applicable." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### value - -Expression | None } description="Gets the value node of the object." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSAssignmentStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSAssignmentStatement ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSAssignmentStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_value -Sets the value of the node's value Expression. - - - -str } - description="The new value to set." - defaultValue="" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSAttribute.mdx b/docs/_deprecated/api-reference/typescript/TSAttribute.mdx deleted file mode 100644 index 9be409a3a..000000000 --- a/docs/_deprecated/api-reference/typescript/TSAttribute.mdx +++ /dev/null @@ -1,600 +0,0 @@ ---- -title: "TSAttribute" -sidebarTitle: "TSAttribute" -icon: "" -description: "Typescript implementation of Attribute detached symbol." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[TSAssignmentStatement](/api-reference/typescript/TSAssignmentStatement), [Attribute](/api-reference/core/Attribute), [AssignmentStatement](/api-reference/core/AssignmentStatement), [Usable](/api-reference/core/Usable), [HasValue](/api-reference/core/HasValue), [Statement](/api-reference/core/Statement), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName) - -## Attributes - -### assignment - -TSAssignment } description="The assignment associated with the attribute." /> - -### assignments - -list[ TSAssignment ] } description="A list of assignments within the statement." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### is_optional - -bool } description="Returns True if this attribute is marked as optional in TypeScript." /> - -### is_private - -bool } description="Determines if this attribute has a private accessibility modifier." /> - -### left - -Expression [ TSAssignment ] } description="The left-hand side expression of the first assignment." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### nested_code_blocks - -list[ Editable ] } description="Returns all nested code blocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ TSAttribute ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### right - -Expression [ TSAssignment ] | None } description="The right-hand side expression of the first assignment, or None if not applicable." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### value - -Expression | None } description="Gets the value node of the object." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ TSSymbol , TSImport ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSAttribute ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSAttribute ] } description=""/> - - -### get_name -Returns the name node of the object. - - - -Name | TSChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSAttribute ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### local_usages -Returns local usages of a TypeScript attribute within its code block. - - - -TSAttribute[TSHasBlock, TSCodeBlock] } - description="The TypeScript attribute instance." - defaultValue="" -/> - - - -list[ Editable ] } description="A sorted list of unique Editable instances representing local usages of the attribute, ordered by their position in the source code."/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Renames a symbol and updates all its references in the codebase. - - - -str } - description="The new name for the symbol." - defaultValue="" -/> -int } - description="Priority of the edit operation. Defaults to 0." - defaultValue="0" -/> - - - -tuple[NodeId, NodeId] } description="A tuple containing the file node ID and the new node ID of the renamed symbol."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### set_value -Sets the value of a node's assignment. - - - -str } - description="The new value to set for the assignment." - defaultValue="" -/> - - - -None } description=""/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ TSImport | TSSymbol | TSExport ] } description="A list of symbols that use or import the exportable object."/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSBlockStatement.mdx b/docs/_deprecated/api-reference/typescript/TSBlockStatement.mdx deleted file mode 100644 index 1b5216553..000000000 --- a/docs/_deprecated/api-reference/typescript/TSBlockStatement.mdx +++ /dev/null @@ -1,526 +0,0 @@ ---- -title: "TSBlockStatement" -sidebarTitle: "TSBlockStatement" -icon: "" -description: "Statement which contains a block." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[TSHasBlock](/api-reference/typescript/TSHasBlock), [BlockStatement](/api-reference/core/BlockStatement), [HasBlock](/api-reference/core/HasBlock), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### code_block - -TSCodeBlock | None } description="The code block contained within the statement, if it exists." /> - -### decorators - -list[ TSDecorator ] } description="Returns a list of decorators associated with this symbol." /> - -### docstring - -TSCommentGroup | None } description="Retrieves the docstring of a function or class." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Gets all function calls within the statement's code block." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### is_decorated - -bool } description="Checks if the current symbol has a decorator." /> - -### jsx_elements - -list[ JSXElement [ TSBlockStatement ]] } description="Returns a list of all JSX elements contained within this symbol." /> - -### nested_code_blocks - -list[ TSCodeBlock ] } description="Returns all nested CodeBlocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ TSBlockStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSBlockStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSBlockStatement ] } description=""/> - - -### get_component -Returns a specific JSX element from within this symbol's JSX elements. - - - -str } - description="The name of the JSX component to find." - defaultValue="" -/> - - - -JSXElement [ TSBlockStatement ] | None } description="The matching JSX element if found, None otherwise."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSBlockStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_docstring -Sets or updates a docstring for a code element. - - - -str } - description="The docstring text to be added or updated." - defaultValue="" -/> -bool, optional } - description="Whether to automatically format the text into a docstring format. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to clean existing formatting from the docstring before inserting. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to add leading "*" to each line of the comment block. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to force single line comments to be multi-line. Defaults to False." - defaultValue="False" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSCatchStatement.mdx b/docs/_deprecated/api-reference/typescript/TSCatchStatement.mdx deleted file mode 100644 index e1dec977e..000000000 --- a/docs/_deprecated/api-reference/typescript/TSCatchStatement.mdx +++ /dev/null @@ -1,530 +0,0 @@ ---- -title: "TSCatchStatement" -sidebarTitle: "TSCatchStatement" -icon: "" -description: "Typescript catch clause." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[TSBlockStatement](/api-reference/typescript/TSBlockStatement), [CatchStatement](/api-reference/core/CatchStatement), [TSHasBlock](/api-reference/typescript/TSHasBlock), [BlockStatement](/api-reference/core/BlockStatement), [HasBlock](/api-reference/core/HasBlock), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### code_block - -TSCodeBlock | None } description="The code block contained within the statement, if it exists." /> - -### condition - -Expression [ TSCatchStatement ] | None } description="The condition which triggers this clause" /> - -### decorators - -list[ TSDecorator ] } description="Returns a list of decorators associated with this symbol." /> - -### docstring - -TSCommentGroup | None } description="Retrieves the docstring of a function or class." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Gets all function calls within the statement's code block." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### is_decorated - -bool } description="Checks if the current symbol has a decorator." /> - -### jsx_elements - -list[ JSXElement [ TSCatchStatement ]] } description="Returns a list of all JSX elements contained within this symbol." /> - -### nested_code_blocks - -list[ TSCodeBlock ] } description="Returns all nested CodeBlocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ TSCatchStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSCatchStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSCatchStatement ] } description=""/> - - -### get_component -Returns a specific JSX element from within this symbol's JSX elements. - - - -str } - description="The name of the JSX component to find." - defaultValue="" -/> - - - -JSXElement [ TSCatchStatement ] | None } description="The matching JSX element if found, None otherwise."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSCatchStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_docstring -Sets or updates a docstring for a code element. - - - -str } - description="The docstring text to be added or updated." - defaultValue="" -/> -bool, optional } - description="Whether to automatically format the text into a docstring format. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to clean existing formatting from the docstring before inserting. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to add leading "*" to each line of the comment block. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to force single line comments to be multi-line. Defaults to False." - defaultValue="False" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSChainedAttribute.mdx b/docs/_deprecated/api-reference/typescript/TSChainedAttribute.mdx deleted file mode 100644 index c77f3ec08..000000000 --- a/docs/_deprecated/api-reference/typescript/TSChainedAttribute.mdx +++ /dev/null @@ -1,429 +0,0 @@ ---- -title: "TSChainedAttribute" -sidebarTitle: "TSChainedAttribute" -icon: "" -description: "A TypeScript chained attribute class representing member access expressions. This class handles the representation and analysis of chained attribute access expressions in TypeScript, such as 'object.property' or 'object.method()'. It provides functionality for accessing the object and property components of the expression, as well as analyzing function calls made on the object." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[ChainedAttribute](/api-reference/core/ChainedAttribute), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### attribute - -TSAttribute } description="Gets the attribute being accessed in a chained attribute expression." /> - -### attribute_chain - -list[ FunctionCall | Name ] } description="Returns a list of elements in a chained attribute expression." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str } description="Returns the full name of the attribute, including the object expression." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of function calls associated with this chained attribute's object." /> - -### object - -Object } description="Returns the object that contains the attribute being looked up." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSChainedAttribute ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSChainedAttribute ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSChainedAttribute ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSClass.mdx b/docs/_deprecated/api-reference/typescript/TSClass.mdx deleted file mode 100644 index 15370aa76..000000000 --- a/docs/_deprecated/api-reference/typescript/TSClass.mdx +++ /dev/null @@ -1,1200 +0,0 @@ ---- -title: "TSClass" -sidebarTitle: "TSClass" -icon: "" -description: "A class representing a TypeScript/JavaScript class with enhanced functionality for class manipulation. The TSClass provides comprehensive functionality for working with TypeScript/JavaScript classes, including handling class methods, attributes, JSX components, and inheritance relationships. It supports operations like adding source code to class bodies, managing class attributes, and handling React JSX components." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[TSHasBlock](/api-reference/typescript/TSHasBlock), [TSSymbol](/api-reference/typescript/TSSymbol), [Class](/api-reference/core/Class), [HasBlock](/api-reference/core/HasBlock), [Exportable](/api-reference/core/Exportable), [Symbol](/api-reference/core/Symbol), [Callable](/api-reference/core/Callable), [Expression](/api-reference/core/Expression), [Usable](/api-reference/core/Usable), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [HasName](/api-reference/core/HasName) - -## Attributes - -### call_sites - -list[ FunctionCall ] } description="Returns all call sites (invocations) of this callable in the codebase." /> - -### code_block - -TSCodeBlock } description="The block of code associated with the code object." /> - -### comment - -TSCommentGroup | None } description="Retrieves the comment group associated with the symbol." /> - -### constructor - -TSFunction | None } description="Returns the constructor method for this class." /> - -### decorators - -list[ TSDecorator ] } description="Returns a list of decorators associated with this symbol." /> - -### docstring - -TSCommentGroup | None } description="Retrieves the docstring of a function or class." /> - -### export - -TSExport | None } description="Returns the export object that exports this symbol." /> - -### exported_name - -str | None } description="Retrieves the exported name of a symbol from its file." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_nodes - -list[ Editable ] } description="Returns the list of nodes associated with this symbol including extended nodes." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns all function calls within the code block and its decorators." /> - -### has_semicolon - -bool } description="Checks whether the current symbol has a semicolon at the end." /> - -### inline_comment - -TSCommentGroup | None } description="Property that retrieves the inline comment group associated with the symbol." /> - -### is_decorated - -bool } description="Checks if the current symbol has a decorator." /> - -### is_exported - -bool } description="Indicates if the symbol is exported from its defining file." /> - -### is_jsx - -bool } description="Determine if the class is a React JSX component." /> - -### is_reexported - -bool } description="Determines if the symbol is re-exported from a different file." /> - -### is_subclass - -bool } description="Indicates whether the current class is a subclass of another class." /> - -### jsx_elements - -list[ JSXElement [ TSClass ]] } description="Returns a list of all JSX elements contained within this symbol." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### nested_classes - -list[ TSClass ] } description="Retrieves the nested classes defined within this class." /> - -### parameters - -SymbolGroup [ TSParameter , TSClass ] | list[ TSParameter ] } description="Retrieves all parameters of a callable symbol." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_class_names - -list[ Name | TSChainedAttribute ] } description="Returns a list of the parent class names that this class inherits from." /> - -### parent_classes - -Parents[ Type , TSClass ] | None } description="The parent classes of this class, if any." /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### return_type - -Type | Placeholder [ TSClass ] } description="The type of value returned by the callable, or a placeholder." /> - -### semicolon_node - -Editable | None } description="Retrieves the semicolon node associated with a TypeScript symbol." /> - -### source - -str } description="Returns the source code of the symbol." /> - -### symbol_type - - } description="The type of symbol, set to SymbolType.Class." /> - -### type_parameters - -TypeParameters[ Type , TSClass ] | None } description="The type parameters of the symbol, if any." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_attribute -Adds an attribute to a class from another class. - - - -TSAttribute } - description="The attribute to add to the class." - defaultValue="" -/> -bool, optional } - description="Whether to include the attribute's dependencies. If True, adds any necessary imports to the class's file. Defaults to False." - defaultValue="False" -/> - - - -None } description=""/> - - -### add_attribute_from_source -Adds a class attribute from source code to a TypeScript/JavaScript class. - - - -str } - description="The source code of the attribute to add to the class." - defaultValue="" -/> - - - -None } description=""/> - - -### add_comment -Adds a new comment to the symbol. - - - -str } - description="The comment text to be added." - defaultValue="" -/> -bool } - description="Whether to automatically format the text into a comment style. Defaults to True." - defaultValue="True" -/> -bool } - description="Whether to clean the format of the comment before inserting. Defaults to True." - defaultValue="True" -/> -TSCommentType } - description="Type of comment to add. Defaults to TSCommentType.DOUBLE_SLASH." - defaultValue="TSCommentType.DOUBLE_SLASH" -/> - - - -None } description=""/> - - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### add_keyword -Insert a keyword in the appropriate place before this symbol if it doesn't already exist. - - - -str } - description="The keyword to be inserted. Must be a valid keyword in the language context." - defaultValue="" -/> - - - -None } description=""/> - - -### add_source -Adds source code to a class body. - - - -str } - description="The source code to be added to the class body." - defaultValue="" -/> - - - -None } description=""/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### attributes -Retrieves all attributes from this Class including those from its superclasses up to a - - - -int | None } - description="The maximum depth of superclass traversal. None means no limit, 0 means only this class." - defaultValue="0" -/> -bool } - description="Whether to include private attributes. Defaults to True." - defaultValue="True" -/> - - - -list[ TSAttribute ] } description="A list of unique attributes from this class and its superclasses. If an attribute is defined in multiple classes, the first definition encountered is used."/> - - -### class_component_to_function_component -Converts a class component to a function component. - - - -None } description=""/> - - -### convert_props_to_interface -Converts React component props to TypeScript interfaces. - - - -None } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ TSSymbol , TSImport ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this node with new_src. - - - -str } - description="The new source code to replace the current source with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, prevents duplicate edits. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSClass ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Flags a TypeScript symbol by adding a flag comment and returning a CodeFlag. - - - -CodeFlag[ TSClass ] } description="The code flag object for tracking purposes"/> - - -### get_attribute -Returns a specific attribute by name. - - - -str } - description="The name of the attribute to search for." - defaultValue="" -/> - - - -TSAttribute | None } description="The matching attribute if found, None otherwise. If multiple attributes with the same name exist in the inheritance hierarchy, returns the first one found."/> - - -### get_component -Returns a specific JSX element from within this symbol's JSX elements. - - - -str } - description="The name of the JSX component to find." - defaultValue="" -/> - - - -JSXElement [ TSClass ] | None } description="The matching JSX element if found, None otherwise."/> - - -### get_import_string -Generates the appropriate import string for a symbol. - - - -str | None, optional } - description="The alias to use for the imported symbol. Defaults to None." - defaultValue="None" -/> -str | None, optional } - description="The module to import from. If None, uses the file's import module name." - defaultValue="None" -/> -ImportType , optional } - description="The type of import to generate (e.g., WILDCARD). Defaults to" - defaultValue="ImportType.UNKNOWN" -/> -bool, optional } - description="Whether this is a type-only import. Defaults to False." - defaultValue="False" -/> - - - -str } description="A formatted import statement string."/> - - -### get_method -Returns a specific method by name from the class or any of its superclasses. - - - -str } - description="The name of the method to find." - defaultValue="" -/> - - - -TSFunction | None } description="The method if found, None otherwise."/> - - -### get_name -Returns the name node of the object. - - - -Name | TSChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_nested_class -Returns a nested class by name from the current class. - - - -str } - description="The name of the nested class to find." - defaultValue="" -/> - - - -TSClass | None } description="The nested class if found, None otherwise."/> - - -### get_parameter -Gets a specific parameter from the callable's parameters list by name. - - - -str } - description="The name of the parameter to retrieve." - defaultValue="" -/> - - - -TSParameter | None } description="The parameter with the specified name, or None if no parameter with that name exists or if there are no parameters."/> - - -### get_parameter_by_index -Returns the parameter at the given index. - - - -int } - description="The index of the parameter to retrieve." - defaultValue="" -/> - - - -TSParameter | None } description="The parameter at the specified index, or None if the parameter list is empty or the index does not exist."/> - - -### get_parameter_by_type -Retrieves a parameter from the callable by its type. - - - -TSSymbol } - description="The type to search for." - defaultValue="" -/> - - - -TSParameter | None } description="The parameter with the specified type, or None if no parameter is found or if the callable has no parameters."/> - - -### get_parent_class -Returns the parent class node with the specified name. - - - -str } - description="The name of the parent class to find." - defaultValue="" -/> - - - -Editable | None } description="The matching parent class node, or None if no match is found."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSClass ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before the current symbol node in the Abstract Syntax Tree. - - - -str } - description="The source code text to insert." - defaultValue="" -/> -bool } - description="Whether to adjust the indentation of new_src to match current text. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after insertion. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to remove duplicate insertions. Defaults to True." - defaultValue="True" -/> -bool } - description="Whether to insert before extended nodes like comments and decorators. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_subclass_of -Checks if the class inherits from a specified parent class. - - - -str | TSClass } - description="The parent class to check for. Can be specified either as a class name string or Class object." - defaultValue="" -/> -int | None } - description="Maximum inheritance depth to search. None means no limit." - defaultValue="None" -/> - - - -bool } description="True if this class inherits from the parent class, False otherwise."/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### methods -Retrieves all methods that exist on this Class, including methods from superclasses, with - - - -int | None, optional } - description="Include parent classes up to max_depth. None means no limit, 0 means only current class. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to include private methods. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to include magic methods. Defaults to False." - defaultValue="True" -/> - - - -list[ TSFunction ] | MultiLineCollection [ TSFunction , TSClass ] } description=""/> - - -### move_to_file -Moves the given symbol to a new file and updates its imports and references. - - - -TSFile } - description="The destination file to move the symbol to." - defaultValue="" -/> -bool } - description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." - defaultValue="True" -/> -str } - description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." - defaultValue=""update_all_imports"" -/> - - - -None } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Renames a symbol and updates all its references in the codebase. - - - -str } - description="The new name for the symbol." - defaultValue="" -/> -int } - description="Priority of the edit operation. Defaults to 0." - defaultValue="0" -/> - - - -tuple[NodeId, NodeId] } description="A tuple containing the file node ID and the new node ID of the renamed symbol."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_comment -Sets a comment to the symbol. - - - -str } - description="The comment text to be added." - defaultValue="" -/> -bool, optional } - description="Whether to automatically format the text into a comment syntax." - defaultValue="True" -/> -bool, optional } - description="Whether to clean the format of the comment before inserting." - defaultValue="True" -/> -TSCommentType , optional } - description="The style of comment to add." - defaultValue="TSCommentType.DOUBLE_SLASH" -/> - - - -None } description=""/> - - -### set_docstring -Sets or updates a docstring for a code element. - - - -str } - description="The docstring text to be added or updated." - defaultValue="" -/> -bool, optional } - description="Whether to automatically format the text into a docstring format. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to clean existing formatting from the docstring before inserting. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to add leading "*" to each line of the comment block. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to force single line comments to be multi-line. Defaults to False." - defaultValue="False" -/> - - - -None } description=""/> - - -### set_inline_comment -Sets an inline comment to the symbol. - - - -str } - description="The inline comment text to be added." - defaultValue="" -/> -bool, optional } - description="Whether to automatically format the text as a comment." - defaultValue="True" -/> -bool, optional } - description="Whether to clean the comment format before inserting." - defaultValue="True" -/> -TSNode | None, optional } - description="The specific node to attach the comment to." - defaultValue="None" -/> - - - -None } description=""/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### subclasses -Returns all classes which subclass this class. - - - -int | None, optional } - description="Maximum inheritance depth to search. If None, searches all depths. Defaults to None." - defaultValue="None" -/> - - - -list[ TSClass ] } description="A list of Class objects that inherit from this class."/> - - -### superclasses -Returns a list of all classes that this class extends, up to max_depth. - - - -int | None } - description="The maximum depth to traverse up the inheritance tree. If None, traverses the entire tree." - defaultValue="None" -/> - - - -list[ TSClass | ExternalModule | TSInterface ] } description="A list of all superclass symbols in MRO order, up to max_depth. Returns an empty list if the class has no parent classes."/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ TSImport | TSSymbol | TSExport ] } description="A list of symbols that use or import the exportable object."/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSCodeBlock.mdx b/docs/_deprecated/api-reference/typescript/TSCodeBlock.mdx deleted file mode 100644 index 97443eafd..000000000 --- a/docs/_deprecated/api-reference/typescript/TSCodeBlock.mdx +++ /dev/null @@ -1,612 +0,0 @@ ---- -title: "TSCodeBlock" -sidebarTitle: "TSCodeBlock" -icon: "" -description: "Extends the CodeBlock class to provide TypeScript-specific functionality." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[CodeBlock](/api-reference/core/CodeBlock), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### assignment_statements - -list[ TSAssignmentStatement [ TSCodeBlock , TSAssignment ]] } description="Returns list of top level assignment statements in the code block." /> - -### assignments - -list[ TSAssignment [ Editable , TSCodeBlock ]] } description="Returns all assignments in the code block across all nesting levels." /> - -### attributes - -list[ TSAttribute [ Editable , TSCodeBlock ]] } description="Returns a list of top level class attribute statements in the code block." /> - -### comments - -list[ TSComment [ Editable , TSCodeBlock ]] } description="Gets list of top level comments in the code block." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls in the code block." /> - -### if_blocks - -list[ TSIfBlockStatement [ TSCodeBlock ]] } description="Returns a list of top level if statements in the code block." /> - -### level - -int } description="The indentation level of the code block." /> - -### local_var_assignments - -list[ TSAssignment [ Editable , TSCodeBlock ]] } description="Returns all local variable assignment in the code block, for all nest levels." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_block - -TSCodeBlock | None } description="The parent code block containing this block, or None if it is a top-level block." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### return_statements - -list[ ReturnStatement [ TSCodeBlock ]] } description="Gets all return statements at the top level of the code block." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### statements - -MultiLineCollection [ Statement , TSCodeBlock ] } description="Gets a view of the top-level statements in the code block." /> - -### symbol_statements - -list[ SymbolStatement ] } description="Returns list of top level symbol statements in the code block." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSCodeBlock ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSCodeBlock ] } description=""/> - - -### get_assignments -Returns a list of assignments with the specified variable name. - - - -str } - description="The name of the variable to find assignments for." - defaultValue="" -/> - - - -list[ TSAssignment [ Editable , TSCodeBlock ]] } description="A list of Assignment objects that match the variable name."/> - - -### get_attributes -Returns attributes from the code block, with the option to include or exclude private - - - -bool } - description="Whether to include private attributes in the returned list. If True, returns both private and" - defaultValue="" -/> - - - -list[ TSAttribute [ Editable , TSCodeBlock ]] } description="A list of attribute statements matching the privacy criteria."/> - - -### get_comment -Gets the first comment statement containing a specific text string. - - - -str } - description="The text string to search for within comment statements." - defaultValue="" -/> - - - -TSComment [ Editable , TSCodeBlock ] | None } description="The first comment statement containing the search text, or None if no matching comment is found."/> - - -### get_local_var_assignment -Returns the first code statement that assigns a local variable with the specified name. - - - -str } - description="The name of the local variable to search for." - defaultValue="" -/> - - - -TSAssignment [ Editable , TSCodeBlock ] | None } description="The first matching local variable assignment, or None if no match is found."/> - - -### get_local_var_assignments -Returns all instances of local variable assignments that match the specified variable - - - -str } - description="The name of the local variable to search for." - defaultValue="" -/> -bool, optional } - description="If True, matches variables whose names contain var_name." - defaultValue="False" -/> - - - -list[ TSAssignment [ Editable , TSCodeBlock ]] } description="List of Assignment objects representing local variable assignments that match the specified name criteria."/> - - -### get_statements -Returns all statements of a given type up to the specified block level. - - - -StatementType | None } - description="The type of statements to return. If None, returns all statement types." - defaultValue="None" -/> -int | None } - description="The maximum block depth level to search. If None, searches all levels." - defaultValue="None" -/> - - - -list[ Statement [ TSCodeBlock ]] } description=""/> - - -### get_variable_usages -Returns all instances of variable usages in a code block. - - - -str } - description="The name of the variable to search for." - defaultValue="" -/> -bool } - description="When True, matches on variable names that contain var_name. When False (default), only matches exact variable names." - defaultValue="False" -/> - - - -list[ Editable [ TSCodeBlock ]] } description="A sorted list of variable usage instances as Editable objects."/> - - -### indent -Adjusts the indentation level of the entire code block. - - - -int } - description="The number of indentation levels to adjust. Positive values indent right, negative values indent left." - defaultValue="" -/> - - - -None } description=""/> - - -### insert_after -Inserts source code at the bottom of the code block. - - - -str } - description="The source code to insert." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of the inserted code. Defaults to True." - defaultValue="True" -/> -bool } - description="Whether to add a newline before the inserted code. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts new source code at the top of the code block. - - - -str } - description="The source code to insert at the top of the code block." - defaultValue="" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename_variable_usages -Renames all instances of variable usages in the code block. - - - -str } - description="The current name of the variable to rename." - defaultValue="" -/> -str } - description="The new name to give the variable." - defaultValue="" -/> -bool } - description="When True, matches variables containing old_var_name. When False, only exact matches. Defaults to False." - defaultValue="False" -/> - - - -None } description="This method mutates the code block in place."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### unwrap -Unwraps a code block by removing its opening and closing braces. - - - -None } description=""/> - - -### wrap -Wraps a code block with a statement and indents it. - - - -str } - description="The source code to insert before the block." - defaultValue="" -/> -str } - description="The source code to insert after the block. Defaults to an empty string." - defaultValue="""" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSComment.mdx b/docs/_deprecated/api-reference/typescript/TSComment.mdx deleted file mode 100644 index f1297ba40..000000000 --- a/docs/_deprecated/api-reference/typescript/TSComment.mdx +++ /dev/null @@ -1,502 +0,0 @@ ---- -title: "TSComment" -sidebarTitle: "TSComment" -icon: "" -description: "Abstract representation of typescript comments" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Comment](/api-reference/core/Comment), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### comment_type - -TSCommentType } description="Determines the type of comment in a TypeScript source code." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### nested_code_blocks - -list[ TSCodeBlock ] } description="Returns a list of nested code blocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ TSComment ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### text - -str } description="Returns the text content of the comment." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### clean_comment -Cleans comment markers and whitespace from a comment string. - - - -str } - description="The raw comment string to be cleaned." - defaultValue="" -/> - - - -str } description="The cleaned comment text with comment markers and excess whitespace removed."/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### edit_text -Replace the text of a comment with new text. - - - -str } - description="The new text content to replace the existing comment text." - defaultValue="" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSComment ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSComment ] } description=""/> - - -### generate_comment -Generates a TypeScript comment block from the given text content. - - - -str } - description="The text content to be converted into a comment." - defaultValue="" -/> -TSCommentType } - description="The type of comment to generate (DOUBLE_SLASH or SLASH_STAR)." - defaultValue="" -/> -bool, optional } - description="Whether to add leading "*" to each line in multi-line comments. Defaults to True." - defaultValue="" -/> -bool, optional } - description="Whether to force multi-line format for single-line content. Defaults to False." - defaultValue="" -/> - - - -str } description="The formatted comment block as a string."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSComment ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSCommentGroup.mdx b/docs/_deprecated/api-reference/typescript/TSCommentGroup.mdx deleted file mode 100644 index a27a5e380..000000000 --- a/docs/_deprecated/api-reference/typescript/TSCommentGroup.mdx +++ /dev/null @@ -1,436 +0,0 @@ ---- -title: "TSCommentGroup" -sidebarTitle: "TSCommentGroup" -icon: "" -description: "A group of related symbols that represent a comment or docstring in TypeScript For example: ``` // Comment 1 // Comment 2 // Comment 3 ``` would be 3 individual comments (accessible via `symbols`), but together they form a `CommentGroup` (accessible via `self)." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[CommentGroup](/api-reference/core/CommentGroup), [SymbolGroup](/api-reference/core/SymbolGroup), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### next_named_sibling - -Editable | None } description="Returns the next named sibling of the last symbol in the group." /> - -### next_sibling - -Editable | None } description="Returns the next sibling of the last symbol in the symbol group." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### source - -str } description="Returns the concatenated source code of all symbols in the group." /> - -### symbols - -list[ Editable ] } description="Returns the list of symbols in the group." /> - -### text - -str } description="Return the text content of all comments in the comment block." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this node with new text. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool, optional } - description="Adjusts the indentation of new_src to match the current text's indentation. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the edit operation. Higher priority edits take precedence. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Prevents duplicate edits at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### edit_text -Replace the text content of a comment group with new text. - - - -str } - description="The new text content to replace the existing comment text." - defaultValue="" -/> - - - -None } description=""/> - - -### find -Search for substrings in the given symbols that match `strings_to_match`. - - - -list[str] | str } - description="The string or list of strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes that exactly match the query." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable objects representing each match found."/> - - -### find_string_literals -Search for string literals matching given strings in the SymbolGroup. - - - -list[str] } - description="List of strings to search for in string literals." - defaultValue="" -/> -bool, optional } - description="If True, performs fuzzy matching instead of exact matching." - defaultValue="False" -/> - - - -list[ Editable ] } description="List of Editable nodes representing the matching string literals found within the symbols."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSCommentGroup ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSCommentGroup ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts source code after this node in the codebase. - - - -str } - description="The source code to insert." - defaultValue="" -/> -bool, optional } - description="Adjust indentation to match current text." - defaultValue="False" -/> -bool, optional } - description="Add a newline before the inserted code." - defaultValue="True" -/> -int, optional } - description="Priority of the edit operation." - defaultValue="0" -/> -bool, optional } - description="Deduplicate identical edits." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts source code before this symbol group. - - - -str } - description="The source code to insert." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of the inserted code to match the current code. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline after the inserted code. Defaults to True." - defaultValue="True" -/> -int, optional } - description="The priority of this edit operation. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to prevent duplicate insertions of the same code. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Removes this node and its related extended nodes from the codebase. - - - -bool, optional } - description="Whether to delete related extended nodes like decorators and comments. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority level of the removal operation. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate removal operations. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Replaces all instances of a string with a new string in all symbols within the group. - - - -str } - description="The string to be replaced." - defaultValue="" -/> -str } - description="The string to replace with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="Number of replacements made."/> - - -### search -Searches for regex matches in the codebase. - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool, optional } - description="Whether to include string literals in the search. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to include comments in the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects representing matched text nodes in the codebase."/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSCommentType.mdx b/docs/_deprecated/api-reference/typescript/TSCommentType.mdx deleted file mode 100644 index 4f69958cb..000000000 --- a/docs/_deprecated/api-reference/typescript/TSCommentType.mdx +++ /dev/null @@ -1,32 +0,0 @@ ---- -title: "TSCommentType" -sidebarTitle: "TSCommentType" -icon: "" -description: "An enumeration representing different types of comments in TypeScript. Represents the possible types of comments that can be used in TypeScript code, including double slash comments (//), slash star comments (/* */), and unknown comment types." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - - -## Attributes - -### DOUBLE_SLASH - - } description="Represents a single-line comment starting with //." /> - -### SLASH_STAR - - } description="Represents a multi-line comment enclosed in /* */." /> - -### UNKNOWN - - } description="Represents an unknown or unrecognized comment type." /> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSConditionalType.mdx b/docs/_deprecated/api-reference/typescript/TSConditionalType.mdx deleted file mode 100644 index 0df5bb9cf..000000000 --- a/docs/_deprecated/api-reference/typescript/TSConditionalType.mdx +++ /dev/null @@ -1,429 +0,0 @@ ---- -title: "TSConditionalType" -sidebarTitle: "TSConditionalType" -icon: "" -description: "Conditional Type Examples: typeof s" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### alternative - -TSType[ TSConditionalType ] } description="The type if the condition is false." /> - -### consequence - -TSType[ TSConditionalType ] } description="The type if the condition is true." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### left - -TSType[ TSConditionalType ] } description="The left-hand side type of the conditional type." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### right - -TSType[ TSConditionalType ] } description="The right-hand side type of the conditional type." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSConditionalType ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSConditionalType ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSConditionalType ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSConfig.mdx b/docs/_deprecated/api-reference/typescript/TSConfig.mdx deleted file mode 100644 index 37ab7da0a..000000000 --- a/docs/_deprecated/api-reference/typescript/TSConfig.mdx +++ /dev/null @@ -1,112 +0,0 @@ ---- -title: "TSConfig" -sidebarTitle: "TSConfig" -icon: "" -description: "TypeScript configuration file specified in tsconfig.json, used for import resolution and computing dependencies." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - - -## Attributes - -### base_config - -TSConfig | None } description="Returns the base TSConfig that this config inherits from." /> - -### base_url - -str | None } description="Returns the base URL defined in the TypeScript configuration." /> - -### config - -dict } description="A dictionary containing the parsed configuration settings." /> - -### config_file - -File } description="The configuration file object representing the tsconfig.json file." /> - -### config_parser - -TSConfigParser } description="The parser used to interpret the TypeScript configuration." /> - -### out_dir - -str | None } description="Returns the outDir defined in the TypeScript configuration." /> - -### path_import_aliases - -dict[str, list[str]] } description="Returns a formatted version of the paths property from a TypeScript configuration file." /> - -### paths - -dict[str, list[str]] } description="Returns all custom module path mappings defined in the tsconfig file." /> - -### reference_import_aliases - -dict[str, list[str]] } description="Returns a formatted version of the references property from a TypeScript configuration file." /> - -### references - -list[ Directory | File ] } description="Returns a list of directories that this TypeScript configuration file depends on." /> - -### root_dir - -str | None } description="Returns the rootDir defined in the TypeScript configuration." /> - -### root_dirs - -list[str] } description="Returns the rootDirs defined in the TypeScript configuration." /> - - -## Methods - -### resolve_base_url -Resolves an import path with the base url. - - - -str } description=""/> - - -### translate_absolute_path -Translates an absolute path to an import path using the tsconfig paths. - - - -str } - description="The absolute path to translate." - defaultValue="" -/> - - - -str } description="The translated import path."/> - - -### translate_import_path -Translates an import path to an absolute path using the tsconfig paths. - - - -str } - description="The import path to translate." - defaultValue="" -/> - - - -str } description="The translated absolute path. If no matching path alias is found, returns the original import path unchanged."/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSDecorator.mdx b/docs/_deprecated/api-reference/typescript/TSDecorator.mdx deleted file mode 100644 index ba1c04b6c..000000000 --- a/docs/_deprecated/api-reference/typescript/TSDecorator.mdx +++ /dev/null @@ -1,467 +0,0 @@ ---- -title: "TSDecorator" -sidebarTitle: "TSDecorator" -icon: "" -description: "Abstract representation of a Decorator" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Decorator](/api-reference/core/Decorator), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName), [Editable](/api-reference/core/Editable) - -## Attributes - -### call - -FunctionCall | None } description="Retrieves the function call expression associated with the decorator." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSDecorator ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSDecorator ] } description=""/> - - -### get_name -Returns the name node of the object. - - - -Name | TSChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSDecorator ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Sets the name of an object and updates all its usages. - - - -str } - description="The new name to assign to the object." - defaultValue="" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSDict.mdx b/docs/_deprecated/api-reference/typescript/TSDict.mdx deleted file mode 100644 index bb42a049e..000000000 --- a/docs/_deprecated/api-reference/typescript/TSDict.mdx +++ /dev/null @@ -1,417 +0,0 @@ ---- -title: "TSDict" -sidebarTitle: "TSDict" -icon: "" -description: "A typescript dict object. You can use standard operations to operate on this dict (IE len, del, set, get, etc)" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Dict](/api-reference/core/Dict), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### unpack - -Unpack [ TSDict ] | None } description="An optional unpacking element, if present." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSDict ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSDict ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSDict ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSEnum.mdx b/docs/_deprecated/api-reference/typescript/TSEnum.mdx deleted file mode 100644 index eff741266..000000000 --- a/docs/_deprecated/api-reference/typescript/TSEnum.mdx +++ /dev/null @@ -1,884 +0,0 @@ ---- -title: "TSEnum" -sidebarTitle: "TSEnum" -icon: "" -description: "Representation of an Enum in TypeScript." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[TSHasBlock](/api-reference/typescript/TSHasBlock), [TSSymbol](/api-reference/typescript/TSSymbol), [HasBlock](/api-reference/core/HasBlock), [Exportable](/api-reference/core/Exportable), [Symbol](/api-reference/core/Symbol), [Expression](/api-reference/core/Expression), [Usable](/api-reference/core/Usable), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [HasName](/api-reference/core/HasName) - -## Attributes - -### attributes - -list[ TSAttribute [ TSEnum , None]] } description="Property that retrieves the attributes of a TypeScript enum." /> - -### body - -Expression [ TSEnum ] } description="The expression representing the body of the enum." /> - -### code_block - -TSCodeBlock } description="The code block associated with the enum." /> - -### comment - -TSCommentGroup | None } description="Retrieves the comment group associated with the symbol." /> - -### decorators - -list[ TSDecorator ] } description="Returns a list of decorators associated with this symbol." /> - -### docstring - -TSCommentGroup | None } description="Retrieves the docstring of a function or class." /> - -### export - -TSExport | None } description="Returns the export object that exports this symbol." /> - -### exported_name - -str | None } description="Retrieves the exported name of a symbol from its file." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_nodes - -list[ Editable ] } description="Returns the list of nodes associated with this symbol including extended nodes." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns all function calls within the code block and its decorators." /> - -### has_semicolon - -bool } description="Checks whether the current symbol has a semicolon at the end." /> - -### inline_comment - -TSCommentGroup | None } description="Property that retrieves the inline comment group associated with the symbol." /> - -### is_decorated - -bool } description="Checks if the current symbol has a decorator." /> - -### is_exported - -bool } description="Indicates if the symbol is exported from its defining file." /> - -### is_reexported - -bool } description="Determines if the symbol is re-exported from a different file." /> - -### jsx_elements - -list[ JSXElement [ TSEnum ]] } description="Returns a list of all JSX elements contained within this symbol." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### semicolon_node - -Editable | None } description="Retrieves the semicolon node associated with a TypeScript symbol." /> - -### source - -str } description="Returns the source code of the symbol." /> - -### symbol_type - - } description="The type of symbol, set to SymbolType.Enum." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_comment -Adds a new comment to the symbol. - - - -str } - description="The comment text to be added." - defaultValue="" -/> -bool } - description="Whether to automatically format the text into a comment style. Defaults to True." - defaultValue="True" -/> -bool } - description="Whether to clean the format of the comment before inserting. Defaults to True." - defaultValue="True" -/> -TSCommentType } - description="Type of comment to add. Defaults to TSCommentType.DOUBLE_SLASH." - defaultValue="TSCommentType.DOUBLE_SLASH" -/> - - - -None } description=""/> - - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### add_keyword -Insert a keyword in the appropriate place before this symbol if it doesn't already exist. - - - -str } - description="The keyword to be inserted. Must be a valid keyword in the language context." - defaultValue="" -/> - - - -None } description=""/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ TSSymbol , TSImport ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this node with new_src. - - - -str } - description="The new source code to replace the current source with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, prevents duplicate edits. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSEnum ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Flags a TypeScript symbol by adding a flag comment and returning a CodeFlag. - - - -CodeFlag[ TSEnum ] } description="The code flag object for tracking purposes"/> - - -### get_attribute -Returns an attribute from the TypeScript enum by its name. - - - -str } - description="The name of the attribute to retrieve." - defaultValue="" -/> - - - -TSAttribute | None } description="The attribute with the given name if it exists, None otherwise."/> - - -### get_component -Returns a specific JSX element from within this symbol's JSX elements. - - - -str } - description="The name of the JSX component to find." - defaultValue="" -/> - - - -JSXElement [ TSEnum ] | None } description="The matching JSX element if found, None otherwise."/> - - -### get_import_string -Generates the appropriate import string for a symbol. - - - -str | None, optional } - description="The alias to use for the imported symbol. Defaults to None." - defaultValue="None" -/> -str | None, optional } - description="The module to import from. If None, uses the file's import module name." - defaultValue="None" -/> -ImportType , optional } - description="The type of import to generate (e.g., WILDCARD). Defaults to" - defaultValue="ImportType.UNKNOWN" -/> -bool, optional } - description="Whether this is a type-only import. Defaults to False." - defaultValue="False" -/> - - - -str } description="A formatted import statement string."/> - - -### get_name -Returns the name node of the object. - - - -Name | TSChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSEnum ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before the current symbol node in the Abstract Syntax Tree. - - - -str } - description="The source code text to insert." - defaultValue="" -/> -bool } - description="Whether to adjust the indentation of new_src to match current text. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after insertion. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to remove duplicate insertions. Defaults to True." - defaultValue="True" -/> -bool } - description="Whether to insert before extended nodes like comments and decorators. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### move_to_file -Moves the given symbol to a new file and updates its imports and references. - - - -TSFile } - description="The destination file to move the symbol to." - defaultValue="" -/> -bool } - description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." - defaultValue="True" -/> -str } - description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." - defaultValue=""update_all_imports"" -/> - - - -None } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Renames a symbol and updates all its references in the codebase. - - - -str } - description="The new name for the symbol." - defaultValue="" -/> -int } - description="Priority of the edit operation. Defaults to 0." - defaultValue="0" -/> - - - -tuple[NodeId, NodeId] } description="A tuple containing the file node ID and the new node ID of the renamed symbol."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_comment -Sets a comment to the symbol. - - - -str } - description="The comment text to be added." - defaultValue="" -/> -bool, optional } - description="Whether to automatically format the text into a comment syntax." - defaultValue="True" -/> -bool, optional } - description="Whether to clean the format of the comment before inserting." - defaultValue="True" -/> -TSCommentType , optional } - description="The style of comment to add." - defaultValue="TSCommentType.DOUBLE_SLASH" -/> - - - -None } description=""/> - - -### set_docstring -Sets or updates a docstring for a code element. - - - -str } - description="The docstring text to be added or updated." - defaultValue="" -/> -bool, optional } - description="Whether to automatically format the text into a docstring format. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to clean existing formatting from the docstring before inserting. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to add leading "*" to each line of the comment block. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to force single line comments to be multi-line. Defaults to False." - defaultValue="False" -/> - - - -None } description=""/> - - -### set_inline_comment -Sets an inline comment to the symbol. - - - -str } - description="The inline comment text to be added." - defaultValue="" -/> -bool, optional } - description="Whether to automatically format the text as a comment." - defaultValue="True" -/> -bool, optional } - description="Whether to clean the comment format before inserting." - defaultValue="True" -/> -TSNode | None, optional } - description="The specific node to attach the comment to." - defaultValue="None" -/> - - - -None } description=""/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ TSImport | TSSymbol | TSExport ] } description="A list of symbols that use or import the exportable object."/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSExport.mdx b/docs/_deprecated/api-reference/typescript/TSExport.mdx deleted file mode 100644 index 0355aa51d..000000000 --- a/docs/_deprecated/api-reference/typescript/TSExport.mdx +++ /dev/null @@ -1,728 +0,0 @@ ---- -title: "TSExport" -sidebarTitle: "TSExport" -icon: "" -description: "Represents a single exported symbol. There is a 1:M relationship between an ExportStatement and an Export" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[HasValue](/api-reference/core/HasValue), [Export](/api-reference/core/Export), [Editable](/api-reference/core/Editable), [Exportable](/api-reference/core/Exportable), [Usable](/api-reference/core/Usable), [Importable](/api-reference/core/Importable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName) - -## Attributes - -### declared_symbol - -TSSymbol | TSImport | None } description="Returns the symbol that was defined in this export." /> - -### descendant_symbols - -list[ Importable ] } description="Returns a list of all descendant symbols from this export's declared symbol." /> - -### export - -TSExport | None } description="Returns the export object that exports this symbol." /> - -### export_statement - -ExportStatement } description="The statement representing the export." /> - -### exported_name - -str | None } description="Retrieves the exported name of a symbol from its file." /> - -### exported_symbol - -Exportable | None } description="Returns the symbol, file, or import being exported from this export object." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### is_exported - -bool } description="Indicates if the symbol is exported from its defining file." /> - -### is_external_export - -bool } description="Determines if this export is exporting a symbol from an external (non-relative) module." /> - -### is_reexported - -bool } description="Determines if the symbol is re-exported from a different file." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_symbol - -Exportable | None } description="Returns the Symbol, SourceFile or External module that this export resolves to." /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Returns the source code of the symbol." /> - -### value - -Expression | None } description="Gets the value node of the object." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ TSSymbol , TSImport ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSExport ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSExport ] } description=""/> - - -### get_import_string -Returns the import string for this export. - - - -str | None } - description="Optional alias to use when importing the symbol." - defaultValue="None" -/> -str | None } - description="Optional module name to import from." - defaultValue="None" -/> -ImportType } - description="The type of import to generate." - defaultValue="ImportType.UNKNOWN" -/> -bool } - description="Whether this is a type-only import." - defaultValue="False" -/> - - - -str } description="The formatted import string."/> - - -### get_name -Returns the name node of the object. - - - -Name | TSChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSExport ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_aliased -Determines if the Export object is aliased. - - - -bool } description="True if the exported symbol has a different name than the name it is exported as, False otherwise."/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_default_export -Determines if an export is the default export for a file. - - - -bool } description="True if this is a default export, False otherwise."/> - - -### is_default_symbol_export -Returns True if this is exporting a default symbol, as opposed to a default object export. - - - -TSExport } - description="The export object being checked." - defaultValue="" -/> - - - -bool } description="True if this is a default symbol export, False otherwise."/> - - -### is_module_export -Determines if the export is exporting a module rather than a symbol. - - - -bool } description="True if the export represents a module export, False otherwise."/> - - -### is_named_export -Determines whether this export is a named export. - - - -bool } description="True if this is a named export, False if it is a default export."/> - - -### is_reexport -Returns whether the export is re-exporting an import or export. - - - -TSExport } - description="The export node being checked." - defaultValue="" -/> - - - -bool } description="True if this export re-exports an imported/exported symbol or entire module, False otherwise."/> - - -### is_type_export -Determines if this export is exclusively exporting a type. - - - -bool } description="True if this is a type-only export, False otherwise."/> - - -### is_wildcard_export -Determines if the export is a wildcard export. - - - -bool } description="True if the export is a wildcard export (e.g. 'export * from "./module"'), False otherwise."/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### make_non_default -Converts the export to a named export. - - - -None } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### reexport_symbol -Returns the import object that is re-exporting this symbol. - - - -TSImport | None } description="The import object being re-exported, or None if this is not a re-export or no import was found."/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Renames a symbol and updates all its references in the codebase. - - - -str } - description="The new name for the symbol." - defaultValue="" -/> -int } - description="Priority of the edit operation. Defaults to 0." - defaultValue="0" -/> - - - -tuple[NodeId, NodeId] } description="A tuple containing the file node ID and the new node ID of the renamed symbol."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### set_value -Sets the value of the node's value Expression. - - - -str } - description="The new value to set." - defaultValue="" -/> - - - -None } description=""/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ TSImport | TSSymbol | TSExport ] } description="A list of symbols that use or import the exportable object."/> - - -### to_import_string -Converts this export into its equivalent import string representation. - - - -str } description="The import string representation of this export. Examples: - For `export { foo } from './bar'` -> `import { foo } from './bar'` - For `export * from './bar'` -> `import * as _namespace from './bar'` - For `export { default as foo } from './bar'` -> `import foo from './bar'`"/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSExpressionType.mdx b/docs/_deprecated/api-reference/typescript/TSExpressionType.mdx deleted file mode 100644 index b92ff6bb4..000000000 --- a/docs/_deprecated/api-reference/typescript/TSExpressionType.mdx +++ /dev/null @@ -1,467 +0,0 @@ ---- -title: "TSExpressionType" -sidebarTitle: "TSExpressionType" -icon: "" -description: "Type defined by evaluation of an expression" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[TSNamedType](/api-reference/typescript/TSNamedType), [NamedType](/api-reference/core/NamedType), [HasName](/api-reference/core/HasName), [Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### expression - -Expression [ TSExpressionType [ Editable ]] } description="The expression to evaluate that yields the type" /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSExpressionType ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSExpressionType ] } description=""/> - - -### get_name -Returns the name node of the object. - - - -Name | TSChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSExpressionType ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Sets the name of an object and updates all its usages. - - - -str } - description="The new name to assign to the object." - defaultValue="" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSFile.mdx b/docs/_deprecated/api-reference/typescript/TSFile.mdx deleted file mode 100644 index 9f5dda3ec..000000000 --- a/docs/_deprecated/api-reference/typescript/TSFile.mdx +++ /dev/null @@ -1,1152 +0,0 @@ ---- -title: "TSFile" -sidebarTitle: "TSFile" -icon: "" -description: "Extends the SourceFile class to provide TypeScript-specific functionality." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Exportable](/api-reference/core/Exportable), [TSHasBlock](/api-reference/typescript/TSHasBlock), [SourceFile](/api-reference/core/SourceFile), [Usable](/api-reference/core/Usable), [HasBlock](/api-reference/core/HasBlock), [File](/api-reference/core/File), [Importable](/api-reference/core/Importable), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable), [HasName](/api-reference/core/HasName) - -## Attributes - -### classes - -list[ TSClass ] } description="Returns all Classes in the file." /> - -### code_block - -TSCodeBlock } description="Represents the block of code contained in the file." /> - -### content - -str } description="Returns the content of the file as a UTF-8 encoded string." /> - -### decorators - -list[ TSDecorator ] } description="Returns a list of decorators associated with this symbol." /> - -### default_exports - -list[ TSExport ] } description="Returns all default export symbols from the file." /> - -### directory - -Directory | None } description="Returns the directory that contains this file." /> - -### docstring - -TSCommentGroup | None } description="Retrieves the docstring of a function or class." /> - -### export - -TSExport | None } description="Returns the export object that exports this symbol." /> - -### export_statements - -list[ ExportStatement [ TSExport ]] } description="Returns a list of all export statements in the file." /> - -### exported_name - -str | None } description="Retrieves the exported name of a symbol from its file." /> - -### exports - -list[ TSExport ] } description="Returns all Export symbols in the file." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### extension - -str } description="Returns the file extension." /> - -### file - -TSFile } description="A property that returns the file object for non-source files." /> - -### file_path - -str } description="The relative file path as a string." /> - -### filepath - -str } description="Retrieves the file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns all function calls within the code block and its decorators." /> - -### functions - -list[ TSFunction ] } description="Returns all Functions in the file." /> - -### global_vars - -list[ TSAssignment ] } description="Returns all GlobalVars in the file." /> - -### import_module_name - -str } description="Returns the module name that this file gets imported as." /> - -### import_statements - -list[ TSImportStatement ] } description="Returns all ImportStatements in the file, where each import statement can contain" /> - -### importers - -list[ TSImport ] } description="Returns all imports that directly imports this file as a module." /> - -### imports - -list[ TSImport ] } description="List of all Imports in this file." /> - -### inbound_imports - -list[ TSImport ] } description="Returns all imports that are importing symbols contained in this file." /> - -### interfaces - -list[ TSInterface ] } description="Returns all Interfaces in the file." /> - -### is_binary - -bool } description="Indicates whether the file contains binary data." /> - -### is_decorated - -bool } description="Checks if the current symbol has a decorator." /> - -### is_exported - -bool } description="Indicates if the symbol is exported from its defining file." /> - -### is_reexported - -bool } description="Determines if the symbol is re-exported from a different file." /> - -### jsx_elements - -list[ JSXElement [ TSFile ]] } description="Returns a list of all JSX elements contained within this symbol." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### named_exports - -list[ TSExport ] } description="Returns the named exports declared in the file." /> - -### owners - -set[str] } description="Returns the CODEOWNERS of the file." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### path - -Path } description="The absolute path of the file as a Path object." /> - -### programming_language - - } description="The programming language of the file. Set to ProgrammingLanguage.TYPESCRIPT." /> - -### promise_chains - -list[TSPromiseChain] } description="Returns all promise chains in the file." /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### start_byte - -int } description="Returns the starting byte position of a file in its content." /> - -### symbols_sorted_topologically - -list[ TSSymbol ] } description="Returns all Symbols in the file, sorted topologically (parents first). Robust to" /> - -### ts_config - -TSConfig | None } description="The ts_config file nearest to this file." /> - -### types - -list[ TSTypeAlias ] } description="Returns all type aliases in the file." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### add_export_to_symbol -Adds an export keyword to a symbol in a TypeScript file. - - - -TSSymbol } - description="The TypeScript symbol (function, class, interface, etc.) to be exported." - defaultValue="" -/> - - - -None } description=""/> - - -### add_import -Adds an import to the file. - - - -TSSymbol | str } - description="Either a Symbol to import or a string representation of an import statement." - defaultValue="" -/> -str | None } - description="Optional alias for the imported symbol. Only used when imp is a Symbol. Defaults to None." - defaultValue="None" -/> -ImportType } - description="The type of import to use. Only used when imp is a Symbol. Defaults to ImportType.UNKNOWN." - defaultValue="ImportType.UNKNOWN" -/> -bool } - description="Whether this is a type-only import. Only used when imp is a Symbol. Defaults to False." - defaultValue="False" -/> - - - -TSImport | None } description="The existing import for the symbol if found, otherwise None."/> - - -### add_symbol -Adds `symbol` to the file. - - - -TSSymbol } - description="The symbol to add to the file." - defaultValue="" -/> -bool, optional } - description="Whether to export the symbol. Defaults to True." - defaultValue="True" -/> - - - -TSSymbol | None } description="The existing symbol if it already exists in the file or None if it was added."/> - - -### add_symbol_from_source -Adds a symbol to a file from a string representation. - - - -str } - description="String representation of the symbol to be added. This should be valid source code for" - defaultValue="" -/> - - - -None } description="The symbol is added directly to the file's content."/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ TSSymbol , TSImport ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this file with new_src. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of new_src to match the current" - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are" - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_by_byte_range -Finds all editable objects that overlap with the given byte range in the file. - - - -Range } - description="The byte range to search within the file." - defaultValue="" -/> - - - -list[ Editable ] } description="A list of all Editable objects that overlap with the given range."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSFile ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSFile ] } description=""/> - - -### get_class -Returns a specific Class by full name. Returns None if not found. - - - -str } - description="The full name of the class to search for." - defaultValue="" -/> - - - -TSClass | None } description="The matching Class object if found, None otherwise."/> - - -### get_component -Returns a specific JSX element from within this symbol's JSX elements. - - - -str } - description="The name of the JSX component to find." - defaultValue="" -/> - - - -JSXElement [ TSFile ] | None } description="The matching JSX element if found, None otherwise."/> - - -### get_config -Returns the nearest tsconfig.json applicable to this file. - - - -TSConfig | None } description="The TypeScript configuration object if found, None otherwise."/> - - -### get_export -Returns an export object with the specified name from the file. - - - -str } - description="The name of the export to find." - defaultValue="" -/> - - - -TSExport | None } description="The export object if found, None otherwise."/> - - -### get_export_statement_for_path -Gets the first export of specified type that contains the given path in single or double quotes. - - - -str } - description="The path to check for in export statements" - defaultValue="" -/> -str } - description="Type of export to get - "WILDCARD", "TYPE", or "EXPORT" (default)" - defaultValue=""EXPORT"" -/> - - - -ExportStatement | None } description="The first matching export if found, None otherwise."/> - - -### get_extensions -Returns a list of file extensions that this class can parse. - - - -list[str] } description="A list of file extensions including '.tsx', '.ts', '.jsx', and '.js'."/> - - -### get_function -Returns a specific Function by name. - - - -str } - description="The name of the function to find." - defaultValue="" -/> - - - -TSFunction | None } description="The matching Function object if found, None otherwise."/> - - -### get_global_var -Returns a specific global var by name. Returns None if not found. - - - -str } - description="The name of the global variable to find." - defaultValue="" -/> - - - -TSAssignment | None } description="The global variable if found, None otherwise."/> - - -### get_import -Returns the import with matching alias. Returns None if not found. - - - -str } - description="The alias name to search for. This can match either the direct import name or the aliased name." - defaultValue="" -/> - - - -TSImport | None } description="The import statement with the matching alias if found, None otherwise."/> - - -### get_import_string -Generates and returns an import statement for the file. - - - -str | None } - description="Alternative name for the imported module. Defaults to None." - defaultValue="None" -/> -str | None } - description="Module path to import from. If None, uses file's default module name." - defaultValue="None" -/> -ImportType } - description="The type of import statement. Defaults to ImportType.UNKNOWN." - defaultValue="ImportType.UNKNOWN" -/> -bool } - description="Whether this is a type-only import. Defaults to False." - defaultValue="False" -/> - - - -str } description="A formatted import statement string importing all exports from the module."/> - - -### get_interface -Retrieves a specific interface from the file by its name. - - - -str } - description="The name of the interface to find." - defaultValue="" -/> - - - -TSInterface | None } description="The interface with the specified name if found, None otherwise."/> - - -### get_name -Returns the name node of the object. - - - -Name | TSChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_namespace -Returns a specific namespace by name from the file's namespaces. - - - -str } - description="The name of the namespace to find." - defaultValue="" -/> - - - -TSNamespace | None } description="The namespace with the specified name if found, None otherwise."/> - - -### get_symbol -Gets a symbol by its name from the file. - - - -str } - description="The name of the symbol to find." - defaultValue="" -/> - - - -TSSymbol | None } description="The found symbol, or None if not found."/> - - -### get_type -Returns a specific Type by name from the file's types. - - - -str } - description="The name of the type alias to retrieve." - defaultValue="" -/> - - - -TSTypeAlias | None } description="The TypeScript type alias with the matching name, or None if not found."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSFile ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### has_export_statement_for_path -Checks if the file has exports of specified type that contains the given path in single or double quotes. - - - -str } - description="The path to check for in export statements" - defaultValue="" -/> -str } - description="Type of export to check for - "WILDCARD", "TYPE", or "EXPORT" (default)" - defaultValue=""EXPORT"" -/> - - - -bool } description="True if there exists an export of specified type with the exact relative path (quoted) in its source, False otherwise."/> - - -### has_import -Returns True if the file has an import with the given alias. - - - -str } - description="The alias to check for in the import statements." - defaultValue="" -/> - - - -bool } description="True if an import with the given alias exists, False otherwise."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Removes the file from the file system and graph. - - - -None } description=""/> - - -### remove_unused_exports -Removes unused exports from the file. - - - -None } description=""/> - - -### rename -Renames a symbol and updates all its references in the codebase. - - - -str } - description="The new name for the symbol." - defaultValue="" -/> -int } - description="Priority of the edit operation. Defaults to 0." - defaultValue="0" -/> - - - -tuple[NodeId, NodeId] } description="A tuple containing the file node ID and the new node ID of the renamed symbol."/> - - -### replace -Replace occurrences of text in the file. - - - -str } - description="The text to be replaced." - defaultValue="" -/> -str } - description="The text to replace with." - defaultValue="" -/> -int } - description="Maximum number of replacements to make. -1 means replace all occurrences." - defaultValue="-1" -/> -bool } - description="If True, treat 'old' as a regular expression pattern." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are" - defaultValue="0" -/> - - - -int } description="List of affected Editable objects. For non-source files, always returns an empty list since they don't have Editable sub-components."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_docstring -Sets or updates a docstring for a code element. - - - -str } - description="The docstring text to be added or updated." - defaultValue="" -/> -bool, optional } - description="Whether to automatically format the text into a docstring format. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to clean existing formatting from the docstring before inserting. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to add leading "*" to each line of the comment block. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to force single line comments to be multi-line. Defaults to False." - defaultValue="False" -/> - - - -None } description=""/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### symbol_can_be_added -Determines if a TypeScript symbol can be added to this file based on its type and JSX compatibility. - - - -TSSymbol } - description="The TypeScript symbol to be checked." - defaultValue="" -/> - - - -bool } description="True if the symbol can be added to this file, False otherwise."/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ TSImport | TSSymbol | TSExport ] } description="A list of symbols that use or import the exportable object."/> - - -### symbols -Returns all Symbols in the file, sorted by position in the file. - - - -list[ TSSymbol | TSClass | TSFunction | TSAssignment | TSInterface ] } description="A list of all top-level symbols in the file, sorted by their position in the file. Symbols can be one of the following types: - Symbol: Base symbol class - TClass: Class definition - TFunction: Function definition - TGlobalVar: Global variable assignment - TInterface: Interface definition"/> - - -### update_filepath -Updates the file path of the current file and all associated imports. - - - -str } - description="The new file path to move the file to." - defaultValue="" -/> - - - -None } description=""/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSForLoopStatement.mdx b/docs/_deprecated/api-reference/typescript/TSForLoopStatement.mdx deleted file mode 100644 index 0edc35ab7..000000000 --- a/docs/_deprecated/api-reference/typescript/TSForLoopStatement.mdx +++ /dev/null @@ -1,550 +0,0 @@ ---- -title: "TSForLoopStatement" -sidebarTitle: "TSForLoopStatement" -icon: "" -description: "Abstract representation of the for loop in TypeScript." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[TSBlockStatement](/api-reference/typescript/TSBlockStatement), [ForLoopStatement](/api-reference/core/ForLoopStatement), [TSHasBlock](/api-reference/typescript/TSHasBlock), [BlockStatement](/api-reference/core/BlockStatement), [HasBlock](/api-reference/core/HasBlock), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### code_block - -TSCodeBlock | None } description="The code block contained within the statement, if it exists." /> - -### condition - -Expression [ TSForLoopStatement ] | None } description="The condition for the loop. Applicable for traditional for loops." /> - -### decorators - -list[ TSDecorator ] } description="Returns a list of decorators associated with this symbol." /> - -### docstring - -TSCommentGroup | None } description="Retrieves the docstring of a function or class." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Retrieves all function calls within a for loop statement." /> - -### increment - -Expression [ TSForLoopStatement ] | None } description="The increment expression. Applicable for traditional for loops." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### initializer - -Expression [ TSForLoopStatement ] | None } description="The counter variable. Applicable for traditional for loops." /> - -### is_decorated - -bool } description="Checks if the current symbol has a decorator." /> - -### is_for_in_loop - -bool } description="Determines whether the current for loop is a `for...in` loop." /> - -### item - -Expression [ TSForLoopStatement ] | None } description="An item in the iterable object. Only applicable for `for...of` loops." /> - -### iterable - -Expression [ TSForLoopStatement ] | None } description="The iterable that is being iterated over. Only applicable for `for...of` loops." /> - -### jsx_elements - -list[ JSXElement [ TSForLoopStatement ]] } description="Returns a list of all JSX elements contained within this symbol." /> - -### nested_code_blocks - -list[ TSCodeBlock ] } description="Returns all nested CodeBlocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ TSForLoopStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSForLoopStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSForLoopStatement ] } description=""/> - - -### get_component -Returns a specific JSX element from within this symbol's JSX elements. - - - -str } - description="The name of the JSX component to find." - defaultValue="" -/> - - - -JSXElement [ TSForLoopStatement ] | None } description="The matching JSX element if found, None otherwise."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSForLoopStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_docstring -Sets or updates a docstring for a code element. - - - -str } - description="The docstring text to be added or updated." - defaultValue="" -/> -bool, optional } - description="Whether to automatically format the text into a docstring format. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to clean existing formatting from the docstring before inserting. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to add leading "*" to each line of the comment block. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to force single line comments to be multi-line. Defaults to False." - defaultValue="False" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSFunction.mdx b/docs/_deprecated/api-reference/typescript/TSFunction.mdx deleted file mode 100644 index 08ece27eb..000000000 --- a/docs/_deprecated/api-reference/typescript/TSFunction.mdx +++ /dev/null @@ -1,1143 +0,0 @@ ---- -title: "TSFunction" -sidebarTitle: "TSFunction" -icon: "" -description: "Representation of a Function in JavaScript/TypeScript" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[TSHasBlock](/api-reference/typescript/TSHasBlock), [TSSymbol](/api-reference/typescript/TSSymbol), [Function](/api-reference/core/Function), [HasBlock](/api-reference/core/HasBlock), [Exportable](/api-reference/core/Exportable), [Symbol](/api-reference/core/Symbol), [Callable](/api-reference/core/Callable), [Expression](/api-reference/core/Expression), [Usable](/api-reference/core/Usable), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [HasName](/api-reference/core/HasName) - -## Attributes - -### call_sites - -list[ FunctionCall ] } description="Returns all call sites (invocations) of this callable in the codebase." /> - -### code_block - -TSCodeBlock } description="The block of code associated with the code object." /> - -### comment - -TSCommentGroup | None } description="Retrieves the comment group associated with the symbol." /> - -### decorators - -list[ TSDecorator ] } description="Returns a list of decorators associated with this symbol." /> - -### docstring - -TSCommentGroup | None } description="Retrieves the docstring of a function or class." /> - -### export - -TSExport | None } description="Returns the export object that exports this symbol." /> - -### exported_name - -str | None } description="Retrieves the exported name of a symbol from its file." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_nodes - -list[ Editable ] } description="Returns the list of nodes associated with this symbol including extended nodes." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Gets all function calls within the function and its parameters." /> - -### function_signature - -str } description="Returns a string representation of the function's signature." /> - -### function_type - -TSFunctionTypeNames } description="Gets the type of function from its TreeSitter node." /> - -### has_semicolon - -bool } description="Checks whether the current symbol has a semicolon at the end." /> - -### inferred_return_type - -str | None } description="Gets the inferred type of the function from the language's native language engine / compiler." /> - -### inline_comment - -TSCommentGroup | None } description="Property that retrieves the inline comment group associated with the symbol." /> - -### is_anonymous - -bool } description="Property indicating whether a function is anonymous." /> - -### is_arrow - -bool } description="Returns True iff the function is an arrow function." /> - -### is_async - -bool } description="Determines if the function is asynchronous." /> - -### is_constructor - -bool } description="Determines if the current function is a constructor method." /> - -### is_decorated - -bool } description="Checks if the current symbol has a decorator." /> - -### is_exported - -bool } description="Indicates if the symbol is exported from its defining file." /> - -### is_jsx - -bool } description="Determines if the function is a React component by checking if it returns a JSX element." /> - -### is_magic - -bool } description="Returns whether this method is a magic method." /> - -### is_method - -bool } description="Returns whether the function is a method of a class." /> - -### is_overload - -bool } description="Indicates whether the function is an overloaded function in a multi-function definition." /> - -### is_private - -bool } description="Determines if a function is private based on its accessibility modifier." /> - -### is_property - -bool } description="Determines if the function is a property." /> - -### is_reexported - -bool } description="Determines if the symbol is re-exported from a different file." /> - -### jsx_elements - -list[ JSXElement [ TSFunction ]] } description="Returns a list of all JSX elements contained within this symbol." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### nested_functions - -list[ TSFunction ] } description="Returns a list of nested functions defined within this function's code block." /> - -### parameters - -SymbolGroup [ TSParameter , TSFunction ] | list[ TSParameter ] } description="Retrieves all parameters of a callable symbol." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### promise_chains - -list[TSPromiseChain] } description="Returns a list of promise chains in the function." /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### return_statements - -list[ ReturnStatement ] } description="Returns a list of all return statements within this function's body." /> - -### return_type - -Type | Placeholder [ TSFunction ] } description="The type of value returned by the callable, or a placeholder." /> - -### semicolon_node - -Editable | None } description="Retrieves the semicolon node associated with a TypeScript symbol." /> - -### source - -str } description="Returns the source code of the symbol." /> - -### symbol_type - - } description="The type of symbol, set to SymbolType.Function." /> - -### type_parameters - -TypeParameters[ Type , TSFunction ] | None } description="The type parameters of the symbol, if any." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_comment -Adds a new comment to the symbol. - - - -str } - description="The comment text to be added." - defaultValue="" -/> -bool } - description="Whether to automatically format the text into a comment style. Defaults to True." - defaultValue="True" -/> -bool } - description="Whether to clean the format of the comment before inserting. Defaults to True." - defaultValue="True" -/> -TSCommentType } - description="Type of comment to add. Defaults to TSCommentType.DOUBLE_SLASH." - defaultValue="TSCommentType.DOUBLE_SLASH" -/> - - - -None } description=""/> - - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### add_keyword -Insert a keyword in the appropriate place before this symbol if it doesn't already exist. - - - -str } - description="The keyword to be inserted. Must be a valid keyword in the language context." - defaultValue="" -/> - - - -None } description=""/> - - -### add_statements -Adds statements to the end of a function body. - - - -str } - description="The lines of code to be added at the end of the function body." - defaultValue="" -/> - - - -None } description=""/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### arrow_to_named -Converts an arrow function to a named function in TypeScript/JavaScript. - - - -str | None } - description="The name for the converted function. If None, uses the name of the variable" - defaultValue="None" -/> - - - -None } description=""/> - - -### asyncify -Modifies the function to be asynchronous, if it is not already. - - - -None } description=""/> - - -### convert_props_to_interface -Converts React component props to TypeScript interfaces. - - - -None } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ TSSymbol , TSImport ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this node with new_src. - - - -str } - description="The new source code to replace the current source with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, prevents duplicate edits. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSFunction ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Flags a TypeScript symbol by adding a flag comment and returning a CodeFlag. - - - -CodeFlag[ TSFunction ] } description="The code flag object for tracking purposes"/> - - -### get_component -Returns a specific JSX element from within this symbol's JSX elements. - - - -str } - description="The name of the JSX component to find." - defaultValue="" -/> - - - -JSXElement [ TSFunction ] | None } description="The matching JSX element if found, None otherwise."/> - - -### get_import_string -Generates the appropriate import string for a symbol. - - - -str | None, optional } - description="The alias to use for the imported symbol. Defaults to None." - defaultValue="None" -/> -str | None, optional } - description="The module to import from. If None, uses the file's import module name." - defaultValue="None" -/> -ImportType , optional } - description="The type of import to generate (e.g., WILDCARD). Defaults to" - defaultValue="ImportType.UNKNOWN" -/> -bool, optional } - description="Whether this is a type-only import. Defaults to False." - defaultValue="False" -/> - - - -str } description="A formatted import statement string."/> - - -### get_name -Returns the name node of the object. - - - -Name | TSChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_parameter -Gets a specific parameter from the callable's parameters list by name. - - - -str } - description="The name of the parameter to retrieve." - defaultValue="" -/> - - - -TSParameter | None } description="The parameter with the specified name, or None if no parameter with that name exists or if there are no parameters."/> - - -### get_parameter_by_index -Returns the parameter at the given index. - - - -int } - description="The index of the parameter to retrieve." - defaultValue="" -/> - - - -TSParameter | None } description="The parameter at the specified index, or None if the parameter list is empty or the index does not exist."/> - - -### get_parameter_by_type -Retrieves a parameter from the callable by its type. - - - -TSSymbol } - description="The type to search for." - defaultValue="" -/> - - - -TSParameter | None } description="The parameter with the specified type, or None if no parameter is found or if the callable has no parameters."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSFunction ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before the current symbol node in the Abstract Syntax Tree. - - - -str } - description="The source code text to insert." - defaultValue="" -/> -bool } - description="Whether to adjust the indentation of new_src to match current text. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after insertion. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to remove duplicate insertions. Defaults to True." - defaultValue="True" -/> -bool } - description="Whether to insert before extended nodes like comments and decorators. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_statements -Inserts lines of code into the function body at the specified index. - - - -str } - description="The code lines to insert into the function body." - defaultValue="" -/> -int, optional } - description="The position in the function body where the lines should be inserted. Defaults to 0." - defaultValue="0" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_valid_node -Determines if a given tree-sitter node corresponds to a valid function type. - - - -TSNode } - description="The tree-sitter node to validate." - defaultValue="" -/> - - - -bool } description="True if the node's type is a valid function type, False otherwise."/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### move_to_file -Moves the given symbol to a new file and updates its imports and references. - - - -TSFile } - description="The destination file to move the symbol to." - defaultValue="" -/> -bool } - description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." - defaultValue="True" -/> -str } - description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." - defaultValue=""update_all_imports"" -/> - - - -None } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### prepend_statements -Prepends the provided code to the beginning of the function body. - - - -str } - description="The code to be prepended to the function body." - defaultValue="" -/> - - - -None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Renames a symbol and updates all its references in the codebase. - - - -str } - description="The new name for the symbol." - defaultValue="" -/> -int } - description="Priority of the edit operation. Defaults to 0." - defaultValue="0" -/> - - - -tuple[NodeId, NodeId] } description="A tuple containing the file node ID and the new node ID of the renamed symbol."/> - - -### rename_local_variable -Renames a local variable and all its usages within a function body. - - - -str } - description="The current name of the local variable to be renamed." - defaultValue="" -/> -str } - description="The new name to give to the local variable." - defaultValue="" -/> -bool, optional } - description="If True, matches variable names that contain old_var_name. Defaults to False." - defaultValue="False" -/> - - - -None } description="The method modifies the AST in place."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_comment -Sets a comment to the symbol. - - - -str } - description="The comment text to be added." - defaultValue="" -/> -bool, optional } - description="Whether to automatically format the text into a comment syntax." - defaultValue="True" -/> -bool, optional } - description="Whether to clean the format of the comment before inserting." - defaultValue="True" -/> -TSCommentType , optional } - description="The style of comment to add." - defaultValue="TSCommentType.DOUBLE_SLASH" -/> - - - -None } description=""/> - - -### set_docstring -Sets or updates a docstring for a code element. - - - -str } - description="The docstring text to be added or updated." - defaultValue="" -/> -bool, optional } - description="Whether to automatically format the text into a docstring format. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to clean existing formatting from the docstring before inserting. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to add leading "*" to each line of the comment block. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to force single line comments to be multi-line. Defaults to False." - defaultValue="False" -/> - - - -None } description=""/> - - -### set_inline_comment -Sets an inline comment to the symbol. - - - -str } - description="The inline comment text to be added." - defaultValue="" -/> -bool, optional } - description="Whether to automatically format the text as a comment." - defaultValue="True" -/> -bool, optional } - description="Whether to clean the comment format before inserting." - defaultValue="True" -/> -TSNode | None, optional } - description="The specific node to attach the comment to." - defaultValue="None" -/> - - - -None } description=""/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### set_return_type -Sets the return type annotation for the function. - - - -str } - description="The new return type annotation to be set. Use an empty string to remove" - defaultValue="" -/> - - - -None } description=""/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ TSImport | TSSymbol | TSExport ] } description="A list of symbols that use or import the exportable object."/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSFunctionType.mdx b/docs/_deprecated/api-reference/typescript/TSFunctionType.mdx deleted file mode 100644 index c5ab49d67..000000000 --- a/docs/_deprecated/api-reference/typescript/TSFunctionType.mdx +++ /dev/null @@ -1,433 +0,0 @@ ---- -title: "TSFunctionType" -sidebarTitle: "TSFunctionType" -icon: "" -description: "Function type definition. Example: a: (a: number) => number" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### name - -None } description="This lets parameters generate their node_id properly." /> - -### parameters - -Collection[ TSParameter , TSFunctionType ] } description="Retrieves the parameters of a function type." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### return_type - -TSType[ TSFunctionType ] | TSReturnTypePlaceholder [ TSFunctionType ] } description="Return type of the function." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### asyncify -Modifies the function type to be asynchronous by wrapping its return type in a Promise. - - - -None } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSFunctionType ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSFunctionType ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSFunctionType ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSGenericType.mdx b/docs/_deprecated/api-reference/typescript/TSGenericType.mdx deleted file mode 100644 index 4d0359730..000000000 --- a/docs/_deprecated/api-reference/typescript/TSGenericType.mdx +++ /dev/null @@ -1,467 +0,0 @@ ---- -title: "TSGenericType" -sidebarTitle: "TSGenericType" -icon: "" -description: "Generic type Examples: `Array`" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[GenericType](/api-reference/core/GenericType), [NamedType](/api-reference/core/NamedType), [HasName](/api-reference/core/HasName), [Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parameters - -Collection[ Type , TSGenericType ] } description="Retrieves the generic type parameters associated with this type." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSGenericType ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSGenericType ] } description=""/> - - -### get_name -Returns the name node of the object. - - - -Name | TSChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSGenericType ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Sets the name of an object and updates all its usages. - - - -str } - description="The new name to assign to the object." - defaultValue="" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSHasBlock.mdx b/docs/_deprecated/api-reference/typescript/TSHasBlock.mdx deleted file mode 100644 index 9bc9e165c..000000000 --- a/docs/_deprecated/api-reference/typescript/TSHasBlock.mdx +++ /dev/null @@ -1,514 +0,0 @@ ---- -title: "TSHasBlock" -sidebarTitle: "TSHasBlock" -icon: "" -description: "A TypeScript base class that provides block-level code organization and decorator handling capabilities. This class extends the concept of block scoping for TypeScript code elements like classes and functions. It provides functionality for managing code blocks, decorators, JSX elements, and documentation within those blocks. The class supports operations such as retrieving and manipulating docstrings, handling JSX components, and managing TypeScript decorators." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[HasBlock](/api-reference/core/HasBlock), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### code_block - -TSCodeBlock } description="The block of code associated with the code object." /> - -### decorators - -list[ TSDecorator ] } description="Returns a list of decorators associated with this symbol." /> - -### docstring - -TSCommentGroup | None } description="Retrieves the docstring of a function or class." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns all function calls within the code block and its decorators." /> - -### is_decorated - -bool } description="Checks if the current symbol has a decorator." /> - -### jsx_elements - -list[ JSXElement [ TSHasBlock ]] } description="Returns a list of all JSX elements contained within this symbol." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSHasBlock ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSHasBlock ] } description=""/> - - -### get_component -Returns a specific JSX element from within this symbol's JSX elements. - - - -str } - description="The name of the JSX component to find." - defaultValue="" -/> - - - -JSXElement [ TSHasBlock ] | None } description="The matching JSX element if found, None otherwise."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSHasBlock ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_docstring -Sets or updates a docstring for a code element. - - - -str } - description="The docstring text to be added or updated." - defaultValue="" -/> -bool, optional } - description="Whether to automatically format the text into a docstring format. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to clean existing formatting from the docstring before inserting. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to add leading "*" to each line of the comment block. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to force single line comments to be multi-line. Defaults to False." - defaultValue="False" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSIfBlockStatement.mdx b/docs/_deprecated/api-reference/typescript/TSIfBlockStatement.mdx deleted file mode 100644 index 3f420ece5..000000000 --- a/docs/_deprecated/api-reference/typescript/TSIfBlockStatement.mdx +++ /dev/null @@ -1,470 +0,0 @@ ---- -title: "TSIfBlockStatement" -sidebarTitle: "TSIfBlockStatement" -icon: "" -description: "Typescript implementation of the if/elif/else statement block. For example, if there is a code block like: if (condition1) { block1 } else if (condition2) { block2 } else { block3 } This class represents the entire block, including the conditions and nested code blocks." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[IfBlockStatement](/api-reference/core/IfBlockStatement), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### alternative_blocks - -list[ TSIfBlockStatement ] } description="Returns a list of alternative if/elif/else blocks for the current block." /> - -### condition - -Expression [ TSIfBlockStatement ] | None } description="The condition expression for the if block. None if the block is an else block." /> - -### consequence_block - -TSCodeBlock } description="The code block that is executed if the condition is True." /> - -### else_statement - -TSIfBlockStatement | None } description="Returns the else block within the if-statement." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns all function calls within the if block statement and its alternative blocks." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### is_elif_statement - -bool } description="Determines if the current block is an elif block." /> - -### is_else_statement - -bool } description="Determines if the current block is an else block." /> - -### is_if_statement - -bool } description="Determines if the current block is a standalone 'if' statement." /> - -### nested_code_blocks - -list[ TSCodeBlock ] } description="Returns all nested code blocks within an if/elif/else statement block." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ TSIfBlockStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### elif_statements -Returns all elif blocks within the if block. - - - -list[ TSIfBlockStatement ] } description="A list of elif block statements. Empty list if no elif blocks exist."/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSIfBlockStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSIfBlockStatement ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSIfBlockStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Simplifies a conditional block by reducing its condition to a boolean value. - - - -bool } - description="The boolean value to reduce the condition to." - defaultValue="" -/> - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSImport.mdx b/docs/_deprecated/api-reference/typescript/TSImport.mdx deleted file mode 100644 index 4f7d1a9e0..000000000 --- a/docs/_deprecated/api-reference/typescript/TSImport.mdx +++ /dev/null @@ -1,766 +0,0 @@ ---- -title: "TSImport" -sidebarTitle: "TSImport" -icon: "" -description: "Extends Import for TypeScript codebases." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Exportable](/api-reference/core/Exportable), [Import](/api-reference/core/Import), [Usable](/api-reference/core/Usable), [Importable](/api-reference/core/Importable), [Editable](/api-reference/core/Editable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName) - -## Attributes - -### alias - -Editable | None } description="The alias of the imported symbol, if one exists." /> - -### export - -TSExport | None } description="Returns the export object that exports this symbol." /> - -### exported_name - -str | None } description="Retrieves the exported name of a symbol from its file." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### from_file - -TSFile | None } description="Returns the SourceFile that an Import is importing from." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### import_specifier - -Editable } description="Retrieves the import specifier node for this import." /> - -### import_statement - -TSImportStatement } description="The statement that this import is part of." /> - -### import_type - -ImportType } description="The type of import, indicating how the symbol is imported." /> - -### imported_exports - -list[ Exportable ] } description="Returns the enumerated list of exports imported from a module import." /> - -### imported_symbol - -TSSymbol | ExternalModule | TSFile | TSImport | None } description="Returns the symbol directly being imported, including an indirect import and an External" /> - -### is_dynamic - -bool } description="Determines if this import is dynamically loaded based on its parent symbol." /> - -### is_exported - -bool } description="Indicates if the symbol is exported from its defining file." /> - -### is_namespace_import - -bool } description="Returns True if this import is importing a namespace." /> - -### is_reexported - -bool } description="Determines if the symbol is re-exported from a different file." /> - -### module - -Editable | None } description="The module from which the symbol is being imported, if applicable." /> - -### name - -str | None } description="Returns the name or alias of the symbol being imported." /> - -### namespace - -str | None } description="If import is a module import, returns any namespace prefix that must be used with import reference." /> - -### namespace_imports - -list[ TSNamespace ] } description="Returns any namespace objects imported by this import statement." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_symbol - -TSSymbol | ExternalModule | TSFile | None } description="Returns the resolved symbol that the import is referencing." /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### symbol_name - -Editable | None } description="The name of the symbol being imported. For instance import a as b has a symbol_name of a." /> - -### to_file - -TSFile } description="SourceFile that this import resides in." /> - -### to_file_id - -NodeId } description="The node ID of the file to which this import belongs." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ TSSymbol , TSImport ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSImport ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSImport ] } description=""/> - - -### get_import_string -Generates an import string for an import statement. - - - -str | None } - description="Alias name for the imported symbol. Defaults to None." - defaultValue="None" -/> -str | None } - description="Module name to import from. Defaults to None. If not provided, uses the file's import module name." - defaultValue="None" -/> -ImportType } - description="Type of import (e.g. WILDCARD, NAMED_EXPORT). Defaults to ImportType.UNKNOWN." - defaultValue="ImportType.UNKNOWN" -/> -bool } - description="Whether this is a type import. Defaults to False." - defaultValue="False" -/> - - - -str } description="A string representation of the import statement."/> - - -### get_name -Returns the name node of the object. - - - -Name | TSChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSImport ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_aliased_import -Returns True if this import is aliased. - - - -bool } description="True if the import has an alias different from its original name, False otherwise."/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_default_import -Determines whether the import is a default export import. - - - -TSImport } - description="The import instance." - defaultValue="" -/> - - - -bool } description="True if the import is a default export import, False otherwise."/> - - -### is_module_import -Determines if an import represents a module-level import. - - - -TSImport } - description="The import object to check." - defaultValue="" -/> - - - -bool } description="True if the import is a module-level import, False otherwise. Returns True for: - Imports of type MODULE, WILDCARD, or DEFAULT_EXPORT - Side effect imports that are not type imports"/> - - -### is_reexport -Returns true if the Import object is also an Export object. - - - -bool } description="True if the import is re-exported, False otherwise."/> - - -### is_symbol_import -Returns True if this import is importing a symbol rather than a module. - - - -bool } description="True if this import is a symbol import, False if it is a module import."/> - - -### is_type_import -Checks if an import is a type import. - - - -bool } description="True if the import is a type import, False otherwise."/> - - -### is_wildcard_import -Returns True if the import symbol is a wildcard import. - - - -bool } description="True if this is a wildcard import, False otherwise."/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Remove this import from the import statement. - - - -bool, optional } - description="Whether to delete any associated formatting. Defaults to True." - defaultValue="True" -/> -int, optional } - description="The priority of the operation. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate imports. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Renames the import symbol and updates all its usages throughout the codebase. - - - -str } - description="The new name to give the imported symbol." - defaultValue="" -/> -int, optional } - description="Priority of the rename operation. Defaults to 0." - defaultValue="0" -/> - - - -tuple[NodeId, NodeId] } description="A tuple containing (file_node_id, new_import_node_id)."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### resolve_import -Resolves an import statement to its target file and symbol. - - - -str | None } - description="The base path to resolve imports from. If None, uses the codebase's base path" - defaultValue="None" -/> - - - -ImportResolution[ TSFile ] | None } description="An ImportResolution object containing the resolved file and symbol, or None if the import could not be resolved (treated as an external module). The ImportResolution contains: - from_file: The file being imported from - symbol: The specific symbol being imported (None for module imports) - imports_file: True if importing the entire file/module"/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_import_module -Sets the module of an import. - - - -str } - description="The new module path to import from." - defaultValue="" -/> - - - -None } description=""/> - - -### set_import_symbol_alias -Sets alias or name of an import at the declaration level. - - - -str } - description="The new name to use for the imported symbol." - defaultValue="" -/> - - - -None } description=""/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ TSImport | TSSymbol | TSExport ] } description="A list of symbols that use or import the exportable object."/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSImportStatement.mdx b/docs/_deprecated/api-reference/typescript/TSImportStatement.mdx deleted file mode 100644 index 03497e463..000000000 --- a/docs/_deprecated/api-reference/typescript/TSImportStatement.mdx +++ /dev/null @@ -1,429 +0,0 @@ ---- -title: "TSImportStatement" -sidebarTitle: "TSImportStatement" -icon: "" -description: "A class representing an import statement in TypeScript, managing both static and dynamic imports. This class handles various types of TypeScript imports including regular import statements, dynamic imports, and export statements. It provides functionality to manage and track imports within a TypeScript file, enabling operations like analyzing dependencies, moving imports, and modifying import statements." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[ImportStatement](/api-reference/core/ImportStatement), [Statement](/api-reference/core/Statement), [Editable](/api-reference/core/Editable), [Expression](/api-reference/core/Expression) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### imports - -Collection[ TSImport , TSImportStatement ] } description="A collection of the individual imports this statement represents" /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### nested_code_blocks - -list[ Editable ] } description="Returns all nested code blocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ TSImportStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSImportStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSImportStatement ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSImportStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSInterface.mdx b/docs/_deprecated/api-reference/typescript/TSInterface.mdx deleted file mode 100644 index ef51fca95..000000000 --- a/docs/_deprecated/api-reference/typescript/TSInterface.mdx +++ /dev/null @@ -1,895 +0,0 @@ ---- -title: "TSInterface" -sidebarTitle: "TSInterface" -icon: "" -description: "Representation of an Interface in TypeScript" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[TSHasBlock](/api-reference/typescript/TSHasBlock), [Interface](/api-reference/core/Interface), [TSSymbol](/api-reference/typescript/TSSymbol), [HasBlock](/api-reference/core/HasBlock), [Exportable](/api-reference/core/Exportable), [Symbol](/api-reference/core/Symbol), [Expression](/api-reference/core/Expression), [Usable](/api-reference/core/Usable), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [HasName](/api-reference/core/HasName) - -## Attributes - -### attributes - -list[ TSAttribute ] } description="Retrieves the list of attributes defined in the TypeScript interface." /> - -### code_block - -TSCodeBlock } description="The block of code associated with the code object." /> - -### comment - -TSCommentGroup | None } description="Retrieves the comment group associated with the symbol." /> - -### decorators - -list[ TSDecorator ] } description="Returns a list of decorators associated with this symbol." /> - -### docstring - -TSCommentGroup | None } description="Retrieves the docstring of a function or class." /> - -### export - -TSExport | None } description="Returns the export object that exports this symbol." /> - -### exported_name - -str | None } description="Retrieves the exported name of a symbol from its file." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_nodes - -list[ Editable ] } description="Returns the list of nodes associated with this symbol including extended nodes." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns all function calls within the code block and its decorators." /> - -### has_semicolon - -bool } description="Checks whether the current symbol has a semicolon at the end." /> - -### inline_comment - -TSCommentGroup | None } description="Property that retrieves the inline comment group associated with the symbol." /> - -### is_decorated - -bool } description="Checks if the current symbol has a decorator." /> - -### is_exported - -bool } description="Indicates if the symbol is exported from its defining file." /> - -### is_reexported - -bool } description="Determines if the symbol is re-exported from a different file." /> - -### jsx_elements - -list[ JSXElement [ TSInterface ]] } description="Returns a list of all JSX elements contained within this symbol." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_interfaces - -Parents[ Type , TSInterface ] | None } description="All the interfaces that this interface extends." /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### semicolon_node - -Editable | None } description="Retrieves the semicolon node associated with a TypeScript symbol." /> - -### source - -str } description="Returns the source code of the symbol." /> - -### symbol_type - - } description="The type of the symbol." /> - -### type_parameters - -TypeParameters[ Type , TSInterface ] | None } description="The type parameters of the symbol, if any." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_comment -Adds a new comment to the symbol. - - - -str } - description="The comment text to be added." - defaultValue="" -/> -bool } - description="Whether to automatically format the text into a comment style. Defaults to True." - defaultValue="True" -/> -bool } - description="Whether to clean the format of the comment before inserting. Defaults to True." - defaultValue="True" -/> -TSCommentType } - description="Type of comment to add. Defaults to TSCommentType.DOUBLE_SLASH." - defaultValue="TSCommentType.DOUBLE_SLASH" -/> - - - -None } description=""/> - - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### add_keyword -Insert a keyword in the appropriate place before this symbol if it doesn't already exist. - - - -str } - description="The keyword to be inserted. Must be a valid keyword in the language context." - defaultValue="" -/> - - - -None } description=""/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ TSSymbol , TSImport ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this node with new_src. - - - -str } - description="The new source code to replace the current source with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, prevents duplicate edits. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### extends -Returns True if the interface implements the given parent interface. - - - -bool } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSInterface ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Flags a TypeScript symbol by adding a flag comment and returning a CodeFlag. - - - -CodeFlag[ TSInterface ] } description="The code flag object for tracking purposes"/> - - -### get_attribute -Returns the attribute with the given name, if it exists. - - - -TSAttribute | None } description=""/> - - -### get_component -Returns a specific JSX element from within this symbol's JSX elements. - - - -str } - description="The name of the JSX component to find." - defaultValue="" -/> - - - -JSXElement [ TSInterface ] | None } description="The matching JSX element if found, None otherwise."/> - - -### get_import_string -Generates the appropriate import string for a symbol. - - - -str | None, optional } - description="The alias to use for the imported symbol. Defaults to None." - defaultValue="None" -/> -str | None, optional } - description="The module to import from. If None, uses the file's import module name." - defaultValue="None" -/> -ImportType , optional } - description="The type of import to generate (e.g., WILDCARD). Defaults to" - defaultValue="ImportType.UNKNOWN" -/> -bool, optional } - description="Whether this is a type-only import. Defaults to False." - defaultValue="False" -/> - - - -str } description="A formatted import statement string."/> - - -### get_name -Returns the name node of the object. - - - -Name | TSChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSInterface ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### implementations -Returns all classes and interfaces that implement a given interface. - - - -list[ TSInterface | TSClass ] } description=""/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before the current symbol node in the Abstract Syntax Tree. - - - -str } - description="The source code text to insert." - defaultValue="" -/> -bool } - description="Whether to adjust the indentation of new_src to match current text. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after insertion. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to remove duplicate insertions. Defaults to True." - defaultValue="True" -/> -bool } - description="Whether to insert before extended nodes like comments and decorators. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### move_to_file -Moves the given symbol to a new file and updates its imports and references. - - - -TSFile } - description="The destination file to move the symbol to." - defaultValue="" -/> -bool } - description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." - defaultValue="True" -/> -str } - description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." - defaultValue=""update_all_imports"" -/> - - - -None } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Renames a symbol and updates all its references in the codebase. - - - -str } - description="The new name for the symbol." - defaultValue="" -/> -int } - description="Priority of the edit operation. Defaults to 0." - defaultValue="0" -/> - - - -tuple[NodeId, NodeId] } description="A tuple containing the file node ID and the new node ID of the renamed symbol."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_comment -Sets a comment to the symbol. - - - -str } - description="The comment text to be added." - defaultValue="" -/> -bool, optional } - description="Whether to automatically format the text into a comment syntax." - defaultValue="True" -/> -bool, optional } - description="Whether to clean the format of the comment before inserting." - defaultValue="True" -/> -TSCommentType , optional } - description="The style of comment to add." - defaultValue="TSCommentType.DOUBLE_SLASH" -/> - - - -None } description=""/> - - -### set_docstring -Sets or updates a docstring for a code element. - - - -str } - description="The docstring text to be added or updated." - defaultValue="" -/> -bool, optional } - description="Whether to automatically format the text into a docstring format. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to clean existing formatting from the docstring before inserting. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to add leading "*" to each line of the comment block. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to force single line comments to be multi-line. Defaults to False." - defaultValue="False" -/> - - - -None } description=""/> - - -### set_inline_comment -Sets an inline comment to the symbol. - - - -str } - description="The inline comment text to be added." - defaultValue="" -/> -bool, optional } - description="Whether to automatically format the text as a comment." - defaultValue="True" -/> -bool, optional } - description="Whether to clean the comment format before inserting." - defaultValue="True" -/> -TSNode | None, optional } - description="The specific node to attach the comment to." - defaultValue="None" -/> - - - -None } description=""/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ TSImport | TSSymbol | TSExport ] } description="A list of symbols that use or import the exportable object."/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSLabeledStatement.mdx b/docs/_deprecated/api-reference/typescript/TSLabeledStatement.mdx deleted file mode 100644 index 34f3db715..000000000 --- a/docs/_deprecated/api-reference/typescript/TSLabeledStatement.mdx +++ /dev/null @@ -1,483 +0,0 @@ ---- -title: "TSLabeledStatement" -sidebarTitle: "TSLabeledStatement" -icon: "" -description: "Statement with a named label. It resolves to various types of statements like loops, switch cases, etc. Examples: ``` outerLoop: for (let i = 0; i < 5; i++) { innerLoop: for (let j = 0; j < 5; j++) { if (i === 2 && j === 2) { break outerLoop; // This will break out of the outer loop } console.log(`i: ${i}, j: ${j}`); } } ``` ``` emptyStatement: { pass } ```" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[HasName](/api-reference/core/HasName), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### body - -Expression | None } description="The body of the labeled statement, which can be an Expression or None." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### label - -str } description="Returns the label of the labeled statement." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### nested_code_blocks - -list[ Editable ] } description="Returns all nested code blocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ TSLabeledStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSLabeledStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSLabeledStatement ] } description=""/> - - -### get_name -Returns the name node of the object. - - - -Name | TSChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSLabeledStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Sets the name of an object and updates all its usages. - - - -str } - description="The new name to assign to the object." - defaultValue="" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSLookupType.mdx b/docs/_deprecated/api-reference/typescript/TSLookupType.mdx deleted file mode 100644 index 092efe210..000000000 --- a/docs/_deprecated/api-reference/typescript/TSLookupType.mdx +++ /dev/null @@ -1,425 +0,0 @@ ---- -title: "TSLookupType" -sidebarTitle: "TSLookupType" -icon: "" -description: "Type lookup Examples: a[\"key\"]" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### lookup - -Expression } description="The expression used for the lookup operation." /> - -### name - -str | None } description="Retrieves the name of the type object." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### type - -TSType[ TSLookupType ] } description="The type of the TypeScript object being looked up." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSLookupType ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSLookupType ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSLookupType ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSNamedType.mdx b/docs/_deprecated/api-reference/typescript/TSNamedType.mdx deleted file mode 100644 index 20dfa55dc..000000000 --- a/docs/_deprecated/api-reference/typescript/TSNamedType.mdx +++ /dev/null @@ -1,463 +0,0 @@ ---- -title: "TSNamedType" -sidebarTitle: "TSNamedType" -icon: "" -description: "Named type Examples: string" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[NamedType](/api-reference/core/NamedType), [HasName](/api-reference/core/HasName), [Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSNamedType ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSNamedType ] } description=""/> - - -### get_name -Returns the name node of the object. - - - -Name | TSChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSNamedType ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Sets the name of an object and updates all its usages. - - - -str } - description="The new name to assign to the object." - defaultValue="" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSNamespace.mdx b/docs/_deprecated/api-reference/typescript/TSNamespace.mdx deleted file mode 100644 index a7e193b8b..000000000 --- a/docs/_deprecated/api-reference/typescript/TSNamespace.mdx +++ /dev/null @@ -1,990 +0,0 @@ ---- -title: "TSNamespace" -sidebarTitle: "TSNamespace" -icon: "" -description: "Representation of a namespace module in TypeScript." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[HasName](/api-reference/core/HasName), [TSHasBlock](/api-reference/typescript/TSHasBlock), [TSSymbol](/api-reference/typescript/TSSymbol), [HasBlock](/api-reference/core/HasBlock), [Exportable](/api-reference/core/Exportable), [Symbol](/api-reference/core/Symbol), [Expression](/api-reference/core/Expression), [Usable](/api-reference/core/Usable), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable) - -## Attributes - -### classes - -list[ TSClass ] } description="Get all classes defined in this namespace." /> - -### code_block - -TSCodeBlock } description="The code block associated with this namespace." /> - -### comment - -TSCommentGroup | None } description="Retrieves the comment group associated with the symbol." /> - -### decorators - -list[ TSDecorator ] } description="Returns a list of decorators associated with this symbol." /> - -### docstring - -TSCommentGroup | None } description="Retrieves the docstring of a function or class." /> - -### export - -TSExport | None } description="Returns the export object that exports this symbol." /> - -### exported_name - -str | None } description="Retrieves the exported name of a symbol from its file." /> - -### exports - -list[ TSExport ] } description="Returns all Export symbols in the namespace." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_nodes - -list[ Editable ] } description="Returns the list of nodes associated with this symbol including extended nodes." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns all function calls within the code block and its decorators." /> - -### functions - -list[ TSFunction ] } description="Get all functions defined in this namespace." /> - -### has_semicolon - -bool } description="Checks whether the current symbol has a semicolon at the end." /> - -### inline_comment - -TSCommentGroup | None } description="Property that retrieves the inline comment group associated with the symbol." /> - -### is_decorated - -bool } description="Checks if the current symbol has a decorator." /> - -### is_exported - -bool } description="Indicates if the symbol is exported from its defining file." /> - -### is_reexported - -bool } description="Determines if the symbol is re-exported from a different file." /> - -### jsx_elements - -list[ JSXElement [ TSNamespace ]] } description="Returns a list of all JSX elements contained within this symbol." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### semicolon_node - -Editable | None } description="Retrieves the semicolon node associated with a TypeScript symbol." /> - -### source - -str } description="Returns the source code of the symbol." /> - -### symbol_type - - } description="The type of the symbol, set to SymbolType.Namespace." /> - -### symbols - -list[ TSSymbol ] } description="Returns all symbols defined within this namespace, including nested ones." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_comment -Adds a new comment to the symbol. - - - -str } - description="The comment text to be added." - defaultValue="" -/> -bool } - description="Whether to automatically format the text into a comment style. Defaults to True." - defaultValue="True" -/> -bool } - description="Whether to clean the format of the comment before inserting. Defaults to True." - defaultValue="True" -/> -TSCommentType } - description="Type of comment to add. Defaults to TSCommentType.DOUBLE_SLASH." - defaultValue="TSCommentType.DOUBLE_SLASH" -/> - - - -None } description=""/> - - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### add_keyword -Insert a keyword in the appropriate place before this symbol if it doesn't already exist. - - - -str } - description="The keyword to be inserted. Must be a valid keyword in the language context." - defaultValue="" -/> - - - -None } description=""/> - - -### add_symbol -Adds a new symbol to the namespace, optionally exporting it if applicable. If the symbol already exists in the namespace, returns the existing symbol. - - - -TSSymbol | None } description="The existing symbol if it already exists in the file or None if it was added."/> - - -### add_symbol_from_source -Adds a symbol to a namespace from a string representation. - - - -str } - description="String representation of the symbol to be added. This should be valid source code for" - defaultValue="" -/> - - - -None } description="The symbol is added directly to the namespace's content."/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ TSSymbol , TSImport ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this node with new_src. - - - -str } - description="The new source code to replace the current source with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, prevents duplicate edits. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSNamespace ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Flags a TypeScript symbol by adding a flag comment and returning a CodeFlag. - - - -CodeFlag[ TSNamespace ] } description="The code flag object for tracking purposes"/> - - -### get_class -Get a class by name from this namespace. - - - -TSClass | None } description=""/> - - -### get_component -Returns a specific JSX element from within this symbol's JSX elements. - - - -str } - description="The name of the JSX component to find." - defaultValue="" -/> - - - -JSXElement [ TSNamespace ] | None } description="The matching JSX element if found, None otherwise."/> - - -### get_enum -Get an enum by name from this namespace. - - - -TSEnum | None } description=""/> - - -### get_function -Get a function by name from this namespace. - - - -TSFunction | None } description=""/> - - -### get_import_string -Generates the appropriate import string for a symbol. - - - -str | None, optional } - description="The alias to use for the imported symbol. Defaults to None." - defaultValue="None" -/> -str | None, optional } - description="The module to import from. If None, uses the file's import module name." - defaultValue="None" -/> -ImportType , optional } - description="The type of import to generate (e.g., WILDCARD). Defaults to" - defaultValue="ImportType.UNKNOWN" -/> -bool, optional } - description="Whether this is a type-only import. Defaults to False." - defaultValue="False" -/> - - - -str } description="A formatted import statement string."/> - - -### get_interface -Get an interface by name from this namespace. - - - -TSInterface | None } description=""/> - - -### get_name -Returns the name node of the object. - - - -Name | TSChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_namespace -Get a namespace by name from this namespace. - - - -TSNamespace | None } description="The found namespace, or None if not found"/> - - -### get_nested_namespaces -Get all nested namespaces within this namespace. - - - -list[ TSNamespace ] } description="List of all nested namespace objects"/> - - -### get_symbol -Get an exported or private symbol by name from this namespace. Returns only exported symbols by default. - - - -TSSymbol | None } description="The found symbol, or None if not found"/> - - -### get_type -Get a type alias by name from this namespace. - - - -TSTypeAlias | None } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSNamespace ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before the current symbol node in the Abstract Syntax Tree. - - - -str } - description="The source code text to insert." - defaultValue="" -/> -bool } - description="Whether to adjust the indentation of new_src to match current text. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after insertion. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to remove duplicate insertions. Defaults to True." - defaultValue="True" -/> -bool } - description="Whether to insert before extended nodes like comments and decorators. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### move_to_file -Moves the given symbol to a new file and updates its imports and references. - - - -TSFile } - description="The destination file to move the symbol to." - defaultValue="" -/> -bool } - description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." - defaultValue="True" -/> -str } - description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." - defaultValue=""update_all_imports"" -/> - - - -None } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### remove_symbol -Removes a symbol from the namespace by name. - - - -TSSymbol | None } description=""/> - - -### rename -Sets the name of an object and updates all its usages. - - - -str } - description="The new name to assign to the object." - defaultValue="" -/> - - - -None } description=""/> - - -### rename_symbol -Renames a symbol within the namespace. - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### resolve_attribute -Resolves an attribute access on the namespace. - - - -TSSymbol | None } description=""/> - - -### resolve_import -Resolves an import name to a symbol within this namespace. - - - -TSSymbol | None } description=""/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_comment -Sets a comment to the symbol. - - - -str } - description="The comment text to be added." - defaultValue="" -/> -bool, optional } - description="Whether to automatically format the text into a comment syntax." - defaultValue="True" -/> -bool, optional } - description="Whether to clean the format of the comment before inserting." - defaultValue="True" -/> -TSCommentType , optional } - description="The style of comment to add." - defaultValue="TSCommentType.DOUBLE_SLASH" -/> - - - -None } description=""/> - - -### set_docstring -Sets or updates a docstring for a code element. - - - -str } - description="The docstring text to be added or updated." - defaultValue="" -/> -bool, optional } - description="Whether to automatically format the text into a docstring format. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to clean existing formatting from the docstring before inserting. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to add leading "*" to each line of the comment block. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to force single line comments to be multi-line. Defaults to False." - defaultValue="False" -/> - - - -None } description=""/> - - -### set_inline_comment -Sets an inline comment to the symbol. - - - -str } - description="The inline comment text to be added." - defaultValue="" -/> -bool, optional } - description="Whether to automatically format the text as a comment." - defaultValue="True" -/> -bool, optional } - description="Whether to clean the comment format before inserting." - defaultValue="True" -/> -TSNode | None, optional } - description="The specific node to attach the comment to." - defaultValue="None" -/> - - - -None } description=""/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ TSImport | TSSymbol | TSExport ] } description="A list of symbols that use or import the exportable object."/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSObjectType.mdx b/docs/_deprecated/api-reference/typescript/TSObjectType.mdx deleted file mode 100644 index 1237dbee8..000000000 --- a/docs/_deprecated/api-reference/typescript/TSObjectType.mdx +++ /dev/null @@ -1,417 +0,0 @@ ---- -title: "TSObjectType" -sidebarTitle: "TSObjectType" -icon: "" -description: "A class representing a TypeScript object type with type annotations and dependencies. A specialized class extending `TSDict` and implementing `Type` for handling TypeScript object type annotations. This class handles object type definitions including nested type structures and manages their dependencies. It provides functionality for computing dependencies within the type structure and handling type relationships in TypeScript code." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Type](/api-reference/core/Type), [TSDict](/api-reference/typescript/TSDict), [Expression](/api-reference/core/Expression), [Dict](/api-reference/core/Dict), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### unpack - -Unpack [ TSObjectType ] | None } description="An optional unpacking element, if present." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSObjectType ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSObjectType ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSObjectType ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSPair.mdx b/docs/_deprecated/api-reference/typescript/TSPair.mdx deleted file mode 100644 index 8a77fec02..000000000 --- a/docs/_deprecated/api-reference/typescript/TSPair.mdx +++ /dev/null @@ -1,442 +0,0 @@ ---- -title: "TSPair" -sidebarTitle: "TSPair" -icon: "" -description: "A TypeScript pair node that represents key-value pairs in object literals. A specialized class extending `Pair` for handling TypeScript key-value pairs, particularly in object literals. It provides functionality for handling both regular key-value pairs and shorthand property identifiers, with support for reducing boolean conditions." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Pair](/api-reference/core/Pair), [HasValue](/api-reference/core/HasValue), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### key - -Expression } description="The key expression of the pair, expected to be of type TExpression." /> - -### name - -str } description="Returns the source text of the key expression in the pair." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### shorthand - -bool } description="Indicates whether this pair uses shorthand property syntax." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### value - -Expression | None } description="Gets the value node of the object." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSPair ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSPair ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSPair ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_value -Sets the value of the node's value Expression. - - - -str } - description="The new value to set." - defaultValue="" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSParameter.mdx b/docs/_deprecated/api-reference/typescript/TSParameter.mdx deleted file mode 100644 index 4fde2b618..000000000 --- a/docs/_deprecated/api-reference/typescript/TSParameter.mdx +++ /dev/null @@ -1,600 +0,0 @@ ---- -title: "TSParameter" -sidebarTitle: "TSParameter" -icon: "" -description: "A class representing a TypeScript function parameter with extensive type analysis capabilities. This class provides functionality to inspect and manipulate TypeScript function parameters, including support for destructured parameters, optional parameters, variadic parameters, default values, and type annotations." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Parameter](/api-reference/core/Parameter), [HasValue](/api-reference/core/HasValue), [Expression](/api-reference/core/Expression), [Typeable](/api-reference/core/Typeable), [Usable](/api-reference/core/Usable), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [HasName](/api-reference/core/HasName) - -## Attributes - -### default - -str | None } description="Returns the default value of a parameter." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### index - -int } description="Returns the 0-based index of this parameter within its parent function's parameter list." /> - -### is_destructured - -bool } description="Determines if a parameter is part of an object destructuring pattern." /> - -### is_optional - -bool } description="Determines if a parameter is marked as optional in TypeScript." /> - -### is_typed - -bool } description="Indicates if a node has an explicit type annotation." /> - -### is_variadic - -bool } description="Determines if a parameter is variadic (using the rest operator)." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### type - -Type | TypePlaceholder [ TSParameter ] } description="The type annotation associated with this node" /> - -### value - -Expression | None } description="Gets the value node of the object." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### convert_to_interface -Converts a parameter's inline type definition to an interface. - - - -None } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ TSSymbol , TSImport ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSParameter ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSParameter ] } description=""/> - - -### get_name -Returns the name node of the object. - - - -Name | TSChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSParameter ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Removes the parameter from the function definition and all its call sites. - - - -bool, optional } - description="Whether to delete formatting around the parameter. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority level for the removal operation. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate removal operations. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Renames a parameter in a function definition and updates all related references. - - - -str } - description="The new name for the parameter." - defaultValue="" -/> -int, optional } - description="The priority of the edit operation. Defaults to 0." - defaultValue="0" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### set_type_annotation -Sets the type annotation for this parameter. - - - -str } - description="The type annotation to set for the parameter." - defaultValue="" -/> - - - -None } description=""/> - - -### set_value -Sets the value of the node's value Expression. - - - -str } - description="The new value to set." - defaultValue="" -/> - - - -None } description=""/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ TSImport | TSSymbol | TSExport ] } description="A list of symbols that use or import the exportable object."/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSQueryType.mdx b/docs/_deprecated/api-reference/typescript/TSQueryType.mdx deleted file mode 100644 index 9ec8ba17b..000000000 --- a/docs/_deprecated/api-reference/typescript/TSQueryType.mdx +++ /dev/null @@ -1,421 +0,0 @@ ---- -title: "TSQueryType" -sidebarTitle: "TSQueryType" -icon: "" -description: "Type query Examples: typeof s" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### name - -str | None } description="Returns the name of the query type." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### query - -TSType[ TSQueryType ] } description="The TypeScript type associated with the query." /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSQueryType ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSQueryType ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSQueryType ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSReadonlyType.mdx b/docs/_deprecated/api-reference/typescript/TSReadonlyType.mdx deleted file mode 100644 index becea31fc..000000000 --- a/docs/_deprecated/api-reference/typescript/TSReadonlyType.mdx +++ /dev/null @@ -1,421 +0,0 @@ ---- -title: "TSReadonlyType" -sidebarTitle: "TSReadonlyType" -icon: "" -description: "Readonly type Examples: readonly s" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### name - -str | None } description="Retrieves the name of the type." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### type - -TSType[ TSReadonlyType ] } description="The underlying TypeScript type associated with this readonly type." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSReadonlyType ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSReadonlyType ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSReadonlyType ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSReturnTypePlaceholder.mdx b/docs/_deprecated/api-reference/typescript/TSReturnTypePlaceholder.mdx deleted file mode 100644 index f012530ff..000000000 --- a/docs/_deprecated/api-reference/typescript/TSReturnTypePlaceholder.mdx +++ /dev/null @@ -1,65 +0,0 @@ ---- -title: "TSReturnTypePlaceholder" -sidebarTitle: "TSReturnTypePlaceholder" -icon: "" -description: "A placeholder class for function return type annotations in TypeScript. This class represents a placeholder for function return type annotations, allowing for modification and addition of return type annotations after the parameter list. It provides functionality to add or modify return type annotations with proper formatting." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Placeholder](/api-reference/core/Placeholder) - - -## Methods - -### edit -Modifies the return type annotation of a function. - - - -str } - description="The return type annotation to add. If it doesn't start with ':', a ':' will be prepended." - defaultValue="" -/> -bool, optional } - description="Whether to fix the indentation of the added code. Defaults to False." - defaultValue="False" -/> -int, optional } - description="The priority of this edit. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to remove duplicate edits. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### remove -Removes this element from its parent container. - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSString.mdx b/docs/_deprecated/api-reference/typescript/TSString.mdx deleted file mode 100644 index 04bf6644f..000000000 --- a/docs/_deprecated/api-reference/typescript/TSString.mdx +++ /dev/null @@ -1,429 +0,0 @@ ---- -title: "TSString" -sidebarTitle: "TSString" -icon: "" -description: "A TypeScript string node representing both literal strings and template strings. This class handles both regular string literals and template strings in TypeScript, providing functionality to parse and manage template string expressions. It extends the base String class with TypeScript-specific capabilities." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[String](/api-reference/core/String), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### content - -str } description="The content of the string" /> - -### content_nodes - -Collection[ Expression [ Editable ], TSString ] } description="A collection of string fragments and escape sequences in TS, or a single string content in Python." /> - -### expressions - -list[ Expression [ Editable ]] } description="Embedded expressions in the string, only applicable for templated or formatted strings." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - -### with_quotes - -str } description="Retrieves the string representation with quotation marks." /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSString ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSString ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSString ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSSwitchCase.mdx b/docs/_deprecated/api-reference/typescript/TSSwitchCase.mdx deleted file mode 100644 index ee1404fa5..000000000 --- a/docs/_deprecated/api-reference/typescript/TSSwitchCase.mdx +++ /dev/null @@ -1,534 +0,0 @@ ---- -title: "TSSwitchCase" -sidebarTitle: "TSSwitchCase" -icon: "" -description: "Typescript switch case." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[TSBlockStatement](/api-reference/typescript/TSBlockStatement), [SwitchCase](/api-reference/core/SwitchCase), [TSHasBlock](/api-reference/typescript/TSHasBlock), [BlockStatement](/api-reference/core/BlockStatement), [HasBlock](/api-reference/core/HasBlock), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### code_block - -TSCodeBlock | None } description="The code block contained within the statement, if it exists." /> - -### condition - -Expression [ TSSwitchCase ] | None } description="The condition which triggers this case" /> - -### decorators - -list[ TSDecorator ] } description="Returns a list of decorators associated with this symbol." /> - -### default - -bool } description="is this a default case?" /> - -### docstring - -TSCommentGroup | None } description="Retrieves the docstring of a function or class." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Gets all function calls within the statement's code block." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### is_decorated - -bool } description="Checks if the current symbol has a decorator." /> - -### jsx_elements - -list[ JSXElement [ TSSwitchCase ]] } description="Returns a list of all JSX elements contained within this symbol." /> - -### nested_code_blocks - -list[ TSCodeBlock ] } description="Returns all nested CodeBlocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ TSSwitchCase ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSSwitchCase ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSSwitchCase ] } description=""/> - - -### get_component -Returns a specific JSX element from within this symbol's JSX elements. - - - -str } - description="The name of the JSX component to find." - defaultValue="" -/> - - - -JSXElement [ TSSwitchCase ] | None } description="The matching JSX element if found, None otherwise."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSSwitchCase ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_docstring -Sets or updates a docstring for a code element. - - - -str } - description="The docstring text to be added or updated." - defaultValue="" -/> -bool, optional } - description="Whether to automatically format the text into a docstring format. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to clean existing formatting from the docstring before inserting. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to add leading "*" to each line of the comment block. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to force single line comments to be multi-line. Defaults to False." - defaultValue="False" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSSwitchStatement.mdx b/docs/_deprecated/api-reference/typescript/TSSwitchStatement.mdx deleted file mode 100644 index af1482b2e..000000000 --- a/docs/_deprecated/api-reference/typescript/TSSwitchStatement.mdx +++ /dev/null @@ -1,433 +0,0 @@ ---- -title: "TSSwitchStatement" -sidebarTitle: "TSSwitchStatement" -icon: "" -description: "Typescript switch statement" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[SwitchStatement](/api-reference/core/SwitchStatement), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### cases - -list[ TSSwitchCase ] } description="A list of switch cases." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns all function calls within the switch statement." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### nested_code_blocks - -list[ TSCodeBlock ] } description="Returns all nested CodeBlocks within the switch statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ TSSwitchStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### value - -Expression [ TSSwitchStatement ] } description="The value to switch on." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSSwitchStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSSwitchStatement ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSSwitchStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSSymbol.mdx b/docs/_deprecated/api-reference/typescript/TSSymbol.mdx deleted file mode 100644 index 9a76aa282..000000000 --- a/docs/_deprecated/api-reference/typescript/TSSymbol.mdx +++ /dev/null @@ -1,758 +0,0 @@ ---- -title: "TSSymbol" -sidebarTitle: "TSSymbol" -icon: "" -description: "A TypeScript symbol representing a code element with advanced manipulation capabilities. This class extends Symbol and Exportable to provide TypeScript-specific functionality for managing code symbols. It offers methods for handling imports, comments, code refactoring, and file operations like moving symbols between files while maintaining their dependencies and references. The class provides functionality for managing both inline and block comments, setting and retrieving import strings, and maintaining semicolon presence. It includes capabilities for moving symbols between files with options to handle dependencies and import strategy selection." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Exportable](/api-reference/core/Exportable), [Symbol](/api-reference/core/Symbol), [Usable](/api-reference/core/Usable), [Importable](/api-reference/core/Importable), [Expression](/api-reference/core/Expression), [HasName](/api-reference/core/HasName), [Editable](/api-reference/core/Editable) - -## Attributes - -### comment - -TSCommentGroup | None } description="Retrieves the comment group associated with the symbol." /> - -### export - -TSExport | None } description="Returns the export object that exports this symbol." /> - -### exported_name - -str | None } description="Retrieves the exported name of a symbol from its file." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_nodes - -list[ Editable ] } description="Returns the list of nodes associated with this symbol including extended nodes." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### has_semicolon - -bool } description="Checks whether the current symbol has a semicolon at the end." /> - -### inline_comment - -TSCommentGroup | None } description="Property that retrieves the inline comment group associated with the symbol." /> - -### is_exported - -bool } description="Indicates if the symbol is exported from its defining file." /> - -### is_reexported - -bool } description="Determines if the symbol is re-exported from a different file." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### semicolon_node - -Editable | None } description="Retrieves the semicolon node associated with a TypeScript symbol." /> - -### source - -str } description="Returns the source code of the symbol." /> - -### symbol_type - -SymbolType } description="The type of the symbol." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_comment -Adds a new comment to the symbol. - - - -str } - description="The comment text to be added." - defaultValue="" -/> -bool } - description="Whether to automatically format the text into a comment style. Defaults to True." - defaultValue="True" -/> -bool } - description="Whether to clean the format of the comment before inserting. Defaults to True." - defaultValue="True" -/> -TSCommentType } - description="Type of comment to add. Defaults to TSCommentType.DOUBLE_SLASH." - defaultValue="TSCommentType.DOUBLE_SLASH" -/> - - - -None } description=""/> - - -### add_keyword -Insert a keyword in the appropriate place before this symbol if it doesn't already exist. - - - -str } - description="The keyword to be inserted. Must be a valid keyword in the language context." - defaultValue="" -/> - - - -None } description=""/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ TSSymbol , TSImport ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this node with new_src. - - - -str } - description="The new source code to replace the current source with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, prevents duplicate edits. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSSymbol ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Flags a TypeScript symbol by adding a flag comment and returning a CodeFlag. - - - -CodeFlag[ TSSymbol ] } description="The code flag object for tracking purposes"/> - - -### get_import_string -Generates the appropriate import string for a symbol. - - - -str | None, optional } - description="The alias to use for the imported symbol. Defaults to None." - defaultValue="None" -/> -str | None, optional } - description="The module to import from. If None, uses the file's import module name." - defaultValue="None" -/> -ImportType , optional } - description="The type of import to generate (e.g., WILDCARD). Defaults to" - defaultValue="ImportType.UNKNOWN" -/> -bool, optional } - description="Whether this is a type-only import. Defaults to False." - defaultValue="False" -/> - - - -str } description="A formatted import statement string."/> - - -### get_name -Returns the name node of the object. - - - -Name | TSChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSSymbol ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before the current symbol node in the Abstract Syntax Tree. - - - -str } - description="The source code text to insert." - defaultValue="" -/> -bool } - description="Whether to adjust the indentation of new_src to match current text. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after insertion. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to remove duplicate insertions. Defaults to True." - defaultValue="True" -/> -bool } - description="Whether to insert before extended nodes like comments and decorators. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### move_to_file -Moves the given symbol to a new file and updates its imports and references. - - - -TSFile } - description="The destination file to move the symbol to." - defaultValue="" -/> -bool } - description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." - defaultValue="True" -/> -str } - description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." - defaultValue=""update_all_imports"" -/> - - - -None } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Renames a symbol and updates all its references in the codebase. - - - -str } - description="The new name for the symbol." - defaultValue="" -/> -int } - description="Priority of the edit operation. Defaults to 0." - defaultValue="0" -/> - - - -tuple[NodeId, NodeId] } description="A tuple containing the file node ID and the new node ID of the renamed symbol."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_comment -Sets a comment to the symbol. - - - -str } - description="The comment text to be added." - defaultValue="" -/> -bool, optional } - description="Whether to automatically format the text into a comment syntax." - defaultValue="True" -/> -bool, optional } - description="Whether to clean the format of the comment before inserting." - defaultValue="True" -/> -TSCommentType , optional } - description="The style of comment to add." - defaultValue="TSCommentType.DOUBLE_SLASH" -/> - - - -None } description=""/> - - -### set_inline_comment -Sets an inline comment to the symbol. - - - -str } - description="The inline comment text to be added." - defaultValue="" -/> -bool, optional } - description="Whether to automatically format the text as a comment." - defaultValue="True" -/> -bool, optional } - description="Whether to clean the comment format before inserting." - defaultValue="True" -/> -TSNode | None, optional } - description="The specific node to attach the comment to." - defaultValue="None" -/> - - - -None } description=""/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ TSImport | TSSymbol | TSExport ] } description="A list of symbols that use or import the exportable object."/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSTernaryExpression.mdx b/docs/_deprecated/api-reference/typescript/TSTernaryExpression.mdx deleted file mode 100644 index 233ccaf95..000000000 --- a/docs/_deprecated/api-reference/typescript/TSTernaryExpression.mdx +++ /dev/null @@ -1,440 +0,0 @@ ---- -title: "TSTernaryExpression" -sidebarTitle: "TSTernaryExpression" -icon: "" -description: "Any ternary expression in the code where a condition will determine branched execution" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[TernaryExpression](/api-reference/core/TernaryExpression), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### alternative - -Expression [ TSTernaryExpression ] | None } description="The expression to execute if the condition is false." /> - -### condition - -Expression [ TSTernaryExpression ] | None } description="The condition expression that determines which branch to execute." /> - -### consequence - -Expression [ TSTernaryExpression ] | None } description="The expression to execute if the condition is true." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSTernaryExpression ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSTernaryExpression ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSTernaryExpression ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Simplifies a ternary expression based on a boolean condition. - - - -bool } - description="The boolean value to reduce the condition to. If True, keeps the consequence branch. If False, keeps the alternative branch." - defaultValue="" -/> -Editable | None, optional } - description="The node to be edited. Defaults to None." - defaultValue="None" -/> - - - -None } description="Modifies the ternary expression in place."/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSTryCatchStatement.mdx b/docs/_deprecated/api-reference/typescript/TSTryCatchStatement.mdx deleted file mode 100644 index b03afc2b1..000000000 --- a/docs/_deprecated/api-reference/typescript/TSTryCatchStatement.mdx +++ /dev/null @@ -1,534 +0,0 @@ ---- -title: "TSTryCatchStatement" -sidebarTitle: "TSTryCatchStatement" -icon: "" -description: "Abstract representation of the try/catch/finally block in TypeScript." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[TSBlockStatement](/api-reference/typescript/TSBlockStatement), [TryCatchStatement](/api-reference/core/TryCatchStatement), [TSHasBlock](/api-reference/typescript/TSHasBlock), [BlockStatement](/api-reference/core/BlockStatement), [HasBlock](/api-reference/core/HasBlock), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### catch - -TSCatchStatement [ TSTryCatchStatement ] | None } description="The catch block." /> - -### code_block - -TSCodeBlock | None } description="The code block contained within the statement, if it exists." /> - -### decorators - -list[ TSDecorator ] } description="Returns a list of decorators associated with this symbol." /> - -### docstring - -TSCommentGroup | None } description="Retrieves the docstring of a function or class." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### finalizer - -TSBlockStatement | None } description="The code block executed regardless of if an exception is thrown or not" /> - -### function_calls - -list[ FunctionCall ] } description="Gets all function calls within a try-catch-finally statement." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### is_decorated - -bool } description="Checks if the current symbol has a decorator." /> - -### jsx_elements - -list[ JSXElement [ TSTryCatchStatement ]] } description="Returns a list of all JSX elements contained within this symbol." /> - -### nested_code_blocks - -list[ TSCodeBlock ] } description="Returns all nested CodeBlocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ TSTryCatchStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSTryCatchStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSTryCatchStatement ] } description=""/> - - -### get_component -Returns a specific JSX element from within this symbol's JSX elements. - - - -str } - description="The name of the JSX component to find." - defaultValue="" -/> - - - -JSXElement [ TSTryCatchStatement ] | None } description="The matching JSX element if found, None otherwise."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSTryCatchStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_docstring -Sets or updates a docstring for a code element. - - - -str } - description="The docstring text to be added or updated." - defaultValue="" -/> -bool, optional } - description="Whether to automatically format the text into a docstring format. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to clean existing formatting from the docstring before inserting. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to add leading "*" to each line of the comment block. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to force single line comments to be multi-line. Defaults to False." - defaultValue="False" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSTypeAlias.mdx b/docs/_deprecated/api-reference/typescript/TSTypeAlias.mdx deleted file mode 100644 index bf53c3cc2..000000000 --- a/docs/_deprecated/api-reference/typescript/TSTypeAlias.mdx +++ /dev/null @@ -1,905 +0,0 @@ ---- -title: "TSTypeAlias" -sidebarTitle: "TSTypeAlias" -icon: "" -description: "Representation of an Interface in TypeScript." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[TSHasBlock](/api-reference/typescript/TSHasBlock), [TypeAlias](/api-reference/core/TypeAlias), [TSSymbol](/api-reference/typescript/TSSymbol), [HasBlock](/api-reference/core/HasBlock), [HasValue](/api-reference/core/HasValue), [Exportable](/api-reference/core/Exportable), [Symbol](/api-reference/core/Symbol), [Expression](/api-reference/core/Expression), [Usable](/api-reference/core/Usable), [Editable](/api-reference/core/Editable), [Importable](/api-reference/core/Importable), [HasName](/api-reference/core/HasName) - -## Attributes - -### attributes - -list[ TSAttribute ] } description="Retrieves all attributes belonging to this type alias." /> - -### code_block - -TSCodeBlock } description="The code block associated with this type alias." /> - -### comment - -TSCommentGroup | None } description="Retrieves the comment group associated with the symbol." /> - -### decorators - -list[ TSDecorator ] } description="Returns a list of decorators associated with this symbol." /> - -### docstring - -TSCommentGroup | None } description="Retrieves the docstring of a function or class." /> - -### export - -TSExport | None } description="Returns the export object that exports this symbol." /> - -### exported_name - -str | None } description="Retrieves the exported name of a symbol from its file." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_nodes - -list[ Editable ] } description="Returns the list of nodes associated with this symbol including extended nodes." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### full_name - -str | None } description="Returns the full name of the object, including the namespace path." /> - -### function_calls - -list[ FunctionCall ] } description="Returns all function calls within the code block and its decorators." /> - -### has_semicolon - -bool } description="Checks whether the current symbol has a semicolon at the end." /> - -### inline_comment - -TSCommentGroup | None } description="Property that retrieves the inline comment group associated with the symbol." /> - -### is_decorated - -bool } description="Checks if the current symbol has a decorator." /> - -### is_exported - -bool } description="Indicates if the symbol is exported from its defining file." /> - -### is_reexported - -bool } description="Determines if the symbol is re-exported from a different file." /> - -### jsx_elements - -list[ JSXElement [ TSTypeAlias ]] } description="Returns a list of all JSX elements contained within this symbol." /> - -### name - -str | None } description="Retrieves the base name of the object without namespace prefixes." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### semicolon_node - -Editable | None } description="Retrieves the semicolon node associated with a TypeScript symbol." /> - -### source - -str } description="Returns the source code of the symbol." /> - -### symbol_type - - } description="The type of symbol, set to SymbolType.Type." /> - -### type_parameters - -TypeParameters[ Type , TSTypeAlias ] | None } description="The type parameters of the symbol, if any." /> - -### value - -Expression | None } description="Gets the value node of the object." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_comment -Adds a new comment to the symbol. - - - -str } - description="The comment text to be added." - defaultValue="" -/> -bool } - description="Whether to automatically format the text into a comment style. Defaults to True." - defaultValue="True" -/> -bool } - description="Whether to clean the format of the comment before inserting. Defaults to True." - defaultValue="True" -/> -TSCommentType } - description="Type of comment to add. Defaults to TSCommentType.DOUBLE_SLASH." - defaultValue="TSCommentType.DOUBLE_SLASH" -/> - - - -None } description=""/> - - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### add_keyword -Insert a keyword in the appropriate place before this symbol if it doesn't already exist. - - - -str } - description="The keyword to be inserted. Must be a valid keyword in the language context." - defaultValue="" -/> - - - -None } description=""/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### dependencies -Returns a list of symbols that this symbol depends on. - - - -UsageType | None } - description="The types of dependencies to search for. Defaults to UsageType.DIRECT." - defaultValue="UsageType.DIRECT" -/> -int | None } - description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" - defaultValue="None" -/> - - - -list[Union[ TSSymbol , TSImport ]] } description="A list of symbols and imports that this symbol depends on, sorted by file location."/> - - -### edit -Replace the source of this node with new_src. - - - -str } - description="The new source code to replace the current source with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of new_src to match the current text's indentation. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of this edit. Higher priority edits take precedence. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, prevents duplicate edits. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSTypeAlias ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Flags a TypeScript symbol by adding a flag comment and returning a CodeFlag. - - - -CodeFlag[ TSTypeAlias ] } description="The code flag object for tracking purposes"/> - - -### get_attribute -Retrieves a specific attribute from a TypeScript type alias by its name. - - - -str } - description="The name of the attribute to retrieve." - defaultValue="" -/> - - - -TSAttribute | None } description="The attribute with the specified name if found, None otherwise."/> - - -### get_component -Returns a specific JSX element from within this symbol's JSX elements. - - - -str } - description="The name of the JSX component to find." - defaultValue="" -/> - - - -JSXElement [ TSTypeAlias ] | None } description="The matching JSX element if found, None otherwise."/> - - -### get_import_string -Generates the appropriate import string for a symbol. - - - -str | None, optional } - description="The alias to use for the imported symbol. Defaults to None." - defaultValue="None" -/> -str | None, optional } - description="The module to import from. If None, uses the file's import module name." - defaultValue="None" -/> -ImportType , optional } - description="The type of import to generate (e.g., WILDCARD). Defaults to" - defaultValue="ImportType.UNKNOWN" -/> -bool, optional } - description="Whether this is a type-only import. Defaults to False." - defaultValue="False" -/> - - - -str } description="A formatted import statement string."/> - - -### get_name -Returns the name node of the object. - - - -Name | TSChainedAttribute | None } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSTypeAlias ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before the current symbol node in the Abstract Syntax Tree. - - - -str } - description="The source code text to insert." - defaultValue="" -/> -bool } - description="Whether to adjust the indentation of new_src to match current text. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after insertion. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of this edit operation. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to remove duplicate insertions. Defaults to True." - defaultValue="True" -/> -bool } - description="Whether to insert before extended nodes like comments and decorators. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### move_to_file -Moves the given symbol to a new file and updates its imports and references. - - - -TSFile } - description="The destination file to move the symbol to." - defaultValue="" -/> -bool } - description="If True, moves all dependencies of the symbol to the new file. If False, adds imports for the dependencies. Defaults to True." - defaultValue="True" -/> -str } - description="The strategy to use for updating imports. Can be either 'add_back_edge' or 'update_all_imports'. Defaults to 'update_all_imports'." - defaultValue=""update_all_imports"" -/> - - - -None } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### rename -Renames a symbol and updates all its references in the codebase. - - - -str } - description="The new name for the symbol." - defaultValue="" -/> -int } - description="Priority of the edit operation. Defaults to 0." - defaultValue="0" -/> - - - -tuple[NodeId, NodeId] } description="A tuple containing the file node ID and the new node ID of the renamed symbol."/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_comment -Sets a comment to the symbol. - - - -str } - description="The comment text to be added." - defaultValue="" -/> -bool, optional } - description="Whether to automatically format the text into a comment syntax." - defaultValue="True" -/> -bool, optional } - description="Whether to clean the format of the comment before inserting." - defaultValue="True" -/> -TSCommentType , optional } - description="The style of comment to add." - defaultValue="TSCommentType.DOUBLE_SLASH" -/> - - - -None } description=""/> - - -### set_docstring -Sets or updates a docstring for a code element. - - - -str } - description="The docstring text to be added or updated." - defaultValue="" -/> -bool, optional } - description="Whether to automatically format the text into a docstring format. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to clean existing formatting from the docstring before inserting. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to add leading "*" to each line of the comment block. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to force single line comments to be multi-line. Defaults to False." - defaultValue="False" -/> - - - -None } description=""/> - - -### set_inline_comment -Sets an inline comment to the symbol. - - - -str } - description="The inline comment text to be added." - defaultValue="" -/> -bool, optional } - description="Whether to automatically format the text as a comment." - defaultValue="True" -/> -bool, optional } - description="Whether to clean the comment format before inserting." - defaultValue="True" -/> -TSNode | None, optional } - description="The specific node to attach the comment to." - defaultValue="None" -/> - - - -None } description=""/> - - -### set_name -Sets the name of a code element. - - - -str } - description="The new name to set for the object." - defaultValue="" -/> - - - -None } description=""/> - - -### set_value -Sets the value of the node's value Expression. - - - -str } - description="The new value to set." - defaultValue="" -/> - - - -None } description=""/> - - -### symbol_usages -Returns a list of symbols that use or import the exportable object. - - - -UsageType | None } - description="The types of usages to search for. Defaults to any." - defaultValue="None" -/> - - - -list[ TSImport | TSSymbol | TSExport ] } description="A list of symbols that use or import the exportable object."/> - - -### usages -Returns a list of usages of the exportable object. - - - -UsageType | None } - description="Specifies which types of usages to include in the results. Default is any usages." - defaultValue="None" -/> - - - -list[ Usage ] } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse."/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSUndefinedType.mdx b/docs/_deprecated/api-reference/typescript/TSUndefinedType.mdx deleted file mode 100644 index c6f8b9791..000000000 --- a/docs/_deprecated/api-reference/typescript/TSUndefinedType.mdx +++ /dev/null @@ -1,413 +0,0 @@ ---- -title: "TSUndefinedType" -sidebarTitle: "TSUndefinedType" -icon: "" -description: "Undefined type. Represents the undefined keyword Examples: undefined" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSUndefinedType ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSUndefinedType ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSUndefinedType ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSUnionType.mdx b/docs/_deprecated/api-reference/typescript/TSUnionType.mdx deleted file mode 100644 index da6e3f8d2..000000000 --- a/docs/_deprecated/api-reference/typescript/TSUnionType.mdx +++ /dev/null @@ -1,396 +0,0 @@ ---- -title: "TSUnionType" -sidebarTitle: "TSUnionType" -icon: "" -description: "Union type Examples: string | number" ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[UnionType](/api-reference/core/UnionType), [Type](/api-reference/core/Type), [Expression](/api-reference/core/Expression), [SymbolGroup](/api-reference/core/SymbolGroup), [Editable](/api-reference/core/Editable) - -## Attributes - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns a list of all function calls contained within this expression." /> - -### next_named_sibling - -Editable | None } description="Returns the next named sibling of the last symbol in the group." /> - -### next_sibling - -Editable | None } description="Returns the next sibling of the last symbol in the symbol group." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Get the source code content of the node." /> - -### symbols - -list[ Editable ] } description="Returns the list of symbols in the group." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Edit the source for this Collection instance. - - - -None } description=""/> - - -### find -Search for substrings in the given symbols that match `strings_to_match`. - - - -list[str] | str } - description="The string or list of strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes that exactly match the query." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable objects representing each match found."/> - - -### find_string_literals -Search for string literals matching given strings in the SymbolGroup. - - - -list[str] } - description="List of strings to search for in string literals." - defaultValue="" -/> -bool, optional } - description="If True, performs fuzzy matching instead of exact matching." - defaultValue="False" -/> - - - -list[ Editable ] } description="List of Editable nodes representing the matching string literals found within the symbols."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSUnionType ] } description=""/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSUnionType ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### index -Return the index of the first occurrence of value. - - - -int } description=""/> - - -### insert -Adds `value` to the container that this node represents - - - -None } description=""/> - - -### insert_after -Inserts source code after this node in the codebase. - - - -str } - description="The source code to insert." - defaultValue="" -/> -bool, optional } - description="Adjust indentation to match current text." - defaultValue="False" -/> -bool, optional } - description="Add a newline before the inserted code." - defaultValue="True" -/> -int, optional } - description="Priority of the edit operation." - defaultValue="0" -/> -bool, optional } - description="Deduplicate identical edits." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts source code before this symbol group. - - - -str } - description="The source code to insert." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of the inserted code to match the current code. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline after the inserted code. Defaults to True." - defaultValue="True" -/> -int, optional } - description="The priority of this edit operation. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to prevent duplicate insertions of the same code. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Removes an element from a Collection. - - - -Editable | None } - description="The element to remove from the Collection. If None, delegates to parent class." - defaultValue="None" -/> - - - -None } description="This method doesn't return anything."/> - - -### replace -Replaces all instances of a string with a new string in all symbols within the group. - - - -str } - description="The string to be replaced." - defaultValue="" -/> -str } - description="The string to replace with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="Number of replacements made."/> - - -### search -Searches for regex matches in the codebase. - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool, optional } - description="Whether to include string literals in the search. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to include comments in the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects representing matched text nodes in the codebase."/> - - - diff --git a/docs/_deprecated/api-reference/typescript/TSWhileStatement.mdx b/docs/_deprecated/api-reference/typescript/TSWhileStatement.mdx deleted file mode 100644 index e36fac613..000000000 --- a/docs/_deprecated/api-reference/typescript/TSWhileStatement.mdx +++ /dev/null @@ -1,530 +0,0 @@ ---- -title: "TSWhileStatement" -sidebarTitle: "TSWhileStatement" -icon: "" -description: "A TypeScript while statement class that represents while loops and manages their condition and code block. This class provides functionality for handling while statements in TypeScript code, including managing the loop's condition and associated code block. It extends the base WhileStatement class with TypeScript-specific behavior." ---- -import {Parameter} from '/snippets/Parameter.mdx'; -import {ParameterWrapper} from '/snippets/ParameterWrapper.mdx'; -import {Return} from '/snippets/Return.mdx'; -import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx'; -import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx'; -import {Attribute} from '/snippets/Attribute.mdx'; - - - -### Inherits from -[TSHasBlock](/api-reference/typescript/TSHasBlock), [WhileStatement](/api-reference/core/WhileStatement), [HasBlock](/api-reference/core/HasBlock), [Statement](/api-reference/core/Statement), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable) - -## Attributes - -### code_block - -TSCodeBlock } description="The code block that represents the body of the while statement." /> - -### condition - -Expression [ TSWhileStatement ] } description="The condition expression of the while statement." /> - -### decorators - -list[ TSDecorator ] } description="Returns a list of decorators associated with this symbol." /> - -### docstring - -TSCommentGroup | None } description="Retrieves the docstring of a function or class." /> - -### extended - -SymbolGroup } description="Returns a SymbolGroup of all extended nodes associated with this element." /> - -### extended_source - -str } description="Returns the source text representation of all extended nodes." /> - -### file - -TSFile } description="The file object that this Editable instance belongs to." /> - -### filepath - -str } description="The file path of the file that this Editable instance belongs to." /> - -### function_calls - -list[ FunctionCall ] } description="Returns all function calls within the while statement block." /> - -### index - -int } description="The 0-based index of the statement in the parent code block." /> - -### is_decorated - -bool } description="Checks if the current symbol has a decorator." /> - -### jsx_elements - -list[ JSXElement [ TSWhileStatement ]] } description="Returns a list of all JSX elements contained within this symbol." /> - -### nested_code_blocks - -list[ TSCodeBlock ] } description="Returns all nested CodeBlocks within the statement." /> - -### nested_statements - -list[ MultiLineCollection [ Statement [ TSWhileStatement ], Editable ]] } description="Returns a list of statement collections within nested code blocks." /> - -### parent - -Editable } description="The parent node of this Editable instance." /> - -### parent_class - -TSClass | None } description="Find the class this node is contained in" /> - -### parent_function - -TSFunction | None } description="Find the function this node is contained in" /> - -### parent_statement - -Statement | None } description="Find the statement this node is contained in" /> - -### resolved_value - -Expression | list[ Expression ] } description="Returns the resolved type of an Expression." /> - -### source - -str } description="Text representation of the Editable instance." /> - -### variable_usages - -list[ Editable ] } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" /> - - -## Methods - -### add_decorator -Adds a decorator to a function or method. - - - -str } - description="The decorator to add, including the '@' symbol." - defaultValue="" -/> -bool, optional } - description="If True, skips adding if the decorator exists." - defaultValue="False" -/> - - - -bool } description="True if the decorator was added, False if skipped."/> - - -### ancestors -Find all ancestors of the node of the given type. Does not return itself - - - -list[ Editable ] } description=""/> - - -### edit -Replace the source of this `Editable` with `new_src`. - - - -str } - description="The new source text to replace the current text with." - defaultValue="" -/> -bool } - description="If True, adjusts the indentation of `new_src` to match the current text's indentation level. Defaults to False." - defaultValue="False" -/> -int } - description="The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0." - defaultValue="0" -/> -bool } - description="If True, deduplicates identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### find -Find and return matching nodes or substrings within an Editable instance. - - - -Union[list[str], str] } - description="One or more strings to search for." - defaultValue="" -/> -bool } - description="If True, only return nodes whose source exactly matches one of the strings_to_match." - defaultValue="False" -/> - - - -list[ Editable ] } description="A list of Editable instances that match the search criteria."/> - - -### find_string_literals -Returns a list of string literals within this node's source that match any of the given - - - -list[str] } - description="A list of strings to search for in string literals." - defaultValue="" -/> -bool } - description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." - defaultValue="False" -/> - - - -list[ Editable [ TSWhileStatement ]] } description="A list of Editable objects representing the matching string literals."/> - - -### flag -Adds a visual flag comment to the end of this Editable's source text. - - - -CodeFlag[ TSWhileStatement ] } description=""/> - - -### get_component -Returns a specific JSX element from within this symbol's JSX elements. - - - -str } - description="The name of the JSX component to find." - defaultValue="" -/> - - - -JSXElement [ TSWhileStatement ] | None } description="The matching JSX element if found, None otherwise."/> - - -### get_variable_usages -Returns Editables for all TreeSitter nodes corresponding to instances of variable usage - - - -str } - description="The variable name to search for." - defaultValue="" -/> -bool } - description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." - defaultValue="False" -/> - - - -Sequence[ Editable [ TSWhileStatement ]] } description="List of Editable objects representing variable usage nodes matching the given name."/> - - -### insert_after -Inserts code after this node. - - - -str } - description="The source code to insert after this node." - defaultValue="" -/> -bool, optional } - description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool, optional } - description="Whether to add a newline before the new_src. Defaults to True." - defaultValue="True" -/> -int, optional } - description="Priority of the insertion transaction. Defaults to 0." - defaultValue="0" -/> -bool, optional } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### insert_before -Inserts text before this node's source with optional indentation and newline handling. - - - -str } - description="The text to insert before this node." - defaultValue="" -/> -bool } - description="Whether to fix the indentation of new_src to match the current node. Defaults to False." - defaultValue="False" -/> -bool } - description="Whether to add a newline after new_src. Defaults to True." - defaultValue="True" -/> -int } - description="Transaction priority for managing multiple edits. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate identical transactions. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### is_child_of -Checks if this node is a descendant of the given editable instance in the AST. - - - -bool } description=""/> - - -### is_wrapped_in -Check if this node is contained another node of the given class - - - -bool } description=""/> - - -### parent_of_type -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### parent_of_types -Find the first ancestor of the node of the given type. Does not return itself - - - -Editable | None } description=""/> - - -### reduce_condition -Reduces an editable to the following condition - - - -None } description=""/> - - -### remove -Deletes this Node and its related extended nodes (e.g. decorators, comments). - - - -bool } - description="Whether to delete surrounding whitespace and formatting. Defaults to True." - defaultValue="True" -/> -int } - description="Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0." - defaultValue="0" -/> -bool } - description="Whether to deduplicate removal transactions at the same location. Defaults to True." - defaultValue="True" -/> - - - -None } description=""/> - - -### replace -Search and replace occurrences of text within this node's source and its extended nodes. - - - -str } - description="The text or pattern to search for." - defaultValue="" -/> -str } - description="The text to replace matches with." - defaultValue="" -/> -int, optional } - description="Maximum number of replacements to make. Defaults to -1 (replace all)." - defaultValue="-1" -/> -bool, optional } - description="Whether to treat 'old' as a regex pattern. Defaults to False." - defaultValue="False" -/> -int, optional } - description="Priority of the replacement operation. Defaults to 0." - defaultValue="0" -/> - - - -int } description="The total number of replacements made."/> - - -### search -Returns a list of all regex match of `regex_pattern`, similar to python's re.search(). - - - -str } - description="The regular expression pattern to search for." - defaultValue="" -/> -bool } - description="When False, excludes the contents of string literals from the search. Defaults to True." - defaultValue="True" -/> -bool } - description="When False, excludes the contents of comments from the search. Defaults to True." - defaultValue="True" -/> - - - -list[ Editable ] } description="A list of Editable objects corresponding to the matches found."/> - - -### set_docstring -Sets or updates a docstring for a code element. - - - -str } - description="The docstring text to be added or updated." - defaultValue="" -/> -bool, optional } - description="Whether to automatically format the text into a docstring format. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to clean existing formatting from the docstring before inserting. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to add leading "*" to each line of the comment block. Defaults to True." - defaultValue="True" -/> -bool, optional } - description="Whether to force single line comments to be multi-line. Defaults to False." - defaultValue="False" -/> - - - -None } description=""/> - - - diff --git a/docs/_deprecated/building-with-codegen/at-a-glance.mdx b/docs/_deprecated/building-with-codegen/at-a-glance.mdx deleted file mode 100644 index 125c39738..000000000 --- a/docs/_deprecated/building-with-codegen/at-a-glance.mdx +++ /dev/null @@ -1,148 +0,0 @@ ---- -title: "Building with Codegen" -sidebarTitle: "At a Glance" -icon: "book" -iconType: "solid" ---- - -Learn how to use Codegen's core APIs to analyze and transform code. - -## Core Concepts - - - - Understand how Codegen parses and analyzes different programming languages. - - - Learn how to work with files, directories, and navigate the codebase - structure. - - - Learn how to safely modify code while preserving formatting and comments. - - - Master the core abstractions for manipulating code safely and effectively. - - - - -## Navigating the Code Graph - - - - Analyze relationships between code elements and track symbol references. - - - Understand function call patterns and manipulate call sites. - - - Work with module imports and manage dependencies. - - - Navigate function call relationships and analyze code flow. - - - -## Code Manipulation - - - - Relocate functions, classes, and other symbols while updating references. - - - Work with code blocks, control flow, and statement manipulation. - - - Handle variable declarations, assignments, and scope. - - - Work with groups of related code elements like functions, classes, and - imports. - - - -## Special Features - - - - Work with React components, JSX syntax, and component transformations. - - - Analyze and manipulate local variable usage and scope. - - - Integrate AI assistance into your code transformations. - - - Visualize code relationships and dependencies. - - - - - Each guide includes practical examples and best practices. Start with core - concepts or jump directly to the topics most relevant to your needs. - diff --git a/docs/_deprecated/building-with-codegen/calling-out-to-llms.mdx b/docs/_deprecated/building-with-codegen/calling-out-to-llms.mdx deleted file mode 100644 index 0b2fa7fa3..000000000 --- a/docs/_deprecated/building-with-codegen/calling-out-to-llms.mdx +++ /dev/null @@ -1,233 +0,0 @@ ---- -title: "Calling Out to LLMs" -sidebarTitle: "LLM Integration" -icon: "brain" -iconType: "solid" ---- - -Codegen natively integrates with LLMs via the [codebase.ai(...)](../api-reference/core/Codebase#ai) method, which lets you use large language models (LLMs) to help generate, modify, and analyze code. - -## Configuration - -Before using AI capabilities, you need to provide an OpenAI API key via [codebase.set_ai_key(...)](../api-reference/core/Codebase#set-ai-key): - -```python -# Set your OpenAI API key -codebase.set_ai_key("your-openai-api-key") -``` - -## Calling Codebase.ai(...) - -The [Codebase.ai(...)](../api-reference/core/Codebase#ai) method takes three key arguments: - -```python -result = codebase.ai( - prompt="Your instruction to the AI", - target=symbol_to_modify, # Optional: The code being operated on - context=additional_info # Optional: Extra context from static analysis -) -``` - -- **prompt**: Clear instruction for what you want the AI to do -- **target**: The symbol (function, class, etc.) being operated on - its source code will be provided to the AI -- **context**: Additional information you want to provide to the AI, which you can gather using GraphSitter's analysis tools - - - Codegen does not automatically provide any context to the LLM by default. It - does not "understand" your codebase, only the context you provide. - - -The context parameter can include: - -- A single symbol (its source code will be provided) -- A list of related symbols -- A dictionary mapping descriptions to symbols/values -- Nested combinations of the above - -### How Context Works - -The AI doesn't automatically know about your codebase. Instead, you can provide relevant context by: - -1. Using GraphSitter's static analysis to gather information: - -```python -function = codebase.get_function("process_data") -context = { - "call_sites": function.call_sites, # Where the function is called - "dependencies": function.dependencies, # What the function depends on - "parent": function.parent, # Class/module containing the function - "docstring": function.docstring, # Existing documentation -} -``` - -2. Passing this information to the AI: - -```python -result = codebase.ai( - "Improve this function's implementation", - target=function, - context=context # AI will see the gathered information -) -``` - -## Common Use Cases - -### Code Generation - -Generate new code or refactor existing code: - -```python -# Break up a large function -function = codebase.get_function("large_function") -new_code = codebase.ai( - "Break this function into smaller, more focused functions", - target=function -) -function.edit(new_code) - -# Generate a test -my_function = codebase.get_function("my_function") -test_code = codebase.ai( - f"Write a test for the function {my_function.name}", - target=my_function -) -my_function.insert_after(test_code) -``` - -### Documentation - -Generate and format documentation: - -```python -# Generate docstrings for a class -class_def = codebase.get_class("MyClass") -for method in class_def.methods: - docstring = codebase.ai( - "Generate a docstring describing this method", - target=method, - context={ - "class": class_def, - "style": "Google docstring format" - } - ) - method.set_docstring(docstring) -``` - -### Code Analysis and Improvement - -Use AI to analyze and improve code: - -```python -# Improve function names -for function in codebase.functions: - if codebase.ai( - "Does this function name clearly describe its purpose? Answer yes/no", - target=function - ).lower() == "no": - new_name = codebase.ai( - "Suggest a better name for this function", - target=function, - context={"call_sites": function.call_sites} - ) - function.rename(new_name) -``` - -### Contextual Modifications - -Make changes with full context awareness: - -```python -# Refactor a class method -method = codebase.get_class("MyClass").get_method("target_method") -new_impl = codebase.ai( - "Refactor this method to be more efficient", - target=method, - context={ - "parent_class": method.parent, - "call_sites": method.call_sites, - "dependencies": method.dependencies - } -) -method.edit(new_impl) -``` - -## Best Practices - -1. **Provide Relevant Context** - - ```python - # Good: Providing specific, relevant context - summary = codebase.ai( - "Generate a summary of this method's purpose", - target=method, - context={ - "class": method.parent, # Class containing the method - "usages": list(method.usages), # How the method is used - "dependencies": method.dependencies, # What the method depends on - "style": "concise" - } - ) - - # Bad: Missing context that could help the AI - summary = codebase.ai( - "Generate a summary", - target=method # AI only sees the method's code - ) - ``` - -2. **Gather Comprehensive Context** - - ```python - # Gather relevant information before AI call - def get_method_context(method): - return { - "class": method.parent, - "call_sites": list(method.call_sites), - "dependencies": list(method.dependencies), - "related_methods": [m for m in method.parent.methods - if m.name != method.name] - } - - # Use gathered context in AI call - new_impl = codebase.ai( - "Refactor this method to be more efficient", - target=method, - context=get_method_context(method) - ) - ``` - -3. **Handle AI Limits** - - ```python - # Set custom AI request limits for large operations - codebase.set_session_options(max_ai_requests=200) - ``` - -4. **Review Generated Code** - ```python - # Generate and review before applying - new_code = codebase.ai( - "Optimize this function", - target=function - ) - print("Review generated code:") - print(new_code) - if input("Apply changes? (y/n): ").lower() == 'y': - function.edit(new_code) - ``` - -## Limitations and Safety - -- The AI doesn't automatically know about your codebase - you must provide relevant context -- AI-generated code should always be reviewed -- Default limit of 150 AI requests per codemod execution - - Use [set_session_options(...)](../api-reference/core/Codebase#set-session-options) to adjust limits: - ```python - codebase.set_session_options(max_ai_requests=200) - ``` - - You can also use `codebase.set_session_options` to increase the execution time and the number of operations allowed in a session. This is useful for handling larger tasks or more complex operations that require additional resources. Adjust the `max_seconds` and `max_transactions` parameters to suit your needs: - ```python - codebase.set_session_options(max_seconds=300, max_transactions=500) - ``` - \ No newline at end of file diff --git a/docs/_deprecated/building-with-codegen/class-api.mdx b/docs/_deprecated/building-with-codegen/class-api.mdx deleted file mode 100644 index 70f4ee686..000000000 --- a/docs/_deprecated/building-with-codegen/class-api.mdx +++ /dev/null @@ -1,175 +0,0 @@ ---- -title: "The Class API" -sidebarTitle: "Classes" -icon: "cube" -iconType: "solid" ---- - -The [Class](/api-reference/core/Class) API extends the [Symbol](/building-with-codegen/symbol-api) API to support methods, attributes, and inheritance hierarchies. - -## Methods and Method Usages - -Classes provide access to their methods and method [usages](/building-with-codegen/dependencies-and-usages) through an intuitive API: - -```python -# Access methods -for method in class_def.methods: - print(f"Method: {method.name}") - # Find all usages of this method - for usage in method.usages: - print(f"Used in {usage.file.name}") - -# Get specific methods -init_method = class_def.constructor # Get __init__ method -process_method = class_def.get_method("process_data") - -# Filter methods -public_methods = class_def.methods(private=False) # Exclude private methods -regular_methods = class_def.methods(magic=False) # Exclude magic methods -``` - - - Methods are typed as [Function](/api-reference/core/Function) objects. - - -## Class Attributes - -[Attributes](/api-reference/core/Attribute) can be accessed and modified easily: - -```python -# Access all attributes -for attr in class_def.attributes: - print(f"Attribute: {attr.name}") - -# Add new attributes -class_def.add_attribute_from_source("count: int = 0") - -# Get specific attribute -name_attr = class_def.get_attribute("name") - -# Add attribute from another class -other_class = codebase.get_class("OtherClass") -class_def.add_attribute( - other_class.get_attribute("config"), - include_dependencies=True # Also adds required imports -) -``` - -### Manipulating Attributes - -[Attributes](/api-reference/core/Attribute) expose their own API for modification and analysis: - -```python -# Modify attribute values and types -attr = class_def.get_attribute("count") -attr.set_value("42") # Change value -attr.assignment.set_type_annotation("float") # Change type -attr.assignment.type.remove() # Remove type annotation - -# Find attribute usages -for usage in attr.usages: - print(f"Used in {usage.file.name}") - -# Find local usages (within the class) -for usage in attr.local_usages: - print(f"Used in method: {usage.parent_function.name}") - -# Rename attributes (updates all references) -attr.rename("new_name") # Also updates self.count -> self.new_name - -# Remove attributes -attr.remove() # Removes the attribute definition - -# Check attribute properties -if attr.is_private: # Starts with underscore - print("Private attribute") -if attr.is_optional: # Optional[Type] or Type | None - print("Optional attribute") - -# Access underlying value -if attr.value: # The expression assigned to the attribute - print(f"Default value: {attr.value.source}") -``` - - - Attribute operations automatically handle all references, including - `self.attribute` usages in methods and string references. - - -### Working with Inheritance - -You can navigate inheritance hierarchies with APIs including: - -- [Class.superclasses](/api-reference/core/Class#superclasses) -- [Class.subclasses](/api-reference/core/Class#subclasses) -- [Class.is_subclass_of](/api-reference/core/Class#is-subclass-of) - -```python -class_def = codebase.get_class("Cube") - -# View ancestors -all_ancestors = class_def.superclasses # All classes inherited -immediate_parents = class_def.superclasses(max_depth=1) # Direct parents only - -# Inheritance-aware method lookup -method = class_def.get_method("process") # Searches up inheritance chain -if method.parent_class != class_def: - print(f"Method inherited from {method.parent_class.name}") - -# Handle external dependencies -if class_def.is_subclass_of("Enum"): # Works with stdlib/external classes - print("This is an enum class") -``` - -Likewise, you can modify inheritance by accessing: - -- [Class.parent_class_names](/api-reference/core/Class#parent-class-names) -- [Class.get_parent_class(cls_name)](/api-reference/core/Class#get-parent-class) - -Which return lists of [Name](/api-reference/core/Name) objects. - -```python -# Modify inheritance -parent_names = class_def.parent_class_names -if parent_names[0] == 'BaseClass': - parent_names[0].edit("NewBaseClass") # Change parent class - -# Get specific parent class -parent_class = class_def.get_parent_class("BaseClass") -if parent_class: - parent_class.edit("NewBaseClass") # Change parent class -``` - - - When working with inheritance, use `max_depth` to control how far up the - inheritance chain to look. `max_depth=0` means current class only, - `max_depth=None` means traverse entire hierarchy. - - - - Codegen handles both internal and external parent classes (like stdlib - classes). The `superclasses` property follows the language's MRO rules for - method resolution. - - -## Method Resolution Order (MRO) - -Codegen follows the target language's method resolution order (MRO) for inheritance: - -```python -# Access superclasses -for parent in class_def.superclasses: - print(f"Parent: {parent.name}") - -# Check inheritance -if class_def.is_subclass_of("BaseClass"): - print("This is a subclass of BaseClass") - -# Get all subclasses -for child in class_def.subclasses: - print(f"Child class: {child.name}") - -# Access inherited methods/attributes -all_methods = class_def.methods(max_depth=None) # Include inherited methods -all_attrs = class_def.attributes(max_depth=None) # Include inherited attributes -``` diff --git a/docs/_deprecated/building-with-codegen/codebase-visualization.mdx b/docs/_deprecated/building-with-codegen/codebase-visualization.mdx deleted file mode 100644 index da5e368f3..000000000 --- a/docs/_deprecated/building-with-codegen/codebase-visualization.mdx +++ /dev/null @@ -1,275 +0,0 @@ ---- -title: "Codebase Visualization" -sidebarTitle: "Visualization" -icon: "share-nodes" -iconType: "solid" ---- - -Codegen provides the ability to create interactive graph visualizations via the [codebase.visualize(...)](/api-reference/core/Codebase#visualize) method. - -These visualizations have a number of applications, including: - -- Understanding codebase structure -- Monitoring critical code paths -- Analyzing dependencies -- Understanding inheritance hierarchies - -This guide provides a basic overview of graph creation and customization. Like the one below which displays the call_graph for the [modal/client.py](https://github.com/modal-labs/modal-client/blob/v0.72.49/modal/client.py) module. - - - - - Codegen visualizations are powered by [NetworkX](https://networkx.org/) and - rendered using [d3](https://d3js.org/what-is-d3). - - -## Basic Usage - -The [Codebase.visualize](/api-reference/core/Codebase#visualize) method operates on a NetworkX [DiGraph](https://networkx.org/documentation/stable/reference/classes/graph.DiGraph.html). - -```python -import networkx as nx - -# Basic visualization -G = nx.grid_2d_graph(5, 5) -# Or start with an empty graph -# G = nx.DiGraph() -codebase.visualize(G) - -``` - -It is up to the developer to add nodes and edges to the graph. - -### Adding Nodes and Edges - -When adding nodes to your graph, you can either add the symbol directly or just its name: - -```python -import networkx as nx -G = nx.DiGraph() -function = codebase.get_function("my_function") - -# Add the function object directly - enables source code preview -graph.add_node(function) # Will show function's source code on click - -# Add just the name - no extra features -graph.add_node(function.name) # Will only show the name -``` - - - Adding symbols to the graph directly (as opposed to adding by name) enables - automatic type information, code preview on hover, and more. - - -## Common Visualization Types - -### Call Graphs - -Visualize how functions call each other and trace execution paths: - -```python -def create_call_graph(entry_point: Function): - graph = nx.DiGraph() - - def add_calls(func): - for call in func.call_sites: - called_func = call.resolved_symbol - if called_func: - # Add function objects for rich previews - graph.add_node(func) - graph.add_node(called_func) - graph.add_edge(func, called_func) - add_calls(called_func) - - add_calls(entry_point) - return graph - -# Visualize API endpoint call graph -endpoint = codebase.get_function("handle_request") -call_graph = create_call_graph(endpoint) -codebase.visualize(call_graph, root=endpoint) -``` - - - Learn more about [traversing the call graph - here](/building-with-codegen/traversing-the-call-graph). - - -### React Component Trees - -Visualize the hierarchy of React components: - -```python -def create_component_tree(root_component: Class): - graph = nx.DiGraph() - - def add_children(component): - for usage in component.usages: - if isinstance(usage.parent, Class) and "Component" in usage.parent.bases: - graph.add_edge(component.name, usage.parent.name) - add_children(usage.parent) - - add_children(root_component) - return graph - -# Visualize component hierarchy -app = codebase.get_class("App") -component_tree = create_component_tree(app) -codebase.visualize(component_tree, root=app) -``` - -### Inheritance Graphs - -Visualize class inheritance relationships: - -```python -import networkx as nx - -G = nx.DiGraph() -base = codebase.get_class("BaseModel") - -def add_subclasses(cls): - for subclass in cls.subclasses: - G.add_edge(cls, subclass) - add_subclasses(subclass) - -add_subclasses(base) - -codebase.visualize(G, root=base) -``` - -### Module Dependencies - -Visualize dependencies between modules: - -```python -def create_module_graph(start_file: File): - G = nx.DiGraph() - - def add_imports(file): - for imp in file.imports: - if imp.resolved_symbol and imp.resolved_symbol.file: - graph.add_edge(file, imp.resolved_symbol.file) - add_imports(imp.resolved_symbol.file) - - add_imports(start_file) - return graph - -# Visualize module dependencies -main = codebase.get_file("main.py") -module_graph = create_module_graph(main) -codebase.visualize(module_graph, root=main) -``` - -### Function Modularity - -Visualize function groupings by modularity: - -```python -def create_modularity_graph(functions: list[Function]): - graph = nx.Graph() - - # Group functions by shared dependencies - for func in functions: - for dep in func.dependencies: - if isinstance(dep, Function): - weight = len(set(func.dependencies) & set(dep.dependencies)) - if weight > 0: - graph.add_edge(func.name, dep.name, weight=weight) - - return graph - -# Visualize function modularity -funcs = codebase.functions -modularity_graph = create_modularity_graph(funcs) -codebase.visualize(modularity_graph) -``` - -## Customizing Visualizations - -You can customize your visualizations using NetworkX's attributes while still preserving the smart node features: - -```python -def create_custom_graph(codebase): - graph = nx.DiGraph() - - # Add nodes with custom attributes while preserving source preview - for func in codebase.functions: - graph.add_node(func, - color='red' if func.is_public else 'blue', - shape='box' if func.is_async else 'oval' - ) - - # Add edges between actual function objects - for func in codebase.functions: - for call in func.call_sites: - if call.resolved_symbol: - graph.add_edge(func, call.resolved_symbol, - style='dashed' if call.is_conditional else 'solid', - weight=call.count - ) - - return graph -``` - -## Best Practices - -1. **Use Symbol Objects for Rich Features** - - ```python - # Better: Add symbol objects for rich previews - # This will include source code previews, syntax highlighting, type information, etc. - for func in api_funcs: - graph.add_node(func) - - # Basic: Just names, no extra features - for func in api_funcs: - graph.add_node(func.name) - ``` - -2. **Focus on Relevant Subgraphs** - - ```python - # Better: Visualize specific subsystem - api_funcs = [f for f in codebase.functions if "api" in f.filepath] - api_graph = create_call_graph(api_funcs) - codebase.visualize(api_graph) - - # Avoid: Visualizing entire codebase - full_graph = create_call_graph(codebase.functions) # Too complex - ``` - -3. **Use Meaningful Layouts** - - ```python - # Group related nodes together - graph.add_node(controller_class, cluster="api") - graph.add_node(service_class, cluster="db") - ``` - -4. **Add Visual Hints** - ```python - # Color code by type while preserving rich previews - for node in codebase.functions: - if "Controller" in node.name: - graph.add_node(node, color="red") - elif "Service" in node.name: - graph.add_node(node, color="blue") - ``` - -## Limitations - -- Large graphs may become difficult to read -- Complex relationships might need multiple views -- Some graph layouts may take time to compute -- Preview features only work when adding symbol objects directly - diff --git a/docs/_deprecated/building-with-codegen/codegen-with-wsl.mdx b/docs/_deprecated/building-with-codegen/codegen-with-wsl.mdx deleted file mode 100644 index 34563e386..000000000 --- a/docs/_deprecated/building-with-codegen/codegen-with-wsl.mdx +++ /dev/null @@ -1,76 +0,0 @@ ---- -title: "Installing with WSL" -sidebarTitle: "Installing with WSL" -iconType: "solid" ---- - -Although Codegen is not natively supported on Windows, we do provide a guide for installing Codegen through WSL. - - -**Windows Subsystem for Linux (WSL)** is a feature of Windows that allows you to run a Linux environment on your Windows machine. Learn more about WSL [here](https://learn.microsoft.com/en-us/windows/wsl/about). - - -## Getting Started - -This tutorial assumes you have a working WSL installation. If you don't have WSL installed, follow the [official Microsoft docs](https://learn.microsoft.com/en-us/windows/wsl/install). There are also plenty of guides and videos online. We also assume you have a basic understanding of the Linux command line. For this guide, we are also assuming an Ubuntu distribution. - -## WSL1 vs WSL2 - -When installing WSL, you have two options: **WSL1 and WSL2**. - -WSL2 is generally recommended for better performance and compatibility, **but if you primarily use Windows for development, WSL1 may be a better fit**. - - -**WSL1 and WSL2 handle filesystems differently with important implications for each.** - -- WSL1 runs on the **Windows filesystem** and directly interacts with the underlying NTFS filesystem. Therefore, it has much better performance for file operations on Windows files. However, it lacks full compatibility with Linux features like system calls and certain file permissions. - -- WSL2 runs on a **virtualized ext4 Linux filesystem**, with a full Linux kernel inside a lightweight VM. As such, WSL2 can only interact with files within the Linux filesystem by default. The Windows filesystem is mounted as a virtual disk through `/mnt/c`, but there is **significant overhead** to interacting with Windows files. (Sometimes up to 10x to 50x slower!) - -You can read more about the differences between WSL1 and WSL2 [here](https://learn.microsoft.com/en-us/windows/wsl/compare-versions). - - -## Installing Codegen - -Initial Codegen installation should be the same as the Linux instructions from the [installation guide](https://docs.codegen.com/introduction/installation). - -## Using Codegen with files from WSL - -Codegen should work the same way as it does on Linux. - -## Using Codegen with files from Windows - -Both WSL1 and WSL2 can interact with Windows files through the `/mnt/c` directory. For example, if you have a file at `C:\Users\username\Documents\file.txt`, you can access it at `/mnt/c/Users/username/Documents/file.txt`. Therefore, you can parse any repo by cd'ing into the repo in `/mnt/c` and using Codegen as intended. - - -There is a significant performance overhead to interacting with Windows files from WSL2. - - -## Integration with VSCode / Cursor / Windsurf / Other IDEs - -If you are using VSCode or any VSCode forks like Cursor or Windsurf, you can use the [WSL extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-wsl) to interact and develop with a Linux environment from Windows. This will have the best performance and compatibility with running Codegen on Windows. - -![](https://code.visualstudio.com/assets/docs/remote/wsl/architecture-wsl.png) - -To use WSL with VSCode: -- Start VSCode -- Press `F1`, select **WSL: Connect to WSL** for the default distro or **WSL: Connect to WSL using Distro** for a specific distro. -- Use the File menu to open your folder. - -You can read more about Developing in WSL [here](https://code.visualstudio.com/docs/remote/wsl). - - -If you plan on using Codegen's MCP (Model Context Protocol) or LSP (Language Server Protocol) features, running VSCode through WSL is highly recommended. - - -## Troubleshooting - -- **I have trouble connecting to MCP or LSP from VSCode**: Windows and WSL run on two different network environments. WSL does come with a compatibility layer called [NAT (Network Address Translation)](https://learn.microsoft.com/en-us/windows/wsl/networking#default-networking-mode-nat) as a translation layer between the two environments, but it can sometimes cause issues. On machines running Windows 11 22H2 and higher, try switching to [Mirrored mode networking](https://learn.microsoft.com/en-us/windows/wsl/networking#mirrored-mode-networking) to see if that fixes the issue. -- **WSL takes up too much memory after running Codegen**: This is a known issue with WSL. Memory does not get properly released after running a memory-intensive process like Codegen. Try killing the WSL process using `wsl --shutdown` to free up memory. ([GitHub Issue for WSL](https://github.com/microsoft/WSL/issues/4166)) -- **WSL hangs and pins the CPU at 100% when I try to run Codegen**: This could be because of WSL running out of memory. Try killing the WSL process using `wsl --shutdown` and then try running Codegen again. If that doesn't work, try [downloading more RAM](https://downloadmoreram.com/). - -For any additional issues, see the [troubleshooting guide](/introduction/installation#troubleshooting). - - -For more help, join our [community Slack](/introduction/community) or check the [FAQ](/introduction/faq). - diff --git a/docs/_deprecated/building-with-codegen/collections.mdx b/docs/_deprecated/building-with-codegen/collections.mdx deleted file mode 100644 index c49c21ea2..000000000 --- a/docs/_deprecated/building-with-codegen/collections.mdx +++ /dev/null @@ -1,100 +0,0 @@ ---- -title: "Collections" -sidebarTitle: "Collections" -icon: "layer-group" -iconType: "solid" ---- - -Codegen enables traversing and manipulating collections through the [List](/api-reference/core/List) and [Dict](/api-reference/core/Dict) classes. - -These APIs work consistently across Python and TypeScript while preserving formatting and structure. - -## Core Concepts - -The [List](/api-reference/core/List) and [Dict](/api-reference/core/Dict) classes provide a consistent interface for working with ordered sequences of elements. Key features include: - -- Standard sequence operations (indexing, length, iteration) -- Automatic formatting preservation -- Safe modification operations -- Language-agnostic behavior -- Comment and whitespace preservation - -Collections handle: - -- Proper indentation -- Delimiters (commas, newlines) -- Multi-line formatting -- Leading/trailing whitespace -- Nested structures - -## List Operations - -Lists in both Python and TypeScript can be manipulated using the same APIs: - -```python -# Basic operations -items_list = file.get_symbol("items").value # Get list value -first = items_list[0] # Access elements -length = len(items_list) # Get length -items_list[0] = "new" # Modify element -items_list.append("d") # Add to end -items_list.insert(1, "x") # Insert at position -del items_list[1] # Remove element - -# Iteration -for item in items_list: - print(item.source) - -# Bulk operations -items_list.clear() # Remove all elements -``` - -### Single vs Multi-line Lists - -Collections automatically preserve formatting: - -```python -# Source code: -items = [a, b, c] -config = [ - "debug", - "verbose", - "trace", -] - -# Manipulation code: -items_list = file.get_symbol("items").value -items_list.append("d") # Adds new element - -config_list = file.get_symbol("config").value -config_list.append("info") # Adds with formatting - -# Result: -items = [a, b, c, d] -config = [ - "debug", - "verbose", - "trace", - "info", -] -``` - -## Dictionary Operations - -Dictionaries provide a similar consistent interface: - -```python -# Basic operations -settings = file.get_symbol("settings").value # Get dict value -value = settings["key"] # Get value -settings["key"] = "value" # Set value -del settings["key"] # Remove key -has_key = "key" in settings # Check existence - -# Iteration -for key in settings: - print(f"{key}: {settings[key]}") - -# Bulk operations -settings.clear() # Remove all entries -``` diff --git a/docs/_deprecated/building-with-codegen/comments-and-docstrings.mdx b/docs/_deprecated/building-with-codegen/comments-and-docstrings.mdx deleted file mode 100644 index 26e4611a8..000000000 --- a/docs/_deprecated/building-with-codegen/comments-and-docstrings.mdx +++ /dev/null @@ -1,214 +0,0 @@ ---- -title: "Comments and Docstrings" -sidebarTitle: "Comments & Docstrings" -icon: "comment" -iconType: "solid" ---- - -Codegen enables reading, modifying, and manipulating comments and docstrings while preserving proper formatting. - -This guide describes proper usage of the following classes: - -- [Comment](/api-reference/core/Comment) - Represents a single comment. -- [CommentGroup](/api-reference/core/CommentGroup) - Represents a group of comments. - -## Accessing with Comments - -Comments can be accessed through any symbol or directly from code blocks. Each comment is represented by a `Comment` object that provides access to both the raw source and parsed text: - -```python -# Find all comments in a file -file = codebase.get_file("my_file.py") -for comment in file.code_block.comments: - print(comment.text) - -# Access comments associated with a symbol -symbol = file.get_symbol("my_function") -if symbol.comment: - print(symbol.comment.text) # Comment text without delimiters - print(symbol.comment.source) # Full comment including delimiters - -# Access inline comments -if symbol.inline_comment: - print(symbol.inline_comment.text) - -# Accessing all comments in a function -for comment in symbol.code_block.comments: - print(comment.text) -``` - -### Editing Comments - -Comments can be modified using the `edit_text()` method, which handles formatting and delimiters automatically: - -```python -# Edit a regular comment -symbol.comment.edit_text("Updated comment text") - -# Edit an inline comment -symbol.set_inline_comment("New inline comment") -``` - -### Comment Groups - -Multiple consecutive comments are automatically grouped into a `CommentGroup`, which can be edited as a single unit: - -```python -# Original comments: -# First line -# Second line -# Third line - -comment_group = symbol.comment -print(comment_group.text) # "First line\nSecond line\nThird line" - -# Edit the entire group at once -comment_group.edit_text("New first line\nNew second line") -``` - -## Working with Docstrings - -Docstrings are special comments that document functions, classes, and modules. Codegen provides similar APIs for working with docstrings: - -```python -function = file.get_symbol("my_function") -if function.docstring: - print(function.docstring.text) # Docstring content - print(function.docstring.source) # Full docstring with delimiters -``` - -### Adding Docstrings - -You can add docstrings to any symbol that supports them: - -```python -# Add a single-line docstring -function.set_docstring("A brief description") - -# Add a multi-line docstring -function.set_docstring(""" - A longer description that - spans multiple lines. - - Args: - param1: Description of first parameter -""") -``` - -### Language-Specific Formatting - -Codegen automatically handles language-specific docstring formatting: - -```python -# Python: Uses triple quotes -def my_function(): - """Docstring is formatted with triple quotes.""" - pass -``` - -```typescript -// TypeScript: Uses JSDoc style -function myFunction() { - /** Docstring is formatted as JSDoc */ -} -``` - -### Editing Docstrings - -Like comments, docstrings can be modified while preserving formatting: - -```python -# Edit a docstring -function.docstring.edit_text("Updated documentation") - -# Edit a multi-line docstring -function.docstring.edit_text(""" - Updated multi-line documentation - that preserves indentation and formatting. -""") -``` - -## Comment Operations - -Codegen provides utilities for working with comments at scale. For example, you can update or remove specific types of comments across your codebase: - -```python -# Example: Remove eslint disable comments for a specific rule -for file in codebase.files: - for comment in file.code_block.comments: - if "eslint-disable" in comment.source: - # Check if comment disables specific rule - if "@typescript-eslint/no-explicit-any" in comment.text: - comment.remove() -``` - - - When editing multi-line comments or docstrings, Codegen automatically handles - indentation and maintains the existing comment style. - - -## Special APIs and AI Integration - -### Google Style Docstrings - -Codegen supports Google-style docstrings and can handle their specific formatting, using the [CommentGroup.to_google_docstring(...)](/api-reference/core/CommentGroup#to-google-docstring) method. - -```python -# Edit while preserving Google style -symbol_a = file.get_symbol("SymbolA") -func_b = symbol_a.get_method("funcB") -func_b.docstring.to_google_docstring(func_b) -``` - -### Using AI for Documentation - -Codegen integrates with LLMs to help generate and improve documentation. You can use the [Codebase.ai(...)](/api-reference/core/Codebase#ai) method to: - -- Generate comprehensive docstrings -- Update existing documentation -- Convert between documentation styles -- Add parameter descriptions - -```python -# Generate a docstring using AI -function = codebase.get_function("my_function") - -new_docstring = codebase.ai( - "Generate a comprehensive docstring in Google style", - target=function - context={ - # provide additional context to the LLM - 'usages': function.usages, - 'dependencies': function.dependencies - } -) -function.set_docstring(new_docstring) -``` - - - Learn more about AI documentation capabilities in our [Documentation - Guide](/tutorials/creating-documentation) and [LLM Integration - Guide](/building-with-codegen/calling-out-to-llms). - - -### Documentation Coverage - -You can analyze and improve documentation coverage across your codebase: - -```python -# Count documented vs undocumented functions -total = 0 -documented = 0 -for function in codebase.functions: - total += 1 - if function.docstring: - documented += 1 - -coverage = (documented / total * 100) if total > 0 else 0 -print(f"Documentation coverage: {coverage:.1f}%") -``` - - - Check out the [Documentation Guide](/tutorials/creating-documentation) for - more advanced coverage analysis and bulk documentation generation. - diff --git a/docs/_deprecated/building-with-codegen/commit-and-reset.mdx b/docs/_deprecated/building-with-codegen/commit-and-reset.mdx deleted file mode 100644 index b0aae8309..000000000 --- a/docs/_deprecated/building-with-codegen/commit-and-reset.mdx +++ /dev/null @@ -1,63 +0,0 @@ ---- -title: "Commit and Reset" -sidebarTitle: "Commit and Reset" -icon: "arrows-rotate" -iconType: "solid" ---- - -Codegen requires you to explicitly commit changes by calling [codebase.commit()](/api-reference/core/Codebase#commit). - - - Keeping everything in memory enables fast, large-scale writes. See the [How it - Works](/introduction/how-it-works) guide to learn more. - - -You can manage your codebase's state with two core APIs: - -- [Codebase.commit()](/api-reference/core/Codebase#commit) - Commit changes to disk -- [Codebase.reset()](/api-reference/core/Codebase#reset) - Reset the `codebase` and filesystem to its initial state - -## Committing Changes - -When you make changes to your codebase through Codegen's APIs, they aren't immediately written to disk. You need to explicitly commit them with [codebase.commit()](/api-reference/core/Codebase#commit): - -```python -from codegen import Codebase - -codebase = Codebase("./") - -# Make some changes -file = codebase.get_file("src/app.py") -file.before("# 🌈 hello, world!") - -# Changes aren't on disk yet -codebase.commit() # Now they are! -``` - -This transaction-like behavior helps ensure your changes are atomic and consistent. - -## Resetting State - -The [codebase.reset()](/api-reference/core/Codebase#reset) method allows you to revert the codebase to its initial state: - -```python -# Make some changes -codebase.get_file("src/app.py").remove() -codebase.create_file("src/new_file.py", "x = 1") - -# Check the changes -assert codebase.get_file("src/app.py", optional=True) is None -assert codebase.get_file("src/new_file.py") is not None - -# Reset everything -codebase.reset() - -# Changes are reverted -assert codebase.get_file("src/app.py") is not None -assert codebase.get_file("src/new_file.py", optional=True) is None -``` - - - `reset()` reverts both the in-memory state and any uncommitted filesystem - changes. However, it preserves your codemod implementation in `.codegen/`. - diff --git a/docs/_deprecated/building-with-codegen/dependencies-and-usages.mdx b/docs/_deprecated/building-with-codegen/dependencies-and-usages.mdx deleted file mode 100644 index ab9bd3acd..000000000 --- a/docs/_deprecated/building-with-codegen/dependencies-and-usages.mdx +++ /dev/null @@ -1,260 +0,0 @@ ---- -title: "Dependencies and Usages" -sidebarTitle: "Dependencies and Usages" -icon: "share-nodes" -iconType: "solid" ---- - -Codegen pre-computes dependencies and usages for all symbols in the codebase, enabling constant-time queries for these relationships. - -## Overview - -Codegen provides two main ways to track relationships between symbols: - -- [.dependencies](/api-reference/core/Symbol#dependencies) / - What symbols does this symbol depend on? -- [.usages](/api-reference/core/Symbol#usages) / [.usages(...)](/api-reference/core/Symbol#usages) - Where is this symbol used? - -Dependencies and usages are inverses of each other. For example, given the following input code: - -```python -# Input code -from module import BaseClass - -class MyClass(BaseClass): - pass -``` - -The following assertions will hold in the Codegen API: - -```python -base = codebase.get_symbol("BaseClass") -my_class = codebase.get_symbol("MyClass") - -# MyClass depends on BaseClass -assert base in my_class.dependencies - -# BaseClass is used by MyClass -assert my_class in base.usages -``` - -If `A` depends on `B`, then `B` is used by `A`. This relationship is tracked in both directions, allowing you to navigate the codebase from either perspective. - -```mermaid - -flowchart LR - B(BaseClass) - - - - A(MyClass) - B ---| used by |A - A ---|depends on |B - - classDef default fill:#fff,stroke:#000,color:#000; -``` - -- `MyClass.dependencies` answers the question: *"which symbols in the codebase does MyClass depend on?"* - -- `BaseClass.usages` answers the question: *"which symbols in the codebase use BaseClass?"* - -## Usage Types - -Both APIs use the [UsageType](../api-reference/core/UsageType) enum to specify different kinds of relationships: - -```python -class UsageType(IntFlag): - DIRECT = auto() # Direct usage within the same file - CHAINED = auto() # Usage through attribute access (module.symbol) - INDIRECT = auto() # Usage through a non-aliased import - ALIASED = auto() # Usage through an aliased import -``` - -### DIRECT Usage - -A direct usage occurs when a symbol is used in the same file where it's defined, without going through any imports or attribute access. - -```python -# Define MyClass -class MyClass: - def __init__(self): - pass - -# Direct usage of MyClass in same file -class Child(MyClass): - pass -``` - -### CHAINED Usage - -A chained usage occurs when a symbol is accessed through module or object attribute access, using dot notation. - -```python -import module - -# Chained usage of ClassB through module -obj = module.ClassB() -# Chained usage of method through obj -result = obj.method() -``` - -### INDIRECT Usage - -An indirect usage happens when a symbol is used through a non-aliased import statement. - -```python -from module import BaseClass - -# Indirect usage of BaseClass through import -class MyClass(BaseClass): - pass -``` - -### ALIASED Usage - -An aliased usage occurs when a symbol is used through an import with an alias. - -```python -from module import BaseClass as AliasedBase - -# Aliased usage of BaseClass -class MyClass(AliasedBase): - pass -``` - -## Dependencies API - -The dependencies API lets you find what symbols a given symbol depends on. - -### Basic Usage - -```python -# Get all direct dependencies -deps = my_class.dependencies # Shorthand for dependencies(UsageType.DIRECT) - -# Get dependencies of specific types -direct_deps = my_class.dependencies(UsageType.DIRECT) -chained_deps = my_class.dependencies(UsageType.CHAINED) -indirect_deps = my_class.dependencies(UsageType.INDIRECT) -``` - -### Combining Usage Types - -You can combine usage types using the bitwise OR operator: - -```python -# Get both direct and indirect dependencies -deps = my_class.dependencies(UsageType.DIRECT | UsageType.INDIRECT) - -# Get all types of dependencies -deps = my_class.dependencies( - UsageType.DIRECT | UsageType.CHAINED | - UsageType.INDIRECT | UsageType.ALIASED -) -``` - -### Common Patterns - -1. Finding dead code (symbols with no usages): - -```python -# Check if a symbol is unused -def is_dead_code(symbol): - return not symbol.usages - -# Find all unused functions in a file -dead_functions = [f for f in file.functions if not f.usages] -``` - - - See [Deleting Dead Code](/tutorials/deleting-dead-code) to learn more about finding - unused code. - - -2. Finding all imports that a symbol uses: - -```python -# Get all imports a class depends on -class_imports = [dep for dep in my_class.dependencies if isinstance(dep, Import)] - -# Get all imports used by a function, including indirect ones -all_function_imports = [ - dep for dep in my_function.dependencies(UsageType.DIRECT | UsageType.INDIRECT) - if isinstance(dep, Import) -] -``` -## Traversing the Dependency Graph - -Sometimes you need to analyze not just direct dependencies, but the entire dependency graph up to a certain depth. The `dependencies` method allows you to traverse the dependency graph and collect all dependencies up to a specified depth level. - -### Basic Usage - -```python - -# Get only direct dependencies -deps = symbol.dependencies(max_depth=1) - -# Get deep dependencies (up to 5 levels) -deps = symbol.dependencies(max_depth=5) -``` - -The method returns a dictionary mapping each symbol to its list of direct dependencies. This makes it easy to analyze the dependency structure: - -```python -# Print the dependency tree -for sym, direct_deps in deps.items(): - print(f"{sym.name} depends on: {[d.name for d in direct_deps]}") -``` - -### Example: Analyzing Class Inheritance - -Here's an example of using `dependencies` to analyze a class inheritance chain: - -```python -class A: - def method_a(self): pass - -class B(A): - def method_b(self): - self.method_a() - -class C(B): - def method_c(self): - self.method_b() - -# Get the full inheritance chain -symbol = codebase.get_class("C") -deps = symbol.dependencies( - max_depth=3 -) - -# Will show: -# C depends on: [B] -# B depends on: [A] -# A depends on: [] -``` - -### Handling Cyclic Dependencies - -The method properly handles cyclic dependencies in the codebase: - -```python -class A: - def method_a(self): - return B() - -class B: - def method_b(self): - return A() - -# Get dependencies including cycles -symbol = codebase.get_class("A") -deps = symbol.dependencies() - -# Will show: -# A depends on: [B] -# B depends on: [A] -``` - - - The `max_depth` parameter helps prevent excessive recursion in large codebases or when there are cycles in the dependency graph. - diff --git a/docs/_deprecated/building-with-codegen/dot-codegen.mdx b/docs/_deprecated/building-with-codegen/dot-codegen.mdx deleted file mode 100644 index b4b493fde..000000000 --- a/docs/_deprecated/building-with-codegen/dot-codegen.mdx +++ /dev/null @@ -1,129 +0,0 @@ ---- -title: "The .codegen Directory" -sidebarTitle: ".codegen Directory" -icon: "folder" -iconType: "solid" ---- - -The `.codegen` directory contains your project's Codegen configuration, codemods, and supporting files. It's automatically created when you run `codegen init`. - -## Directory Structure - -```bash -.codegen/ -β”œβ”€β”€ .venv/ # Python virtual environment (gitignored) -β”œβ”€β”€ config.toml # Project configuration -β”œβ”€β”€ codemods/ # Your codemod implementations -β”œβ”€β”€ jupyter/ # Jupyter notebooks for exploration -└── codegen-system-prompt.txt # AI system prompt -``` - -## Initialization - -The directory is created and managed using the `codegen init` command: - -```bash -codegen init [--fetch-docs] [--repo-name NAME] [--organization-name ORG] -``` - - -The `--fetch-docs` flag downloads API documentation and examples specific to your project's programming language. - - -## Virtual Environment - -Codegen maintains its own virtual environment in `.codegen/.venv/` to ensure consistent package versions and isolation from your project's dependencies. This environment is: - -- Created using `uv` for fast, reliable package management -- Initialized with Python 3.13 -- Automatically managed by Codegen commands -- Used for running codemods and Jupyter notebooks -- Gitignored to avoid committing environment-specific files - -The environment is created during `codegen init` and used by commands like `codegen run` and `codegen notebook`. - -To debug codemods, you will need to set the python virtual environment in your IDE to `.codegen/.venv` - -### Configuration - -The `.env` file stores your project settings: - -```env -REPOSITORY_OWNER = "your-org" -REPOSITORY_PATH = "/root/git/your-repo" -REPOSITORY_LANGUAGE = "python" # or other supported language -``` - -This configuration is used by Codegen to provide language-specific features and proper repository context. - -## Git Integration - -Codegen automatically adds appropriate entries to your `.gitignore`: - -```gitignore -# Codegen -.codegen/.venv/ -.codegen/docs/ -.codegen/jupyter/ -.codegen/codegen-system-prompt.txt -``` - - -- While most directories are ignored, your codemods in `.codegen/codemods/` and `config.toml` are tracked in Git -- The virtual environment and Jupyter notebooks are gitignored to avoid environment-specific issues - - -## Working with Codemods - -The `codemods/` directory is where your transformation functions live. You can create new codemods using: - -```bash -codegen create my-codemod PATH [--description "what it does"] -``` - -This will: -1. Create a new file in `.codegen/codemods/` -2. Generate a system prompt in `.codegen/prompts/` (if using `--description`) -3. Set up the necessary imports and decorators - - -Use `codegen list` to see all codemods in your project. - - -## Jupyter Integration - -The `jupyter/` directory contains notebooks for interactive development: - -```python -from codegen import Codebase - -# Initialize codebase -codebase = Codebase('../../') - -# Print stats -print(f"πŸ“š Total Files: {len(codebase.files)}") -print(f"⚑ Total Functions: {len(codebase.functions)}") -``` - - -A default notebook is created during initialization to help you explore your codebase. - - -## Next Steps - -After initializing your `.codegen` directory: - -1. Create your first codemod: -```bash -codegen create my-codemod . -d "describe what you want to do" -``` - -2. Run it: -```bash -codegen run my-codemod --apply-local -``` - -3. Deploy it for team use: -```bash -codegen deploy my-codemod -``` diff --git a/docs/_deprecated/building-with-codegen/editables-and-behaviors.mdx b/docs/_deprecated/building-with-codegen/editables-and-behaviors.mdx deleted file mode 100644 index ba3ba0175..000000000 --- a/docs/_deprecated/building-with-codegen/editables-and-behaviors.mdx +++ /dev/null @@ -1,112 +0,0 @@ ---- -title: "Inheritable Behaviors" -sidebarTitle: "Inheritable Behaviors" -icon: "puzzle-piece" -iconType: "solid" ---- - -Codegen uses a set of core behaviors that can be inherited by code elements. These behaviors provide consistent APIs across different types of symbols. - -This guide explains the key behaviors and how to use them effectively. - -## Core Behaviors - -- [HasName](/api-reference/core/HasName): For elements with names (functions, classes, variables) -- [HasValue](/api-reference/core/HasValue): For elements with values (variables, parameters) -- [HasBlock](/api-reference/core/HasBlock): For elements containing code blocks (functions, classes) -- [Editable](/api-reference/core/Editable): For elements that can be safely modified ([learn more](/building-with-codegen/the-editable-api)) - -## Working with Names - -The [HasName](/api-reference/core/HasName) behavior provides APIs for working with named elements: - -```python -# Access the name -print(function.name) # Base name without namespace -print(function.full_name) # Full qualified name with namespace - -# Modify the name -function.set_name("new_name") # Changes just the name -function.rename("new_name") # Changes name and updates all usages - -# Get the underlying name node -name_node = function.get_name() -``` - -## Working with Values - -The [HasValue](/api-reference/core/HasValue) behavior provides APIs for elements that have values: - -```python -# Access the value -value = variable.value # Gets the value Expression node -print(value.source) # Gets the string content - -# Modify the value -variable.set_value("new_value") - -# Common patterns -if variable.value is not None: - print(f"{variable.name} = {variable.value.source}") -``` - -## Working with Code Blocks - -The [HasBlock](/api-reference/core/HasBlock) behavior provides APIs for elements containing code: - -```python -# Access the code block -block = function.code_block -print(len(block.statements)) # Number of statements - -# Work with decorators -for decorator in function.decorators: - print(f"@{decorator.name}") - -function.add_decorator("@deprecated") - -# Access docstrings -print(function.docstring) -function.set_docstring("New documentation") - -# Find function calls -for fcall in function.function_calls: - print(f"Calls {fcall.name}") -``` - -## Working with Attributes - -The [get_attribute](/api-reference/core/Class#get-attribute) method provides APIs for attribute access: - -```python -# Common patterns -class_attr = class_def.get_attribute("attribute_name") -if class_attr: - print(f"Class variable value: {class_attr.value.source}") -``` - - - Learn more about [working with Attributes - here](/building-with-codegen/class-api#class-attributes). - - -## Behavior Combinations - -Many code elements inherit multiple behaviors. For example, a function typically has: - -```python -# Functions combine multiple behaviors -function = codebase.get_function("process_data") - -# HasName behavior -print(function.name) -function.rename("process_input") - -# HasBlock behavior -print(len(function.code_block.statements)) -function.add_decorator("@timer") - -# Editable behavior -function.edit("def process_input():\n pass") -``` - diff --git a/docs/_deprecated/building-with-codegen/exports.mdx b/docs/_deprecated/building-with-codegen/exports.mdx deleted file mode 100644 index 3d2286f01..000000000 --- a/docs/_deprecated/building-with-codegen/exports.mdx +++ /dev/null @@ -1,209 +0,0 @@ ---- -title: "The Export API" -sidebarTitle: "Exports" -icon: "file-export" -iconType: "solid" ---- - -The [Export](/api-reference/core/Export) API provides tools for managing exports and module boundaries in TypeScript codebases. - -Exports are a TS-only language feature - -## Export Statements vs Exports - -Similar to imports, Codegen provides two levels of abstraction for working with exports: - -- [ExportStatement](/api-reference/core/ExportStatement) - Represents a complete export statement -- [Export](/api-reference/core/Export) - Represents individual exported symbols - -```typescript -// One ExportStatement containing multiple Export objects -export { foo, bar as default, type User }; -// Creates: -// - Export for 'foo' -// - Export for 'bar' as default -// - Export for 'User' as a type - -// Direct exports create one ExportStatement per export -export const value = 42; -export function process() {} -``` - -You can access these through your file's collections: - -```python -# Access all exports in the codebase -for export in codebase.exports: - ... - -# Access all export statements -for stmt in file.export_statements: - for exp in stmt.exports: - ... -``` - - -ExportStatement inherits from [Statement](/building-with-codegen/statements-and-code-blocks), providing operations like `remove()` and `insert_before()`. This is particularly useful when you want to manipulate the entire export declaration. - - -## Common Operations - -Here are common operations for working with exports: - -```python -# Add exports from source code -file.add_export_from_source("export { MyComponent };") -file.add_export_from_source("export type { MyType } from './types';") - -# Export existing symbols -component = file.get_function("MyComponent") -file.add_export(component) # export { MyComponent } -file.add_export(component, alias="default") # export { MyComponent as default } - -# Convert to type export -export = file.get_export("MyType") -export.make_type_export() - -# Remove exports -export = file.get_export("MyComponent") -export.remove() # Removes export but keeps the symbol - -# Remove multiple exports -for export in file.exports: - if not export.is_type_export(): - export.remove() - -# Update export properties -export.update( - name="NewName", - is_type=True, - is_default=False -) - -# Export from another file -other_file = codebase.get_file("./components.ts") -component = other_file.get_class("Button") -file.add_export(component, from_file=other_file) # export { Button } from './components'; - -# Analyze symbols being exported -for export in file.exports: - if isinstance(export.exported_symbol, ExternalModule): - print('Exporting ExternalModule') - else: - ... -``` - - -When adding exports, you can: -- Add from source code with `add_export_from_source()` -- Export existing symbols with `add_export()` -- Re-export from other files by specifying `from_file` - -The export will automatically handle adding any required imports. - - -## Export Types - -Codegen supports several types of exports: - -```typescript -// Direct exports -export const value = 42; // Value export -export function myFunction() {} // Function export -export class MyClass {} // Class export -export type MyType = string; // Type export -export interface MyInterface {} // Interface export -export enum MyEnum {} // Enum export - -// Re-exports -export { foo, bar } from './other-file'; // Named re-exports -export type { Type } from './other-file'; // Type re-exports -export * from './other-file'; // Wildcard re-exports -export * as utils from './other-file'; // Namespace re-exports - -// Aliased exports -export { foo as foop }; // Basic alias -export { foo as default }; // Default export alias -export { bar as baz } from './other-file'; // Re-export with alias -``` - -## Identifying Export Types - -The Export API provides methods to identify and filter exports: -- [.is_type_export()](/api-reference/typescript/TSExport#is-type-export) -- [.is_default_export()](/api-reference/typescript/TSExport#is-default-export) -- [.is_wildcard_export()](/api-reference/typescript/TSExport#is-wildcard-export) - - -```python -# Check export types -for exp in file.exports: - if exp.is_type_export(): - print(f"Type export: {exp.name}") - elif exp.is_default_export(): - print(f"Default export: {exp.name}") - elif exp.is_wildcard_export(): - print(f"Wildcard export from: {exp.from_file.filepath}") -``` - -## Export Resolution - -You can trace exports to their original symbols: - -```python -for exp in file.exports: - if exp.is_reexport(): - # Get original and current symbols - current = exp.exported_symbol - original = exp.resolved_symbol - - print(f"Re-exporting {original.name} from {exp.from_file.filepath}") - print(f"Through: {' -> '.join(e.file.filepath for e in exp.export_chain)}") -``` - -## Managing Re-exports - -You can manage re-exports with the [TSExport.is_reexport()](/api-reference/typescript/TSExport#is-reexport) API: - -```python -# Create public API -index_file = codebase.get_file("index.ts") - -# Re-export from internal files -for internal_file in codebase.files: - if internal_file.name != "index": - for symbol in internal_file.symbols: - if symbol.is_public: - index_file.add_export( - symbol, - from_file=internal_file - ) - -# Convert default to named exports -for exp in file.exports: - if exp.is_default_export(): - exp.make_named_export() - -# Consolidate re-exports -from collections import defaultdict - -file_exports = defaultdict(list) -for exp in file.exports: - if exp.is_reexport(): - file_exports[exp.from_file].append(exp) - -for from_file, exports in file_exports.items(): - if len(exports) > 1: - # Create consolidated re-export - names = [exp.name for exp in exports] - file.add_export_from_source( - f"export {{ {', '.join(names)} }} from '{from_file.filepath}'" - ) - # Remove individual exports - for exp in exports: - exp.remove() -``` - - -When managing exports, consider the impact on your module's public API. Not all symbols that can be exported should be exported. - \ No newline at end of file diff --git a/docs/_deprecated/building-with-codegen/external-modules.mdx b/docs/_deprecated/building-with-codegen/external-modules.mdx deleted file mode 100644 index a3f0ce2ae..000000000 --- a/docs/_deprecated/building-with-codegen/external-modules.mdx +++ /dev/null @@ -1,119 +0,0 @@ ---- -title: "External Modules" -sidebarTitle: "External Modules" -icon: "box-archive" -iconType: "solid" ---- - -Codegen provides a way to handle imports from external packages and modules through the [ExternalModule](/api-reference/core/ExternalModule) class. - -```python -# Python examples -import datetime -from requests import get - -# TypeScript/JavaScript examples -import React from 'react' -import { useState, useEffect } from 'react' -import type { ReactNode } from 'react' -import axios from 'axios' -``` - -## What are External Modules? - -When writing code, you often import from packages that aren't part of your project - like `datetime` and `requests` in Python, or `react` and `axios` in TypeScript. In Codegen, these are represented as [ExternalModule](/api-reference/core/ExternalModule) instances. - -```python -for imp in codebase.imports: - if isinstance(imp.symbol, ExternalModule): - print(f"Importing from external package: {imp.resolved_symbol.source}") -``` - - - External modules are read-only - you can analyze them but can't modify their - implementation. This makes sense since they live in your project's - dependencies! - - -## Working with External Modules - -The most common use case is handling external modules differently from your project's code: - -### Identifying Function Calls as External Modules - -For [FunctionCall](/api-reference/core/FunctionCall) instances, you can check if the function definition is an [ExternalModule](/api-reference/core/ExternalModule) via the [FunctionCall.function_definition](/api-reference/core/FunctionCall#function-definition) property: - -```python -for fcall in file.function_calls: - definition = fcall.function_definition - if isinstance(definition, ExternalModule): - # Skip external functions - print(f'External function: {definition.name}') - else: - # Process local functions... - print(f'Local function: {definition.name}') -``` - -### Import Resolution - -Similarly, when working with imports, you can determine if they resolve to external modules by checking the [Import.resolved_symbol](/api-reference/core/Import#resolved-symbol) property: - -```python -for imp in file.imports: - resolved = imp.resolved_symbol - if isinstance(resolved, ExternalModule): - print(f"Import from external package: from {imp.module} import {imp.name}") -``` - - - Use `isinstance(symbol, ExternalModule)` to reliably identify external - modules. This works better than checking names or paths since it handles all - edge cases. - - -## Properties and Methods - -External modules provide several useful properties: - -```python -# Get the module name -module_name = external_module.name # e.g. "datetime" or "useState" - -# Check if it's from node_modules (TypeScript/JavaScript) -if external_module.filepath == "": - print("This is an external package from node_modules") -``` - -## Common Patterns - -Here are some typical ways you might work with external modules: - -### Skip External Processing: - -When modifying function calls or imports, skip external modules since they can't be changed: - -```python -# Example from a codemod that adds type hints -def add_type_hints(function): - if isinstance(function.definition, ExternalModule): - return # Can't add type hints to external modules like React.FC - # Add type hints to local functions... -``` - -### Analyze Dependencies - -Track which external packages your code uses: - -```python -# Find all external package dependencies -external_deps = set() -for imp in codebase.imports: - if isinstance(imp.resolved_symbol, ExternalModule): - external_deps.add(imp.resolved_symbol.source) - # Will find things like 'react', 'lodash', 'datetime', etc. -``` - - - When working with imports, always handle external modules as a special case. - This ensures your codemods work correctly with both local and external code. - diff --git a/docs/_deprecated/building-with-codegen/files-and-directories.mdx b/docs/_deprecated/building-with-codegen/files-and-directories.mdx deleted file mode 100644 index b15d6e3d4..000000000 --- a/docs/_deprecated/building-with-codegen/files-and-directories.mdx +++ /dev/null @@ -1,312 +0,0 @@ ---- -title: "Files and Directories" -sidebarTitle: "Files & Directories" -icon: "folder-tree" -iconType: "solid" ---- - -Codegen provides three primary abstractions for working with your codebase's file structure: - -- [File](/api-reference/core/File) - Represents a file in the codebase (e.g. README.md, package.json, etc.) -- [SourceFile](/api-reference/core/SourceFile) - Represents a source code file (e.g. Python, TypeScript, React, etc.) -- [Directory](/api-reference/core/Directory) - Represents a directory in the codebase - - - [SourceFile](/api-reference/core/SourceFile) is a subclass of [File](/api-reference/core/File) that provides additional functionality for source code files. - - - -## Accessing Files and Directories - -You typically access files from the [codebase](/api-reference/core/Codebase) object with two APIs: - -- [codebase.get_file(...)](/api-reference/core/Codebase#get-file) - Get a file by its path -- [codebase.files](/api-reference/core/Codebase#files) - Enables iteration over all files in the codebase - -```python -# Get a file from the codebase -file = codebase.get_file("path/to/file.py") - -# Iterate over all files in the codebase -for file in codebase.files: - pass - -# Check if a file exists -exists = codebase.has_file("path/to/file.py") - -``` - - -These APIs are similar for [Directory](/api-reference/core/Directory), which provides similar methods for accessing files and subdirectories. - -```python -# Get a directory -dir = codebase.get_directory("path/to/dir") - -# Iterate over all files in the directory -for file in dir.files: - pass - -# Get the directory containing a file: -dir = file.directory - -# Check if a directory exists -exists = codebase.has_directory("path/to/dir") -``` - -## Differences between SourceFile and File - -- [File](/api-reference/core/File) - a general purpose class that represents any file in the codebase including non-code files like README.md, .env, .json, image files, etc. -- [SourceFile](/api-reference/core/SourceFile) - a subclass of [File](/api-reference/core/File) that provides additional functionality for source code files written in languages supported by the [codegen-sdk](/introduction/overview) (Python, TypeScript, JavaScript, React). - -The majority of intended use cases involve using exclusively [SourceFile](/api-reference/core/SourceFile) objects as these contain code that can be parsed and manipulated by the [codegen-sdk](/introduction/overview). However, there may be cases where it will be necessary to work with non-code files. In these cases, the [File](/api-reference/core/File) class can be used. - -By default, the `codebase.files` property will only return [SourceFile](/api-reference/core/SourceFile) objects. To include non-code files the `extensions='*'` argument must be used. - -```python -# Get all source files in the codebase -source_files = codebase.files - -# Get all files in the codebase (including non-code files) -all_files = codebase.files(extensions="*") -``` - - -When getting a file with `codebase.get_file`, files ending in `.py, .js, .ts, .jsx, .tsx` are returned as [SourceFile](/api-reference/core/SourceFile) objects while other files are returned as [File](/api-reference/core/File) objects. - -Furthermore, you can use the `isinstance` function to check if a file is a [SourceFile](/api-reference/core/SourceFile): - -```python -py_file = codebase.get_file("path/to/file.py") -if isinstance(py_file, SourceFile): - print(f"File {py_file.filepath} is a source file") - -# prints: `File path/to/file.py is a source file` - -mdx_file = codebase.get_file("path/to/file.mdx") -if not isinstance(mdx_file, SourceFile): - print(f"File {mdx_file.filepath} is a non-code file") - -# prints: `File path/to/file.mdx is a non-code file` -``` - - - Currently, the codebase object can only parse source code files of one language at a time. This means that if you want to work with both Python and TypeScript files, you will need to create two separate codebase objects. - - -## Accessing Code - -[SourceFiles](/api-reference/core/SourceFile) and [Directories](/api-reference/core/Directory) provide several APIs for accessing and iterating over their code. - -See, for example: - -- `.functions` ([SourceFile](/api-reference/core/SourceFile#functions) / [Directory](/api-reference/core/Directory#functions)) - All [Functions](/api-reference/core/Function) in the file/directory -- `.classes` ([SourceFile](/api-reference/core/SourceFile#classes) / [Directory](/api-reference/core/Directory#classes)) - All [Classes](/api-reference/core/Class) in the file/directory -- `.imports` ([SourceFile](/api-reference/core/SourceFile#imports) / [Directory](/api-reference/core/Directory#imports)) - All [Imports](/api-reference/core/Import) in the file/directory -- `.get_function(...)` ([SourceFile](/api-reference/core/SourceFile#get-function) / [Directory](/api-reference/core/Directory#get-function)) - Get a specific function by name -- `.get_class(...)` ([SourceFile](/api-reference/core/SourceFile#get-class) / [Directory](/api-reference/core/Directory#get-class)) - Get a specific class by name -- `.get_global_var(...)` ([SourceFile](/api-reference/core/SourceFile#get-global-var) / [Directory](/api-reference/core/Directory#get-global-var)) - Get a specific global variable by name - - -```python -# Get all functions in a file -for function in file.functions: - print(f"Found function: {function.name}") - print(f"Parameters: {[p.name for p in function.parameters]}") - print(f"Return type: {function.return_type}") - -# Get all classes -for cls in file.classes: - print(f"Found class: {cls.name}") - print(f"Methods: {[m.name for m in cls.methods]}") - print(f"Attributes: {[a.name for a in cls.attributes]}") - -# Get imports (can also do `file.import_statements`) -for imp in file.imports: - print(f"Import from: {imp.module}") - print(f"Imported symbol: {[s.name for s in imp.imported_symbol]}") - -# Get specific symbols -main_function = file.get_function("main") -user_class = file.get_class("User") -config = file.get_global_var("CONFIG") - -# Access code blocks -if main_function: - for statement in main_function.code_block.statements: - print(f"Statement type: {statement.statement_type}") - -# Get local variables in a function -if main_function: - local_vars = main_function.code_block.get_local_var_assignments() - for var in local_vars: - print(f"Local var: {var.name} = {var.value}") -``` - -## Working with Non-Code Files (README, JSON, etc.) - -By default, Codegen focuses on source code files (Python, TypeScript, etc). However, you can access all files in your codebase, including documentation, configuration, and other non-code [files](/api-reference/core/File) like README.md, package.json, or .env: - -```python -# Get all files in the codebase (including README, docs, config files) -files = codebase.files(extensions="*") - -# Print files that are not source code (documentation, config, etc) -for file in files: - if not file.filepath.endswith(('.py', '.ts', '.js')): - print(f"πŸ“„ Non-code file: {file.filepath}") -``` - -You can also filter for specific file types: - -```python -# Get only markdown documentation files -docs = codebase.files(extensions=[".md", ".mdx"]) - -# Get configuration files -config_files = codebase.files(extensions=[".json", ".yaml", ".toml"]) -``` - -These APIs are similar for [Directory](/api-reference/core/Directory), which provides similar methods for accessing files and subdirectories. - -## Raw Content and Metadata - -```python -# Grab raw file string content -content = file.content # For text files -print('Length:', len(content)) -print('# of functions:', len(file.functions)) - -# Access file metadata -name = file.name # Base name without extension -extension = file.extension # File extension with dot -filepath = file.filepath # Full relative path -dir = file.directory # Parent directory - -# Access directory metadata -name = dir.name # Base name without extension -path = dir.path # Full relative path from repository root -parent = dir.parent # Parent directory -``` - -## Editing Files Directly - -Files themselves are [Editable](/api-reference/core/Editable.mdx) objects, just like Functions and Classes. - - - Learn more about the [Editable API](/building-with-codegen/the-editable-api). - - -This means they expose many useful operations, including: - -- [File.search](/api-reference/core/File#search) - Search for all functions named "main" -- [File.edit](/api-reference/core/File#edit) - Edit the file -- [File.replace](/api-reference/core/File#replace) - Replace all instances of a string with another string -- [File.insert_before](/api-reference/core/File#insert-before) - Insert text before a specific string -- [File.insert_after](/api-reference/core/File#insert-after) - Insert text after a specific string -- [File.remove](/api-reference/core/File#remove) - Remove a specific string - -```python -# Get a file -file = codebase.get_file("path/to/file.py") - -# Replace all instances of a string -file.replace("name", "new_name") -file.replace("name", "new_name", include_comments=False) # Don't edit comments - -# Replace entire text of the file -file.edit('hello, world!') - -# Get + delete all instances of a string -for editable in file.search("foo"): - editable.remove() - -# Insert text at the top of the file -file.insert_before("def main():\npass") -# ... or at the bottom -file.insert_after("def end():\npass") - -# Delete the file -file.remove() -``` - -You can frequently do bulk modifictions via the [.edit(...)](/api-reference/core/Editable#edit) method or [.replace(...)](/api-reference/core/File#replace) method. - - - Most useful operations will have bespoke APIs that handle edge cases, update - references, etc. - - -## Moving and Renaming Files - -Files can be manipulated through methods like [File.update_filepath()](/api-reference/core/File#update-filepath), [File.rename()](/api-reference/core/File#rename), and [File.remove()](/api-reference/core/File#remove): - -```python -# Move/rename a file -file.update_filepath("/path/to/foo.py") # Move to new location -file.rename("bar") # Rename preserving extension, e.g. `bar.py` - -# Remove a file (potentially destructive) -file.remove() - -# Move all tests to a tests directory -for file in codebase.files: - if 'test_' in file.name: - # This will handle updating imports and other references - file.update_filepath('tests/' + file.filepath.replace("test_", "")) -``` - - - Removing files is a potentially breaking operation. Only remove files if they - have no external usages. - - -## Directories - -[Directories](/api-reference/core/Directory) expose a similar API to the [File](/api-reference/core/File.mdx) class, with the addition of the `subdirectories` property. - -```python -# Get a directory -dir = codebase.get_directory("path/to/dir") - -# Iterate over all directories in the codebase -for directory in codebase.directories: - print(f"Found directory: {directory.path}") - -# Check directory existence -exists = codebase.has_directory("path/to/dir") - -# Access metadata -name = dir.name # Directory name -path = dir.path # Full path -parent = dir.parent # Parent directory - -# Get specific items -file = dir.get_file("file.py") -subdir = dir.get_subdirectory("subdir") - -# Get all ancestor subdirectories -subdirs = dir.subdirectories - -# Get the parent directory -parent_dir = dir.parent - -# Find all child directories -for subdir in dir.subdirectories: - if dir.parent == subdir: - print(f"Found child subdirectory: {subdir.path}") - -# Move to new location -dir.update_filepath("new/path") - -# Rename directory in place -dir.rename("new_name") - -# Remove a directory and all contents (potentially destructive) -dir.remove() -``` - - - Removing directories is a potentially destructive operation. Only remove - directories if they have no external usages. - diff --git a/docs/_deprecated/building-with-codegen/flagging-symbols.mdx b/docs/_deprecated/building-with-codegen/flagging-symbols.mdx deleted file mode 100644 index 690addc80..000000000 --- a/docs/_deprecated/building-with-codegen/flagging-symbols.mdx +++ /dev/null @@ -1,67 +0,0 @@ ---- -title: "Flagging Symbols" -description: "Learn how to use symbol flags for debugging, tracking changes, and marking code for review" -icon: "flag" -iconType: "solid" ---- - -# Flagging Symbols - -Symbol flags are a powerful feature in Codegen that allow you to mark and track specific code elements during development, debugging, or code review processes. Flags can be used to visually highlight code in the editor and can also integrate with various messaging systems. - -## Basic Usage - -The simplest way to flag a symbol is to call the `flag()` method on any symbol: - -```python -# Flag a function -function.flag(message="This function needs optimization") - -# Flag a class -my_class.flag(message="Consider breaking this into smaller classes") - -# Flag a variable -variable.flag(message="Type hints needed here") -``` - -When you flag a symbol, two things happen: -1. A visual flag emoji (🚩) is added as an inline comment -2. A `CodeFlag` object is created to track the flag in the system - - -## Language-Specific Behavior - -The flag system adapts automatically to the programming language being used: - -```python -# Python -# Results in: def my_function(): # 🚩 Review needed -python_function.flag(message="Review needed") - -# TypeScript -# Results in: function myFunction() { // 🚩 Review needed -typescript_function.flag(message="Review needed") -``` - - -## Example: Code Analysis - -Here's an example of using flags during code analysis: - -```python -def analyze_codebase(codebase): - for function in codebase.functions: - # Check documentation - if not function.docstring: - function.flag( - message="Missing docstring", - ) - - # Check error handling - if function.is_async and not function.has_try_catch: - function.flag( - message="Async function missing error handling", - ) -``` - -This feature is particularly useful when building, and iterating on the symbols that you are trying to modify. \ No newline at end of file diff --git a/docs/_deprecated/building-with-codegen/function-calls-and-callsites.mdx b/docs/_deprecated/building-with-codegen/function-calls-and-callsites.mdx deleted file mode 100644 index 8066692aa..000000000 --- a/docs/_deprecated/building-with-codegen/function-calls-and-callsites.mdx +++ /dev/null @@ -1,243 +0,0 @@ ---- -title: "Function Calls and Call Sites" -sidebarTitle: "Function Calls" -icon: "function" -iconType: "solid" ---- - -Codegen provides comprehensive APIs for working with function calls through several key classes: - -- [FunctionCall](../api-reference/core/FunctionCall) - Represents a function invocation -- [Argument](../api-reference/core/Argument) - Represents arguments passed to a function -- [Parameter](../api-reference/core/Parameter) - Represents parameters in a function definition - - - See [Migrating APIs](/tutorials/migrating-apis) for relevant tutorials and - applications. - - -## Navigating Function Calls - -Codegen provides two main ways to navigate function calls: - -1. From a function to its call sites using [call_sites](../api-reference/core/Function#call-sites) -2. From a function to the calls it makes (within it's [CodeBlock](../api-reference/core/CodeBlock)) using [function_calls](../api-reference/core/Function#function-calls) - -Here's how to analyze function usage patterns: - -```python -# Find the most called function -most_called = max(codebase.functions, key=lambda f: len(f.call_sites)) -print(f"\nMost called function: {most_called.name}") -print(f"Called {len(most_called.call_sites)} times from:") -for call in most_called.call_sites: - print(f" - {call.parent_function.name} at line {call.start_point[0]}") - -# Find function that makes the most calls -most_calls = max(codebase.functions, key=lambda f: len(f.function_calls)) -print(f"\nFunction making most calls: {most_calls.name}") -print(f"Makes {len(most_calls.function_calls)} calls to:") -for call in most_calls.function_calls: - print(f" - {call.name}") - -# Find functions with no callers (potential dead code) -unused = [f for f in codebase.functions if len(f.call_sites) == 0] -print(f"\nUnused functions:") -for func in unused: - print(f" - {func.name} in {func.filepath}") - -# Find recursive functions -recursive = [f for f in codebase.functions - if any(call.name == f.name for call in f.function_calls)] -print(f"\nRecursive functions:") -for func in recursive: - print(f" - {func.name}") -``` - -This navigation allows you to: - -- Find heavily used functions -- Analyze call patterns -- Map dependencies between functions - -## Arguments and Parameters - -The [Argument](../api-reference/core/Argument) class represents values passed to a function, while [Parameter](../api-reference/core/Parameter) represents the receiving variables in the function definition: - -Consider the following code: - -```python -# Source code: -def process_data(input_data: str, debug: bool = False): - pass - -process_data("test", debug=True) -``` - -You can access and modify the arguments and parameters of the function call with APIs detailed below. - -### Finding Arguments - -The primary APIs for finding arguments are: - -- [FunctionCall.args](/api-reference/core/FunctionCall#args) -- [FunctionCall.get_arg_by_parameter_name(...)](/api-reference/core/FunctionCall#get-arg-by-parameter-name) -- [FunctionCall.get_arg_by_index(...)](/api-reference/core/FunctionCall#get-arg-by-index) - -```python -# Get the function call -call = file.function_calls[0] - -# Working with arguments -for arg in call.args: - print(f"Arg {arg.index}: {arg.value}") # Access argument value - print(f"Is named: {arg.is_named}") # Check if it's a kwarg - print(f"Name: {arg.name}") # For kwargs, e.g. "debug" - - # Get corresponding parameter - if param := arg.parameter: - print(f"Parameter type: {param.type}") - print(f"Is optional: {param.is_optional}") - print(f"Has default: {param.default}") - -# Finding specific arguments -debug_arg = call.get_arg_by_parameter_name("debug") -first_arg = call.get_arg_by_index(0) -``` - -### Modifying Arguments - -There are two ways to modify function call arguments: - -1. Using [FunctionCall.set_kwarg(...)](/api-reference/core/FunctionCall#set-kwarg) to add or modify keyword arguments: - -```python -# Modifying keyword arguments -call.set_kwarg("debug", "False") # Modifies existing kwarg -call.set_kwarg("new_param", "value", create_on_missing=True) # Adds new kwarg -call.set_kwarg("input_data", "'new_value'", override_existing=True) # Converts positional to kwarg -``` - -2. Using [FuncionCall.args.append(...)](/api-reference/core/FunctionCall#args) to add new arguments: - - [FunctionCall.args](/api-reference/core/FunctionCall#args) is a - [Collection](/building-with-codegen/collections) of - [Argument](/api-reference/core/Argument) objects, so it supports - [.append(...)](/api-reference/core/List#append), - [.insert(...)](/api-reference/core/List#insert) and other collection - methods. - - -```python -# Adding new arguments -call.args.append('cloud="aws"') # Add a new keyword argument -call.args.append('"value"') # Add a new positional argument - -# Real-world example: Adding arguments to a decorator -@app.function(image=runner_image) -def my_func(): - pass - -# Add cloud and region if not present -if "cloud=" not in decorator.call.source: - decorator.call.args.append('cloud="aws"') -if "region=" not in decorator.call.source: - decorator.call.args.append('region="us-east-1"') -``` - -The `set_kwarg` method provides intelligent argument manipulation: - -- If the argument exists and is positional, it converts it to a keyword argument -- If the argument exists and is already a keyword, it updates its value (if override_existing=True) -- If the argument doesn't exist, it creates it (if create_on_missing=True) -- When creating new arguments, it intelligently places them based on parameter order - -Arguments and parameters support safe edit operations like so: - -```python -# Modifying arguments -debug_arg.edit("False") # Change argument value -first_arg.add_keyword("input_data") # Convert to named argument - -# modifying parameters -param = codebase.get_function('process_data').get_parameter('debug') -param.rename('_debug') # updates all call-sites -param.set_type_annotation('bool') -``` - -## Finding Function Definitions - -Every [FunctionCall](../api-reference/core/FunctionCall) can navigate to its definition through [function_definition](../api-reference/core/FunctionCall#function-definition) and [function_definitions](../api-reference/core/FunctionCall#function-definitions): - -```python -function_call = codebase.files[0].function_calls[0] -function_definition = function_call.function_definition -print(f"Definition found in: {function_definition.filepath}") -``` - -## Finding Parent (Containing) Functions - -FunctionCalls can access the function that invokes it via [parent_function](../api-reference/core/FunctionCall#parent-function). - -For example, given the following code: - -```python -# Source code: -def outer(): - def inner(): - helper() - inner() -``` - -You can find the parent function of the helper call: - -```python -# Manipulation code: -# Find the helper() call -helper_call = file.get_function("outer").function_calls[1] - -# Get containing function -parent = helper_call.parent_function -print(f"Call is inside: {parent.name}") # 'inner' - -# Get the full call hierarchy -outer = parent.parent_function -print(f"Which is inside: {outer.name}") # 'outer' -``` - -## Method Chaining - -Codegen enables working with chained method calls through [predecessor](../api-reference/core/FunctionCall#predecessor) and related properties: - -For example, for the following database query: - -```python -# Source code: -query.select(Table) - .where(id=1) - .order_by("name") - .limit(10) -``` - -You can access the chain of calls: - -```python -# Manipulation code: -# Get the `limit` call in the chain -limit_call = next(f for f in file.function.function_calls if f.name == "limit", None) - -# Navigate backwards through the chain -order_by = limit_call.predecessor -where = order_by.predecessor -select = where.predecessor - -# Get the full chain at once -chain = limit_call.call_chain # [select, where, order_by, limit] - -# Access the root object -base = limit_call.base # Returns the 'query' object - -# Check call relationships -print(f"After {order_by.name}: {limit_call.name}") -print(f"Before {where.name}: {select.name}") -``` diff --git a/docs/_deprecated/building-with-codegen/function-decorator.mdx b/docs/_deprecated/building-with-codegen/function-decorator.mdx deleted file mode 100644 index cbf95d18b..000000000 --- a/docs/_deprecated/building-with-codegen/function-decorator.mdx +++ /dev/null @@ -1,52 +0,0 @@ ---- -title: Function Decorator -sidebarTitle: "@codegen.function" -icon: "at" -iconType: "solid" ---- - -# Function Decorator - -The `function` decorator is used to define codegen functions within your application. It allows you to specify a name for the function that will be ran making it easier to run specific codemods - -## Usage - -To use the `function` decorator, simply annotate your function with `@codegen.function` and provide a name as an argument. - -### Example - -```python -@codegen.function('my-function') -def run(codebase): - pass -``` - -In this example, the function `run` is decorated with `@codegen.function` and given the name `'my-function'`. This name will be used when the function is ran. - -## Parameters - -- `name` (str): The name of the function to be used when ran. - -## Description - -The `function` decorator is part of the codegen SDK CLI and is used to mark functions that are intended to be ran as part of a code generation process. It ensures that the function is properly registered and can be invoked with the specified name. - - -## CLI Examples - -### Running a Function - -To run a deployed function using the CLI, use the following command: - -```bash -codegen run my-function -``` - -This command runs the function named `my-function`. - -## See Also - -- [Codebase Visualization](./codebase-visualization.mdx): For visualizing codebases in your application. -- [CLI Init Command](../cli/init.mdx): For initializing projects or environments related to the function decorator. -- [CLI Create Command](../cli/create.mdx): For creating new functions or projects using the CLI. -- [CLI Run Command](../cli/run.mdx): For running code or scripts using the CLI. diff --git a/docs/_deprecated/building-with-codegen/git-operations.mdx b/docs/_deprecated/building-with-codegen/git-operations.mdx deleted file mode 100644 index 0c7daa70a..000000000 --- a/docs/_deprecated/building-with-codegen/git-operations.mdx +++ /dev/null @@ -1,72 +0,0 @@ ---- -title: "Git Operations" -sidebarTitle: "Git Operations" -icon: "code-branch" ---- - -Many workflows require Git operations. Codegen provides a high-level API for common Git operations through the [Codebase](/api-reference/core/Codebase) class, including: - -- [Codebase.git_commit(...)](/api-reference/core/Codebase#git_commit) -- [Codebase.checkout(...)](/api-reference/core/Codebase#checkout) - -## Committing Changes to Git - -You can commit changes to Git using the [Codebase.git_commit(...)](/api-reference/core/Codebase#git_commit): - -```python -# Make some changes and call `commit()` to sync them to disk -codebase.functions[0].rename('foo') -codebase.commit() - -# Commit all staged changes to git with a message -commit = codebase.git_commit("feat: update function signatures") - -# You can also verify the commit (runs pre-commit hooks) -commit = codebase.git_commit("feat: update signatures", verify=True) - -# The method returns the commit object if changes were committed, None otherwise -if commit: - print(f"Created commit: {commit.hexsha}") -``` - - - `git_commit` will only commit changes that have been synced to the filesystem - by calling [Codebase.commit()](/api-reference/core/Codebase#commit). See - [Commit and Reset](/building-with-codegen/commit-and-reset) for more - details. - - -## Checking Current Git State - -Codegen provides properties to check the current Git state: - -```python -# Get the default branch (e.g. 'main' or 'master') -default = codebase.default_branch -print(f"Default branch: {default}") - -# Get the current commit -current = codebase.current_commit -if current: - print(f"Current commit: {current.hexsha}") -``` - -## Checking Out Branches and Commits - -The [Codebase.checkout(...)](/api-reference/core/Codebase#checkout) method allows you to switch between branches and commits. - -This will automatically re-parse the codebase to reflect the new state. - -```python -# Checkout a branch -result = codebase.checkout(branch="feature/new-api") - -# Create a new branch if it doesn't exist -result = codebase.checkout(branch="feature/new-api", create_if_missing=True) - -# Checkout a specific commit -result = codebase.checkout(commit="abc123") - -# Checkout and pull from remote -result = codebase.checkout(branch="main", remote=True) -``` diff --git a/docs/_deprecated/building-with-codegen/imports.mdx b/docs/_deprecated/building-with-codegen/imports.mdx deleted file mode 100644 index 8a707365d..000000000 --- a/docs/_deprecated/building-with-codegen/imports.mdx +++ /dev/null @@ -1,175 +0,0 @@ ---- -title: "The Import API" -sidebarTitle: "Imports" -icon: "file-import" -iconType: "solid" ---- - -The [Import](/api-reference/core/Import) API provides tools for working with imports and managing dependencies between files. - -## Accessing Imports - -You can access these through [File.imports](/api-reference/core/File#imports) and [File.import_statements](/api-reference/core/File#import-statements): - -```python -# Direct access to imports via file -for imp in file.imports: - ... - -# Grab by name of symbol being imported -imp = file.get_import('math') - -# Grab and filter from a codebase -from codegen.sdk import ExternalModule - -external_imports = [i for i in codebase.imports if isinstance(i, ExternalModule)] -``` - -## Common Operations - -The Import API provides several methods for modifying imports: - -```python -# Get a specific import -import_stmt = file.get_import("MyComponent") - -# Change import source -import_stmt.set_module("./new/path") - -# Add/update alias -import_stmt.set_alias("MyAlias") # import X as MyAlias - -# TypeScript-specific operations -import_stmt.make_type_import() # Convert to 'import type' -import_stmt.make_value_import() # Remove 'type' modifier - -# Update multiple properties -import_stmt.update( - module="./new/path", - alias="NewAlias", - is_type=True -) -``` - -## Import Resolution - -Imports can be traced to their original symbols: - -```python -# Follow import chain to source -import_stmt = file.get_import("MyComponent") -original = import_stmt.resolved_symbol - -if original: - print(f"Defined in: {original.file.filepath}") - print(f"Original name: {original.name}") - -# Get file relationships -print(f"From file: {import_stmt.from_file.filepath}") -print(f"To file: {import_stmt.to_file.filepath}") -``` - - -With Python one can specify the `PYTHONPATH` environment variable which is then considered when resolving -packages. - - -## Working with External Modules - -You can determine if an import references an [ExternalModule](/api-reference/core/ExternalModule) by checking the type of [Import.imported_symbol](/api-reference/core/Import#imported-symbol), like so: - -```python -# Check if import is from external package -for imp in file.imports: - if isinstance(imp.imported_symbol, ExternalModule): - print(f"External import: {imp.name} from {imp.module}") - else: - print(f"Local import: {imp.name}") -``` - -Learn more about [external modules here](/building-with-codegen/external-modules) - - -## Bulk Operations - -Here are patterns for working with multiple imports: - -```python -# Update imports from a specific module -old_path = "./old/path" -new_path = "./new/path" - -for imp in file.imports: - if imp.module == old_path: - imp.set_module(new_path) - -# Remove unused imports (excluding external) -for imp in file.imports: - if not imp.usages and not isinstance(imp.resolved_symbol, ExternalModule): - print(f"Removing: {imp.name}") - imp.remove() - -# Consolidate duplicate imports -from collections import defaultdict - -module_imports = defaultdict(list) -for imp in file.imports: - module_imports[imp.module].append(imp) - -for module, imports in module_imports.items(): - if len(imports) > 1: - # Create combined import - symbols = [imp.name for imp in imports] - file.add_import( - f"import {{ {', '.join(symbols)} }} from '{module}'" - ) - # Remove old imports - for imp in imports: - imp.remove() -``` - - -Always check if imports resolve to external modules before modification to avoid breaking third-party package imports. - - -## Import Statements vs Imports - -Codegen provides two levels of abstraction for working with imports: - -- [ImportStatement](/api-reference/core/ImportStatement) - Represents a complete import statement -- [Import](/api-reference/core/Import) - Represents individual imported symbols - - -```python Python -# One ImportStatement containing multiple Import objects -from math import sin, cos as cosine -# Creates: -# - Import for 'sin' -# - Import for 'cos' with alias 'cosine' -``` - -```typescript Typescript -// One ImportStatement containing multiple Import objects -import { sin, cos as cosine } from 'math'; -// Creates: -// - Import for 'sin' -// - Import for 'cos' with alias 'cosine' -``` - - -You can access these through [File.imports](/api-reference/core/File#imports) and [File.import_statements](/api-reference/core/File#import-statements): - -```python -# Direct access to imports -for imp in file.imports: - ... - -# Access to imports via statements -for stmt in file.import_statements: - for imp in stmt.imports: - ... -``` - - -ImportStatement inherits from [Statement](/building-with-codegen/statements-and-code-blocks), providing operations like `remove()` and `insert_before()`. - \ No newline at end of file diff --git a/docs/_deprecated/building-with-codegen/inheritable-behaviors.mdx b/docs/_deprecated/building-with-codegen/inheritable-behaviors.mdx deleted file mode 100644 index 74eb2386d..000000000 --- a/docs/_deprecated/building-with-codegen/inheritable-behaviors.mdx +++ /dev/null @@ -1,104 +0,0 @@ ---- -title: "Inheritable Behaviors" -sidebarTitle: "Inheritable Behaviors" -icon: "puzzle-piece" -iconType: "solid" ---- - -Codegen uses a set of core behaviors that can be inherited by code elements. These behaviors provide consistent APIs across different types of symbols. - - -## Core Behaviors - -- [HasName](/api-reference/core/HasName): For elements with [Names](/api-reference/core/Name) (Functions, Classes, Assignments, etc.) -- [HasValue](/api-reference/core/HasValue): For elements with [Values](/api-reference/core/Value) (Arguments, Assignments, etc.) -- [HasBlock](/api-reference/core/HasBlock): For elements containing [CodeBlocks](/api-reference/core/CodeBlock) (Files, Functions, Classes) -- [Editable](/api-reference/core/Editable): For elements that can be safely modified ([learn more](/building-with-codegen/the-editable-api)) - -These "behaviors" are implemented as inherited classes. - -## Working with Names - -The [HasName](/api-reference/core/HasName) behavior provides APIs for working with named elements: - -```python -# Access the name -print(function.name) # Base name without namespace -print(function.full_name) # Full qualified name with namespace - -# Modify the name -function.set_name("new_name") # Changes just the name -function.rename("new_name") # Changes name and updates all usages - -# Get the underlying name node -name_node = function.get_name() -``` - -## Working with Values - -The [HasValue](/api-reference/core/HasValue) behavior provides APIs for elements that have values: - -```python -# Access the value -value = variable.value # Gets the value Expression node -print(value.source) # Gets the string content - -# Modify the value -variable.set_value("new_value") - -# Common patterns -if variable.value is not None: - print(f"{variable.name} = {variable.value.source}") -``` - -## Working with Code Blocks - -The [HasBlock](/api-reference/core/HasBlock) behavior provides APIs for elements containing code: - -```python -# Access the code block -block = function.code_block -print(len(block.statements)) # Number of statements -printS(block.source) -``` - - - Learn more about [CodeBlocks and Statements - here](/building-with-codegen/statements-and-code-blocks) - - -## Working with Attributes - -The [get_attribute](/api-reference/core/Class#get-attribute) method provides APIs for attribute access: - -```python -# Common patterns -class_attr = class_def.get_attribute("attribute_name") -if class_attr: - print(f"Class variable value: {class_attr.value.source}") -``` - - - Learn more about [working with Attributes - here](/building-with-codegen/class-api#class-attributes). - - -## Behavior Combinations - -Many code elements inherit multiple behaviors. For example, a function typically has: - -```python -# Functions combine multiple behaviors -function = codebase.get_function("process_data") - -# HasName behavior -print(function.name) -function.rename("process_input") - -# HasBlock behavior -print(len(function.code_block.statements)) -function.add_decorator("@timer") - -# Editable behavior -function.edit("def process_input():\n pass") -``` diff --git a/docs/_deprecated/building-with-codegen/language-support.mdx b/docs/_deprecated/building-with-codegen/language-support.mdx deleted file mode 100644 index 93cde215f..000000000 --- a/docs/_deprecated/building-with-codegen/language-support.mdx +++ /dev/null @@ -1,111 +0,0 @@ ---- -title: "Language Support" -sidebarTitle: "Language Support" -icon: "binary" -iconType: "solid" ---- - -Codegen provides first-class support for both Python and TypeScript codebases. The language is automatically inferred when you initialize a codebase. - -## Language Detection - -When you create a new `Codebase` instance, Codegen automatically detects the programming language: - -```python -from codegen import Codebase - -# Automatically detects Python or TypeScript -codebase = Codebase("./") - -# View language with `codebase.language` -print(codebase.language) # "python" or "typescript" -``` - - - Learn more about codebase initialization options in [Parsing - Codebases](/building-with-codegen/parsing-codebases). - - -## Type System - -Codegen uses specialized types for each language. These are defined as type aliases: - -```python -# Python codebases use PyCodebaseType -PyCodebaseType = Codebase[ - PyFile, Directory, PySymbol, PyClass, PyFunction, - PyImport, PyAssignment, Interface, TypeAlias, - PyParameter, PyCodeBlock -] - -# TypeScript codebases use TSCodebaseType -TSCodebaseType = Codebase[ - TSFile, Directory, TSSymbol, TSClass, TSFunction, - TSImport, TSAssignment, TSInterface, TSTypeAlias, - TSParameter, TSCodeBlock -] -``` - -Every code element has both a Python and TypeScript implementation that inherits from a common base class. For example: - -- [Function](/api-reference/core/Function) - - [PyFunction](/api-reference/python/PyFunction) - - [TSFunction](/api-reference/typescript/TSFunction) -- [Class](/api-reference/core/Class) - - [PyClass](/api-reference/python/PyClass) - - [TSClass](/api-reference/typescript/TSClass) -- [Import](/api-reference/core/Import) - - [PyImport](/api-reference/python/PyImport) - - [TSImport](/api-reference/typescript/TSImport) - -... - -```python -# Base class (core/function.py) -class Function: - """Abstract representation of a Function.""" - pass - -# Python implementation (python/function.py) -class PyFunction(Function): - """Extends Function for Python codebases.""" - pass - -# TypeScript implementation (typescript/function.py) -class TSFunction(Function): - """Extends Function for TypeScript codebases.""" - pass -``` - -This inheritance pattern means that most Codegen programs can work with either Python or TypeScript without modification, since they share the same API structure. - -```python -# Works for both Python and TypeScript -for function in codebase.functions: - print(f"Function: {function.name}") - print(f"Parameters: {[p.name for p in function.parameters]}") - print(f"Return type: {function.return_type}") -``` - -## TypeScript-Specific Features - -Some features are only available in TypeScript codebases: - -- **Types and Interfaces**: TypeScript's rich type system ([TSTypeAlias](/api-reference/typescript/TSTypeAlias), [TSInterface](/api-reference/typescript/TSInterface)) -- **Exports**: Module exports and re-exports ([TSExport](/api-reference/typescript/TSExport)) -- **JSX/TSX**: React component handling (see [React and JSX](/building-with-codegen/react-and-jsx)) - -Example of TypeScript-specific features: - -```python -# Only works with TypeScript codebases -if isinstance(codebase, TSCodebaseType): - # Work with TypeScript interfaces - for interface in codebase.interfaces: - print(f"Interface: {interface.name}") - print(f"Extends: {[i.name for i in interface.parent_interfaces]}") - - # Work with type aliases - for type_alias in codebase.type_aliases: - print(f"Type alias: {type_alias.name}") -``` diff --git a/docs/_deprecated/building-with-codegen/local-variables.mdx b/docs/_deprecated/building-with-codegen/local-variables.mdx deleted file mode 100644 index 383f9000d..000000000 --- a/docs/_deprecated/building-with-codegen/local-variables.mdx +++ /dev/null @@ -1,65 +0,0 @@ ---- -title: "Local Variables" -sidebarTitle: "Local Variables" -icon: "cube" -iconType: "solid" ---- - -This document explains how to work with local variables in Codegen. - -## Overview - -Through the [CodeBlock](../api-reference/core/CodeBlock) class, Codegen exposes APIs for analyzing and manipulating local variables within code blocks. - -- [local_var_assignments](../api-reference/core/CodeBlock#local-var-assignments): find all [Assignments](../api-reference/core/Assignment) in this scope -- [get_local_var_assignment(...)](../api-reference/core/CodeBlock#get-local-var-assignment): get specific [Assignments](../api-reference/core/Assignment) by name -- [rename_local_variable(...)](../api-reference/core/CodeBlock#rename-local-variable): rename variables safely across the current scope - -## Basic Usage - -Every code block (function body, loop body, etc.) provides access to its local variables: - -```python -# Get all local variables in a function -function = codebase.get_function("process_data") -local_vars = function.code_block.local_var_assignments -for var in local_vars: - print(var.name) - -# Find a specific variable -config_var = function.code_block.get_local_var_assignment("config") -config_var.rename("settings") # Updates all references safely - -# Rename a variable used in this scope (but not necessarily declared here) -function.rename_local_variable("foo", "bar") -``` - -## Fuzzy Matching - -Codegen supports fuzzy matching when searching for local variables. This allows you to find variables whose names contain a substring, rather than requiring exact matches: - -```python -# Get all local variables containing "config" -function = codebase.get_function("process_data") - -# Exact match - only finds variables named exactly "config" -exact_matches = function.code_block.get_local_var_assignments("config") -# Returns: config = {...} - -# Fuzzy match - finds any variable containing "config" -fuzzy_matches = function.code_block.get_local_var_assignments("config", fuzzy_match=True) -# Returns: config = {...}, app_config = {...}, config_settings = {...} - -# Fuzzy matching also works for variable usages -usages = function.code_block.get_variable_usages("config", fuzzy_match=True) - -# And for renaming variables -function.code_block.rename_variable_usages("config", "settings", fuzzy_match=True) -# Renames: config -> settings, app_config -> app_settings, config_settings -> settings_settings -``` - - - Be careful with fuzzy matching when renaming variables, as it will replace the - matched substring in all variable names. This might lead to unintended renames - like `config_settings` becoming `settings_settings`. - diff --git a/docs/_deprecated/building-with-codegen/moving-symbols.mdx b/docs/_deprecated/building-with-codegen/moving-symbols.mdx deleted file mode 100644 index b29f6bd32..000000000 --- a/docs/_deprecated/building-with-codegen/moving-symbols.mdx +++ /dev/null @@ -1,69 +0,0 @@ ---- -title: "Moving Symbols" -sidebarTitle: "Moving Symbols" -icon: "arrows-up-down-left-right" -iconType: "solid" ---- - -Codegen provides fast, configurable and safe APIs for moving symbols (functions, classes, variables) between files while automatically handling imports and dependencies. - -The key API is [Symbol.move_to_file(...)](/api-reference/core/Symbol#move-to-file). - -## Basic Symbol Movement - -Simply call [Symbol.move_to_file(...)](/api-reference/core/Symbol#move-to-file) to move a symbol to a new file. - -```python -# Manipulation code: -file1 = codebase.get_file("file1.py") -file2 = codebase.get_file("file2.py") - -helper_func = file1.get_symbol("helper") - -# Ensure the destination file exists -if not file2.exists(): - file2 = codebase.create_file('file2.py') - -# Move the symbol -helper_func.move_to_file(file2) -``` - - - By default, this will move any dependencies, including imports, to the new - file. - - -## Moving Strategies - -The [Symbol.move_to_file(...)](/api-reference/core/Symbol#move-to-file) method accepts a `strategy` parameter, which can be used to control how imports are updated. - -Your options are: - -- `"update_all_imports"`: Updates all import statements across the codebase (default) -- `"add_back_edge"`: Adds import and re-export in the original file - -`"add_back_edge"` is useful when moving a symbol that is depended on by other symbols in the original file, and will result in smaller diffs. - - - `"add_back_edge"` will result in circular dependencies if the symbol has - non-import dependencies in it's original file. - - -## Moving Symbols in Bulk - -Make sure to call [Codebase.commit(...)](/api-reference/core/Codebase#commit) _after_ moving symbols in bulk for performant symbol movement. - -```python -# Move all functions with a specific prefix -for file in codebase.files: - for function in file.functions: - if function.name.startswith("pylsp_"): - function.move_to_file( - shared_file, - include_dependencies=True, - strategy="update_all_imports" - ) - -# Commit the changes once, at the end -codebase.commit() -``` diff --git a/docs/_deprecated/building-with-codegen/parsing-codebases.mdx b/docs/_deprecated/building-with-codegen/parsing-codebases.mdx deleted file mode 100644 index ac8168f73..000000000 --- a/docs/_deprecated/building-with-codegen/parsing-codebases.mdx +++ /dev/null @@ -1,128 +0,0 @@ ---- -title: "Parsing Codebases" -sidebarTitle: "Parsing Codebases" -icon: "power-off" -iconType: "solid" ---- - -The primary entrypoint to programs leveraging Codegen is the [Codebase](/api-reference/core/Codebase) class. - -## Local Codebases - -Construct a Codebase by passing in a path to a local `git` repository or any subfolder within it. The path must be within a git repository (i.e., somewhere in the parent directory tree must contain a `.git` folder). - -```python -from codegen import Codebase - -# Parse from a git repository root -codebase = Codebase("path/to/repository") - -# Parse from a subfolder within a git repository -codebase = Codebase("path/to/repository/src/subfolder") - -# Parse from current directory (must be within a git repo) -codebase = Codebase("./") - -# Specify programming language (instead of inferring from file extensions) -codebase = Codebase("./", language="typescript") -``` - - - By default, Codegen will automatically infer the programming language of the codebase and - parse all files in the codebase. You can override this by passing the `language` parameter - with a value from the `ProgrammingLanguage` enum. - - - - The initial parse may take a few minutes for large codebases. This - pre-computation enables constant-time operations afterward. [Learn more - here.](/introduction/how-it-works) - - -## Remote Repositories - -To fetch and parse a repository directly from GitHub, use the `from_repo` function. - -```python -from codegen import Codebase -# Fetch and parse a repository (defaults to /tmp/codegen/{repo_name}) -codebase = Codebase.from_repo('fastapi/fastapi') - -# Customize temp directory, clone depth, specific commit, or programming language -codebase = Codebase.from_repo( - 'fastapi/fastapi', - tmp_dir='/custom/temp/dir', # Optional: custom temp directory - commit='786a8ada7ed0c7f9d8b04d49f24596865e4b7901', # Optional: specific commit - shallow=False, # Optional: full clone instead of shallow - language="python" # Optional: override language detection -) -``` - - - Remote repositories are cloned to the `/tmp/codegen/{repo_name}` directory by - default. The clone is shallow by default for better performance. - - -## Configuration Options - -You can customize the behavior of your Codebase instance by passing a `CodebaseConfig` object. This allows you to configure secrets (like API keys) and toggle specific features: - -```python -from codegen import Codebase -from codegen.configs.models.codebase import CodebaseConfig -from codegen.configs.models.secrets import SecretsConfig - -codebase = Codebase( - "path/to/repository", - config=CodebaseConfig(debug=True), - secrets=SecretsConfig(openai_api_key="your-openai-key") # For AI-powered features -) -``` - -- `CodebaseConfig` and `SecretsConfig` allow you to configure - - `config`: Toggle specific features like language engines, dependency management, and graph synchronization - - `secrets`: API keys and other sensitive information needed by the codebase - -For a complete list of available feature flags and configuration options, see the [source code on GitHub](https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/codebase/config.py). - -## Advanced Initialization - -For more complex scenarios, Codegen supports an advanced initialization mode using `ProjectConfig`. This allows for fine-grained control over: - -- Repository configuration -- Base path and subdirectory filtering -- Multiple project configurations - -Here's an example: - -```python -from codegen import Codebase -from codegen.git.repo_operator.local_repo_operator import LocalRepoOperator -from codegen.git.schemas.repo_config import BaseRepoConfig -from codegen.sdk.codebase.config import ProjectConfig - -codebase = Codebase( - projects = [ - ProjectConfig( - repo_operator=LocalRepoOperator( - repo_path="/tmp/codegen-sdk", - repo_config=BaseRepoConfig(), - bot_commit=True - ), - language="typescript", - base_path="src/codegen/sdk/typescript", - subdirectories=["src/codegen/sdk/typescript"] - ) - ] -) -``` - -For more details on advanced configuration options, see the [source code on GitHub](https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/codebase.py). - -## Supported Languages - -Codegen currently supports: - -- [Python](/api-reference/python) -- [TypeScript/JavaScript](/api-reference/typescript) -- [React/JSX](/building-with-codegen/react-and-jsx) diff --git a/docs/_deprecated/building-with-codegen/react-and-jsx.mdx b/docs/_deprecated/building-with-codegen/react-and-jsx.mdx deleted file mode 100644 index 1784c8a41..000000000 --- a/docs/_deprecated/building-with-codegen/react-and-jsx.mdx +++ /dev/null @@ -1,140 +0,0 @@ ---- -title: "React and JSX" -sidebarTitle: "React and JSX" -icon: "react" -iconType: "brands" ---- - -GraphSitter exposes several React and JSX-specific APIs for working with modern React codebases. - -Key APIs include: - -- [Function.is_jsx](/api-reference/typescript/TSFunction#is-jsx) - Check if a function contains JSX elements -- [Class.jsx_elements](/api-reference/typescript/TSClass#jsx-elements) - Get all JSX elements in a class -- [Function.jsx_elements](/api-reference/typescript/TSFunction#jsx-elements) - Get all JSX elements in a function -- [JSXElement](/api-reference/typescript/JSXElement) - Manipulate JSX elements -- [JSXProp](/api-reference/typescript/JSXProp) - Manipulate JSX props - - - See [React Modernization](/tutorials/react-modernization) for tutorials and - applications of the concepts described here - - -## Detecting React Components with `is_jsx` - -Codegen exposes a `is_jsx` property on both classes and functions, which can be used to check if a symbol is a React component. - -```python -# Check if a function is a React component -function = file.get_function("MyComponent") -is_component = function.is_jsx # True for React components - -# Check if a class is a React component -class_def = file.get_class("MyClassComponent") -is_component = class_def.is_jsx # True for React class components -``` - -## Working with JSX Elements - -Given a React component, you can access its JSX elements using the [jsx_elements](/api-reference/typescript/TSFunction#jsx-elements) property. - -You can manipulate these elements by using the [JSXElement](/api-reference/typescript/JSXElement) and [JSXProp](/api-reference/typescript/JSXProp) APIs. - -```python -# Get all JSX elements in a component -for element in component.jsx_elements: - # Access element name - if element.name == "Button": - # Wrap element in a div - element.wrap("
", "
") - - # Get specific prop - specific_prop = element.get_prop("className") - - # Iterate over all props - for prop in element.props: - if prop.name == "className": - # Set prop value - prop.set_value('"my-classname"') - - # Modify element - element.set_name("NewComponent") - element.add_prop("newProp", "{value}") - - # Get child JSX elements - child_elements = element.jsx_elements - - # Wrap element in a JSX expression (preserves whitespace) - element.wrap("
", "
") -``` - -## Common React Operations - -See [React Modernization](/tutorials/react-modernization) for more - -### Refactoring Components into Separate Files - -Split React components into individual files: - -```python -# Find (named) React components -react_components = [ - func for func in codebase.functions - if func.is_jsx and func.name is not None -] - -# Filter out those that are not the default export -non_default_components = [ - comp for comp in react_components - if not comp.export or not comp.export.is_default_export() -] - -# Move these non-default components to new files -for component in react_components: - if component != default_component: - # Create new file - new_file_path = '/'.join(component.filepath.split('/')[:-1]) + f"{component.name}.tsx" - new_file = codebase.create_file(new_file_path) - - # Move component and update imports - component.move_to_file(new_file, strategy="add_back_edge") -``` - - - See [Moving Symbols](/building-with-codegen/moving-symbols) for more details - on moving symbols between files. - - -### Updating Component Names and Props - -Replace components throughout the codebase with prop updates: - -```python -# Find target component -new_component = codebase.get_symbol("NewComponent") - -for function in codebase.functions: - if function.is_jsx: - # Update JSX elements - for element in function.jsx_elements: - if element.name == "OldComponent": - # Update name - element.set_name("NewComponent") - - # Edit props - needs_clsx = not file.has_import("clsx") - for prop in element.props: - if prop.name == "className": - prop.set_value('clsx("new-classname")') - needs_clsx = True - elif prop.name == "onClick": - prop.set_name('handleClick') - - # Add import if needed - if needs_clsx: - file.add_import_from_import_source("import clsx from 'clsx'") - - # Add import if needed - if not file.has_import("NewComponent"): - file.add_import(new_component) -``` diff --git a/docs/_deprecated/building-with-codegen/reducing-conditions.mdx b/docs/_deprecated/building-with-codegen/reducing-conditions.mdx deleted file mode 100644 index 7460308fa..000000000 --- a/docs/_deprecated/building-with-codegen/reducing-conditions.mdx +++ /dev/null @@ -1,277 +0,0 @@ ---- -title: "Reducing Conditions" -sidebarTitle: "Reducing Conditions" -icon: "code-branch" -iconType: "solid" ---- - -Codegen provides powerful APIs for reducing conditional logic to constant values. This is particularly useful for removing feature flags, cleaning up dead code paths, and simplifying conditional logic. - -## Overview - -The `reduce_condition()` method is available on various conditional constructs: - -- [If/else statements](/api-reference/core/IfBlockStatement#reduce-condition) -- [Ternary expressions](/api-reference/core/TernaryExpression#reduce-condition) -- [Binary expressions](/api-reference/core/BinaryExpression#reduce-condition) -- [Function calls](/api-reference/core/FunctionCall#reduce-condition) - -When you reduce a condition to `True` or `False`, Codegen automatically: - -1. Evaluates which code path(s) to keep -2. Removes unnecessary branches -3. Preserves proper indentation and formatting - -### Motivating Example - -For example, consider the following code: - -```python -flag = get_feature_flag('MY_FEATURE') -if flag: - print('MY_FEATURE: ON') -else: - print('MY_FEATURE: OFF') -``` - -`.reduce_condition` allows you to deterministically reduce this code to the following: - -```python -print('MY_FEATURE: ON') -``` - -This is useful when a feature flag is fully "rolled out". - -## Implementations - -### [IfBlockStatements](/api-reference/core/IfBlockStatement#reduce-condition) - -You can reduce if/else statements to either their "true" or "false" branch. - -For example, in the code snippet above: - -```python -# Grab if statement -if_block = file.code_block.statements[1] - -# Reduce to True branch -if_block.reduce_condition(True) -``` - -This will remove the `else` branch and keep the `print` statement, like so: - -```python -flag = get_feature_flag('MY_FEATURE') -print('MY_FEATURE: ON') -``` - -### Handling Elif Chains - -Codegen intelligently handles elif chains when reducing conditions: - -```python -# Original code -if condition_a: - print("A") -elif condition_b: - print("B") -else: - print("C") - -# Reduce first condition to False -if_block.reduce_condition(False) -# Result: -if condition_b: - print("B") -else: - print("C") - -# Reduce elif condition to True -elif_block.reduce_condition(True) -# Result: -print("B") -``` - -## Ternary Expressions - -Ternary expressions (conditional expressions) can also be reduced: - -```python -# Original code -result = 'valueA' if condition else 'valueB' - -# Reduce to True -ternary_expr.reduce_condition(True) -# Result: -result = 'valueA' - -# Reduce to False -ternary_expr.reduce_condition(False) -# Result: -result = 'valueB' -``` - -### Nested Ternaries - -Codegen handles nested ternary expressions correctly: - -```python -# Original code -result = 'A' if a else 'B' if b else 'C' - -# Reduce outer condition to False -outer_ternary.reduce_condition(False) -# Result: -result = 'B' if b else 'C' - -# Then reduce inner condition to True -inner_ternary.reduce_condition(True) -# Result: -result = 'B' -``` - -## Binary Operations - -Binary operations (and/or) can be reduced to simplify logic: - -```python -# Original code -result = (x or y) and b - -# Reduce x to True -x_assign.reduce_condition(True) -# Result: -result = b - -# Reduce y to False -y_assign.reduce_condition(False) -# Result: -result = x and b -``` - -## Function Calls - -[Function calls](/api-reference/core/FunctionCall#reduce-condition) can also be reduced, which is particularly useful when dealing with hooks or utility functions that return booleans: - -```typescript -// Original code -const isEnabled = useFeatureFlag("my_feature"); -return isEnabled ? : ; - -// After reducing useFeatureFlag to True -return ; -``` - -### Feature Flag Hooks - -A common use case is reducing feature flag hooks to constants. Consider the following code: - -```typescript -// Original code -function MyComponent() { - const showNewUI = useFeatureFlag("new_ui_enabled"); - - if (showNewUI) { - return ; - } - return ; -} -``` - -We can reduce the `useFeatureFlag` hook to a constant value like so, with [FunctionCall.reduce_condition](/api-reference/core/FunctionCall#reduce-condition): - -```python -hook = codebase.get_function("useFeatureFlag") -for usage in hook.usages(): - if isinstance(usage.match, FunctionCall): - fcall = usage.match - if fcall.args[0].value.content == 'new_ui_enabled': - # This will automatically reduce any conditions using the flag - fcall.reduce_condition(True) -``` - -This produces the following code: - -```typescript -function MyComponent() { - return ; -} -``` - -### Comprehensive Example - -Here's a complete example of removing a feature flag from both configuration and usage: - -```python -feature_flag_name = "new_ui_enabled" -target_value = True - -# 1. Remove from config -config_file = codebase.get_file("src/featureFlags/config.ts") -feature_flag_config = config_file.get_symbol("FEATURE_FLAG_CONFIG").value -feature_flag_config.pop(feature_flag_name) - -# 2. Find and reduce all usages -hook = codebase.get_function("useFeatureFlag") -for usage in hook.usages(): - fcall = usage.match - if isinstance(fcall, FunctionCall): - # Check if this usage is for our target flag - first_arg = fcall.args[0].value - if isinstance(first_arg, String) and first_arg.content == feature_flag_name: - print(f'Reducing in: {fcall.parent_symbol.name}') - # This will automatically reduce: - # - Ternary expressions using the flag - # - If statements checking the flag - # - Binary operations with the flag - fcall.reduce_condition(target_value) - -# Commit changes to disk -codebase.commit() -``` - -This example: - -1. Removes the feature flag from configuration -2. Finds all usages of the feature flag hook -3. Reduces each usage to a constant value -4. Automatically handles all conditional constructs using the flag - - - When reducing a function call, Codegen automatically handles all dependent - conditions. This includes: - [If/else - statements](/api-reference/core/IfBlockStatement#reduce-condition) - [Ternary - expressions](/api-reference/core/TernaryExpression#reduce-condition) - [Binary - operations](/api-reference/core/BinaryExpression#reduce-condition) - - -## TypeScript and JSX Support - -Condition reduction works with TypeScript and JSX, including conditional rendering: - -```typescript -// Original JSX -const MyComponent: React.FC = () => { - let isVisible = true; - return ( -
- {isVisible && Visible} - {!isVisible && Hidden} -
- ); -}; - -// After reducing isVisible to True -const MyComponent: React.FC = () => { - return ( -
- Visible -
- ); -}; -``` - - - Condition reduction is particularly useful for cleaning up feature flags in - React components, where conditional rendering is common. - diff --git a/docs/_deprecated/building-with-codegen/reusable-codemods.mdx b/docs/_deprecated/building-with-codegen/reusable-codemods.mdx deleted file mode 100644 index 0768e1a0d..000000000 --- a/docs/_deprecated/building-with-codegen/reusable-codemods.mdx +++ /dev/null @@ -1,120 +0,0 @@ ---- -title: "Reusable Codemods" -sidebarTitle: "Reusable Codemods" -icon: "arrows-rotate" -iconType: "solid" ---- - -Codegen enables you to create reusable code transformations using Python functions decorated with `@codegen.function`. These codemods can be shared, versioned, and run by your team. - -## Creating Codemods - -The easiest way to create a new codemod is using the CLI [create](/cli/create) command: - -```bash -codegen create rename-function . -``` - -This creates a new codemod in your `.codegen/codemods` directory: - -```python -import codegen -from codegen import Codebase - -@codegen.function("rename-function") -def run(codebase: Codebase): - """Add a description of what this codemod does.""" - # Add your code here - pass -``` - - - Codemods are stored in `.codegen/codemods/name/name.py` and are tracked in Git for easy sharing. - - -### AI-Powered Generation with `-d` - -You can use AI to generate an initial implementation by providing a description: - -```bash -codegen create rename-function . -d "Rename the getUserData function to fetchUserProfile" -``` - -This will: -1. Generate an implementation based on your description -2. Create a custom system prompt that you can provide to an IDE chat assistant (learn more about [working with AI](/introduction/work-with-ai)) -3. Place both files in the codemod directory - -## Running Codemods - -Once created, run your codemod using: - -```bash -codegen run rename-function -``` - -The execution flow: -1. Codegen parses your codebase into a graph representation -2. Your codemod function is executed against this graph -3. Changes are tracked and applied to your filesystem -4. A diff preview shows what changed - - -## Codemod Structure - -A codemod consists of three main parts: - -1. The `@codegen.function` decorator that names your codemod -2. A `run` function that takes a `Codebase` parameter -3. Your transformation logic using the Codebase API - -```python -import codegen -from codegen import Codebase - -@codegen.function("update-imports") -def run(codebase: Codebase): - """Update import statements to use new package names.""" - for file in codebase.files: - for imp in file.imports: - if imp.module == "old_package": - imp.rename("new_package") - codebase.commit() -``` - -## Arguments - -Codemods can accept arguments using Pydantic models: - -```python -from pydantic import BaseModel - -class RenameArgs(BaseModel): - old_name: str - new_name: str - -@codegen.function("rename-function") -def run(codebase: Codebase, arguments: RenameArgs): - """Rename a function across the codebase.""" - old_func = codebase.get_function(arguments.old_name) - if old_func: - old_func.rename(arguments.new_name) - codebase.commit() -``` - -Run it with: -```bash -codegen run rename-function --arguments '{"old_name": "getUserData", "new_name": "fetchUserProfile"}' -``` - -## Directory Structure - -Your codemods live in a dedicated directory structure: - -``` -.codegen/ -└── codemods/ - └── rename_function/ - β”œβ”€β”€ rename_function.py # The codemod implementation - └── rename_function_prompt.md # System prompt (if using AI) -``` \ No newline at end of file diff --git a/docs/_deprecated/building-with-codegen/semantic-code-search.mdx b/docs/_deprecated/building-with-codegen/semantic-code-search.mdx deleted file mode 100644 index 63119924a..000000000 --- a/docs/_deprecated/building-with-codegen/semantic-code-search.mdx +++ /dev/null @@ -1,133 +0,0 @@ ---- -title: "Semantic Code Search" -sidebarTitle: "Semantic Code Search" -icon: "magnifying-glass" -iconType: "solid" ---- - -Codegen provides semantic code search capabilities using embeddings. This allows you to search codebases using natural language queries and find semantically related code, even when the exact terms aren't present. - -This is under active development. Interested in an application? [Reach out to the team!](/introduction/about.tsx) - -## Basic Usage - -Here's how to create and use a semantic code search index: - -```python -# Parse a codebase -codebase = Codebase.from_repo('fastapi/fastapi', language='python') - -# Create index -index = FileIndex(codebase) -index.create() # computes per-file embeddings - -# Save index to .pkl -index.save('index.pkl') - -# Load index into memory -index.load('index.pkl') - -# Update index after changes -codebase.files[0].edit('# 🌈 Replacing File Content 🌈') -codebase.commit() -index.update() # re-computes 1 embedding -``` - - -## Searching Code - -Once you have an index, you can perform semantic searches: - -```python -# Search with natural language -results = index.similarity_search( - "How does FastAPI handle dependency injection?", - k=5 # number of results -) - -# Print results -for file, score in results: - print(f"\nScore: {score:.3f} | File: {file.filepath}") - print(f"Preview: {file.content[:200]}...") -``` -The `FileIndex` returns tuples of ([File](/api-reference/core/SourceFile), `score`) - - -The search uses cosine similarity between embeddings to find the most semantically related files, regardless of exact keyword matches. - - -## Available Indices - -Codegen provides two types of semantic indices: - -### FileIndex - -The `FileIndex` operates at the file level: -- Indexes entire files, splitting large files into chunks -- Best for finding relevant files or modules -- Simpler and faster to create/update - -```python -from codegen.extensions.index.file_index import FileIndex - -index = FileIndex(codebase) -index.create() -``` - -### SymbolIndex (Experimental) - -The `SymbolIndex` operates at the symbol level: -- Indexes individual functions, classes, and methods -- Better for finding specific code elements -- More granular search results - -```python -from codegen.extensions.index.symbol_index import SymbolIndex - -index = SymbolIndex(codebase) -index.create() -``` - -## How It Works - -The semantic indices: -1. Process code at either file or symbol level -2. Split large content into chunks that fit within token limits -3. Use OpenAI's text-embedding-3-small model to create embeddings -4. Store embeddings efficiently for similarity search -5. Support incremental updates when code changes - -When searching: -1. Your query is converted to an embedding -2. Cosine similarity is computed with all stored embeddings -3. The most similar items are returned with their scores - - -Creating embeddings requires an OpenAI API key with access to the embeddings endpoint. - - -## Example Searches - -Here are some example semantic searches: - -```python -# Find authentication-related code -results = index.similarity_search( - "How is user authentication implemented?", - k=3 -) - -# Find error handling patterns -results = index.similarity_search( - "Show me examples of error handling and custom exceptions", - k=3 -) - -# Find configuration management -results = index.similarity_search( - "Where is the application configuration and settings handled?", - k=3 -) -``` - -The semantic search can understand concepts and return relevant results even when the exact terms aren't present in the code. diff --git a/docs/_deprecated/building-with-codegen/statements-and-code-blocks.mdx b/docs/_deprecated/building-with-codegen/statements-and-code-blocks.mdx deleted file mode 100644 index b768ba4b1..000000000 --- a/docs/_deprecated/building-with-codegen/statements-and-code-blocks.mdx +++ /dev/null @@ -1,335 +0,0 @@ ---- -title: "Statements and Code Blocks" -sidebarTitle: "Statements and Code Blocks" -icon: "code" -iconType: "solid" ---- - -Codegen uses two classes to represent code structure at the highest level: - -- [Statement](../api-reference/core/Statement): Represents a single line or block of code - - - Can be assignments, imports, loops, conditionals, etc. - - Contains source code, dependencies, and type information - - May contain nested code blocks (like in functions or loops) - -- [CodeBlock](../api-reference/core/CodeBlock): A container for multiple Statements - - Found in files, functions, classes, and control flow blocks - - Provides APIs for analyzing and manipulating statements - - Handles scope, variables, and dependencies - -Codegen provides rich APIs for working with code statements and blocks, allowing you to analyze and manipulate code structure at a granular level. - -## Working with Statements - -### Basic Usage - -Every file, function, and class in Codegen has a [CodeBlock](../api-reference/core/CodeBlock) that contains its statements: - -```python -# Access statements in a file -file = codebase.get_file("main.py") -for statement in file.code_block.statements: - print(f"Statement type: {statement.statement_type}") - -# Access statements in a function -function = file.get_function("process_data") -for statement in function.code_block.statements: - print(f"Statement: {statement.source}") -``` - -### Filtering Statements - -Filter through statements using Python's builtin `isinstance` function. - -```python -# Filter statements by type -for stmt in file.code_block.statements: - if isinstance(stmt, ImportStatement): - print(stmt) -``` - -### Adding Statements - -Functions and Files support [.prepend_statement(...)](../api-reference/core/Symbol#prepend-statement) and [.add_statement(...)](../api-reference/core/Function#add-statement) to add statements to the symbol. - - - See [Adding - Statements](/building-with-codegen/symbol-api#function-statement-manipulation) - for details. - - -### Working with Nested Structures - -Frequently you will want to check if a statement is nested within another structure, for example if a statement is inside an `if` block or a `try/catch` statement. - -Codegen supports this functionality with the [Editable.is_wrapped_in(...)](../api-reference/core/Editable#is-wrapped-in) method. - -```python -func = codebase.get_function("process_data") -for usage in func.local_variable_usages: - if usage.is_wrapped_in(IfStatement): - print(f"Usage of {usage.name} is inside an if block") -``` - -Similarly, all Editable objects support the `.parent_statement`, which can be used to navigate the statement hierarchy. - -```python -func = codebase.get_function("process_data") -for usage in func.local_variable_usages: - if isinstance(usage.parent_statement, IfStatement): - print(f"Usage of {usage.name} is directly beneath an IfStatement") -``` - -### Wrapping and Unwrapping Statements - -[CodeBlocks](../api-reference/core/CodeBlock) support wrapping and unwrapping with the following APIs: - -- [.wrap(...)](../api-reference/core/CodeBlock#wrap) - allows you to wrap a statement in a new structure. -- [.unwrap(...)](../api-reference/core/CodeBlock#unwrap) - allows you to remove the wrapping structure while preserving the code block's contents. - -```python -# Wrap code blocks with new structures -function.code_block.wrap("with open('test.txt', 'w') as f:") -# Result: -# with open('test.txt', 'w') as f: -# original_code_here... - -# Wrap code in a function -file.code_block.wrap("def process_data(a, b):") -# Result: -# def process_data(a, b): -# original_code_here... - -# Unwrap code from its container -if_block.code_block.unwrap() # Removes the if statement but keeps its body -while_loop.code_block.unwrap() # Removes the while loop but keeps its body -``` - - - Both `wrap` and `unwrap` are potentially unsafe changes and will modify - business logic. - - - - The `unwrap()` method preserves the indentation of the code block's contents - while removing the wrapping structure. This is useful for refactoring nested - code structures. - - -## Statement Types - -Codegen supports various statement types, each with specific APIs: - -### [Import Statements](../api-reference/core/ImportStatement) / [Export Statements](../api-reference/core/ExportStatement) - - - See [imports](/building-with-codegen/imports) and [exports](../building-with-codegen/exports) for - more details. - - -```python -# Access import statements -for import_stmt in file.import_statements: - print(f"Module: {import_stmt.module}") - for imported in import_stmt.imports: - print(f" Imported: {imported.name}") - -# Remove specific imports -import_stmt = file.import_statements[0] -import_stmt.imports[0].remove() # Remove first import - -# Remove entire import statement -import_stmt.remove() -``` - -### [If/Else Statements](../api-reference/core/IfBlockStatement) - -If/Else statements provide rich APIs for analyzing and manipulating conditional logic: - -```python -# Access if/else blocks -if_block = file.code_block.statements[0] -print(f"Condition: {if_block.condition.source}") - -# Check block types -if if_block.is_if_statement: - print("Main if block") -elif if_block.is_elif_statement: - print("Elif block") -elif if_block.is_else_statement: - print("Else block") - -# Access alternative blocks -for elif_block in if_block.elif_statements: - print(f"Elif condition: {elif_block.condition.source}") - -if else_block := if_block.else_statement: - print("Has else block") - -# Access nested code blocks -for block in if_block.nested_code_blocks: - print(f"Block statements: {len(block.statements)}") -``` - -If blocks also support condition reduction, which can simplify conditional logic: - -```python -# Reduce if condition to True -if_block.reduce_condition(True) -# Before: -# if condition: -# print("a") -# else: -# print("b") -# After: -# print("a") - -# Reduce elif condition to False -elif_block.reduce_condition(False) -# Before: -# if a: -# print("a") -# elif condition: -# print("b") -# else: -# print("c") -# After: -# if a: -# print("a") -# else: -# print("c") -``` - - - When reducing conditions, Codegen automatically handles the restructuring of - elif/else chains and preserves the correct control flow. - - -### [Switch](../api-reference/core/SwitchStatement)/[Match](../api-reference/python/PyMatchStatement) Statements - -```python -# TypeScript switch statements -switch_stmt = file.code_block.statements[0] -for case_stmt in switch_stmt.cases: - print(f"Case condition: {case_stmt.condition}") - print(f"Is default: {case_stmt.default}") - - # Access statements in each case - for statement in case_stmt.code_block.statements: - print(f"Statement: {statement.source}") - -# Python match statements -match_stmt = file.code_block.statements[0] -for case in match_stmt.cases: - print(f"Pattern: {case.pattern}") - for statement in case.code_block.statements: - print(f"Statement: {statement.source}") -``` - -### [While Statements](../api-reference/core/WhileStatement) - -```python -while_stmt = file.code_block.statements[0] -print(f"Condition: {while_stmt.condition}") - -# Access loop body -for statement in while_stmt.code_block.statements: - print(f"Body statement: {statement.source}") - -# Get function calls within the loop -for call in while_stmt.function_calls: - print(f"Function call: {call.source}") -``` - -### [Assignment Statements](../api-reference/core/AssignmentStatement) - -```python -# Access assignments in a code block -for statement in code_block.statements: - if statement.statement_type == StatementType.ASSIGNMENT: - for assignment in statement.assignments: - print(f"Variable: {assignment.name}") - print(f"Value: {assignment.value}") -``` - -## Working with Code Blocks - -Code blocks provide several ways to analyze and manipulate their content: - -### Statement Access - -```python -code_block = function.code_block - -# Get all statements -all_statements = code_block.statements - -# Get statements by type -if_blocks = code_block.if_blocks -while_loops = code_block.while_loops -try_blocks = code_block.try_blocks - -# Get local variables -local_vars = code_block.get_local_var_assignments() -``` - -### Statement Dependencies - -```python -# Get dependencies between statements -function = file.get_function("process") -for statement in function.code_block.statements: - deps = statement.dependencies - print(f"Statement {statement.source} depends on: {[d.name for d in deps]}") -``` - -### Parent-Child Relationships - -```python -# Access parent statements -function = file.get_function("main") -parent_stmt = function.parent_statement - -# Access nested symbols -class_def = file.get_class("MyClass") -for method in class_def.methods: - parent = method.parent_statement - print(f"Method {method.name} is defined in {parent.source}") -``` - -## Common Operations - -### Finding Statements - -```python -# Find specific statements -assignments = [s for s in code_block.statements - if s.statement_type == StatementType.ASSIGNMENT] - -# Find statements by content -matching = [s for s in code_block.statements - if "specific_function()" in s.source] -``` - -### Analyzing Flow Control - -```python -# Analyze control flow -for statement in code_block.statements: - if statement.statement_type == StatementType.IF_BLOCK: - print("Condition:", statement.condition) - print("Then:", statement.consequence_block.statements) - if statement.alternative_block: - print("Else:", statement.alternative_block.statements) -``` - -### Working with Functions - -```python -# Analyze function calls in statements -for statement in code_block.statements: - for call in statement.function_calls: - print(f"Calls function: {call.name}") - print(f"With arguments: {[arg.source for arg in call.arguments]}") -``` diff --git a/docs/_deprecated/building-with-codegen/symbol-api.mdx b/docs/_deprecated/building-with-codegen/symbol-api.mdx deleted file mode 100644 index 8545fb5fe..000000000 --- a/docs/_deprecated/building-with-codegen/symbol-api.mdx +++ /dev/null @@ -1,116 +0,0 @@ ---- -title: "The Symbol API" -sidebarTitle: "Symbols" -icon: "shapes" -iconType: "solid" ---- - -The [Symbol](/api-reference/core/Symbol) is the primary way developers interact with code in Codegen. It maps to how developers think about code - as functions, classes, variables, and other named entities. - -Both the [Function](/api-reference/core/Function) and [Class](/api-reference/core/Class) symbols are subclasses of the [Symbol](/api-reference/core/Symbol) class. - -## Accessing Symbols - -The [Codebase](/api-reference/core/Codebase) class provides getters and iterators for functions, classes and symbols: - -```python -# Core symbol types -symbol = codebase.get_symbol("process_data") # will return a Function, Class, etc. -function = codebase.get_function("process_data") -class_def = codebase.get_class("DataProcessor") - -# Iterate over all symbols (includes functions + classes) -for symbol in codebase.symbols: - print(symbol.name) - -# Iterate over all functions and classes -for symbol in codebase.functions + codebase.classes: - print(symbol.name) -``` - -## Shared APIs - -All symbols share common APIs for manipulation: - -- The [Editable](/api-reference/core/Editable) API -- Metadata - - [symbol.name](/api-reference/core/Symbol#name) - - [symbol.source](/api-reference/core/Symbol#source) - - [symbol.docstring](/api-reference/core/Symbol#docstring) -- Edit operations - - [symbol.set_docstring](/api-reference/core/Symbol#set-docstring) - - [symbol.move_to_file](/api-reference/core/Symbol#move-to-file) (see [Moving Symbols](/building-with-codegen/moving-symbols)) -- Graph relations (See [Usages and Dependencies](/building-with-codegen/dependencies-and-usages)) - - [symbol.usages](/api-reference/core/Symbol#usages) - - [symbol.dependencies](/api-reference/core/Symbol#dependencies) - -## Name operations - -```python -# Name operations -print(symbol.name) -symbol.rename("new_name") - -# Source code -print(symbol.source) # Get source code -symbol.edit("new source code") # Modify source - -# Documentation -print(symbol.docstring) # Get docstring -symbol.set_docstring("New documentation") - -# Move symbol to new file -symbol.move_to_file(new_file) - -# Add before/after other symbols -symbol.insert_before("# deprecated") -symbol.insert_after("# end deprecated") -``` - -## Function Statement Manipulation - -Functions provide special APIs for adding statements to their body: - -- [Function.prepend_statements](/api-reference/core/Function#prepend_statements) - add statements to the start of the function body -- [Function.add_statements](/api-reference/core/Function#add_statements) - add statements to the end of the function body - -```python -# Add statements at the start of a function -function.prepend_statements("print('Starting function')") -method.prepend_statements("self.validate_input()") - -# Add statements at the end of a function -function.add_statements("print('Done')") -method.add_statements("return self.result") -``` - - - The statement manipulation APIs (`prepend_statements` and `add_statements`) - are only available on Function objects. For other symbols, use the general - Editable APIs like `insert_before` and `insert_after`. - - -## Common Patterns - -Most Codegen programs focus on finding and manipulating symbols: - -```python -# Find and modify functions -for function in codebase.functions: - if function.name.startswith("old_"): - # Rename function - function.rename(function.name.replace("old_", "new_")) - # Update docstring - function.set_docstring("Updated version of function") - -# Update class methods -for method in class_def.methods: - # Add logging - method.prepend_statements("logger.info('Called {}'".format(method.name)) -``` - - - The Symbol API is designed to be intuitive and match how developers think - about code. Most transformations start with finding relevant symbols and then - applying changes to them. - diff --git a/docs/_deprecated/building-with-codegen/the-editable-api.mdx b/docs/_deprecated/building-with-codegen/the-editable-api.mdx deleted file mode 100644 index 8eab4b04f..000000000 --- a/docs/_deprecated/building-with-codegen/the-editable-api.mdx +++ /dev/null @@ -1,170 +0,0 @@ ---- -title: "The Editable API" -sidebarTitle: "Editables" -icon: "pencil" -iconType: "solid" ---- - -Every code element in Codegen is an [Editable](../api-reference/core/Editable) - meaning it can be manipulated while maintaining correctness. - -All higher-level code manipulation APIs are built on top of the atomic Editable API. - -## Core Concepts - -Every Editable provides: - -- Information about the source code: - - [source](../api-reference/core/Editable#source) - the text content of the Editable - - [extended_source](../api-reference/core/Editable#extended_source) - includes relevant content like decorators, comments, etc. -- Information about the file that contains the Editable: - - [file](../api-reference/core/Editable#file) - the [SourceFile](../api-reference/core/SourceFile) that contains this Editable -- Relationship tracking - - [parent_class](../api-reference/core/Editable#parent-class) - the [Class](../api-reference/core/Class) that contains this Editable - - [parent_function](../api-reference/core/Editable#parent-function) - the [Function](../api-reference/core/Function) that contains this Editable - - [parent_statement](../api-reference/core/Editable#parent-statement) - the [Statement](../api-reference/core/Statement) that contains this Editable -- Safe modification operations - -## Basic Editing - -There are several fundamental ways to modify code with Editables: - -```python -# 1. edit() - Replace entire source with new content -function = codebase.get_function("process_data") -function.edit(""" -def process_data(input_data: dict) -> dict: - return transform(input_data) -""") - -# 2. Replace - Substitute text while preserving context -class_def = codebase.get_class("UserModel") -class_def.replace("user_id", "account_id") # Updates all occurrences - -# 3. Remove - Safely delete code with proper cleanup -unused_import = file.get_import("from utils import deprecated_func") -unused_import.remove() # Handles formatting, commas, etc - -# 4. Insert - Add code before or after an element -function.insert_before("# Process user input") # Adds comment before function -function.insert_after(""" -def validate_data(data: dict) -> bool: - return all(required in data for required in REQUIRED_FIELDS) -""") # Adds new function after -``` - -## Finding and Searching - -Editables provide powerful search capabilities: - -```python -# Find string literals -results = function.find_string_literals(["error", "warning"]) -results = function.find_string_literals(["error"], fuzzy_match=True) - -# Search with regex -matches = function.search(r"data\['[^']*'\]") # Find dict access -matches = function.search("TODO:", include_comments=True) - -# Find specific patterns -variables = function.get_variable_usages("config") -function_calls = function.function_calls # All function calls within this node -``` - -## Smart Formatting - -Codegen handles formatting details automatically: - -```python -# Adding to import statements -import_stmt = file.get_import("from mylib import func1") -import_stmt.add_symbol("func2") # Handles comma placement -import_stmt.add_symbol("func3") # Maintains proper formatting - -# Multi-line formatting is preserved -from mylib import ( - func1, - func2, # New imports maintain - func3 # existing style -) -``` - -## Safe Removals - -Removing code elements is safe and clean: - -```python -# Remove a function and its decorators -function.remove() # Removes associated comments and formatting - -# Remove imports cleanly -import_stmt.remove() # Handles commas and whitespace -``` - -## Working with References - -Editables track their relationships to other code elements: - -```python -# Find and update all references -function = codebase.get_function("old_name") -function.rename("new_name") # Updates all usages - -# Navigate relationships -print(function.parent_function) # Containing function -print(function.parent_class) # Containing class -print(function.parent_statement) # Containing statement -``` - -## Understanding Context - -Editables provide rich information about their location and context in the code: - -### Parent Relationships - -```python -# Get containing elements -function = codebase.get_function("process_data") -print(function.parent_class) # Class containing this function -print(function.parent_function) # Function containing this function (for nested functions) -print(function.parent_statement) # Statement containing this function - -# Check if top-level -is_top_level = function.parent_class is None and function.parent_function is None -``` - -### Statement Containment - -The `is_wrapped_in` method lets you check if an Editable is contained within specific types of statements: - -```python -# Check containment in statement types -is_in_try = function.is_wrapped_in("try") -is_in_if = function.is_wrapped_in("if") -is_in_while = function.is_wrapped_in("while") - -# Get the first parent statements of a certain type -if_block = function.parent_of_type(IfStatement) - -# Common patterns -if function.is_wrapped_in(IfStatement): - print("This is in an IfBlock") - -if variable.is_wrapped_in(WithStatement): - print("Variable used in WithStatement") -``` - -### Common Use Cases - -```python -# Move nested functions to module level -for func in file.functions: - if func.parent_function: # This is a nested function - func.parent_function.insert_before(func.source) # Move to module level - func.remove() # Remove the nested function - -# Find variables defined in unsafe blocks -for var in function.code_block.get_local_var_assignments(): - if var.is_wrapped_in(TryStatement): - print(f"Warning: {var.name} defined in try block") -``` - diff --git a/docs/_deprecated/building-with-codegen/traversing-the-call-graph.mdx b/docs/_deprecated/building-with-codegen/traversing-the-call-graph.mdx deleted file mode 100644 index 9152b1aad..000000000 --- a/docs/_deprecated/building-with-codegen/traversing-the-call-graph.mdx +++ /dev/null @@ -1,152 +0,0 @@ ---- -title: "Traversing the Call Graph" -sidebarTitle: "Call Graph" -icon: "sitemap" -iconType: "solid" ---- - -Codegen provides powerful capabilities for analyzing and visualizing function call relationships in your codebase. This guide will show you how to traverse the call graph and create visual representations of function call paths. - -## Understanding Call Graph Traversal - -At the heart of call graph traversal is the [.function_calls](/api-reference/core/Function#function-calls) property, which returns information about all function calls made within a function: - -```python -def example_function(): - result = helper_function() - process_data() - return result - -# Get all calls made by example_function -successors = example_function.function_calls -for successor in successors: - print(f"Call: {successor.source}") # The actual function call - print(f"Called: {successor.function_definition.name}") # The function being called -``` - -## Building a Call Graph - -Here's how to build a directed graph of function calls using NetworkX: - -```python -import networkx as nx -from codegen.sdk.core.interfaces.callable import FunctionCallDefinition -from codegen.sdk.core.function import Function -from codegen.sdk.core.external_module import ExternalModule - -def create_call_graph(start_func, end_func, max_depth=5): - G = nx.DiGraph() - - def traverse_calls(parent_func, current_depth): - if current_depth > max_depth: - return - - # Determine source node - if isinstance(parent_func, Function): - src_call = src_func = parent_func - else: - src_func = parent_func.function_definition - src_call = parent_func - - # Skip external modules - if isinstance(src_func, ExternalModule): - return - - # Traverse all function calls - for call in src_func.function_calls: - func = call.function_definition - - # Skip recursive calls - if func.name == src_func.name: - continue - - # Add nodes and edges - G.add_node(call) - G.add_edge(src_call, call) - - # Check if we reached the target - if func == end_func: - G.add_edge(call, end_func) - return - - # Continue traversal - traverse_calls(call, current_depth + 1) - - # Initialize graph - G.add_node(start_func, color="blue") # Start node - G.add_node(end_func, color="red") # End node - - # Start traversal - traverse_calls(start_func, 1) - return G - -# Usage example -start = codebase.get_function("create_skill") -end = codebase.get_function("auto_define_skill_description") -graph = create_call_graph(start, end) -``` - -## Filtering and Visualization - -You can filter the graph to show only relevant paths and visualize the results: - -```python -# Find all paths between start and end -all_paths = nx.all_simple_paths(graph, source=start, target=end) - -# Create subgraph of only the nodes in these paths -nodes_in_paths = set() -for path in all_paths: - nodes_in_paths.update(path) -filtered_graph = graph.subgraph(nodes_in_paths) - -# Visualize the graph -codebase.visualize(filtered_graph) -``` - -## Advanced Usage - -### Example: Finding Dead Code - -You can use call graph analysis to find unused functions: - -```python -def find_dead_code(codebase): - dead_functions = [] - for function in codebase.functions: - if not any(function.function_calls): - # No other functions call this one - dead_functions.append(function) - return dead_functions -``` - -### Example: Analyzing Call Chains - -Find the longest call chain in your codebase: - -```python -def get_max_call_chain(function): - G = nx.DiGraph() - - def build_graph(func, depth=0): - if depth > 10: # Prevent infinite recursion - return - for call in func.function_calls: - called_func = call.function_definition - G.add_edge(func, called_func) - build_graph(called_func, depth + 1) - - build_graph(function) - return nx.dag_longest_path(G) -``` - - -The `.function_calls` property is optimized for performance and uses Codegen's internal graph structure to quickly traverse relationships. It's much faster than parsing the code repeatedly. - - - -When traversing call graphs, be mindful of: -- Recursive calls that could create infinite loops -- External module calls that might not be resolvable -- Dynamic/runtime function calls that can't be statically analyzed - diff --git a/docs/_deprecated/building-with-codegen/type-annotations.mdx b/docs/_deprecated/building-with-codegen/type-annotations.mdx deleted file mode 100644 index 0ecc9a548..000000000 --- a/docs/_deprecated/building-with-codegen/type-annotations.mdx +++ /dev/null @@ -1,177 +0,0 @@ ---- -title: "Working with Type Annotations" -sidebarTitle: "Type Annotations" -icon: "code" -iconType: "solid" ---- - -This guide covers the core APIs and patterns for working with type annotations in Codegen. - -## Type Resolution - -Codegen builds a complete dependency graph of your codebase, connecting functions, classes, imports, and their relationships. This enables powerful type resolution capabilities: - -```python -from codegen import Codebase - -# Initialize codebase with dependency graph -codebase = Codebase("./") - -# Get a function with a type annotation -function = codebase.get_file("path/to/file.py").get_function("my_func") - -# Resolve its return type to actual symbols -return_type = function.return_type -resolved_symbols = return_type.resolved_types # Returns the actual Symbol objects - -# For generic types, you can resolve parameters -if hasattr(return_type, "parameters"): - for param in return_type.parameters: - resolved_param = param.resolved_types # Get the actual type parameter symbols - -# For assignments, resolve their type -assignment = codebase.get_file("path/to/file.py").get_assignment("my_var") -resolved_type = assignment.type.resolved_types -``` - - - Type resolution follows imports and handles complex cases like type aliases, forward references, and generic type parameters. - - -## Core Interfaces - -Type annotations in Codegen are built on two key interfaces: - -- [Typeable](/api-reference/core/Typeable) - The base interface for any node that can have a type annotation (parameters, variables, functions, etc). Provides `.type` and `.is_typed`. -- [Type](/api-reference/core/Type) - The base class for all type annotations. Provides type resolution and dependency tracking. - -Any node that inherits from `Typeable` will have a `.type` property that returns a `Type` object, which can be used to inspect and modify type annotations. - -Learn more about [inheritable behaviors](/building-with-codegen/inheritable-behaviors) like Typeable here - -## Core Type APIs - -Type annotations can be accessed and modified through several key APIs: - -### Function Types - -The main APIs for function types are [Function.return_type](/api-reference/python/PyFunction#return-type) and [Function.set_return_type](/api-reference/python/PyFunction#set-return-type): - -```python -# Get return type -return_type = function.return_type # -> TypeAnnotation -print(return_type.source) # "List[str]" -print(return_type.is_typed) # True/False - -# Set return type -function.set_return_type("List[str]") -function.set_return_type(None) # Removes type annotation -``` - -### Parameter Types - -Parameters use [Parameter.type](/api-reference/core/Parameter#type) and [Parameter.set_type_annotation](/api-reference/core/Parameter#set-type-annotation): - -```python -for param in function.parameters: - # Get parameter type - param_type = param.type # -> TypeAnnotation - print(param_type.source) # "int" - print(param_type.is_typed) # True/False - - # Set parameter type - param.set_type("int") - param.set_type(None) # Removes type annotation -``` - -### Variable Types - -Variables and attributes use [Assignment.type](/api-reference/core/Assignment#type) and [Assignment.set_type_annotation](/api-reference/core/Assignment#set-type-annotation). This applies to: -- Global variables -- Local variables -- Class attributes (via [Class.attributes](/api-reference/core/Class#attributes)) - -```python -# For global/local assignments -assignment = file.get_assignment("my_var") -var_type = assignment.type # -> TypeAnnotation -print(var_type.source) # "str" - -# Set variable type -assignment.set_type("str") -assignment.set_type(None) # Removes type annotation - -# For class attributes -class_def = file.get_class("MyClass") -for attr in class_def.attributes: - # Each attribute has an assignment property - attr_type = attr.assignment.type # -> TypeAnnotation - print(f"{attr.name}: {attr_type.source}") # e.g. "x: int" - - # Set attribute type - attr.assignment.set_type("int") - -# You can also access attributes directly by index -first_attr = class_def.attributes[0] -first_attr.assignment.set_type("str") -``` - -## Working with Complex Types - -### Union Types - -Union types ([UnionType](/api-reference/core/UnionType)) can be manipulated as collections: - -```python -# Get union type -union_type = function.return_type # -> A | B -print(union_type.symbols) # ["A", "B"] - -# Add/remove options -union_type.append("float") -union_type.remove("None") - -# Check contents -if "str" in union_type.options: - print("String is a possible type") -``` -Learn more about [working with collections here](/building-with-codegen/collections) - -### Generic Types - -Generic types ([GenericType](/api-reference/core/GenericType)) expose their parameters as collection of [Parameters](/api-reference/core/Parameter): - -```python -# Get generic type -generic_type = function.return_type # -> GenericType -print(generic_type.base) # "List" -print(generic_type.parameters) # ["str"] - -# Modify parameters -generic_type.parameters.append("int") -generic_type.parameters[0] = "float" - -# Create new generic -function.set_return_type("List[str]") -``` -Learn more about [working with collections here](/building-with-codegen/collections) - -### Type Resolution - -Type resolution uses [Type.resolved_value](/api-reference/core/Type#resolved-value) to get the actual symbols that a type refers to: - -```python -# Get the actual symbols for a type -type_annotation = function.return_type # -> Type -resolved_types = type_annotation.resolved_value # Returns an Expression, likely a Symbol or collection of Symbols - -# For generic types, resolve each parameter -if hasattr(type_annotation, "parameters"): - for param in type_annotation.parameters: - param_types = param.resolved_value # Get symbols for each parameter - -# For union types, resolve each option -if hasattr(type_annotation, "options"): - for option in type_annotation.options: - option_types = option.resolved_value # Get symbols for each union option -``` diff --git a/docs/_deprecated/building-with-codegen/variable-assignments.mdx b/docs/_deprecated/building-with-codegen/variable-assignments.mdx deleted file mode 100644 index 1dfc17df7..000000000 --- a/docs/_deprecated/building-with-codegen/variable-assignments.mdx +++ /dev/null @@ -1,84 +0,0 @@ ---- -title: "Variable Assignments" -sidebarTitle: "Variable Assignments" -icon: "equals" -iconType: "solid" ---- - -Codegen's enables manipulation of variable assignments via the following classes: - -- [AssignmentStatement](../api-reference/core/AssignmentStatement) - A statement containing one or more assignments -- [Assignment](../api-reference/core/Assignment) - A single assignment within an AssignmentStatement - - -### Simple Value Changes - -Consider the following source code: - -```typescript -const userId = 123; -const [userName, userAge] = ["Eve", 25]; -``` - -In Codegen, you can access assignments with the [get_local_var_assignment](../api-reference/core/CodeBlock#get-local-var-assignment) method. - -You can then manipulate the assignment with the [set_value](../api-reference/core/Assignment#set-value) method. - -```python -id_assignment = file.code_block.get_local_var_assignment("userId") -id_assignment.set_value("456") - -name_assignment = file.code_block.get_local_var_assignment("name") -name_assignment.rename("userName") -``` - - - Assignments inherit both [HasName](/api-reference/core/HasName) and - [HasValue](/api-reference/core/HasValue) behaviors. See [Inheritable - Behaviors](/building-with-codegen/inheritable-behaviors) for more details. - - -### Type Annotations - -Similarly, you can set type annotations with the [set_type_annotation](../api-reference/core/Assignment#set-type-annotation) method. - -For example, consider the following source code: - -```typescript -let status; -const data = fetchData(); -``` - -You can manipulate the assignments as follows: - -```python -status_assignment = file.code_block.get_local_var_assignment("status") -status_assignment.set_type_annotation("Status") -status_assignment.set_value("Status.ACTIVE") - -data_assignment = file.code_block.get_local_var_assignment("data") -data_assignment.set_type_annotation("ResponseData") - -# Result: -let status: Status = Status.ACTIVE; -const data: ResponseData = fetchData(); -``` - -## Tracking Usages and Dependencies - -Like other symbols, Assignments support [usages](/api-reference/core/Assignment#usages) and [dependencies](/api-reference/core/Assignment#dependencies). - -```python -assignment = file.code_block.get_local_var_assignment("userId") - -# Get all usages of the assignment -usages = assignment.usages - -# Get all dependencies of the assignment -dependencies = assignment.dependencies -``` - - - See [Dependencies and Usages](/building-with-codegen/dependencies-and-usages) - for more details. - diff --git a/docs/_deprecated/cli/about.mdx b/docs/_deprecated/cli/about.mdx deleted file mode 100644 index 8d4fa938b..000000000 --- a/docs/_deprecated/cli/about.mdx +++ /dev/null @@ -1,61 +0,0 @@ ---- -title: "Codegen CLI" -sidebarTitle: "Overview" -icon: "square-info" -iconType: "solid" ---- - -The Codegen CLI helps you: - -- Initialize Codegen in your repository -- Create and run codemods -- Work with AI assistance - - - For installation instructions, see our [Getting - Started](/introduction/getting-started) guide. - - -## Getting Started - -1. **Initialize Codegen** in your repository: - -```bash -codegen init -``` - -2. **Create your first codemod**: - -```bash -codegen create my-codemod --description "What you want to accomplish" -``` - -The `--description` flag enables AI assistance to help generate your codemod. Be as specific as possible about what you want to achieve. - -## Available Commands - - - - Initialize Codegen in your repository. - - - Create new codemods with optional AI assistance. - - - Execute codemods with various options. - - - Get help from the Codegen AI expert. - - - -## Working with AI - -When using Cursor, you can mention `@codegen-sh` in any chat or composer window to get: - -- Documentation about available APIs -- Context about your active codemod -- Examples of similar codemods -- Relevant code snippets - -The AI uses this context to provide accurate and helpful responses about working with Codegen. diff --git a/docs/_deprecated/cli/create.mdx b/docs/_deprecated/cli/create.mdx deleted file mode 100644 index 938e974e3..000000000 --- a/docs/_deprecated/cli/create.mdx +++ /dev/null @@ -1,90 +0,0 @@ ---- -title: "Create Command" -sidebarTitle: "create" -icon: "plus" -iconType: "solid" ---- - -The `create` command generates a new codemod function with the necessary boilerplate. - -```bash -codegen create rename-function . -``` - -## Usage - -```bash -codegen create NAME PATH [OPTIONS] -``` - -## Arguments - -- `NAME`: The name of the codemod to create (e.g., "rename-function") -- `PATH`: The path where the codemod should be created (e.g., "." for current directory) - -## Options - -- `--description`, `-d`: A description of what the codemod should do. This will be used to generate an AI-powered implementation. - -## Generated Files - -When you run `codegen create rename-function .`, it creates: - -``` -.codegen/ -└── codemods/ - └── rename_function/ - β”œβ”€β”€ rename_function.py # The codemod implementation - └── rename_function-system-prompt.txt # System prompt (if --description used) -``` - -The generated codemod will have this structure: - -```python -import codegen -from codegen import Codebase - -@codegen.function("rename-function") -def run(codebase: Codebase): - """Add a description of what this codemod does.""" - # Add your code here - print('Total files: ', len(codebase.files)) - print('Total functions: ', len(codebase.functions)) - print('Total imports: ', len(codebase.imports)) - -if __name__ == "__main__": - print('Parsing codebase...') - codebase = Codebase("./") - - print('Running...') - run(codebase) -``` - -## Examples - -Create a basic codemod: -```bash -codegen create rename-function . -``` - -Create with an AI-powered implementation: -```bash -codegen create rename-function . -d "Rename the getUserData function to fetchUserProfile" -``` - -## Next Steps - -After creating a codemod: -1. Edit the implementation in the generated .py file -2. Test it with `codegen run rename-function` -3. Deploy it for team use with `codegen deploy rename-function` - -## Common Issues - -If you see "File already exists": -1. Choose a different name for your codemod, or -2. Use the `--overwrite` flag to replace the existing file - - -The codemod name will be converted to snake_case for the Python file (e.g., `update-imports` becomes `update_imports.py`). - diff --git a/docs/_deprecated/cli/expert.mdx b/docs/_deprecated/cli/expert.mdx deleted file mode 100644 index c6ecc5e91..000000000 --- a/docs/_deprecated/cli/expert.mdx +++ /dev/null @@ -1,61 +0,0 @@ ---- -title: "Expert Command" -sidebarTitle: "expert" -icon: "robot" -iconType: "solid" ---- - -The `expert` command gives you direct access to Codegen's AI expert, which is specifically trained to help with codemods, transformations, and Codegen's APIs. - -## Usage - -```bash -codegen expert --query "your question here" -``` - -## Options - -- `--query`, `-q`: The question to ask the expert - -## Examples - -Ask about a specific API: -```bash -codegen expert -q "How do I use codebase.find_function() to locate all async functions?" -``` - -Get help with a transformation: -```bash -codegen expert -q "What's the best way to rename a function and all its references?" -``` - -Ask about best practices: -```bash -codegen expert -q "What's the recommended way to handle error cases in codemods?" -``` - -## Use Cases - -The expert is particularly helpful for: -- Understanding Codegen's APIs and capabilities -- Getting guidance on codemod implementation strategies -- Learning best practices for code transformations -- Troubleshooting common issues -- Finding the right approach for complex refactoring tasks - - -The expert has deep knowledge of Codegen's internals and common transformation patterns. For general programming questions, consider using standard AI assistants instead. - - -## Tips - -1. Be specific in your questions -2. Include relevant context about your codebase or transformation -3. Ask follow-up questions if needed -4. Use code examples in your questions when applicable - -## Related Commands - -- `codegen create`: Create new codemods with AI assistance -- `codegen run`: Execute your codemods -- `codegen docs-search`: Search documentation and examples diff --git a/docs/_deprecated/cli/init.mdx b/docs/_deprecated/cli/init.mdx deleted file mode 100644 index 5c37df415..000000000 --- a/docs/_deprecated/cli/init.mdx +++ /dev/null @@ -1,114 +0,0 @@ ---- -title: "Init Command" -sidebarTitle: "init" -icon: "power-off" -iconType: "solid" ---- - -The `init` command sets up Codegen in your repository, creating necessary configuration files and pulling documentation locally. - -## Usage - -```bash -codegen init [OPTIONS] -``` - -## Options - -- `--repo-name`: The name of the repository (defaults to current git repo name) -- `--organization-name`: The name of the organization (defaults to git organization) - -## Directory Structure - -When you run `init`, Codegen creates a `.codegen` directory in your repository with the following structure: - -``` -.codegen/ -β”œβ”€β”€ config.toml # Configuration file with repo and org info -β”œβ”€β”€ codemods/ # Your codemods live here -β”‚ └── my_codemod.py # Created via `codegen create my-codemod` -β”œβ”€β”€ docs/ # Local documentation for offline access -β”‚ β”œβ”€β”€ api/ -β”‚ β”œβ”€β”€ examples/ -β”‚ └── tutorials/ -└── prompts/ # Generated system prompts for AI assistance -``` - - - Only `config.toml` and the `codemods/` directory are tracked in Git. The rest - of the `.codegen` directory is automatically added to your `.gitignore`. - - -This setup allows you to: - -- Track and version your codemods with your repository -- Use `codebase.reset()` without losing progress on your codemod implementation -- Share codemods with your team through version control - -## Recommended Structure - -We recommend keeping your Codegen codemods in the `.codegen/codemods/` directory (this is the default when using `codegen create`). This: - -- Keeps transformation code separate from your application code -- Makes it easy to find and manage all your codemods -- Ensures consistent behavior with `codebase.reset()` - -## Local Documentation - -Codegen pulls documentation and examples locally to: - -- Provide offline access to guides and references -- Enable AI to give contextual help about your codebase -- Allow searching through examples and tutorials - -## Requirements - -The command must be run from within a git repository. If you're not in one, you'll need to: - -```bash -git init -git remote add origin -codegen init -``` - -## Examples - -Initialize with default settings (uses git repo info): - -```bash -codegen init -``` - -Initialize with custom organization and repo: - -```bash -codegen init --organization-name "my-org" --repo-name "my-project" -``` - -## Next Steps - -After initializing: - -1. Create your first codemod: - -```bash -codegen create my-function . -d "describe what you want to do" -``` - -Note: The second parameter (`.`) specifies the path where the codemod should be created. This is required. - -2. Run it: - -```bash -codegen run my-function --apply-local -``` - -## Updating - -You can run `init` again to update your local documentation and configuration: - -```bash -codegen init -``` - -This will refresh the `.codegen` directory while preserving your existing configuration. diff --git a/docs/_deprecated/cli/login.mdx b/docs/_deprecated/cli/login.mdx deleted file mode 100644 index 6b9f1f340..000000000 --- a/docs/_deprecated/cli/login.mdx +++ /dev/null @@ -1,85 +0,0 @@ ---- -title: "Login Command" -sidebarTitle: "login" -icon: "right-to-bracket" -iconType: "solid" ---- - -The `login` command authenticates you with Codegen's services, enabling access to AI features and private codemods. - -## Usage - -```bash -codegen login [--token ] -``` - -## Options - -- `--token `: Directly provide an authentication token instead of using browser-based authentication - -## Authentication Flow - -1. **Browser Authentication** (Default): - ```bash - codegen login - ``` - This will: - - Open your default browser - - Direct you to the Codegen authentication page - - Automatically complete authentication when you log in - -2. **Token Authentication**: - ```bash - codegen login --token your-token-here - ``` - Useful for: - - CI/CD environments - - Machines without browsers - - Automated scripts - -## Validation - -After logging in, Codegen will: -1. Validate your credentials -2. Store the authentication token securely -3. Configure your environment for subsequent commands - -## Environment Variables - -- `CODEGEN_TOKEN`: Alternative way to provide authentication token -- `ENV`: Set to `prod` or `staging` to specify environment - -## Examples - -```bash -# Standard login with browser -codegen login - -# Login with specific token -codegen login --token abc123 - -# Login to production -ENV=prod codegen login -``` - -## Common Issues - -1. **Browser doesn't open**: - - Use the `--token` option instead - - Check your default browser settings - -2. **Token expired**: - - Simply run `codegen login` again - - New token will replace the old one - -3. **Permission issues**: - - Ensure you have the correct permissions - - Contact support if problems persist - - -Your authentication token is stored securely in your system's credential storage. - - - -Never share your authentication token or commit it to version control. - \ No newline at end of file diff --git a/docs/_deprecated/cli/notebook.mdx b/docs/_deprecated/cli/notebook.mdx deleted file mode 100644 index 4941f1a94..000000000 --- a/docs/_deprecated/cli/notebook.mdx +++ /dev/null @@ -1,74 +0,0 @@ ---- -title: "Notebook Command" -sidebarTitle: "notebook" -description: "Open a Jupyter notebook with the current codebase loaded" -icon: "book" -iconType: "solid" ---- - -The `notebook` command launches a Jupyter Lab instance with a pre-configured notebook for exploring your codebase. - -## Usage - -```bash -codegen notebook [--background] -``` - -### Options - -- `--background`: Run Jupyter Lab in the background (default: false) - -By default, Jupyter Lab runs in the foreground, making it easy to stop with Ctrl+C. Use `--background` if you want to run it in the background. - -## What it Does - -This will: - -1. Create a Python virtual environment in `.codegen/.venv` if it doesn't exist -2. Install required packages (codegen and jupyterlab) -3. Create a starter notebook in `.codegen/jupyter/tmp.ipynb` -4. Launch Jupyter Lab with the notebook open - -The notebook comes pre-configured with: - -```python -from codegen import Codebase - -# Initialize codebase -codebase = Codebase('../../') -``` - - - The notebook is created in `.codegen/jupyter/`, so the relative path `../../` - points to your repository root. - - -## Directory Structure - -After running `codegen notebook`, your repository will have this structure: - -``` -.codegen/ -β”œβ”€β”€ .venv/ # Virtual environment for this project -β”œβ”€β”€ jupyter/ # Jupyter notebooks -β”‚ └── tmp.ipynb # Pre-configured notebook -└── config.toml # Project configuration -``` - -## Examples - -```bash -# Run Jupyter in the foreground (default) -codegen notebook - -# Run Jupyter in the background -codegen notebook --background - -# Initialize a new repository and launch notebook -codegen init && codegen notebook -``` - - - The notebook command will automatically initialize codegen if needed, so you - can run it directly in a new repository. - diff --git a/docs/_deprecated/cli/reset.mdx b/docs/_deprecated/cli/reset.mdx deleted file mode 100644 index 756bdfb40..000000000 --- a/docs/_deprecated/cli/reset.mdx +++ /dev/null @@ -1,46 +0,0 @@ ---- -title: "Reset Command" -sidebarTitle: "reset" -icon: "rotate-left" -iconType: "solid" ---- - -The `reset` command performs a hard reset of your git repository while carefully preserving all files in the `.codegen` directory. This is useful for undoing codemod changes while keeping your codemod implementations intact. - -## Usage - -```bash -codegen reset -``` - -## What it Does - -When you run `codegen reset`, it: - -1. Backs up all files in `.codegen` directory, preserving their content and staged/unstaged status -2. Performs a hard reset (`git reset --hard HEAD`) on the repository -3. Restores all `.codegen` files to their previous state, including their git staging status -4. Removes untracked files (except those in `.codegen`) - - -This is more sophisticated than `git checkout .` as it: -- Preserves both staged and unstaged changes in `.codegen` -- Handles deleted files correctly -- Removes untracked files (like `git clean`) while protecting `.codegen` - - -## Examples - -Reset after testing a codemod: -```bash -# Run your codemod -codegen run organize-imports - -# If the changes aren't what you wanted -codegen reset # Reverts changes but keeps your codemod implementation -``` - - - -This command performs a hard reset and removes untracked files. Make sure you have committed any changes you want to keep outside of `.codegen`. - diff --git a/docs/_deprecated/cli/run.mdx b/docs/_deprecated/cli/run.mdx deleted file mode 100644 index 3adce12a4..000000000 --- a/docs/_deprecated/cli/run.mdx +++ /dev/null @@ -1,65 +0,0 @@ ---- -title: "Run Command" -sidebarTitle: "run" -icon: "play" -iconType: "solid" ---- - -The `run` command executes a codemod against your local codebase, showing you the changes and applying them to your filesystem. - -```bash -codegen run rename-function -``` - -## Usage - -```bash -codegen run LABEL [OPTIONS] -``` - -## Arguments - -- `LABEL`: The name of the codemod to run (e.g., "rename-function") - -## Options - -- `--diff-preview N`: Show a preview of the first N lines of the diff -- `--arguments JSON`: Pass arguments to the codemod as a JSON string (required if the codemod expects arguments) - -## Examples - -Run a codemod: -```bash -codegen run rename-function -``` - -Run with a diff preview limited to 50 lines: -```bash -codegen run rename-function --diff-preview 50 -``` - -Run with arguments (for codemods that require them): -```bash -codegen run rename-function --arguments '{"old_name": "getUserData", "new_name": "fetchUserProfile"}' -``` - -## Output - -The command will: -1. Parse your codebase -2. Run the codemod -3. Show a diff preview (if requested) -4. Apply changes to your filesystem - -## Execution Flow - -When you run a codemod: -1. Codegen parses your entire codebase into a graph representation -2. The codemod function is executed against this graph -3. Any changes made by the codemod are tracked -4. Changes are automatically applied to your local files -5. A summary of changes is displayed - - -The codebase parsing step may take a few moments for larger codebases. Learn more in [How it Works](/introduction/how-it-works.mdx) - diff --git a/docs/_deprecated/cli/update.mdx b/docs/_deprecated/cli/update.mdx deleted file mode 100644 index f4bda0b12..000000000 --- a/docs/_deprecated/cli/update.mdx +++ /dev/null @@ -1,67 +0,0 @@ ---- -title: "Update Command" -sidebarTitle: "update" -icon: "sync" -iconType: "solid" ---- - -The `update` command is designed to help you manage the version of Codegen installed on your system. Whether you want to update to the latest version or switch to a specific version, this command offers a streamlined way to do so. Additionally, you can list all supported versions available on PyPI. - -```bash -codegen update [OPTIONS] -``` - -## Usage - -```bash -codegen update [OPTIONS] -``` - -## Options - -- `--list, -l`: List all supported versions of Codegen. - When used, the command fetches the available releases from PyPI, filters them to display a range of versions (typically including the current version and a few preceding minor versions), and highlights the current version in the output. - -- `--version, -v`: Update to a specific version of Codegen (e.g., `2.1.0`). - This option enables you to target a particular version rather than updating to the latest available release. - -## Examples - -Update Codegen to the latest version: -```bash -codegen update -``` - -List all supported versions of Codegen: -```bash -codegen update --list -``` - -Update Codegen to a specific version: -```bash -codegen update --version 2.1.0 -``` - -## Execution Flow - -When you run the `update` command, the following steps occur: - -1. **Retrieve Current Version:** - The command retrieves the current version of Codegen by accessing package metadata. - -2. **Option Handling:** - - **Listing Versions:** - If you use the `--list` flag, the command fetches all available releases from PyPI, filters them based on a defined range (typically covering future versions and a couple of previous minor versions), and prints the list with the current version highlighted. - - - **Specific Version Update:** - If the `--version` option is provided, the command installs the specified version by invoking `pip install` with the exact version (e.g., `pip install codegen==2.1.0`). - - - **Default Update:** - If no options are provided, the command updates Codegen to the latest version using `pip install --upgrade`. - -3. **Error Handling:** - The command checks for mutually exclusive options. If both `--list` and `--version` are specified simultaneously, an error is raised. - - -Ensure you use either `--list` or `--version` when running the update command, not both. - \ No newline at end of file diff --git a/docs/_deprecated/graph-sitter/about.mdx b/docs/_deprecated/graph-sitter/about.mdx deleted file mode 100644 index d7ffe80a1..000000000 --- a/docs/_deprecated/graph-sitter/about.mdx +++ /dev/null @@ -1,72 +0,0 @@ ---- -title: "Codegen, Inc." -sidebarTitle: "About Us" -icon: "building" -iconType: "solid" ---- - - - -## Our Mission - -Our mission is to build fully-autonomous software engineering - the equivalent of self-driving cars for code. - -We believe the highest leverage path to autonomous development is enabling AI agents to "act via code." - -Just as self-driving cars need sophisticated sensors and controls to navigate the physical world, AI agents need powerful, precise tools to manipulate codebases. We're building that foundational layer: a programmatic interface that lets AI agents express complex code transformations through code itself. - -This approach creates a shared language that both humans and AI can use to: - -- Express powerful changes with precision and predictability -- Build sophisticated tools from primitive operations -- Create and maintain their own abstractions -- Scale transformations across massive codebases - -## The Team - -Based in San Francisco, we're a team of engineers and researchers passionate about: - -- Making large-scale code changes more accessible -- Building tools that work the way developers think -- Creating the infrastructure for AI-powered code manipulation -- Advancing the state of the art in program transformation - -## Open Source - -We believe in the power of open source software. Our core library, [codegen](https://github.com/codegen-sh/codegen-sdk), is freely available and open to contributions from the community. - -## Join Us - - - - We're hiring! Join us in building the future of code transformation. - - - Connect with other developers and share your Codegen experiences. - - - -## Connect with Us - - - - Follow us for updates and announcements - - - Connect with our team and stay updated on company news - - - - - Want to learn more about what we're building? Check out our [getting started - guide](/introduction/getting-started) or join our [community - Slack](https://community.codegen.com). - diff --git a/docs/_deprecated/graph-sitter/advanced-settings.mdx b/docs/_deprecated/graph-sitter/advanced-settings.mdx deleted file mode 100644 index 08f0e5472..000000000 --- a/docs/_deprecated/graph-sitter/advanced-settings.mdx +++ /dev/null @@ -1,404 +0,0 @@ ---- -title: "Advanced Settings" -sidebarTitle: "Advanced Settings" -icon: "memory" -iconType: "solid" ---- - -Codegen's [Codebase](/api-reference/core/Codebase) constructor accepts a `CodebaseConfig` object which is used to configure more advanced behaviors of the graph construction process. - -These flags are helpful for debugging problematic repos, optimizing Codegen's performance, or testing unreleased or experimental (potentially backwards-breaking) features. - - -**These are considered experimental features and may change in the future!** - -As such, they may have little to no testing or documentation. Many of these flags may also be unsupported in the future! - -If you need help, please visit our [community](/introduction/community). - - - -These configuration options are defined in [src/codegen/configs/models/codebase.py](https://github.com/codegen-sh/codegen/blob/develop/src/codegen/configs/models/codebase.py). - - -# Usage - -You can customize the behavior of the graph construction process when initializing a [Codebase](/api-reference/core/Codebase) by passing a `CodebaseConfig` object with the desired configuration flags. - -```python -from codegen import Codebase -from codegen.configs import CodebaseConfig - -# Initialize a Codebase with custom configuration -codebase = Codebase( - "", - config=CodebaseConfig( - flag1=..., - flag2=..., - ... - ) -) -``` - -# Table of Contents - -- [debug](#flag-debug) -- [verify-graph](#flag-verify-graph) -- [track-graph](#flag-track-graph) -- [method-usages](#flag-method-usages) -- [sync-enabled](#flag-sync-enabled) -- [full-range-index](#flag-full-range-index) -- [ignore-process-errors](#flag-ignore-process-errors) -- [disable-graph](#flag-disable-graph) -- [disable-file-parse](#flag-disable-file-parse) -- [exp-lazy-graph](#flag-exp-lazy-graph) -- [generics](#flag-generics) -- [import-resolution-paths](#flag-import-resolution-paths) -- [import-resolution-overrides](#flag-import-resolution-overrides) -- [py-resolve-syspath](#flag-py-resolve-syspath) -- [ts-dependency-manager](#flag-ts-dependency-manager) -- [ts-language-engine](#flag-ts-language-engine) -- [v8-ts-engine](#flag-v8-ts-engine) -- [unpacking-assignment-partial-removal](#flag-unpacking-assignment-partial-removal) - -# Configuration Flags - -## Flag: `debug` -> **Default: `False`** - -Enables verbose logging for debugging purposes. In its current form, it enables: -- Verbose logging when adding nodes to the graph -- Verbose logging during initial file parsing -- Additional assertions on graph creation -- Additional (costly) debug metrics on codebase construction -- etc. - - -This flag may be very noisy and significantly impact performance. It is generally not recommended to use. - - -## Flag: `verify_graph` -> **Default: `False`** - -Adds assertions for graph state during reset resync. Used to test and debug graph desyncs after a codebase reset. - -Runs `post_reset_validation` after a reset resync. - - -This is an internal debug flag. - - -## Flag: `track_graph` -> **Default: `False`** - -Keeps a copy of the original graph before a resync. Used in conjunction with `verify_graph` to test and debug graph desyncs. - -Original graph is saved as `ctx.old_graph`. - - -This is an internal debug flag. - - -## Flag: `method_usages` -> **Default: `True`** - -Enables and disables resolving method usages. - -**Example Codebase:** -```python -class Foo: - def bar(): - ... - -obj = Foo() -obj.bar() # Method Usage -``` - -**Codemod with `method_usages` on:** -```python -bar_func = codebase.get_class("Foo").get_method("bar") -len(bar_func.usages) # 1 -bar_func.usages # [obj.bar()] -``` - -**Codemod with `method_usages` off:** -```python -bar_func = codebase.get_class("Foo").get_method("bar") -len(bar_func.usages) # 0 -bar_func.usages # [] -``` - -Method usage resolution could be disabled for a marginal performance boost. However, it is generally recommended to leave it enabled. - -## Flag: `sync_enabled` -> **Default: `False`** - -Enables or disables graph sync during `codebase.commit`. - - -Implementation-specific details on sync graph can be found [here](https://github.com/codegen-sh/codegen/blob/develop/architecture/6.%20incremental-computation/C.%20Graph%20Recomputation.md). - - -This section won't go into the specific details of sync graph, but the general idea is that enabling sync graph will update the Codebase object to whatever new changes were made. - -**Example with `sync_enabled` on:** -```python -file = codebase.get_file(...) -file.insert_after("foobar = 1") -codebase.commit() - -foobar = codebase.get_symbol("foobar") -assert foobar # foobar is available after commit / graph sync -``` - -**Example with `sync_enabled` disabled:** -```python -file = codebase.get_file(...) -file.insert_after("foobar = 1") - -foobar = codebase.get_symbol("foobar", optional=True) -assert not foobar # foobar is not available after commit -``` - - -Enabling sync graph will have a performance impact on codebase commit, but will also unlock a bunch of operations that were previously not possible. - - -## Flag: `full_range_index` -> **Default: `False`** - -By default, Codebase maintains an internal range-to-node index for fast lookups. (i.e. `bytes 120 to 130 maps to node X`). -For optimization purposes, this only applies to nodes defined and handled by `parser.py`. - -Enabling `full_range_index` will create an additional index that maps **all** tree-sitter ranges to nodes. -This can be useful for debugging or when you need to build any applications that require a full range-to-node index (i.e. a codebase tree lookup). - - -This flag **significantly** increases memory usage! - - -## Flag: `ignore_process_errors` -> **Default: `True`** - -Controls whether to ignore errors that occur during external process execution (such as dependency manager or language engine). - -Disabling `ignore_process_errors` would make Codegen fail on errors that would otherwise be logged then ignored. - -## Flag: `disable_graph` -> **Default: `False`** - -Disables the graph construction process. Any operations that require the graph will no longer work. (In other words, this turns off import resolution and usage/dependency resolution) - -Functions that operate purely on AST such as getting and editing parameters or modifying function and class definitions will still work. - - -For codemods that do not require the graph (aka only AST/Syntax-level changes), **disabling graph parse could yield a 30%-40% decrease in parse time and memory usage**! - - -## Flag: `disable_file_parse` -> **Default: `False`** - -Disables **ALL** parsing, including file and graph parsing. This essentially treats all codebases as the "UNSUPPORTED" language mode. - -Nearly all functions except for editing primitives like `codebase.get_file` and `file.edit` will no longer work. - - -This flag is useful for any usages of Codegen that do **NOT** require any AST/CST/Graph parsing. (i.e. using Codegen purely as a file editing harness) - -If this is your use case, this **could decrease parse and memory usage by 95%.** - - -## Flag: `exp_lazy_graph` -> **Default: `False`** - -This experimental flag pushes the graph creation back until the graph is needed. This is an experimental feature and may have some unintended consequences. - -**Example Codemod:** -```python -from codegen import Codebase -from codegen.configs import CodebaseConfig - -# Enable lazy graph parsing -codebase = Codebase("", config=CodebaseConfig(exp_lazy_graph=True)) - -# The codebase object will be created immediately with no parsing done -# These all do not require graph parsing -codebase.files -codebase.directories -codebase.get_file("...") - -# These do require graph parsing, and will create the graph only if called -codebase.get_function("...") -codebase.get_class("...") -codebase.imports -``` - - -This may have a very slight performance boost. Use at your own risk! - - -## Flag: `generics` -> **Default: `True`** - -Enables and disables generic type resolution. - -**Example Codebase:** -```python -class Point: - def scale(cls, n: int): - pass - -class List[T](): - def pop(self) -> T: - ... - -l: List[Point] = [] -l.pop().scale(1) # Generic Usage -``` - -**Codemod with `generics` on:** -```python -bar_func = codebase.get_class("Point").get_method("scale") -len(bar_func.usages) # 1 -bar_func.usages # [l.pop().scale(1)] -``` - -**Codemod with `generics` off:** -```python -bar_func = codebase.get_class("Point").get_method("scale") -len(bar_func.usages) # 0 -bar_func.usages # [] -``` - - -Generic resolution is still largely WIP and experimental, and may not work in all cases. In some rare circumstances, disabling generics may result in a significant performance boost. - - -## Flag: `import_resolution_paths` -> **Default: `[]`** - -Controls alternative paths to resolve imports from. - -**Example Codebase:** -```python -# a/b/c/src.py -def update(): - pass - -# consumer.py -from c import src as operations - -operations.update() -``` - -**Codemod:** -```python -codebase.ctx.config.import_resolution_paths = ["a/b"] -``` - -## Flag: `import_resolution_overrides` -> **Default: `{}`** - -Controls import path overrides during import resolution. - -**Example** -`from a.b.c import d` with the override `a/b` -> `foo/bar` will internally resolve the import as `from foo.bar.c import d`. - -## Flag: `py_resolve_syspath` -> **Default: `False`** - -Enables and disables resolution of imports from `sys.path`. - - -For this to properly work, you must also set `allow_external` to `True`. - - -## Flag: `allow_external` -> **Default: `False`** - -Enables resolving imports, files, modules, and directories from outside of the repo path. - - -Turning this flag off may allow for bad actors to access files outside of the repo path! Use with caution! - - -## Flag: `ts_dependency_manager` -> **Default: `False`** - - -**This is an internal flag used for Codegen Cloud and should not be used externally!** - -This flag **WILL** nuke any existing `node_modules` folder! - - - -This flag also assumes many constants for Codegen Cloud. Very likely this will not work if run locally. - -Instead, just install `node_modules` as normal (either through `npm`, `pnpm`, or `yarn`) and skip this setting! - - -Enables Codegen's internal dependency installer for TypeScript. This will modify `package.json` and install the bare minimum set of installable dependencies. - - -More documentation on TypeScript dependency manager can be found [here](https://github.com/codegen-sh/codegen/blob/develop/architecture/external/dependency-manager.md) - - -## Flag: `ts_language_engine` -> **Default: `False`** - - -This feature was built primarily with Codegen Cloud in mind. As such, this assumes a valid NodeJS and TypeScript environment. - - -Enables using the TypeScript compiler to extract information from the codebase. Enables commands such as `inferred_return_type`. - - -This will increase memory usage and parsing time. Larger repos may even hit resource constraints with the bundled TypeScript compiler integration. - - -## Flag: `v8_ts_engine` -> **Default: `False`** - - -This feature flag requires `ts_language_engine` to be enabled as well. - - -Enables using the **V8-based TypeScript compiler** to extract information from the codebase. Enables commands such as `inferred_return_type`. - -The V8 implementation (as opposed to the default external-process based implementation) is less stable, but provides the entire TypeScript API to be used from within Codegen. - - -This will increase memory usage and parsing time. Larger repos may even hit resource constraints with the V8-based TypeScript compiler integration. - - -## Flag: `unpacking_assignment_partial_removal` -> **Default: `False`** - -Enables smarter removal of unpacking assignments. - -**Example Codebase:** -```python -a, b, c = (1, 2, 3) -``` - -**Codemod with `unpacking_assignment_partial_removal` on:** -```python -file = codebase.get_file(...) -b = file.get_symbol("b") -b.remove() -codebase.commit() - -file.symbols # [a, c] -file.source # "a, c = (1, 3)" -``` - -**Codemod with `unpacking_assignment_partial_removal` off:** -```python -file = codebase.get_file(...) -b = file.get_symbol("b") -b.remove() -codebase.commit() - -file.symbols # [] -file.source # "" -``` diff --git a/docs/_deprecated/graph-sitter/community.mdx b/docs/_deprecated/graph-sitter/community.mdx deleted file mode 100644 index ed02a4276..000000000 --- a/docs/_deprecated/graph-sitter/community.mdx +++ /dev/null @@ -1,48 +0,0 @@ ---- -title: "Community & Contributing" -sidebarTitle: "Community" -icon: "people-group" -iconType: "solid" ---- - -import { - COMMUNITY_SLACK_URL, - CODEGEN_SDK_GITHUB_URL, -} from "/snippets/links.mdx"; - -Join the growing Codegen community! We're excited to have you be part of our journey to make codebase manipulation and transformation more accessible. - - - - Connect with the community, get help, and share your Codegen projects in our - active Slack workspace. - - - Star us on GitHub, report issues, submit PRs, and contribute to the project. - - - Follow us for updates, tips, and community highlights. - - - Learn how to use Codegen effectively with our comprehensive guides. - - - - - Please help us improve this library and documentation by submitting a PR! - - -## Contributing - -We welcome contributions of all kinds! Whether you're fixing a typo in documentation, reporting a bug, or implementing a new feature, we appreciate your help in making Codegen better. - -Check out our [Contributing Guide](https://github.com/codegen-sh/codegen-sdk/blob/develop/CONTRIBUTING.md) on GitHub to learn how to: - -- Set up your development environment -- Submit pull requests -- Report issues -- Contribute to documentation diff --git a/docs/_deprecated/graph-sitter/faq.mdx b/docs/_deprecated/graph-sitter/faq.mdx deleted file mode 100644 index d7f3abfba..000000000 --- a/docs/_deprecated/graph-sitter/faq.mdx +++ /dev/null @@ -1,58 +0,0 @@ ---- -title: "Frequently Asked Questions" -sidebarTitle: "FAQ" -icon: "square-question" -iconType: "solid" ---- - - - - Codegen currently parses two languages: - - [Python](/api-reference/python) - - [TypeScript](/api-reference/typescript) - - We're actively working on expanding language support based on community needs. - - Learn more about how Codegen handles language specifics in the [Language - Support](/building-with-codegen/language-support) guide. - - - Interested in adding support for your language? [Let us know](https://x.com/codegen) or [contribute](/introduction/community)! - - - - - Pretty much! Codegen is roughly on par with `mypy` and `tsc`. There are always edge cases in static analysis that are provably impossible to get (for example doing `eval()` on a string), but all of Codegen's APIs are intended to be exact unless otherwise specified. Please reach out if you find an edge case and we will do our best to patch it. - - - Yes! Codegen was developed on multmillion-line Python and Typescript codebases - and includes optimizations for handling large-scale transformations. - - For enterprise support, please reach out to [team@codegen.com](mailto:team@codegen.com) - - - - Yes - [by design](/introduction/guiding-principles#python-first-composability). - - Codegen works like any other python package. It works alongside your IDE, version control system, and other development tools. - - - Start by trying out Codegen, joining our [Slack community](https://community.codegen.com), and looking for - issues labeled "good first issue" on [GitHub](https://github.com/codegen-sh/codegen-sdk). We welcome contributions to - documentation, examples, and code improvements. - - - Yes, Codegen is [open source](https://github.com/codegen-sh/codegen-sdk) and free to use under the [Apache 2.0 - license](https://github.com/codegen-sh/codegen-sdk?tab=Apache-2.0-1-ov-file). - You can use it for both personal and commercial projects. - - - The best places to get help are: - 1. Our community [Slack channel](https://community.codegen.com) - 2. [GitHub issues](https://github.com/codegen-sh/codegen-sdk) for bug reports - 3. Reach out to us on [Twitter](https://x.com/codegen) - - diff --git a/docs/_deprecated/graph-sitter/getting-started.mdx b/docs/_deprecated/graph-sitter/getting-started.mdx deleted file mode 100644 index ad9e2c5f2..000000000 --- a/docs/_deprecated/graph-sitter/getting-started.mdx +++ /dev/null @@ -1,342 +0,0 @@ ---- -title: "Getting Started" -sidebarTitle: "Getting Started" -icon: "bolt" -iconType: "solid" ---- - -A quick tour of Codegen in a Jupyter notebook. - -## Installation - -Install [codegen](https://pypi.org/project/codegen/) on Pypi via [uv](https://github.com/astral-sh/uv): - -```bash -uv tool install codegen -``` - -## Quick Start with Jupyter - -The [codegen notebook](/cli/notebook) command creates a virtual environment and opens a Jupyter notebook for quick prototyping. This is often the fastest way to get up and running. - -```bash -# Launch Jupyter with a demo notebook -codegen notebook --demo -``` - - - - The `notebook --demo` comes pre-configured to load [FastAPI](https://github.com/fastapi/fastapi)'s codebase, so you can start - exploring right away! - - - - Prefer working in your IDE? See [IDE Usage](/introduction/ide-usage) - - -## Initializing a Codebase - -Instantiating a [Codebase](/api-reference/core/Codebase) will automatically parse a codebase and make it available for manipulation. - -```python -from codegen import Codebase - -# Clone + parse fastapi/fastapi -codebase = Codebase.from_repo('fastapi/fastapi') - -# Or, parse a local repository -codebase = Codebase("path/to/git/repo") -``` - - - This will automatically infer the programming language of the codebase and - parse all files in the codebase. Learn more about [parsing codebases here](/building-with-codegen/parsing-codebases) - - -## Exploring Your Codebase - -Let's explore the codebase we just initialized. - -Here are some common patterns for code navigation in Codegen: - -- Iterate over all [Functions](/api-reference/core/Function) with [Codebase.functions](/api-reference/core/Codebase#functions) -- View class inheritance with [Class.superclasses](/api-reference/core/Class#superclasses) -- View function usages with [Function.usages](/api-reference/core/Function#usages) -- View inheritance hierarchies with [inheritance APIs](https://docs.codegen.com/building-with-codegen/class-api#working-with-inheritance) -- Identify recursive functions by looking at [FunctionCalls](https://docs.codegen.com/building-with-codegen/function-calls-and-callsites) -- View function call-sites with [Function.call_sites](/api-reference/core/Function#call-sites) - -```python -# Print overall stats -print("πŸ” Codebase Analysis") -print("=" * 50) -print(f"πŸ“š Total Classes: {len(codebase.classes)}") -print(f"⚑ Total Functions: {len(codebase.functions)}") -print(f"πŸ”„ Total Imports: {len(codebase.imports)}") - -# Find class with most inheritance -if codebase.classes: - deepest_class = max(codebase.classes, key=lambda x: len(x.superclasses)) - print(f"\n🌳 Class with most inheritance: {deepest_class.name}") - print(f" πŸ“Š Chain Depth: {len(deepest_class.superclasses)}") - print(f" ⛓️ Chain: {' -> '.join(s.name for s in deepest_class.superclasses)}") - -# Find first 5 recursive functions -recursive = [f for f in codebase.functions - if any(call.name == f.name for call in f.function_calls)][:5] -if recursive: - print(f"\nπŸ”„ Recursive functions:") - for func in recursive: - print(f" - {func.name}") -``` - -## Analyzing Tests - -Let's specifically drill into large test files, which can be cumbersome to manage. - -```python -from collections import Counter - -# Filter to all test functions and classes -test_functions = [x for x in codebase.functions if x.name.startswith('test_')] -test_classes = [x for x in codebase.classes if x.name.startswith('Test')] - -print("πŸ§ͺ Test Analysis") -print("=" * 50) -print(f"πŸ“ Total Test Functions: {len(test_functions)}") -print(f"πŸ”¬ Total Test Classes: {len(test_classes)}") -print(f"πŸ“Š Tests per File: {len(test_functions) / len(codebase.files):.1f}") - -# Find files with the most tests -print("\nπŸ“š Top Test Files by Class Count") -print("-" * 50) -file_test_counts = Counter([x.file for x in test_classes]) -for file, num_tests in file_test_counts.most_common()[:5]: - print(f"πŸ” {num_tests} test classes: {file.filepath}") - print(f" πŸ“ File Length: {len(file.source)} lines") - print(f" πŸ’‘ Functions: {len(file.functions)}") -``` - -## Splitting Up Large Test Files - -Lets split up the largest test files into separate modules for better organization. - -This uses Codegen's [codebase.move_to_file(...)](/building-with-codegen/moving-symbols), which will: -- update all imports -- (optionally) move dependencies -- do so very fast ⚑️ - -While maintaining correctness. - -```python -filename = 'tests/test_path.py' -print(f"πŸ“¦ Splitting Test File: {filename}") -print("=" * 50) - -# Grab a file -file = codebase.get_file(filename) -base_name = filename.replace('.py', '') - -# Group tests by subpath -test_groups = {} -for test_function in file.functions: - if test_function.name.startswith('test_'): - test_subpath = '_'.join(test_function.name.split('_')[:3]) - if test_subpath not in test_groups: - test_groups[test_subpath] = [] - test_groups[test_subpath].append(test_function) - -# Print and process each group -for subpath, tests in test_groups.items(): - print(f"\\n{subpath}/") - new_filename = f"{base_name}/{subpath}.py" - - # Create file if it doesn't exist - if not codebase.has_file(new_filename): - new_file = codebase.create_file(new_filename) - file = codebase.get_file(new_filename) - - # Move each test in the group - for test_function in tests: - print(f" - {test_function.name}") - test_function.move_to_file(new_file, strategy="add_back_edge") - -# Commit changes to disk -codebase.commit() -``` - - - In order to commit changes to your filesystem, you must call - [codebase.commit()](/api-reference/core/Codebase#commit). Learn more about - [commit() and reset()](/building-with-codegen/commit-and-reset). - - -### Finding Specific Content - -Once you have a general sense of your codebase, you can filter down to exactly what you're looking for. Codegen's graph structure makes it straightforward and performant to find and traverse specific code elements: - -```python -# Grab specific content by name -my_resource = codebase.get_symbol('TestResource') - -# Find classes that inherit from a specific base -resource_classes = [ - cls for cls in codebase.classes - if cls.is_subclass_of('Resource') -] - -# Find functions with specific decorators -test_functions = [ - f for f in codebase.functions - if any('pytest' in d.source for d in f.decorators) -] - -# Find files matching certain patterns -test_files = [ - f for f in codebase.files - if f.name.startswith('test_') -] -``` - -## Safe Code Transformations - -Codegen guarantees that code transformations maintain correctness. It automatically handles updating imports, references, and dependencies. Here are some common transformations: - -```python -# Move all Enum classes to a dedicated file -for cls in codebase.classes: - if cls.is_subclass_of('Enum'): - # Codegen automatically: - # - Updates all imports that reference this class - # - Maintains the class's dependencies - # - Preserves comments and decorators - # - Generally performs this in a sane manner - cls.move_to_file(f'enums.py') - -# Rename a function and all its usages -old_function = codebase.get_function('process_data') -old_function.rename('process_resource') # Updates all references automatically - -# Change a function's signature -handler = codebase.get_function('event_handler') -handler.get_parameter('e').rename('event') # Automatically updates all call-sites -handler.add_parameter('timeout: int = 30') # Handles formatting and edge cases -handler.add_return_type('Response | None') - -# Perform surgery on call-sites -for fcall in handler.call_sites: - arg = fcall.get_arg_by_parameter_name('env') - # f(..., env={ data: x }) => f(..., env={ data: x or None }) - if isinstance(arg.value, Collection): - data_key = arg.value.get('data') - data_key.value.edit(f'{data_key.value} or None') -``` - - - When moving symbols, Codegen will automatically update all imports and - references. See [Moving Symbols](/building-with-codegen/moving-symbols) to - learn more. - - -## Leveraging Graph Relations - -Codegen's graph structure makes it easy to analyze relationships between code elements across files: - -```python -# Find dead code -for func in codebase.functions: - if len(func.usages) == 0: - print(f'πŸ—‘οΈ Dead code: {func.name}') - func.remove() - -# Analyze import relationships -file = codebase.get_file('api/endpoints.py') -print("\nFiles that import endpoints.py:") -for import_stmt in file.inbound_imports: - print(f" {import_stmt.file.path}") - -print("\nFiles that endpoints.py imports:") -for import_stmt in file.imports: - if import_stmt.resolved_symbol: - print(f" {import_stmt.resolved_symbol.file.path}") - -# Explore class hierarchies -base_class = codebase.get_class('BaseModel') -if base_class: - print(f"\nClasses that inherit from {base_class.name}:") - for subclass in base_class.subclasses: - print(f" {subclass.name}") - # We can go deeper in the inheritance tree - for sub_subclass in subclass.subclasses: - print(f" └─ {sub_subclass.name}") -``` - - - Learn more about [dependencies and - references](/building-with-codegen/dependencies-and-usages) or [imports](/building-with-codegen/imports) and [exports](/building-with-codegen/exports). - - -## Advanced Settings - -Codegen also supports a number of advanced settings that can be used to customize the behavior of the graph construction process. - -These flags are helpful for debugging problematic repos, optimizing Codegen’s performance, or testing unreleased or experimental (potentially backwards-breaking) features. - -```python -from codegen import Codebase -from codegen.configs import CodebaseConfig - -# Initialize a Codebase with custom configuration -codebase = Codebase( - "path/to/git/repo"", - config=CodebaseConfig( - verify_graph=True, - method_usages=False, - sync_enabled=True, - generics=False, - import_resolution_overrides={ - "old_module": "new_module" - }, - ts_language_engine=True, - v8_ts_engine=True - ) -) -``` - -To learn more about available settings, see the [Advanced Settings](/introduction/advanced-settings) page. - - -These are considered experimental and unstable features that may be removed or changed in the future. - - -## What's Next? - - - - Follow step-by-step tutorials for common code transformation tasks like - modernizing React codebases or migrating APIs. - - - Understand key concepts like working with files, functions, imports, and the - call graph to effectively manipulate code. - - - Iterate locally with your favorite IDE, work with a debugger and build sophisticated codemods - - - Learn how to use Codegen with Cursor, Devin, Windsurf, and more. - - - diff --git a/docs/_deprecated/graph-sitter/guiding-principles.mdx b/docs/_deprecated/graph-sitter/guiding-principles.mdx deleted file mode 100644 index 53201e5c1..000000000 --- a/docs/_deprecated/graph-sitter/guiding-principles.mdx +++ /dev/null @@ -1,75 +0,0 @@ ---- -title: "Guiding Principles" -sidebarTitle: "Principles" -icon: "compass" -iconType: "solid" ---- - -Codegen was developed by working backwards from real-world, large-scale codebase migrations. Instead of starting with abstract syntax trees and parser theory, we started with the question: "How do developers actually think about code changes?" - -This practical origin led to four core principles that shape Codegen's design: - -## Intuitive APIs - -Write code that reads like natural language, without worrying about abstract syntax trees or parser internals. Codegen provides high-level APIs that map directly to the transformations developers want to perform: - -```python -# Methods that read like English -function.rename("new_name") # Not ast.update_node(function_node, "name", "new_name") -function.move_to_file("new_file.py") # Not ast.relocate_node(function_node, "new_file.py") - -# Clean, readable properties -if function.is_async: # Not ast.get_node_attribute(function_node, "async") - print(function.name) # Not ast.get_node_name(function_node) - -# Natural iteration patterns -for usage in function.usages: # Not ast.find_references(function_node) - print(f"Used in {usage.file.name}") -``` - -## No Sharp Edges - -Focus on your high-level intent while Codegen handles the intricate details. - -Codegen operations handle the edge cases - it should be hard to break lint. - -```python -# Moving a function? Codegen handles: -function.move_to_file("new_file.py") -# βœ“ Updating all import statements -# βœ“ Preserving dependencies -# βœ“ Maintaining references -# βœ“ Fixing relative imports -# βœ“ Resolving naming conflicts - -# Renaming a symbol? Codegen manages: -class_def.rename("NewName") -# βœ“ Updating all usages -# βœ“ Handling string references -# βœ“ Preserving docstrings -# βœ“ Maintaining inheritance -``` - -## Performance through Pre-Computation - -Codegen frontloads as much as possible to enable fast, efficient transformations. - -It is built with the insight that each codebase only needs to be parsed once per commit. - - - Learn more about parsing the codebase graph in the [How it - Works](/introduction/how-it-works) guide. - - -## Python-First Composability - -Codegen embraces Python's strength as a "glue language" - its ability to seamlessly integrate different tools and APIs. This makes it natural to compose Codegen with your existing toolchain: - -- Build complex transforms by combining simpler operations -- Integrate Codegen with your existing tools (linters, type checkers, test frameworks, AI tools) - - - Python's rich ecosystem makes it ideal for code manipulation tasks. Codegen is - designed to be one tool in your toolbox, not a replacement for your entire - workflow. - diff --git a/docs/_deprecated/graph-sitter/how-it-works.mdx b/docs/_deprecated/graph-sitter/how-it-works.mdx deleted file mode 100644 index 8777a5be4..000000000 --- a/docs/_deprecated/graph-sitter/how-it-works.mdx +++ /dev/null @@ -1,89 +0,0 @@ ---- -title: "Under the Hood" -sidebarTitle: "How it Works" -icon: "gear" -iconType: "solid" -subtitle: "How Codegen's codebase graph works" ---- - -Codegen performs advanced static analysis to build a rich graph representation of your codebase. This pre-computation step analyzes dependencies, references, types, and control flow to enable fast and reliable code manipulation operations. - - - Codegen is built on top of - [Tree-sitter](https://tree-sitter.github.io/tree-sitter/) and - [rustworkx](https://github.com/Qiskit/rustworkx) and has implemented most - language server features from scratch. - - - Codegen is open source. Check out the [source - code](https://github.com/codegen-sh/codegen-sdk) to learn more! - - -## The Codebase Graph - -At the heart of Codegen is a comprehensive graph representation of your code. When you initialize a [Codebase](/api-reference/core/Codebase), it performs static analysis to construct a rich graph structure connecting code elements: - -```python -# Initialize and analyze the codebase -from codegen import Codebase -codebase = Codebase("./") - -# Access pre-computed relationships -function = codebase.get_symbol("process_data") -print(f"Dependencies: {function.dependencies}") # Instant lookup -print(f"Usages: {function.usages}") # No parsing needed -``` - -### Building the Graph - -Codegen's graph construction happens in two stages: - -1. **AST Parsing**: We use [Tree-sitter](https://tree-sitter.github.io/tree-sitter/) as our foundation for parsing code into Abstract Syntax Trees. Tree-sitter provides fast, reliable parsing across multiple languages. - -2. **Multi-file Graph Construction**: Custom parsing logic, implemented in [rustworkx](https://github.com/Qiskit/rustworkx) and Python, analyzes these ASTs to construct a more sophisticated graph structure. This graph captures relationships between [symbols](/building-with-codegen/symbol-api), [files](/building-with-codegen/files-and-directories), [imports](/building-with-codegen/imports), and more. - -### Performance Through Pre-computation - -Pre-computing a rich index enables Codegen to make certain operations very fast that that are relevant to refactors and code analysis: - -- Finding all usages of a symbol -- Detecting circular dependencies -- Analyzing the dependency graphs -- Tracing call graphs -- Static analysis-based code retrieval for RAG -- ...etc. - - - Pre-parsing the codebase enables constant-time lookups rather than requiring - re-parsing or real-time analysis. - - -## Multi-Language Support - -One of Codegen's core principles is that many programming tasks are fundamentally similar across languages. - -Currently, Codegen supports: - -- [Python](/api-reference/python) -- [TypeScript](/api-reference/typescript) -- [React & JSX](/building-with-codegen/react-and-jsx) - - - Learn about how Codegen handles language specifics in the [Language - Support](/building-with-codegen/language-support) guide. - - -We've started with these ecosystems but designed our architecture to be extensible. The graph-based approach provides a consistent interface across languages while handling language-specific details under the hood. - -## Build with Us - -Codegen is just getting started, and we're excited about the possibilities ahead. We enthusiastically welcome contributions from the community, whether it's: - -- Adding support for new languages -- Implementing new analysis capabilities -- Improving performance -- Expanding the API -- Adding new transformations -- Improving documentation - -Check out our [community guide](/introduction/community) to get involved! diff --git a/docs/_deprecated/graph-sitter/ide-usage.mdx b/docs/_deprecated/graph-sitter/ide-usage.mdx deleted file mode 100644 index 3c58d39ab..000000000 --- a/docs/_deprecated/graph-sitter/ide-usage.mdx +++ /dev/null @@ -1,178 +0,0 @@ ---- -title: "Using Codegen in Your IDE" -sidebarTitle: "IDE Usage" -icon: "window" -iconType: "solid" ---- - -Get up and running with Codegen programs in IDEs like VSCode, Cursor and PyCharm. - -Make sure to [install and initialize](/introduction/installation) Codegen with `codegen init` - -## Configuring your IDE Interpreter - -Codegen creates a custom Python environment in `.codegen/.venv`. Configure your IDE to use this environment for the best development experience. - - - - 1. Install the VSCode Python Extensions for LSP and debugging support. We recommend Python, Pylance and Python Debugger for the best experience. - - 2. Open the Command Palette (Cmd/Ctrl + Shift + P) - 3. Type "Python: Select Interpreter" - - 4. Choose "Enter interpreter path" - 5. Navigate to and select: - ```bash - .codegen/.venv/bin/python - ``` - - Alternatively, create a `.vscode/settings.json`: - ```json - { - "python.defaultInterpreterPath": "${workspaceFolder}/.codegen/.venv/bin/python", - "python.analysis.extraPaths": [ - "${workspaceFolder}/.codegen/.venv/lib/python3.12/site-packages" - ] - } - ``` - - - - 1. Open PyCharm Settings/Preferences - 2. Navigate to "Project > Python Interpreter" - 3. Click the gear icon βš™οΈ and select "Add" - 4. Choose "Existing Environment" - 5. Set interpreter path to: - ```bash - .codegen/.venv/bin/python - ``` - - - - - -## MCP Server Setup -This is an optional step but highly recommended if your IDE supports MCP support and you use AI Agents. -The MCP server is a local server that allows your AI Agent to interact with the Codegen specific tools, -it will allow an agent to: -- ask an expert to create a codemod -- improve a codemod -- get setup instructions - -### IDE Configuration -#### Cline -Add this to your cline_mcp_settings.json: -```json -{ - "mcpServers": { - "codegen-cli": { - "command": "uv", - "args": [ - "--directory", - "/codegen-sdk/src/codegen/cli/mcp", - "run", - "server.py" - ] - } - } -} -``` - - -#### Cursor: -Under the `Settings` > `Feature` > `MCP Servers` section, click "Add New MCP Server" and add the following: - -``` -Name: codegen-mcp -Type: Command -Command: uv --directory /codegen-sdk/src/codegen/cli/mcp run server.py -``` - - -## Index Codegen Docs -#### Cursor: -If you use Cursor you'll be able to configure the IDE to index the Codegen docs. To do so go to `Settings` > `Features` > `Docs` -and then click on `Add new docs`. We recommend using this url to index the API reference: -``` -https://docs.codegen.com/api-reference/index -``` - - -## Create a New Codemod - -Generate the boilerplate for a new code manipulation program using [codegen create](/cli/create): - -```bash -codegen create organize-types \ - -d "Move all TypeScript types to \ - into a centralized types.ts file" -``` - - - Passing in `-d --description` will get an LLM expert to compose an initial version for you. This requires a Github account registered on [codegen.sh](https://codegen.sh) - - -This will: -1. Create a new codemod in `.codegen/codemods/organize_types/` -2. Generate a custom `system-prompt.txt` based on your task -3. Set up the basic structure for your program - - -The generated codemod includes type hints and docstrings, making it easy to get IDE autocompletion and documentation. - - -## Iterating with Chat Assistants - -When you do `codegen init`, you will receive a [system prompt optimized for AI consumption](/introduction/work-with-ai) at `.codegen/codegen-system-prompt.txt`. - -If you reference this file in "chat" sessions with Copilot, Cursor, Cody, etc., the assistant will become fluent in Codegen. - - - - Collaborating with Cursor's assistant and the Codegen system prompt - - -In addition, when you [create](/cli/create) a codemod with "-d", Codegen generates an optimized system prompt in `.codegen/codemods/{name}/{name}-system-prompt.txt`. This prompt contains: -- Relevant Codegen API documentation -- Examples of relevant transformations -- Context about your specific task - - -You can also drag and drop the system prompt ([available here](/introduction/work-with-ai))file directly into chat windows like ChatGPT or Claude for standalone help. - - -## Running and Testing Codemods - -```bash -# Run => write changes to disk -codegen run organize-types - -# Reset changes on disk -codegen reset -``` - -You can also run the program directly via `.codegen/.venv/bin/python path/to/codemod.py` or via your editor's debugger - -## Viewing Changes - -We recommend viewing changes in your IDE's native diff editor. - - -## What's Next - - - - See real-world examples of codemods in action. - - - Learn about Codegen's core concepts and features - - diff --git a/docs/_deprecated/graph-sitter/installation.mdx b/docs/_deprecated/graph-sitter/installation.mdx deleted file mode 100644 index 41188c64b..000000000 --- a/docs/_deprecated/graph-sitter/installation.mdx +++ /dev/null @@ -1,125 +0,0 @@ ---- -title: "Installation" -sidebarTitle: "Installation" -icon: "download" -iconType: "solid" ---- - -Install and set up Codegen in your development environment. - -#### We currently support: -- Running Codegen in Python 3.12 - 3.13 (recommended: Python 3.13+) -- macOS and Linux - - macOS is supported - - Linux is supported on x86_64 and aarch64 with glibc 2.34+ - - Windows is supported via WSL. See [here](https://docs.codegen.com/building-with-codegen/codegen-with-wsl) for more details. -- Python, Typescript, Javascript and React codebases - -## Prerequisites - -We recommend using [uv](https://github.com/astral-sh/uv) for installation. If you haven't installed `uv` yet: -```bash -curl -LsSf https://astral.sh/uv/install.sh | sh -``` - -## Installing Codegen - -```bash -uv tool install codegen --python 3.13 -``` - - - -This makes the `codegen` command available globally in your terminal, while keeping its dependencies isolated. - - -## Quick Start - -Let's walk through a minimal example of using Codegen in a project: - -1. Navigate to your repository: - ```bash - cd path/to/your/project - ``` - -2. Initialize Codegen in your project with [codegen init](/cli/init): - ```bash - codegen init - ``` - - This creates a `.codegen/` directory with: - ```bash - .codegen/ - β”œβ”€β”€ .venv/ # Python virtual environment (gitignored) - β”œβ”€β”€ config.toml # Project configuration - β”œβ”€β”€ codemods/ # Your codemod implementations - β”œβ”€β”€ jupyter/ # Jupyter notebooks for exploration - └── codegen-system-prompt.txt # AI system prompt - ``` - -3. Create your first codemod with [codegen create](/cli/create): - ```bash - codegen create organize-imports \ - -d "Sort and organize imports according to PEP8" - ``` - - The `-d` flag in `codegen create` generates an AI-powered implementation. This requires a Github account registered on [codegen.sh](https://codegen.sh) - - - - -4. Run your codemod with [codegen run](/cli/run): - ```bash - codegen run organize-imports - ``` - -5. Reset any filesystem changes (excluding `.codegen/*`) with [codegen reset](/cli/reset): - ```bash - codegen reset - ``` - -## Troubleshooting - -Having issues? Here are some common problems and their solutions: - -- **I'm hitting an UV error related to `[[ packages ]]`**: This means you're likely using an outdated version of UV. Try updating to the latest version with: `uv self update`. -- **I'm hitting an error about `No module named 'codegen.sdk.extensions.utils'`**: The compiled cython extensions are out of sync. Update them with `uv sync --reinstall-package codegen`. -- **I'm hitting a `RecursionError: maximum recursion depth exceeded` error while parsing my codebase**: If you are using python 3.12, try upgrading to 3.13. If you are already on 3.13, try upping the recursion limit with `sys.setrecursionlimit(10000)`. - - -For more help, join our [community Slack](/introduction/community) or check the [FAQ](/introduction/faq). - - -## Next Steps - - - - Learn how to use Codegen effectively in VSCode, Cursor, and other IDEs. - - - Follow step-by-step tutorials for common code transformation tasks. - - - Leverage AI assistants like Copilot, Cursor and Devin - - - Learn more about building with Codegen - - - diff --git a/docs/_deprecated/graph-sitter/overview.mdx b/docs/_deprecated/graph-sitter/overview.mdx deleted file mode 100644 index 4d428fc71..000000000 --- a/docs/_deprecated/graph-sitter/overview.mdx +++ /dev/null @@ -1,159 +0,0 @@ ---- -title: "Codegen" -sidebarTitle: "Overview" -icon: "code" -iconType: "solid" ---- - -[Codegen](https://github.com/codegen-sh/codegen-sdk) is a python library for manipulating codebases. - -It provides a scriptable interface to a powerful, multi-lingual language server built on top of [Tree-sitter](https://tree-sitter.github.io/tree-sitter/). - -```python -from codegen import Codebase - -# Codegen builds a complete graph connecting -# functions, classes, imports and their relationships -codebase = Codebase("./") - -# Work with code without dealing with syntax trees or parsing -for function in codebase.functions: - # Comprehensive static analysis for references, dependencies, etc. - if not function.usages: - # Auto-handles references and imports to maintain correctness - function.remove() - -# Fast, in-memory code index -codebase.commit() -``` - - - -Codegen handles complex refactors while maintaining correctness, enabling a broad set of advanced code manipulation programs. - - -Codegen works with both Python and Typescript/JSX codebases. Learn more about language support [here](/building-with-codegen/language-support). - -## Quick Started - - -Codegen requires Python 3.12 - 3.13 (recommended: Python 3.13+). - - -### Using UV (Recommended) -```bash -uv tool install codegen --python 3.13 -``` - -### Using Pipx - - -Pipx is not officially supported by Codegen, but it should still work. - - -```bash -pipx install codegen -``` - - -For further & more in depth installation instructions, see the [installation guide](/introduction/installation). - - -## What can I do with Codegen? - -Codegen's simple yet powerful APIs enable a range of applications, including: - - - - Create an intelligent agent that can analyze and manipulate your codebase using natural language. - - - Generate interactive visualizations of your codebase's structure, dependencies, and relationships. - - - Create high-quality training data for fine-tuning LLMs on your codebase. - - - Create powerful code transformations to automate large-scale changes. - - - -See below for an example call graph visualization generated with Codegen. - - - - - -View source code on [modal/modal-client](https://github.com/modal-labs/modal-client/blob/cbac0d80dfd98588027ecd21850152776be3ab82/modal/client.py#L70). View codemod on [codegen.sh](https://www.codegen.sh/codemod/66e2e195-ceec-4935-876a-ed4cfc1731c7/public/diff) - - -## Get Started - -import { - COMMUNITY_SLACK_URL, - CODEGEN_SDK_GITHUB_URL, -} from "/snippets/links.mdx"; - - - - Follow our step-by-step tutorial to start manipulating code with Codegen. - - - Learn how to use Codegen for common code transformation tasks. - - - Star us on GitHub and contribute to the project. - - - Get help and connect with the Codegen community. - - - -## Why Codegen? - -Many software engineering tasks - refactors, enforcing patterns, analyzing control flow, etc. - are fundamentally programmatic operations. Yet the tools we use to express these transformations often feel disconnected from how we think about code. - -Codegen was engineered backwards from real-world refactors we performed for enterprises at [Codegen, Inc.](/introduction/about). Instead of starting with theoretical abstractions, we built the set of APIs that map directly to how humans and AI think about code changes: - -- **Natural Mental Model**: Express transformations through high-level operations that match how you reason about code changes, not low-level text or AST manipulation. -- **Clean Business Logic**: Let the engine handle the complexities of imports, references, and cross-file dependencies. -- **Scale with Confidence**: Make sweeping changes across large codebases consistently across Python, TypeScript, JavaScript, and React. - -As AI becomes increasingly sophisticated, we're seeing a fascinating shift: AI agents aren't bottlenecked by their ability to understand code or generate solutions. Instead, they're limited by their ability to efficiently manipulate codebases. The challenge isn't the "brain" - it's the "hands." - -We built Codegen with a key insight: future AI agents will need to ["act via code,"](/blog/act-via-code) building their own sophisticated tools for code manipulation. Rather than generating diffs or making direct text changes, these agents will: - -1. Express transformations as composable programs -2. Build higher-level tools by combining primitive operations -3. Create and maintain their own abstractions for common patterns - -This creates a shared language that both humans and AI can reason about effectively, making code changes more predictable, reviewable, and maintainable. Whether you're a developer writing a complex refactoring script or an AI agent building transformation tools, Codegen provides the foundation for expressing code changes as they should be: through code itself. diff --git a/docs/_deprecated/graph-sitter/work-with-ai.mdx b/docs/_deprecated/graph-sitter/work-with-ai.mdx deleted file mode 100644 index c826aad75..000000000 --- a/docs/_deprecated/graph-sitter/work-with-ai.mdx +++ /dev/null @@ -1,86 +0,0 @@ ---- -title: "Working with AI" -sidebarTitle: "AI Integration" -icon: "microchip" -iconType: "solid" ---- - -Codegen is designed to be used with AI assistants. This document describes how to use Codegen with common AI tools, including Copilot, Cursor, Devin and more. - -## System Prompt - -Codegen provides a `.txt` file that you can drag-and-drop into any chat assistant. This is roughly 60k tokens and will enable chat assistants like, ChatGPT, Claude 3.5 etc. to build effectively with Codegen. - -import { - CODEGEN_SYSTEM_PROMPT -} from "/snippets/links.mdx"; - - - Download System Prompt - - -Learn about leveraging this in IDE chat assistants like Cursor [here](/introduction/ide-usage#iterating-with-chat-assistants) - -## Generating System Prompts - -The [Codegen CLI](/cli/about) provides commands to generate `.md` files that can be fed to any AI assistant for more accurate and contextual help. - -When you create a new codemod via [codegen create](/cli/create): - -```bash -codegen create delete-dead-imports . --description "Delete unused imports" -``` - -Codegen automatically generates an optimized ["system prompt"](https://news.ycombinator.com/item?id=37880023) that includes: - -- An introduction to Codegen -- Codegen API documentation -- Examples of relevant transformations - -You can find this generated prompt in the `.codegen/prompts/-system-prompt.md` file. - - - All contents of the `.codegen/prompts` directory are by default ignored the - `.gitignore` file. after running [codegen init](/cli/init) - - -This `.md` file can be used with any AI assistant (Claude, GPT-4, etc.) to get more accurate and contextual help. - -## Example Workflow - - - - Use the [create command](/cli/create) with a detailed description of what you want to accomplish: - ```bash - codegen create modernize-components . --description "Convert class components to functional components with hooks" - ``` - - - Check the AI context that Codegen generated for your transformation: ```bash - cat codegen-sh/codemods/modernize-components/prompt.md ``` - - - - Reference your codemod when asking questions to get contextual help: ``` - @codegen-sh/codemods/modernize-components How should I handle - componentDidMount? ``` - - - - The AI will understand you're working on React modernization and provide relevant suggestions about using useEffect hooks and other modern React patterns. - - - -## Copilot, Cursor and Windsurf (IDEs) - -When using IDE chat assistants, you can leverage Codegen's context by mentioning your codemod in composer mode: - -```bash -@.codegen/codemods/upgrade-react18 @.codegen/prompts/system-prompt.md -``` - -This will ensure that the IDE's native chat model is aware of the APIs and common patterns for Codegen. - -## Devin, OpenHands and Semi-autonomous Code Agents - -Coming soon! diff --git a/docs/_deprecated/tutorials/at-a-glance.mdx b/docs/_deprecated/tutorials/at-a-glance.mdx deleted file mode 100644 index 87c8f467f..000000000 --- a/docs/_deprecated/tutorials/at-a-glance.mdx +++ /dev/null @@ -1,150 +0,0 @@ ---- -title: "Learn by Example" -sidebarTitle: "At a Glance" -icon: "graduation-cap" -iconType: "solid" ---- - -Explore our tutorials to learn how to use Codegen for various code transformation tasks. - -## Featured Tutorials - - - - Create an intelligent code agent with Langchain and powerful, codegen-powered tools - - - Generate interactive visualizations of your codebase's structure, dependencies, and relationships. - - - Create high-quality training data for LLM pre-training similar to word2vec or node2vec - - - Remove unused imports, functions, and variables with confidence. - - - -## API Migrations - - - - Update API calls, handle breaking changes, and manage bulk updates across your codebase. - - - Update SQLAlchemy code to use the new 2.0-style query interface and patterns. - - - Convert Flask applications to FastAPI, updating routes and dependencies. - - - Migrate Python 2 code to Python 3, updating syntax and modernizing APIs. - - - -## Code Organization - - - - Restructure files, enforce naming conventions, and improve project layout. - - - Split large files, extract shared logic, and manage dependencies. - - - Organize and optimize TypeScript module exports. - - - Convert between default and named exports in TypeScript/JavaScript. - - - -## Testing & Types - - - - Convert unittest test suites to pytest's modern testing style. - - - Add TypeScript types, infer types from usage, and improve type safety. - - - -## Documentation & AI - - - - Generate JSDoc comments, README files, and API documentation. - - - Generate system prompts, create hierarchical documentation, and optimize for AI assistance. - - - - - Each tutorial includes practical examples, code snippets, and best practices. - Follow them in order or jump to the ones most relevant to your needs. - diff --git a/docs/_deprecated/tutorials/attributions.mdx b/docs/_deprecated/tutorials/attributions.mdx deleted file mode 100644 index 832c9a74b..000000000 --- a/docs/_deprecated/tutorials/attributions.mdx +++ /dev/null @@ -1,191 +0,0 @@ ---- -title: "Code Attributions" -sidebarTitle: "Code Attributions" -description: "Learn how to analyze code statistics and attributions using Codegen" -icon: "network-wired" -iconType: "solid" ---- - -# AI Impact Analysis - -This tutorial shows how to use Codegen's attribution extension to analyze the impact of AI on your -codebase. You'll learn how to identify which parts of your code were written by AI tools like -GitHub Copilot, Devin, or other AI assistants. - -Note: the code is flexible - you can track CI pipeline bots, or any other contributor you want. - - -## Overview - -The attribution extension analyzes git history to: - -1. Identify which symbols (functions, classes, etc.) were authored or modified by AI tools -2. Calculate the percentage of AI contributions in your codebase -3. Find high-impact AI-written code (code that many other parts depend on) -4. Track the evolution of AI contributions over time - -## Installation - -The attribution extension is included with Codegen. No additional installation is required. - -## Basic Usage - -### Running the Analysis - -You can run the AI impact analysis using the Codegen CLI: - -```bash -codegen analyze-ai-impact -``` - -Or from Python code: - -```python -from codegen import Codebase -from codegen.extensions.attribution.cli import run - -# Initialize codebase from current directory -codebase = Codebase.from_repo("your-org/your-repo", language="python") - -# Run the analysis -run(codebase) -``` - -### Understanding the Results - -The analysis will print a summary of AI contributions to your console and save detailed results to a JSON file. The summary includes: - -- List of all contributors (human and AI) -- Percentage of commits made by AI -- Number of files and symbols touched by AI -- High-impact AI-written code (code with many dependents) -- Top files by AI contribution percentage - -## Advanced Usage - -### Accessing Attribution Information - -After running the analysis, each symbol in your codebase will have attribution information attached to it: - -```python -from codegen import Codebase -from codegen.extensions.attribution.main import add_attribution_to_symbols - -# Initialize codebase -codebase = Codebase.from_repo("your-org/your-repo", language="python") - -# Add attribution information to symbols -ai_authors = ['github-actions[bot]', 'dependabot[bot]', 'copilot[bot]'] -add_attribution_to_symbols(codebase, ai_authors) - -# Access attribution information on symbols -for symbol in codebase.symbols: - if hasattr(symbol, 'is_ai_authored') and symbol.is_ai_authored: - print(f"AI-authored symbol: {symbol.name} in {symbol.filepath}") - print(f"Last editor: {symbol.last_editor}") - print(f"All editors: {symbol.editor_history}") -``` - -### Customizing AI Author Detection - -By default, the analysis looks for common AI bot names in commit authors. -You can customize this by providing your own list of AI authors: - -```python -from codegen import Codebase -from codegen.extensions.attribution.main import analyze_ai_impact - -# Initialize codebase -codebase = Codebase.from_repo("your-org/your-repo", language="python") - -# Define custom AI authors -ai_authors = [ - 'github-actions[bot]', - 'dependabot[bot]', - 'copilot[bot]', - 'devin[bot]', - 'your-custom-ai-email@example.com' -] - -# Run analysis with custom AI authors -results = analyze_ai_impact(codebase, ai_authors) -``` - -## Example: Contributor Analysis - -Here's a complete example that analyzes contributors to your codebase and their impact: - -```python -import os -from collections import Counter - -from codegen import Codebase -from codegen.extensions.attribution.main import add_attribution_to_symbols -from codegen.git.repo_operator.repo_operator import RepoOperator -from codegen.git.schemas.repo_config import RepoConfig -from codegen.sdk.codebase.config import ProjectConfig -from codegen.shared.enums.programming_language import ProgrammingLanguage - -def analyze_contributors(codebase): - """Analyze contributors to the codebase and their impact.""" - print("\nπŸ” Contributor Analysis:") - - # Define which authors are considered AI - ai_authors = ['devin[bot]', 'codegen[bot]', 'github-actions[bot]', 'dependabot[bot]'] - - # Add attribution information to all symbols - print("Adding attribution information to symbols...") - add_attribution_to_symbols(codebase, ai_authors) - - # Collect statistics about contributors - contributor_stats = Counter() - ai_contributor_stats = Counter() - - print("Analyzing symbol attributions...") - for symbol in codebase.symbols: - if hasattr(symbol, 'last_editor') and symbol.last_editor: - contributor_stats[symbol.last_editor] += 1 - - # Track if this is an AI contributor - if any(ai in symbol.last_editor for ai in ai_authors): - ai_contributor_stats[symbol.last_editor] += 1 - - # Print top contributors overall - print("\nπŸ‘₯ Top Contributors by Symbols Authored:") - for contributor, count in contributor_stats.most_common(10): - is_ai = any(ai in contributor for ai in ai_authors) - ai_indicator = "πŸ€–" if is_ai else "πŸ‘€" - print(f" {ai_indicator} {contributor}: {count} symbols") - - # Print top AI contributors if any - if ai_contributor_stats: - print("\nπŸ€– Top AI Contributors:") - for contributor, count in ai_contributor_stats.most_common(5): - print(f" β€’ {contributor}: {count} symbols") - -# Initialize codebase from current directory -if os.path.exists(".git"): - repo_path = os.getcwd() - repo_config = RepoConfig.from_repo_path(repo_path) - repo_operator = RepoOperator(repo_config=repo_config) - - project = ProjectConfig.from_repo_operator( - repo_operator=repo_operator, - programming_language=ProgrammingLanguage.PYTHON - ) - codebase = Codebase(projects=[project]) - - # Run the contributor analysis - analyze_contributors(codebase) -``` - -## Conclusion - -The attribution extension provides valuable insights into how AI tools are being used in your -development process. By understanding which parts of your codebase are authored by AI, you can: - -- Track the adoption of AI coding assistants in your team -- Identify areas where AI is most effective -- Ensure appropriate review of AI-generated code -- Measure the impact of AI on developer productivity - diff --git a/docs/_deprecated/tutorials/build-mcp.mdx b/docs/_deprecated/tutorials/build-mcp.mdx deleted file mode 100644 index 691a5e2ce..000000000 --- a/docs/_deprecated/tutorials/build-mcp.mdx +++ /dev/null @@ -1,75 +0,0 @@ ---- -title: "Building a Model Context Protocol server with Codegen" -sidebarTitle: "MCP Server" -icon: "boxes-stacked" -iconType: "solid" ---- - -Learn how to build a Model Context Protocol (MCP) server that enables AI models to understand and manipulate code using Codegen's powerful tools. - -This guide will walk you through creating an MCP server that can provide semantic code search - -View the full code in our [examples repository](https://github.com/codegen-sh/codegen-sdk/tree/develop/src/codegen/extensions/mcp) - - -## Setup: -Install the MCP python library -``` -uv pip install mcp -``` - -## Step 1: Setting Up Your MCP Server - -First, let's create a basic MCP server using Codegen's MCP tools: - -server.py -```python -from codegen import Codebase -from mcp.server.fastmcp import FastMCP -from typing import Annotated -# Initialize the codebase -codebase = Codebase.from_repo(".") - -# create the MCP server using FastMCP -mcp = FastMCP(name="demo-mcp", instructions="Use this server for semantic search of codebases") - - -if __name__ == "__main__": - # Initialize and run the server - print("Starting demo mpc server...") - mcp.run(transport="stdio") - -``` - -## Step 2: Create the search tool - -Let's implement the semantic search tool. - -server.py -```python -from codegen.extensions.tools.semantic_search import semantic_search - -.... - -@mcp.tool('codebase_semantic_search', "search codebase with the provided query") -def search(query: Annotated[str, "search query to run against codebase"]): - codebase = Codebase("provide location to codebase", language="provide codebase Language") - # use the semantic search tool from codegen.extensions.tools OR write your own - results = semantic_search(codebase=codebase, query=query) - return results - -.... -``` - -## Run Your MCP Server - -You can run and inspect your MCP server with: - -``` -mcp dev server.py -``` - -If you'd like to integrate this into an IDE checkout out this [setup guide](/introduction/ide-usage#mcp-server-setup) - -And that's a wrap, chime in at our [community - Slack](https://community.codegen.com) if you have questions or ideas for additional MCP tools/capabilities diff --git a/docs/_deprecated/tutorials/codebase-analytics-dashboard.mdx b/docs/_deprecated/tutorials/codebase-analytics-dashboard.mdx deleted file mode 100644 index d35f4f5b4..000000000 --- a/docs/_deprecated/tutorials/codebase-analytics-dashboard.mdx +++ /dev/null @@ -1,157 +0,0 @@ ---- -title: "Codebase Analytics" -sidebarTitle: "Analytics" -icon: "calculator" -iconType: "solid" ---- - -This tutorial explains how codebase metrics are efficiently calculated using the `codegen` library in the Codebase Analytics Dashboard. The metrics include indices of codebase maintainabilith and complexity. - -View the full code and setup instructions in our [codebase-analytics repository](https://github.com/codegen-sh/codebase-analytics). - - -## Complexity Metrics - -Complexity metrics help quantify how easy or difficult a codebase is to understand and maintain. These metrics are calculated by analyzing various aspects of the code structure, including control flow, code volume, and inheritance patterns. The following metrics provide different perspectives on code complexity. - -### Cyclomatic Complexity -Cyclomatic Complexity measures the number of linearly independent paths through the codebase, making it a valuable indicator of how difficult code will be to test and maintain. - -**Calculation Method**: - - Base complexity of 1 - - +1 for each: - - if statement - - elif statement - - for loop - - while loop - - +1 for each boolean operator (and, or) in conditions - - +1 for each except block in try-catch statements - -The `calculate_cyclomatic_complexity()` function traverses the Codgen codebase object and uses the above rules to find statement objects within each function and calculate the overall cyclomatic complexity of the codebase. - -```python -def calculate_cyclomatic_complexity(function): - def analyze_statement(statement): - complexity = 0 - - if isinstance(statement, IfBlockStatement): - complexity += 1 - if hasattr(statement, "elif_statements"): - complexity += len(statement.elif_statements) - - elif isinstance(statement, (ForLoopStatement, WhileStatement)): - complexity += 1 - - return complexity -``` - -### Halstead Volume -Halstead Volume is a software metric which measures the complexity of a codebase by counting the number of unique operators and operands. It is calculated by multiplying the sum of unique operators and operands by the logarithm base 2 of the sum of unique operators and operands. - -**Halstead Volume**: `V = (N1 + N2) * log2(n1 + n2)` - -This calculation uses codegen's expression types to make this calculation very efficient - these include BinaryExpression, UnaryExpression and ComparisonExpression. The function extracts operators and operands from the codebase object and calculated in `calculate_halstead_volume()` function. - -```python -def calculate_halstead_volume(operators, operands): - n1 = len(set(operators)) - n2 = len(set(operands)) - - N1 = len(operators) - N2 = len(operands) - - N = N1 + N2 - n = n1 + n2 - - if n > 0: - volume = N * math.log2(n) - return volume, N1, N2, n1, n2 - return 0, N1, N2, n1, n2 -``` - -### Depth of Inheritance (DOI) -Depth of Inheritance measures the length of inheritance chain for each class. It is calculated by counting the length of the superclasses list for each class in the codebase. The implementation is handled through a simple calculation using codegen's class information in the `calculate_doi()` function. - -```python -def calculate_doi(cls): - return len(cls.superclasses) -``` - -## Maintainability Index -Maintainability Index is a software metric which measures how maintainable a codebase is. Maintainability is described as ease to support and change the code. This index is calculated as a factored formula consisting of SLOC (Source Lines Of Code), Cyclomatic Complexity and Halstead volume. - -**Maintainability Index**: `M = 171 - 5.2 * ln(HV) - 0.23 * CC - 16.2 * ln(SLOC)` - -This formula is then normalized to a scale of 0-100, where 100 is the maximum maintainability. - -The implementation is handled through the `calculate_maintainability_index()` function. The codegen codebase object is used to efficiently extract the Cyclomatic Complexity and Halstead Volume for each function and class in the codebase, which are then used to calculate the maintainability index. - -```python -def calculate_maintainability_index( - halstead_volume: float, cyclomatic_complexity: float, loc: int -) -> int: - """Calculate the normalized maintainability index for a given function.""" - if loc <= 0: - return 100 - - try: - raw_mi = ( - 171 - - 5.2 * math.log(max(1, halstead_volume)) - - 0.23 * cyclomatic_complexity - - 16.2 * math.log(max(1, loc)) - ) - normalized_mi = max(0, min(100, raw_mi * 100 / 171)) - return int(normalized_mi) - except (ValueError, TypeError): - return 0 -``` - -## Line Metrics - -Line metrics provide insights into the size, complexity, and maintainability of a codebase. These measurements help determine the scale of a project, identify areas that may need refactoring, and track the growth of the codebase over time. - -### Lines of Code -Lines of Code refers to the total number of lines in the source code, including blank lines and comments. This is accomplished with a simple count of all lines in the source file. - -### Logical Lines of Code (LLOC) -LLOC is the amount of lines of code which contain actual functional statements. It excludes comments, blank lines, and other lines which do not contribute to the utility of the codebase. A high LLOC relative to total lines of code suggests dense, potentially complex code that may benefit from breaking into smaller functions or modules with more documentation. - -### Source Lines of Code (SLOC) -SLOC refers to the number of lines containing actual code, excluding blank lines. This includes programming language keywords and comments. While a higher SLOC indicates a larger codebase, it should be evaluated alongside other metrics like cyclomatic complexity and maintainability index to assess if the size is justified by the functionality provided. - -### Comment Density -Comment density is calculated by dividing the lines of code which contain comments by the total lines of code in the codebase. The formula is: - -```python -"comment_density": (total_comments / total_loc * 100) -``` - -It measures the proportion of comments in the codebase and is a good indicator of how much code is properly documented. Accordingly, it can show how maintainable and easy to understand the codebase is. - -## General Codebase Statistics -The number of files is determined by traversing codegen's FileNode objects in the parsed codebase. The number of functions is calculated by counting FunctionDef nodes across all parsed files. The number of classes is obtained by summing ClassDef nodes throughout the codebase. - -```python -num_files = len(codebase.files(extensions="*")) -num_functions = len(codebase.functions) -num_classes = len(codebase.classes) -``` - -The commit activity is calculated by using the git history of the repository. The number of commits is counted for each month in the last 12 months. - -## Using the Analysis Tool (Modal Server) - -The tool is implemented as a FastAPI application wrapped in a Modal deployment. To analyze a repository: - -1. Send a POST request to `/analyze_repo` with the repository URL -2. The tool will: - - Clone the repository - - Parse the codebase using codegen - - Calculate all metrics - - Return a comprehensive JSON response with all metrics - -This is the only endpoint in the FastAPI server, as it takes care of the entire analysis process. To run the FastAPI server locally, install all dependencies and run the server with `modal serve modal_main.py`. - -The server can be connected to the frontend dashboard. This web component is implemented as a Next.js application with appropriate comments and visualizations for the raw server data. To run the frontend locally, install all dependencies and run the server with `npm run dev`. This can be connected to the FastAPI server by setting the URL in the request to the `/analyze_repo` endpoint. - diff --git a/docs/_deprecated/tutorials/codebase-visualization.mdx b/docs/_deprecated/tutorials/codebase-visualization.mdx deleted file mode 100644 index a8d29484a..000000000 --- a/docs/_deprecated/tutorials/codebase-visualization.mdx +++ /dev/null @@ -1,398 +0,0 @@ ---- -title: "Codebase Visualization" -sidebarTitle: "Visualization" -description: "This guide will show you how to create codebase visualizations using [codegen](/introduction/overview)." -icon: "share-nodes" -iconType: "solid" ---- - - - - - -## Overview - -To demonstrate the visualization capabilities of the codegen we will generate three different visualizations of PostHog's open source [repository](https://github.com/PostHog/posthog). - - [Call Trace Visualization](#call-trace-visualization) - - [Function Dependency Graph](#function-dependency-graph) - - [Blast Radius Visualization](#blast-radius-visualization) - - -## Call Trace Visualization - -Visualizing the call trace of a function is a great way to understand the flow of a function and for debugging. In this tutorial we will create a call trace visualization of the `patch` method of the `SharingConfigurationViewSet` class. View the source code [here](https://github.com/PostHog/posthog/blob/c2986d9ac7502aa107a4afbe31b3633848be6582/posthog/api/sharing.py#L163). - - -### Basic Setup -First, we'll set up our codebase, graph and configure some basic parameters: - -```python -import networkx as nx -from codegen import Codebase - -# Initialize codebase -codebase = Codebase("path/to/posthog/") - -# Create a directed graph for representing call relationships -G = nx.DiGraph() - -# Configuration flags -IGNORE_EXTERNAL_MODULE_CALLS = True # Skip calls to external modules -IGNORE_CLASS_CALLS = False # Include class definition calls -MAX_DEPTH = 10 - -COLOR_PALETTE = { - "StartFunction": "#9cdcfe", # Light blue - Start Function - "PyFunction": "#a277ff", # Soft purple/periwinkle - PyFunction - "PyClass": "#ffca85", # Warm peach/orange - PyClass - "ExternalModule": "#f694ff" # Bright magenta/pink - ExternalModule -} -``` - -### Building the Visualization -We'll create a function that will recursively traverse the call trace of a function and add nodes and edges to the graph: - -```python -def create_downstream_call_trace(src_func: Function, depth: int = 0): - """Creates call graph by recursively traversing function calls - - Args: - src_func (Function): Starting function for call graph - depth (int): Current recursion depth - """ - # Prevent infinite recursion - if MAX_DEPTH <= depth: - return - - # External modules are not functions - if isinstance(src_func, ExternalModule): - return - - # Process each function call - for call in src_func.function_calls: - # Skip self-recursive calls - if call.name == src_func.name: - continue - - # Get called function definition - func = call.function_definition - if not func: - continue - - # Apply configured filters - if isinstance(func, ExternalModule) and IGNORE_EXTERNAL_MODULE_CALLS: - continue - if isinstance(func, Class) and IGNORE_CLASS_CALLS: - continue - - # Generate display name (include class for methods) - if isinstance(func, Class) or isinstance(func, ExternalModule): - func_name = func.name - elif isinstance(func, Function): - func_name = f"{func.parent_class.name}.{func.name}" if func.is_method else func.name - - # Add node and edge with metadata - G.add_node(func, name=func_name, - color=COLOR_PALETTE.get(func.__class__.__name__)) - G.add_edge(src_func, func, **generate_edge_meta(call)) - - # Recurse for regular functions - if isinstance(func, Function): - create_downstream_call_trace(func, depth + 1) -``` - -### Adding Edge Metadata -We can enrich our edges with metadata about the function calls: - -```python -def generate_edge_meta(call: FunctionCall) -> dict: - """Generate metadata for call graph edges - - Args: - call (FunctionCall): Function call information - - Returns: - dict: Edge metadata including name and location - """ - return { - "name": call.name, - "file_path": call.filepath, - "start_point": call.start_point, - "end_point": call.end_point, - "symbol_name": "FunctionCall" - } -``` -### Visualizing the Graph -Finally, we can visualize our call graph starting from a specific function: -```python -# Get target function to analyze -target_class = codebase.get_class('SharingConfigurationViewSet') -target_method = target_class.get_method('patch') - -# Add root node -G.add_node(target_method, - name=f"{target_class.name}.{target_method.name}", - color=COLOR_PALETTE["StartFunction"]) - -# Build the call graph -create_downstream_call_trace(target_method) - -# Render the visualization -codebase.visualize(G) -``` - - -### Take a look - - -View on [codegen.sh](https://www.codegen.sh/codemod/6a34b45d-c8ad-422e-95a8-46d4dc3ce2b0/public/diff) - - -### Common Use Cases -The call graph visualization is particularly useful for: - - Understanding complex codebases - - Planning refactoring efforts - - Identifying tightly coupled components - - Analyzing critical paths - - Documenting system architecture - -## Function Dependency Graph - -Understanding symbol dependencies is crucial for maintaining and refactoring code. This tutorial will show you how to create visual dependency graphs using Codegen and NetworkX. We will be creating a dependency graph of the `get_query_runner` function. View the source code [here](https://github.com/PostHog/posthog/blob/c2986d9ac7502aa107a4afbe31b3633848be6582/posthog/hogql_queries/query_runner.py#L152). - -### Basic Setup - -We'll use the same basic setup as the [Call Trace Visualization](/tutorials/codebase-visualization#call-trace-visualization) tutorial. - - -### Building the Dependency Graph -The core function for building our dependency graph: -```python -def create_dependencies_visualization(symbol: Symbol, depth: int = 0): - """Creates visualization of symbol dependencies - - Args: - symbol (Symbol): Starting symbol to analyze - depth (int): Current recursion depth - """ - # Prevent excessive recursion - if depth >= MAX_DEPTH: - return - - # Process each dependency - for dep in symbol.dependencies: - dep_symbol = None - - # Handle different dependency types - if isinstance(dep, Symbol): - # Direct symbol reference - dep_symbol = dep - elif isinstance(dep, Import): - # Import statement - get resolved symbol - dep_symbol = dep.resolved_symbol if dep.resolved_symbol else None - - if dep_symbol: - # Add node with appropriate styling - G.add_node(dep_symbol, - color=COLOR_PALETTE.get(dep_symbol.__class__.__name__, - "#f694ff")) - - # Add dependency relationship - G.add_edge(symbol, dep_symbol) - - # Recurse unless it's a class (avoid complexity) - if not isinstance(dep_symbol, PyClass): - create_dependencies_visualization(dep_symbol, depth + 1) -``` - -### Visualizing the Graph -Finally, we can visualize our dependency graph starting from a specific symbol: -```python -# Get target symbol -target_func = codebase.get_function("get_query_runner") - -# Add root node -G.add_node(target_func, color=COLOR_PALETTE["StartFunction"]) - -# Generate dependency graph -create_dependencies_visualization(target_func) - -# Render visualization -codebase.visualize(G) -``` - -### Take a look - - -View on [codegen.sh](https://www.codegen.sh/codemod/39a36f0c-9d35-4666-9db7-12ae7c28fc17/public/diff) - - -## Blast Radius visualization - -Understanding the impact of code changes is crucial for safe refactoring. A blast radius visualization shows how changes to one function might affect other parts of the codebase by tracing usage relationships. In this tutorial we will create a blast radius visualization of the `export_asset` function. View the source code [here](https://github.com/PostHog/posthog/blob/c2986d9ac7502aa107a4afbe31b3633848be6582/posthog/tasks/exporter.py#L57). - -### Basic Setup - -We'll use the same basic setup as the [Call Trace Visualization](/tutorials/codebase-visualization#call-trace-visualization) tutorial. - - -### Helper Functions -We'll create some utility functions to help build our visualization: -```python -# List of HTTP methods to highlight -HTTP_METHODS = ["get", "put", "patch", "post", "head", "delete"] - -def generate_edge_meta(usage: Usage) -> dict: - """Generate metadata for graph edges - - Args: - usage (Usage): Usage relationship information - - Returns: - dict: Edge metadata including name and location - """ - return { - "name": usage.match.source, - "file_path": usage.match.filepath, - "start_point": usage.match.start_point, - "end_point": usage.match.end_point, - "symbol_name": usage.match.__class__.__name__ - } - -def is_http_method(symbol: PySymbol) -> bool: - """Check if a symbol is an HTTP endpoint method - - Args: - symbol (PySymbol): Symbol to check - - Returns: - bool: True if symbol is an HTTP method - """ - if isinstance(symbol, PyFunction) and symbol.is_method: - return symbol.name in HTTP_METHODS - return False -``` - -### Building the Blast Radius Visualization -The main function for creating our blast radius visualization: -```python -def create_blast_radius_visualization(symbol: PySymbol, depth: int = 0): - """Create visualization of symbol usage relationships - - Args: - symbol (PySymbol): Starting symbol to analyze - depth (int): Current recursion depth - """ - # Prevent excessive recursion - if depth >= MAX_DEPTH: - return - - # Process each usage of the symbol - for usage in symbol.usages: - usage_symbol = usage.usage_symbol - - # Determine node color based on type - if is_http_method(usage_symbol): - color = COLOR_PALETTE.get("HTTP_METHOD") - else: - color = COLOR_PALETTE.get(usage_symbol.__class__.__name__, "#f694ff") - - # Add node and edge to graph - G.add_node(usage_symbol, color=color) - G.add_edge(symbol, usage_symbol, **generate_edge_meta(usage)) - - # Recursively process usage symbol - create_blast_radius_visualization(usage_symbol, depth + 1) -``` - -### Visualizing the Graph -Finally, we can create our blast radius visualization: -```python -# Get target function to analyze -target_func = codebase.get_function('export_asset') - -# Add root node -G.add_node(target_func, color=COLOR_PALETTE.get("StartFunction")) - -# Build the visualization -create_blast_radius_visualization(target_func) - -# Render graph to show impact flow -# Note: a -> b means changes to a will impact b -codebase.visualize(G) -``` - -### Take a look - - -View on [codegen.sh](https://www.codegen.sh/codemod/d255db6c-9a86-4197-9b78-16c506858a3b/public/diff) - - -## What's Next? - - - - Learn how to use Codegen to create modular codebases. - - - Learn how to use Codegen to delete dead code. - - - Learn how to use Codegen to increase type coverage. - - - Explore the complete API documentation for all Codegen classes and methods. - - \ No newline at end of file diff --git a/docs/_deprecated/tutorials/converting-default-exports.mdx b/docs/_deprecated/tutorials/converting-default-exports.mdx deleted file mode 100644 index dd3064c8b..000000000 --- a/docs/_deprecated/tutorials/converting-default-exports.mdx +++ /dev/null @@ -1,172 +0,0 @@ ---- -title: "Converting Default Exports" -sidebarTitle: "Default Export Conversion" -description: "Convert default exports to named exports in your TypeScript codebase" -icon: "arrow-right-arrow-left" -iconType: "solid" ---- - -Codegen provides tools to help you migrate away from default exports to named exports in your TypeScript codebase. This tutorial builds on the concepts covered in [exports](/building-with-codegen/exports) to show you how to automate this conversion process. - -## Overview - -Default exports can make code harder to maintain and refactor. Converting them to named exports provides several benefits: - -- Better IDE support for imports and refactoring -- More explicit and consistent import statements -- Easier to track symbol usage across the codebase - -## Converting Default Exports - -Here's how to convert default exports to named exports: - -```python -for file in codebase.files: - target_file = file.filepath - if not target_file: - print(f"⚠️ Target file not found: {filepath}") - continue - - # Get corresponding non-shared file - non_shared_path = target_file.filepath.replace('/shared/', '/') - if not codebase.has_file(non_shared_path): - print(f"⚠️ No matching non-shared file for: {filepath}") - continue - - non_shared_file = codebase.get_file(non_shared_path) - print(f"πŸ“„ Processing {target_file.filepath}") - - # Process individual exports - for export in target_file.exports: - # Handle default exports - if export.is_reexport() and export.is_default_export(): - print(f" πŸ”„ Converting default export '{export.name}'") - default_export = next((e for e in non_shared_file.default_exports), None) - if default_export: - default_export.make_non_default() - - print(f"✨ Fixed exports in {target_file.filepath}") -``` - -## Understanding the Process - -Let's break down how this works: - - - - ```python - # Process individual exports - for export in target_file.exports: - # Handle default exports - if export.is_reexport() and export.is_default_export(): - print(f" πŸ”„ Converting default export '{export.name}'") - ``` - - The code identifies default exports by checking: - 1. If it's a re-export (`is_reexport()`) - 2. If it's a default export (`is_default_export()`) - - - - ```python - default_export = next((e for e in non_shared_file.default_exports), None) - if default_export: - default_export.make_non_default() - ``` - - For each default export: - 1. Find the corresponding export in the non-shared file - 2. Convert it to a named export using `make_non_default()` - - - - ```python - # Get corresponding non-shared file - non_shared_path = target_file.filepath.replace('/shared/', '/') - if not codebase.has_file(non_shared_path): - print(f"⚠️ No matching non-shared file for: {filepath}") - continue - - non_shared_file = codebase.get_file(non_shared_path) - ``` - - The code: - 1. Maps shared files to their non-shared counterparts - 2. Verifies the non-shared file exists - 3. Loads the non-shared file for processing - - - -## Best Practices - -1. **Check for Missing Files**: Always verify files exist before processing: -```python -if not target_file: - print(f"⚠️ Target file not found: {filepath}") - continue -``` - -2. **Log Progress**: Add logging to track the conversion process: -```python -print(f"πŸ“„ Processing {target_file.filepath}") -print(f" πŸ”„ Converting default export '{export.name}'") -``` - -3. **Handle Missing Exports**: Check that default exports exist before converting: -```python -default_export = next((e for e in non_shared_file.default_exports), None) -if default_export: - default_export.make_non_default() -``` - -## Next Steps - -After converting default exports: - -1. Run your test suite to verify everything still works -2. Update any import statements that were using default imports -3. Review the changes to ensure all exports were converted correctly -4. Consider adding ESLint rules to prevent new default exports - - -Remember to test thoroughly after converting default exports, as this change affects how other files import the converted modules. - - -### Related tutorials -- [Managing typescript exports](/tutorials/managing-typescript-exports) -- [Exports](/building-with-codegen/exports) -- [Dependencies and usages](/building-with-codegen/dependencies-and-usages) - -## Complete Codemod - -Here's the complete codemod that you can copy and use directly: - -```python - -for file in codebase.files: - target_file = file.filepath - if not target_file: - print(f"⚠️ Target file not found: {filepath}") - continue - - # Get corresponding non-shared file - non_shared_path = target_file.filepath.replace('/shared/', '/') - if not codebase.has_file(non_shared_path): - print(f"⚠️ No matching non-shared file for: {filepath}") - continue - - non_shared_file = codebase.get_file(non_shared_path) - print(f"πŸ“„ Processing {target_file.filepath}") - - # Process individual exports - for export in target_file.exports: - # Handle default exports - if export.is_reexport() and export.is_default_export(): - print(f" πŸ”„ Converting default export '{export.name}'") - default_export = next((e for e in non_shared_file.default_exports), None) - if default_export: - default_export.make_non_default() - - print(f"✨ Fixed exports in {target_file.filepath}") - -``` \ No newline at end of file diff --git a/docs/_deprecated/tutorials/creating-documentation.mdx b/docs/_deprecated/tutorials/creating-documentation.mdx deleted file mode 100644 index f11169b36..000000000 --- a/docs/_deprecated/tutorials/creating-documentation.mdx +++ /dev/null @@ -1,213 +0,0 @@ ---- -title: "Creating Documentation" -sidebarTitle: "Documentation" -icon: "book" -iconType: "solid" ---- - -This guide demonstrates how to determine docs coverage and create documentation for your codebase. - -This primarily leverages two APIs: -- [codebase.ai(...)](/api-reference/core/Codebase#ai) for generating docstrings -- [function.set_docstring(...)](/api-reference/core/HasBlock#set-docstring) for modifying them - -## Determining Documentation Coverage - -In order to determine the extent of your documentation coverage, you can iterate through all symbols of interest and count the number of docstrings: - -To see your current documentation coverage, you can iterate through all symbols of interest and count the number of docstrings: - -```python python -# Initialize counters -total_functions = 0 -functions_with_docs = 0 -total_classes = 0 -classes_with_docs = 0 - -# Check functions -for function in codebase.functions: - total_functions += 1 - if function.docstring: - functions_with_docs += 1 - -# Check classes -for cls in codebase.classes: - total_classes += 1 - if cls.docstring: - classes_with_docs += 1 - -# Calculate percentages -func_coverage = (functions_with_docs / total_functions * 100) if total_functions > 0 else 0 -class_coverage = (classes_with_docs / total_classes * 100) if total_classes > 0 else 0 - -# Print results with emojis -print("\nπŸ“Š Documentation Coverage Report:") -print(f"\nπŸ“ Functions:") -print(f" β€’ Total: {total_functions}") -print(f" β€’ Documented: {functions_with_docs}") -print(f" β€’ Coverage: {func_coverage:.1f}%") - -print(f"\nπŸ“š Classes:") -print(f" β€’ Total: {total_classes}") -print(f" β€’ Documented: {classes_with_docs}") -print(f" β€’ Coverage: {class_coverage:.1f}%") - -print(f"\n🎯 Overall Coverage: {((functions_with_docs + classes_with_docs) / (total_functions + total_classes) * 100):.1f}%") -``` - -Which provides the following output: -``` -πŸ“Š Documentation Coverage Report: -πŸ“ Functions: - β€’ Total: 1384 - β€’ Documented: 331 - β€’ Coverage: 23.9% -πŸ“š Classes: - β€’ Total: 453 - β€’ Documented: 91 - β€’ Coverage: 20.1% -🎯 Overall Coverage: 23.0% -``` - -## Identifying Areas of Low Documentation Coverage - - -To identify areas of low documentation coverage, you can iterate through all directories and count the number of functions with docstrings. - -Learn more about [Directories here](/building-with-codegen/files-and-directories). - -```python python -# Track directory stats -dir_stats = {} - -# Analyze each directory -for directory in codebase.directories: - # Skip test, sql and alembic directories - if any(x in directory.path.lower() for x in ['test', 'sql', 'alembic']): - continue - - # Get undecorated functions - funcs = [f for f in directory.functions if not f.is_decorated] - total = len(funcs) - - # Only analyze dirs with >10 functions - if total > 10: - documented = sum(1 for f in funcs if f.docstring) - coverage = (documented / total * 100) - dir_stats[directory.path] = { - 'total': total, - 'documented': documented, - 'coverage': coverage - } - -# Find lowest coverage directory -if dir_stats: - lowest_dir = min(dir_stats.items(), key=lambda x: x[1]['coverage']) - path, stats = lowest_dir - - print(f"πŸ“‰ Lowest coverage directory: '{path}'") - print(f" β€’ Total functions: {stats['total']}") - print(f" β€’ Documented: {stats['documented']}") - print(f" β€’ Coverage: {stats['coverage']:.1f}%") - - # Print all directory stats for comparison - print("\nπŸ“Š All directory coverage rates:") - for path, stats in sorted(dir_stats.items(), key=lambda x: x[1]['coverage']): - print(f" '{path}': {stats['coverage']:.1f}% ({stats['documented']}/{stats['total']} functions)") -``` - -Which provides the following output: -```python -πŸ“‰ Lowest coverage directory: 'codegen-backend/app/utils/github_utils/branch' - β€’ Total functions: 12 - β€’ Documented: 0 - β€’ Coverage: 0.0% -πŸ“Š All directory coverage rates: - 'codegen-backend/app/utils/github_utils/branch': 0.0% (0/12 functions) - 'codegen-backend/app/utils/slack': 14.3% (2/14 functions) - 'codegen-backend/app/modal_app/github': 18.2% (2/11 functions) - 'codegen-backend/app/modal_app/slack': 18.2% (2/11 functions) - 'codegen-backend/app/utils/github_utils/webhook': 21.4% (6/28 functions) - 'codegen-backend/app/modal_app/cron': 23.1% (3/13 functions) - 'codegen-backend/app/utils/github_utils': 23.5% (39/166 functions) - 'codegen-backend/app/codemod': 25.0% (7/28 functions) -``` - -## Leveraging AI for Generating Documentation - -For non-trivial codebases, it can be challenging to achieve full documentation coverage. - -The most efficient way to edit informative docstrings is to use [codebase.ai](/api-reference/core/Codebase#ai) to generate docstrings, then use the [set_docstring](/api-reference/core/HasBlock#set-docstring) method to update the docstring. - -Learn more about using AI in our [guides](/building-with-codegen/calling-out-to-llms). - -```python python -# Import datetime for timestamp -from datetime import datetime - -# Get current timestamp -timestamp = datetime.now().strftime("%B %d, %Y") - -print("πŸ“š Generating and Updating Function Documentation") - -# Process all functions in the codebase -for function in codebase.functions: - current_docstring = function.docstring() - - if current_docstring: - # Update existing docstring to be more descriptive - new_docstring = codebase.ai( - f"Update the docstring for {function.name} to be more descriptive and comprehensive.", - target=function - ) - new_docstring += f"\n\nUpdated on: {timestamp}" - else: - # Generate new docstring for function - new_docstring = codebase.ai( - f"Generate a comprehensive docstring for {function.name} including parameters, return type, and description.", - target=function - ) - new_docstring += f"\n\nCreated on: {timestamp}" - - # Set the new or updated docstring - function.set_docstring(new_docstring) -``` - - - -## Adding Explicit Parameter Names and Types - -Alternatively, you can also rely on deterministic string formatting to edit docstrings. - -To add "Google-style" parameter names and types to a function docstring, you can use the following code snippet: - -```python python -# Iterate through all functions in the codebase -for function in codebase.functions: - # Skip if function already has a docstring - if function.docstring: - continue - - # Build parameter documentation - param_docs = [] - for param in function.parameters: - param_type = param.type.source if param.is_typed else "Any" - param_docs.append(f" {param.name} ({param_type}): Description of {param.name}") - - # Get return type if present - return_type = function.return_type.source if function.return_type else "None" - - # Create Google-style docstring - docstring = f'''""" - Description of {function.name}. - - Args: -{chr(10).join(param_docs)} - - Returns: - {return_type}: Description of return value - """''' - - # Set the new docstring - function.set_docstring(docstring) -``` diff --git a/docs/_deprecated/tutorials/deep-code-research.mdx b/docs/_deprecated/tutorials/deep-code-research.mdx deleted file mode 100644 index 6b1e72b2b..000000000 --- a/docs/_deprecated/tutorials/deep-code-research.mdx +++ /dev/null @@ -1,215 +0,0 @@ ---- -title: "Deep Code Research with AI" -sidebarTitle: "Code Research Agent" -icon: "magnifying-glass" -iconType: "solid" ---- - -This guide demonstrates how to build an intelligent code research tool that can analyze and explain codebases using Codegen's and LangChain. The tool combines semantic code search, dependency analysis, and natural language understanding to help developers quickly understand new codebases. - -View the full code on [GitHub](https://github.com/codegen-sh/codegen-sdk/tree/develop/codegen-examples/examples/deep_code_research) - -This example works with any public GitHub repository - just provide the repo name in the format owner/repo - -## Overview - -The process involves three main components: - -1. A CLI interface for interacting with the research agent -2. A set of code analysis tools powered by Codegen -3. An LLM-powered agent that combines the tools to answer questions - -Let's walk through building each component. - -## Step 1: Setting Up the Research Tools - -First, let's import the necessary components and set up our research tools: - -```python -from codegen import Codebase -from codegen.extensions.langchain.agent import create_agent_with_tools -from codegen.extensions.langchain.tools import ( - ListDirectoryTool, - RevealSymbolTool, - SearchTool, - SemanticSearchTool, - ViewFileTool, -) -from langchain_core.messages import SystemMessage -``` - -We'll create a function to initialize our codebase with a nice progress indicator: - -```python -def initialize_codebase(repo_name: str) -> Optional[Codebase]: - """Initialize a codebase with a spinner showing progress.""" - with console.status("") as status: - try: - status.update(f"[bold blue]Cloning {repo_name}...[/bold blue]") - codebase = Codebase.from_repo(repo_name) - status.update("[bold green]βœ“ Repository cloned successfully![/bold green]") - return codebase - except Exception as e: - console.print(f"[bold red]Error initializing codebase:[/bold red] {e}") - return None -``` - -Then we'll set up our research tools: - -```python -# Create research tools -tools = [ - ViewFileTool(codebase), # View file contents - ListDirectoryTool(codebase), # Explore directory structure - SearchTool(codebase), # Text-based search - SemanticSearchTool(codebase), # Natural language search - RevealSymbolTool(codebase), # Analyze symbol relationships -] -``` - -Each tool provides specific capabilities: -- `ViewFileTool`: Read and understand file contents -- `ListDirectoryTool`: Explore the codebase structure -- `SearchTool`: Find specific code patterns -- `SemanticSearchTool`: Search using natural language -- `RevealSymbolTool`: Analyze dependencies and usages - -## Step 2: Creating the Research Agent - -Next, we'll create an agent that can use these tools intelligently. We'll give it a detailed prompt about its role: - -```python -RESEARCH_AGENT_PROMPT = """You are a code research expert. Your goal is to help users understand codebases by: -1. Finding relevant code through semantic and text search -2. Analyzing symbol relationships and dependencies -3. Exploring directory structures -4. Reading and explaining code - -Always explain your findings in detail and provide context about how different parts of the code relate to each other. -When analyzing code, consider: -- The purpose and functionality of each component -- How different parts interact -- Key patterns and design decisions -- Potential areas for improvement - -Break down complex concepts into understandable pieces and use examples when helpful.""" - -# Initialize the agent -agent = create_agent_with_tools( - codebase=codebase, - tools=tools, - chat_history=[SystemMessage(content=RESEARCH_AGENT_PROMPT)], - verbose=True -) -``` - -## Step 3: Building the CLI Interface - -Finally, we'll create a user-friendly CLI interface using rich-click: - -```python -import rich_click as click -from rich.console import Console -from rich.markdown import Markdown - -@click.group() -def cli(): - """πŸ” Codegen Code Research CLI""" - pass - -@cli.command() -@click.argument("repo_name", required=False) -@click.option("--query", "-q", default=None, help="Initial research query.") -def research(repo_name: Optional[str] = None, query: Optional[str] = None): - """Start a code research session.""" - # Initialize codebase - codebase = initialize_codebase(repo_name) - - # Create and run the agent - agent = create_research_agent(codebase) - - # Main research loop - while True: - if not query: - query = Prompt.ask("[bold cyan]Research query[/bold cyan]") - - result = agent.invoke( - {"input": query}, - config={"configurable": {"thread_id": 1}} - ) - console.print(Markdown(result["messages"][-1].content)) - - query = None # Clear for next iteration -``` - -## Using the Research Tool - -You can use the tool in several ways: - -1. Interactive mode (will prompt for repo): -```bash -python run.py research -``` - -2. Specify a repository: -```bash -python run.py research "fastapi/fastapi" -``` - -3. Start with an initial query: -```bash -python run.py research "fastapi/fastapi" -q "Explain the main components" -``` - -Example research queries: -- "Explain the main components and their relationships" -- "Find all usages of the FastAPI class" -- "Show me the dependency graph for the routing module" -- "What design patterns are used in this codebase?" - - - The agent maintains conversation history, so you can ask follow-up questions - and build on previous findings. - - -## Advanced Usage - -### Custom Research Tools - -You can extend the agent with custom tools for specific analysis needs: - -```python -from langchain.tools import BaseTool -from pydantic import BaseModel, Field - -class CustomAnalysisTool(BaseTool): - """Custom tool for specialized code analysis.""" - name = "custom_analysis" - description = "Performs specialized code analysis" - - def _run(self, query: str) -> str: - # Custom analysis logic - return results - -# Add to tools list -tools.append(CustomAnalysisTool()) -``` - -### Customizing the Agent - -You can modify the agent's behavior by adjusting its prompt: - -```python -CUSTOM_PROMPT = """You are a specialized code reviewer focused on: -1. Security best practices -2. Performance optimization -3. Code maintainability -... -""" - -agent = create_agent_with_tools( - codebase=codebase, - tools=tools, - chat_history=[SystemMessage(content=CUSTOM_PROMPT)], -) -``` diff --git a/docs/_deprecated/tutorials/deleting-dead-code.mdx b/docs/_deprecated/tutorials/deleting-dead-code.mdx deleted file mode 100644 index 655108f59..000000000 --- a/docs/_deprecated/tutorials/deleting-dead-code.mdx +++ /dev/null @@ -1,113 +0,0 @@ ---- -title: "Deleting Dead Code" -sidebarTitle: "Dead Code" -icon: "trash" -iconType: "solid" ---- - -Dead code refers to code that is not being used or referenced anywhere in your codebase. - -However, it's important to note that some code might appear unused but should not be deleted, including: -- Test files and test functions -- Functions with decorators (which may be called indirectly) -- Public API endpoints -- Event handlers or callback functions -- Code used through reflection or dynamic imports - -This guide will show you how to safely identify and remove genuinely unused code while preserving important functionality. - -## Overview - -To simply identify code without any external usages, you can check for the absence of [Symbol.usages](/api-reference/core/Symbol#usages). - -See [Dependencies and Usages](/building-with-codegen/dependencies-and-usages) for more information on how to use these properties. - -```python -# Iterate through all functions in the codebase -for function in codebase.functions: - # Remove functions with no usages - if not function.usages: - function.remove() - -# Commit -codebase.commit() -``` - - -This will remove all code that is not explicitly referenced elsewhere, including tests, endpoints, etc. This is almost certainly not what you want. We recommend further filtering. - - -## Filtering for Special Cases - -To filter out special cases that are not explicitly referenced yet are, nonetheless, worth keeping around, you can use the following pattern: - - -```python -for function in codebase.functions: - - # Skip test files - if "test" in function.file.filepath: - continue - - # Skip decorated functions - if function.decorators: - continue - - # Skip public routes, e.g. next.js endpoints - # (Typescript only) - if 'routes' in function.file.filepath and function.is_jsx: - continue - - # ... etc. - - # Check if the function has no usages and no call sites - if not function.usages and not function.call_sites: - # Print a message indicating the removal of the function - print(f"Removing unused function: {function.name}") - # Remove the function from the file - function.remove() - -# Commit -codebase.commit() -``` - - -## Cleaning Up Unused Variables - -To remove unused variables, you can check for their usages within their scope: - -```python typescript -for func in codebase.functions: - # Iterate through local variable assignments in the function - for var_assignments in func.code_block.local_var_assignments: - # Check if the local variable assignment has no usages - if not var_assignments.local_usages: - # Remove the local variable assignment - var_assignments.remove() - -# Commit -codebase.commit() -``` - - -## Cleaning Up After Removal - -After removing dead code, you may need to clean up any remaining artifacts: - -```python -for file in codebase.files: - # Check if the file is empty - if not file.content.strip(): - # Print a message indicating the removal of the empty file - print(f"Removing empty file: {file.filepath}") - # Remove the empty file - file.remove() - -# commit is NECESSARY to remove the files from the codebase -codebase.commit() - -# Remove redundant newlines -for file in codebase.files: - # Replace three or more consecutive newlines with two newlines - file.edit(re.sub(r"\n{3,}", "\n\n", file.content)) -``` diff --git a/docs/_deprecated/tutorials/fixing-import-loops-in-pytorch.mdx b/docs/_deprecated/tutorials/fixing-import-loops-in-pytorch.mdx deleted file mode 100644 index 2c9faf55d..000000000 --- a/docs/_deprecated/tutorials/fixing-import-loops-in-pytorch.mdx +++ /dev/null @@ -1,276 +0,0 @@ ---- -title: "Fixing Import Loops" -description: "Learn how to identify and fix problematic import loops using Codegen." -icon: "arrows-rotate" -iconType: "solid" ---- - - - - - -Import loops occur when two or more Python modules depend on each other, creating a circular dependency. While some import cycles can be harmless, others can lead to runtime errors and make code harder to maintain. - -In this tutorial, we'll explore how to identify and fix problematic import cycles using Codegen. - - -You can find the complete example code in our [examples repository](https://github.com/codegen-sh/codegen-sdk/tree/develop/codegen-examples/examples/removing_import_loops_in_pytorch). - - -## Overview - -The steps to identify and fix import loops are as follows: -1. Detect import loops -2. Visualize them -3. Identify problematic cycles with mixed static/dynamic imports -4. Fix these cycles using Codegen - -# Step 1: Detect Import Loops -- Create a graph -- Loop through imports in the codebase and add edges between the import files -- Find strongly connected components using Networkx (the import loops) -```python -G = nx.MultiDiGraph() - -# Add all edges to the graph -for imp in codebase.imports: - if imp.from_file and imp.to_file: - edge_color = "red" if imp.is_dynamic else "black" - edge_label = "dynamic" if imp.is_dynamic else "static" - - # Store the import statement and its metadata - G.add_edge( - imp.to_file.filepath, - imp.from_file.filepath, - color=edge_color, - label=edge_label, - is_dynamic=imp.is_dynamic, - import_statement=imp, # Store the whole import object - key=id(imp.import_statement), - ) -# Find strongly connected components -cycles = [scc for scc in nx.strongly_connected_components(G) if len(scc) > 1] - -print(f"πŸ”„ Found {len(cycles)} import cycles:") -for i, cycle in enumerate(cycles, 1): - print(f"\nCycle #{i}:") - print(f"Size: {len(cycle)} files") - - # Create subgraph for this cycle to count edges - cycle_subgraph = G.subgraph(cycle) - - # Count total edges - total_edges = cycle_subgraph.number_of_edges() - print(f"Total number of imports in cycle: {total_edges}") - - # Count dynamic and static imports separately - dynamic_imports = sum(1 for u, v, data in cycle_subgraph.edges(data=True) if data.get("color") == "red") - static_imports = sum(1 for u, v, data in cycle_subgraph.edges(data=True) if data.get("color") == "black") - - print(f"Number of dynamic imports: {dynamic_imports}") - print(f"Number of static imports: {static_imports}") -``` - - -## Understanding Import Cycles - -Not all import cycles are problematic! Here's an example of a cycle that one may think would cause an error but it does not because due to using dynamic imports. - -```python -# top level import in in APoT_tensor.py -from quantizer.py import objectA -``` - -```python -# dynamic import in quantizer.py -def some_func(): - # dynamic import (evaluated when some_func() is called) - from APoT_tensor.py import objectB -``` - - - -A dynamic import is an import defined inside of a function, method or any executable body of code which delays the import execution until that function, method or body of code is called. - -You can use [Import.is_dynamic](/api-reference/core/Import#is-dynamic) to check if the import is dynamic allowing you to investigate imports that are handled more intentionally. - -# Step 2: Visualize Import Loops -- Create a new subgraph to visualize one cycle -- color and label the edges based on their type (dynamic/static) -- visualize the cycle graph using [codebase.visualize(graph)](/api-reference/core/Codebase#visualize) - -Learn more about codebase visualization [here](/building-with-codegen/codebase-visualization) - -```python -cycle = cycles[0] - -def create_single_loop_graph(cycle): - cycle_graph = nx.MultiDiGraph() # Changed to MultiDiGraph to support multiple edges - cycle = list(cycle) - for i in range(len(cycle)): - for j in range(len(cycle)): - # Get all edges between these nodes from original graph - edge_data_dict = G.get_edge_data(cycle[i], cycle[j]) - if edge_data_dict: - # For each edge between these nodes - for edge_key, edge_data in edge_data_dict.items(): - # Add edge with all its attributes to cycle graph - cycle_graph.add_edge(cycle[i], cycle[j], **edge_data) - return cycle_graph - - -cycle_graph = create_single_loop_graph(cycle) -codebase.visualize(cycle_graph) -``` - - - - - - -# Step 3: Identify problematic cycles with mixed static & dynamic imports - -The import loops that we are really concerned about are those that have mixed static/dynamic imports. - -Here's an example of a problematic cycle that we want to fix: - -```python -# In flex_decoding.py -from .flex_attention import ( - compute_forward_block_mn, - compute_forward_inner, - # ... more static imports -) - -# Also in flex_decoding.py -def create_flex_decoding_kernel(*args, **kwargs): - from .flex_attention import set_head_dim_values # dynamic import -``` - -It's clear that there is both a top level and a dynamic import that imports from the *same* module. Thus, this can cause issues if not handled carefully. - - - -Let's find these problematic cycles: - -```python -def find_problematic_import_loops(G, sccs): - """Find cycles where files have both static and dynamic imports between them.""" - problematic_cycles = [] - - for i, scc in enumerate(sccs): - if i == 2: # skipping the second import loop as it's incredibly long (it's also invalid) - continue - mixed_import_files = {} # (from_file, to_file) -> {dynamic: count, static: count} - - # Check all file pairs in the cycle - for from_file in scc: - for to_file in scc: - if G.has_edge(from_file, to_file): - # Get all edges between these files - edges = G.get_edge_data(from_file, to_file) - - # Count imports by type - dynamic_count = sum(1 for e in edges.values() if e["color"] == "red") - static_count = sum(1 for e in edges.values() if e["color"] == "black") - - # If we have both types between same files, this is problematic - if dynamic_count > 0 and static_count > 0: - mixed_import_files[(from_file, to_file)] = {"dynamic": dynamic_count, "static": static_count, "edges": edges} - - if mixed_import_files: - problematic_cycles.append({"files": scc, "mixed_imports": mixed_import_files, "index": i}) - - # Print findings - print(f"Found {len(problematic_cycles)} cycles with mixed imports:") - for i, cycle in enumerate(problematic_cycles): - print(f"\n⚠️ Problematic Cycle #{i + 1}:") - print(f"\n⚠️ Index #{cycle['index']}:") - print(f"Size: {len(cycle['files'])} files") - - for (from_file, to_file), data in cycle["mixed_imports"].items(): - print("\nπŸ“ Mixed imports detected:") - print(f" From: {from_file}") - print(f" To: {to_file}") - print(f" Dynamic imports: {data['dynamic']}") - print(f" Static imports: {data['static']}") - - return problematic_cycles - -problematic_cycles = find_problematic_import_loops(G, cycles) -``` - -# Step 4: Fix the loop by moving the shared symbols to a separate `utils.py` file -One common fix to this problem to break this cycle is to move all the shared symbols to a separate `utils.py` file. We can do this using the method [symbol.move_to_file](/api-reference/core/Symbol#move-to-file): - -Learn more about moving symbols [here](/building-with-codegen/moving-symbols) - -```python -# Create new utils file -utils_file = codebase.create_file("torch/_inductor/kernel/flex_utils.py") - -# Get the two files involved in the import cycle -decoding_file = codebase.get_file("torch/_inductor/kernel/flex_decoding.py") -attention_file = codebase.get_file("torch/_inductor/kernel/flex_attention.py") -attention_file_path = "torch/_inductor/kernel/flex_attention.py" -decoding_file_path = "torch/_inductor/kernel/flex_decoding.py" - -# Track symbols to move -symbols_to_move = set() - -# Find imports from flex_attention in flex_decoding -for imp in decoding_file.imports: - if imp.from_file and imp.from_file.filepath == attention_file_path: - # Get the actual symbol from flex_attention - if imp.imported_symbol: - symbols_to_move.add(imp.imported_symbol) - -# Move identified symbols to utils file -for symbol in symbols_to_move: - symbol.move_to_file(utils_file) - -print(f"πŸ”„ Moved {len(symbols_to_move)} symbols to flex_utils.py") -for symbol in symbols_to_move: - print(symbol.name) - -# Commit changes -codebase.commit() -``` - -# Conclusions & Next Steps - -Import loops can be tricky to identify and fix, but Codegen provides powerful tools to help manage them: - -- Use `codebase.imports` to analyze import relationships across your project -- Visualize import cycles to better understand dependencies -- Distinguish between static and dynamic imports using `Import.is_dynamic` -- Move shared symbols to break cycles using `symbol.move_to_file` - -Here are some next steps you can take: - -1. **Analyze Your Codebase**: Run similar analysis on your own codebase to identify potential import cycles -2. **Create Import Guidelines**: Establish best practices for your team around when to use static vs dynamic imports -3. **Automate Fixes**: Create scripts to automatically detect and fix problematic import patterns -4. **Monitor Changes**: Set up CI checks to prevent new problematic import cycles from being introduced - - -For more examples of codebase analysis and refactoring, check out our other [tutorials](/tutorials/at-a-glance). - \ No newline at end of file diff --git a/docs/_deprecated/tutorials/flask-to-fastapi.mdx b/docs/_deprecated/tutorials/flask-to-fastapi.mdx deleted file mode 100644 index e8076ceeb..000000000 --- a/docs/_deprecated/tutorials/flask-to-fastapi.mdx +++ /dev/null @@ -1,217 +0,0 @@ ---- -title: "Migrating from Flask to FastAPI" -sidebarTitle: "Flask to FastAPI" -icon: "bolt" -iconType: "solid" ---- - -Migrating from [Flask](https://flask.palletsprojects.com/) to [FastAPI](https://fastapi.tiangolo.com/) involves several key changes to your codebase. This guide will walk you through using Codegen to automate this migration, handling imports, route decorators, static files, and template rendering. - -You can find the complete example code in our [examples repository](https://github.com/codegen-sh/codegen-sdk/tree/develop/codegen-examples/examples/flask_to_fastapi_migration) - -## Overview - -The migration process involves four main steps: - -1. Updating imports and initialization -2. Converting route decorators -3. Setting up static file handling -4. Updating template handling - -Let's walk through each step using Codegen. - -## I: Update Imports and Initialization - -First, we need to update Flask imports to their FastAPI equivalents and modify the app initialization: - - - Learn more about [imports here](/building-with-codegen/imports). - - -```python -from codegen import Codebase - -# Parse the codebase -codebase = Codebase("./") - -# Update imports and initialization -for file in codebase.files: - # Update Flask to FastAPI imports - for imp in file.imports: - if imp.name == "Flask": - imp.set_name("FastAPI") - elif imp.module == "flask": - imp.set_module("fastapi") - - # Update app initialization - for call in file.function_calls: - if call.name == "Flask": - call.set_name("FastAPI") - # Remove __name__ argument (not needed in FastAPI) - if len(call.args) > 0 and call.args[0].value == "__name__": - call.args[0].remove() -``` - -This transforms code from: - -```python -from flask import Flask -app = Flask(__name__) -``` - -to: - -```python -from fastapi import FastAPI -app = FastAPI() -``` - - - FastAPI doesn't require the `__name__` argument that Flask uses for template - resolution. Codegen automatically removes it during migration. - - -## II: Convert Route Decorators - -Next, we update Flask's route decorators to FastAPI's operation decorators: - -```python -for function in file.functions: - for decorator in function.decorators: - if "@app.route" in decorator.source: - route = decorator.source.split('"')[1] - method = "get" # Default to GET - if "methods=" in decorator.source: - methods = decorator.source.split("methods=")[1].split("]")[0] - if "post" in methods.lower(): - method = "post" - elif "put" in methods.lower(): - method = "put" - elif "delete" in methods.lower(): - method = "delete" - decorator.edit(f'@app.{method}("{route}")') -``` - -This converts decorators from Flask style: - -```python -@app.route("/users", methods=["POST"]) -def create_user(): - pass -``` - -to FastAPI style: - -```python -@app.post("/users") -def create_user(): - pass -``` - - - FastAPI provides specific decorators for each HTTP method, making the API more - explicit and enabling better type checking and OpenAPI documentation. - - -## III: Setup Static Files - -FastAPI handles static files differently than Flask. We need to add the StaticFiles mounting: - -```python -# Add StaticFiles import -file.add_import("from fastapi.staticfiles import StaticFiles") - -# Mount static directory -file.add_symbol_from_source( - 'app.mount("/static", StaticFiles(directory="static"), name="static")' -) -``` - -This sets up static file serving equivalent to Flask's automatic static file handling. - - - FastAPI requires explicit mounting of static directories, which provides more - flexibility in how you serve static files. - - -## IV: Update Template Handling - -Finally, we update the template rendering to use FastAPI's Jinja2Templates: - -```python -for func_call in file.function_calls: - if func_call.name == "render_template": - # Convert to FastAPI's template response - func_call.set_name("Jinja2Templates(directory='templates').TemplateResponse") - if len(func_call.args) > 1: - # Convert template variables to context dict - context_arg = ", ".join( - f"{arg.name}={arg.value}" for arg in func_call.args[1:] - ) - func_call.set_kwarg("context", f"{'{'}{context_arg}{'}'}") - # Add required request parameter - func_call.set_kwarg("request", "request") -``` - -This transforms template rendering from Flask style: - -```python -@app.get("/users") -def list_users(): - return render_template("users.html", users=users) -``` - -to FastAPI style: - -```python -@app.get("/users") -def list_users(request: Request): - return Jinja2Templates(directory="templates").TemplateResponse( - "users.html", - context={"users": users}, - request=request - ) -``` - - - FastAPI requires the `request` object to be passed to templates. Codegen - automatically adds this parameter during migration. - - -## Running the Migration - -You can run the complete migration using our example script: - -```bash -git clone https://github.com/codegen-sh/codegen-sdk.git -cd codegen-examples/examples/flask_to_fastapi_migration -python run.py -``` - -The script will: - -1. Process all Python [files](/api-reference/python/PyFile) in your codebase -2. Apply the transformations in the correct order -3. Maintain your code's functionality while updating to FastAPI patterns - -## Next Steps - -After migration, you might want to: - -- Add type hints to your route parameters -- Set up dependency injection -- Add request/response models -- Configure CORS and middleware - -Check out these related tutorials: - -- [Increase Type Coverage](/tutorials/increase-type-coverage) -- [Managing TypeScript Exports](/tutorials/managing-typescript-exports) -- [Organizing Your Codebase](/tutorials/organize-your-codebase) - -## Learn More - -- [FastAPI Documentation](https://fastapi.tiangolo.com/) -- [Codegen API Reference](/api-reference) -- [Moving Symbols Guide](/building-with-codegen/moving-symbols) -- [Dependencies and Usages](/building-with-codegen/dependencies-and-usages) diff --git a/docs/_deprecated/tutorials/increase-type-coverage.mdx b/docs/_deprecated/tutorials/increase-type-coverage.mdx deleted file mode 100644 index 53c7785f1..000000000 --- a/docs/_deprecated/tutorials/increase-type-coverage.mdx +++ /dev/null @@ -1,122 +0,0 @@ ---- -title: "Increasing Type Coverage" -sidebarTitle: "Type Coverage" -icon: "shield-check" -iconType: "solid" ---- - -This guide demonstrates how to analyze and manipulate type annotations with Codegen SDK. - -Common use cases include: - -- Adding a type to a union or generic type -- Checking if a generic type has a given subtype -- Resolving a type annotation - - - Adding type hints can improve developer experience and [significantly speed up](https://github.com/microsoft/Typescript/wiki/Performance#using-type-annotations) programs like the Typescript compiler and `mypy`. - - -See [Type Annotations](/building-with-codegen/type-annotations) for a general overview of the type maninpulation - -## APIs for monitoring types - -Codegen programs typically access type annotations through the following APIs: -- [Parameter.type](/api-reference/core/Parameter#type) -- [Function.return_type](/api-reference/python/PyFunction#return-type) -- [Assignment.type](/api-reference/core/Assignment#type) - -Each of these has an associated setter. - - -## Finding the extent of your type coverage - -To get an indication of your progress on type coverage, analyze the percentage of typed elements across your codebase - -```python -# Initialize counters for parameters -total_parameters = 0 -typed_parameters = 0 - -# Initialize counters for return types -total_functions = 0 -typed_returns = 0 - -# Initialize counters for class attributes -total_attributes = 0 -typed_attributes = 0 - -# Count parameter and return type coverage -for function in codebase.functions: - # Count parameters - total_parameters += len(function.parameters) - typed_parameters += sum(1 for param in function.parameters if param.is_typed) - - # Count return types - total_functions += 1 - if function.return_type and function.return_type.is_typed: - typed_returns += 1 - -# Count class attribute coverage -for cls in codebase.classes: - for attr in cls.attributes: - total_attributes += 1 - if attr.is_typed: - typed_attributes += 1 - -# Calculate percentages -param_percentage = (typed_parameters / total_parameters * 100) if total_parameters > 0 else 0 -return_percentage = (typed_returns / total_functions * 100) if total_functions > 0 else 0 -attr_percentage = (typed_attributes / total_attributes * 100) if total_attributes > 0 else 0 - -# Print results -print("\nType Coverage Analysis") -print("---------------------") -print(f"Parameters: {param_percentage:.1f}% ({typed_parameters}/{total_parameters} typed)") -print(f"Return types: {return_percentage:.1f}% ({typed_returns}/{total_functions} typed)") -print(f"Class attributes: {attr_percentage:.1f}% ({typed_attributes}/{total_attributes} typed)") -``` - -This analysis gives you a breakdown of type coverage across three key areas: -1. Function parameters - Arguments passed to functions -2. Return types - Function return type annotations -3. Class attributes - Type hints on class variables - - - Focus first on adding types to the most frequently used functions and classes, as these will have the biggest impact on type checking and IDE support. - - -## Adding simple return type annotations - -To add a return type, use `function.set_return_type`. The script below will add a `-> None` return type to all functions that contain no return statements: - - -```python For Python -for file in codebase.files: - # Check if 'app' is in the file's filepath - if "app" in file.filepath: - # Iterate through all functions in the file - for function in file.functions: - # Check if the function has no return statements - if len(function.return_statements) == 0: - # Set the return type to None - function.set_return_type("None") -``` - -```python For Typescript -for file in codebase.files: - # Check if 'app' is in the file's filepath - if "app" in file.filepath: - # Iterate through all functions in the file - for function in file.functions: - # Check if the function has no return statements - if len(function.return_statements) == 0: - # Set the return type to None - function.set_return_type("null") -``` - - - -## Coming Soon: Advanced Type Inference - -Codegen is building out an API for direct interface with `tsc` and `mypy` for precise type inference. Interested piloting this API? Let us know! \ No newline at end of file diff --git a/docs/_deprecated/tutorials/manage-feature-flags.mdx b/docs/_deprecated/tutorials/manage-feature-flags.mdx deleted file mode 100644 index 41ac176a0..000000000 --- a/docs/_deprecated/tutorials/manage-feature-flags.mdx +++ /dev/null @@ -1,157 +0,0 @@ ---- -title: "Managing Feature Flags" -sidebarTitle: "Feature Flags" -icon: "flag" -iconType: "solid" ---- - -Codegen has been used in production for multi-million line codebases to automatically delete "dead" (rolled-out) feature flags. This guide will walk you through analyzing feature flag usage and safely removing rolled out flags. - - - Every codebase does feature flags differently. This guide shows common techniques and syntax but likely requires adaptation to codebase-specific circumstances. - - -## Analyzing Feature Flag Usage - -Before removing a feature flag, it's important to analyze its usage across the codebase. Codegen provides tools to help identify where and how feature flags are used. - -### For Python Codebases - -For Python codebases using a `FeatureFlags` class pattern like so: -```python -class FeatureFlags: - FEATURE_1 = False - FEATURE_2 = True -``` - -You can use [Class.get_attribute(...)](/api-reference/core/Class#get-attribute) and [Attribute.usages](/api-reference/core/Attribute#usages) to analyze the coverage of your flags, like so: - - - -```python -feature_flag_usage = {} -feature_flag_class = codebase.get_class('FeatureFlag') - -if feature_flag_class: - # Initialize usage count for all attributes - for attr in feature_flag_class.attributes: - feature_flag_usage[attr.name] = 0 - - # Get all usages of the FeatureFlag class - for usage in feature_flag_class.usages: - usage_source = usage.usage_symbol.source if hasattr(usage, 'usage_symbol') else str(usage) - for flag_name in feature_flag_usage.keys(): - if f"FeatureFlag.{flag_name}" in usage_source: - feature_flag_usage[flag_name] += 1 - - sorted_flags = sorted(feature_flag_usage.items(), key=lambda x: x[1], reverse=True) - - print("Feature Flag Usage Table:") - print("-------------------------") - print(f"{'Feature Flag':<30} | {'Usage Count':<12}") - print("-" * 45) - for flag, count in sorted_flags: - print(f"{flag:<30} | {count:<12}") - - print(f"\nTotal feature flags: {len(sorted_flags)}") -else: - print("❗ FeatureFlag enum not found in the codebase") -``` - -This will output a table showing all feature flags and their usage counts, helping identify which flags are candidates for removal. - - - Learn more about [Attributes](/building-with-codegen/class-api#class-attributes) and [tracking usages](/building-with-codegen/dependencies-and-usages) here - - - -## Removing Rolled Out Flags - -Once you've identified a flag that's ready to be removed, Codegen can help safely delete it and its associated code paths. - - - This primarily leverages Codegen's API for [reduction conditions](/building-with-codegen/reducing-conditions) - - -### Python Example - -For Python codebases, here's how to remove a feature flag and its usages: - -```python -flag_name = "FEATURE_TO_REMOVE" - -# Get the feature flag variable -feature_flag_file = codebase.get_file("app/utils/feature_flags.py") -flag_class = feature_flag_file.get_class("FeatureFlag") - -# Check if the flag exists -flag_var = flag_class.get_attribute(flag_name) -if not flag_var: - print(f'No such flag: {flag_name}') - return - -# Remove all usages of the feature flag -for usage in flag_var.usages: - if isinstance(usage.parent, IfBlockStatement): - # For if statements, reduce the condition to True - usage.parent.reduce_condition(True) - elif isinstance(usage.parent, WithStatement): - # For with statements, keep the code block - usage.parent.code_block.unwrap() - else: - # For other cases, remove the usage - usage.remove() - -# Remove the flag definition -flag_var.remove() - -# Commit changes -codebase.commit() -``` - -### React/TypeScript Example - -For React applications using a hooks-based feature flag system: - -```python -feature_flag_name = "NEW_UI_ENABLED" -target_value = True # The value to reduce the flag to - -print(f'Removing feature flag: {feature_flag_name}') - -# 1. Remove from configuration -config_file = codebase.get_file("src/featureFlags/config.ts") -feature_flag_config = config_file.get_symbol("FEATURE_FLAG_CONFIG").value -if feature_flag_name in feature_flag_config.keys(): - feature_flag_config.pop(feature_flag_name) - print('βœ… Removed from feature flag config') - -# 2. Find and reduce all hook usages -hook = codebase.get_function("useFeatureFlag") -for usage in hook.usages: - fcall = usage.match - if isinstance(fcall, FunctionCall): - # Check if this usage is for our target flag - first_arg = fcall.args[0].value - if isinstance(first_arg, String) and first_arg.content == feature_flag_name: - print(f'Reducing in: {fcall.parent_symbol.name}') - # This automatically handles: - # - Ternary expressions: flag ? : - # - If statements: if (flag) { ... } - # - Conditional rendering: {flag && } - fcall.reduce_condition(target_value) - -# 3. Commit changes -codebase.commit() -``` - -This will: -1. Remove the feature flag from the configuration -2. Find all usages of the `useFeatureFlag` hook for this flag -3. Automatically reduce any conditional logic using the flag -4. Handle common React patterns like ternaries and conditional rendering - - -## Related Resources -- [Reducing Conditions](/building-with-codegen/reducing-conditions) - Details on condition reduction APIs -- [Dead Code Removal](/tutorials/deleting-dead-code) - Remove unused code after flag deletion \ No newline at end of file diff --git a/docs/_deprecated/tutorials/managing-typescript-exports.mdx b/docs/_deprecated/tutorials/managing-typescript-exports.mdx deleted file mode 100644 index aa28633f3..000000000 --- a/docs/_deprecated/tutorials/managing-typescript-exports.mdx +++ /dev/null @@ -1,323 +0,0 @@ ---- -title: "Managing TypeScript Exports" -sidebarTitle: "Export Management" -description: "Safely and systematically manage exports in your TypeScript codebase" -icon: "ship" -iconType: "solid" ---- - -Codegen provides powerful tools for managing and reorganizing exports in TypeScript codebases. This tutorial builds on the concepts covered in [exports](/building-with-codegen/exports) to show you how to automate common export management tasks and ensure your module boundaries stay clean and maintainable. - -## Common Export Management Tasks - -### Collecting and Processing Exports - -When reorganizing exports, the first step is identifying which exports need to be processed: - -```python -processed_imports = set() - -for file in codebase.files: - # Only process files under /src/shared - if '/src/shared' not in file.filepath: - continue - - # Gather all reexports that are not external exports - all_reexports = [] - for export_stmt in file.export_statements: - for export in export_stmt.exports: - if export.is_reexport() and not export.is_external_export: - all_reexports.append(export) - - # Skip if there are none - if not all_reexports: - continue -``` - -### Moving Exports to Public Files - -When centralizing exports in public-facing files: - -```python -# Replace "src/" with "src/shared/" -resolved_public_file = export.resolved_symbol.filepath.replace("src/", "src/shared/") - -# Get relative path from the "public" file back to the original file -relative_path = codebase.get_relative_path( - from_file=resolved_public_file, - to_file=export.resolved_symbol.filepath -) - -# Ensure the "public" file exists -if not codebase.has_file(resolved_public_file): - target_file = codebase.create_file(resolved_public_file, sync=True) -else: - target_file = codebase.get_file(resolved_public_file) - -# If target file already has a wildcard export for this relative path, skip -if target_file.has_export_statement_for_path(relative_path, "WILDCARD"): - has_wildcard = True - continue -``` - -### Managing Different Export Types - -Codegen can handle all types of exports automatically: - - - - ```python - # A) Wildcard export, e.g. `export * from "..."` - if export.is_wildcard_export(): - target_file.insert_before(f'export * from "{relative_path}"') - ``` - - - - ```python - # B) Type export, e.g. `export type { Foo, Bar } from "..."` - elif export.is_type_export(): - # Does this file already have a type export statement for the path? - statement = file.get_export_statement_for_path(relative_path, "TYPE") - if statement: - # Insert into existing statement - if export.is_aliased(): - statement.insert(0, f"{export.resolved_symbol.name} as {export.name}") - else: - statement.insert(0, f"{export.name}") - else: - # Insert a new type export statement - if export.is_aliased(): - target_file.insert_before( - f'export type {{ {export.resolved_symbol.name} as {export.name} }} ' - f'from "{relative_path}"' - ) - else: - target_file.insert_before( - f'export type {{ {export.name} }} from "{relative_path}"' - ) - ``` - - - - ```python - # C) Normal export, e.g. `export { Foo, Bar } from "..."` - else: - statement = file.get_export_statement_for_path(relative_path, "EXPORT") - if statement: - # Insert into existing statement - if export.is_aliased(): - statement.insert(0, f"{export.resolved_symbol.name} as {export.name}") - else: - statement.insert(0, f"{export.name}") - else: - # Insert a brand-new normal export statement - if export.is_aliased(): - target_file.insert_before( - f'export {{ {export.resolved_symbol.name} as {export.name} }} ' - f'from "{relative_path}"' - ) - else: - target_file.insert_before( - f'export {{ {export.name} }} from "{relative_path}"' - ) - ``` - - - -## Updating Import References - -After moving exports, you need to update all import references: - -```python -# Now update all import usages that refer to this export -for usage in export.symbol_usages(): - if isinstance(usage, TSImport) and usage not in processed_imports: - processed_imports.add(usage) - - # Translate the resolved_public_file to the usage file's TS config import path - new_path = usage.file.ts_config.translate_import_path(resolved_public_file) - - if has_wildcard and export.name != export.resolved_symbol.name: - name = f"{export.resolved_symbol.name} as {export.name}" - else: - name = usage.name - - if usage.is_type_import(): - new_import = f'import type {{ {name} }} from "{new_path}"' - else: - new_import = f'import {{ {name} }} from "{new_path}"' - - usage.file.insert_before(new_import) - usage.remove() - -# Remove the old export from the original file -export.remove() - -# If the file ends up with no exports, remove it entirely -if not file.export_statements and len(file.symbols) == 0: - file.remove() -``` - -## Best Practices - -1. **Check for Wildcards First**: Always check for existing wildcard exports before adding new ones: -```python -if target_file.has_export_statement_for_path(relative_path, "WILDCARD"): - has_wildcard = True - continue -``` - -2. **Handle Path Translations**: Use TypeScript config for path translations: -```python -new_path = usage.file.ts_config.translate_import_path(resolved_public_file) -``` - -3. **Clean Up Empty Files**: Remove files that no longer contain exports or symbols: -```python -if not file.export_statements and len(file.symbols) == 0: - file.remove() -``` - -## Next Steps - -After reorganizing your exports: - -1. Run your test suite to verify everything still works -2. Review the generated import statements -3. Check for any empty files that should be removed -4. Verify that all export types (wildcard, type, named) are working as expected - - -Remember that managing exports is an iterative process. You may need to run the codemod multiple times as your codebase evolves. - - -### Related tutorials -- [Moving symbols](/building-with-codegen/moving-symbols) -- [Exports](/building-with-codegen/exports) -- [Dependencies and usages](/building-with-codegen/dependencies-and-usages) - -## Complete Codemod - -Here's the complete codemod that you can copy and use directly: - -```python -processed_imports = set() - -for file in codebase.files: - # Only process files under /src/shared - if '/src/shared' not in file.filepath: - continue - - # Gather all reexports that are not external exports - all_reexports = [] - for export_stmt in file.export_statements: - for export in export_stmt.exports: - if export.is_reexport() and not export.is_external_export: - all_reexports.append(export) - - # Skip if there are none - if not all_reexports: - continue - - for export in all_reexports: - has_wildcard = False - - # Replace "src/" with "src/shared/" - resolved_public_file = export.resolved_symbol.filepath.replace("src/", "src/shared/") - - # Get relative path from the "public" file back to the original file - relative_path = codebase.get_relative_path( - from_file=resolved_public_file, - to_file=export.resolved_symbol.filepath - ) - - # Ensure the "public" file exists - if not codebase.has_file(resolved_public_file): - target_file = codebase.create_file(resolved_public_file, sync=True) - else: - target_file = codebase.get_file(resolved_public_file) - - # If target file already has a wildcard export for this relative path, skip - if target_file.has_export_statement_for_path(relative_path, "WILDCARD"): - has_wildcard = True - continue - - # Compare "public" path to the local file's export.filepath - if codebase._remove_extension(resolved_public_file) != codebase._remove_extension(export.filepath): - - # A) Wildcard export, e.g. `export * from "..."` - if export.is_wildcard_export(): - target_file.insert_before(f'export * from "{relative_path}"') - - # B) Type export, e.g. `export type { Foo, Bar } from "..."` - elif export.is_type_export(): - # Does this file already have a type export statement for the path? - statement = file.get_export_statement_for_path(relative_path, "TYPE") - if statement: - # Insert into existing statement - if export.is_aliased(): - statement.insert(0, f"{export.resolved_symbol.name} as {export.name}") - else: - statement.insert(0, f"{export.name}") - else: - # Insert a new type export statement - if export.is_aliased(): - target_file.insert_before( - f'export type {{ {export.resolved_symbol.name} as {export.name} }} ' - f'from "{relative_path}"' - ) - else: - target_file.insert_before( - f'export type {{ {export.name} }} from "{relative_path}"' - ) - - # C) Normal export, e.g. `export { Foo, Bar } from "..."` - else: - statement = file.get_export_statement_for_path(relative_path, "EXPORT") - if statement: - # Insert into existing statement - if export.is_aliased(): - statement.insert(0, f"{export.resolved_symbol.name} as {export.name}") - else: - statement.insert(0, f"{export.name}") - else: - # Insert a brand-new normal export statement - if export.is_aliased(): - target_file.insert_before( - f'export {{ {export.resolved_symbol.name} as {export.name} }} ' - f'from "{relative_path}"' - ) - else: - target_file.insert_before( - f'export {{ {export.name} }} from "{relative_path}"' - ) - - # Now update all import usages that refer to this export - for usage in export.symbol_usages(): - if isinstance(usage, TSImport) and usage not in processed_imports: - processed_imports.add(usage) - - # Translate the resolved_public_file to the usage file's TS config import path - new_path = usage.file.ts_config.translate_import_path(resolved_public_file) - - if has_wildcard and export.name != export.resolved_symbol.name: - name = f"{export.resolved_symbol.name} as {export.name}" - else: - name = usage.name - - if usage.is_type_import(): - new_import = f'import type {{ {name} }} from "{new_path}"' - else: - new_import = f'import {{ {name} }} from "{new_path}"' - - usage.file.insert_before(new_import) - usage.remove() - - # Remove the old export from the original file - export.remove() - - # If the file ends up with no exports, remove it entirely - if not file.export_statements and len(file.symbols) == 0: - file.remove() -``` \ No newline at end of file diff --git a/docs/_deprecated/tutorials/migrating-apis.mdx b/docs/_deprecated/tutorials/migrating-apis.mdx deleted file mode 100644 index a0e68da95..000000000 --- a/docs/_deprecated/tutorials/migrating-apis.mdx +++ /dev/null @@ -1,209 +0,0 @@ ---- -title: "Migrating APIs" -sidebarTitle: "API Migrations" -icon: "webhook" -iconType: "solid" ---- - -API migrations are a common task in large codebases. Whether you're updating a deprecated function, changing parameter names, or modifying return types, Codegen makes it easy to update all call sites consistently. - -## Common Migration Scenarios - -### Renaming Parameters - -When updating parameter names across an API, you need to update both the function definition and all call sites: - -```python -# Find the API function to update -api_function = codebase.get_function("process_data") - -# Update the parameter name -old_param = api_function.get_parameter("input") -old_param.rename("data") - -# All call sites are automatically updated: -# process_data(input="test") -> process_data(data="test") -``` - -See [dependencies and usages](/building-with-codegen/dependencies-and-usages) for more on updating parameter names and types. - -### Adding Required Parameters - -When adding a new required parameter to an API: - -```python -# Find all call sites before modifying the function -call_sites = list(api_function.call_sites) - -# Add the new parameter -api_function.add_parameter("timeout: int") - -# Update all existing call sites to include the new parameter -for call in call_sites: - call.add_argument("timeout=30") # Add with a default value -``` - -See [function calls and callsites](/building-with-codegen/function-calls-and-callsites) for more on handling call sites. - -### Changing Parameter Types - -When updating parameter types: - -```python -# Update the parameter type -param = api_function.get_parameter("user_id") -param.type = "UUID" # Change from string to UUID - -# Find all call sites that need type conversion -for call in api_function.call_sites: - arg = call.get_arg_by_parameter_name("user_id") - if arg: - # Convert string to UUID - arg.edit(f"UUID({arg.value})") -``` - -See [working with type annotations](/building-with-codegen/type-annotations) for more on changing parameter types. - -### Deprecating Functions - -When deprecating an old API in favor of a new one: - -```python -old_api = codebase.get_function("old_process_data") -new_api = codebase.get_function("new_process_data") - -# Add deprecation warning -old_api.add_decorator('@deprecated("Use new_process_data instead")') - -# Update all call sites to use the new API -for call in old_api.call_sites: - # Map old arguments to new parameter names - args = [ - f"data={call.get_arg_by_parameter_name('input').value}", - f"timeout={call.get_arg_by_parameter_name('wait').value}" - ] - - # Replace the old call with the new API - call.replace(f"new_process_data({', '.join(args)})") -``` - -## Bulk Updates to Method Chains - -When updating chained method calls, like database queries or builder patterns: - -```python -# Find all query chains ending with .execute() -for execute_call in codebase.function_calls: - if execute_call.name != "execute": - continue - - # Get the full chain - chain = execute_call.call_chain - - # Example: Add .timeout() before .execute() - if "timeout" not in {call.name for call in chain}: - execute_call.insert_before("timeout(30)") -``` - -## Handling Breaking Changes - -When making breaking changes to an API, it's important to: -1. Identify all affected call sites -2. Make changes consistently -3. Update related documentation -4. Consider backward compatibility - -Here's a comprehensive example: - -```python -def migrate_api_v1_to_v2(codebase): - old_api = codebase.get_function("create_user_v1") - - # Document all existing call patterns - call_patterns = {} - for call in old_api.call_sites: - args = [arg.source for arg in call.args] - pattern = ", ".join(args) - call_patterns[pattern] = call_patterns.get(pattern, 0) + 1 - - print("Found call patterns:") - for pattern, count in call_patterns.items(): - print(f" {pattern}: {count} occurrences") - - # Create new API version - new_api = old_api.copy() - new_api.rename("create_user_v2") - - # Update parameter types - new_api.get_parameter("email").type = "EmailStr" - new_api.get_parameter("role").type = "UserRole" - - # Add new required parameters - new_api.add_parameter("tenant_id: UUID") - - # Update all call sites - for call in old_api.call_sites: - # Get current arguments - email_arg = call.get_arg_by_parameter_name("email") - role_arg = call.get_arg_by_parameter_name("role") - - # Build new argument list with type conversions - new_args = [ - f"email=EmailStr({email_arg.value})", - f"role=UserRole({role_arg.value})", - "tenant_id=get_current_tenant_id()" - ] - - # Replace old call with new version - call.replace(f"create_user_v2({', '.join(new_args)})") - - # Add deprecation notice to old version - old_api.add_decorator('@deprecated("Use create_user_v2 instead")') - -# Run the migration -migrate_api_v1_to_v2(codebase) -``` - -## Best Practices - -1. **Analyze First**: Before making changes, analyze all call sites to understand usage patterns - ```python - # Document current usage - for call in api.call_sites: - print(f"Called from: {call.parent_function.name}") - print(f"With args: {[arg.source for arg in call.args]}") - ``` - -2. **Make Atomic Changes**: Update one aspect at a time - ```python - # First update parameter names - param.rename("new_name") - - # Then update types - param.type = "new_type" - - # Finally update call sites - for call in api.call_sites: - # ... update calls - ``` - -3. **Maintain Backwards Compatibility**: - ```python - # Add new parameter with default - api.add_parameter("new_param: str = None") - - # Later make it required - api.get_parameter("new_param").remove_default() - ``` - -4. **Document Changes**: - ```python - # Add clear deprecation messages - old_api.add_decorator('''@deprecated( - "Use new_api() instead. Migration guide: docs/migrations/v2.md" - )''') - ``` - - -Remember to test thoroughly after making bulk changes to APIs. While Codegen ensures syntactic correctness, you'll want to verify the semantic correctness of the changes. - \ No newline at end of file diff --git a/docs/_deprecated/tutorials/modularity.mdx b/docs/_deprecated/tutorials/modularity.mdx deleted file mode 100644 index 84c55835d..000000000 --- a/docs/_deprecated/tutorials/modularity.mdx +++ /dev/null @@ -1,202 +0,0 @@ ---- -title: "Improving Code Modularity" -sidebarTitle: "Modularity" -icon: "diagram-project" -iconType: "solid" ---- - -Codegen SDK provides powerful tools for analyzing and improving code modularity. This guide will help you identify and fix common modularity issues like circular dependencies, tight coupling, and poorly organized imports. - -Common use cases include: -- Breaking up circular dependencies -- Organizing imports and exports -- Identifying highly coupled modules -- Extracting shared code into common modules -- Analyzing module boundaries - -## Analyzing Import Relationships - -First, let's see how to analyze import relationships in your codebase: - -```python -import networkx as nx -from collections import defaultdict - -# Create a graph of file dependencies -def create_dependency_graph(): - G = nx.DiGraph() - - for file in codebase.files: - # Add node for this file - G.add_node(file.filepath) - - # Add edges for each import - for imp in file.imports: - if imp.from_file: # Skip external imports - G.add_edge(file.filepath, imp.from_file.filepath) - - return G - -# Create and analyze the graph -graph = create_dependency_graph() - -# Find circular dependencies -cycles = list(nx.simple_cycles(graph)) -if cycles: - print("πŸ”„ Found circular dependencies:") - for cycle in cycles: - print(f" β€’ {' -> '.join(cycle)}") - -# Calculate modularity metrics -print("\nπŸ“Š Modularity Metrics:") -print(f" β€’ Number of files: {len(graph.nodes)}") -print(f" β€’ Number of imports: {len(graph.edges)}") -print(f" β€’ Average imports per file: {len(graph.edges)/len(graph.nodes):.1f}") -``` - -## Breaking Circular Dependencies - -When you find circular dependencies, here's how to break them: - -```python -def break_circular_dependency(cycle): - # Get the first two files in the cycle - file1 = codebase.get_file(cycle[0]) - file2 = codebase.get_file(cycle[1]) - - # Create a shared module for common code - shared_dir = "shared" - if not codebase.has_directory(shared_dir): - codebase.create_directory(shared_dir) - - # Find symbols used by both files - shared_symbols = [] - for symbol in file1.symbols: - if any(usage.file == file2 for usage in symbol.usages): - shared_symbols.append(symbol) - - # Move shared symbols to a new file - if shared_symbols: - shared_file = codebase.create_file(f"{shared_dir}/shared_types.py") - for symbol in shared_symbols: - symbol.move_to_file(shared_file, strategy="update_all_imports") - -# Break each cycle found -for cycle in cycles: - break_circular_dependency(cycle) -``` - -## Organizing Imports - -Clean up and organize imports across your codebase: - -```python -def organize_file_imports(file): - # Group imports by type - std_lib_imports = [] - third_party_imports = [] - local_imports = [] - - for imp in file.imports: - if imp.is_standard_library: - std_lib_imports.append(imp) - elif imp.is_third_party: - third_party_imports.append(imp) - else: - local_imports.append(imp) - - # Sort each group - for group in [std_lib_imports, third_party_imports, local_imports]: - group.sort(key=lambda x: x.module_name) - - # Remove all existing imports - for imp in file.imports: - imp.remove() - - # Add imports back in organized groups - if std_lib_imports: - for imp in std_lib_imports: - file.add_import(imp.source) - file.insert_after_imports("") # Add newline - - if third_party_imports: - for imp in third_party_imports: - file.add_import(imp.source) - file.insert_after_imports("") # Add newline - - if local_imports: - for imp in local_imports: - file.add_import(imp.source) - -# Organize imports in all files -for file in codebase.files: - organize_file_imports(file) -``` - -## Identifying Highly Coupled Modules - -Find modules that might need to be split up: - -```python -from collections import defaultdict - -def analyze_module_coupling(): - coupling_scores = defaultdict(int) - - for file in codebase.files: - # Count unique files imported from - imported_files = {imp.from_file for imp in file.imports if imp.from_file} - coupling_scores[file.filepath] = len(imported_files) - - # Count files that import this file - importing_files = {usage.file for symbol in file.symbols - for usage in symbol.usages if usage.file != file} - coupling_scores[file.filepath] += len(importing_files) - - # Sort by coupling score - sorted_files = sorted(coupling_scores.items(), - key=lambda x: x[1], - reverse=True) - - print("\nπŸ” Module Coupling Analysis:") - print("\nMost coupled files:") - for filepath, score in sorted_files[:5]: - print(f" β€’ {filepath}: {score} connections") - -analyze_module_coupling() -``` - -## Extracting Shared Code - -When you find highly coupled modules, extract shared code: - -```python -def extract_shared_code(file, min_usages=3): - # Find symbols used by multiple files - for symbol in file.symbols: - # Get unique files using this symbol - using_files = {usage.file for usage in symbol.usages - if usage.file != file} - - if len(using_files) >= min_usages: - # Create appropriate shared module - module_name = determine_shared_module(symbol) - if not codebase.has_file(f"shared/{module_name}.py"): - shared_file = codebase.create_file(f"shared/{module_name}.py") - else: - shared_file = codebase.get_file(f"shared/{module_name}.py") - - # Move symbol to shared module - symbol.move_to_file(shared_file, strategy="update_all_imports") - -def determine_shared_module(symbol): - # Logic to determine appropriate shared module name - if symbol.is_type: - return "types" - elif symbol.is_constant: - return "constants" - elif symbol.is_utility: - return "utils" - else: - return "common" -``` \ No newline at end of file diff --git a/docs/_deprecated/tutorials/neo4j-graph.mdx b/docs/_deprecated/tutorials/neo4j-graph.mdx deleted file mode 100644 index 0c571bf4e..000000000 --- a/docs/_deprecated/tutorials/neo4j-graph.mdx +++ /dev/null @@ -1,93 +0,0 @@ ---- -title: "Neo4j Graph" -sidebarTitle: "Neo4j Graph" -icon: "database" -iconType: "solid" ---- - - - - - -# Neo4j Graph - -Codegen can export codebase graphs to Neo4j for visualization and analysis. - -## Installation -In order to use Neo4j you will need to install it and run it locally using Docker. - -### Neo4j -First, install Neo4j using the official [installation guide](https://neo4j.com/docs/desktop-manual/current/installation/download-installation/). - -### Docker -To run Neo4j locally using Docker, follow the instructions [here](https://neo4j.com/docs/apoc/current/installation/#docker). - -## Launch Neo4j Locally - -```bash -docker run \ - -p 7474:7474 -p 7687:7687 \ - -v $PWD/data:/data -v $PWD/plugins:/plugins \ - --name neo4j-apoc \ - -e NEO4J_apoc_export_file_enabled=true \ - -e NEO4J_apoc_import_file_enabled=true \ - -e NEO4J_apoc_import_file_use__neo4j__config=true \ - -e NEO4J_PLUGINS=\[\"apoc\"\] \ - neo4j:latest -``` -## Usage - -```python -from codegen import Codebase -from codegen.extensions.graph.main import visualize_codebase - -# parse codebase -codebase = Codebase("path/to/codebase") - -# export to Neo4j -visualize_codebase(codebase, "bolt://localhost:7687", "neo4j", "password") -``` - -## Visualization - -Once exported, you can open the Neo4j browser at `http://localhost:7474`, sign in with the username `neo4j` and the password `password`, and use the following Cypher queries to visualize the codebase: - -### Class Hierarchy - -```cypher -Match (s: Class )-[r: INHERITS_FROM*]-> (e:Class) RETURN s, e LIMIT 10 -``` - - - - -### Methods Defined by Each Class - -```cypher -Match (s: Class )-[r: DEFINES]-> (e:Method) RETURN s, e LIMIT 10 -``` - - - - -### Function Calls - -```cypher -Match (s: Func )-[r: CALLS]-> (e:Func) RETURN s, e LIMIT 10 -``` - - - - - -### Call Graph - -```cypher -Match path = (:(Method|Func)) -[:CALLS*5..10]-> (:(Method|Func)) -Return path -LIMIT 20 -``` - - - - \ No newline at end of file diff --git a/docs/_deprecated/tutorials/organize-your-codebase.mdx b/docs/_deprecated/tutorials/organize-your-codebase.mdx deleted file mode 100644 index 81767871d..000000000 --- a/docs/_deprecated/tutorials/organize-your-codebase.mdx +++ /dev/null @@ -1,257 +0,0 @@ ---- -title: "Organizing Your Codebase" -sidebarTitle: "Organization" -icon: "folder-tree" -iconType: "solid" ---- - -Codegen SDK provides a powerful set of tools for deterministically moving code safely and efficiently. This guide will walk you through the basics of moving code with Codegen SDK. - -Common use cases include: - - - - -```python -print(f"πŸ” Processing file: {filepath}") -file = codebase.get_file(filepath) - -# Get the directory path for creating new files -dir_path = file.directory.path if file.directory else "" - -# Iterate through all functions in the file -for function in file.functions: - # Create new filename based on function name - new_filepath = f"{dir_path}/{function.name}.py" - print(f"πŸ“ Creating new file: {new_filepath}") - - # Create the new file - new_file = codebase.create_file(new_filepath) - - # Move the function to the new file, including dependencies - print(f"➑️ Moving function: {function.name}") - function.move_to_file(new_file, include_dependencies=True) -``` - - - - - -```python -# Dictionary to track modules and their functions -module_map = { - "utils": lambda f: f.name.startswith("util_") or f.name.startswith("helper_"), - "api": lambda f: f.name.startswith("api_") or f.name.startswith("endpoint_"), - "data": lambda f: f.name.startswith("data_") or f.name.startswith("db_"), - "core": lambda f: True # Default module for other functions -} - -print("πŸ” Starting code organization...") - -# Create module directories if they don't exist -for module in module_map.keys(): - if not codebase.has_directory(module): - print(f"πŸ“ Creating module directory: {module}") - codebase.create_directory(module, exist_ok=True) - -# Process each file in the codebase -for file in codebase.files: - print(f"\nπŸ“„ Processing file: {file.filepath}") - - # Skip if file is already in a module directory - if any(file.filepath.startswith(module) for module in module_map.keys()): - continue - - # Process each function in the file - for function in file.functions: - # Determine which module this function belongs to - target_module = next( - (module for module, condition in module_map.items() - if condition(function)), - "core" - ) - - # Create the new file path - new_filepath = f"{target_module}/{function.name}.py" - - print(f" ➑️ Moving {function.name} to {target_module} module") - - # Create new file and move function - if not codebase.has_file(new_filepath): - new_file = codebase.create_file(new_filepath) - function.move_to_file(new_file, include_dependencies=True) - -print("\nβœ… Code organization complete!") -``` - - - - - -```python -# Create a graph to detect cycles -import networkx as nx - -# Build dependency graph -G = nx.DiGraph() - -# Add edges for imports between files -for file in codebase.files: - for imp in file.imports: - if imp.from_file: - G.add_edge(file.filepath, imp.from_file.filepath) - -# Find cycles in the graph -cycles = list(nx.simple_cycles(G)) - -if not cycles: - print("βœ… No import cycles found!") - exit() - -print(f"πŸ” Found {len(cycles)} import cycles") - -# Process each cycle -for cycle in cycles: - print(f"\nβ­• Processing cycle: {' -> '.join(cycle)}") - - # Get the first two files in the cycle - file1 = codebase.get_file(cycle[0]) - file2 = codebase.get_file(cycle[1]) - - # Find functions in file1 that are used by file2 - for function in file1.functions: - if any(usage.file == file2 for usage in function.usages): - # Create new file for the shared function - new_filepath = f"shared/{function.name}.py" - print(f" ➑️ Moving {function.name} to {new_filepath}") - - if not codebase.has_directory("shared"): - codebase.create_directory("shared") - - new_file = codebase.create_file(new_filepath) - function.move_to_file(new_file, include_dependencies=True) - -print("\nβœ… Import cycles resolved!") -``` - - - - - - Most operations in Codegen will automatically handle updaging - [dependencies](/building-with-codegen/dependencies-and-usages) and - [imports](/building-with-codegen/imports). See [Moving - Symbols](/building-with-codegen/moving-symbols) to learn more. - - -## Basic Symbol Movement - -To move a symbol from one file to another, you can use the [move_to_file](/api-reference/core/Function#move-to-file) method. - - -```python python -# Get the symbol -symbol_to_move = source_file.get_symbol("my_function") -# Pick a destination file -dst_file = codebase.get_file("path/to/dst/location.py") -# Move the symbol, move all of its dependencies with it (remove from old file), and add an import of symbol into old file -symbol_to_move.move_to_file(dst_file, include_dependencies=True, strategy="add_back_edge") -``` - -```python typescript -# Get the symbol -symbol_to_move = source_file.get_symbol("myFunction") -# Pick a destination file -dst_file = codebase.get_file("path/to/dst/location.ts") -# Move the symbol, move all of its dependencies with it (remove from old file), and add an import of symbol into old file -symbol_to_move.move_to_file(dst_file, include_dependencies=True, strategy="add_back_edge") -``` - - - -This will move `my_function` to `path/to/dst/location.py`, safely updating all references to it in the process. - -## Updating Imports - -After moving a symbol, you may need to update imports throughout your codebase. GraphSitter offers two strategies for this: - -1. **Update All Imports**: This strategy updates all imports across the codebase to reflect the new location of the symbol. - - -```python python -symbol_to_move = codebase.get_symbol("symbol_to_move") -dst_file = codebase.create_file("new_file.py") -symbol_to_move.move_to_file(dst_file, strategy="update_all_imports") -``` - -```python typescript -symbol_to_move = codebase.get_symbol("symbolToMove") -dst_file = codebase.create_file("new_file.ts") -symbol_to_move.move_to_file(dst_file, strategy="update_all_imports") -``` - - - -Updating all imports can result in very large PRs - -2. **Add Back Edge**: This strategy adds an import in the original file that re-imports (and exports) the moved symbol, maintaining backwards compatibility. This will result in fewer total modifications, as existing imports will not need to be updated. - - -```python python -symbol_to_move = codebase.get_symbol("symbol_to_move") -dst_file = codebase.create_file("new_file.py") -symbol_to_move.move_to_file(dst_file, strategy="add_back_edge") -``` - -```python typescript -symbol_to_move = codebase.get_symbol("symbolToMove") -dst_file = codebase.create_file("new_file.ts") -symbol_to_move.move_to_file(dst_file, strategy="add_back_edge") -``` - - - -## Handling Dependencies - -By default, Codegen will move all of a symbols dependencies along with it. This ensures that your codebase remains consistent and functional. - - -```python python -my_symbol = codebase.get_symbol("my_symbol") -dst_file = codebase.create_file("new_file.py") -my_symbol.move_to_file(dst_file, include_dependencies=True) -``` - -```python typescript -my_symbol = codebase.get_symbol("mySymbol") -dst_file = codebase.create_file("new_file.ts") -my_symbol.move_to_file(dst_file, include_dependencies=True) -``` - - - -If you set `include_dependencies=False`, only the symbol itself will be moved, and any dependencies will remain in the original file. - -## Moving Multiple Symbols - -If you need to move multiple symbols, you can do so in a loop: - -```python -source_file = codebase.get_file("path/to/source_file.py") -dest_file = codebase.get_file("path/to/destination_file.py") -# Create a list of symbols to move -symbols_to_move = [source_file.get_function("my_function"), source_file.get_class("MyClass")] -# Move each symbol to the destination file -for symbol in symbols_to_move: - symbol.move_to_file(dest_file, include_dependencies=True, strategy="update_all_imports") -``` - -## Best Practices - -1. **Commit After Major Changes**: If you're making multiple significant changes, use `codebase.commit()` between them to ensure the codebase graph is up-to-date. - -2. **Re-fetch References**: After a commit, re-fetch any file or symbol references you're working with, as they may have become stale. - -3. **Handle Errors**: Be prepared to handle cases where symbols or files might not exist, or where moves might fail due to naming conflicts. - -By following these guidelines, you can effectively move symbols around your codebase while maintaining its integrity and functionality. diff --git a/docs/_deprecated/tutorials/preparing-your-codebase-for-ai.mdx b/docs/_deprecated/tutorials/preparing-your-codebase-for-ai.mdx deleted file mode 100644 index 4f6f03e5d..000000000 --- a/docs/_deprecated/tutorials/preparing-your-codebase-for-ai.mdx +++ /dev/null @@ -1,179 +0,0 @@ ---- -title: "Preparing Your Codebase for AI" -sidebarTitle: "AI Preparation" -icon: "robot" -iconType: "solid" -description: "Generate a hierarchical README for your codebase using AI" ---- - -When working with large codebases, having clear documentation about each directory's purpose and contents is crucial. This guide shows how to use Codegen and AI to automatically generate a hierarchical README that explains your codebase structure. - -## Generating Directory READMEs - -Here's how to recursively generate README files for each directory using AI: - -```python -def generate_directory_readme(directory): - # Skip non-source directories - if any(skip in directory.name for skip in [ - 'node_modules', 'venv', '.git', '__pycache__', 'build', 'dist' - ]): - return - - # Collect directory contents for context - files = [f for f in directory.files if f.is_source_file] - functions = directory.functions - classes = directory.classes - - # Create context for AI - context = { - "Directory Name": directory.name, - "Files": [f"{f.name} ({len(f.source.splitlines())} lines)" for f in files], - "Functions": [f.name for f in functions], - "Classes": [c.name for c in classes] - } - - # Generate directory summary using AI - readme_content = codebase.ai( - prompt="""Generate a README section that explains this directory's: - 1. Purpose and responsibility - 2. Key components and their roles - 3. How it fits into the larger codebase - 4. Important patterns or conventions - - Keep it clear and concise.""", - target=directory, - context=context - ) - - # Add file listing - if files: - readme_content += "\n\n## Files\n" - for file in files: - # Get file summary from AI - file_summary = codebase.ai( - prompt="Describe this file's purpose in one line:", - target=file - ) - readme_content += f"\n### {file.name}\n{file_summary}\n" - - # List key components - if file.classes: - readme_content += "\nKey classes:\n" - for cls in file.classes: - readme_content += f"- `{cls.name}`\n" - if file.functions: - readme_content += "\nKey functions:\n" - for func in file.functions: - readme_content += f"- `{func.name}`\n" - - # Create or update README.md - readme_path = f"{directory.path}/README.md" - if codebase.has_file(readme_path): - readme_file = codebase.get_file(readme_path) - readme_file.edit(readme_content) - else: - readme_file = codebase.create_file(readme_path) - readme_file.edit(readme_content) - - # Recursively process subdirectories - for subdir in directory.subdirectories: - generate_directory_readme(subdir) - -# Generate READMEs for the entire codebase -generate_directory_readme(codebase.root_directory) -``` - -This will create a hierarchy of README.md files that explain each directory's purpose and contents. For example: - -```markdown -# src/ -Core implementation directory containing the main business logic and data models. -This directory is responsible for the core functionality of the application. - -## Key Patterns -- Business logic is separated from API endpoints -- Models follow the Active Record pattern -- Services implement the Repository pattern - -## Files - -### models.py -Defines the core data models and their relationships. - -Key classes: -- `User` -- `Product` -- `Order` - -### services.py -Implements business logic and data access services. - -Key classes: -- `UserService` -- `ProductService` -Key functions: -- `initialize_db` -- `migrate_data` -``` - -## Customizing the Generation - -You can customize the README generation by modifying the prompts and adding more context: - -```python -def get_directory_patterns(directory): - """Analyze common patterns in a directory""" - patterns = [] - - # Check for common file patterns - if any('test_' in f.name for f in directory.files): - patterns.append("Contains unit tests") - if any('interface' in f.name.lower() for f in directory.files): - patterns.append("Uses interface-based design") - if any(c.is_dataclass for c in directory.classes): - patterns.append("Uses dataclasses for data models") - - return patterns - -def generate_enhanced_readme(directory): - # Get additional context - patterns = get_directory_patterns(directory) - dependencies = [imp.module for imp in directory.imports] - - # Enhanced context for AI - context = { - "Common Patterns": patterns, - "Dependencies": dependencies, - "Parent Directory": directory.parent.name if directory.parent else None, - "Child Directories": [d.name for d in directory.subdirectories], - "Style": "technical but approachable" - } - - # Generate README with enhanced context - # ... rest of the generation logic -``` - -## Best Practices - -1. **Keep Summaries Focused**: Direct the AI to generate concise, purpose-focused summaries. - -2. **Include Key Information**: - - Directory purpose - - Important patterns - - Key files and their roles - - How components work together - -3. **Maintain Consistency**: Use consistent formatting and structure across all READMEs. - -4. **Update Regularly**: Regenerate READMEs when directory structure or purpose changes. - -5. **Version Control**: Commit generated READMEs to track documentation evolution. - - -The AI-generated summaries are a starting point. Review and refine them to ensure accuracy and completeness. - - - -Be mindful of sensitive information in your codebase. Configure the generator to skip sensitive files or directories. - diff --git a/docs/_deprecated/tutorials/promise-to-async-await.mdx b/docs/_deprecated/tutorials/promise-to-async-await.mdx deleted file mode 100644 index 2811ee2ae..000000000 --- a/docs/_deprecated/tutorials/promise-to-async-await.mdx +++ /dev/null @@ -1,274 +0,0 @@ ---- -title: "Converting Promise Chains to Async/Await" -sidebarTitle: "Promise to Async/Await" -icon: "code-merge" -iconType: "solid" ---- - -Modern JavaScript/TypeScript codebases often need to migrate from Promise-based code to the more readable async/await syntax. Codegen provides powerful tools to automate this conversion while preserving business logic and handling complex scenarios. - - -You can find the complete example code in our [examples repository](https://github.com/codegen-sh/codegen-sdk/blob/develop/codegen-examples/examples/promises_to_async_await/promises_to_async_await.ipynb). - - - -## Finding Promise Chains - -Codegen offers multiple ways to locate Promise chains in your codebase: -- In files -- In functions -- Part of a function call chain - -### Promise Chains in a File - -Find all Promise chains in a file: - -```python -ts_file = codebase.get_file("api_client.ts") -promise_chains = ts_file.promise_chains - -print(f"Found {len(promise_chains)} Promise chains") -``` - -### Promise Chains in a Function - -Find Promise chains within a specific function: - -```python -ts_func = codebase.get_function("getUserData") -chains = ts_func.promise_chains - -for chain in chains: - print(f"Found chain starting with: {chain.name}") -``` - -### Promise Chain starting from a Function Call - -Find Promise chains starting from a specific function call: - -```python -# Assuming the function call is part of a promise chain -fetch_call = codebase.get_function("fetchUserData").function_calls[2] -chain = fetch_call.promise_chain -``` - - -## Converting Promise Chains - -### In-Place Conversion - -Convert Promise chains directly in your codebase: - -```python -# Find and convert all Promise chains in a file -for chain in typescript_file.promise_chains: - chain.convert_to_async_await() -``` - -### Handle Business Logic Without In-Place Edit - -Generate the transformed code without inplace edit by returning the new code as a string. This is useful when you want to add additional business logic to the overall conversion. - -```python -async_await_code = chain.convert_to_async_await(inplace_edit=False) -print("Converted code:", async_await_code) - -promise_statement = chain.parent_statement -new_code = promise_statement.edit( - f""" - {async_await_code} - - // handle additional business logic here - """ -) -``` - - -## Supported Promise Chain Patterns - -- Basic `promise.then()` statements of any length -- Catch `promise.then().catch()` statements of any length -- Finally `promise.then().catch().finally()` statements of any length -- Desctructure `promise.then((var1, var2))` statements -> `let [var1, var2] = await statement;` -- Implicit returns -> `return promise.then(() => console.log("hello"))` -- Top level variable assignments -> `let assigned_var = promise.then()` -- Top level variable assignments -> `let assigned_var = promise.then()` -- Ambiguous/conditional return blocks - - -A list of all the covered cases can be found in the [example notebook](https://github.com/codegen-sh/codegen-sdk/tree/codegen-examples/examples/promises_to_async_await/promise_to_async_await.ipynb). - - - -## Examples -### 1. Basic Promise Chains - -```typescript -// Before -function getValue(): Promise { - return Promise.resolve(10) - .then(value => value * 2); -} -``` - -***Applying the conversion...*** -```python -promise_chain = codebase.get_function("getValue").promise_chains[0] -promise_chain.convert_to_async_await() -codebase.commit() -``` - -```typescript -// After -async function getValue(): Promise { - let value = await Promise.resolve(10); - return value * 2; -} -``` - -### 2. Error Handling with Catch/Finally - -```typescript -// Before -function processData(): Promise { - return fetchData() - .then(data => processData(data)) - .catch(error => { - console.error("Error:", error); - throw error; - }) - .finally(() => { - cleanup(); - }); -} -``` - -***Applying the conversion...*** -```python -promise_chain = codebase.get_function("processData").promise_chains[0] -promise_chain.convert_to_async_await() -codebase.commit() -``` - -```typescript -// After -async function processData(): Promise { - try { - let data = await fetchData(); - return processData(data); - } catch (error) { - console.error("Error:", error); - throw error; - } finally { - cleanup(); - } -} -``` - -### 3. Promise.all with Destructuring - -```typescript -// Before -function getAllUserInfo(userId: number) { - return Promise.all([ - fetchUserData(userId), - fetchUserPosts(userId) - ]).then(([user, posts]) => { - return { user, posts }; - }); -} -``` - -***Applying the conversion...*** -```python -promise_chain = codebase.get_function("getAllUserInfo").promise_chains[0] -promise_chain.convert_to_async_await() -codebase.commit() -``` - - -```typescript -// After -async function getAllUserInfo(userId: number) { - const [user, posts] = await Promise.all([ - fetchUserData(userId), - fetchUserPosts(userId) - ]); - return { user, posts }; -} -``` - - -### 4. Handling Ambiguous Returns Using Anonymous functions - - -For `then` blocks that have more than one return statement, Codegen will add an anonymous function to handle the ambiguous return to guarantee a deterministic conversion. - -```typescript -// Before -function create(opts: any): Promise { - let qResponse = request(opts); - qResponse = qResponse.then(function success(response) { - if (response.statusCode < 200 || response.statusCode >= 300) { - throw new Error(JSON.stringify(response)); - } - if (typeof response.body === "string") { - return JSON.parse(response.body); - } - return response.body; - }); - - return qResponse; -} - -``` - -***Applying the conversion...*** -```python -promise_chain = codebase.get_function("create").promise_chains[0] -promise_chain.convert_to_async_await() -codebase.commit() -``` -```typescript -// After -async function create(opts): Promise { - let qResponse = request(opts); - let response = await qResponse; - qResponse = (async (response) => { - if (response.statusCode < 200 || response.statusCode >= 300) { - throw new Error(JSON.stringify(response)); - } - if (typeof response.body === "string") { - return JSON.parse(response.body); - } - return response.body; - })(response); - - return qResponse; -} -``` - - - -## Handling Top-Level Assignment Variables - -When converting Promise chains that involve top-level assignment variables, you can specify the variable name of your choice or pick the default which is the original variable assignment name. - -```python -# Convert with custom variable names for clarity -chain.convert_to_async_await( - assignment_variable_name="operationResult", -) -``` - - -## Next Steps - - -Converting Promise chains to async/await improves code readability and maintainability. Codegen's tools make this migration process automated and reliable, handling complex cases while preserving business logic. -Here are some next steps to ensure a successful migration: - -1. Ensure to run `npx prettier --write .` after the migration to fix indentation + linting -2. **Incremental Migration**: Convert one module at a time -3. **Handle Additional Business Logic**: Use `.promise_statement.edit()` to modify the entire chain and handle external business logic -4. If the specific conversion case is not covered, open an issue on the [Codegen](https://github.com/codegen-sh/codegen-sdk) repository or try to right your own transformation logic using the codegen-sdk diff --git a/docs/_deprecated/tutorials/python2-to-python3.mdx b/docs/_deprecated/tutorials/python2-to-python3.mdx deleted file mode 100644 index 08e61648c..000000000 --- a/docs/_deprecated/tutorials/python2-to-python3.mdx +++ /dev/null @@ -1,256 +0,0 @@ ---- -title: "Migrating from Python 2 to Python 3" -sidebarTitle: "Python 2 to 3" -description: "Learn how to migrate Python 2 codebases to Python 3 using Codegen" -icon: "snake" -iconType: "solid" ---- - -Migrating from Python 2 to Python 3 involves several syntax and API changes. This guide will walk you through using Codegen to automate this migration, handling print statements, string handling, iterators, and more. - - -You can find the complete example code in our [examples repository](https://github.com/codegen-sh/codegen-sdk/tree/develop/codegen-examples/examples/python2_to_python3). - - -## Overview - -The migration process involves five main steps: - -1. Converting print statements to function calls -2. Updating Unicode to str -3. Converting raw_input to input -4. Updating exception handling syntax -5. Modernizing iterator methods - -Let's walk through each step using Codegen. - -## Step 1: Convert Print Statements - -First, we need to convert Python 2's print statements to Python 3's print function calls: - -```python -def convert_print_statements(file): - """Convert Python 2 print statements to Python 3 function calls""" - lines = file.content.split('\n') - new_content = [] - - for line in lines: - stripped = line.strip() - if stripped.startswith('print '): - indent = line[:len(line) - len(line.lstrip())] - args = stripped[6:].strip() - new_content.append(f"{indent}print({args})") - else: - new_content.append(line) - - if new_content != lines: - file.edit('\n'.join(new_content)) -``` - -This transforms code from: - -```python -print "Hello, world!" -print x, y, z -``` - -to: - -```python -print("Hello, world!") -print(x, y, z) -``` - - - In Python 3, `print` is a function rather than a statement, requiring - parentheses around its arguments. - - -## Step 2: Update Unicode to str - -Next, we update Unicode-related code to use Python 3's unified string type: - -```python -def update_unicode_to_str(file): - """Convert Unicode-related code to str for Python 3""" - # Update imports from 'unicode' to 'str' - for imp in file.imports: - if imp.name == 'unicode': - imp.set_name("str") - - # Update function calls from Unicode to str - for func_call in file.function_calls: - if func_call.name == "unicode": - func_call.set_name("str") - - # Check function arguments for Unicode references - for arg in func_call.args: - if arg.value == "unicode": - arg.set_value("str") - - # Find and update Unicode string literals (u"...") - for string_literal in file.find('u"'): - if string_literal.source.startswith('u"') or string_literal.source.startswith("u'"): - new_string = string_literal.source[1:] # Remove the 'u' prefix - string_literal.edit(new_string) -``` - -This converts code from: - -```python -from __future__ import unicode_literals -text = unicode("Hello") -prefix = u"prefix" -``` - -to: - -```python -text = str("Hello") -prefix = "prefix" -``` - - - Python 3 unifies string types, making the `unicode` type and `u` prefix - unnecessary. - - -## Step 3: Convert raw_input to input - -Python 3 renames `raw_input()` to `input()`: - -```python -def convert_raw_input(file): - """Convert raw_input() calls to input()""" - for call in file.function_calls: - if call.name == "raw_input": - call.edit(f"input{call.source[len('raw_input'):]}") -``` - -This updates code from: - -```python -name = raw_input("Enter your name: ") -``` - -to: - -```python -name = input("Enter your name: ") -``` - - - Python 3's `input()` function always returns a string, like Python 2's - `raw_input()`. - - -## Step 4: Update Exception Handling - -Python 3 changes the syntax for exception handling: - -```python -def update_exception_syntax(file): - """Update Python 2 exception handling to Python 3 syntax""" - for editable in file.find("except "): - if editable.source.lstrip().startswith("except") and ", " in editable.source and " as " not in editable.source: - parts = editable.source.split(",", 1) - new_source = f"{parts[0]} as{parts[1]}" - editable.edit(new_source) -``` - -This converts code from: - -```python -try: - process_data() -except ValueError, e: - print(e) -``` - -to: - -```python -try: - process_data() -except ValueError as e: - print(e) -``` - - - Python 3 uses `as` instead of a comma to name the exception variable. - - -## Step 5: Update Iterator Methods - -Finally, we update iterator methods to use Python 3's naming: - -```python -def update_iterators(file): - """Update iterator methods from Python 2 to Python 3""" - for cls in file.classes: - next_method = cls.get_method("next") - if next_method: - # Create new __next__ method with same content - new_method_source = next_method.source.replace("def next", "def __next__") - cls.add_source(new_method_source) - next_method.remove() -``` - -This transforms iterator classes from: - -```python -class MyIterator: - def next(self): - return self.value -``` - -to: - -```python -class MyIterator: - def __next__(self): - return self.value -``` - - - Python 3 renames the `next()` method to `__next__()` for consistency with - other special methods. - - -## Running the Migration - -You can run the complete migration using our example script: - -```bash -git clone https://github.com/codegen-sh/codegen-sdk.git -cd codegen-examples/examples/python2_to_python3 -python run.py -``` - -The script will: - -1. Process all Python [files](/api-reference/python/PyFile) in your codebase -2. Apply the transformations in the correct order -3. Maintain your code's functionality while updating to Python 3 syntax - -## Next Steps - -After migration, you might want to: - -- Add type hints to your code -- Use f-strings for string formatting -- Update dependencies to Python 3 versions -- Run the test suite to verify functionality - -Check out these related tutorials: - -- [Increase Type Coverage](/tutorials/increase-type-coverage) -- [Organizing Your Codebase](/tutorials/organize-your-codebase) -- [Creating Documentation](/tutorials/creating-documentation) - -## Learn More - -- [Python 3 Documentation](https://docs.python.org/3/) -- [What's New in Python 3](https://docs.python.org/3/whatsnew/3.0.html) -- [Codegen API Reference](/api-reference) -- [Dependencies and Usages](/building-with-codegen/dependencies-and-usages) diff --git a/docs/_deprecated/tutorials/react-modernization.mdx b/docs/_deprecated/tutorials/react-modernization.mdx deleted file mode 100644 index 170999c5a..000000000 --- a/docs/_deprecated/tutorials/react-modernization.mdx +++ /dev/null @@ -1,322 +0,0 @@ ---- -title: "React Modernization" -sidebarTitle: "React Modernization" -icon: "react" -iconType: "brands" -description: "Modernize your React codebase with Codegen" ---- - -Codegen SDK provides powerful APIs for modernizing React codebases. This guide will walk you through common React modernization patterns. - -Common use cases include: - -- Upgrading to modern APIs, including React 18+ -- Automatically memoizing components -- Converting to modern hooks -- Standardizing prop types -- Organizing components into individual files - -and much more. - -## Converting Class Components to Functions - -Here's how to convert React class components to functional components: - -```python -# Find all React class components -for class_def in codebase.classes: - # Skip if not a React component - if not class_def.is_jsx or "Component" not in [base.name for base in class_def.bases]: - continue - - print(f"Converting {class_def.name} to functional component") - - # Extract state from constructor - constructor = class_def.get_method("constructor") - state_properties = [] - if constructor: - for statement in constructor.code_block.statements: - if "this.state" in statement.source: - # Extract state properties - state_properties = [prop.strip() for prop in - statement.source.split("{")[1].split("}")[0].split(",")] - - # Create useState hooks for each state property - state_hooks = [] - for prop in state_properties: - hook_name = f"[{prop}, set{prop[0].upper()}{prop[1:]}]" - state_hooks.append(f"const {hook_name} = useState(null);") - - # Convert lifecycle methods to effects - effects = [] - if class_def.get_method("componentDidMount"): - effects.append(""" - useEffect(() => { - // TODO: Move componentDidMount logic here - }, []); - """) - - if class_def.get_method("componentDidUpdate"): - effects.append(""" - useEffect(() => { - // TODO: Move componentDidUpdate logic here - }); - """) - - # Get the render method - render_method = class_def.get_method("render") - - # Create the functional component - func_component = f""" -const {class_def.name} = ({class_def.get_method("render").parameters[0].name}) => {{ - {chr(10).join(state_hooks)} - {chr(10).join(effects)} - - {render_method.code_block.source} -}} -""" - - # Replace the class with the functional component - class_def.edit(func_component) - - # Add required imports - file = class_def.file - if not any("useState" in imp.source for imp in file.imports): - file.add_import("import { useState, useEffect } from 'react';") -``` - -## Migrating to Modern Hooks - -Convert legacy patterns to modern React hooks: - -```python -# Find components using legacy patterns -for function in codebase.functions: - if not function.is_jsx: - continue - - # Look for common legacy patterns - for call in function.function_calls: - # Convert withRouter to useNavigate - if call.name == "withRouter": - # Add useNavigate import - function.file.add_import( - "import { useNavigate } from 'react-router-dom';" - ) - # Add navigate hook - function.insert_before_first_return("const navigate = useNavigate();") - # Replace history.push calls - for history_call in function.function_calls: - if "history.push" in history_call.source: - history_call.edit( - history_call.source.replace("history.push", "navigate") - ) - - # Convert lifecycle methods in hooks - elif call.name == "componentDidMount": - call.parent.edit(""" -useEffect(() => { - // Your componentDidMount logic here -}, []); -""") -``` - -## Standardizing Props - -### Inferring Props from Usage - -Add proper prop types and TypeScript interfaces based on how props are used: - -```python -# Add TypeScript interfaces for props -for function in codebase.functions: - if not function.is_jsx: - continue - - # Get props parameter - props_param = function.parameters[0] if function.parameters else None - if not props_param: - continue - - # Collect used props - used_props = set() - for prop_access in function.function_calls: - if f"{props_param.name}." in prop_access.source: - prop_name = prop_access.source.split(".")[1] - used_props.add(prop_name) - - # Create interface - if used_props: - interface_def = f""" -interface {function.name}Props {{ - {chr(10).join(f' {prop}: any;' for prop in used_props)} -}} -""" - function.insert_before(interface_def) - # Update function signature - function.edit(function.source.replace( - f"({props_param.name})", - f"({props_param.name}: {function.name}Props)" - )) -``` - -### Extracting Inline Props - -Convert inline prop type definitions to separate type declarations: - -```python -# Iterate over all files in the codebase -for file in codebase.files: - # Iterate over all functions in the file - for function in file.functions: - # Check if the function is a React functional component - if function.is_jsx: # Assuming is_jsx indicates a function component - # Check if the function has inline props definition - if len(function.parameters) == 1 and isinstance(function.parameters[0].type, Dict): - # Extract the inline prop type - inline_props: TSObjectType = function.parameters[0].type.source - # Create a new type definition for the props - props_type_name = f"{function.name}Props" - props_type_definition = f"type {props_type_name} = {inline_props};" - - # Set the new type for the parameter - function.parameters[0].set_type_annotation(props_type_name) - # Add the new type definition to the file - function.insert_before('\n' + props_type_definition + '\n') -``` - -This will convert components from: - -```typescript -function UserCard({ name, age }: { name: string; age: number }) { - return ( -
- {name} ({age}) -
- ); -} -``` - -To: - -```typescript -type UserCardProps = { name: string; age: number }; - -function UserCard({ name, age }: UserCardProps) { - return ( -
- {name} ({age}) -
- ); -} -``` - - - Extracting prop types makes them reusable and easier to maintain. It also - improves code readability by separating type definitions from component logic. - - -## Updating Fragment Syntax - -Modernize React Fragment syntax: - -```python -for function in codebase.functions: - if not function.is_jsx: - continue - - # Replace React.Fragment with <> - for element in function.jsx_elements: - if element.name == "React.Fragment": - element.edit(element.source.replace( - "", - "<>" - ).replace( - "", - "" - )) -``` - -## Organizing Components into Individual Files - -A common modernization task is splitting files with multiple components into a more maintainable structure where each component has its own file. This is especially useful when modernizing legacy React codebases that might have grown organically. - -```python -# Initialize a dictionary to store files and their corresponding JSX components -files_with_jsx_components = {} - -# Iterate through all files in the codebase -for file in codebase.files: - # Check if the file is in the components directory - if 'components' not in file.filepath: - continue - - # Count the number of JSX components in the file - jsx_count = sum(1 for function in file.functions if function.is_jsx) - - # Only proceed if there are multiple JSX components - if jsx_count > 1: - # Identify non-default exported components - non_default_components = [ - func for func in file.functions - if func.is_jsx and not func.is_exported - ] - default_components = [ - func for func in file.functions - if func.is_jsx and func.is_exported and func.export.is_default_export() - ] - - # Log the file path and its components - print(f"πŸ“ {file.filepath}:") - for component in default_components: - print(f" 🟒 {component.name} (default)") - for component in non_default_components: - print(f" πŸ”΅ {component.name}") - - # Create a new directory path based on the original file's directory - new_dir_path = "/".join(file.filepath.split("/")[:-1]) + "/" + file.name.split(".")[0] - codebase.create_directory(new_dir_path, exist_ok=True) - - # Create a new file path for the component - new_file_path = f"{new_dir_path}/{component.name}.tsx" - new_file = codebase.create_file(new_file_path) - - # Log the movement of the component - print(f" 🫸 Moved to: {new_file_path}") - - # Move the component to the new file - component.move_to_file(new_file, strategy="add_back_edge") -``` - -This script will: - -1. Find files containing multiple React components -2. Create a new directory structure based on the original file -3. Move each non-default exported component to its own file -4. Preserve imports and dependencies automatically -5. Keep default exports in their original location - -For example, given this structure: - -``` -components/ - Forms.tsx # Contains Button, Input, Form (default) -``` - -It will create: - -``` -components/ - Forms.tsx # Contains Form (default) - forms/ - Button.tsx - Input.tsx -``` - - - The `strategy="add_back_edge"` parameter ensures that any components that were - previously co-located can still import each other without circular - dependencies. Learn more about [moving - code](/building-with-codegen/moving-symbols) here. - - diff --git a/docs/_deprecated/tutorials/slack-bot.mdx b/docs/_deprecated/tutorials/slack-bot.mdx deleted file mode 100644 index 9aeb36741..000000000 --- a/docs/_deprecated/tutorials/slack-bot.mdx +++ /dev/null @@ -1,217 +0,0 @@ ---- -title: "Building a RAG-powered Slack Bot" -sidebarTitle: "Slack Bot" -icon: "slack" -iconType: "solid" ---- - -This tutorial demonstrates how to build a Slack bot that can answer code questions using simple RAG (Retrieval Augmented Generation) over a codebase. The bot uses semantic search to find relevant code snippets and generates detailed answers using OpenAI's APIs. - -View the full code and setup instructions in our [examples repository](https://github.com/codegen-sh/codegen-sdk/tree/develop/codegen-examples/examples/slack_chatbot) - -While this example uses the Codegen codebase, you can adapt it to any repository by changing the repository URL - -## Overview - -The process involves three main steps: - -1. Initializing and indexing the codebase -2. Finding relevant code snippets for a query -3. Generating answers using RAG - -Let's walk through each step using Codegen. - -## Step 1: Initializing the Codebase - -First, we initialize the codebase and create a vector index for semantic search: - -```python -from codegen import Codebase -from codegen.extensions import VectorIndex - -def initialize_codebase(): - """Initialize and index the codebase.""" - # Initialize codebase with smart caching - codebase = Codebase.from_repo( - "codegen-sh/codegen-sdk", - language="python", - tmp_dir="/root" - ) - - # Initialize vector index - index = VectorIndex(codebase) - - # Try to load existing index or create new one - index_path = "/root/E.pkl" - try: - index.load(index_path) - except FileNotFoundError: - # Create new index if none exists - index.create() - index.save(index_path) - - return codebase, index -``` - - -The vector index is persisted to disk, so subsequent queries will be much faster. -See [semantic code search](/building-with-codegen/semantic-code-search) to learn more about VectorIndex. - - -## Step 2: Finding Relevant Code - -Next, we use the vector index to find code snippets relevant to a query: - -```python -def find_relevant_code(index: VectorIndex, query: str) -> list[tuple[str, float]]: - """Find code snippets relevant to the query.""" - # Get top 10 most relevant files - results = index.similarity_search(query, k=10) - - # Clean up chunk references from index - cleaned_results = [] - for filepath, score in results: - if "#chunk" in filepath: - filepath = filepath.split("#chunk")[0] - cleaned_results.append((filepath, score)) - - return cleaned_results -``` - - -VectorIndex automatically chunks large files for better search results. We clean up the chunk references to show clean file paths. - - -## Step 3: Generating Answers - -Finally, we use GPT-4 to generate answers based on the relevant code: - -```python -from openai import OpenAI - -def generate_answer(query: str, context: str) -> str: - """Generate an answer using RAG.""" - prompt = f"""You are a code expert. Given the following code context and question, -provide a clear and accurate answer. - -Note: Keep it short and sweet - 2 paragraphs max. - -Question: {query} - -Relevant code: -{context} - -Answer:""" - - client = OpenAI() - response = client.chat.completions.create( - model="gpt-4o", - messages=[ - {"role": "system", "content": "You are a code expert. Answer questions about the given repo based on RAG'd results."}, - {"role": "user", "content": prompt}, - ], - temperature=0, - ) - - return response.choices[0].message.content -``` - -## Putting It All Together - -Here's how the components work together to answer questions: - -```python -def answer_question(query: str) -> tuple[str, list[tuple[str, float]]]: - """Answer a question about the codebase using RAG.""" - # Initialize or load codebase and index - codebase, index = initialize_codebase() - - # Find relevant files - results = find_relevant_code(index, query) - - # Collect context from relevant files - context = "" - for filepath, score in results: - file = codebase.get_file(filepath) - context += f"File: {filepath}\n```\n{file.content}\n```\n\n" - - # Generate answer - answer = generate_answer(query, context) - - return answer, results -``` - -This will: -1. Load or create the vector index -2. Find relevant code snippets -3. Generate a detailed answer -4. Return both the answer and file references - -## Example Usage - -Here's what the output looks like: - -```python -answer, files = answer_question("How does VectorIndex handle large files?") - -print("Answer:", answer) -print("\nRelevant files:") -for filepath, score in files: - print(f"β€’ {filepath} (score: {score:.2f})") -``` - -Output: -``` -Answer: -VectorIndex handles large files by automatically chunking them into smaller pieces -using tiktoken. Each chunk is embedded separately and can be searched independently, -allowing for more precise semantic search results. - -Relevant files: -β€’ src/codegen/extensions/vector_index.py (score: 0.92) -β€’ src/codegen/extensions/tools/semantic_search.py (score: 0.85) -``` - -## Extensions - -While this example demonstrates a simple RAG-based bot, you can extend it to build a more powerful code agent that can: -- Do more sophisticated code retrieval -- Make code changes using Codegen's edit APIs -- Gather further context from Slack channels -- ... etc. - -Check out our [Code Agent tutorial](/tutorials/build-code-agent) to learn how to build an intelligent agent with access to Codegen's full suite of tools - - -## Learn More - - - - Learn how to use VectorIndex for semantic code search and embeddings. - - - Create a more powerful agent with multi-step reasoning and code manipulation. - - - Learn about OpenAI's text embeddings and how they work. - - - Understand RAG patterns and best practices for better results. - - diff --git a/docs/_deprecated/tutorials/sqlalchemy-1.6-to-2.0.mdx b/docs/_deprecated/tutorials/sqlalchemy-1.6-to-2.0.mdx deleted file mode 100644 index daee01f8b..000000000 --- a/docs/_deprecated/tutorials/sqlalchemy-1.6-to-2.0.mdx +++ /dev/null @@ -1,126 +0,0 @@ ---- -title: "Migrating from SQLAlchemy 1.4 to 2.0" -sidebarTitle: "SQLAlchemy 1.4 to 2.0" -description: "Learn how to migrate SQLAlchemy 1.4 codebases to 2.0 using Codegen" -icon: "layer-group" -iconType: "solid" ---- - -Migrating from [SQLAlchemy](https://www.sqlalchemy.org/) 1.4 to 2.0 involves several API changes to support the new 2.0-style query interface. This guide will walk you through using Codegen to automate this migration, handling query syntax, session usage, and ORM patterns. - - -You can find the complete example code in our [examples repository](https://github.com/codegen-sh/codegen-sdk/tree/develop/codegen-examples/examples/sqlalchemy_1.4_to_2.0). - - -## Overview - -The migration process involves three main steps: - -1. Converting legacy Query objects to select() statements -2. Updating session execution patterns -3. Modernizing ORM relationship declarations - -Let's walk through each step using Codegen. - -## Step 1: Convert Query to Select - -First, we need to convert legacy Query-style operations to the new select() syntax: - -```python -def convert_query_to_select(file): - """Convert Query-style operations to select() statements""" - for call in file.function_calls: - if call.name == "query": - # Convert query(Model) to select(Model) - call.set_name("select") - - # Update method chains - if call.parent and call.parent.is_method_chain: - chain = call.parent - if "filter" in chain.source: - # Convert .filter() to .where() - chain.source = chain.source.replace(".filter(", ".where(") - if "filter_by" in chain.source: - # Convert .filter_by(name='x') to .where(Model.name == 'x') - model = call.args[0].value - conditions = chain.source.split("filter_by(")[1].split(")")[0] - new_conditions = [] - for cond in conditions.split(","): - if "=" in cond: - key, value = cond.split("=") - new_conditions.append(f"{model}.{key.strip()} == {value.strip()}") - chain.edit(f".where({' & '.join(new_conditions)})") -``` - -This transforms code from: - -```python -# Legacy Query style -session.query(User).filter_by(name='john').filter(User.age >= 18).all() -``` - -to: - -```python -# New select() style -session.execute( - select(User).where(User.name == 'john').where(User.age >= 18) -).scalars().all() -``` - - - SQLAlchemy 2.0 standardizes on select() statements for all queries, providing - better type checking and a more consistent API. - - -## Step 2: Update Session Execution - -Next, we update how queries are executed with the Session: - -```python -def update_session_execution(file): - """Update session execution patterns for 2.0 style""" - for call in file.function_calls: - if call.name == "query": - # Find the full query chain - chain = call - while chain.parent and chain.parent.is_method_chain: - chain = chain.parent - - # Wrap in session.execute() if needed - if not chain.parent or "execute" not in chain.parent.source: - chain.edit(f"execute(select{chain.source[5:]})") - - # Add .scalars() for single-entity queries - if len(call.args) == 1: - chain.edit(f"{chain.source}.scalars()") -``` - -This converts patterns like: - -```python -# Old style -users = session.query(User).all() -first_user = session.query(User).first() -``` - -to: - -```python -# New style -users = session.execute(select(User)).scalars().all() -first_user = session.execute(select(User)).scalars().first() -``` - - - The new execution pattern is more explicit about what's being returned, making - it easier to understand and maintain type safety. - - -## Step 3: Update ORM Relationships - -Finally, we update relationship declarations to use the new style: - -``` - -``` diff --git a/docs/_deprecated/tutorials/training-data.mdx b/docs/_deprecated/tutorials/training-data.mdx deleted file mode 100644 index 300ad07da..000000000 --- a/docs/_deprecated/tutorials/training-data.mdx +++ /dev/null @@ -1,202 +0,0 @@ ---- -title: "Mining Training Data for LLMs" -sidebarTitle: "Mining Data" -description: "Learn how to generate training data for large language models using Codegen" -icon: "network-wired" -iconType: "solid" ---- - -This guide demonstrates how to use Codegen to generate high-quality training data for large language models (LLMs) by extracting function implementations along with their dependencies and usages. This approach is similar to [word2vec](https://www.tensorflow.org/text/tutorials/word2vec) or [node2vec](https://snap.stanford.edu/node2vec/) - given the context of a function, learn to predict the function's implementation. - -View the full code in our [examples repository](https://github.com/codegen-sh/codegen-sdk/tree/develop/codegen-examples/examples/generate_training_data) - -This example works with both Python and Typescript repositories without modification - -## Overview - -The process involves three main steps: - -1. Finding all functions in the codebase -2. Extracting their implementations, dependencies, and usages -3. Generating structured training data - -Let's walk through each step using Codegen. - -## Step 1: Finding Functions and Their Context - -First, we will do a "graph expansion" for each function - grab the function's source, as well as the full source of all usages of the function and all dependencies. - -See [dependencies and usages](/building-with-codegen/dependencies-and-usages) to learn more about navigating the code graph - -First, let's import the types we need from Codegen: - -```python -import codegen -from codegen import Codebase -from codegen.sdk.core.external_module import ExternalModule -from codegen.sdk.core.import_resolution import Import -from codegen.sdk.core.symbol import Symbol -``` - -Here's how we get the full context for each function: - -```python -def get_function_context(function) -> dict: - """Get the implementation, dependencies, and usages of a function.""" - context = { - "implementation": {"source": function.source, "filepath": function.filepath}, - "dependencies": [], - "usages": [], - } - - # Add dependencies - for dep in function.dependencies: - # Hop through imports to find the root symbol source - if isinstance(dep, Import): - dep = hop_through_imports(dep) - - context["dependencies"].append({"source": dep.source, "filepath": dep.filepath}) - - # Add usages - for usage in function.usages: - context["usages"].append({ - "source": usage.usage_symbol.source, - "filepath": usage.usage_symbol.filepath, - }) - - return context -``` - -Notice how we use `hop_through_imports` to resolve dependencies. When working with imports, symbols can be re-exported multiple times. For example, a helper function might be imported and re-exported through several files before being used. We need to follow this chain to find the actual implementation: - -```python -def hop_through_imports(imp: Import) -> Symbol | ExternalModule: - """Finds the root symbol for an import.""" - if isinstance(imp.imported_symbol, Import): - return hop_through_imports(imp.imported_symbol) - return imp.imported_symbol -``` - -This creates a structured representation of each function's context: - -```json -{ - "implementation": { - "source": "def process_data(input: str) -> dict: ...", - "filepath": "src/data_processor.py" - }, - "dependencies": [ - { - "source": "def validate_input(data: str) -> bool: ...", - "filepath": "src/validators.py" - } - ], - "usages": [ - { - "source": "result = process_data(user_input)", - "filepath": "src/api.py" - } - ] -} -``` - -## Step 2: Processing the Codebase - -Next, we process all functions in the codebase to generate our training data: - -```python -def run(codebase: Codebase): - """Generate training data using a node2vec-like approach for code embeddings.""" - # Track all function contexts - training_data = { - "functions": [], - "metadata": { - "total_functions": len(codebase.functions), - "total_processed": 0, - "avg_dependencies": 0, - "avg_usages": 0, - }, - } - - # Process each function in the codebase - for function in codebase.functions: - # Skip if function is too small - if len(function.source.split("\n")) < 2: - continue - - # Get function context - context = get_function_context(function) - - # Only keep functions with enough context - if len(context["dependencies"]) + len(context["usages"]) > 0: - training_data["functions"].append(context) - - # Update metadata - training_data["metadata"]["total_processed"] = len(training_data["functions"]) - if training_data["functions"]: - training_data["metadata"]["avg_dependencies"] = sum( - len(f["dependencies"]) for f in training_data["functions"] - ) / len(training_data["functions"]) - training_data["metadata"]["avg_usages"] = sum( - len(f["usages"]) for f in training_data["functions"] - ) / len(training_data["functions"]) - - return training_data -``` - -## Step 3: Running the Generator - -Finally, we can run our training data generator on any codebase. - -See [parsing codebases](/building-with-codegen/parsing-codebases) to learn more - -```python -if __name__ == "__main__": - print("Initializing codebase...") - codebase = Codebase.from_repo("fastapi/fastapi") - - print("Generating training data...") - training_data = run(codebase) - - print("Saving training data...") - with open("training_data.json", "w") as f: - json.dump(training_data, f, indent=2) - print("Training data saved to training_data.json") -``` - -This will: -1. Load the target codebase -2. Process all functions -3. Save the structured training data to a JSON file - - - You can use any Git repository as your source codebase by passing the repo URL - to [Codebase.from_repo(...)](/api-reference/core/Codebase#from-repo). - - -## Using the Training Data - -The generated data can be used to train LLMs in several ways: - -1. **Masked Function Prediction**: Hide a function's implementation and predict it from dependencies and usages -2. **Code Embeddings**: Generate embeddings that capture semantic relationships between functions -3. **Dependency Prediction**: Learn to predict which functions are likely to be dependencies -4. **Usage Pattern Learning**: Train models to understand common usage patterns - -For example, to create a masked prediction task: - -```python -def create_training_example(function_data): - """Create a masked prediction example from function data.""" - return { - "context": { - "dependencies": function_data["dependencies"], - "usages": function_data["usages"] - }, - "target": function_data["implementation"] - } - -# Create training examples -examples = [create_training_example(f) for f in training_data["functions"]] -``` - diff --git a/docs/_deprecated/tutorials/unittest-to-pytest.mdx b/docs/_deprecated/tutorials/unittest-to-pytest.mdx deleted file mode 100644 index bf633308c..000000000 --- a/docs/_deprecated/tutorials/unittest-to-pytest.mdx +++ /dev/null @@ -1,210 +0,0 @@ ---- -title: "Migrating from unittest to pytest" -sidebarTitle: "Unittest to Pytest" -description: "Learn how to migrate unittest test suites to pytest using Codegen" -icon: "vial" -iconType: "solid" ---- - -Migrating from [unittest](https://docs.python.org/3/library/unittest.html) to [pytest](https://docs.pytest.org/) involves converting test classes and assertions to pytest's more modern and concise style. This guide will walk you through using Codegen to automate this migration. - - -You can find the complete example code in our [examples repository](https://github.com/codegen-sh/codegen-sdk/tree/develop/codegen-examples/examples/unittest_to_pytest). - - -## Overview - -The migration process involves four main steps: - -1. Converting test class inheritance and setup/teardown methods -2. Updating assertions to pytest style -3. Converting test discovery patterns -4. Modernizing fixture usage - -Let's walk through each step using Codegen. - -## Step 1: Convert Test Classes and Setup Methods - -The first step is to convert unittest's class-based tests to pytest's function-based style. This includes: - -- Removing `unittest.TestCase` inheritance -- Converting `setUp` and `tearDown` methods to fixtures -- Updating class-level setup methods - -```python -# From: -class TestUsers(unittest.TestCase): - def setUp(self): - self.db = setup_test_db() - - def tearDown(self): - self.db.cleanup() - - def test_create_user(self): - user = self.db.create_user("test") - self.assertEqual(user.name, "test") - -# To: -import pytest - -@pytest.fixture -def db(): - db = setup_test_db() - yield db - db.cleanup() - -def test_create_user(db): - user = db.create_user("test") - assert user.name == "test" -``` - -## Step 2: Update Assertions - -Next, we'll convert unittest's assertion methods to pytest's plain assert statements: - -```python -# From: -def test_user_validation(self): - self.assertTrue(is_valid_email("user@example.com")) - self.assertFalse(is_valid_email("invalid")) - self.assertEqual(get_user_count(), 0) - self.assertIn("admin", get_roles()) - self.assertRaises(ValueError, parse_user_id, "invalid") - -# To: -def test_user_validation(): - assert is_valid_email("user@example.com") - assert not is_valid_email("invalid") - assert get_user_count() == 0 - assert "admin" in get_roles() - with pytest.raises(ValueError): - parse_user_id("invalid") -``` - -## Step 3: Update Test Discovery - -pytest uses a different test discovery pattern than unittest. We'll update the test file names and patterns: - -```python -# From: -if __name__ == '__main__': - unittest.main() - -# To: -# Remove the unittest.main() block entirely -# Rename test files to test_*.py or *_test.py -``` - -## Step 4: Modernize Fixture Usage - -Finally, we'll update how test dependencies are managed using pytest's powerful fixture system: - -```python -# From: -class TestDatabase(unittest.TestCase): - @classmethod - def setUpClass(cls): - cls.db_conn = create_test_db() - - def setUp(self): - self.transaction = self.db_conn.begin() - - def tearDown(self): - self.transaction.rollback() - -# To: -@pytest.fixture(scope="session") -def db_conn(): - return create_test_db() - -@pytest.fixture -def transaction(db_conn): - transaction = db_conn.begin() - yield transaction - transaction.rollback() -``` - -## Common Patterns - -Here are some common patterns you'll encounter when migrating to pytest: - -1. **Parameterized Tests** - -```python -# From: -def test_validation(self): - test_cases = [("valid@email.com", True), ("invalid", False)] - for email, expected in test_cases: - with self.subTest(email=email): - self.assertEqual(is_valid_email(email), expected) - -# To: -@pytest.mark.parametrize("email,expected", [ - ("valid@email.com", True), - ("invalid", False) -]) -def test_validation(email, expected): - assert is_valid_email(email) == expected -``` - -2. **Exception Testing** - -```python -# From: -def test_exceptions(self): - self.assertRaises(ValueError, process_data, None) - with self.assertRaises(TypeError): - process_data(123) - -# To: -def test_exceptions(): - with pytest.raises(ValueError): - process_data(None) - with pytest.raises(TypeError): - process_data(123) -``` - -3. **Temporary Resources** - -```python -# From: -def setUp(self): - self.temp_dir = tempfile.mkdtemp() - -def tearDown(self): - shutil.rmtree(self.temp_dir) - -# To: -@pytest.fixture -def temp_dir(): - dir = tempfile.mkdtemp() - yield dir - shutil.rmtree(dir) -``` - -## Tips and Notes - -1. pytest fixtures are more flexible than unittest's setup/teardown methods: - - - They can be shared across test files - - They support different scopes (function, class, module, session) - - They can be parameterized - -2. pytest's assertion introspection provides better error messages by default: - - ```python - # pytest shows a detailed comparison - assert result == expected - ``` - -3. You can gradually migrate to pytest: - - - pytest can run unittest-style tests - - Convert one test file at a time - - Start with assertion style updates before moving to fixtures - -4. Consider using pytest's built-in fixtures: - - `tmp_path` for temporary directories - - `capsys` for capturing stdout/stderr - - `monkeypatch` for modifying objects - - `caplog` for capturing log messages diff --git a/docs/capabilities/interrupts.mdx b/docs/capabilities/interrupts.mdx index a91b52ff2..33f2521ef 100644 --- a/docs/capabilities/interrupts.mdx +++ b/docs/capabilities/interrupts.mdx @@ -1,6 +1,8 @@ --- title: "Interrupts" description: "How Codegen handles real-time interrupts from Slack and Linear while working" +icon: "bolt" +iconType: "solid" --- ## Overview @@ -29,10 +31,13 @@ In Slack, you can send interrupt messages by: 3. **Sending follow-up messages** in the same channel -**Important**: You **must** mention `@codegen` in your interrupt messages for Codegen to respond in Slack channels, unless you're in a direct message (DM) with Codegen where it will respond automatically. + **Important**: You **must** mention `@codegen` in your interrupt messages for + Codegen to respond in Slack channels, unless you're in a direct message (DM) + with Codegen where it will respond automatically. **Example:** + ``` User: @codegen can you fix the login bug? Codegen: I'll fix the login bug! πŸ”§ [starts working] @@ -49,10 +54,12 @@ In Linear, interrupts work through: 3. **Changing issue priority or labels** (triggers re-evaluation) -**Note**: Codegen will respond automatically to your comments in Linear unless another user is tagged in the same comment. + **Note**: Codegen will respond automatically to your comments in Linear unless + another user is tagged in the same comment. **Example:** + ``` Issue: Fix authentication system Codegen: Working on the authentication fix... @@ -60,14 +67,13 @@ Codegen: Working on the authentication fix... Codegen: I see you've added 2FA requirements - incorporating that now! ``` - - ## Best Practices ### For Users -**Send interrupts early**: If you realize you need to add context or change requirements, send the message immediately rather than waiting for completion. + **Send interrupts early**: If you realize you need to add context or change + requirements, send the message immediately rather than waiting for completion. - **Be specific**: Clearly state what you want to add or change diff --git a/docs/gen/capabilities.mdx b/docs/gen/capabilities.mdx deleted file mode 100644 index 1ff500218..000000000 --- a/docs/gen/capabilities.mdx +++ /dev/null @@ -1,102 +0,0 @@ ---- -title: "Capabilities" -icon: "gear" ---- - -Codegen is built on an [open-source library](/introduction/overview) for code manipulation. - -It combines "tools" for code editing with powerful integrations, including Github, Linear and Slack. - - - Learn more about our open source [code agent implementation](/tutorials/build-code-agent) - - -## Communication Tools - -- **SlackSendMessageTool**: Allows Codegen to send messages in Slack channels and threads, providing responses to your queries and sharing information with your team. - -## GitHub Integration Tools - -Codegen includes a comprehensive set of GitHub tools: - -- **GithubCheckoutPRTool**: Checks out pull requests to your local environment for review and testing. - -- **GithubCreatePRTool**: Creates new pull requests from your current branch, including title, description, and target branch. - -- **GithubCreatePRCommentTool**: Adds comments to pull requests for feedback and team communication. - -- **GithubCreatePRReviewCommentTool**: Provides inline comments on specific code changes within pull requests. - -- **GithubEditPRTool**: Modifies existing pull requests, including updating titles, descriptions, and other metadata. - -- **GithubSearchIssuesTool**: Searches for GitHub issues based on various criteria like status, assignee, or labels. - -- **GithubViewPRTool**: Retrieves and displays information about specific pull requests. - -- **GithubViewPRCheckTool**: Checks the status of CI/CD and other automated checks on pull requests. - -- **GithubViewCommitHistoryTool**: Shows the commit history of a repository or specific branch. - -- **GithubViewCommitTool**: Displays details about specific commits, including changes made. - -## Linear Integration Tools (Optional) - -For teams using Linear for project management, Codegen offers: - -- **LinearGetIssueTool**: Retrieves details about specific Linear issues. - -- **LinearGetIssueCommentsTool**: Fetches comments on Linear issues for context and history. - -- **LinearCommentOnIssueTool**: Adds comments to Linear issues for team communication. - -- **LinearSearchIssuesTool**: Searches for Linear issues based on various criteria. - -- **LinearCreateIssueTool**: Creates new issues in Linear with appropriate metadata. - -- **LinearGetTeamsTool**: Retrieves information about teams in your Linear organization. - -## How Codegen Uses These Tools - -Codegen's brain (powered by Claude 3.7 Sonnet) intelligently selects and combines these tools to: - -1. Understand your requests through natural language in Slack -2. Determine the most appropriate tools to fulfill your request -3. Execute the necessary actions across GitHub, Linear, and your codebase -4. Provide clear, helpful responses back in Slack - -This seamless integration allows you to manage your entire development workflow through simple conversations, without having to switch between different platforms and interfaces. - -## Recommended Best Practices for Using Codegen - -Here are some recommended best practices for integrating Codegen effectively into your development workflow: - -### Workflow Integration - -- **Small bug fixes**: For minor issues, consider using Codegen for instant fixes and merges -- **Larger tickets**: A multi-step approach often works best: - 1. Ask Codegen to do a first pass on the implementation - 2. Check out the branch and review the changes - 3. Add any necessary adjustments - 4. QA the changes - 5. Merge the code - -### When to Use Codegen vs. IDE - -Consider using Codegen for: -- Initial exploration and first pass on tickets and engineering efforts -- Quickly gathering context on issues (e.g., explaining errors in notification threads) -- Understanding the "blast radius" of a given change to assess its impact -- Getting a solid first pass at approximately 80% of your work - -Use your preferred IDE (like Cursor or VS Code) for: -- Making precise adjustments after Codegen's first pass -- Detailed work that requires deep context - -### Effectiveness Tips - -- Be diligent about analyzing tasks and determining how to break them down for Codegen -- Split complex tasks into manageable chunks -- Don't hesitate to discard unhelpful outputs and try a different approach -- View Codegen as a powerful assistant rather than an infallible oracle - -These practices can help you leverage Codegen effectively while maintaining high code quality and productivity. diff --git a/docs/gen/faq.mdx b/docs/gen/faq.mdx deleted file mode 100644 index 2a34b0435..000000000 --- a/docs/gen/faq.mdx +++ /dev/null @@ -1,18 +0,0 @@ ---- -title: "Frequently Asked Questions" -sidebarTitle: "FAQ" -icon: "square-question" -iconType: "solid" ---- - - - - Claude 3.7. Our code agent is roughly comparable with Claude Code. - - - Yes! For now. Get it while it's hot. - - - Codegen stores this data in their private cloud. We are SOC-2 compliant. [Learn more](/introduction/about) - - \ No newline at end of file diff --git a/docs/gen/integrations.mdx b/docs/gen/integrations.mdx deleted file mode 100644 index a1d94c500..000000000 --- a/docs/gen/integrations.mdx +++ /dev/null @@ -1,49 +0,0 @@ ---- -title: 'Integrations' -description: 'Integrate Codegen with your favorite tools and platforms' -icon: 'puzzle-piece' ---- - - - Get started with Codegen integrations by installing the CLI - - -## Available Integrations - -### GitHub - -Codegen integrates seamlessly with GitHub, allowing you to: -- Run automated code reviews -- Manage pull requests -- Analyze codebases -- Automate code modifications at scale - -### Slack - -Connect Codegen with Slack to: -- Receive notifications about code changes -- Run code analysis directly from Slack -- Get instant feedback on pull requests -- Collaborate with your team on code reviews - -### Linear - -Our Linear integration enables you to: -- Link code changes to issues -- Automatically update ticket status -- Track code modifications across projects -- Streamline your development workflow - -## Coming Soon - -We're actively working on integrations with: -- Sentry -- Vercel -- Modal -- And more! - -Stay tuned for updates or [join our community](/introduction/community) to request new integrations. diff --git a/docs/gen/introduction.mdx b/docs/gen/introduction.mdx deleted file mode 100644 index a5d953af0..000000000 --- a/docs/gen/introduction.mdx +++ /dev/null @@ -1,43 +0,0 @@ ---- -title: "Codegen: AI Development Assistant" -sidebarTitle: "Introduction" -icon: "lightbulb" ---- - -Codegen is an intelligent code agent powered that seamlessly integrates with Slack, Github and Linear. - - - - - - - Explore our [Capabilities](/gen/capabilities) page to learn more about - Codegen's full feature set and available tools! - - - -# Installation - -[Log in with GitHub](https://codegen.sh/install) to install Codegen and set up integrations. - - - Install codegen via OAuth with Github, Slack and Linear - - -# Common Queries - -> *Edit repo X so that the user auth flow uses JWT* -Modify the authentication flow in a specified repository to use JSON Web Tokens. This ensures secure and stateless authentication. - -> *Show me the recent activity on my repo X* -Display the latest commits, pull requests, and other activities in a specified repository. This helps you stay updated with ongoing changes. - -> *Can you figure out why my tests are failing on `main`?* -Analyze the test failures on the main branch to identify potential issues. This assists in maintaining code quality and stability. - -> *Can you review my PR?* -Perform a code review on a specified pull request, providing feedback and suggestions. This ensures code quality and adherence to best practices. - -> *Do we have any tickets about Y?* -Search for tickets related to a specific topic or issue. This helps in tracking and managing tasks effectively. - diff --git a/docs/graph-sitter/about.mdx b/docs/graph-sitter/about.mdx deleted file mode 100644 index d7ffe80a1..000000000 --- a/docs/graph-sitter/about.mdx +++ /dev/null @@ -1,72 +0,0 @@ ---- -title: "Codegen, Inc." -sidebarTitle: "About Us" -icon: "building" -iconType: "solid" ---- - - - -## Our Mission - -Our mission is to build fully-autonomous software engineering - the equivalent of self-driving cars for code. - -We believe the highest leverage path to autonomous development is enabling AI agents to "act via code." - -Just as self-driving cars need sophisticated sensors and controls to navigate the physical world, AI agents need powerful, precise tools to manipulate codebases. We're building that foundational layer: a programmatic interface that lets AI agents express complex code transformations through code itself. - -This approach creates a shared language that both humans and AI can use to: - -- Express powerful changes with precision and predictability -- Build sophisticated tools from primitive operations -- Create and maintain their own abstractions -- Scale transformations across massive codebases - -## The Team - -Based in San Francisco, we're a team of engineers and researchers passionate about: - -- Making large-scale code changes more accessible -- Building tools that work the way developers think -- Creating the infrastructure for AI-powered code manipulation -- Advancing the state of the art in program transformation - -## Open Source - -We believe in the power of open source software. Our core library, [codegen](https://github.com/codegen-sh/codegen-sdk), is freely available and open to contributions from the community. - -## Join Us - - - - We're hiring! Join us in building the future of code transformation. - - - Connect with other developers and share your Codegen experiences. - - - -## Connect with Us - - - - Follow us for updates and announcements - - - Connect with our team and stay updated on company news - - - - - Want to learn more about what we're building? Check out our [getting started - guide](/introduction/getting-started) or join our [community - Slack](https://community.codegen.com). - diff --git a/docs/graph-sitter/advanced-settings.mdx b/docs/graph-sitter/advanced-settings.mdx deleted file mode 100644 index 08f0e5472..000000000 --- a/docs/graph-sitter/advanced-settings.mdx +++ /dev/null @@ -1,404 +0,0 @@ ---- -title: "Advanced Settings" -sidebarTitle: "Advanced Settings" -icon: "memory" -iconType: "solid" ---- - -Codegen's [Codebase](/api-reference/core/Codebase) constructor accepts a `CodebaseConfig` object which is used to configure more advanced behaviors of the graph construction process. - -These flags are helpful for debugging problematic repos, optimizing Codegen's performance, or testing unreleased or experimental (potentially backwards-breaking) features. - - -**These are considered experimental features and may change in the future!** - -As such, they may have little to no testing or documentation. Many of these flags may also be unsupported in the future! - -If you need help, please visit our [community](/introduction/community). - - - -These configuration options are defined in [src/codegen/configs/models/codebase.py](https://github.com/codegen-sh/codegen/blob/develop/src/codegen/configs/models/codebase.py). - - -# Usage - -You can customize the behavior of the graph construction process when initializing a [Codebase](/api-reference/core/Codebase) by passing a `CodebaseConfig` object with the desired configuration flags. - -```python -from codegen import Codebase -from codegen.configs import CodebaseConfig - -# Initialize a Codebase with custom configuration -codebase = Codebase( - "", - config=CodebaseConfig( - flag1=..., - flag2=..., - ... - ) -) -``` - -# Table of Contents - -- [debug](#flag-debug) -- [verify-graph](#flag-verify-graph) -- [track-graph](#flag-track-graph) -- [method-usages](#flag-method-usages) -- [sync-enabled](#flag-sync-enabled) -- [full-range-index](#flag-full-range-index) -- [ignore-process-errors](#flag-ignore-process-errors) -- [disable-graph](#flag-disable-graph) -- [disable-file-parse](#flag-disable-file-parse) -- [exp-lazy-graph](#flag-exp-lazy-graph) -- [generics](#flag-generics) -- [import-resolution-paths](#flag-import-resolution-paths) -- [import-resolution-overrides](#flag-import-resolution-overrides) -- [py-resolve-syspath](#flag-py-resolve-syspath) -- [ts-dependency-manager](#flag-ts-dependency-manager) -- [ts-language-engine](#flag-ts-language-engine) -- [v8-ts-engine](#flag-v8-ts-engine) -- [unpacking-assignment-partial-removal](#flag-unpacking-assignment-partial-removal) - -# Configuration Flags - -## Flag: `debug` -> **Default: `False`** - -Enables verbose logging for debugging purposes. In its current form, it enables: -- Verbose logging when adding nodes to the graph -- Verbose logging during initial file parsing -- Additional assertions on graph creation -- Additional (costly) debug metrics on codebase construction -- etc. - - -This flag may be very noisy and significantly impact performance. It is generally not recommended to use. - - -## Flag: `verify_graph` -> **Default: `False`** - -Adds assertions for graph state during reset resync. Used to test and debug graph desyncs after a codebase reset. - -Runs `post_reset_validation` after a reset resync. - - -This is an internal debug flag. - - -## Flag: `track_graph` -> **Default: `False`** - -Keeps a copy of the original graph before a resync. Used in conjunction with `verify_graph` to test and debug graph desyncs. - -Original graph is saved as `ctx.old_graph`. - - -This is an internal debug flag. - - -## Flag: `method_usages` -> **Default: `True`** - -Enables and disables resolving method usages. - -**Example Codebase:** -```python -class Foo: - def bar(): - ... - -obj = Foo() -obj.bar() # Method Usage -``` - -**Codemod with `method_usages` on:** -```python -bar_func = codebase.get_class("Foo").get_method("bar") -len(bar_func.usages) # 1 -bar_func.usages # [obj.bar()] -``` - -**Codemod with `method_usages` off:** -```python -bar_func = codebase.get_class("Foo").get_method("bar") -len(bar_func.usages) # 0 -bar_func.usages # [] -``` - -Method usage resolution could be disabled for a marginal performance boost. However, it is generally recommended to leave it enabled. - -## Flag: `sync_enabled` -> **Default: `False`** - -Enables or disables graph sync during `codebase.commit`. - - -Implementation-specific details on sync graph can be found [here](https://github.com/codegen-sh/codegen/blob/develop/architecture/6.%20incremental-computation/C.%20Graph%20Recomputation.md). - - -This section won't go into the specific details of sync graph, but the general idea is that enabling sync graph will update the Codebase object to whatever new changes were made. - -**Example with `sync_enabled` on:** -```python -file = codebase.get_file(...) -file.insert_after("foobar = 1") -codebase.commit() - -foobar = codebase.get_symbol("foobar") -assert foobar # foobar is available after commit / graph sync -``` - -**Example with `sync_enabled` disabled:** -```python -file = codebase.get_file(...) -file.insert_after("foobar = 1") - -foobar = codebase.get_symbol("foobar", optional=True) -assert not foobar # foobar is not available after commit -``` - - -Enabling sync graph will have a performance impact on codebase commit, but will also unlock a bunch of operations that were previously not possible. - - -## Flag: `full_range_index` -> **Default: `False`** - -By default, Codebase maintains an internal range-to-node index for fast lookups. (i.e. `bytes 120 to 130 maps to node X`). -For optimization purposes, this only applies to nodes defined and handled by `parser.py`. - -Enabling `full_range_index` will create an additional index that maps **all** tree-sitter ranges to nodes. -This can be useful for debugging or when you need to build any applications that require a full range-to-node index (i.e. a codebase tree lookup). - - -This flag **significantly** increases memory usage! - - -## Flag: `ignore_process_errors` -> **Default: `True`** - -Controls whether to ignore errors that occur during external process execution (such as dependency manager or language engine). - -Disabling `ignore_process_errors` would make Codegen fail on errors that would otherwise be logged then ignored. - -## Flag: `disable_graph` -> **Default: `False`** - -Disables the graph construction process. Any operations that require the graph will no longer work. (In other words, this turns off import resolution and usage/dependency resolution) - -Functions that operate purely on AST such as getting and editing parameters or modifying function and class definitions will still work. - - -For codemods that do not require the graph (aka only AST/Syntax-level changes), **disabling graph parse could yield a 30%-40% decrease in parse time and memory usage**! - - -## Flag: `disable_file_parse` -> **Default: `False`** - -Disables **ALL** parsing, including file and graph parsing. This essentially treats all codebases as the "UNSUPPORTED" language mode. - -Nearly all functions except for editing primitives like `codebase.get_file` and `file.edit` will no longer work. - - -This flag is useful for any usages of Codegen that do **NOT** require any AST/CST/Graph parsing. (i.e. using Codegen purely as a file editing harness) - -If this is your use case, this **could decrease parse and memory usage by 95%.** - - -## Flag: `exp_lazy_graph` -> **Default: `False`** - -This experimental flag pushes the graph creation back until the graph is needed. This is an experimental feature and may have some unintended consequences. - -**Example Codemod:** -```python -from codegen import Codebase -from codegen.configs import CodebaseConfig - -# Enable lazy graph parsing -codebase = Codebase("", config=CodebaseConfig(exp_lazy_graph=True)) - -# The codebase object will be created immediately with no parsing done -# These all do not require graph parsing -codebase.files -codebase.directories -codebase.get_file("...") - -# These do require graph parsing, and will create the graph only if called -codebase.get_function("...") -codebase.get_class("...") -codebase.imports -``` - - -This may have a very slight performance boost. Use at your own risk! - - -## Flag: `generics` -> **Default: `True`** - -Enables and disables generic type resolution. - -**Example Codebase:** -```python -class Point: - def scale(cls, n: int): - pass - -class List[T](): - def pop(self) -> T: - ... - -l: List[Point] = [] -l.pop().scale(1) # Generic Usage -``` - -**Codemod with `generics` on:** -```python -bar_func = codebase.get_class("Point").get_method("scale") -len(bar_func.usages) # 1 -bar_func.usages # [l.pop().scale(1)] -``` - -**Codemod with `generics` off:** -```python -bar_func = codebase.get_class("Point").get_method("scale") -len(bar_func.usages) # 0 -bar_func.usages # [] -``` - - -Generic resolution is still largely WIP and experimental, and may not work in all cases. In some rare circumstances, disabling generics may result in a significant performance boost. - - -## Flag: `import_resolution_paths` -> **Default: `[]`** - -Controls alternative paths to resolve imports from. - -**Example Codebase:** -```python -# a/b/c/src.py -def update(): - pass - -# consumer.py -from c import src as operations - -operations.update() -``` - -**Codemod:** -```python -codebase.ctx.config.import_resolution_paths = ["a/b"] -``` - -## Flag: `import_resolution_overrides` -> **Default: `{}`** - -Controls import path overrides during import resolution. - -**Example** -`from a.b.c import d` with the override `a/b` -> `foo/bar` will internally resolve the import as `from foo.bar.c import d`. - -## Flag: `py_resolve_syspath` -> **Default: `False`** - -Enables and disables resolution of imports from `sys.path`. - - -For this to properly work, you must also set `allow_external` to `True`. - - -## Flag: `allow_external` -> **Default: `False`** - -Enables resolving imports, files, modules, and directories from outside of the repo path. - - -Turning this flag off may allow for bad actors to access files outside of the repo path! Use with caution! - - -## Flag: `ts_dependency_manager` -> **Default: `False`** - - -**This is an internal flag used for Codegen Cloud and should not be used externally!** - -This flag **WILL** nuke any existing `node_modules` folder! - - - -This flag also assumes many constants for Codegen Cloud. Very likely this will not work if run locally. - -Instead, just install `node_modules` as normal (either through `npm`, `pnpm`, or `yarn`) and skip this setting! - - -Enables Codegen's internal dependency installer for TypeScript. This will modify `package.json` and install the bare minimum set of installable dependencies. - - -More documentation on TypeScript dependency manager can be found [here](https://github.com/codegen-sh/codegen/blob/develop/architecture/external/dependency-manager.md) - - -## Flag: `ts_language_engine` -> **Default: `False`** - - -This feature was built primarily with Codegen Cloud in mind. As such, this assumes a valid NodeJS and TypeScript environment. - - -Enables using the TypeScript compiler to extract information from the codebase. Enables commands such as `inferred_return_type`. - - -This will increase memory usage and parsing time. Larger repos may even hit resource constraints with the bundled TypeScript compiler integration. - - -## Flag: `v8_ts_engine` -> **Default: `False`** - - -This feature flag requires `ts_language_engine` to be enabled as well. - - -Enables using the **V8-based TypeScript compiler** to extract information from the codebase. Enables commands such as `inferred_return_type`. - -The V8 implementation (as opposed to the default external-process based implementation) is less stable, but provides the entire TypeScript API to be used from within Codegen. - - -This will increase memory usage and parsing time. Larger repos may even hit resource constraints with the V8-based TypeScript compiler integration. - - -## Flag: `unpacking_assignment_partial_removal` -> **Default: `False`** - -Enables smarter removal of unpacking assignments. - -**Example Codebase:** -```python -a, b, c = (1, 2, 3) -``` - -**Codemod with `unpacking_assignment_partial_removal` on:** -```python -file = codebase.get_file(...) -b = file.get_symbol("b") -b.remove() -codebase.commit() - -file.symbols # [a, c] -file.source # "a, c = (1, 3)" -``` - -**Codemod with `unpacking_assignment_partial_removal` off:** -```python -file = codebase.get_file(...) -b = file.get_symbol("b") -b.remove() -codebase.commit() - -file.symbols # [] -file.source # "" -``` diff --git a/docs/graph-sitter/community.mdx b/docs/graph-sitter/community.mdx deleted file mode 100644 index ed02a4276..000000000 --- a/docs/graph-sitter/community.mdx +++ /dev/null @@ -1,48 +0,0 @@ ---- -title: "Community & Contributing" -sidebarTitle: "Community" -icon: "people-group" -iconType: "solid" ---- - -import { - COMMUNITY_SLACK_URL, - CODEGEN_SDK_GITHUB_URL, -} from "/snippets/links.mdx"; - -Join the growing Codegen community! We're excited to have you be part of our journey to make codebase manipulation and transformation more accessible. - - - - Connect with the community, get help, and share your Codegen projects in our - active Slack workspace. - - - Star us on GitHub, report issues, submit PRs, and contribute to the project. - - - Follow us for updates, tips, and community highlights. - - - Learn how to use Codegen effectively with our comprehensive guides. - - - - - Please help us improve this library and documentation by submitting a PR! - - -## Contributing - -We welcome contributions of all kinds! Whether you're fixing a typo in documentation, reporting a bug, or implementing a new feature, we appreciate your help in making Codegen better. - -Check out our [Contributing Guide](https://github.com/codegen-sh/codegen-sdk/blob/develop/CONTRIBUTING.md) on GitHub to learn how to: - -- Set up your development environment -- Submit pull requests -- Report issues -- Contribute to documentation diff --git a/docs/graph-sitter/faq.mdx b/docs/graph-sitter/faq.mdx deleted file mode 100644 index d7f3abfba..000000000 --- a/docs/graph-sitter/faq.mdx +++ /dev/null @@ -1,58 +0,0 @@ ---- -title: "Frequently Asked Questions" -sidebarTitle: "FAQ" -icon: "square-question" -iconType: "solid" ---- - - - - Codegen currently parses two languages: - - [Python](/api-reference/python) - - [TypeScript](/api-reference/typescript) - - We're actively working on expanding language support based on community needs. - - Learn more about how Codegen handles language specifics in the [Language - Support](/building-with-codegen/language-support) guide. - - - Interested in adding support for your language? [Let us know](https://x.com/codegen) or [contribute](/introduction/community)! - - - - - Pretty much! Codegen is roughly on par with `mypy` and `tsc`. There are always edge cases in static analysis that are provably impossible to get (for example doing `eval()` on a string), but all of Codegen's APIs are intended to be exact unless otherwise specified. Please reach out if you find an edge case and we will do our best to patch it. - - - Yes! Codegen was developed on multmillion-line Python and Typescript codebases - and includes optimizations for handling large-scale transformations. - - For enterprise support, please reach out to [team@codegen.com](mailto:team@codegen.com) - - - - Yes - [by design](/introduction/guiding-principles#python-first-composability). - - Codegen works like any other python package. It works alongside your IDE, version control system, and other development tools. - - - Start by trying out Codegen, joining our [Slack community](https://community.codegen.com), and looking for - issues labeled "good first issue" on [GitHub](https://github.com/codegen-sh/codegen-sdk). We welcome contributions to - documentation, examples, and code improvements. - - - Yes, Codegen is [open source](https://github.com/codegen-sh/codegen-sdk) and free to use under the [Apache 2.0 - license](https://github.com/codegen-sh/codegen-sdk?tab=Apache-2.0-1-ov-file). - You can use it for both personal and commercial projects. - - - The best places to get help are: - 1. Our community [Slack channel](https://community.codegen.com) - 2. [GitHub issues](https://github.com/codegen-sh/codegen-sdk) for bug reports - 3. Reach out to us on [Twitter](https://x.com/codegen) - - diff --git a/docs/graph-sitter/getting-started.mdx b/docs/graph-sitter/getting-started.mdx deleted file mode 100644 index ad9e2c5f2..000000000 --- a/docs/graph-sitter/getting-started.mdx +++ /dev/null @@ -1,342 +0,0 @@ ---- -title: "Getting Started" -sidebarTitle: "Getting Started" -icon: "bolt" -iconType: "solid" ---- - -A quick tour of Codegen in a Jupyter notebook. - -## Installation - -Install [codegen](https://pypi.org/project/codegen/) on Pypi via [uv](https://github.com/astral-sh/uv): - -```bash -uv tool install codegen -``` - -## Quick Start with Jupyter - -The [codegen notebook](/cli/notebook) command creates a virtual environment and opens a Jupyter notebook for quick prototyping. This is often the fastest way to get up and running. - -```bash -# Launch Jupyter with a demo notebook -codegen notebook --demo -``` - - - - The `notebook --demo` comes pre-configured to load [FastAPI](https://github.com/fastapi/fastapi)'s codebase, so you can start - exploring right away! - - - - Prefer working in your IDE? See [IDE Usage](/introduction/ide-usage) - - -## Initializing a Codebase - -Instantiating a [Codebase](/api-reference/core/Codebase) will automatically parse a codebase and make it available for manipulation. - -```python -from codegen import Codebase - -# Clone + parse fastapi/fastapi -codebase = Codebase.from_repo('fastapi/fastapi') - -# Or, parse a local repository -codebase = Codebase("path/to/git/repo") -``` - - - This will automatically infer the programming language of the codebase and - parse all files in the codebase. Learn more about [parsing codebases here](/building-with-codegen/parsing-codebases) - - -## Exploring Your Codebase - -Let's explore the codebase we just initialized. - -Here are some common patterns for code navigation in Codegen: - -- Iterate over all [Functions](/api-reference/core/Function) with [Codebase.functions](/api-reference/core/Codebase#functions) -- View class inheritance with [Class.superclasses](/api-reference/core/Class#superclasses) -- View function usages with [Function.usages](/api-reference/core/Function#usages) -- View inheritance hierarchies with [inheritance APIs](https://docs.codegen.com/building-with-codegen/class-api#working-with-inheritance) -- Identify recursive functions by looking at [FunctionCalls](https://docs.codegen.com/building-with-codegen/function-calls-and-callsites) -- View function call-sites with [Function.call_sites](/api-reference/core/Function#call-sites) - -```python -# Print overall stats -print("πŸ” Codebase Analysis") -print("=" * 50) -print(f"πŸ“š Total Classes: {len(codebase.classes)}") -print(f"⚑ Total Functions: {len(codebase.functions)}") -print(f"πŸ”„ Total Imports: {len(codebase.imports)}") - -# Find class with most inheritance -if codebase.classes: - deepest_class = max(codebase.classes, key=lambda x: len(x.superclasses)) - print(f"\n🌳 Class with most inheritance: {deepest_class.name}") - print(f" πŸ“Š Chain Depth: {len(deepest_class.superclasses)}") - print(f" ⛓️ Chain: {' -> '.join(s.name for s in deepest_class.superclasses)}") - -# Find first 5 recursive functions -recursive = [f for f in codebase.functions - if any(call.name == f.name for call in f.function_calls)][:5] -if recursive: - print(f"\nπŸ”„ Recursive functions:") - for func in recursive: - print(f" - {func.name}") -``` - -## Analyzing Tests - -Let's specifically drill into large test files, which can be cumbersome to manage. - -```python -from collections import Counter - -# Filter to all test functions and classes -test_functions = [x for x in codebase.functions if x.name.startswith('test_')] -test_classes = [x for x in codebase.classes if x.name.startswith('Test')] - -print("πŸ§ͺ Test Analysis") -print("=" * 50) -print(f"πŸ“ Total Test Functions: {len(test_functions)}") -print(f"πŸ”¬ Total Test Classes: {len(test_classes)}") -print(f"πŸ“Š Tests per File: {len(test_functions) / len(codebase.files):.1f}") - -# Find files with the most tests -print("\nπŸ“š Top Test Files by Class Count") -print("-" * 50) -file_test_counts = Counter([x.file for x in test_classes]) -for file, num_tests in file_test_counts.most_common()[:5]: - print(f"πŸ” {num_tests} test classes: {file.filepath}") - print(f" πŸ“ File Length: {len(file.source)} lines") - print(f" πŸ’‘ Functions: {len(file.functions)}") -``` - -## Splitting Up Large Test Files - -Lets split up the largest test files into separate modules for better organization. - -This uses Codegen's [codebase.move_to_file(...)](/building-with-codegen/moving-symbols), which will: -- update all imports -- (optionally) move dependencies -- do so very fast ⚑️ - -While maintaining correctness. - -```python -filename = 'tests/test_path.py' -print(f"πŸ“¦ Splitting Test File: {filename}") -print("=" * 50) - -# Grab a file -file = codebase.get_file(filename) -base_name = filename.replace('.py', '') - -# Group tests by subpath -test_groups = {} -for test_function in file.functions: - if test_function.name.startswith('test_'): - test_subpath = '_'.join(test_function.name.split('_')[:3]) - if test_subpath not in test_groups: - test_groups[test_subpath] = [] - test_groups[test_subpath].append(test_function) - -# Print and process each group -for subpath, tests in test_groups.items(): - print(f"\\n{subpath}/") - new_filename = f"{base_name}/{subpath}.py" - - # Create file if it doesn't exist - if not codebase.has_file(new_filename): - new_file = codebase.create_file(new_filename) - file = codebase.get_file(new_filename) - - # Move each test in the group - for test_function in tests: - print(f" - {test_function.name}") - test_function.move_to_file(new_file, strategy="add_back_edge") - -# Commit changes to disk -codebase.commit() -``` - - - In order to commit changes to your filesystem, you must call - [codebase.commit()](/api-reference/core/Codebase#commit). Learn more about - [commit() and reset()](/building-with-codegen/commit-and-reset). - - -### Finding Specific Content - -Once you have a general sense of your codebase, you can filter down to exactly what you're looking for. Codegen's graph structure makes it straightforward and performant to find and traverse specific code elements: - -```python -# Grab specific content by name -my_resource = codebase.get_symbol('TestResource') - -# Find classes that inherit from a specific base -resource_classes = [ - cls for cls in codebase.classes - if cls.is_subclass_of('Resource') -] - -# Find functions with specific decorators -test_functions = [ - f for f in codebase.functions - if any('pytest' in d.source for d in f.decorators) -] - -# Find files matching certain patterns -test_files = [ - f for f in codebase.files - if f.name.startswith('test_') -] -``` - -## Safe Code Transformations - -Codegen guarantees that code transformations maintain correctness. It automatically handles updating imports, references, and dependencies. Here are some common transformations: - -```python -# Move all Enum classes to a dedicated file -for cls in codebase.classes: - if cls.is_subclass_of('Enum'): - # Codegen automatically: - # - Updates all imports that reference this class - # - Maintains the class's dependencies - # - Preserves comments and decorators - # - Generally performs this in a sane manner - cls.move_to_file(f'enums.py') - -# Rename a function and all its usages -old_function = codebase.get_function('process_data') -old_function.rename('process_resource') # Updates all references automatically - -# Change a function's signature -handler = codebase.get_function('event_handler') -handler.get_parameter('e').rename('event') # Automatically updates all call-sites -handler.add_parameter('timeout: int = 30') # Handles formatting and edge cases -handler.add_return_type('Response | None') - -# Perform surgery on call-sites -for fcall in handler.call_sites: - arg = fcall.get_arg_by_parameter_name('env') - # f(..., env={ data: x }) => f(..., env={ data: x or None }) - if isinstance(arg.value, Collection): - data_key = arg.value.get('data') - data_key.value.edit(f'{data_key.value} or None') -``` - - - When moving symbols, Codegen will automatically update all imports and - references. See [Moving Symbols](/building-with-codegen/moving-symbols) to - learn more. - - -## Leveraging Graph Relations - -Codegen's graph structure makes it easy to analyze relationships between code elements across files: - -```python -# Find dead code -for func in codebase.functions: - if len(func.usages) == 0: - print(f'πŸ—‘οΈ Dead code: {func.name}') - func.remove() - -# Analyze import relationships -file = codebase.get_file('api/endpoints.py') -print("\nFiles that import endpoints.py:") -for import_stmt in file.inbound_imports: - print(f" {import_stmt.file.path}") - -print("\nFiles that endpoints.py imports:") -for import_stmt in file.imports: - if import_stmt.resolved_symbol: - print(f" {import_stmt.resolved_symbol.file.path}") - -# Explore class hierarchies -base_class = codebase.get_class('BaseModel') -if base_class: - print(f"\nClasses that inherit from {base_class.name}:") - for subclass in base_class.subclasses: - print(f" {subclass.name}") - # We can go deeper in the inheritance tree - for sub_subclass in subclass.subclasses: - print(f" └─ {sub_subclass.name}") -``` - - - Learn more about [dependencies and - references](/building-with-codegen/dependencies-and-usages) or [imports](/building-with-codegen/imports) and [exports](/building-with-codegen/exports). - - -## Advanced Settings - -Codegen also supports a number of advanced settings that can be used to customize the behavior of the graph construction process. - -These flags are helpful for debugging problematic repos, optimizing Codegen’s performance, or testing unreleased or experimental (potentially backwards-breaking) features. - -```python -from codegen import Codebase -from codegen.configs import CodebaseConfig - -# Initialize a Codebase with custom configuration -codebase = Codebase( - "path/to/git/repo"", - config=CodebaseConfig( - verify_graph=True, - method_usages=False, - sync_enabled=True, - generics=False, - import_resolution_overrides={ - "old_module": "new_module" - }, - ts_language_engine=True, - v8_ts_engine=True - ) -) -``` - -To learn more about available settings, see the [Advanced Settings](/introduction/advanced-settings) page. - - -These are considered experimental and unstable features that may be removed or changed in the future. - - -## What's Next? - - - - Follow step-by-step tutorials for common code transformation tasks like - modernizing React codebases or migrating APIs. - - - Understand key concepts like working with files, functions, imports, and the - call graph to effectively manipulate code. - - - Iterate locally with your favorite IDE, work with a debugger and build sophisticated codemods - - - Learn how to use Codegen with Cursor, Devin, Windsurf, and more. - - - diff --git a/docs/graph-sitter/guiding-principles.mdx b/docs/graph-sitter/guiding-principles.mdx deleted file mode 100644 index 53201e5c1..000000000 --- a/docs/graph-sitter/guiding-principles.mdx +++ /dev/null @@ -1,75 +0,0 @@ ---- -title: "Guiding Principles" -sidebarTitle: "Principles" -icon: "compass" -iconType: "solid" ---- - -Codegen was developed by working backwards from real-world, large-scale codebase migrations. Instead of starting with abstract syntax trees and parser theory, we started with the question: "How do developers actually think about code changes?" - -This practical origin led to four core principles that shape Codegen's design: - -## Intuitive APIs - -Write code that reads like natural language, without worrying about abstract syntax trees or parser internals. Codegen provides high-level APIs that map directly to the transformations developers want to perform: - -```python -# Methods that read like English -function.rename("new_name") # Not ast.update_node(function_node, "name", "new_name") -function.move_to_file("new_file.py") # Not ast.relocate_node(function_node, "new_file.py") - -# Clean, readable properties -if function.is_async: # Not ast.get_node_attribute(function_node, "async") - print(function.name) # Not ast.get_node_name(function_node) - -# Natural iteration patterns -for usage in function.usages: # Not ast.find_references(function_node) - print(f"Used in {usage.file.name}") -``` - -## No Sharp Edges - -Focus on your high-level intent while Codegen handles the intricate details. - -Codegen operations handle the edge cases - it should be hard to break lint. - -```python -# Moving a function? Codegen handles: -function.move_to_file("new_file.py") -# βœ“ Updating all import statements -# βœ“ Preserving dependencies -# βœ“ Maintaining references -# βœ“ Fixing relative imports -# βœ“ Resolving naming conflicts - -# Renaming a symbol? Codegen manages: -class_def.rename("NewName") -# βœ“ Updating all usages -# βœ“ Handling string references -# βœ“ Preserving docstrings -# βœ“ Maintaining inheritance -``` - -## Performance through Pre-Computation - -Codegen frontloads as much as possible to enable fast, efficient transformations. - -It is built with the insight that each codebase only needs to be parsed once per commit. - - - Learn more about parsing the codebase graph in the [How it - Works](/introduction/how-it-works) guide. - - -## Python-First Composability - -Codegen embraces Python's strength as a "glue language" - its ability to seamlessly integrate different tools and APIs. This makes it natural to compose Codegen with your existing toolchain: - -- Build complex transforms by combining simpler operations -- Integrate Codegen with your existing tools (linters, type checkers, test frameworks, AI tools) - - - Python's rich ecosystem makes it ideal for code manipulation tasks. Codegen is - designed to be one tool in your toolbox, not a replacement for your entire - workflow. - diff --git a/docs/graph-sitter/how-it-works.mdx b/docs/graph-sitter/how-it-works.mdx deleted file mode 100644 index 8777a5be4..000000000 --- a/docs/graph-sitter/how-it-works.mdx +++ /dev/null @@ -1,89 +0,0 @@ ---- -title: "Under the Hood" -sidebarTitle: "How it Works" -icon: "gear" -iconType: "solid" -subtitle: "How Codegen's codebase graph works" ---- - -Codegen performs advanced static analysis to build a rich graph representation of your codebase. This pre-computation step analyzes dependencies, references, types, and control flow to enable fast and reliable code manipulation operations. - - - Codegen is built on top of - [Tree-sitter](https://tree-sitter.github.io/tree-sitter/) and - [rustworkx](https://github.com/Qiskit/rustworkx) and has implemented most - language server features from scratch. - - - Codegen is open source. Check out the [source - code](https://github.com/codegen-sh/codegen-sdk) to learn more! - - -## The Codebase Graph - -At the heart of Codegen is a comprehensive graph representation of your code. When you initialize a [Codebase](/api-reference/core/Codebase), it performs static analysis to construct a rich graph structure connecting code elements: - -```python -# Initialize and analyze the codebase -from codegen import Codebase -codebase = Codebase("./") - -# Access pre-computed relationships -function = codebase.get_symbol("process_data") -print(f"Dependencies: {function.dependencies}") # Instant lookup -print(f"Usages: {function.usages}") # No parsing needed -``` - -### Building the Graph - -Codegen's graph construction happens in two stages: - -1. **AST Parsing**: We use [Tree-sitter](https://tree-sitter.github.io/tree-sitter/) as our foundation for parsing code into Abstract Syntax Trees. Tree-sitter provides fast, reliable parsing across multiple languages. - -2. **Multi-file Graph Construction**: Custom parsing logic, implemented in [rustworkx](https://github.com/Qiskit/rustworkx) and Python, analyzes these ASTs to construct a more sophisticated graph structure. This graph captures relationships between [symbols](/building-with-codegen/symbol-api), [files](/building-with-codegen/files-and-directories), [imports](/building-with-codegen/imports), and more. - -### Performance Through Pre-computation - -Pre-computing a rich index enables Codegen to make certain operations very fast that that are relevant to refactors and code analysis: - -- Finding all usages of a symbol -- Detecting circular dependencies -- Analyzing the dependency graphs -- Tracing call graphs -- Static analysis-based code retrieval for RAG -- ...etc. - - - Pre-parsing the codebase enables constant-time lookups rather than requiring - re-parsing or real-time analysis. - - -## Multi-Language Support - -One of Codegen's core principles is that many programming tasks are fundamentally similar across languages. - -Currently, Codegen supports: - -- [Python](/api-reference/python) -- [TypeScript](/api-reference/typescript) -- [React & JSX](/building-with-codegen/react-and-jsx) - - - Learn about how Codegen handles language specifics in the [Language - Support](/building-with-codegen/language-support) guide. - - -We've started with these ecosystems but designed our architecture to be extensible. The graph-based approach provides a consistent interface across languages while handling language-specific details under the hood. - -## Build with Us - -Codegen is just getting started, and we're excited about the possibilities ahead. We enthusiastically welcome contributions from the community, whether it's: - -- Adding support for new languages -- Implementing new analysis capabilities -- Improving performance -- Expanding the API -- Adding new transformations -- Improving documentation - -Check out our [community guide](/introduction/community) to get involved! diff --git a/docs/graph-sitter/ide-usage.mdx b/docs/graph-sitter/ide-usage.mdx deleted file mode 100644 index 3c58d39ab..000000000 --- a/docs/graph-sitter/ide-usage.mdx +++ /dev/null @@ -1,178 +0,0 @@ ---- -title: "Using Codegen in Your IDE" -sidebarTitle: "IDE Usage" -icon: "window" -iconType: "solid" ---- - -Get up and running with Codegen programs in IDEs like VSCode, Cursor and PyCharm. - -Make sure to [install and initialize](/introduction/installation) Codegen with `codegen init` - -## Configuring your IDE Interpreter - -Codegen creates a custom Python environment in `.codegen/.venv`. Configure your IDE to use this environment for the best development experience. - - - - 1. Install the VSCode Python Extensions for LSP and debugging support. We recommend Python, Pylance and Python Debugger for the best experience. - - 2. Open the Command Palette (Cmd/Ctrl + Shift + P) - 3. Type "Python: Select Interpreter" - - 4. Choose "Enter interpreter path" - 5. Navigate to and select: - ```bash - .codegen/.venv/bin/python - ``` - - Alternatively, create a `.vscode/settings.json`: - ```json - { - "python.defaultInterpreterPath": "${workspaceFolder}/.codegen/.venv/bin/python", - "python.analysis.extraPaths": [ - "${workspaceFolder}/.codegen/.venv/lib/python3.12/site-packages" - ] - } - ``` - - - - 1. Open PyCharm Settings/Preferences - 2. Navigate to "Project > Python Interpreter" - 3. Click the gear icon βš™οΈ and select "Add" - 4. Choose "Existing Environment" - 5. Set interpreter path to: - ```bash - .codegen/.venv/bin/python - ``` - - - - - -## MCP Server Setup -This is an optional step but highly recommended if your IDE supports MCP support and you use AI Agents. -The MCP server is a local server that allows your AI Agent to interact with the Codegen specific tools, -it will allow an agent to: -- ask an expert to create a codemod -- improve a codemod -- get setup instructions - -### IDE Configuration -#### Cline -Add this to your cline_mcp_settings.json: -```json -{ - "mcpServers": { - "codegen-cli": { - "command": "uv", - "args": [ - "--directory", - "/codegen-sdk/src/codegen/cli/mcp", - "run", - "server.py" - ] - } - } -} -``` - - -#### Cursor: -Under the `Settings` > `Feature` > `MCP Servers` section, click "Add New MCP Server" and add the following: - -``` -Name: codegen-mcp -Type: Command -Command: uv --directory /codegen-sdk/src/codegen/cli/mcp run server.py -``` - - -## Index Codegen Docs -#### Cursor: -If you use Cursor you'll be able to configure the IDE to index the Codegen docs. To do so go to `Settings` > `Features` > `Docs` -and then click on `Add new docs`. We recommend using this url to index the API reference: -``` -https://docs.codegen.com/api-reference/index -``` - - -## Create a New Codemod - -Generate the boilerplate for a new code manipulation program using [codegen create](/cli/create): - -```bash -codegen create organize-types \ - -d "Move all TypeScript types to \ - into a centralized types.ts file" -``` - - - Passing in `-d --description` will get an LLM expert to compose an initial version for you. This requires a Github account registered on [codegen.sh](https://codegen.sh) - - -This will: -1. Create a new codemod in `.codegen/codemods/organize_types/` -2. Generate a custom `system-prompt.txt` based on your task -3. Set up the basic structure for your program - - -The generated codemod includes type hints and docstrings, making it easy to get IDE autocompletion and documentation. - - -## Iterating with Chat Assistants - -When you do `codegen init`, you will receive a [system prompt optimized for AI consumption](/introduction/work-with-ai) at `.codegen/codegen-system-prompt.txt`. - -If you reference this file in "chat" sessions with Copilot, Cursor, Cody, etc., the assistant will become fluent in Codegen. - - - - Collaborating with Cursor's assistant and the Codegen system prompt - - -In addition, when you [create](/cli/create) a codemod with "-d", Codegen generates an optimized system prompt in `.codegen/codemods/{name}/{name}-system-prompt.txt`. This prompt contains: -- Relevant Codegen API documentation -- Examples of relevant transformations -- Context about your specific task - - -You can also drag and drop the system prompt ([available here](/introduction/work-with-ai))file directly into chat windows like ChatGPT or Claude for standalone help. - - -## Running and Testing Codemods - -```bash -# Run => write changes to disk -codegen run organize-types - -# Reset changes on disk -codegen reset -``` - -You can also run the program directly via `.codegen/.venv/bin/python path/to/codemod.py` or via your editor's debugger - -## Viewing Changes - -We recommend viewing changes in your IDE's native diff editor. - - -## What's Next - - - - See real-world examples of codemods in action. - - - Learn about Codegen's core concepts and features - - diff --git a/docs/graph-sitter/installation.mdx b/docs/graph-sitter/installation.mdx deleted file mode 100644 index 41188c64b..000000000 --- a/docs/graph-sitter/installation.mdx +++ /dev/null @@ -1,125 +0,0 @@ ---- -title: "Installation" -sidebarTitle: "Installation" -icon: "download" -iconType: "solid" ---- - -Install and set up Codegen in your development environment. - -#### We currently support: -- Running Codegen in Python 3.12 - 3.13 (recommended: Python 3.13+) -- macOS and Linux - - macOS is supported - - Linux is supported on x86_64 and aarch64 with glibc 2.34+ - - Windows is supported via WSL. See [here](https://docs.codegen.com/building-with-codegen/codegen-with-wsl) for more details. -- Python, Typescript, Javascript and React codebases - -## Prerequisites - -We recommend using [uv](https://github.com/astral-sh/uv) for installation. If you haven't installed `uv` yet: -```bash -curl -LsSf https://astral.sh/uv/install.sh | sh -``` - -## Installing Codegen - -```bash -uv tool install codegen --python 3.13 -``` - - - -This makes the `codegen` command available globally in your terminal, while keeping its dependencies isolated. - - -## Quick Start - -Let's walk through a minimal example of using Codegen in a project: - -1. Navigate to your repository: - ```bash - cd path/to/your/project - ``` - -2. Initialize Codegen in your project with [codegen init](/cli/init): - ```bash - codegen init - ``` - - This creates a `.codegen/` directory with: - ```bash - .codegen/ - β”œβ”€β”€ .venv/ # Python virtual environment (gitignored) - β”œβ”€β”€ config.toml # Project configuration - β”œβ”€β”€ codemods/ # Your codemod implementations - β”œβ”€β”€ jupyter/ # Jupyter notebooks for exploration - └── codegen-system-prompt.txt # AI system prompt - ``` - -3. Create your first codemod with [codegen create](/cli/create): - ```bash - codegen create organize-imports \ - -d "Sort and organize imports according to PEP8" - ``` - - The `-d` flag in `codegen create` generates an AI-powered implementation. This requires a Github account registered on [codegen.sh](https://codegen.sh) - - - - -4. Run your codemod with [codegen run](/cli/run): - ```bash - codegen run organize-imports - ``` - -5. Reset any filesystem changes (excluding `.codegen/*`) with [codegen reset](/cli/reset): - ```bash - codegen reset - ``` - -## Troubleshooting - -Having issues? Here are some common problems and their solutions: - -- **I'm hitting an UV error related to `[[ packages ]]`**: This means you're likely using an outdated version of UV. Try updating to the latest version with: `uv self update`. -- **I'm hitting an error about `No module named 'codegen.sdk.extensions.utils'`**: The compiled cython extensions are out of sync. Update them with `uv sync --reinstall-package codegen`. -- **I'm hitting a `RecursionError: maximum recursion depth exceeded` error while parsing my codebase**: If you are using python 3.12, try upgrading to 3.13. If you are already on 3.13, try upping the recursion limit with `sys.setrecursionlimit(10000)`. - - -For more help, join our [community Slack](/introduction/community) or check the [FAQ](/introduction/faq). - - -## Next Steps - - - - Learn how to use Codegen effectively in VSCode, Cursor, and other IDEs. - - - Follow step-by-step tutorials for common code transformation tasks. - - - Leverage AI assistants like Copilot, Cursor and Devin - - - Learn more about building with Codegen - - - diff --git a/docs/graph-sitter/overview.mdx b/docs/graph-sitter/overview.mdx deleted file mode 100644 index 4d428fc71..000000000 --- a/docs/graph-sitter/overview.mdx +++ /dev/null @@ -1,159 +0,0 @@ ---- -title: "Codegen" -sidebarTitle: "Overview" -icon: "code" -iconType: "solid" ---- - -[Codegen](https://github.com/codegen-sh/codegen-sdk) is a python library for manipulating codebases. - -It provides a scriptable interface to a powerful, multi-lingual language server built on top of [Tree-sitter](https://tree-sitter.github.io/tree-sitter/). - -```python -from codegen import Codebase - -# Codegen builds a complete graph connecting -# functions, classes, imports and their relationships -codebase = Codebase("./") - -# Work with code without dealing with syntax trees or parsing -for function in codebase.functions: - # Comprehensive static analysis for references, dependencies, etc. - if not function.usages: - # Auto-handles references and imports to maintain correctness - function.remove() - -# Fast, in-memory code index -codebase.commit() -``` - - - -Codegen handles complex refactors while maintaining correctness, enabling a broad set of advanced code manipulation programs. - - -Codegen works with both Python and Typescript/JSX codebases. Learn more about language support [here](/building-with-codegen/language-support). - -## Quick Started - - -Codegen requires Python 3.12 - 3.13 (recommended: Python 3.13+). - - -### Using UV (Recommended) -```bash -uv tool install codegen --python 3.13 -``` - -### Using Pipx - - -Pipx is not officially supported by Codegen, but it should still work. - - -```bash -pipx install codegen -``` - - -For further & more in depth installation instructions, see the [installation guide](/introduction/installation). - - -## What can I do with Codegen? - -Codegen's simple yet powerful APIs enable a range of applications, including: - - - - Create an intelligent agent that can analyze and manipulate your codebase using natural language. - - - Generate interactive visualizations of your codebase's structure, dependencies, and relationships. - - - Create high-quality training data for fine-tuning LLMs on your codebase. - - - Create powerful code transformations to automate large-scale changes. - - - -See below for an example call graph visualization generated with Codegen. - - - - - -View source code on [modal/modal-client](https://github.com/modal-labs/modal-client/blob/cbac0d80dfd98588027ecd21850152776be3ab82/modal/client.py#L70). View codemod on [codegen.sh](https://www.codegen.sh/codemod/66e2e195-ceec-4935-876a-ed4cfc1731c7/public/diff) - - -## Get Started - -import { - COMMUNITY_SLACK_URL, - CODEGEN_SDK_GITHUB_URL, -} from "/snippets/links.mdx"; - - - - Follow our step-by-step tutorial to start manipulating code with Codegen. - - - Learn how to use Codegen for common code transformation tasks. - - - Star us on GitHub and contribute to the project. - - - Get help and connect with the Codegen community. - - - -## Why Codegen? - -Many software engineering tasks - refactors, enforcing patterns, analyzing control flow, etc. - are fundamentally programmatic operations. Yet the tools we use to express these transformations often feel disconnected from how we think about code. - -Codegen was engineered backwards from real-world refactors we performed for enterprises at [Codegen, Inc.](/introduction/about). Instead of starting with theoretical abstractions, we built the set of APIs that map directly to how humans and AI think about code changes: - -- **Natural Mental Model**: Express transformations through high-level operations that match how you reason about code changes, not low-level text or AST manipulation. -- **Clean Business Logic**: Let the engine handle the complexities of imports, references, and cross-file dependencies. -- **Scale with Confidence**: Make sweeping changes across large codebases consistently across Python, TypeScript, JavaScript, and React. - -As AI becomes increasingly sophisticated, we're seeing a fascinating shift: AI agents aren't bottlenecked by their ability to understand code or generate solutions. Instead, they're limited by their ability to efficiently manipulate codebases. The challenge isn't the "brain" - it's the "hands." - -We built Codegen with a key insight: future AI agents will need to ["act via code,"](/blog/act-via-code) building their own sophisticated tools for code manipulation. Rather than generating diffs or making direct text changes, these agents will: - -1. Express transformations as composable programs -2. Build higher-level tools by combining primitive operations -3. Create and maintain their own abstractions for common patterns - -This creates a shared language that both humans and AI can reason about effectively, making code changes more predictable, reviewable, and maintainable. Whether you're a developer writing a complex refactoring script or an AI agent building transformation tools, Codegen provides the foundation for expressing code changes as they should be: through code itself. diff --git a/docs/graph-sitter/work-with-ai.mdx b/docs/graph-sitter/work-with-ai.mdx deleted file mode 100644 index c826aad75..000000000 --- a/docs/graph-sitter/work-with-ai.mdx +++ /dev/null @@ -1,86 +0,0 @@ ---- -title: "Working with AI" -sidebarTitle: "AI Integration" -icon: "microchip" -iconType: "solid" ---- - -Codegen is designed to be used with AI assistants. This document describes how to use Codegen with common AI tools, including Copilot, Cursor, Devin and more. - -## System Prompt - -Codegen provides a `.txt` file that you can drag-and-drop into any chat assistant. This is roughly 60k tokens and will enable chat assistants like, ChatGPT, Claude 3.5 etc. to build effectively with Codegen. - -import { - CODEGEN_SYSTEM_PROMPT -} from "/snippets/links.mdx"; - - - Download System Prompt - - -Learn about leveraging this in IDE chat assistants like Cursor [here](/introduction/ide-usage#iterating-with-chat-assistants) - -## Generating System Prompts - -The [Codegen CLI](/cli/about) provides commands to generate `.md` files that can be fed to any AI assistant for more accurate and contextual help. - -When you create a new codemod via [codegen create](/cli/create): - -```bash -codegen create delete-dead-imports . --description "Delete unused imports" -``` - -Codegen automatically generates an optimized ["system prompt"](https://news.ycombinator.com/item?id=37880023) that includes: - -- An introduction to Codegen -- Codegen API documentation -- Examples of relevant transformations - -You can find this generated prompt in the `.codegen/prompts/-system-prompt.md` file. - - - All contents of the `.codegen/prompts` directory are by default ignored the - `.gitignore` file. after running [codegen init](/cli/init) - - -This `.md` file can be used with any AI assistant (Claude, GPT-4, etc.) to get more accurate and contextual help. - -## Example Workflow - - - - Use the [create command](/cli/create) with a detailed description of what you want to accomplish: - ```bash - codegen create modernize-components . --description "Convert class components to functional components with hooks" - ``` - - - Check the AI context that Codegen generated for your transformation: ```bash - cat codegen-sh/codemods/modernize-components/prompt.md ``` - - - - Reference your codemod when asking questions to get contextual help: ``` - @codegen-sh/codemods/modernize-components How should I handle - componentDidMount? ``` - - - - The AI will understand you're working on React modernization and provide relevant suggestions about using useEffect hooks and other modern React patterns. - - - -## Copilot, Cursor and Windsurf (IDEs) - -When using IDE chat assistants, you can leverage Codegen's context by mentioning your codemod in composer mode: - -```bash -@.codegen/codemods/upgrade-react18 @.codegen/prompts/system-prompt.md -``` - -This will ensure that the IDE's native chat model is aware of the APIs and common patterns for Codegen. - -## Devin, OpenHands and Semi-autonomous Code Agents - -Coming soon! diff --git a/docs/integrations/mcp.mdx b/docs/integrations/mcp.mdx index 05057486d..d6b6a225e 100644 --- a/docs/integrations/mcp.mdx +++ b/docs/integrations/mcp.mdx @@ -1,6 +1,7 @@ --- title: "MCP Server" description: "Connect AI agents to Codegen using the Model Context Protocol (MCP) server" +icon: "server" --- The Codegen MCP server enables AI agents to interact with the Codegen platform through the Model Context Protocol (MCP). This integration allows AI agents to access Codegen APIs, manage agent runs, and interact with your development workflow. @@ -8,6 +9,7 @@ The Codegen MCP server enables AI agents to interact with the Codegen platform t ## Overview The MCP server provides: + - **API Integration**: Direct access to Codegen platform APIs - **Agent Management**: Create and monitor agent runs - **Organization Management**: Access organization and user information @@ -125,11 +127,13 @@ The MCP server provides the following tools for AI agents: The MCP server supports two transport methods: ### stdio (Default) + - Best for most AI agents and IDE integrations - Direct communication through standard input/output - No network configuration required ### HTTP + - Useful for web-based integrations - Requires specifying host and port - Currently falls back to stdio (HTTP support coming soon) @@ -149,16 +153,19 @@ export CODEGEN_API_KEY="your-api-key-here" ### Common Issues **Server won't start** + - Ensure the Codegen CLI is properly installed - Check that your API key is set correctly - Verify network connectivity to the Codegen API **Authentication errors** + - Verify your API key is valid and not expired - Check that the API key has the necessary permissions - Ensure the `CODEGEN_API_KEY` environment variable is set **Connection issues** + - For stdio transport, ensure your AI agent supports MCP - For HTTP transport, check firewall settings and port availability - Verify the host and port configuration diff --git a/docs/use-cases/I. Upgrading APIs.md b/docs/use-cases/I. Upgrading APIs.md deleted file mode 100644 index e69de29bb..000000000 diff --git a/docs/use-cases/II. Improving Codebase Modularity.md b/docs/use-cases/II. Improving Codebase Modularity.md deleted file mode 100644 index e69de29bb..000000000 diff --git a/docs/use-cases/III. Improving Type Coverage.md b/docs/use-cases/III. Improving Type Coverage.md deleted file mode 100644 index e69de29bb..000000000 diff --git a/docs/use-cases/IV. Analyzing Critical Code Paths.md b/docs/use-cases/IV. Analyzing Critical Code Paths.md deleted file mode 100644 index e69de29bb..000000000