1
1
import * as vscode from 'vscode' ;
2
2
import { log } from "./util" ;
3
3
4
- export interface InlayHintOptions {
5
- typeHints : boolean ;
6
- parameterHints : boolean ;
7
- maxLength : number | null ;
8
- }
9
-
10
- export interface CargoWatchOptions {
11
- enable : boolean ;
12
- arguments : string [ ] ;
13
- command : string ;
14
- allTargets : boolean ;
15
- }
16
-
17
- export interface CargoFeatures {
18
- noDefaultFeatures : boolean ;
19
- allFeatures : boolean ;
20
- features : string [ ] ;
21
- loadOutDirsFromCheck : boolean ;
22
- }
23
-
24
4
export type UpdatesChannel = "stable" | "nightly" ;
25
5
26
6
export const NIGHTLY_TAG = "nightly" ;
7
+
27
8
export class Config {
28
9
readonly extensionId = "matklad.rust-analyzer" ;
29
10
@@ -50,25 +31,24 @@ export class Config {
50
31
. packageJSON
51
32
. releaseTag ?? undefined ;
52
33
53
- private cfg ! : vscode . WorkspaceConfiguration ;
34
+ readonly globalStoragePath : string ;
54
35
55
- constructor ( private readonly ctx : vscode . ExtensionContext ) {
56
- vscode . workspace . onDidChangeConfiguration ( this . onConfigChange , this , ctx . subscriptions ) ;
57
- this . refreshConfig ( ) ;
36
+ constructor ( ctx : vscode . ExtensionContext ) {
37
+ this . globalStoragePath = ctx . globalStoragePath ;
38
+ vscode . workspace . onDidChangeConfiguration ( this . onDidChangeConfiguration , this , ctx . subscriptions ) ;
39
+ this . refreshLogging ( ) ;
58
40
}
59
41
60
- private refreshConfig ( ) {
61
- this . cfg = vscode . workspace . getConfiguration ( this . rootSection ) ;
62
- const enableLogging = this . cfg . get ( "trace.extension" ) as boolean ;
63
- log . setEnabled ( enableLogging ) ;
42
+ private refreshLogging ( ) {
43
+ log . setEnabled ( this . traceExtension ) ;
64
44
log . debug (
65
45
"Extension version:" , this . packageJsonVersion ,
66
46
"using configuration:" , this . cfg
67
47
) ;
68
48
}
69
49
70
- private async onConfigChange ( event : vscode . ConfigurationChangeEvent ) {
71
- this . refreshConfig ( ) ;
50
+ private async onDidChangeConfiguration ( event : vscode . ConfigurationChangeEvent ) {
51
+ this . refreshLogging ( ) ;
72
52
73
53
const requiresReloadOpt = this . requiresReloadOpts . find (
74
54
opt => event . affectsConfiguration ( opt )
@@ -86,49 +66,53 @@ export class Config {
86
66
}
87
67
}
88
68
89
- get globalStoragePath ( ) : string { return this . ctx . globalStoragePath ; }
90
-
91
69
// We don't do runtime config validation here for simplicity. More on stackoverflow:
92
70
// https://stackoverflow.com/questions/60135780/what-is-the-best-way-to-type-check-the-configuration-for-vscode-extension
93
71
94
- get serverPath ( ) { return this . cfg . get ( "serverPath" ) as null | string ; }
95
- get channel ( ) { return this . cfg . get < "stable" | "nightly" > ( "updates.channel" ) ! ; }
96
- get askBeforeDownload ( ) { return this . cfg . get ( "updates.askBeforeDownload" ) as boolean ; }
97
- get highlightingSemanticTokens ( ) { return this . cfg . get ( "highlighting.semanticTokens" ) as boolean ; }
98
- get highlightingOn ( ) { return this . cfg . get ( "highlightingOn" ) as boolean ; }
99
- get rainbowHighlightingOn ( ) { return this . cfg . get ( "rainbowHighlightingOn" ) as boolean ; }
100
- get lruCapacity ( ) { return this . cfg . get ( "lruCapacity" ) as null | number ; }
101
- get inlayHints ( ) : InlayHintOptions {
72
+ private get cfg ( ) : vscode . WorkspaceConfiguration {
73
+ return vscode . workspace . getConfiguration ( this . rootSection ) ;
74
+ }
75
+
76
+ get serverPath ( ) { return this . cfg . get < null | string > ( "serverPath" ) ! ; }
77
+ get channel ( ) { return this . cfg . get < UpdatesChannel > ( "updates.channel" ) ! ; }
78
+ get askBeforeDownload ( ) { return this . cfg . get < boolean > ( "updates.askBeforeDownload" ) ! ; }
79
+ get highlightingSemanticTokens ( ) { return this . cfg . get < boolean > ( "highlighting.semanticTokens" ) ! ; }
80
+ get highlightingOn ( ) { return this . cfg . get < boolean > ( "highlightingOn" ) ! ; }
81
+ get rainbowHighlightingOn ( ) { return this . cfg . get < boolean > ( "rainbowHighlightingOn" ) ! ; }
82
+ get lruCapacity ( ) { return this . cfg . get < null | number > ( "lruCapacity" ) ! ; }
83
+ get excludeGlobs ( ) { return this . cfg . get < string [ ] > ( "excludeGlobs" ) ! ; }
84
+ get useClientWatching ( ) { return this . cfg . get < boolean > ( "useClientWatching" ) ! ; }
85
+ get featureFlags ( ) { return this . cfg . get < Record < string , boolean > > ( "featureFlags" ) ! ; }
86
+ get rustfmtArgs ( ) { return this . cfg . get < string [ ] > ( "rustfmtArgs" ) ! ; }
87
+ get loadOutDirsFromCheck ( ) { return this . cfg . get < boolean > ( "loadOutDirsFromCheck" ) ! ; }
88
+ get traceExtension ( ) { return this . cfg . get < boolean > ( "trace.extension" ) ! ; }
89
+
90
+ // for internal use
91
+ get withSysroot ( ) { return this . cfg . get < boolean > ( "withSysroot" , true ) ! ; }
92
+
93
+ get inlayHints ( ) {
102
94
return {
103
- typeHints : this . cfg . get ( "inlayHints.typeHints" ) as boolean ,
104
- parameterHints : this . cfg . get ( "inlayHints.parameterHints" ) as boolean ,
105
- maxLength : this . cfg . get ( "inlayHints.maxLength" ) as null | number ,
95
+ typeHints : this . cfg . get < boolean > ( "inlayHints.typeHints" ) ! ,
96
+ parameterHints : this . cfg . get < boolean > ( "inlayHints.parameterHints" ) ! ,
97
+ maxLength : this . cfg . get < null | number > ( "inlayHints.maxLength" ) ! ,
106
98
} ;
107
99
}
108
- get excludeGlobs ( ) { return this . cfg . get ( "excludeGlobs" ) as string [ ] ; }
109
- get useClientWatching ( ) { return this . cfg . get ( "useClientWatching" ) as boolean ; }
110
- get featureFlags ( ) { return this . cfg . get ( "featureFlags" ) as Record < string , boolean > ; }
111
- get rustfmtArgs ( ) { return this . cfg . get ( "rustfmtArgs" ) as string [ ] ; }
112
- get loadOutDirsFromCheck ( ) { return this . cfg . get ( "loadOutDirsFromCheck" ) as boolean ; }
113
100
114
- get cargoWatchOptions ( ) : CargoWatchOptions {
101
+ get cargoWatchOptions ( ) {
115
102
return {
116
- enable : this . cfg . get ( "cargo-watch.enable" ) as boolean ,
117
- arguments : this . cfg . get ( "cargo-watch.arguments" ) as string [ ] ,
118
- allTargets : this . cfg . get ( "cargo-watch.allTargets" ) as boolean ,
119
- command : this . cfg . get ( "cargo-watch.command" ) as string ,
103
+ enable : this . cfg . get < boolean > ( "cargo-watch.enable" ) ! ,
104
+ arguments : this . cfg . get < string [ ] > ( "cargo-watch.arguments" ) ! ,
105
+ allTargets : this . cfg . get < boolean > ( "cargo-watch.allTargets" ) ! ,
106
+ command : this . cfg . get < string > ( "cargo-watch.command" ) ! ,
120
107
} ;
121
108
}
122
109
123
- get cargoFeatures ( ) : CargoFeatures {
110
+ get cargoFeatures ( ) {
124
111
return {
125
- noDefaultFeatures : this . cfg . get ( "cargoFeatures.noDefaultFeatures" ) as boolean ,
126
- allFeatures : this . cfg . get ( "cargoFeatures.allFeatures" ) as boolean ,
127
- features : this . cfg . get ( "cargoFeatures.features" ) as string [ ] ,
128
- loadOutDirsFromCheck : this . cfg . get ( "cargoFeatures.loadOutDirsFromCheck" ) as boolean ,
112
+ noDefaultFeatures : this . cfg . get < boolean > ( "cargoFeatures.noDefaultFeatures" ) ! ,
113
+ allFeatures : this . cfg . get < boolean > ( "cargoFeatures.allFeatures" ) ! ,
114
+ features : this . cfg . get < string [ ] > ( "cargoFeatures.features" ) ! ,
115
+ loadOutDirsFromCheck : this . cfg . get < boolean > ( "cargoFeatures.loadOutDirsFromCheck" ) ! ,
129
116
} ;
130
117
}
131
-
132
- // for internal use
133
- get withSysroot ( ) { return this . cfg . get ( "withSysroot" , true ) as boolean ; }
134
118
}
0 commit comments