Fix file links not opening in Notebooks on Mac (#18202)

* convert vscode-file to file

* update comment

* check for undefined uri
This commit is contained in:
Lucy Zhang
2022-02-07 12:53:40 -08:00
committed by GitHub
parent 49e98ff3fa
commit 94cbae55ca

View File

@@ -11,6 +11,7 @@ import { INotebookService } from 'sql/workbench/services/notebook/browser/notebo
import { relative, resolve } from 'vs/base/common/path'; import { relative, resolve } from 'vs/base/common/path';
import { IFileService } from 'vs/platform/files/common/files'; import { IFileService } from 'vs/platform/files/common/files';
import { isWeb } from 'vs/base/common/platform'; import { isWeb } from 'vs/base/common/platform';
import { FileAccess } from 'vs/base/common/network';
const knownSchemes = new Set(['http', 'https', 'file', 'mailto', 'data', 'azuredatastudio', 'azuredatastudio-insiders', 'vscode', 'vscode-insiders', 'vscode-resource', 'onenote']); const knownSchemes = new Set(['http', 'https', 'file', 'mailto', 'data', 'azuredatastudio', 'azuredatastudio-insiders', 'vscode', 'vscode-insiders', 'vscode-resource', 'onenote']);
@Directive({ @Directive({
@@ -71,27 +72,31 @@ export class LinkHandlerDirective {
return; return;
} }
} }
if (uri && this.openerService && this.isSupportedLink(uri)) { if (uri && this.openerService) {
if (uri.fragment && uri.fragment.length > 0 && uri.fsPath === this.workbenchFilePath.fsPath) { // Convert vscode-file protocol URIs to file since that's what Notebooks expect to work with
this.notebookService.navigateTo(this.notebookUri, uri.fragment); uri = FileAccess.asFileUri(uri);
} else { if (this.isSupportedLink(uri)) {
if (uri.scheme === 'file') { if (uri.fragment && uri.fragment.length > 0 && uri.fsPath === this.workbenchFilePath.fsPath) {
let exists = await this.fileService.exists(uri); this.notebookService.navigateTo(this.notebookUri, uri.fragment);
if (!exists) { } else {
let relPath = relative(this.workbenchFilePath.fsPath, uri.fsPath); if (uri.scheme === 'file') {
let path = resolve(this.notebookUri.fsPath, relPath); let exists = await this.fileService.exists(uri);
try { if (!exists) {
uri = URI.file(path); let relPath = relative(this.workbenchFilePath.fsPath, uri.fsPath);
} catch (error) { let path = resolve(this.notebookUri.fsPath, relPath);
onUnexpectedError(error); try {
uri = URI.file(path);
} catch (error) {
onUnexpectedError(error);
}
} }
} }
} if (this.forceOpenExternal(uri)) {
if (this.forceOpenExternal(uri)) { this.openerService.open(uri, { openExternal: true }).catch(onUnexpectedError);
this.openerService.open(uri, { openExternal: true }).catch(onUnexpectedError); }
} else {
else { this.openerService.open(uri, { allowCommands: true }).catch(onUnexpectedError);
this.openerService.open(uri, { allowCommands: true }).catch(onUnexpectedError); }
} }
} }
} }