|
1 | 1 | import * as vscode from 'vscode' |
2 | 2 | import * as CR from 'typings' |
3 | | -import { createCommands } from './commands' |
| 3 | +import {createCommands} from './commands' |
4 | 4 | import * as storage from '../services/storage' |
5 | 5 | import * as git from '../services/git' |
6 | 6 | import * as position from '../services/position' |
7 | 7 |
|
8 | 8 | interface Props { |
9 | | - machine: CR.StateMachine |
10 | | - setWorkspaceRoot(rootPath: string): void |
| 9 | + machine: CR.StateMachine |
| 10 | + setWorkspaceRoot(rootPath: string): void |
11 | 11 | } |
12 | 12 |
|
13 | 13 | class Editor { |
14 | | - // extension context set on activation |
15 | | - // @ts-ignore |
16 | | - private context: vscode.ExtensionContext |
17 | | - private machine: CR.StateMachine |
| 14 | + // extension context set on activation |
| 15 | + // @ts-ignore |
| 16 | + private vscodeExt: vscode.ExtensionContext |
| 17 | + private machine: CR.StateMachine |
18 | 18 |
|
19 | | - constructor({ machine, setWorkspaceRoot }: Props) { |
20 | | - this.machine = machine |
| 19 | + constructor({machine, setWorkspaceRoot}: Props) { |
| 20 | + this.machine = machine |
21 | 21 |
|
22 | | - // set workspace root for node executions |
23 | | - const { workspace } = vscode |
24 | | - const { rootPath } = workspace |
25 | | - if (!rootPath) { |
26 | | - throw new Error('Requires a workspace. Please open a folder') |
27 | | - } |
28 | | - setWorkspaceRoot(rootPath) |
29 | | - } |
30 | | - public activate = (context: vscode.ExtensionContext): void => { |
31 | | - console.log('ACTIVATE!') |
32 | | - this.context = context |
33 | | - // commands |
34 | | - this.activateCommands() |
| 22 | + // set workspace root for node executions |
| 23 | + const {workspace} = vscode |
| 24 | + const {rootPath} = workspace |
| 25 | + if (!rootPath) { |
| 26 | + throw new Error('Requires a workspace. Please open a folder') |
| 27 | + } |
| 28 | + setWorkspaceRoot(rootPath) |
| 29 | + } |
| 30 | + public activate = (vscodeExt: vscode.ExtensionContext): void => { |
| 31 | + console.log('ACTIVATE!') |
| 32 | + this.vscodeExt = vscodeExt |
| 33 | + // commands |
| 34 | + this.activateCommands() |
35 | 35 |
|
36 | | - // setup tasks or views here |
37 | | - } |
38 | | - public deactivate = (): void => { |
39 | | - console.log('DEACTIVATE!') |
40 | | - // cleanup subscriptions/tasks |
41 | | - for (const disposable of this.context.subscriptions) { |
42 | | - disposable.dispose() |
43 | | - } |
44 | | - // shut down state machine |
45 | | - console.log('deactivate machine') |
46 | | - this.machine.deactivate() |
47 | | - } |
| 36 | + // setup tasks or views here |
| 37 | + } |
| 38 | + public deactivate = (): void => { |
| 39 | + console.log('DEACTIVATE!') |
| 40 | + // cleanup subscriptions/tasks |
| 41 | + for (const disposable of this.vscodeExt.subscriptions) { |
| 42 | + disposable.dispose() |
| 43 | + } |
| 44 | + // shut down state machine |
| 45 | + console.log('deactivate machine') |
| 46 | + this.machine.deactivate() |
| 47 | + } |
48 | 48 |
|
49 | | - // execute vscode command |
50 | | - public dispatch = (type: string, payload?: any) => { |
51 | | - vscode.commands.executeCommand(type, payload) |
52 | | - } |
| 49 | + // execute vscode command |
| 50 | + public dispatch = (type: string, payload?: any) => { |
| 51 | + vscode.commands.executeCommand(type, payload) |
| 52 | + } |
53 | 53 |
|
54 | | - private activateCommands = (): void => { |
55 | | - const commands = createCommands({ |
56 | | - context: this.context, |
57 | | - machine: this.machine, |
58 | | - storage, |
59 | | - git, |
60 | | - position, |
61 | | - }) |
62 | | - for (const cmd in commands) { |
63 | | - const command: vscode.Disposable = vscode.commands.registerCommand(cmd, commands[cmd]) |
64 | | - this.context.subscriptions.push(command) |
65 | | - } |
66 | | - } |
| 54 | + private activateCommands = (): void => { |
| 55 | + const commands = createCommands({ |
| 56 | + vscodeExt: this.vscodeExt, |
| 57 | + machine: this.machine, |
| 58 | + git, |
| 59 | + }) |
| 60 | + for (const cmd in commands) { |
| 61 | + const command: vscode.Disposable = vscode.commands.registerCommand(cmd, commands[cmd]) |
| 62 | + this.vscodeExt.subscriptions.push(command) |
| 63 | + } |
| 64 | + } |
67 | 65 | } |
68 | 66 |
|
69 | 67 | export default Editor |
0 commit comments