Skip to content

Add REVERSE_RELATIVE_FILEPATH snippet variable and expand cross-platform/remote/out-of-workspace test coverage#315155

Draft
Copilot wants to merge 8 commits intomainfrom
copilot/add-reverse-relative-variable
Draft

Add REVERSE_RELATIVE_FILEPATH snippet variable and expand cross-platform/remote/out-of-workspace test coverage#315155
Copilot wants to merge 8 commits intomainfrom
copilot/add-reverse-relative-variable

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 8, 2026

Description

Adds a reverse companion to RELATIVE_FILEPATH so snippets can compute a path from the current file back to the workspace folder.

  • Snippet variable surface

    • Registered new built-in variable: REVERSE_RELATIVE_FILEPATH.
  • Resolution behavior

    • Implemented in ModelBasedVariableResolver using existing label-service relative path behavior.
    • Returns:
      • undefined when the file is not in a workspace folder context.
      • . when the file is at workspace root.
      • .., ../.., etc. (platform separator aware) for nested paths.
    • Refactored resolver control flow to switch and extracted reverse-path computation into a dedicated helper for readability/maintainability.
  • Docs and grammar parity

    • Updated snippet variable docs (snippet.md).
    • Updated snippet syntax grammar allowlist (snippets.tmLanguage.json) so the new variable is recognized in snippet JSON.
{
  "Print reverse path": {
    "prefix": "revpath",
    "body": "from ${REVERSE_RELATIVE_FILEPATH}"
  }
}

Testing

  • Extended snippet variable tests to cover:
    • out-of-workspace case,
    • workspace-root case,
    • file-above-workspace-root case (relative path remains absolute and reverse resolves to undefined),
    • nested file case (.., ../..),
    • platform-specific separator behavior (including backslash cases),
    • Windows drive-letter path scenarios (C:\...),
    • remote URI scenarios (both in-workspace and out-of-workspace behavior).
  • Ran:
    • npm run compile-check-ts-native
    • npm run test-node -- --grep "Snippet Variables Resolver"

Copilot AI requested review from Copilot and removed request for Copilot May 8, 2026 01:47
Copilot AI linked an issue May 8, 2026 that may be closed by this pull request
Agent-Logs-Url: https://github.com/microsoft/vscode/sessions/90968350-ad07-450f-8ad9-ce68bef9849a

Co-authored-by: dmitrivMS <9581278+dmitrivMS@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 8, 2026 01:57
Copilot AI changed the title [WIP] Add reverse relative variable to snippets Add REVERSE_RELATIVE_FILEPATH snippet variable May 8, 2026
Copilot AI requested a review from dmitrivMS May 8, 2026 01:58
Copy link
Copy Markdown
Contributor

@dmitrivMS dmitrivMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comments

} else {
assertVariableResolve(resolver, 'RELATIVE_FILEPATH', 'files\\text.txt');
}
assertVariableResolve(resolver, 'REVERSE_RELATIVE_FILEPATH', '..');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot that's it? one test?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added broader coverage for REVERSE_RELATIVE_FILEPATH in fc686605 (including deeply nested paths, workspace root, out-of-workspace, and backslash separator behavior).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot I don't see any tests for Windows paths (C:...).
Also, what happens in remote scenarios?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added explicit coverage in 9483cf96/e1f10a2b for Windows drive paths (C:\workspace\dir\sub\text.txt -> ..\\..) and remote URIs: in-workspace remote paths resolve to parent traversal (..), while remote out-of-workspace paths resolve to undefined.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot we should probably use a switch instead of else if tree here...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated ModelBasedVariableResolver.resolve to use a switch and extracted reverse-path logic into a helper in 6292b69a (with follow-up polish in fc686605).

Agent-Logs-Url: https://github.com/microsoft/vscode/sessions/ad126469-3f4a-47aa-bc06-a4affd3929e7

Co-authored-by: dmitrivMS <9581278+dmitrivMS@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 8, 2026 02:11
Agent-Logs-Url: https://github.com/microsoft/vscode/sessions/ad126469-3f4a-47aa-bc06-a4affd3929e7

Co-authored-by: dmitrivMS <9581278+dmitrivMS@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 8, 2026 02:12
Agent-Logs-Url: https://github.com/microsoft/vscode/sessions/ad126469-3f4a-47aa-bc06-a4affd3929e7

Co-authored-by: dmitrivMS <9581278+dmitrivMS@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 8, 2026 02:13
Copilot AI changed the title Add REVERSE_RELATIVE_FILEPATH snippet variable Add REVERSE_RELATIVE_FILEPATH snippet variable and refine resolver/tests May 8, 2026
Copilot AI requested a review from dmitrivMS May 8, 2026 02:13
} else {
assertVariableResolve(resolver, 'RELATIVE_FILEPATH', 'files\\text.txt');
}
assertVariableResolve(resolver, 'REVERSE_RELATIVE_FILEPATH', '..');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot I don't see any tests for Windows paths (C:...).
Also, what happens in remote scenarios?

}

return undefined;
private _resolveReverseRelativeFilepath(): string | undefined {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot what will happen if file is not in workspace? if it's above workspace?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For files outside the workspace (including above a workspace root), REVERSE_RELATIVE_FILEPATH resolves to undefined and RELATIVE_FILEPATH stays absolute. I added explicit coverage for the “above workspace” case in 78474ed5.

Copilot AI requested review from Copilot and removed request for Copilot May 8, 2026 02:26
Agent-Logs-Url: https://github.com/microsoft/vscode/sessions/7cc9fe0d-9fc5-4b68-aa98-3f0997bd744d

Co-authored-by: dmitrivMS <9581278+dmitrivMS@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 8, 2026 02:27
Copilot AI changed the title Add REVERSE_RELATIVE_FILEPATH snippet variable and refine resolver/tests Add REVERSE_RELATIVE_FILEPATH snippet variable and expand cross-platform/remote test coverage May 8, 2026
Copilot AI requested a review from dmitrivMS May 8, 2026 02:28
Agent-Logs-Url: https://github.com/microsoft/vscode/sessions/2ace4b45-56f1-46d2-ad23-8a45c873f723

Co-authored-by: dmitrivMS <9581278+dmitrivMS@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot May 8, 2026 02:32
Copilot AI changed the title Add REVERSE_RELATIVE_FILEPATH snippet variable and expand cross-platform/remote test coverage Add REVERSE_RELATIVE_FILEPATH snippet variable and expand cross-platform/remote/out-of-workspace test coverage May 8, 2026
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.

Add reverse relative variable to snippets

2 participants