Skip to content

Commit a49d15b

Browse files
committed
refactored some more commands
Fixed tests fixed npm scripts
1 parent 725efde commit a49d15b

15 files changed

+182
-610
lines changed

vscode/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -773,9 +773,9 @@
773773
"compile": "tsc -p ./ && node ./esbuild.js",
774774
"watch": "tsc -watch -p ./ | node ./esbuild.js --watch",
775775
"test": "npm run compile && node ./out/test/runTest.js",
776-
"nbcode": "node ./out/nbcode.js",
777-
"nbjavac": "node ./out/nbcode.js -J-Dnetbeans.close=true --modules --install .*nbjavac.*",
778-
"apisupport": "node ./out/nbcode.js -J-Dnetbeans.close=true --modules --install '(org.netbeans.libs.xerces|org.netbeans.modules.editor.structure|org.netbeans.modules.xml|org.netbeans.modules.xml.axi|org.netbeans.modules.xml.retriever|org.netbeans.modules.xml.schema.model|org.netbeans.modules.xml.tax|org.netbeans.modules.xml.text|org.netbeans.modules.ant.browsetask|.*apisupport.*|org.netbeans.modules.debugger.jpda.ant)' && node ./out/nbcode.js -J-Dnetbeans.close=true --modules --enable .*apisupport.ant",
776+
"nbcode": "node ./out/test/launchNbcode.js",
777+
"nbjavac": "node ./out/test/launchNbcode.js -J-Dnetbeans.close=true --modules --install .*nbjavac.*",
778+
"apisupport": "node ./out/test/launchNbcode.js -J-Dnetbeans.close=true --modules --install '(org.netbeans.libs.xerces|org.netbeans.modules.editor.structure|org.netbeans.modules.xml|org.netbeans.modules.xml.axi|org.netbeans.modules.xml.retriever|org.netbeans.modules.xml.schema.model|org.netbeans.modules.xml.tax|org.netbeans.modules.xml.text|.*apisupport.*|org.netbeans.modules.debugger.jpda.ant)' && node ./out/test/launchNbcode.js -J-Dnetbeans.close=true --modules --enable .*apisupport.ant",
779779
"artifactory:check": "node ./esbuild.js --artifactory-check"
780780
},
781781
"devDependencies": {

vscode/src/commands/buildOperations.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,26 @@ import { extCommands, nbCommands } from "./commands";
1919
import { ICommand } from "./types";
2020
import { wrapCommandWithProgress, wrapProjectActionWithProgress } from "./utils";
2121

22-
const compileWorkspaceCHandler = () => {
23-
wrapCommandWithProgress(nbCommands.buildWorkspace, l10n.value('jdk.extension.command.progress.compilingWorkSpace'), LOGGER.getOutputChannel(), true);
22+
const compileWorkspaceHandler = () => {
23+
return wrapCommandWithProgress(nbCommands.buildWorkspace, l10n.value('jdk.extension.command.progress.compilingWorkSpace'), LOGGER.getOutputChannel());
2424
}
2525
const cleanWorkspaceHandler = () => {
26-
wrapCommandWithProgress(nbCommands.cleanWorkspace,l10n.value('jdk.extension.command.progress.cleaningWorkSpace'), LOGGER.getOutputChannel(), true)
26+
return wrapCommandWithProgress(nbCommands.cleanWorkspace,l10n.value('jdk.extension.command.progress.cleaningWorkSpace'), LOGGER.getOutputChannel());
2727
}
2828

2929
const compileProjectHandler = (args: any) => {
30-
wrapProjectActionWithProgress('build', undefined, l10n.value('jdk.extension.command.progress.compilingProject'), LOGGER.getOutputChannel(), true, args);
30+
return wrapProjectActionWithProgress('build', undefined, l10n.value('jdk.extension.command.progress.compilingProject'), LOGGER.getOutputChannel(), args);
3131
}
3232

3333
const cleanProjectHandler = (args: any) => {
34-
wrapProjectActionWithProgress('clean', undefined, l10n.value('jdk.extension.command.progress.cleaningProject'), LOGGER.getOutputChannel(), true, args);
34+
return wrapProjectActionWithProgress('clean', undefined, l10n.value('jdk.extension.command.progress.cleaningProject'), LOGGER.getOutputChannel(), args);
3535
}
3636

3737

3838
export const registerBuildOperationCommands: ICommand[] = [
3939
{
4040
command: extCommands.compileWorkspace,
41-
handler: compileWorkspaceCHandler
41+
handler: compileWorkspaceHandler
4242
}, {
4343
command: extCommands.cleanWorkspace,
4444
handler: cleanWorkspaceHandler

vscode/src/commands/navigation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const goToTest = async (ctx: any) => {
7777
}
7878

7979
const openTypeHandler = () => {
80-
wrapCommandWithProgress(nbCommands.quickOpen, l10n.value('jdk.extension.command.progress.quickOpen'), LOGGER.getOutputChannel(), true).then(() => {
80+
wrapCommandWithProgress(nbCommands.quickOpen, l10n.value('jdk.extension.command.progress.quickOpen'), LOGGER.getOutputChannel()).then(() => {
8181
commands.executeCommand(builtInCommands.focusActiveEditorGroup);
8282
});
8383
}
@@ -90,7 +90,7 @@ const openStackHandler = async (uri: any, methodName: any, fileName: any, line:
9090
} else {
9191
if (methodName) {
9292
const fqn: string = methodName.substring(0, methodName.lastIndexOf('.'));
93-
commands.executeCommand(builtInCommands.quickAccess, '#' + fqn.substring(fqn.lastIndexOf('.') + 1));
93+
await commands.executeCommand(builtInCommands.quickAccess, '#' + fqn.substring(fqn.lastIndexOf('.') + 1));
9494
}
9595
}
9696
}

vscode/src/commands/refactor.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { builtInCommands, extCommands, nbCommands } from "./commands";
2020
import { l10n } from "../localiser";
2121
import { globalVars } from "../extension";
2222
import { WorkspaceEdit } from 'vscode-languageserver-protocol';
23+
import { SymbolInformation } from 'vscode-languageclient';
2324

2425
const goToSuperImplementationHandler = async () => {
2526
if (window.activeTextEditor?.document.languageId !== extConstants.LANGUAGE_ID) {
@@ -74,6 +75,12 @@ const completeAbstractMethodsHandler = async () => {
7475
}
7576
}
7677

78+
const workspaceSymbolsHandler = async (query: any) => {
79+
const client = await globalVars.clientPromise.client;
80+
return (await client.sendRequest<SymbolInformation[]>("workspace/symbol", { "query": query })) ?? [];
81+
}
82+
83+
7784
export const registerRefactorCommands: ICommand[] = [
7885
{
7986
command: extCommands.goToSuperImpl,
@@ -90,5 +97,8 @@ export const registerRefactorCommands: ICommand[] = [
9097
}, {
9198
command: extCommands.abstractMethodsComplete,
9299
handler: completeAbstractMethodsHandler
100+
}, {
101+
command: extCommands.workspaceSymbols,
102+
handler: workspaceSymbolsHandler
93103
}
94104
];

vscode/src/commands/register.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { registerNavigationCommands } from "./navigation";
2121
import { registerWebviewCommands } from "./webViews";
2222
import { registerBuildOperationCommands } from "./buildOperations";
2323
import { registerRefactorCommands } from "./refactor";
24+
import { registerUtilCommands } from "./utilCommands";
2425

2526
type ICommandModules = Record<string, ICommand[]>;
2627

@@ -30,7 +31,8 @@ const commandModules: ICommandModules = {
3031
navigation: registerNavigationCommands,
3132
webview: registerWebviewCommands,
3233
buildOperations: registerBuildOperationCommands,
33-
refactor: registerRefactorCommands
34+
refactor: registerRefactorCommands,
35+
util: registerUtilCommands
3436
}
3537

3638
export const subscribeCommands = (context: ExtensionContext) => {

vscode/src/commands/utilCommands.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
import { globalVars } from "../extension";
17+
import { extCommands } from "./commands";
18+
import { ICommand } from "./types";
19+
20+
const startupConditionHandler = () => {
21+
return globalVars.clientPromise.client;
22+
}
23+
24+
const addEventListenerHandler = async (eventName: any, listener: any) => {
25+
let ls = globalVars.listeners.get(eventName);
26+
if (!ls) {
27+
ls = [];
28+
globalVars.listeners.set(eventName, ls);
29+
}
30+
ls.push(listener);
31+
}
32+
33+
34+
export const registerUtilCommands: ICommand[] = [
35+
{
36+
command: extCommands.startupCondition,
37+
handler: startupConditionHandler
38+
}, {
39+
command: extCommands.nbEventListener,
40+
handler: addEventListenerHandler
41+
}
42+
];

vscode/src/commands/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const isNbCommandRegistered = async (command: string) => {
5656
* @param args additional arguments
5757
* @returns Promise for the command's result
5858
*/
59-
export const wrapProjectActionWithProgress = (action: string, configuration: string | undefined, title: string, log?: OutputChannel, showOutput?: boolean, ...args: any[]): Thenable<unknown> => {
59+
export const wrapProjectActionWithProgress = (action: string, configuration: string | undefined, title: string, log?: OutputChannel, ...args: any[]): Thenable<unknown> => {
6060
let items = [];
6161
let actionParams = {
6262
action: action,
@@ -72,10 +72,10 @@ export const wrapProjectActionWithProgress = (action: string, configuration: str
7272
items.push(item);
7373
}
7474
}
75-
return wrapCommandWithProgress(nbCommands.runProjectAction, title, log, showOutput, actionParams, ...items);
75+
return wrapCommandWithProgress(nbCommands.runProjectAction, title, log, actionParams, ...items);
7676
}
7777

78-
export const wrapCommandWithProgress = (lsCommand: string, title: string, log?: OutputChannel, showOutput?: boolean, ...args: any[]): Thenable<unknown> => {
78+
export const wrapCommandWithProgress = (lsCommand: string, title: string, log?: OutputChannel, ...args: any[]): Thenable<unknown> => {
7979
return window.withProgress({ location: ProgressLocation.Window }, p => {
8080
return new Promise(async (resolve, reject) => {
8181
let c: LanguageClient = await globalVars.clientPromise.client;

vscode/src/extension.ts

Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
'use strict';
2525

26-
import { commands, window, workspace, ExtensionContext, ProgressLocation, TextEditorDecorationType } from 'vscode';
26+
import { commands, window, workspace, ExtensionContext, TextEditorDecorationType } from 'vscode';
2727

2828
import {
2929
LanguageClient,
@@ -33,21 +33,18 @@ import {
3333
import {
3434
MessageType,
3535
LogMessageNotification,
36-
SymbolInformation,
3736
TelemetryEventNotification
3837
} from 'vscode-languageclient';
3938

4039
import * as net from 'net';
4140
import * as fs from 'fs';
42-
import * as os from 'os';
4341
import * as path from 'path';
4442
import * as vscode from 'vscode';
45-
import * as ls from 'vscode-languageserver-protocol';
4643
import { StreamDebugAdapter} from './streamDebugAdapter';
4744
import { NbTestAdapter } from './testAdapter';
4845
import { asRanges, StatusMessageRequest, ShowStatusMessageParams, QuickPickRequest, InputBoxRequest, MutliStepInputRequest, TestProgressNotification, DebugConnector,
4946
TextEditorDecorationCreateRequest, TextEditorDecorationSetNotification, TextEditorDecorationDisposeNotification, HtmlPageRequest, HtmlPageParams,
50-
ExecInHtmlPageRequest, SetTextEditorDecorationParams, ProjectActionParams, UpdateConfigurationRequest, QuickPickStep, InputBoxStep, SaveDocumentsRequest, SaveDocumentRequestParams
47+
ExecInHtmlPageRequest, SetTextEditorDecorationParams, UpdateConfigurationRequest, QuickPickStep, InputBoxStep, SaveDocumentsRequest, SaveDocumentRequestParams
5148
} from './lsp/protocol';
5249
import * as launchConfigurations from './launchConfigurations';
5350
import { TreeViewService, Visualizer } from './explorer';
@@ -56,7 +53,6 @@ import { InputStep, MultiStepInput } from './utils';
5653
import { PropertiesView } from './propertiesView/propertiesView';
5754
import { l10n } from './localiser';
5855
import { extConstants } from './constants';
59-
import { JdkDownloaderView } from './jdkDownloader/view';
6056
import { ExtensionInfo } from './extensionInfo';
6157
import { ClientPromise } from './lsp/clientPromise';
6258
import { ExtensionLogger, LogLevel } from './logger';
@@ -66,10 +62,11 @@ import { NbLanguageClient } from './lsp/nbLanguageClient';
6662
import { configChangeListener } from './configurations/listener';
6763
import { isNbJavacDisabledHandler } from './configurations/handlers';
6864
import { subscribeCommands } from './commands/register';
65+
import { VSNetBeansAPI } from './lsp/types';
6966

70-
const listeners = new Map<string, string[]>();
7167
export let LOGGER: ExtensionLogger;
7268
export namespace globalVars {
69+
export const listeners = new Map<string, string[]>();
7370
export let extensionInfo: ExtensionInfo;
7471
export let clientPromise: ClientPromise;
7572
export let debugPort: number = -1;
@@ -105,31 +102,6 @@ export function findClusters(myPath : string): string[] {
105102
return clusters;
106103
}
107104

108-
// for tests only !
109-
export function awaitClient() : Promise<NbLanguageClient> {
110-
const clientPromise = globalVars.clientPromise;
111-
if (clientPromise.client && clientPromise.initialPromiseResolved) {
112-
return clientPromise.client;
113-
}
114-
let nbcode = vscode.extensions.getExtension(extConstants.ORACLE_VSCODE_EXTENSION_ID);
115-
if (!nbcode) {
116-
return Promise.reject(new Error(l10n.value("jdk.extension.notInstalled.label")));
117-
}
118-
const t : Thenable<NbLanguageClient> = nbcode.activate().then(nc => {
119-
if (globalVars.clientPromise.client === undefined || !globalVars.clientPromise.initialPromiseResolved) {
120-
throw new Error(l10n.value("jdk.extenstion.error_msg.clientNotAvailable"));
121-
} else {
122-
return globalVars.clientPromise.client;
123-
}
124-
});
125-
return Promise.resolve(t);
126-
}
127-
128-
interface VSNetBeansAPI {
129-
version : string;
130-
apiVersion: string;
131-
}
132-
133105
function contextUri(ctx : any) : vscode.Uri | undefined {
134106
if (ctx?.fsPath) {
135107
return ctx as vscode.Uri;
@@ -307,21 +279,6 @@ export function activate(context: ExtensionContext): VSNetBeansAPI {
307279
context.subscriptions.push(commands.registerCommand(extConstants.COMMAND_PREFIX + '.package.test', async (uri, launchConfiguration?) => {
308280
await runDebug(true, true, uri, undefined, launchConfiguration);
309281
}));
310-
context.subscriptions.push(commands.registerCommand(extConstants.COMMAND_PREFIX + '.workspace.symbols', async (query) => {
311-
const c = await globalVars.clientPromise.client;
312-
return (await c.sendRequest<SymbolInformation[]>("workspace/symbol", { "query": query })) ?? [];
313-
}));
314-
context.subscriptions.push(commands.registerCommand(extConstants.COMMAND_PREFIX + '.startup.condition', async () => {
315-
return globalVars.clientPromise.client;
316-
}));
317-
context.subscriptions.push(commands.registerCommand(extConstants.COMMAND_PREFIX + '.addEventListener', (eventName, listener) => {
318-
let ls = listeners.get(eventName);
319-
if (!ls) {
320-
ls = [];
321-
listeners.set(eventName, ls);
322-
}
323-
ls.push(listener);
324-
}));
325282
context.subscriptions.push(commands.registerCommand(extConstants.COMMAND_PREFIX + '.node.properties.edit',
326283
async (node) => await PropertiesView.createOrShow(context, node, (await globalVars.clientPromise.client).findTreeViewService())));
327284

@@ -481,7 +438,7 @@ function doActivateWithJDK(): void {
481438
}
482439
});
483440
c.onNotification(TelemetryEventNotification.type, (param) => {
484-
const ls = listeners.get(param);
441+
const ls = globalVars.listeners.get(param);
485442
if (ls) {
486443
for (const listener of ls) {
487444
commands.executeCommand(listener);

vscode/src/lsp/clientPromise.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ import { NbLanguageClient } from "./nbLanguageClient";
2323
export class ClientPromise {
2424
setClient!: [(c: NbLanguageClient) => void, (err: any) => void];
2525
client!: Promise<NbLanguageClient>;
26-
activationPending!: boolean;
27-
initialPromiseResolved: boolean = false;
26+
activationPending: boolean = true;
2827

2928
public clientPromiseInitialization = (): void => {
3029
this.client = new Promise<NbLanguageClient>((clientOK, clientErr) => {
@@ -43,6 +42,11 @@ export class ClientPromise {
4342
commands.executeCommand('setContext', 'nbJdkReady', false);
4443
}
4544

45+
public initializedSuccessfully = (client: NbLanguageClient) => {
46+
globalVars.clientPromise.setClient[0](client);
47+
commands.executeCommand('setContext', 'nbJdkReady', true);
48+
}
49+
4650
public stopClient = async (): Promise<void> => {
4751
if (globalVars.testAdapter) {
4852
globalVars.testAdapter.dispose();

vscode/src/lsp/types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,9 @@ export type userDefinedLaunchOptionsType = {
1919
optionToPass?: string | string[],
2020
encloseInvertedComma?: boolean
2121
}
22-
};
22+
};
23+
24+
export interface VSNetBeansAPI {
25+
version : string;
26+
apiVersion: string;
27+
}

0 commit comments

Comments
 (0)