Skip to content

Commit c82fb86

Browse files
committed
Refactored views, moved listeners to appropriate directories and removed unused imports
1 parent 85adc15 commit c82fb86

20 files changed

+674
-579
lines changed

vscode/src/commands/commands.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { appendPrefixToCommand } from "../utils";
1818

1919
export const extCommands = {
2020
configureRunSettings: appendPrefixToCommand('workspace.configureRunSettings'),
21-
newFromTemplate : appendPrefixToCommand('workspace.new'),
21+
newFromTemplate: appendPrefixToCommand('workspace.new'),
2222
newProject: appendPrefixToCommand('workspace.newproject'),
2323
openTest: appendPrefixToCommand('open.test'),
2424
deleteCache: appendPrefixToCommand('delete.cache'),
@@ -47,6 +47,8 @@ export const extCommands = {
4747
nbEventListener: appendPrefixToCommand('addEventListener'),
4848
selectEditorProjs: appendPrefixToCommand('select.editor.projects'),
4949
attachDebugger: appendPrefixToCommand("java.attachDebugger.connector"),
50+
loadWorkspaceTests: appendPrefixToCommand("load.workspace.tests"),
51+
projectDeleteEntry: "javals.foundProjects.deleteEntry"
5052
}
5153

5254
export const builtInCommands = {
@@ -59,6 +61,7 @@ export const builtInCommands = {
5961
quickAccess: 'workbench.action.quickOpen',
6062
openSettings: 'workbench.action.openSettings',
6163
startDebug: 'workbench.action.debug.start',
64+
focusReplDebug: 'workbench.debug.action.focusRepl',
6265
}
6366

6467
export const nbCommands = {

vscode/src/commands/register.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { registerBuildOperationCommands } from "./buildOperations";
2323
import { registerRefactorCommands } from "./refactor";
2424
import { registerUtilCommands } from "./utilCommands";
2525
import { registerDebugCommands } from "./debug";
26+
import { registerRunConfigurationCommands } from "./runConfiguration";
2627

2728
type ICommandModules = Record<string, ICommand[]>;
2829

@@ -34,7 +35,8 @@ const commandModules: ICommandModules = {
3435
buildOperations: registerBuildOperationCommands,
3536
refactor: registerRefactorCommands,
3637
util: registerUtilCommands,
37-
debug: registerDebugCommands
38+
debug: registerDebugCommands,
39+
runConfiguration: registerRunConfigurationCommands
3840
}
3941

4042
export const subscribeCommands = (context: ExtensionContext) => {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Copyright (c) 2023-2024, Oracle and/or its affiliates.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
https://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import { extCommands } from "./commands";
18+
import { globalVars } from "../extension";
19+
import { configureRunSettings } from "../views/runConfiguration";
20+
import { ICommand } from "./types";
21+
22+
23+
const configureRunSettingsHandler = (...params: any[]) => {
24+
configureRunSettings(globalVars.extensionInfo.getExtensionContext(), params);
25+
}
26+
27+
28+
export const registerRunConfigurationCommands: ICommand[] = [{
29+
command: extCommands.configureRunSettings,
30+
handler: configureRunSettingsHandler
31+
}]

vscode/src/configurations/listener.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
Copyright (c) 2023-2024, Oracle and/or its affiliates.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
https://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import { ConfigurationChangeEvent, ExtensionContext, workspace } from "vscode";
18+
import { globalVars } from "../extension";
19+
import { userConfigsListened } from "./configuration";
20+
import { Disposable } from "vscode-languageclient";
21+
22+
const configChangeHandler = (params: ConfigurationChangeEvent) => {
23+
userConfigsListened.forEach((config: string) => {
24+
const doesAffect = params.affectsConfiguration(config);
25+
if (doesAffect) {
26+
globalVars.clientPromise.restartExtension(globalVars.nbProcessManager, true);
27+
}
28+
});
29+
}
30+
31+
const configChangeListener = workspace.onDidChangeConfiguration(configChangeHandler);
32+
33+
34+
const listeners: Disposable[] = [configChangeListener];
35+
36+
export const registerConfigChangeListeners = (context: ExtensionContext) => {
37+
listeners.forEach((listener: Disposable)=>{
38+
context.subscriptions.push(listener);
39+
});
40+
}

vscode/src/debugger/debugger.ts

Lines changed: 86 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ import { l10n } from '../localiser';
2424
import { StreamDebugAdapter } from './streamDebugAdapter';
2525
import { globalVars } from '../extension';
2626
import { extCommands, nbCommands } from '../commands/commands';
27+
import { argumentsNode, environmentVariablesNode, vmOptionsNode, workingDirectoryNode } from '../views/runConfiguration';
28+
import { initializeRunConfiguration } from '../utils';
2729

2830
export function registerDebugger(context: ExtensionContext): void {
29-
let debugTrackerFactory =new NetBeansDebugAdapterTrackerFactory();
31+
let debugTrackerFactory = new NetBeansDebugAdapterTrackerFactory();
3032
context.subscriptions.push(vscode.debug.registerDebugAdapterTrackerFactory(extConstants.COMMAND_PREFIX, debugTrackerFactory));
3133
let configInitialProvider = new NetBeansConfigurationInitialProvider();
3234
context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider(extConstants.COMMAND_PREFIX, configInitialProvider, vscode.DebugConfigurationProviderTriggerKind.Initial));
@@ -36,7 +38,12 @@ export function registerDebugger(context: ExtensionContext): void {
3638
context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider(extConstants.COMMAND_PREFIX, configResolver));
3739
context.subscriptions.push(vscode.debug.onDidTerminateDebugSession(((session) => onDidTerminateSession(session))));
3840
let debugDescriptionFactory = new NetBeansDebugAdapterDescriptionFactory();
39-
context.subscriptions.push(vscode.debug.registerDebugAdapterDescriptorFactory(extConstants.COMMAND_PREFIX, debugDescriptionFactory));
41+
context.subscriptions.push(vscode.debug.registerDebugAdapterDescriptorFactory(extConstants.COMMAND_PREFIX, debugDescriptionFactory));
42+
initializeRunConfiguration().then(initialized => {
43+
if (initialized) {
44+
context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider(extConstants.COMMAND_PREFIX, new RunConfigurationProvider()));
45+
}
46+
});
4047
};
4148

4249
class NetBeansDebugAdapterTrackerFactory implements vscode.DebugAdapterTrackerFactory {
@@ -66,13 +73,13 @@ class NetBeansDebugAdapterDescriptionFactory implements vscode.DebugAdapterDescr
6673
}
6774
} else {
6875
// resolve(new vscode.DebugAdapterServer(debugPort));
69-
const socket = net.connect(globalVars.debugPort, "127.0.0.1", () => {});
70-
socket.on("connect", () => {
71-
const adapter = new StreamDebugAdapter();
72-
socket.write(globalVars.debugHash ? globalVars.debugHash : "");
73-
adapter.connect(socket, socket);
74-
resolve(new vscode.DebugAdapterInlineImplementation(adapter));
75-
});
76+
const socket = net.connect(globalVars.debugPort, "127.0.0.1", () => { });
77+
socket.on("connect", () => {
78+
const adapter = new StreamDebugAdapter();
79+
socket.write(globalVars.debugHash ? globalVars.debugHash : "");
80+
adapter.connect(socket, socket);
81+
resolve(new vscode.DebugAdapterInlineImplementation(adapter));
82+
});
7683
}
7784
}
7885
fnc();
@@ -84,26 +91,26 @@ class NetBeansDebugAdapterDescriptionFactory implements vscode.DebugAdapterDescr
8491
class NetBeansConfigurationInitialProvider implements vscode.DebugConfigurationProvider {
8592

8693
provideDebugConfigurations(folder: vscode.WorkspaceFolder | undefined, token?: vscode.CancellationToken): vscode.ProviderResult<vscode.DebugConfiguration[]> {
87-
return this.doProvideDebugConfigurations(folder, token);
94+
return this.doProvideDebugConfigurations(folder, token);
8895
}
8996

90-
async doProvideDebugConfigurations(folder: vscode.WorkspaceFolder | undefined, _token?: vscode.CancellationToken): Promise<vscode.DebugConfiguration[]> {
91-
let c : LanguageClient = await globalVars.clientPromise.client;
97+
async doProvideDebugConfigurations(folder: vscode.WorkspaceFolder | undefined, _token?: vscode.CancellationToken): Promise<vscode.DebugConfiguration[]> {
98+
let c: LanguageClient = await globalVars.clientPromise.client;
9299
if (!folder) {
93100
return [];
94101
}
95-
var u : vscode.Uri | undefined;
102+
var u: vscode.Uri | undefined;
96103
if (folder && folder.uri) {
97104
u = folder.uri;
98105
} else {
99106
u = vscode.window.activeTextEditor?.document?.uri
100107
}
101-
let result : vscode.DebugConfiguration[] = [];
102-
const configNames : string[] | null | undefined = await vscode.commands.executeCommand(nbCommands.projectConfigurations, u?.toString());
108+
let result: vscode.DebugConfiguration[] = [];
109+
const configNames: string[] | null | undefined = await vscode.commands.executeCommand(nbCommands.projectConfigurations, u?.toString());
103110
if (configNames) {
104-
let first : boolean = true;
111+
let first: boolean = true;
105112
for (let cn of configNames) {
106-
let cname : string;
113+
let cname: string;
107114

108115
if (first) {
109116
// ignore the default config, comes first.
@@ -112,7 +119,7 @@ class NetBeansConfigurationInitialProvider implements vscode.DebugConfigurationP
112119
} else {
113120
cname = "Launch Java: " + cn;
114121
}
115-
const debugConfig : vscode.DebugConfiguration = {
122+
const debugConfig: vscode.DebugConfiguration = {
116123
name: cname,
117124
type: extConstants.COMMAND_PREFIX,
118125
request: "launch",
@@ -135,19 +142,19 @@ class NetBeansConfigurationDynamicProvider implements vscode.DebugConfigurationP
135142
}
136143

137144
provideDebugConfigurations(folder: vscode.WorkspaceFolder | undefined, token?: vscode.CancellationToken): vscode.ProviderResult<vscode.DebugConfiguration[]> {
138-
return this.doProvideDebugConfigurations(folder, this.context, this.commandValues, token);
145+
return this.doProvideDebugConfigurations(folder, this.context, this.commandValues, token);
139146
}
140147

141-
async doProvideDebugConfigurations(folder: vscode.WorkspaceFolder | undefined, context: ExtensionContext, commandValues: Map<string, string>, _token?: vscode.CancellationToken): Promise<vscode.DebugConfiguration[]> {
142-
let c : LanguageClient = await globalVars.clientPromise.client;
148+
async doProvideDebugConfigurations(folder: vscode.WorkspaceFolder | undefined, context: ExtensionContext, commandValues: Map<string, string>, _token?: vscode.CancellationToken): Promise<vscode.DebugConfiguration[]> {
149+
let c: LanguageClient = await globalVars.clientPromise.client;
143150
if (!folder) {
144151
return [];
145152
}
146-
let result : vscode.DebugConfiguration[] = [];
147-
const attachConnectors : DebugConnector[] | null | undefined = await vscode.commands.executeCommand(extCommands.attachDebugger);
153+
let result: vscode.DebugConfiguration[] = [];
154+
const attachConnectors: DebugConnector[] | null | undefined = await vscode.commands.executeCommand(extCommands.attachDebugger);
148155
if (attachConnectors) {
149156
for (let ac of attachConnectors) {
150-
const debugConfig : vscode.DebugConfiguration = {
157+
const debugConfig: vscode.DebugConfiguration = {
151158
name: ac.name,
152159
type: ac.type,
153160
request: "attach",
@@ -207,6 +214,61 @@ class NetBeansConfigurationResolver implements vscode.DebugConfigurationProvider
207214
}
208215
}
209216

217+
class RunConfigurationProvider implements vscode.DebugConfigurationProvider {
218+
219+
resolveDebugConfiguration(_folder: vscode.WorkspaceFolder | undefined, config: vscode.DebugConfiguration, _token?: vscode.CancellationToken): vscode.ProviderResult<vscode.DebugConfiguration> {
220+
return new Promise<vscode.DebugConfiguration>(resolve => {
221+
resolve(config);
222+
});
223+
}
224+
225+
resolveDebugConfigurationWithSubstitutedVariables?(_folder: vscode.WorkspaceFolder | undefined, config: vscode.DebugConfiguration, _token?: vscode.CancellationToken): vscode.ProviderResult<vscode.DebugConfiguration> {
226+
return new Promise<vscode.DebugConfiguration>(resolve => {
227+
const args = argumentsNode.getValue();
228+
if (args) {
229+
if (!config.args) {
230+
config.args = args;
231+
} else {
232+
config.args = `${config.args} ${args}`;
233+
}
234+
}
235+
236+
const vmArgs = vmOptionsNode.getValue();
237+
if (vmArgs) {
238+
if (!config.vmArgs) {
239+
config.vmArgs = vmArgs;
240+
} else {
241+
config.vmArgs = `${config.vmArgs} ${vmArgs}`;
242+
}
243+
}
244+
245+
const env = environmentVariablesNode.getValue();
246+
if (env) {
247+
const envs = env.split(',');
248+
if (!config.env) {
249+
config.env = {};
250+
}
251+
for (let val of envs) {
252+
val = val.trim();
253+
const div = val.indexOf('=');
254+
if (div > 0) { // div === 0 means bad format (no ENV name)
255+
config.env[val.substring(0, div)] = val.substring(div + 1, val.length);
256+
}
257+
}
258+
}
259+
260+
const cwd = workingDirectoryNode.getValue();
261+
if (cwd) {
262+
config.cwd = cwd;
263+
}
264+
265+
resolve(config);
266+
});
267+
}
268+
269+
}
270+
271+
210272
function onDidTerminateSession(session: vscode.DebugSession): any {
211273
const config = session.configuration;
212274
if (config.env) {

vscode/src/extension.ts

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ import { ExtensionContext, TextEditorDecorationType } from 'vscode';
2727

2828

2929
import * as vscode from 'vscode';
30-
import { NbTestAdapter } from './testAdapter';
31-
import { SetTextEditorDecorationParams} from './lsp/protocol';
30+
import { NbTestAdapter } from './views/TestViewController';
31+
import { SetTextEditorDecorationParams } from './lsp/protocol';
3232
import * as launchConfigurations from './launchConfigurations';
33-
import { initializeRunConfiguration, runConfigurationProvider, runConfigurationNodeProvider, configureRunSettings } from './runConfiguration';
3433
import { extConstants } from './constants';
3534
import { ExtensionInfo } from './extensionInfo';
3635
import { ClientPromise } from './lsp/clientPromise';
@@ -39,14 +38,14 @@ import { NbProcessManager } from './lsp/nbProcessManager';
3938
import { clientInit } from './lsp/initializer';
4039
import { subscribeCommands } from './commands/register';
4140
import { VSNetBeansAPI } from './lsp/types';
42-
import { registerListenersBeforeClientInit } from './listener';
4341
import { registerDebugger } from './debugger/debugger';
4442
import { registerConfigChangeListeners } from './configurations/listener';
4543
import { registerFileProviders } from './lsp/listeners/textDocumentContentProvider';
44+
import { createViews } from './views/initializer';
4645

4746
export let LOGGER: ExtensionLogger;
4847
export namespace globalVars {
49-
export const listeners = new Map<string, string[]>();
48+
export const listeners = new Map<string, string[]>();
5049
export let extensionInfo: ExtensionInfo;
5150
export let clientPromise: ClientPromise;
5251
export let debugPort: number = -1;
@@ -65,34 +64,22 @@ export function activate(context: ExtensionContext): VSNetBeansAPI {
6564
LOGGER = new ExtensionLogger(extConstants.SERVER_NAME);
6665

6766
globalVars.clientPromise.initialize();
68-
registerListenersBeforeClientInit();
67+
registerConfigChangeListeners(context);
6968
clientInit();
7069

71-
//register debugger:
7270
registerDebugger(context);
73-
// initialize Run Configuration
74-
initializeRunConfiguration().then(initialized => {
75-
if (initialized) {
76-
context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider(extConstants.COMMAND_PREFIX, runConfigurationProvider));
77-
context.subscriptions.push(vscode.window.registerTreeDataProvider('run-config', runConfigurationNodeProvider));
78-
context.subscriptions.push(vscode.commands.registerCommand(extConstants.COMMAND_PREFIX + '.workspace.configureRunSettings', (...params: any[]) => {
79-
configureRunSettings(context, params);
80-
}));
81-
vscode.commands.executeCommand('setContext', 'runConfigurationInitialized', true);
82-
}
83-
});
84-
85-
// register commands
8671
subscribeCommands(context);
72+
createViews(context);
8773
registerFileProviders(context);
88-
74+
8975
launchConfigurations.updateLaunchConfig();
9076

9177
// register completions:
9278
launchConfigurations.registerCompletion(context);
79+
9380
return Object.freeze({
94-
version : extConstants.API_VERSION,
95-
apiVersion : extConstants.API_VERSION
81+
version: extConstants.API_VERSION,
82+
apiVersion: extConstants.API_VERSION
9683
});
9784
}
9885

vscode/src/extensionInfo.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
import { Disposable, ExtensionContext } from "vscode";
1717

1818
export class ExtensionInfo {
19-
constructor(private context: ExtensionContext){}
19+
constructor(private context: ExtensionContext) { }
2020

21-
getGlobalStorage = () => this.context.globalStorageUri;
22-
getWorkspaceStorage = () => this.context.storageUri;
23-
getExtensionStorageUri = () => this.context.extensionUri;
24-
pushSubscription = (listener: Disposable) => this.context.subscriptions.push(listener);
21+
getGlobalStorage = () => this.context.globalStorageUri;
22+
getWorkspaceStorage = () => this.context.storageUri;
23+
getExtensionStorageUri = () => this.context.extensionUri;
24+
getExtensionContext = () => this.context;
25+
pushSubscription = (listener: Disposable) => this.context.subscriptions.push(listener);
2526
}

0 commit comments

Comments
 (0)