Skip to content

fix: update import paths when .flyde files are moved or renamed#256

Open
maoshuorz wants to merge 1 commit intoflydelabs:mainfrom
maoshuorz:fix/update-imports-on-file-move
Open

fix: update import paths when .flyde files are moved or renamed#256
maoshuorz wants to merge 1 commit intoflydelabs:mainfrom
maoshuorz:fix/update-imports-on-file-move

Conversation

@maoshuorz
Copy link

Summary

Fixes #112 — broken imports after moving files.

/claim #112

When a .flyde or .flyde.ts file is moved or renamed in VS Code, all .flyde files that reference it via source.type: "file" now have their relative paths automatically updated to point to the new location.

Problem

When a user creates a flow that imports another .flyde file (e.g., ./ChildFlow.flyde) and then moves that imported file to a different folder, the import path breaks because the relative path stored in source.data is no longer valid.

Solution

Added a workspace.onDidRenameFiles handler in the VS Code extension (updateImportsOnFileMove.ts) that intercepts file move/rename events and automatically updates import paths in all affected .flyde files.

Three scenarios handled:

  1. Imported file is moved — All .flyde files referencing the moved file get their source.data paths recalculated relative to the new location.

  2. Flow file itself is moved to a different directory — Its internal source.type: "file" references are recalculated relative to the new directory.

  3. Both files move simultaneously — The handler cross-references the rename list so paths resolve correctly even when multiple related files are moved at once.

Implementation details:

  • Listens to workspace.onDidRenameFiles (fires after the move completes)
  • Only processes moves of .flyde and .flyde.ts files
  • Parses affected flows with the yaml library (already a dependency via @flyde/loader)
  • Handles inline visual nodes recursively
  • Uses POSIX-style relative paths (e.g., ./subfolder/Child.flyde) matching the existing convention
  • Shows an info message when paths are updated so the user knows what changed

Files changed

  • vscode/src/updateImportsOnFileMove.ts — New file with the import update logic
  • vscode/src/extension.ts — Registers the handler on extension activation

Test plan

  • Create Parent.flyde that imports ./Child.flyde via source: { type: file, data: ./Child.flyde }
  • Move Child.flyde to a subfolder — verify Parent.flyde updates to ./subfolder/Child.flyde
  • Move Parent.flyde to a subfolder — verify its reference updates relative to new location
  • Move a .flyde.ts code node file — verify referencing flows update
  • Move unrelated files — verify no .flyde files are modified

When a .flyde or .flyde.ts file is moved/renamed in VS Code, all other
.flyde files that reference it via source.type "file" now have their
relative paths automatically updated to point to the new location.

This handles three scenarios:
1. An imported file is moved — all referencing flows are updated
2. A flow file itself is moved — its internal file references are
   recalculated relative to the new location
3. Both imported and importing files move simultaneously — paths are
   resolved correctly using the new locations

Fixes flydelabs#112
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Broken imports after moving files

1 participant