diff --git a/extensions/markdown-language-features/src/commands/openDocumentLink.ts b/extensions/markdown-language-features/src/commands/openDocumentLink.ts index 8e1dd8661b4..eed32d6efb0 100644 --- a/extensions/markdown-language-features/src/commands/openDocumentLink.ts +++ b/extensions/markdown-language-features/src/commands/openDocumentLink.ts @@ -35,7 +35,7 @@ export class OpenDocumentLinkCommand implements Command { public execute(args: OpenDocumentLinkArgs) { const p = decodeURIComponent(args.path); return this.tryOpen(p, args).catch(() => { - if (extname(p) === '') { + if (p && extname(p) === '') { return this.tryOpen(p + '.md', args); } const resource = vscode.Uri.file(p); @@ -47,13 +47,14 @@ export class OpenDocumentLinkCommand implements Command { private async tryOpen(path: string, args: OpenDocumentLinkArgs) { const resource = vscode.Uri.file(path); - if (vscode.window.activeTextEditor && isMarkdownFile(vscode.window.activeTextEditor.document) && vscode.window.activeTextEditor.document.uri.fsPath === resource.fsPath) { - return this.tryRevealLine(vscode.window.activeTextEditor, args.fragment); - } else { - return vscode.workspace.openTextDocument(resource) - .then(vscode.window.showTextDocument) - .then(editor => this.tryRevealLine(editor, args.fragment)); + if (vscode.window.activeTextEditor && isMarkdownFile(vscode.window.activeTextEditor.document)) { + if (!path || vscode.window.activeTextEditor.document.uri.fsPath === resource.fsPath) { + return this.tryRevealLine(vscode.window.activeTextEditor, args.fragment); + } } + return vscode.workspace.openTextDocument(resource) + .then(vscode.window.showTextDocument) + .then(editor => this.tryRevealLine(editor, args.fragment)); } private async tryRevealLine(editor: vscode.TextEditor, fragment?: string) { diff --git a/extensions/markdown-language-features/src/features/documentLinkProvider.ts b/extensions/markdown-language-features/src/features/documentLinkProvider.ts index c714e388257..f4e1bd0a9d2 100644 --- a/extensions/markdown-language-features/src/features/documentLinkProvider.ts +++ b/extensions/markdown-language-features/src/features/documentLinkProvider.ts @@ -23,7 +23,7 @@ function normalizeLink( const tempUri = vscode.Uri.parse(`vscode-resource:${link}`); let resourcePath = tempUri.path; - if (!tempUri.path) { + if (!tempUri.path && document.uri.scheme === 'file') { resourcePath = document.uri.path; } else if (tempUri.path[0] === '/') { const root = vscode.workspace.getWorkspaceFolder(document.uri); @@ -31,7 +31,7 @@ function normalizeLink( resourcePath = path.join(root.uri.fsPath, tempUri.path); } } else { - resourcePath = path.join(base, tempUri.path); + resourcePath = base ? path.join(base, tempUri.path) : tempUri.path; } return OpenDocumentLinkCommand.createCommandUri(resourcePath, tempUri.fragment); @@ -59,7 +59,7 @@ export default class LinkProvider implements vscode.DocumentLinkProvider { document: vscode.TextDocument, _token: vscode.CancellationToken ): vscode.DocumentLink[] { - const base = path.dirname(document.uri.fsPath); + const base = document.uri.scheme === 'file' ? path.dirname(document.uri.fsPath) : ''; const text = document.getText(); return this.providerInlineLinks(text, document, base)