1
- 'use strict' ;
2
-
3
- import { debug , ExtensionContext , languages , window , workspace } from 'vscode' ;
4
- import { GenerateStubCommandProvider } from './annotator/generateStub' ;
5
- import { CLI } from './cli' ;
6
- import { ConfigProvider } from './config/configProvider' ;
7
- import { ReferenceProvider } from './gaugeReference' ;
8
- import { GaugeState } from './gaugeState' ;
9
- import { GaugeWorkspace } from './gaugeWorkspace' ;
10
- import { ProjectInitializer } from './init/projectInit' ;
11
- import { ProjectFactory } from './project/projectFactory' ;
12
- import { hasActiveGaugeDocument } from './util' ;
13
- import { showInstallGaugeNotification , showWelcomeNotification } from './welcomeNotifications' ;
14
- import { GaugeClients as GaugeProjectClientMap } from './gaugeClients' ;
15
-
16
- const MINIMUM_SUPPORTED_GAUGE_VERSION = '0.9.6' ;
17
-
18
- const clientsMap : GaugeProjectClientMap = new GaugeProjectClientMap ( ) ;
19
-
20
- export async function activate ( context : ExtensionContext ) {
21
- let cli = CLI . instance ( ) ;
22
- if ( ! cli ) {
23
- return ;
24
- }
25
- let folders = workspace . workspaceFolders ;
26
- context . subscriptions . push ( new ProjectInitializer ( cli ) ) ;
27
- let hasGaugeProject = folders && folders . some ( ( f ) => ProjectFactory . isGaugeProject ( f . uri . fsPath ) ) ;
28
- if ( ! hasActiveGaugeDocument ( window . activeTextEditor ) && ! hasGaugeProject ) return ;
29
- if ( ! cli . isGaugeInstalled ( ) || ! cli . isGaugeVersionGreaterOrEqual ( MINIMUM_SUPPORTED_GAUGE_VERSION ) ) {
30
- return showInstallGaugeNotification ( ) ;
1
+ 'use strict' ;
2
+
3
+ import { debug , ExtensionContext , languages , window , workspace , ConfigurationTarget } from 'vscode' ;
4
+ import { GenerateStubCommandProvider } from './annotator/generateStub' ;
5
+ import { CLI } from './cli' ;
6
+ import { ConfigProvider } from './config/configProvider' ;
7
+ import { ReferenceProvider } from './gaugeReference' ;
8
+ import { GaugeState } from './gaugeState' ;
9
+ import { GaugeWorkspace } from './gaugeWorkspace' ;
10
+ import { ProjectInitializer } from './init/projectInit' ;
11
+ import { ProjectFactory } from './project/projectFactory' ;
12
+ import { hasActiveGaugeDocument } from './util' ;
13
+ import { showInstallGaugeNotification , showWelcomeNotification } from './welcomeNotifications' ;
14
+ import { GaugeClients as GaugeProjectClientMap } from './gaugeClients' ;
15
+ import { GaugeSemanticTokensProvider , legend } from './semanticTokensProvider' ;
16
+
17
+ const MINIMUM_SUPPORTED_GAUGE_VERSION = '0.9.6' ;
18
+
19
+ const clientsMap : GaugeProjectClientMap = new GaugeProjectClientMap ( ) ;
20
+
21
+ // This function reads Gauge-specific semantic token colors from the configuration
22
+ // and then updates the editor.semanticTokenColorCustomizations setting.
23
+ function updateGaugeSemanticTokenColors ( ) {
24
+ // Read Gauge settings from the gauge configuration section.
25
+ const gaugeConfig = workspace . getConfiguration ( "gauge.semanticTokenColors" ) ;
26
+ const colors = {
27
+ argument : gaugeConfig . get ( "argument" ) ,
28
+ stepMarker : gaugeConfig . get ( "stepMarker" ) ,
29
+ step : gaugeConfig . get ( "step" ) ,
30
+ table : gaugeConfig . get ( "table" ) ,
31
+ tableHeaderSeparator : gaugeConfig . get ( "tableHeaderSeparator" ) ,
32
+ tableBorder : gaugeConfig . get ( "tableBorder" ) ,
33
+ tagKeyword : gaugeConfig . get ( "tagKeyword" ) ,
34
+ tagValue : gaugeConfig . get ( "tagValue" ) ,
35
+ specification : gaugeConfig . get ( "specification" ) ,
36
+ scenario : gaugeConfig . get ( "scenario" ) ,
37
+ comment : gaugeConfig . get ( "comment" ) ,
38
+ disabledStep : gaugeConfig . get ( "disabledStep" )
39
+ } ;
40
+
41
+ // Build a new set of semantic token color rules.
42
+ const semanticTokenRules = {
43
+ "argument" : { "foreground" : colors . argument } ,
44
+ "stepMarker" : { "foreground" : colors . stepMarker } ,
45
+ "step" : { "foreground" : colors . step } ,
46
+ "table" : { "foreground" : colors . table } ,
47
+ "tableHeaderSeparator" : { "foreground" : colors . tableHeaderSeparator } ,
48
+ "tableBorder" : { "foreground" : colors . tableBorder } ,
49
+ "tagKeyword" : { "foreground" : colors . tagKeyword } ,
50
+ "tagValue" : { "foreground" : colors . tagValue } ,
51
+ "specification" : { "foreground" : colors . specification } ,
52
+ "scenario" : { "foreground" : colors . scenario } ,
53
+ "comment" : { "foreground" : colors . comment } ,
54
+ "disabledStep" : { "foreground" : colors . disabledStep }
55
+ } ;
56
+
57
+ // Get the current global editor configuration.
58
+ const editorConfig = workspace . getConfiguration ( "editor" ) ;
59
+
60
+ // Update the semantic token color customizations.
61
+ editorConfig . update ( "semanticTokenColorCustomizations" , { rules : semanticTokenRules } , ConfigurationTarget . Global ) ;
31
62
}
32
- showWelcomeNotification ( context ) ;
33
- languages . setLanguageConfiguration ( 'gauge' , { wordPattern : / ^ (?: [ * ] ) ( [ ^ * ] .* ) $ / g } ) ;
34
- let gaugeWorkspace = new GaugeWorkspace ( new GaugeState ( context ) , cli , clientsMap ) ;
35
-
36
- context . subscriptions . push (
37
- gaugeWorkspace ,
38
- new ReferenceProvider ( clientsMap ) ,
39
- new GenerateStubCommandProvider ( clientsMap ) ,
40
- new ConfigProvider ( context ) ,
41
- debug . registerDebugConfigurationProvider ( 'gauge' ,
42
- {
43
- resolveDebugConfiguration : ( ) => {
44
- throw Error ( "Starting with the Gauge debug configuration is not supported. Please use the 'Gauge' commands instead." ) ;
63
+
64
+ export async function activate ( context : ExtensionContext ) {
65
+ let cli = CLI . instance ( ) ;
66
+ if ( ! cli ) {
67
+ return ;
68
+ }
69
+ let folders = workspace . workspaceFolders ;
70
+ context . subscriptions . push ( new ProjectInitializer ( cli ) ) ;
71
+ let hasGaugeProject = folders && folders . some ( ( f ) => ProjectFactory . isGaugeProject ( f . uri . fsPath ) ) ;
72
+ if ( ! hasActiveGaugeDocument ( window . activeTextEditor ) && ! hasGaugeProject ) return ;
73
+ if ( ! cli . isGaugeInstalled ( ) || ! cli . isGaugeVersionGreaterOrEqual ( MINIMUM_SUPPORTED_GAUGE_VERSION ) ) {
74
+ return showInstallGaugeNotification ( ) ;
75
+ }
76
+ showWelcomeNotification ( context ) ;
77
+ languages . setLanguageConfiguration ( 'gauge' , { wordPattern : / ^ (?: [ * ] ) ( [ ^ * ] .* ) $ / g } ) ;
78
+ let gaugeWorkspace = new GaugeWorkspace ( new GaugeState ( context ) , cli , clientsMap ) ;
79
+ updateGaugeSemanticTokenColors ( ) ;
80
+
81
+ context . subscriptions . push (
82
+ gaugeWorkspace ,
83
+ new ReferenceProvider ( clientsMap ) ,
84
+ new GenerateStubCommandProvider ( clientsMap ) ,
85
+ new ConfigProvider ( context ) ,
86
+ debug . registerDebugConfigurationProvider ( 'gauge' ,
87
+ {
88
+ resolveDebugConfiguration : ( ) => {
89
+ throw Error ( "Starting with the Gauge debug configuration is not supported. Please use the 'Gauge' commands instead." ) ;
90
+ }
91
+ } ) ,
92
+ languages . registerDocumentSemanticTokensProvider (
93
+ { language : 'gauge' } ,
94
+ new GaugeSemanticTokensProvider ( ) ,
95
+ legend
96
+ ) ,
97
+ workspace . onDidChangeConfiguration ( ( e ) => {
98
+ if ( e . affectsConfiguration ( "gauge.semanticTokenColors" ) ) {
99
+ updateGaugeSemanticTokenColors ( ) ;
45
100
}
46
101
} )
47
- ) ;
48
- }
102
+ ) ;
103
+ }
49
104
50
- export function deactivate ( ) : Thenable < void > {
51
- const promises : Thenable < void > [ ] = [ ] ;
105
+ export function deactivate ( ) : Thenable < void > {
106
+ const promises : Thenable < void > [ ] = [ ] ;
52
107
53
- for ( const { client} of clientsMap . values ( ) ) {
54
- promises . push ( client . stop ( ) ) ;
55
- }
56
- return Promise . all ( promises ) . then ( ( ) => undefined ) ;
57
- }
108
+ for ( const { client } of clientsMap . values ( ) ) {
109
+ promises . push ( client . stop ( ) ) ;
110
+ }
111
+ return Promise . all ( promises ) . then ( ( ) => undefined ) ;
112
+ }
0 commit comments