Skip to content

Commit 5558cdb

Browse files
authored
Merge pull request #268 from Achal1607/code-cleanup
Doing some code cleanup and refactoring
2 parents 6079973 + bf41231 commit 5558cdb

File tree

3 files changed

+38
-41
lines changed

3 files changed

+38
-41
lines changed

NOTICE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ This product includes software developed at
22
The Apache Software Foundation (http://www.apache.org/).
33

44
Oracle Java Platform Extension for Visual Studio Code
5-
Copyright (c) 2023, Oracle and/or its affiliates.
5+
Copyright (c) 2023-2024, Oracle and/or its affiliates.
66

77
Apache NetBeans
8-
Copyright 2017-2023 The Apache Software Foundation
8+
Copyright 2017-2024 The Apache Software Foundation
99

1010
The code is based on NetBeans, that has been kindly donated to the Apache
1111
Software Foundation by Oracle.

build.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@
206206

207207
<target name="apply-patches" if="has-patches">
208208
<echo>${patches}</echo>
209-
<exec executable="git">
209+
<exec executable="git" failonerror="true">
210210
<arg value="apply"/>
211211
<arg value="--directory=netbeans"/>
212212
<arg value="--whitespace=nowarn"/>
@@ -235,7 +235,7 @@
235235
<arg value="${patches}" />
236236
</java>
237237
<echo>${reverse.patches}</echo>
238-
<exec executable="git">
238+
<exec executable="git" failonerror="true">
239239
<arg value="apply"/>
240240
<arg value="--directory=netbeans"/>
241241
<arg value="--whitespace=nowarn"/>

vscode/src/extension.ts

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ import { JdkDownloaderView } from './jdkDownloader/view';
7272

7373
const API_VERSION : string = "1.0";
7474
const SERVER_NAME : string = "Oracle Java SE Language Server";
75+
const NB_LANGUAGE_CLIENT_ID: string = "java";
76+
const LANGUAGE_ID: string = "java";
77+
7578
export const COMMAND_PREFIX : string = "jdk";
7679
const listeners = new Map<string, string[]>();
7780
let client: Promise<NbLanguageClient>;
@@ -171,15 +174,10 @@ function findJDK(onChange: (path : string | null) => void): void {
171174
let nowDark : boolean = isDarkColorTheme();
172175
let nowNbJavacDisabled : boolean = isNbJavacDisabled();
173176
function find(): string | null {
174-
let nbJdk = workspace.getConfiguration('jdk').get('jdkhome');
177+
let nbJdk = workspace.getConfiguration(COMMAND_PREFIX).get('jdkhome');
175178
if (nbJdk) {
176179
return nbJdk as string;
177180
}
178-
let javahome = workspace.getConfiguration('java').get('home');
179-
if (javahome) {
180-
return javahome as string;
181-
}
182-
183181
let jdkHome: any = process.env.JDK_HOME;
184182
if (jdkHome) {
185183
return jdkHome as string;
@@ -199,7 +197,7 @@ function findJDK(onChange: (path : string | null) => void): void {
199197
return;
200198
}
201199
let interested : boolean = false;
202-
if (params.affectsConfiguration('jdk') || params.affectsConfiguration('java')) {
200+
if (params.affectsConfiguration(COMMAND_PREFIX)) {
203201
interested = true;
204202
} else if (params.affectsConfiguration('workbench.colorTheme')) {
205203
let d = isDarkColorTheme();
@@ -215,7 +213,7 @@ function findJDK(onChange: (path : string | null) => void): void {
215213
let newJdk = find();
216214
let newD = isDarkColorTheme();
217215
let newNbJavacDisabled = isNbJavacDisabled();
218-
let newProjectJdk : string | undefined = workspace.getConfiguration('jdk')?.get('project.jdkhome') as string;
216+
let newProjectJdk : string | undefined = workspace.getConfiguration(COMMAND_PREFIX)?.get('project.jdkhome') as string;
219217
if (newJdk !== currentJdk || newD != nowDark || newNbJavacDisabled != nowNbJavacDisabled || newProjectJdk != projectJdk) {
220218
nowDark = newD;
221219
currentJdk = newJdk;
@@ -367,23 +365,22 @@ export function activate(context: ExtensionContext): VSNetBeansAPI {
367365

368366
//register debugger:
369367
let debugTrackerFactory =new NetBeansDebugAdapterTrackerFactory();
370-
context.subscriptions.push(vscode.debug.registerDebugAdapterTrackerFactory('jdk', debugTrackerFactory));
368+
context.subscriptions.push(vscode.debug.registerDebugAdapterTrackerFactory(COMMAND_PREFIX, debugTrackerFactory));
371369
let configInitialProvider = new NetBeansConfigurationInitialProvider();
372-
context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider('jdk', configInitialProvider, vscode.DebugConfigurationProviderTriggerKind.Initial));
370+
context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider(COMMAND_PREFIX, configInitialProvider, vscode.DebugConfigurationProviderTriggerKind.Initial));
373371
let configDynamicProvider = new NetBeansConfigurationDynamicProvider(context);
374-
context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider('jdk', configDynamicProvider, vscode.DebugConfigurationProviderTriggerKind.Dynamic));
372+
context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider(COMMAND_PREFIX, configDynamicProvider, vscode.DebugConfigurationProviderTriggerKind.Dynamic));
375373
let configResolver = new NetBeansConfigurationResolver();
376-
context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider('jdk', configResolver));
374+
context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider(COMMAND_PREFIX, configResolver));
377375
context.subscriptions.push(vscode.debug.onDidTerminateDebugSession(((session) => onDidTerminateSession(session))));
378376

379377
let debugDescriptionFactory = new NetBeansDebugAdapterDescriptionFactory();
380-
context.subscriptions.push(vscode.debug.registerDebugAdapterDescriptorFactory('jdk', debugDescriptionFactory));
378+
context.subscriptions.push(vscode.debug.registerDebugAdapterDescriptorFactory(COMMAND_PREFIX, debugDescriptionFactory));
381379

382380
// initialize Run Configuration
383381
initializeRunConfiguration().then(initialized => {
384382
if (initialized) {
385-
context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider('jdk', runConfigurationProvider));
386-
context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider('java', runConfigurationProvider));
383+
context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider(COMMAND_PREFIX, runConfigurationProvider));
387384
context.subscriptions.push(vscode.window.registerTreeDataProvider('run-config', runConfigurationNodeProvider));
388385
context.subscriptions.push(vscode.commands.registerCommand(COMMAND_PREFIX + '.workspace.configureRunSettings', (...params: any[]) => {
389386
configureRunSettings(context, params);
@@ -572,7 +569,7 @@ export function activate(context: ExtensionContext): VSNetBeansAPI {
572569
});
573570
}));
574571
context.subscriptions.push(commands.registerCommand(COMMAND_PREFIX + '.java.goto.super.implementation', async () => {
575-
if (window.activeTextEditor?.document.languageId !== "java") {
572+
if (window.activeTextEditor?.document.languageId !== LANGUAGE_ID) {
576573
return;
577574
}
578575
const uri = window.activeTextEditor.document.uri;
@@ -618,7 +615,7 @@ export function activate(context: ExtensionContext): VSNetBeansAPI {
618615
if (!Array.isArray(c)) {
619616
return undefined;
620617
}
621-
let f = c.filter((v) => v['type'] === 'jdk');
618+
let f = c.filter((v) => v['type'] === COMMAND_PREFIX);
622619
if (!f.length) {
623620
return undefined;
624621
}
@@ -631,10 +628,10 @@ export function activate(context: ExtensionContext): VSNetBeansAPI {
631628
}
632629
}
633630
let provider = new P();
634-
let d = vscode.debug.registerDebugConfigurationProvider('jdk', provider);
631+
let d = vscode.debug.registerDebugConfigurationProvider(COMMAND_PREFIX, provider);
635632
// let vscode to select a debug config
636633
return await vscode.commands.executeCommand('workbench.action.debug.start', { config: {
637-
type: 'jdk',
634+
type: COMMAND_PREFIX,
638635
mainClass: uri.toString()
639636
}, noDebug: true}).then((v) => {
640637
d.dispose();
@@ -650,7 +647,7 @@ export function activate(context: ExtensionContext): VSNetBeansAPI {
650647
if (docUri) {
651648
// attempt to find the active configuration in the vsode launch settings; undefined if no config is there.
652649
let debugConfig : vscode.DebugConfiguration = await findRunConfiguration(docUri) || {
653-
type: "jdk",
650+
type: COMMAND_PREFIX,
654651
name: "Java Single Debug",
655652
request: "launch"
656653
};
@@ -879,11 +876,11 @@ function isDarkColorTheme() : boolean {
879876
}
880877

881878
function isNbJavacDisabled() : boolean {
882-
return workspace.getConfiguration('jdk')?.get('advanced.disable.nbjavac') as boolean;
879+
return workspace.getConfiguration(COMMAND_PREFIX)?.get('advanced.disable.nbjavac') as boolean;
883880
}
884881

885882
function getProjectJDKHome() : string {
886-
return workspace.getConfiguration('jdk')?.get('project.jdkhome') as string;
883+
return workspace.getConfiguration(COMMAND_PREFIX)?.get('project.jdkhome') as string;
887884
}
888885

889886
function doActivateWithJDK(specifiedJDK: string | null, context: ExtensionContext, log : vscode.OutputChannel, notifyKill: boolean,
@@ -897,7 +894,7 @@ function doActivateWithJDK(specifiedJDK: string | null, context: ExtensionContex
897894
}, time);
898895
};
899896

900-
const netbeansConfig = workspace.getConfiguration('jdk');
897+
const netbeansConfig = workspace.getConfiguration(COMMAND_PREFIX);
901898
const beVerbose : boolean = netbeansConfig.get('verbose', false);
902899
let userdir = process.env['nbcode_userdir'] || netbeansConfig.get('userdir', 'local');
903900
switch (userdir) {
@@ -993,7 +990,7 @@ function doActivateWithJDK(specifiedJDK: string | null, context: ExtensionContex
993990
if (isDarkColorTheme()) {
994991
extras.push('--laf', 'com.formdev.flatlaf.FlatDarkLaf');
995992
}
996-
let serverVmOptions: string[] = workspace.getConfiguration('jdk').get("serverVmOptions",[]);
993+
let serverVmOptions: string[] = workspace.getConfiguration(COMMAND_PREFIX).get("serverVmOptions",[]);
997994
extras.push(...serverVmOptions.map(el => `-J${el}`));
998995
let p = launcher.launch(info, ...extras);
999996
handleLog(log, "LSP server launching: " + p.pid);
@@ -1087,7 +1084,7 @@ function doActivateWithJDK(specifiedJDK: string | null, context: ExtensionContex
10871084
});
10881085
const conf = workspace.getConfiguration();
10891086
let documentSelectors : DocumentSelector = [
1090-
{ language: 'java' },
1087+
{ language: LANGUAGE_ID },
10911088
{ language: 'yaml', pattern: '**/{application,bootstrap}*.yml' },
10921089
{ language: 'properties', pattern: '**/{application,bootstrap}*.properties' },
10931090
{ language: 'jackpot-hint' },
@@ -1101,12 +1098,12 @@ function doActivateWithJDK(specifiedJDK: string | null, context: ExtensionContex
11011098
documentSelector: documentSelectors,
11021099
synchronize: {
11031100
configurationSection: [
1104-
'jdk.hints',
1105-
'jdk.format',
1106-
'jdk.java.imports',
1107-
'jdk.project.jdkhome',
1108-
'jdk.runConfig.vmOptions',
1109-
'jdk.runConfig.cwd'
1101+
COMMAND_PREFIX + '.hints',
1102+
COMMAND_PREFIX + '.format',
1103+
COMMAND_PREFIX + '.java.imports',
1104+
COMMAND_PREFIX + '.project.jdkhome',
1105+
COMMAND_PREFIX + '.runConfig.vmOptions',
1106+
COMMAND_PREFIX + '.runConfig.cwd'
11101107
],
11111108
fileEvents: [
11121109
workspace.createFileSystemWatcher('**/*.java')
@@ -1143,7 +1140,7 @@ function doActivateWithJDK(specifiedJDK: string | null, context: ExtensionContex
11431140

11441141

11451142
let c = new NbLanguageClient(
1146-
'java',
1143+
NB_LANGUAGE_CLIENT_ID,
11471144
'Oracle Java SE',
11481145
connection,
11491146
log,
@@ -1324,7 +1321,7 @@ function doActivateWithJDK(specifiedJDK: string | null, context: ExtensionContex
13241321
}
13251322

13261323
ctx.subscriptions.push(window.onDidChangeActiveTextEditor(ed => {
1327-
const netbeansConfig = workspace.getConfiguration('jdk');
1324+
const netbeansConfig = workspace.getConfiguration(COMMAND_PREFIX);
13281325
if (netbeansConfig.get("revealActiveInProjects")) {
13291326
revealActiveEditor(ed);
13301327
}
@@ -1431,9 +1428,9 @@ function doActivateWithJDK(specifiedJDK: string | null, context: ExtensionContex
14311428
const settings = l10n.value("jdk.extension.nbjavac.label.openSettings");
14321429
window.showErrorMessage(message, enable, settings).then(reply => {
14331430
if (enable === reply) {
1434-
workspace.getConfiguration().update('jdk.advanced.disable.nbjavac', false);
1431+
workspace.getConfiguration().update(COMMAND_PREFIX + '.advanced.disable.nbjavac', false);
14351432
} else if (settings === reply) {
1436-
vscode.commands.executeCommand('workbench.action.openSettings', 'jdk.jdkhome');
1433+
vscode.commands.executeCommand('workbench.action.openSettings', COMMAND_PREFIX + '.jdkhome');
14371434
}
14381435
});
14391436
} else {
@@ -1578,7 +1575,7 @@ class NetBeansConfigurationInitialProvider implements vscode.DebugConfigurationP
15781575
}
15791576
const debugConfig : vscode.DebugConfiguration = {
15801577
name: cname,
1581-
type: "jdk",
1578+
type: COMMAND_PREFIX,
15821579
request: "launch",
15831580
launchConfiguration: cn,
15841581
};
@@ -1652,7 +1649,7 @@ class NetBeansConfigurationResolver implements vscode.DebugConfigurationProvider
16521649

16531650
resolveDebugConfiguration(_folder: vscode.WorkspaceFolder | undefined, config: vscode.DebugConfiguration, _token?: vscode.CancellationToken): vscode.ProviderResult<vscode.DebugConfiguration> {
16541651
if (!config.type) {
1655-
config.type = 'jdk';
1652+
config.type = COMMAND_PREFIX;
16561653
}
16571654
if (!config.request) {
16581655
config.request = 'launch';

0 commit comments

Comments
 (0)