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

Custom editor support #39

Merged
merged 8 commits into from
Oct 16, 2023
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
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@
}
]
},
"customEditors": [
{
"viewType": "memory-inspector.inspect",
"displayName": "Memory Inspector",
"selector": [
{
"filenamePattern": "*"
}
],
"priority": "option"
}
],
"configuration": {
"title": "Memory Inspector",
"properties": {
Expand Down
2 changes: 2 additions & 0 deletions src/plugin/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

export const PACKAGE_NAME = 'memory-inspector';
export const DISPLAY_NAME = 'Memory Inspector';
export const EDITOR_NAME = `${PACKAGE_NAME}.inspect`;

export const CONFIG_LOGGING_VERBOSITY = 'loggingVerbosity';
export const DEFAULT_LOGGING_VERBOSITY = 'warn';
export const CONFIG_DEBUG_TYPES = 'debugTypes';
Expand Down
38 changes: 35 additions & 3 deletions src/plugin/memory-webview-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const columnConfigurations = [
manifest.CONFIG_SHOW_VARIABLES_COLUMN,
];

export class MemoryWebview {
export class MemoryWebview implements vscode.CustomReadonlyEditorProvider {
public static ViewType = `${manifest.PACKAGE_NAME}.memory`;
public static ShowCommandType = `${manifest.PACKAGE_NAME}.show`;
public static VariableCommandType = `${manifest.PACKAGE_NAME}.show-variable`;
Expand All @@ -76,6 +76,7 @@ export class MemoryWebview {

public activate(context: vscode.ExtensionContext): void {
context.subscriptions.push(
vscode.window.registerCustomEditorProvider(manifest.EDITOR_NAME, this),
vscode.commands.registerCommand(MemoryWebview.ShowCommandType, () => this.show()),
vscode.commands.registerCommand(MemoryWebview.VariableCommandType, node => {
const variable = node.variable;
Expand All @@ -86,7 +87,34 @@ export class MemoryWebview {
);
};

public async show(initialMemory?: Partial<DebugProtocol.ReadMemoryArguments>): Promise<void> {
public openCustomDocument(uri: vscode.Uri): vscode.CustomDocument {
return {
uri,
dispose: () => {}
};
}

public async resolveCustomEditor(document: vscode.CustomDocument, webviewPanel: vscode.WebviewPanel): Promise<void> {
/*
memoryReference = debugprotocol.variable.memoryReference
displayName = 'memory'
colin-grant-work marked this conversation as resolved.
Show resolved Hide resolved
DEBUG_MEMORY_SCHEME = 'vscode-debug-memory'
sessionId = <debug session ID>
range = undefined

document.uri is:

scheme: DEBUG_MEMORY_SCHEME,
authority: sessionId,
path: '/' + encodeURIComponent(memoryReference) + `/${encodeURIComponent(displayName)}.bin`,
colin-grant-work marked this conversation as resolved.
Show resolved Hide resolved
query: range ? `?range=${range.fromOffset}:${range.toOffset}` : undefined,
colin-grant-work marked this conversation as resolved.
Show resolved Hide resolved
*/

const memoryReference = decodeURIComponent(document.uri.path.split('/')[1]);
await this.show({ memoryReference }, webviewPanel);
}

public async show(initialMemory?: Partial<DebugProtocol.ReadMemoryArguments>, panel?: vscode.WebviewPanel): Promise<void> {
const distPathUri = vscode.Uri.joinPath(this.extensionUri, 'dist', 'views');
const mediaPathUri = vscode.Uri.joinPath(this.extensionUri, 'media');
const codiconPathUri = vscode.Uri.joinPath(this.extensionUri, 'node_modules', '@vscode', 'codicons', 'dist');
Expand All @@ -97,7 +125,11 @@ export class MemoryWebview {
localResourceRoots: [distPathUri, mediaPathUri, codiconPathUri] // restrict extension's local file access
};

const panel = vscode.window.createWebviewPanel(MemoryWebview.ViewType, 'Memory Inspector', vscode.ViewColumn.Active, options);
if (!panel) {
panel = vscode.window.createWebviewPanel(MemoryWebview.ViewType, 'Memory Inspector', vscode.ViewColumn.Active, options);
} else {
panel.webview.options = options;
}

// Set HTML content
await this.getWebviewContent(panel);
Expand Down