Skip to content

Commit df8db18

Browse files
committed
builtin config keys added
1 parent af1466b commit df8db18

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

vscode/src/configurations/configuration.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,19 @@ export const configKeys = {
2828
runConfigCwd: 'runConfig.cwd',
2929
verbose: 'verbose',
3030
userdir: 'userdir',
31-
vscodeTheme: 'workbench.colorTheme'
3231
};
3332

34-
export const userConfigsListened = [
33+
export const builtInConfigKeys = {
34+
vscodeTheme: 'workbench.colorTheme'
35+
}
36+
37+
export const userConfigsListened: string[] = [
3538
appendPrefixToCommand(configKeys.jdkHome),
3639
appendPrefixToCommand(configKeys.userdir),
3740
appendPrefixToCommand(configKeys.lspVmOptions),
3841
appendPrefixToCommand(configKeys.disableNbJavac),
3942
appendPrefixToCommand(configKeys.disableProjSearchLimit),
40-
configKeys.vscodeTheme,
43+
builtInConfigKeys.vscodeTheme,
4144
];
4245

4346

vscode/src/configurations/handlers.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
limitations under the License.
1515
*/
1616
import { extensions, workspace } from "vscode";
17-
import { configKeys } from "./configuration";
17+
import { builtInConfigKeys, configKeys } from "./configuration";
1818
import { extConstants, NODE_WINDOWS_LABEL } from "../constants";
1919
import * as os from 'os';
2020
import { globalVars, LOGGER } from "../extension";
@@ -27,6 +27,14 @@ export const getConfigurationValue = <T>(key: string, defaultValue: T | undefine
2727
return defaultValue != undefined ? conf.get(key, defaultValue) : conf.get(key) as T;
2828
}
2929

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+
3038
export const jdkHomeValueHandler = (): string | null => {
3139
return getConfigurationValue(configKeys.jdkHome) ||
3240
process.env.JDK_HOME ||
@@ -71,8 +79,7 @@ export const lspServerVmOptionsHandler = (): string[] => {
7179
}
7280

7381
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);
7683
if (!themeName) {
7784
return false;
7885
}
@@ -110,12 +117,12 @@ export const userdirHandler = (): string => {
110117
const userdir = path.join(userdirParentDir, "userdir");
111118

112119
try {
113-
if(!fs.existsSync(userdir)){
120+
if (!fs.existsSync(userdir)) {
114121
fs.mkdirSync(userdir, { recursive: true });
115122
const stats = fs.statSync(userdir);
116123
if (!stats.isDirectory()) {
117124
throw new Error(`${userdir} is not a directory`);
118-
}
125+
}
119126
}
120127

121128
return userdir;
@@ -125,5 +132,5 @@ export const userdirHandler = (): string => {
125132
}
126133

127134
export const isNbJavacDisabledHandler = (): boolean => {
128-
return getConfigurationValue(configKeys.verbose, false);
135+
return getConfigurationValue(configKeys.verbose, false);
129136
}

vscode/src/lsp/launchOptions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
import { configKeys } from "../configurations/configuration"
16+
import { builtInConfigKeys, configKeys } from "../configurations/configuration"
1717
import { isDarkColorThemeHandler, isNbJavacDisabledHandler, jdkHomeValueHandler, lspServerVmOptionsHandler, projectSearchRootsValueHandler, userdirHandler } from "../configurations/handlers";
1818
import { l10n } from "../localiser";
1919
import { userDefinedLaunchOptionsType } from "./types"
@@ -35,7 +35,7 @@ export const getUserConfigLaunchOptionsDefaults = (): userDefinedLaunchOptionsTy
3535
value: isNbJavacDisabledHandler(),
3636
optionToPass: '-J-Dnetbeans.logger.console='
3737
},
38-
[configKeys.vscodeTheme]: {
38+
[builtInConfigKeys.vscodeTheme]: {
3939
value: isDarkColorThemeHandler() ? 'com.formdev.flatlaf.FlatDarkLaf' : null,
4040
optionToPass: ['--laf']
4141
},

0 commit comments

Comments
 (0)