Add point-and-click Insert from local project files (#6129)
* WIP: Add point-and-click Import for geometry Will eventually fix #6120 Right now the whole loop is there but the codemod doesn't work yet * Better pathToNOde, log on non-working cm dispatch call * Add workaround to updateModelingState not working * Back to updateModelingState with a skip flag * Better todo * Change working from Import to Insert, cleanups * Sister command in kclCommands to populate file options * Improve path selector * Unsure: move importAstMod to kclCommands onSubmit 😶 * Add e2e test * Clean up for review * Add native file menu entry and test * No await yo lint said so * @lrev-Dev's suggestion to remove a comment Co-authored-by: Kurt Hutten <k.hutten@protonmail.ch> * Update to scene.settled(cmdBar) * Lint --------- Co-authored-by: Kurt Hutten <k.hutten@protonmail.ch>
This commit is contained in:
@ -1,7 +1,11 @@
|
||||
import type { ImportStatement } from '@rust/kcl-lib/bindings/ImportStatement'
|
||||
import type { Name } from '@rust/kcl-lib/bindings/Name'
|
||||
import type { Node } from '@rust/kcl-lib/bindings/Node'
|
||||
import type { TagDeclarator } from '@rust/kcl-lib/bindings/TagDeclarator'
|
||||
|
||||
import type { ImportPath } from '@rust/kcl-lib/bindings/ImportPath'
|
||||
import type { ImportSelector } from '@rust/kcl-lib/bindings/ImportSelector'
|
||||
import type { ItemVisibility } from '@rust/kcl-lib/bindings/ItemVisibility'
|
||||
import { ARG_TAG } from '@src/lang/constants'
|
||||
import { getNodeFromPath } from '@src/lang/queryAst'
|
||||
import { getNodePathFromSourceRange } from '@src/lang/queryAstNodePathUtils'
|
||||
@ -12,6 +16,7 @@ import type {
|
||||
CallExpression,
|
||||
CallExpressionKw,
|
||||
Expr,
|
||||
ExpressionStatement,
|
||||
Identifier,
|
||||
LabeledArg,
|
||||
Literal,
|
||||
@ -333,6 +338,44 @@ export function createBinaryExpressionWithUnary([left, right]: [
|
||||
return createBinaryExpression([left, '+', right])
|
||||
}
|
||||
|
||||
export function createImportAsSelector(name: string): ImportSelector {
|
||||
return { type: 'None', alias: createIdentifier(name) }
|
||||
}
|
||||
|
||||
export function createImportStatement(
|
||||
selector: ImportSelector,
|
||||
path: ImportPath,
|
||||
visibility: ItemVisibility = 'default'
|
||||
): Node<ImportStatement> {
|
||||
return {
|
||||
type: 'ImportStatement',
|
||||
start: 0,
|
||||
end: 0,
|
||||
moduleId: 0,
|
||||
outerAttrs: [],
|
||||
preComments: [],
|
||||
commentStart: 0,
|
||||
selector,
|
||||
path,
|
||||
visibility,
|
||||
}
|
||||
}
|
||||
|
||||
export function createExpressionStatement(
|
||||
expression: Expr
|
||||
): Node<ExpressionStatement> {
|
||||
return {
|
||||
type: 'ExpressionStatement',
|
||||
start: 0,
|
||||
end: 0,
|
||||
moduleId: 0,
|
||||
outerAttrs: [],
|
||||
preComments: [],
|
||||
commentStart: 0,
|
||||
expression,
|
||||
}
|
||||
}
|
||||
|
||||
export function findUniqueName(
|
||||
ast: Program | string,
|
||||
name: string,
|
||||
|
||||
Reference in New Issue
Block a user