Skip to content

Commit b6e428e

Browse files
committed
Use fileUrl module
1 parent 24c2a66 commit b6e428e

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"url": "https://github.com/felixfbecker/vscode-php-debug/issues"
3434
},
3535
"dependencies": {
36+
"file-url": "^1.1.0",
3637
"iconv-lite": "^0.4.13",
3738
"moment": "^2.11.2",
3839
"url-relative": "^1.0.0",

src/phpDebug.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,9 @@ import * as url from 'url';
88
import * as childProcess from 'child_process';
99
import * as path from 'path';
1010
import * as util from 'util';
11+
import fileUrl = require('file-url');
1112
import {Terminal} from './terminal';
1213

13-
/** converts a path to a file URI */
14-
function fileUrl(path: string): string {
15-
let pathName = path.replace(/\\/g, '/');
16-
// Windows drive letter must be prefixed with a slash
17-
if (pathName[0] !== '/') {
18-
pathName = '/' + pathName;
19-
}
20-
return encodeURI('file://' + pathName);
21-
}
22-
2314
/** formats a xdebug property value for VS Code */
2415
function formatPropertyValue(property: xdebug.BaseProperty): string {
2516
let displayValue: string;
@@ -260,14 +251,14 @@ class PhpDebugSession extends vscode.DebugSession {
260251

261252
/** converts a local path from VS Code to a server-side XDebug file URI with respect to source root settings */
262253
protected convertClientPathToDebugger(localPath: string): string {
263-
let localFileUri = fileUrl(localPath);
254+
let localFileUri = fileUrl(localPath, {resolve: false});
264255
let serverFileUri: string;
265256
if (this._args.serverSourceRoot && this._args.localSourceRoot) {
266-
let localSourceRootUrl = fileUrl(this._args.localSourceRoot);
257+
let localSourceRootUrl = fileUrl(this._args.localSourceRoot, {resolve: false});
267258
if (!localSourceRootUrl.endsWith('/')) {
268259
localSourceRootUrl += '/';
269260
}
270-
let serverSourceRootUrl = fileUrl(this._args.serverSourceRoot);
261+
let serverSourceRootUrl = fileUrl(this._args.serverSourceRoot, {resolve: false});
271262
if (!serverSourceRootUrl.endsWith('/')) {
272263
serverSourceRootUrl += '/';
273264
}

src/typings/file-url/file-url.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module 'file-url' {
2+
function fileUrl(path: string, options?: {resolve: boolean}): string;
3+
export = fileUrl;
4+
}

0 commit comments

Comments
 (0)