Skip to content

fix(vscode): rewrite .flyde imports on file rename/move (#112)#266

Open
dukunline-cyber wants to merge 1 commit into
flydelabs:mainfrom
dukunline-cyber:fix/112-rewrite-imports-on-file-move
Open

fix(vscode): rewrite .flyde imports on file rename/move (#112)#266
dukunline-cyber wants to merge 1 commit into
flydelabs:mainfrom
dukunline-cyber:fix/112-rewrite-imports-on-file-move

Conversation

@dukunline-cyber
Copy link
Copy Markdown

@dukunline-cyber dukunline-cyber commented May 16, 2026

/claim #112

Closes #112.

Problem

When a file referenced by a .flyde flow is moved to a different folder (or when a .flyde flow itself is moved), the relative path stored in source: { type: file, data: ... } breaks and the import fails to resolve.

Reproduction matches the issue body: create a flow, import another flow, move either file -> import is broken until manually edited.

Fix

New module vscode/src/flydeImportRewriter.ts registers a vscode.workspace.onDidRenameFiles listener that handles both directions:

  1. Moved file IS a .flyde flow -> rewrite each data: value inside the moved flow so the relative path resolves to the same absolute target it pointed at before the move.
  2. Moved file is an IMPORTED target -> walk all .flyde files in the workspace (excluding node_modules) and rewrite any data: value whose resolved absolute path matches the old location.

The rewriter:

  • Operates only on source blocks where type: file (leaves package and inline sources untouched).
  • Edits only the data: line, preserving indentation, quoting style, and surrounding YAML so diffs stay minimal and YAML-valid.
  • Uses POSIX-style ./relative paths to match the existing convention in the repo's sample flows.
  • Is case-insensitive on win32 paths.
  • Wraps every rewrite in try/catch so a single corrupt flow file can never crash the listener.

Wired up via 4-line patch in vscode/src/extension.ts (one import + one call inside activate).

Diff stats

  • vscode/src/flydeImportRewriter.ts - new file, 176 lines
  • vscode/src/extension.ts - +4 lines

Verification notes

  • VSCode's onDidRenameFiles fires for both single-file renames and folder moves (folder moves emit one event per descendant), so folder-level reorganization is covered.
  • The YAML walker is line-based and indentation-aware, so it tolerates the existing flow files in website/playground-examples/* and test-fixtures/.
  • Listener is disposed automatically because the subscription is pushed onto context.subscriptions.

Happy to add unit tests around mutateFileSourceData if the maintainers want a follow-up.

Closes flydelabs#112. Hooks into vscode.workspace.onDidRenameFiles and updates relative `source: { type: file, data: ... }` paths inside .flyde flow files so imports keep resolving after files are moved or renamed. Handles both directions: a .flyde flow being moved (rewrite its own imports relative to the new location) and an imported target being moved (walk all .flyde flows in the workspace and update references).
@dukunline-cyber
Copy link
Copy Markdown
Author

/claim #112

@dukunline-cyber
Copy link
Copy Markdown
Author

Hi, just checking in — any feedback on this PR? Happy to address any changes needed.

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