1
1
import vscode = require( "vscode" ) ;
2
- import { currentFile } from "../utils" ;
2
+ import { currentFile , currentFileFromContent } from "../utils" ;
3
3
import { Subject } from "await-notify" ;
4
4
import {
5
5
InitializedEvent ,
@@ -19,7 +19,6 @@ import WebSocket = require("ws");
19
19
import { AtelierAPI } from "../api" ;
20
20
import * as xdebug from "./xdebugConnection" ;
21
21
import { schemas } from "../extension" ;
22
- import * as url from "url" ;
23
22
import { DocumentContentProvider } from "../providers/DocumentContentProvider" ;
24
23
import { formatPropertyValue } from "./utils" ;
25
24
@@ -40,20 +39,15 @@ interface AttachRequestArguments extends DebugProtocol.AttachRequestArguments {
40
39
/** converts a uri from VS Code to a server-side XDebug file URI with respect to source root settings */
41
40
async function convertClientPathToDebugger ( uri : vscode . Uri , namespace : string ) : Promise < string > {
42
41
const { scheme, path } = uri ;
43
- const { query } = url . parse ( uri . toString ( true ) , true ) ;
42
+ const params = new URLSearchParams ( uri . query ) ;
44
43
let fileName : string ;
45
44
if ( scheme && schemas . includes ( scheme ) ) {
46
- if ( query . ns && query . ns !== "" ) {
47
- namespace = query . ns . toString ( ) ;
45
+ if ( params . has ( "ns" ) && params . get ( "ns" ) !== "" ) {
46
+ namespace = params . get ( "ns" ) ;
48
47
}
49
48
fileName = path . slice ( 1 ) . replace ( / \/ / g, "." ) ;
50
49
} else {
51
- fileName = await vscode . workspace
52
- . openTextDocument ( uri )
53
- . then ( currentFile )
54
- . then ( ( curFile ) => {
55
- return curFile . name ;
56
- } ) ;
50
+ fileName = currentFileFromContent ( uri , new TextDecoder ( ) . decode ( await vscode . workspace . fs . readFile ( uri ) ) ) ?. name ;
57
51
}
58
52
59
53
namespace = encodeURIComponent ( namespace ) ;
@@ -294,7 +288,7 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
294
288
currentSymbol . detail . toLowerCase ( ) !== "query"
295
289
) {
296
290
// This breakpoint is in a method
297
- const currentdoc = await vscode . workspace . openTextDocument ( uri ) ;
291
+ const currentdoc = new TextDecoder ( ) . decode ( await vscode . workspace . fs . readFile ( uri ) ) . split ( / \r ? \n / ) ;
298
292
if ( languageServer ) {
299
293
// selectionRange.start.line is the method definition line
300
294
for (
@@ -303,7 +297,7 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
303
297
methodlinenum ++
304
298
) {
305
299
// Find the offset of this breakpoint in the method
306
- const methodlinetext : string = currentdoc . lineAt ( methodlinenum ) . text . trim ( ) ;
300
+ const methodlinetext : string = currentdoc [ methodlinenum ] . trim ( ) ;
307
301
if ( methodlinetext . endsWith ( "{" ) ) {
308
302
// This is the last line of the method definition, so count from here
309
303
if ( breakpoint . condition ) {
@@ -527,15 +521,15 @@ export class ObjectScriptDebugSession extends LoggingDebugSession {
527
521
}
528
522
}
529
523
if ( currentSymbol !== undefined ) {
530
- const currentdoc = await vscode . workspace . openTextDocument ( fileUri ) ;
524
+ const currentdoc = new TextDecoder ( ) . decode ( await vscode . workspace . fs . readFile ( fileUri ) ) . split ( / \r ? \n / ) ;
531
525
if ( languageServer ) {
532
526
for (
533
527
let methodlinenum = currentSymbol . selectionRange . start . line ;
534
528
methodlinenum <= currentSymbol . range . end . line ;
535
529
methodlinenum ++
536
530
) {
537
531
// Find the offset of this breakpoint in the method
538
- const methodlinetext : string = currentdoc . lineAt ( methodlinenum ) . text . trim ( ) ;
532
+ const methodlinetext : string = currentdoc [ methodlinenum ] . trim ( ) ;
539
533
if ( methodlinetext . endsWith ( "{" ) ) {
540
534
// This is the last line of the method definition, so count from here
541
535
line = methodlinenum + stackFrame . methodOffset + 1 ;
0 commit comments