Skip to content

Commit d51443c

Browse files
committed
Merge branch 'commands' into dev
2 parents 3c65653 + a6405e9 commit d51443c

24 files changed

+176
-128
lines changed

.vscode/launch.json

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
"runtimeExecutable": "${execPath}",
1010
"args": [
1111
"--disable-extensions",
12+
"--trace-warnings",
1213
"--trace-depreciation",
1314
"--extensionDevelopmentPath=${workspaceFolder}",
1415
"${workspaceFolder}/samplenc/sample-colors.nc",
1516
"${workspaceFolder}/samplenc/sample-profile.nc",
1617
"${workspaceFolder}/samplenc/sample-circular-pocket.nc"
1718
],
19+
"cwd": "${workspaceFolder}",
1820
"outFiles": [
1921
"${workspaceFolder}/dist/**/*.js"
2022
],
@@ -26,11 +28,12 @@
2628
"preLaunchTask": "npm: webpack",
2729
"skipFiles": [
2830
"<node_internals>/**",
29-
"**/node_modules/**"
31+
"**/node_modules/**",
32+
"**/resources/app/out/vs/**"
3033
],
3134
"smartStep": true,
3235
"sourceMaps": true,
33-
"trace": true
36+
"trace": true,
3437
},
3538
{
3639
"name": "Run G-Code (Sandbox)",
@@ -42,6 +45,7 @@
4245
"--trace-depreciation",
4346
"--extensionDevelopmentPath=${workspaceFolder}"
4447
],
48+
"cwd": "${workspaceFolder}",
4549
"outFiles": [
4650
"${workspaceFolder}/dist/**/*.js"
4751
],
@@ -53,7 +57,8 @@
5357
"preLaunchTask": "npm: webpack",
5458
"skipFiles": [
5559
"<node_internals>/**",
56-
"**/node_modules/**"
60+
"**/node_modules/**",
61+
"**/resources/app/out/vs/**"
5762
],
5863
"smartStep": true,
5964
"sourceMaps": true,
@@ -123,11 +128,18 @@
123128
"<node_internals>/**",
124129
"**/node_modules/**"
125130
],
131+
"presentation": {
132+
"hidden": false,
133+
"group": "Testing",
134+
"order": 1
135+
},
126136
"env": {
127137
"NODE_ENV": "testing",
128138
"TS_NODE_PROJECT": "./tsconfig.tests.json"
129139
},
130-
"sourceMaps": true
140+
"sourceMaps": true,
141+
"smartStep": true,
142+
"trace": true
131143
}
132144
]
133145
}

package.json

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,14 @@
6060
"onLanguage:gcode",
6161
"onView:gcode.gcodeTree",
6262
"onView:gcode.gcodeStats",
63+
"onCommand:gcode.addComment",
64+
"onCommand:gcode.addLineNumbers",
65+
"onCommand:gcode.removeComment",
66+
"onCommand:gcode.removeLineNumbers",
67+
"onCommand:gcode.showSettings",
68+
"onCommand:gcode.supportGCode",
6369
"onCommand:gcode.views.navTree.refresh",
64-
"onCommand:gcode.views.stats.refresh",
65-
"onCommand:gcode.supportGCode"
70+
"onCommand:gcode.views.stats.refresh"
6671
],
6772
"capabilities": {
6873
"virtualWorkspaces": true
@@ -353,38 +358,63 @@
353358
],
354359
"commandPalette": [
355360
{
356-
"command": "gcode.views.navTree.refresh",
357-
"when": "true"
361+
"command": "gcode.addComment",
362+
"when": "editorLangId == gcode"
358363
},
359364
{
360-
"command": "gcode.views.stats.refresh",
365+
"command": "gcode.addLineNumbers",
366+
"when": "editorLangId == gcode"
367+
},
368+
{
369+
"command": "gcode.removeComment",
370+
"when": "editorLangId == gcode"
371+
},
372+
{
373+
"command": "gcode.removeLineNumbers",
374+
"when": "editorLangId == gcode"
375+
},
376+
{
377+
"command": "gcode.showSettings",
361378
"when": "true"
362379
},
363380
{
364381
"command": "gcode.supportGCode",
365382
"when": "false"
383+
},
384+
{
385+
"command": "gcode.views.navTree.refresh",
386+
"when": "editorLangId == gcode"
387+
},
388+
{
389+
"command": "gcode.views.stats.refresh",
390+
"when": "editorLangId == gcode"
366391
}
367392
],
368393
"editor/context": [
369394
{
370-
"when": "resourceLangId == gcode",
395+
"when": "editorLangId == gcode",
371396
"command": "gcode.views.navTree.refresh",
372397
"group": "gcode"
373398
},
374399
{
375-
"when": "resourceLangId == gcode",
400+
"when": "editorLangId == gcode",
376401
"command": "gcode.views.stats.refresh",
377402
"group": "gcode"
378403
},
379404
{
380-
"when": "resourceLangId == gcode",
405+
"when": "editorLangId == gcode",
381406
"command": "gcode.addComment",
382407
"group": "gcode"
383408
},
384409
{
385-
"when": "resourceLangId == gcode",
410+
"when": "editorLangId == gcode",
386411
"command": "gcode.removeComment",
387412
"group": "gcode"
413+
},
414+
{
415+
"when": "editorLangId == gcode",
416+
"command": "gcode.showSettings",
417+
"group": "gcode"
388418
}
389419
]
390420
},
@@ -464,6 +494,7 @@
464494
"pretest": "npm run compile",
465495
"pretty": "prettier --config .prettierrc --loglevel warn .",
466496
"pub": "vsce publish",
497+
"refresh": "npm run clean && shx rm -rf ./node_modules && npm install",
467498
"test": "node ./out/test/runTests.js",
468499
"test:unit": "SET TS_NODE_PROJECT=./tsconfig.tests.json && mocha -r ts-node/register test/unit/*.test.ts",
469500
"vscode:prepublish": "npm run bundle",

src/control.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ import { StatusBarControl } from './util/statusBar';
1212
import { NavTreeView } from './views/navTreeView';
1313
import { GCodeUnitsController } from './gcodeUnits';
1414
import { StatsView } from './views/statsView';
15-
import { constants, Contexts, PIcon, VSBuiltInCommands } from './util/constants';
16-
import { UtilCommands } from './util/commands/common';
15+
import { constants, Contexts, GCommands, PIcon, VSBuiltInCommands } from './util/constants';
1716
import { Version } from './util/version';
1817
import { Messages } from './util/messages';
1918
import { StateControl } from './util/stateControl';
2019
import { CodesWebview } from './webviews/codesWebview';
2120
import { MachineTypeControl } from './util/machineType';
2221
import { GCodeHoverControl } from './hovers/gcodeHoverControl';
2322
import { defaults } from './util/configuration/defaults';
23+
import { registerCommands } from './util/commands/functions';
2424

2525
const cfgUnits = 'general.units';
2626
const cfgAutoRef = {
@@ -32,6 +32,7 @@ export class Control {
3232
private static _config: Config | undefined;
3333
private static _context: ExtensionContext;
3434
private static _units: string | undefined;
35+
private static _version: Version;
3536

3637
// Controllers
3738
private static _machineTypeControl: MachineTypeControl | undefined;
@@ -75,9 +76,16 @@ export class Control {
7576

7677
// Static Methods
7778
static initialize(context: ExtensionContext, config: Config) {
79+
// Initialize G-Code Extension
7880
this._context = context;
7981
this._config = config;
8082

83+
// Initialze Configuration
84+
Config.initialize(this._context, this._config);
85+
86+
// Register Commands
87+
context.subscriptions.push(...registerCommands());
88+
8189
// Load StatusBars
8290
context.subscriptions.push((this._statusBarControl = new StatusBarControl()));
8391

@@ -136,7 +144,7 @@ export class Control {
136144
'support',
137145
'Support G-Code Syntax ❤',
138146
undefined,
139-
UtilCommands.ShowSupportGCode,
147+
GCommands.ShowSupportGCode,
140148
);
141149

142150
// Check Version

src/extension.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
* -------------------------------------------------------------------------------------------- */
55
'use strict';
66
import { ExtensionContext } from 'vscode';
7-
import { Config, configuration } from './util/configuration/config';
7+
import { configuration } from './util/configuration/config';
88
import { constants } from './util/constants';
99
import { Logger } from './util/logger';
10-
import { registerCommands } from './util/commands';
1110
import { Control } from './control';
1211

1312
export function activate(context: ExtensionContext) {
@@ -17,13 +16,6 @@ export function activate(context: ExtensionContext) {
1716
Logger.initialize(context);
1817
Logger.enable();
1918

20-
// Initialize Config
21-
const cfg = configuration;
22-
Config.initialize(context, cfg);
23-
24-
// Register Commands
25-
void registerCommands(context);
26-
2719
// Initialize Controller
2820
Control.initialize(context, configuration);
2921

src/gcodeUnits.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
import { ConfigurationChangeEvent, Disposable, TextDocumentChangeEvent, TextEditor, window, workspace } from 'vscode';
88
import { Control } from './control';
9-
import { UtilCommands } from './util/commands/common';
109
import { configuration } from './util/configuration/config';
1110
import { defaults } from './util/configuration/defaults';
11+
import { GCommands } from './util/constants';
1212
import { Logger } from './util/logger';
1313
import { StatusBar, StatusBarControl } from './util/statusBar';
1414

@@ -39,7 +39,7 @@ export class GCodeUnitsController implements Disposable {
3939
this.unitsStatusBar,
4040
undefined,
4141
undefined,
42-
UtilCommands.ShowGCodeSettings,
42+
GCommands.ShowGCodeSettings,
4343
);
4444

4545
Control.context.subscriptions.push(configuration.onDidChange(this.onConfigurationChanged, this));
@@ -61,7 +61,7 @@ export class GCodeUnitsController implements Disposable {
6161
this.unitsStatusBar,
6262
undefined,
6363
undefined,
64-
UtilCommands.ShowGCodeSettings,
64+
GCommands.ShowGCodeSettings,
6565
);
6666
} else {
6767
Logger.log(`Units: ${this._units}`);
@@ -71,7 +71,7 @@ export class GCodeUnitsController implements Disposable {
7171
this.unitsStatusBar,
7272
undefined,
7373
undefined,
74-
UtilCommands.ShowGCodeSettings,
74+
GCommands.ShowGCodeSettings,
7575
);
7676
}
7777
}
@@ -91,7 +91,7 @@ export class GCodeUnitsController implements Disposable {
9191
this.unitsStatusBar,
9292
undefined,
9393
undefined,
94-
UtilCommands.ShowGCodeSettings,
94+
GCommands.ShowGCodeSettings,
9595
);
9696
} else {
9797
return;
@@ -112,7 +112,7 @@ export class GCodeUnitsController implements Disposable {
112112
this.unitsStatusBar,
113113
undefined,
114114
undefined,
115-
UtilCommands.ShowGCodeSettings,
115+
GCommands.ShowGCodeSettings,
116116
);
117117
} else {
118118
return;

src/hovers/gcodeHoverControl.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export class GCodeHoverControl implements Disposable {
2828
}
2929

3030
dispose() {
31+
this.unregister();
3132
this._disposable && this._disposable.dispose();
3233
}
3334

src/util/commands.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/util/commands/addComment.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
'use strict';
77

88
import { Range, window } from 'vscode';
9-
import { constants } from '../constants';
10-
import { GCommand, UtilCommands } from './common';
9+
import { constants, GCommands } from '../constants';
10+
import { GCommand } from './base';
1111

1212
export class AddComment extends GCommand {
1313
constructor() {
14-
super(UtilCommands.AddComment);
14+
super(GCommands.AddComment);
1515
}
1616

1717
execute() {

src/util/commands/addLineNumbers.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
'use strict';
77

88
import { configuration } from '../configuration/config';
9+
import { GCommands } from '../constants';
910
import { LineNumberer, LineNumbererOptions } from '../lineNumberer';
1011
import { LineNumbersInput } from '../quickpicks/lineNumbers';
11-
import { GCommand, UtilCommands } from './common';
12+
import { GCommand } from './base';
1213

1314
export class AddLineNumbers extends GCommand {
1415
constructor() {
15-
super(UtilCommands.AddLineNumbers);
16+
super(GCommands.AddLineNumbers);
1617
}
1718

1819
async execute() {
Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,22 @@
66
'use strict';
77

88
import { commands, Disposable } from 'vscode';
9-
10-
export const enum UtilCommands {
11-
ShowGCodeSettings = 'gcode.showSettings',
12-
ShowSupportGCode = 'gcode.supportGCode',
13-
AddComment = 'gcode.addComment',
14-
RemoveComment = 'gcode.removeComment',
15-
AddLineNumbers = 'gcode.addLineNumbers',
16-
RemoveLineNumbers = 'gcode.removeLineNumbers',
17-
}
9+
import { GCommands } from '../constants';
1810

1911
export abstract class GCommand implements Disposable {
20-
private _disposable: Disposable;
12+
private readonly _disposable: Disposable;
13+
14+
constructor(cmd: GCommands | GCommands[]) {
15+
if (typeof cmd === 'string') {
16+
this._disposable = commands.registerCommand(cmd, (...args: any[]) => this._execute(cmd, ...args), this);
2117

22-
constructor(cmd: UtilCommands) {
23-
this._disposable = commands.registerCommand(cmd, (...args: any[]) => this._execute(cmd, ...args), this);
18+
return;
19+
}
2420

25-
return;
21+
const subscriptions = cmd.map(cmd =>
22+
commands.registerCommand(cmd, (...args: any[]) => this._execute(cmd, ...args), this),
23+
);
24+
this._disposable = Disposable.from(...subscriptions);
2625
}
2726

2827
dispose() {

0 commit comments

Comments
 (0)