Skip to content

Commit a2aea91

Browse files
committed
changes to config classes
1 parent 255ab25 commit a2aea91

File tree

2 files changed

+122
-5
lines changed

2 files changed

+122
-5
lines changed

src/util/configuration/config.ts

Lines changed: 115 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,103 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
2+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
13
/* ---------------------------------------------------------------------------------------------
24
* Copyright (c) Applied Eng & Design All rights reserved.
35
* Licensed under the MIT License. See License.md in the project root for license information.
46
* -------------------------------------------------------------------------------------------- */
57
'use strict';
6-
import { ConfigurationChangeEvent, ConfigurationScope, Event, EventEmitter, ExtensionContext, workspace } from 'vscode';
8+
import {
9+
ConfigurationChangeEvent,
10+
ConfigurationScope,
11+
Event,
12+
EventEmitter,
13+
ExtensionContext,
14+
extensions,
15+
StatusBarAlignment,
16+
workspace,
17+
} from 'vscode';
718
import { constants } from '../constants';
8-
import { Logger } from '../logger';
19+
import { Logger, TraceLevel } from '../logger';
20+
import { LineNumberFrequency } from '../lineNumberer';
21+
22+
import { GCodeUnits } from '../../gcodeUnits';
23+
24+
export interface GCodeConfiguration {
25+
general: {
26+
machineType: 'Mill' | 'Lathe' | '3D Printer';
27+
28+
hovers: {
29+
enabled: boolean;
30+
};
31+
32+
statusBars: {
33+
enabled: boolean;
34+
alignment: StatusBarAlignment;
35+
};
36+
37+
units: GCodeUnits;
38+
39+
outputLevel: TraceLevel;
40+
};
41+
42+
lineNumberer: {
43+
addSpaceAfter: boolean;
44+
frequency: LineNumberFrequency;
45+
ignoreBlank: boolean;
46+
ignoreProgramNumbers: boolean;
47+
};
48+
49+
views: {
50+
maxAutoRefresh: number;
51+
52+
navTree: {
53+
autoRefresh: boolean;
54+
};
55+
56+
stats: {
57+
autoRefresh: boolean;
58+
};
59+
};
60+
61+
webviews: {
62+
enabled: boolean;
63+
};
64+
}
65+
66+
export const defaults: GCodeConfiguration = {
67+
general: {
68+
machineType: 'Mill',
69+
hovers: {
70+
enabled: true,
71+
},
72+
statusBars: {
73+
enabled: true,
74+
alignment: StatusBarAlignment.Left,
75+
},
76+
units: GCodeUnits.Auto,
77+
outputLevel: TraceLevel.Verbose,
78+
},
79+
lineNumberer: {
80+
addSpaceAfter: true,
81+
frequency: LineNumberFrequency.EveryLine,
82+
ignoreBlank: true,
83+
ignoreProgramNumbers: true,
84+
},
85+
views: {
86+
maxAutoRefresh: 10000,
87+
navTree: {
88+
autoRefresh: true,
89+
},
90+
stats: {
91+
autoRefresh: false,
92+
},
93+
},
94+
webviews: {
95+
enabled: true,
96+
},
97+
};
98+
999
export class Config {
100+
private static _defaults: GCodeConfiguration;
10101
private _onDidChange = new EventEmitter<ConfigurationChangeEvent>();
11102
get onDidChange(): Event<ConfigurationChangeEvent> {
12103
return this._onDidChange.event;
@@ -22,7 +113,6 @@ export class Config {
22113
this._onDidChange.fire(e);
23114
}
24115

25-
// Get Parameter
26116
getParam<T>(param: string, scope?: ConfigurationScope, defaultValue?: T): T | undefined {
27117
return defaultValue === undefined
28118
? workspace.getConfiguration(constants.configId, scope).get<T>(param)
@@ -44,6 +134,28 @@ export class Config {
44134
changed(e: ConfigurationChangeEvent, section: string, scope?: ConfigurationScope): boolean {
45135
return e.affectsConfiguration(`${constants.configId}.${section}`, scope) ?? true;
46136
}
137+
138+
static get defaults() {
139+
return this._defaults;
140+
}
141+
142+
private buildDefaults() {
143+
const gcode = extensions.getExtension(constants.extensionQualifiedId);
144+
145+
if (gcode) {
146+
const pkgCfg = gcode.packageJSON.contrubutes.configuration;
147+
}
148+
}
47149
}
48150

49151
export const configuration = new Config();
152+
153+
export const cfg = new Proxy(defaults, {
154+
get: function (name: GCodeConfiguration, prop: string): string | undefined {
155+
if (!(prop in name)) {
156+
return undefined;
157+
}
158+
},
159+
});
160+
161+
cfg.general.machineType;

src/util/configuration/defaults.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
2+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
13
/* ---------------------------------------------------------------------------------------------
24
* Copyright (c) Applied Eng & Design All rights reserved.
35
* Licensed under the MIT License. See License.md in the project root for license information.
46
* -------------------------------------------------------------------------------------------- */
57

68
'use strict';
79

8-
import { StatusBarAlignment } from 'vscode';
10+
import { extensions, StatusBarAlignment } from 'vscode';
911
import { GCodeUnits } from '../../gcodeUnits';
12+
import { constants } from '../constants';
1013
import { LineNumberFrequency } from '../lineNumberer';
1114
import { TraceLevel } from '../logger';
1215

13-
interface GCodeConfiguration {
16+
export interface GCodeConfiguration {
1417
general: {
1518
machineType: 'Mill' | 'Lathe' | '3D Printer';
1619

@@ -52,6 +55,8 @@ interface GCodeConfiguration {
5255
};
5356
}
5457

58+
const pkgCfg = extensions.getExtension(constants.extensionQualifiedId)!.packageJSON.contrubutes.configuration;
59+
5560
export const defaults: GCodeConfiguration = {
5661
general: {
5762
machineType: 'Mill',

0 commit comments

Comments
 (0)