Skip to content

fix(plugin-ext): match custom editor filenamePattern against full path#17654

Open
safisa wants to merge 1 commit into
eclipse-theia:masterfrom
safisa:safi-fix/custom-editor-filename-pattern-paths
Open

fix(plugin-ext): match custom editor filenamePattern against full path#17654
safisa wants to merge 1 commit into
eclipse-theia:masterfrom
safisa:safi-fix/custom-editor-filename-pattern-paths

Conversation

@safisa

@safisa safisa commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

What it does

CustomEditorOpener matched a custom editor's filenamePattern against the file's basename only, so a pattern containing a path separator (e.g. **/components/*/config.json) never matched.

This mirrors VS Code's editorResolverService#globMatchesResource: a pattern containing a / is matched against scheme:path, while a plain pattern is matched against the basename only (case-insensitive in both cases).

I think this fixes the issue:
Fixes: #16492

How to test

End-to-end: install a plugin contributing a custom editor whose selector uses a path-scoped filenamePattern (e.g. **/foo/*/bar.json), open a matching file, and confirm the custom editor is offered/opened. Confirm a plain *.ext pattern still resolves as before.

Follow-ups

None.

Breaking changes

  • This PR introduces breaking changes.

Review checklist

  • As an author, I have thoroughly tested my changes and carefully followed the review guidelines
  • No user-facing text is added, so no nls localization is required

@github-project-automation github-project-automation Bot moved this to Waiting on reviewers in PR Backlog Jun 11, 2026
@ndoschek ndoschek requested a review from lucas-koehler July 2, 2026 10:58

@lucas-koehler lucas-koehler left a comment

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.

Hi @safisa , thanks for this improvement! The change generally looks good to me. I have one comment inline regarding parity with the VS Code implementation. Please have a look :)

if (selector.filenamePattern) {
if (match(selector.filenamePattern.toLowerCase(), resource.path.name.toLowerCase() + resource.path.ext.toLowerCase())) {
const filenamePattern = selector.filenamePattern.toLowerCase();
// Mirror VS Code's editor-association matching (editorResolverService#globMatchesResource):

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.

The VSCode implementation never matches patterns that use schemes for extensions, settings, etc as defined in the following. Was it on purpose to deviate from the VSCode behavior?

https://github.com/microsoft/vscode/blob/190016f57611359bf4bafe2395ce27c074a6317d/src/vs/workbench/services/editor/common/editorResolverService.ts#L272-L276

@safisa safisa Jul 3, 2026

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.

Good catch, not intentional, thanks. I've added the excluded-schemes short-circuit to mirror globMatchesResource, so extension, webview-panel, vscode-workspace-trust, and vscode-settings resources match no pattern. Theia only defines Schemes constants for vscode-settings and webview-panel, so the other two are referenced by their literal scheme strings. Added a test covering it.

CustomEditorOpener only tested the basename, so a filenamePattern containing a
path separator (e.g. **/components/*/config.json) never matched. Mirror VS Code's
editorResolverService#globMatchesResource: a pattern with a / is matched against
scheme:path, a plain pattern against the basename only, and the internal schemes
it excludes (extension, webview-panel, vscode-workspace-trust, vscode-settings)
match no pattern. Add unit tests for selectorMatches.

Fixes eclipse-theia#16492
@safisa safisa force-pushed the safi-fix/custom-editor-filename-pattern-paths branch from 1d36e4c to 914beb2 Compare July 3, 2026 18:50
@safisa safisa requested a review from lucas-koehler July 3, 2026 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Waiting on reviewers

Development

Successfully merging this pull request may close these issues.

vscode.window.showTextDocument doesn't open built-in text editor when a custom editor is registered for document type

2 participants