Skip to content

Commit 07a3606

Browse files
committed
Fix bug to open body link of absolute path with Ctrl/Cmd+Click
1 parent 59bb885 commit 07a3606

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

‎src/documentLinkProvider.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class RequestBodyDocumentLinkProvider implements DocumentLinkProvider {
1515
let lines: string[] = text.split(/\r?\n/g);
1616
for (var index = 0; index < lines.length; index++) {
1717
var line = lines[index];
18-
let match: RegExpMatchArray | null;
18+
let match: RegExpMatchArray;
1919
if (match = this._linkPattern.exec(line)) {
2020
let filePath = match[2];
2121
const offset = match[1].length;
@@ -41,8 +41,10 @@ export class RequestBodyDocumentLinkProvider implements DocumentLinkProvider {
4141
let resourcePath;
4242
if (!uri.path) {
4343
resourcePath = document.uri.path;
44-
} else if (uri.path[0] === '/') {
45-
resourcePath = path.join(workspace.rootPath || '', uri.path);
44+
} else if (path.isAbsolute(uri.path)) {
45+
resourcePath = uri.path;
46+
} else if (workspace.rootPath) {
47+
resourcePath = path.join(workspace.rootPath, uri.path);
4648
} else {
4749
resourcePath = path.join(base, uri.path);
4850
}

‎src/extension.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ export async function activate(context: ExtensionContext) {
4343
context.subscriptions.push(commands.registerCommand('rest-client.copy-request-as-curl', () => codeSnippetController.copyAsCurl()));
4444
context.subscriptions.push(commands.registerCommand('rest-client.switch-environment', () => environmentController.switchEnvironment()));
4545
context.subscriptions.push(commands.registerCommand('rest-client._openDocumentLink', args => {
46-
workspace.openTextDocument(Uri.file(args.path)).then(window.showTextDocument, window.showErrorMessage);
46+
workspace.openTextDocument(Uri.file(args.path)).then(window.showTextDocument, error => {
47+
window.showErrorMessage(error.message);
48+
});
4749
}));
4850
context.subscriptions.push(languages.registerCompletionItemProvider('http', new HttpCompletionItemProvider()));
4951
context.subscriptions.push(languages.registerHoverProvider('http', new CustomVariableHoverProvider()));

0 commit comments

Comments
 (0)