Skip to content

Commit 206cd1e

Browse files
authored
Fix 'No file system provider found' errors when debugging local file (#1047)
1 parent eeca829 commit 206cd1e

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/debug/debugSession.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { DebugProtocol } from "vscode-debugprotocol";
1818
import WebSocket = require("ws");
1919
import { AtelierAPI } from "../api";
2020
import * as xdebug from "./xdebugConnection";
21-
import { schemas } from "../extension";
21+
import { documentContentProvider, OBJECTSCRIPT_FILE_SCHEMA, schemas } from "../extension";
2222
import { DocumentContentProvider } from "../providers/DocumentContentProvider";
2323
import { formatPropertyValue } from "./utils";
2424

@@ -38,6 +38,15 @@ interface AttachRequestArguments extends DebugProtocol.AttachRequestArguments {
3838
stopOnEntry?: boolean;
3939
}
4040

41+
/** Get the text of file `uri`. Works for all file systems and the `objectscript` `DocumentContentProvider`. */
42+
async function getFileText(uri: vscode.Uri): Promise<string> {
43+
if (uri.scheme == OBJECTSCRIPT_FILE_SCHEMA) {
44+
return await documentContentProvider.provideTextDocumentContent(uri, new vscode.CancellationTokenSource().token);
45+
} else {
46+
return new TextDecoder().decode(await vscode.workspace.fs.readFile(uri));
47+
}
48+
}
49+
4150
/** converts a uri from VS Code to a server-side XDebug file URI with respect to source root settings */
4251
async function convertClientPathToDebugger(uri: vscode.Uri, namespace: string): Promise<string> {
4352
const { scheme, path } = uri;
@@ -49,7 +58,7 @@ async function convertClientPathToDebugger(uri: vscode.Uri, namespace: string):
4958
}
5059
fileName = path.slice(1).replace(/\//g, ".");
5160
} else {
52-
fileName = currentFileFromContent(uri, new TextDecoder().decode(await vscode.workspace.fs.readFile(uri)))?.name;
61+
fileName = currentFileFromContent(uri, await getFileText(uri))?.name;
5362
}
5463

5564
namespace = encodeURIComponent(namespace);
@@ -303,7 +312,7 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
303312
currentSymbol.detail.toLowerCase() !== "query"
304313
) {
305314
// This breakpoint is in a method
306-
const currentdoc = new TextDecoder().decode(await vscode.workspace.fs.readFile(uri)).split(/\r?\n/);
315+
const currentdoc = (await getFileText(uri)).split(/\r?\n/);
307316
if (languageServer) {
308317
// selectionRange.start.line is the method definition line
309318
for (
@@ -536,7 +545,7 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
536545
}
537546
}
538547
if (currentSymbol !== undefined) {
539-
const currentdoc = new TextDecoder().decode(await vscode.workspace.fs.readFile(fileUri)).split(/\r?\n/);
548+
const currentdoc = (await getFileText(fileUri)).split(/\r?\n/);
540549
if (languageServer) {
541550
for (
542551
let methodlinenum = currentSymbol.selectionRange.start.line;

0 commit comments

Comments
 (0)