-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display Kernel startup Errors in cell output for more visibility (#8304)
- Loading branch information
1 parent
d9de7a5
commit f3f77cf
Showing
14 changed files
with
347 additions
and
218 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
import { inject, injectable } from 'inversify'; | ||
import { commands, notebooks, Position, Range, Selection, TextEditorRevealType, Uri } from 'vscode'; | ||
import { IExtensionSyncActivationService } from '../../activation/types'; | ||
import { IApplicationShell, ICommandManager, IDocumentManager } from '../../common/application/types'; | ||
import { IFileSystem } from '../../common/platform/types'; | ||
import { IDisposableRegistry } from '../../common/types'; | ||
import { InteractiveWindowMessages } from '../interactive-common/interactiveWindowTypes'; | ||
import { LineQueryRegex, linkCommandAllowList } from '../interactive-common/linkProvider'; | ||
|
||
@injectable() | ||
export class ErrorRendererCommunicationHandler implements IExtensionSyncActivationService { | ||
constructor( | ||
@inject(IDisposableRegistry) private readonly disposables: IDisposableRegistry, | ||
@inject(IDocumentManager) private readonly documentManager: IDocumentManager, | ||
@inject(ICommandManager) private readonly commandManager: ICommandManager, | ||
@inject(IFileSystem) private readonly fs: IFileSystem, | ||
@inject(IApplicationShell) private readonly applicationShell: IApplicationShell | ||
) {} | ||
|
||
activate(): void { | ||
const messageChannel = notebooks.createRendererMessaging('jupyter-error-renderer'); | ||
this.disposables.push( | ||
messageChannel.onDidReceiveMessage(async (e) => { | ||
const message = e.message; | ||
if (message.message === InteractiveWindowMessages.OpenLink) { | ||
const href = message.payload; | ||
if (href.startsWith('file')) { | ||
await this.openFile(href); | ||
} else if (href.startsWith('https://command:') || href.startsWith('command:')) { | ||
const temp: string = href.startsWith('https://command:') | ||
? href.split(':')[2] | ||
: href.split(':')[1]; | ||
const params: string[] = temp.includes('/?') ? temp.split('/?')[1].split(',') : []; | ||
let command = temp.split('/?')[0]; | ||
if (command.endsWith('/')) { | ||
command = command.substring(0, command.length - 1); | ||
} | ||
if (linkCommandAllowList.includes(command)) { | ||
await commands.executeCommand(command, params); | ||
} | ||
} else { | ||
this.applicationShell.openUrl(href); | ||
} | ||
} | ||
}) | ||
); | ||
} | ||
|
||
private async openFile(fileUri: string) { | ||
const uri = Uri.parse(fileUri); | ||
let selection: Range = new Range(new Position(0, 0), new Position(0, 0)); | ||
if (uri.query) { | ||
// Might have a line number query on the file name | ||
const lineMatch = LineQueryRegex.exec(uri.query); | ||
if (lineMatch) { | ||
const lineNumber = parseInt(lineMatch[1], 10); | ||
selection = new Range(new Position(lineNumber, 0), new Position(lineNumber, 0)); | ||
} | ||
} | ||
|
||
// Show the matching editor if there is one | ||
let editor = this.documentManager.visibleTextEditors.find((e) => this.fs.arePathsSame(e.document.uri, uri)); | ||
if (editor) { | ||
return this.documentManager | ||
.showTextDocument(editor.document, { selection, viewColumn: editor.viewColumn }) | ||
.then((e) => { | ||
e.revealRange(selection, TextEditorRevealType.InCenter); | ||
}); | ||
} else { | ||
// Not a visible editor, try opening otherwise | ||
return this.commandManager.executeCommand('vscode.open', uri).then(() => { | ||
// See if that opened a text document | ||
editor = this.documentManager.visibleTextEditors.find((e) => this.fs.arePathsSame(e.document.uri, uri)); | ||
if (editor) { | ||
// Force the selection to change | ||
editor.revealRange(selection); | ||
editor.selection = new Selection(selection.start, selection.start); | ||
} | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.