monaco-editor icon indicating copy to clipboard operation
monaco-editor copied to clipboard

[Bug] Models with "@" in their name don't work correctly (codefixes)

Open YousefED opened this issue 3 years ago • 1 comments

Reproducible in vscode.dev or in VS Code Desktop?

  • [X] Not reproducible in vscode.dev or VS Code Desktop

Reproducible in the monaco editor playground?

Monaco Editor Playground Code

const uri = monaco.Uri.parse('file:///hello/@test.ts');
const model = monaco.editor.createModel("export let data: string = 4;", 'typescript', uri);
editor = monaco.editor.create(document.getElementById('container'), { model });

Reproduction Steps

Paste code in playground

Actual (Problematic) Behavior

The expected warning for "export let data: string = 4;" doesn't show up ("can't assign number to string")

Expected Behavior

Show the codefix warning

Additional Context

There was a related issue fixed in https://github.com/microsoft/monaco-editor/pull/3057 (https://github.com/microsoft/monaco-editor/issues/2295). However, I suspect it fixes the issue at the wrong level.

The demo shows that code fixes and possibly other functionality as well still don't work for models with an "@" (or other would-be-encoded characters) in their path.

In the case of code fixes, you can see it goes wrong in the function getSourceFileByPath:

function getSourceFileByPath(path) {
      return filesByName.get(path) || void 0;
    }

filesByName contains the files without escaped characters, but the "path" passed in from provideCodeActions is based on resource.toString(), which would return an encoded version of the Uri.

I suspect this issue affects more code paths than just for code completions, and maybe a decision should be made on whether to always call resource.toString(true) (skipEncoding) for all calls to model.uri.toString?

YousefED avatar Aug 09 '22 17:08 YousefED

always call resource.toString(true) (skipEncoding) for all calls to model.uri.toString?

This is already just a hack. File path -> uri was never intended to be a bijective map...

hediet avatar Aug 09 '22 18:08 hediet