Skip to content

Commit fb89e3c

Browse files
author
Chouzz
authored
Add call Hierarchy webview class (#6)
* Add call Hierarchy webview class * Update github actions configuraion
1 parent d66a04a commit fb89e3c

File tree

4 files changed

+60
-12
lines changed

4 files changed

+60
-12
lines changed

.github/workflows/CI.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
push:
55
branches: [main]
66
pull_request:
7-
branches: [main]
87
release:
98
types:
109
- published

src/webview/callHierarchyWebview.ts

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import * as vscode from 'vscode';
2+
import {
3+
callHierarchyGotoItemsCommandType,
4+
callHierarchyInitItemsCommandType,
5+
callHierarchyOnHoverCommandType,
6+
IpcMessage,
7+
State,
8+
} from './protocol';
9+
10+
import { WebviewViewBase } from './webviewBase';
11+
12+
export class CallHierarchyWebview extends WebviewViewBase<State> {
13+
constructor() {
14+
super('callHierarchyView', 'index.html', 'Call Hierarchy');
15+
}
16+
17+
protected onMessageReceived(e: IpcMessage): void {
18+
switch (e.method) {
19+
case callHierarchyGotoItemsCommandType.method:
20+
this.onGotoItem(e.params);
21+
break;
22+
case callHierarchyInitItemsCommandType.method:
23+
this.onInitItem(e.params);
24+
break;
25+
26+
case callHierarchyOnHoverCommandType.method:
27+
this.onHoverItem(e.params);
28+
break;
29+
default:
30+
break;
31+
}
32+
}
33+
34+
private onGotoItem(params: any) {}
35+
36+
private onInitItem(params: any) {}
37+
38+
private onHoverItem(params: any) {}
39+
}
40+
41+
export function activate(context: vscode.ExtensionContext){
42+
const webview = new CallHierarchyWebview();
43+
context.subscriptions.push(webview);
44+
}

src/webview/protocol.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,25 @@ export function onIpc<T extends IpcMessageType<any>>(
3131
fn(msg.params as IpcMessageParams<T>, type);
3232
}
3333

34+
export interface State {
35+
extensionEnabled: boolean;
36+
webroot?: string;
37+
}
3438
// COMMANDS
3539

36-
export const WebviewReadyCommandType = new IpcCommandType('webview/ready');
40+
export const webviewReadyCommandType = new IpcCommandType('webview/ready');
41+
export const callHierarchyInitItemsCommandType = new IpcCommandType('callHierarchy/initItems');
42+
export const callHierarchyGotoItemsCommandType = new IpcCommandType('callHierarchy/gotoItem');
43+
export const callHierarchyOnHoverCommandType = new IpcCommandType('callHierarchy/onHover');
3744

3845
export interface WebviewFocusChangedParams {
3946
focused: boolean;
4047
inputFocused: boolean;
4148
}
42-
export const WebviewFocusChangedCommandType = new IpcCommandType<WebviewFocusChangedParams>('webview/focus');
49+
export const webviewFocusChangedCommandType = new IpcCommandType<WebviewFocusChangedParams>('webview/focus');
4350

4451
export interface ExecuteCommandParams {
4552
command: string;
4653
args?: [];
4754
}
48-
export const ExecuteCommandType = new IpcCommandType<ExecuteCommandParams>('command/execute');
55+
export const executeCommandType = new IpcCommandType<ExecuteCommandParams>('command/execute');

src/webview/webviewBase.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import * as vscode from 'vscode';
33
import { getNonce } from '../common/node';
44
import { extensionContext } from '../extension';
55
import {
6-
ExecuteCommandType,
6+
executeCommandType,
77
IpcMessage,
88
IpcMessageParams,
99
IpcNotificationType,
1010
onIpc,
11-
WebviewReadyCommandType,
11+
webviewReadyCommandType,
1212
} from './protocol';
1313

1414
const maxSmallIntegerV8 = 2 ** 30; // Max number that can be stored in V8's smis (small integers)
@@ -24,8 +24,6 @@ function nextIpcId() {
2424
return `host:${ipcSequence}`;
2525
}
2626

27-
export type WebviewViewIds = 'commitDetails' | 'home' | 'timeline';
28-
2927
export abstract class WebviewViewBase<State, SerializedState = State>
3028
implements vscode.WebviewViewProvider, vscode.Disposable
3129
{
@@ -199,16 +197,16 @@ export abstract class WebviewViewBase<State, SerializedState = State>
199197
}
200198

201199
switch (e.method) {
202-
case WebviewReadyCommandType.method:
203-
onIpc(WebviewReadyCommandType, e, () => {
200+
case webviewReadyCommandType.method:
201+
onIpc(webviewReadyCommandType, e, () => {
204202
this.isReady = true;
205203
this.onReady?.();
206204
});
207205

208206
break;
209207

210-
case ExecuteCommandType.method:
211-
onIpc(ExecuteCommandType, e, (params) => {
208+
case executeCommandType.method:
209+
onIpc(executeCommandType, e, (params) => {
212210
if (params.args) {
213211
vscode.commands.executeCommand(params.command, ...params.args);
214212
} else {

0 commit comments

Comments
 (0)