Skip to content

Commit de7f33a

Browse files
committed
docs: updated API reference
1 parent e7c28b6 commit de7f33a

File tree

4 files changed

+199
-249
lines changed

4 files changed

+199
-249
lines changed

docs/api-reference/core/SourceFile.mdx

Lines changed: 29 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx';
1111
import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx';
1212
import {Attribute} from '/snippets/Attribute.mdx';
1313

14-
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/file.py#L412-L1168" />
14+
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/file.py#L412-L1162" />
1515

1616
### Inherits from
1717
[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)
@@ -184,26 +184,44 @@ Adds a decorator to a function or method.
184184
<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="True if the decorator was added, False if skipped."/>
185185

186186

187-
### <span className="text-primary">add_import_from_import_string</span>
188-
Adds import to the file from a string representation of an import statement.
189-
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/file.py#L977-L1001" />
187+
### <span className="text-primary">add_import</span>
188+
Adds an import to the file.
189+
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/file.py#L947-L995" />
190190

191191
<ParameterWrapper>
192192
<Parameter
193-
name="import_string"
194-
type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> }
195-
description="The string representation of the import statement to add."
193+
name="imp"
194+
type={ <><a href="/api-reference/core/Symbol" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Symbol</a> <span>| str</span></> }
195+
description="Either a Symbol to import or a string representation of an import statement."
196196
defaultValue=""
197197
/>
198+
<Parameter
199+
name="alias"
200+
type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str | None</code> }
201+
description="Optional alias for the imported symbol. Only used when imp is a Symbol. Defaults to None."
202+
defaultValue="None"
203+
/>
204+
<Parameter
205+
name="import_type"
206+
type={ <><a href="/api-reference/core/ImportType" style={ {fontWeight: "inherit", fontSize: "inherit"} }>ImportType</a></> }
207+
description="The type of import to use. Only used when imp is a Symbol. Defaults to ImportType.UNKNOWN."
208+
defaultValue="ImportType.UNKNOWN"
209+
/>
210+
<Parameter
211+
name="is_type_import"
212+
type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> }
213+
description="Whether this is a type-only import. Only used when imp is a Symbol. Defaults to False."
214+
defaultValue="False"
215+
/>
198216
</ParameterWrapper>
199217

200218

201-
<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description=""/>
219+
<Return return_type={ <><a href="/api-reference/core/Import" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Import</a> <span>| None</span></> } description="The existing import for the symbol if found, otherwise None."/>
202220

203221

204222
### <span className="text-primary">add_symbol</span>
205223
Adds `symbol` to the file.
206-
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/file.py#L1024-L1055" />
224+
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/file.py#L1018-L1049" />
207225

208226
<ParameterWrapper>
209227
<Parameter
@@ -226,7 +244,7 @@ Adds `symbol` to the file.
226244

227245
### <span className="text-primary">add_symbol_from_source</span>
228246
Adds a symbol to a file from a string representation.
229-
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/file.py#L1004-L1021" />
247+
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/file.py#L998-L1015" />
230248

231249
<ParameterWrapper>
232250
<Parameter
@@ -241,41 +259,6 @@ Adds a symbol to a file from a string representation.
241259
<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description="The symbol is added directly to the file's content."/>
242260

243261

244-
### <span className="text-primary">add_symbol_import</span>
245-
Adds an import to a file for a given symbol.
246-
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/file.py#L947-L974" />
247-
248-
<ParameterWrapper>
249-
<Parameter
250-
name="symbol"
251-
type={ <><a href="/api-reference/core/Symbol" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Symbol</a></> }
252-
description="The symbol to import."
253-
defaultValue=""
254-
/>
255-
<Parameter
256-
name="alias"
257-
type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str | None</code> }
258-
description="Optional alias for the imported symbol. Defaults to None."
259-
defaultValue="None"
260-
/>
261-
<Parameter
262-
name="import_type"
263-
type={ <><a href="/api-reference/core/ImportType" style={ {fontWeight: "inherit", fontSize: "inherit"} }>ImportType</a></> }
264-
description="The type of import to use. Defaults to ImportType.UNKNOWN."
265-
defaultValue="ImportType.UNKNOWN"
266-
/>
267-
<Parameter
268-
name="is_type_import"
269-
type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> }
270-
description="Whether this is a type-only import. Defaults to False."
271-
defaultValue="False"
272-
/>
273-
</ParameterWrapper>
274-
275-
276-
<Return return_type={ <><a href="/api-reference/core/Import" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Import</a> <span>| None</span></> } description="The existing import for the symbol or None if it was added."/>
277-
278-
279262
### <span className="text-primary">ancestors</span>
280263
Find all ancestors of the node of the given type. Does not return itself
281264
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/interfaces/editable.py#L1109-L1117" />
@@ -367,7 +350,7 @@ Find and return matching nodes or substrings within an Editable instance.
367350

368351
### <span className="text-primary">find_by_byte_range</span>
369352
Finds all editable objects that overlap with the given byte range in the file.
370-
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/file.py#L1151-L1163" />
353+
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/file.py#L1145-L1157" />
371354

372355
<ParameterWrapper>
373356
<Parameter

docs/api-reference/python/PyFile.mdx

Lines changed: 33 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {HorizontalDivider} from '/snippets/HorizontalDivider.mdx';
1111
import {GithubLinkNote} from '/snippets/GithubLinkNote.mdx';
1212
import {Attribute} from '/snippets/Attribute.mdx';
1313

14-
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/python/file.py#L28-L246" />
14+
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/python/file.py#L29-L276" />
1515

1616
### Inherits from
1717
[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)
@@ -188,26 +188,44 @@ Adds a decorator to a function or method.
188188
<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="True if the decorator was added, False if skipped."/>
189189

190190

191-
### <span className="text-primary">add_import_from_import_string</span>
192-
Adds an import statement to the file from a string representation.
193-
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/python/file.py#L149-L169" />
191+
### <span className="text-primary">add_import</span>
192+
Adds an import to the file.
193+
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/python/file.py#L150-L199" />
194194

195195
<ParameterWrapper>
196196
<Parameter
197-
name="import_string"
198-
type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> }
199-
description="The string representation of the import statement to add (e.g., 'from module import symbol')."
197+
name="imp"
198+
type={ <><a href="/api-reference/python/PySymbol" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PySymbol</a> <span>| str</span></> }
199+
description="Either a Symbol to import or a string representation of an import statement."
200200
defaultValue=""
201201
/>
202+
<Parameter
203+
name="alias"
204+
type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str | None</code> }
205+
description="Optional alias for the imported symbol. Only used when imp is a Symbol. Defaults to None."
206+
defaultValue="None"
207+
/>
208+
<Parameter
209+
name="import_type"
210+
type={ <><a href="/api-reference/core/ImportType" style={ {fontWeight: "inherit", fontSize: "inherit"} }>ImportType</a></> }
211+
description="The type of import to use. Only used when imp is a Symbol. Defaults to ImportType.UNKNOWN."
212+
defaultValue="ImportType.UNKNOWN"
213+
/>
214+
<Parameter
215+
name="is_type_import"
216+
type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> }
217+
description="Whether this is a type-only import. Only used when imp is a Symbol. Defaults to False."
218+
defaultValue="False"
219+
/>
202220
</ParameterWrapper>
203221

204222

205-
<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description="This function modifies the file in place."/>
223+
<Return return_type={ <><a href="/api-reference/python/PyImport" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyImport</a> <span>| None</span></> } description="The existing import for the symbol if found, otherwise None."/>
206224

207225

208226
### <span className="text-primary">add_symbol</span>
209227
Adds `symbol` to the file.
210-
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/file.py#L1024-L1055" />
228+
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/file.py#L1018-L1049" />
211229

212230
<ParameterWrapper>
213231
<Parameter
@@ -230,7 +248,7 @@ Adds `symbol` to the file.
230248

231249
### <span className="text-primary">add_symbol_from_source</span>
232250
Adds a symbol to a file from a string representation.
233-
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/file.py#L1004-L1021" />
251+
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/file.py#L998-L1015" />
234252

235253
<ParameterWrapper>
236254
<Parameter
@@ -245,41 +263,6 @@ Adds a symbol to a file from a string representation.
245263
<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description="The symbol is added directly to the file's content."/>
246264

247265

248-
### <span className="text-primary">add_symbol_import</span>
249-
Adds an import to a file for a given symbol.
250-
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/file.py#L947-L974" />
251-
252-
<ParameterWrapper>
253-
<Parameter
254-
name="symbol"
255-
type={ <><a href="/api-reference/python/PySymbol" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PySymbol</a></> }
256-
description="The symbol to import."
257-
defaultValue=""
258-
/>
259-
<Parameter
260-
name="alias"
261-
type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str | None</code> }
262-
description="Optional alias for the imported symbol. Defaults to None."
263-
defaultValue="None"
264-
/>
265-
<Parameter
266-
name="import_type"
267-
type={ <><a href="/api-reference/core/ImportType" style={ {fontWeight: "inherit", fontSize: "inherit"} }>ImportType</a></> }
268-
description="The type of import to use. Defaults to ImportType.UNKNOWN."
269-
defaultValue="ImportType.UNKNOWN"
270-
/>
271-
<Parameter
272-
name="is_type_import"
273-
type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> }
274-
description="Whether this is a type-only import. Defaults to False."
275-
defaultValue="False"
276-
/>
277-
</ParameterWrapper>
278-
279-
280-
<Return return_type={ <><a href="/api-reference/python/PyImport" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyImport</a> <span>| None</span></> } description="The existing import for the symbol or None if it was added."/>
281-
282-
283266
### <span className="text-primary">ancestors</span>
284267
Find all ancestors of the node of the given type. Does not return itself
285268
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/interfaces/editable.py#L1109-L1117" />
@@ -371,7 +354,7 @@ Find and return matching nodes or substrings within an Editable instance.
371354

372355
### <span className="text-primary">find_by_byte_range</span>
373356
Finds all editable objects that overlap with the given byte range in the file.
374-
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/file.py#L1151-L1163" />
357+
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/core/file.py#L1145-L1157" />
375358

376359
<ParameterWrapper>
377360
<Parameter
@@ -436,7 +419,7 @@ Returns a specific Class by full name. Returns None if not found.
436419

437420
### <span className="text-primary">get_extensions</span>
438421
Returns the file extensions associated with Python files.
439-
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/python/file.py#L38-L46" />
422+
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/python/file.py#L39-L47" />
440423

441424

442425
<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">list[str]</code> } description="A list containing '.py' as the only Python file extension."/>
@@ -495,7 +478,7 @@ Returns the import with matching alias. Returns None if not found.
495478

496479
### <span className="text-primary">get_import_insert_index</span>
497480
Determines the index position where a new import statement should be inserted in a Python file.
498-
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/python/file.py#L116-L142" />
481+
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/python/file.py#L117-L143" />
499482

500483
<ParameterWrapper>
501484
<Parameter
@@ -512,7 +495,7 @@ Determines the index position where a new import statement should be inserted in
512495

513496
### <span className="text-primary">get_import_string</span>
514497
Generates an import string for a symbol.
515-
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/python/file.py#L85-L113" />
498+
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/python/file.py#L86-L114" />
516499

517500
<ParameterWrapper>
518501
<Parameter
@@ -879,7 +862,7 @@ Sets the name of a code element.
879862

880863
### <span className="text-primary">symbol_can_be_added</span>
881864
Checks if a Python symbol can be added to this Python source file.
882-
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/python/file.py#L48-L59" />
865+
<GithubLinkNote link="https://github.com/codegen-sh/codegen-sdk/blob/develop/src/codegen/sdk/python/file.py#L49-L60" />
883866

884867
<ParameterWrapper>
885868
<Parameter

0 commit comments

Comments
 (0)