-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add message passing from the webview to the IDE
- Loading branch information
Showing
26 changed files
with
207 additions
and
138 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { IAnalysisStep } from '../model/analysisStep' | ||
import { WebviewPage } from '../model/webviewPages' | ||
import { IdeEvent, IdeEventType, JumpToCodeEvent } from './ideEvent' | ||
import { WebviewEvent, webviewEventType } from './webviewEvent' | ||
|
||
export class EventManager { | ||
private sendFunc = new Function('request', 'console.log(request)') | ||
|
||
constructor(private setPageState: React.Dispatch<React.SetStateAction<WebviewPage>>) { | ||
this.setEventReceiver() | ||
} | ||
|
||
private sendEvent = (req: IdeEvent): void => { | ||
this.sendFunc(req) | ||
} | ||
|
||
private setEventReceiver(): void { | ||
window.addEventListener('message', event => { | ||
const eventData: WebviewEvent = event.data | ||
|
||
switch (eventData.type) { | ||
case webviewEventType.SetEmitter: | ||
this.sendFunc = new Function(eventData.emitterFunc)() | ||
break | ||
case webviewEventType.ShowPage: | ||
this.setPageState(eventData.pageData) | ||
break | ||
} | ||
}) | ||
} | ||
|
||
public jumpToCode(data: IAnalysisStep): void { | ||
this.sendEvent({ type: IdeEventType.JUMP_TO_CODE, data: data } as JumpToCodeEvent) | ||
} | ||
} |
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,12 @@ | ||
import { IAnalysisStep } from '../model/analysisStep' | ||
|
||
export interface JumpToCodeEvent { | ||
type: IdeEventType.JUMP_TO_CODE | ||
data: IAnalysisStep | ||
} | ||
|
||
export enum IdeEventType { | ||
JUMP_TO_CODE = 'SHOW_CODE' | ||
} | ||
|
||
export type IdeEvent = JumpToCodeEvent |
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,18 @@ | ||
import { WebviewPage } from '../model/webviewPages' | ||
|
||
export interface ShowPageEvent { | ||
type: webviewEventType.ShowPage | ||
pageData: WebviewPage | ||
} | ||
|
||
export interface SetEmitterEvent { | ||
type: webviewEventType.SetEmitter | ||
emitterFunc: string | ||
} | ||
|
||
export enum webviewEventType { | ||
SetEmitter = 'SET_EMITTER', | ||
ShowPage = 'SHOW_DATA' | ||
} | ||
|
||
export type WebviewEvent = ShowPageEvent | SetEmitterEvent |
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
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 was deleted.
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
export interface IAnalysisStep { | ||
file: string | ||
fileName?: string | ||
row: number | ||
column: number | ||
startRow: number | ||
startColumn: number | ||
endRow: number | ||
endColumn: number | ||
snippet?: string | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.