Microsoft/monaco-editor

[Bug] Error: Could not find source file

Open

#3,391 创建于 2022年11月2日

在 GitHub 查看
 (2 评论) (4 反应) (0 负责人)JavaScript (1,283 fork)batch import
bughelp wantedtypescript

仓库指标

Star
 (14,836 star)
PR 合并指标
 (平均合并 6小时 26分钟) (30 天内合并 15 个 PR)

描述

Reproducible in vscode.dev or in VS Code Desktop?

  • Not reproducible in vscode.dev or VS Code Desktop

Reproducible in the monaco editor playground?

Monaco Editor Playground Code

monaco.editor.create(document.getElementById("container"), {
    model: monaco.editor.createModel(
        "import * as t from 'test';\nt.X.toExponential();", 
        "typescript",
        monaco.Uri.parse("root")
    )
});

monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
  ...monaco.languages.typescript.typescriptDefaults.getCompilerOptions(),
  moduleResolution: monaco.languages.typescript.ModuleResolutionKind.Classic
});

const parsed = monaco.Uri.parse("/test.ts?id=123");
monaco.editor.createModel(
    "export const X = 1;", 
    "javascript",
    parsed
);
console.log(parsed)

Reproduction Steps

  1. Paste the code
  2. Open browser debug tool
  3. Press "Run" button
  4. Hover over import statement to make worker work

Actual (Problematic) Behavior

There's an error caused by adding query param (with equal sign or Russian word as example) to URI. The problem is in method getValidSourceFile. This file exists in the list of models, I checked this via program.getSourceFiles(), but its fileName doesn't correspond due to encoding equal sign to %3D, so the method returns undefined and console shows this error:

Uncaught (in promise) Error: Could not find source file: 'file:///test.ts?id%3D123'. at Ve (/vs/language/typescript/tsWorker.js:255:8493) at Object.On [as getSyntacticDiagnostics] (/vs/language/typescript/tsWorker.js:255:13349) at lm.getSyntacticDiagnostics (/vs/language/typescript/tsWorker.js:33955:2559) at S.fmr (workerMain.js:22:33695) at f._handleMessage (workerMain.js:22:17684) at Object.handleMessage (workerMain.js:22:17309) at w._handleRequestMessage (workerMain.js:22:14120) at w._handleMessage (workerMain.js:22:13570) at w.handleMessage (workerMain.js:22:13458) at f.onmessage (workerMain.js:22:17401)

Expected Behavior

File should be returned from the list of model regardless encoding/decoding issues in URI.

Additional Context

No response

贡献者指南