14
14
limitations under the License.
15
15
*/
16
16
import { extensions , workspace } from "vscode" ;
17
- import { configKeys } from "./configuration" ;
17
+ import { builtInConfigKeys , configKeys } from "./configuration" ;
18
18
import { extConstants , NODE_WINDOWS_LABEL } from "../constants" ;
19
19
import * as os from 'os' ;
20
20
import { globalVars , LOGGER } from "../extension" ;
@@ -27,6 +27,14 @@ export const getConfigurationValue = <T>(key: string, defaultValue: T | undefine
27
27
return defaultValue != undefined ? conf . get ( key , defaultValue ) : conf . get ( key ) as T ;
28
28
}
29
29
30
+ export const getBuiltinConfigurationValue = < T > ( key : string , defaultValue : T | undefined = undefined ) : T => {
31
+ const splitKey = key . split ( '.' ) ;
32
+ const selector = splitKey ?. [ 0 ] ;
33
+ const conf = workspace . getConfiguration ( selector ) ;
34
+ const confKey = splitKey ?. slice ( 1 ) ?. join ( '.' ) ;
35
+ return defaultValue != undefined ? conf ?. get ( confKey , defaultValue ) : conf ?. get ( confKey ) as T ;
36
+ }
37
+
30
38
export const jdkHomeValueHandler = ( ) : string | null => {
31
39
return getConfigurationValue ( configKeys . jdkHome ) ||
32
40
process . env . JDK_HOME ||
@@ -71,8 +79,7 @@ export const lspServerVmOptionsHandler = (): string[] => {
71
79
}
72
80
73
81
export const isDarkColorThemeHandler = ( ) : boolean => {
74
- // const themeName = getConfigurationValue(configKeys.vscodeTheme);
75
- const themeName = workspace . getConfiguration ( 'workbench' ) ?. get ( 'colorTheme' ) ;
82
+ const themeName : string = getBuiltinConfigurationValue ( builtInConfigKeys . vscodeTheme ) ;
76
83
if ( ! themeName ) {
77
84
return false ;
78
85
}
@@ -110,12 +117,12 @@ export const userdirHandler = (): string => {
110
117
const userdir = path . join ( userdirParentDir , "userdir" ) ;
111
118
112
119
try {
113
- if ( ! fs . existsSync ( userdir ) ) {
120
+ if ( ! fs . existsSync ( userdir ) ) {
114
121
fs . mkdirSync ( userdir , { recursive : true } ) ;
115
122
const stats = fs . statSync ( userdir ) ;
116
123
if ( ! stats . isDirectory ( ) ) {
117
124
throw new Error ( `${ userdir } is not a directory` ) ;
118
- }
125
+ }
119
126
}
120
127
121
128
return userdir ;
@@ -125,5 +132,5 @@ export const userdirHandler = (): string => {
125
132
}
126
133
127
134
export const isNbJavacDisabledHandler = ( ) : boolean => {
128
- return getConfigurationValue ( configKeys . verbose , false ) ;
135
+ return getConfigurationValue ( configKeys . verbose , false ) ;
129
136
}
0 commit comments