Skip to content

Commit

Permalink
fix: vscode
Browse files Browse the repository at this point in the history
  • Loading branch information
dineug committed Oct 3, 2024
1 parent 26803b8 commit 17f0816
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 36 deletions.
2 changes: 1 addition & 1 deletion packages/erd-editor-vscode/src/constants/viewType.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const MODERN_VIEW_TYPE = 'editor.erd';
export const VIEW_TYPE = 'editor.erd';
22 changes: 6 additions & 16 deletions packages/erd-editor-vscode/src/erd-editor-provider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from 'vscode';

import { MODERN_VIEW_TYPE } from '@/constants/viewType';
import { VIEW_TYPE } from '@/constants/viewType';
import { CreateEditor } from '@/editor';
import { ErdDocument } from '@/erd-document';
import { trackEvent } from '@/utils/googleAnalytics';
Expand All @@ -26,20 +26,12 @@ export class ErdEditorProvider
context: vscode.ExtensionContext,
createEditor: CreateEditor
): vscode.Disposable {
const provider = new ErdEditorProvider(
context,
MODERN_VIEW_TYPE,
createEditor
);
const provider = new ErdEditorProvider(context, VIEW_TYPE, createEditor);

return vscode.window.registerCustomEditorProvider(
MODERN_VIEW_TYPE,
provider,
{
webviewOptions: { retainContextWhenHidden: true },
supportsMultipleEditorsPerDocument: true,
}
);
return vscode.window.registerCustomEditorProvider(VIEW_TYPE, provider, {
webviewOptions: { retainContextWhenHidden: true },
supportsMultipleEditorsPerDocument: true,
});
}

async openCustomDocument(
Expand All @@ -54,15 +46,13 @@ export class ErdEditorProvider
const listener = document.onDidChangeContent(() => {
this._onDidChangeCustomDocument.fire({ document });
});
let unsubscribe = () => {};

if (!this.docToWebviewMap.has(document)) {
this.docToWebviewMap.set(document, new Set());
}

document.onDidDispose(() => {
listener.dispose();
unsubscribe();
this.docToWebviewMap.delete(document);
});

Expand Down
25 changes: 6 additions & 19 deletions packages/erd-editor-vscode/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
import * as vscode from 'vscode';

import { MODERN_VIEW_TYPE } from '@/constants/viewType';
import { VIEW_TYPE } from '@/constants/viewType';
import { widthEditor } from '@/editor';
import { ErdEditor } from '@/erd-editor';
import { ErdEditorProvider } from '@/erd-editor-provider';

export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(
ErdEditorProvider.register(context, widthEditor(ErdEditor))
);
context.subscriptions.push(
vscode.commands.registerCommand('vuerd.showSource', showSource)
);
context.subscriptions.push(
vscode.commands.registerCommand('vuerd.showEditor', showEditor)
);
context.subscriptions.push(
ErdEditorProvider.register(context, widthEditor(ErdEditor)),
vscode.commands.registerCommand('vuerd.showSource', showSource),
vscode.commands.registerCommand('vuerd.showEditor', showEditor),
vscode.commands.registerCommand('vuerd.showEditorToSide', uri =>
showEditor(uri, vscode.ViewColumn.Beside)
)
);
context.subscriptions.push(
),
vscode.commands.registerCommand('vuerd.showSourceToSide', uri =>
showSource(uri, vscode.ViewColumn.Beside)
)
Expand All @@ -32,10 +24,5 @@ function showSource(uri: vscode.Uri, viewColumn?: vscode.ViewColumn) {
}

function showEditor(uri: vscode.Uri, viewColumn?: vscode.ViewColumn) {
vscode.commands.executeCommand(
'vscode.openWith',
uri,
MODERN_VIEW_TYPE,
viewColumn
);
vscode.commands.executeCommand('vscode.openWith', uri, VIEW_TYPE, viewColumn);
}

0 comments on commit 17f0816

Please sign in to comment.