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' ;
718import { 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+
999export 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
49151export 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 ;
0 commit comments