Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added first set of integration tests #2

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/documentation/DocumentationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ import contextKeys from "../contextKeys";
export class DocumentationManager implements vscode.Disposable {
private previewEditor?: DocumentationPreviewEditor;
private editorUpdatedContentEmitter = new vscode.EventEmitter<RenderNode>();
private editorRenderedEmitter = new vscode.EventEmitter<void>();

constructor(
private readonly extension: vscode.ExtensionContext,
private readonly context: WorkspaceContext
) {}

onPreviewDidUpdateContent = this.editorUpdatedContentEmitter.event;
onPreviewDidRenderContent = this.editorRenderedEmitter.event;

async launchDocumentationPreview(): Promise<boolean> {
if (!contextKeys.supportsDocumentationRendering) {
Expand All @@ -45,6 +47,9 @@ export class DocumentationManager implements vscode.Disposable {
this.previewEditor.onDidUpdateContent(content => {
this.editorUpdatedContentEmitter.fire(content);
}),
this.previewEditor.onDidRenderContent(() => {
this.editorRenderedEmitter.fire();
}),
this.previewEditor.onDidDispose(() => {
subscriptions.forEach(d => d.dispose());
this.previewEditor = undefined;
Expand Down
28 changes: 20 additions & 8 deletions src/documentation/DocumentationPreviewEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@ import { RenderNode, WebviewMessage } from "./webview/WebviewMessage";
import { WorkspaceContext } from "../WorkspaceContext";
import { RenderDocumentationRequest } from "../sourcekit-lsp/extensions/RenderDocumentationRequest";

export enum PreviewEditorConstant {
VIEW_TYPE = "swift.previewDocumentationEditor",
TITLE = "Preview Swift Documentation",
}

export class DocumentationPreviewEditor implements vscode.Disposable {
private readonly webviewPanel: vscode.WebviewPanel;
private subscriptions: vscode.Disposable[] = [];

private disposeEmitter = new vscode.EventEmitter<void>();
private renderEmitter = new vscode.EventEmitter<void>();
private updateContentEmitter = new vscode.EventEmitter<RenderNode>();

constructor(
Expand All @@ -33,8 +39,8 @@ export class DocumentationPreviewEditor implements vscode.Disposable {
const swiftDoccRenderPath = this.extension.asAbsolutePath("assets/swift-docc-render");
// Create and hook up events for the WebviewPanel
this.webviewPanel = vscode.window.createWebviewPanel(
"swift.previewDocumentationEditor",
"Preview Swift Documentation",
PreviewEditorConstant.VIEW_TYPE,
PreviewEditorConstant.TITLE,
{ viewColumn: vscode.ViewColumn.Beside, preserveFocus: true },
{
enableScripts: true,
Expand All @@ -59,12 +65,12 @@ export class DocumentationPreviewEditor implements vscode.Disposable {
this.webviewPanel.webview.html = documentationHTML;
this.subscriptions.push(
this.webviewPanel.webview.onDidReceiveMessage(this.receiveMessage.bind(this)),
vscode.window.onDidChangeActiveTextEditor(editor =>
this.renderDocumentation(editor)
),
vscode.window.onDidChangeTextEditorSelection(event =>
this.renderDocumentation(event.textEditor)
),
vscode.window.onDidChangeActiveTextEditor(editor => {
this.renderDocumentation(editor);
}),
vscode.window.onDidChangeTextEditorSelection(event => {
this.renderDocumentation(event.textEditor);
}),
this.webviewPanel.onDidDispose(this.dispose.bind(this))
);
// Reveal the editor, but don't change the focus of the active text editor
Expand All @@ -79,6 +85,9 @@ export class DocumentationPreviewEditor implements vscode.Disposable {
/** An event that is fired when the Documentation Preview Editor updates its content */
onDidUpdateContent = this.updateContentEmitter.event;

/** An event that is fired when the Documentation Preview Editor renders its content */
onDidRenderContent = this.renderEmitter.event;

reveal() {
this.webviewPanel.reveal();
}
Expand All @@ -102,6 +111,9 @@ export class DocumentationPreviewEditor implements vscode.Disposable {
case "loaded":
this.renderDocumentation(vscode.window.activeTextEditor);
break;
case "rendered":
this.renderEmitter.fire();
break;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/utilities/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ export enum Workbench {
ACTION_DEBUG_CONTINUE = "workbench.action.debug.continue",
ACTION_CLOSEALLEDITORS = "workbench.action.closeAllEditors",
ACTION_RELOADWINDOW = "workbench.action.reloadWindow",
ACTION_PREVIOUSEDITORINGROUP = "workbench.action.previousEditorInGroup",
}
70 changes: 0 additions & 70 deletions test/integration-tests/documentation/DocumentationManager.test.ts

This file was deleted.

Loading
Loading