MCPcopy Index your code
hub / github.com/coderoad/coderoad-vscode / Channel

Class Channel

src/channel.ts:14–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12}
13
14class Channel implements Channel {
15 public context: Context
16 constructor(workspaceState: vscode.Memento) {
17 // workspaceState used for local storages
18 this.context = new Context(workspaceState)
19 }
20
21 // receive from webview
22 public receive = async (action: T.Action): Promise<void> => {
23 if (action.source !== 'coderoad') {
24 // filter out events from other extensions
25 return
26 }
27
28 // action may be an object.type or plain string
29 const actionType: string = typeof action === 'string' ? action : action.type
30
31 if (actionType === 'CLIENT_LOG') {
32 // logs in web client are not easily visible
33 // it's simpler to log to the "CodeRoad (Logs)" channel
34 logger(action.payload)
35 return
36 }
37
38 logger(actionType)
39
40 switch (actionType) {
41 case 'EDITOR_STARTUP':
42 actions.onStartup(this.context)
43 return
44 // clear tutorial local storage
45 // configure test runner, language, git
46 case 'EDITOR_TUTORIAL_CONFIG':
47 actions.onTutorialConfigNew(action, this.context)
48 return
49 case 'EDITOR_TUTORIAL_CONTINUE_CONFIG':
50 actions.onTutorialConfigContinue(action, this.context)
51 return
52 case 'EDITOR_VALIDATE_SETUP':
53 actions.onValidateSetup()
54 return
55 case 'EDITOR_REQUEST_WORKSPACE':
56 openWorkspace()
57 return
58 // load step actions (git commits, commands, open files)
59 case 'EDITOR_LEVEL_ENTER':
60 case 'EDITOR_STEP_ENTER':
61 await vscode.commands.executeCommand(COMMANDS.SET_CURRENT_POSITION, action.payload.position)
62 await hooks.onSetupEnter(action.payload.actions)
63 return
64 // load solution step actions (git commits, commands, open files)
65 case 'EDITOR_SOLUTION_ENTER':
66 await vscode.commands.executeCommand(COMMANDS.SET_CURRENT_POSITION, action.payload.position)
67 await hooks.onSolutionEnter(action.payload.actions)
68 return
69 case 'EDITOR_SYNC_POSITION':
70 // update progress when a level is deemed complete in the client
71 await this.context.position.set(action.payload.position)

Callers

nothing calls this directly

Calls 2

openWorkspaceFunction · 0.90
loggerFunction · 0.50

Tested by

no test coverage detected