Skip to content

fix(vscode): update relative imports when moving or renaming flow files (#112) - #299

Open
heroking777 wants to merge 1 commit into
flydelabs:mainfrom
heroking777:wf-trial/flyde-112
Open

heroking777 wants to merge 1 commit into
flydelabs:mainfrom
heroking777:wf-trial/flyde-112

Conversation

@heroking777

Copy link
Copy Markdown

Summary

When files or folders containing Flyde flows (.flyde) or custom code nodes (.flyde.ts, .flyde.js) are moved or renamed in VS Code, existing relative imports and file-sourced node instances break because their paths still point to the previous locations.

This PR implements an automatic path updater in the VS Code extension:

  • Subscribes to vscode.workspace.onDidRenameFiles in vscode/src/extension.ts.
  • Traverses all .flyde files across the workspace.
  • Deserializes and inspects node instance file sources (source.type === "file", including nested inline flows) as well as the flow's imports map.
  • Calculates and updates relative paths accurately using POSIX path formatting when:
    1. An imported code node or visual subflow file is moved or renamed.
    2. The parent directory of an imported file is moved or renamed.
    3. The .flyde flow file itself is moved to a different folder.
  • Replaces document contents via vscode.WorkspaceEdit and saves non-dirty open documents cleanly.
  • Leaves external packages (@flyde/nodes, npm packages) and URL sources untouched.

Testing & Verification

  1. Unit tests added in vscode/src/updateImportsOnMove.pure.test.ts:
    • updates file-sourced instance when an imported node file is moved: verified child instance relative path update.
    • updates relative file imports when the flow file itself is moved: verified parent relocation updating relative child path while keeping package sources intact.
    • computes updated relative import across directory moves: verified directory rename rebasing.
    • leaves package and external sources untouched: verified non-file sources remain unchanged.
    • Ran npx mocha -r ts-node/register src/updateImportsOnMove.pure.test.ts --ui tdd -> 4 passing (8ms).
  2. Verified TypeScript compilation:
    • npx pnpm --dir vscode run compile -> Passed cleanly with 0 errors.
    • Verified compiled test execution: npx mocha out/updateImportsOnMove.pure.test.js --ui tdd -> 4 passing (7ms).

Fixes #112
/claim #112

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Broken imports after moving files

1 participant