[netbeans] branch master updated: Fix case when ANTLR getText() causes assertion in LexerInput.

2023-03-07 Thread lkishalmi
This is an automated email from the ASF dual-hosted git repository.

lkishalmi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
 new 34f880e181 Fix case when ANTLR getText() causes assertion in 
LexerInput.
34f880e181 is described below

commit 34f880e181ea29855cf41771573f77be42ca73ec
Author: Laszlo Kishalmi 
AuthorDate: Mon Mar 6 17:57:45 2023 -0800

Fix case when ANTLR getText() causes assertion in LexerInput.
---
 .../netbeans/spi/lexer/antlr4/LexerInputCharStream.java| 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git 
a/ide/lexer.antlr4/src/org/netbeans/spi/lexer/antlr4/LexerInputCharStream.java 
b/ide/lexer.antlr4/src/org/netbeans/spi/lexer/antlr4/LexerInputCharStream.java
index 2f782bb275..3a2f672262 100644
--- 
a/ide/lexer.antlr4/src/org/netbeans/spi/lexer/antlr4/LexerInputCharStream.java
+++ 
b/ide/lexer.antlr4/src/org/netbeans/spi/lexer/antlr4/LexerInputCharStream.java
@@ -45,14 +45,14 @@ final class LexerInputCharStream implements CharStream {
 }
 int start = intrvl.a - tokenMark;
 int end = intrvl.b - tokenMark + 1;
-int toread = end - start - input.readLength();
-for (int i = 0; i < toread; i++) {
-input.read();
-}
-String ret = String.valueOf(input.readText(start, end));
-if (toread > 0) {
-input.backup(toread);
+int readCount = 0;
+int next = 0;
+while ((end > input.readLength()) && (next != EOF)) {
+next = input.read();
+readCount++;
 }
+String ret = String.valueOf(input.readText(start, Math.min(end, 
input.readLength(;
+input.backup(readCount);
 return ret;
 }
 


-
To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org
For additional commands, e-mail: commits-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists



[netbeans] branch master updated: Provide a waitable command that completes after NBLS fully starts & registers server-provided commands

2023-03-07 Thread sdedic
This is an automated email from the ASF dual-hosted git repository.

sdedic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
 new 084770067c Provide a waitable command that completes after NBLS fully 
starts & registers server-provided commands
 new ce4ed99adf Merge pull request #5615 from 
sdedic/vscode/startup-complete-condition
084770067c is described below

commit 084770067c6d06dfcf142447616b84472d795a45
Author: Svata Dedic 
AuthorDate: Mon Mar 6 13:37:00 2023 +0100

Provide a waitable command that completes after NBLS fully starts & 
registers server-provided commands
---
 java/java.lsp.server/vscode/src/extension.ts | 54 +++-
 1 file changed, 46 insertions(+), 8 deletions(-)

diff --git a/java/java.lsp.server/vscode/src/extension.ts 
b/java/java.lsp.server/vscode/src/extension.ts
index f74dde140b..9f86ce9219 100644
--- a/java/java.lsp.server/vscode/src/extension.ts
+++ b/java/java.lsp.server/vscode/src/extension.ts
@@ -134,7 +134,7 @@ export function findClusters(myPath : string): string[] {
 // for tests only !
 export function awaitClient() : Promise {
 const c : Promise = client;
-if (c) {
+if (c && !(c instanceof InitialPromise)) {
 return c;
 }
 let nbcode = vscode.extensions.getExtension('asf.apache-netbeans-java');
@@ -142,7 +142,7 @@ export function awaitClient() : Promise {
 return Promise.reject(new Error("Extension not installed."));
 }
 const t : Thenable = nbcode.activate().then(nc => {
-if (client === undefined) {
+if (client === undefined || client instanceof InitialPromise) {
 throw new Error("Client not available");
 } else {
 return client;
@@ -292,9 +292,29 @@ function wrapCommandWithProgress(lsCommand : string, title 
: string, log? : vsco
 });
 }
 
+/**
+ * Just a simple promise subclass, so I can test for the 'initial promise' 
value:
+ * unlike all other promises, that must be fullfilled in order to e.g. 
properly stop the server or otherwise communicate with it,
+ * the initial one needs to be largely ignored in the launching/mgmt code, BUT 
should be available to normal commands / features.
+ */
+class InitialPromise extends Promise {
+constructor(f : (resolve: (value: NbLanguageClient | 
PromiseLike) => void, reject: (reason?: any) => void) => 
void) {
+super(f);
+}
+}
+
 export function activate(context: ExtensionContext): VSNetBeansAPI {
 let log = vscode.window.createOutputChannel("Apache NetBeans Language 
Server");
 
+var clientResolve : (x : NbLanguageClient) => void;
+var clientReject : (err : any) => void;
+
+// establish a waitable Promise, export the callbacks so they can be 
called after activation.
+client = new InitialPromise((resolve, reject) => {
+clientResolve = resolve;
+clientReject = reject;
+});
+
 function checkConflict(): void {
 let conf = workspace.getConfiguration();
 if (conf.get("netbeans.conflict.check") && 
conf.get("netbeans.javaSupport.enabled")) {
@@ -325,10 +345,10 @@ export function activate(context: ExtensionContext): 
VSNetBeansAPI {
 const newClusters = findClusters(context.extensionPath).sort();
 if (newClusters.length !== currentClusters.length || 
newClusters.find((value, index) => value !== currentClusters[index])) {
 currentClusters = newClusters;
-activateWithJDK(specifiedJDK, context, log, true);
+activateWithJDK(specifiedJDK, context, log, true, 
clientResolve, clientReject);
 }
 }));
-activateWithJDK(specifiedJDK, context, log, true);
+activateWithJDK(specifiedJDK, context, log, true, clientResolve, 
clientReject);
 });
 
 //register debugger:
@@ -538,6 +558,9 @@ export function activate(context: ExtensionContext): 
VSNetBeansAPI {
 context.subscriptions.push(commands.registerCommand('java.package.test', 
async (uri, launchConfiguration?) => {
 await runDebug(true, true, uri, undefined, launchConfiguration);
 }));
+
context.subscriptions.push(commands.registerCommand('nbls.startup.condition', 
async () => {
+return client;
+}));
 
 // register completions:
 launchConfigurations.registerCompletion(context);
@@ -557,7 +580,8 @@ let maintenance : Promise | null;
  */
 let activationPending : boolean = false;
 
-function activateWithJDK(specifiedJDK: string | null, context: 
ExtensionContext, log : vscode.OutputChannel, notifyKill: boolean): void {
+function activateWithJDK(specifiedJDK: string | null, context: 
ExtensionContext, log : vscode.OutputChannel, notifyKill: boolean, 
+clientResolve? : (x : NbLanguageClient) => void, clientReject? : (x : any) 
=> void): void {
 if (activationPending) {
 // do not activate more than once in parallel.

[netbeans] branch master updated: Display DB welcome only when no connections are defined.

2023-03-07 Thread sdedic
This is an automated email from the ASF dual-hosted git repository.

sdedic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
 new d5b874f0f9 Display DB welcome only when no connections are defined.
 new d2f4382da8 Merge pull request #5613 from 
sdedic/lsp/welcome-after-dbinit
d5b874f0f9 is described below

commit d5b874f0f9f76802c92c993eec96eb0caf1a1bd3
Author: Svata Dedic 
AuthorDate: Mon Mar 6 10:14:16 2023 +0100

Display DB welcome only when no connections are defined.
---
 java/java.lsp.server/vscode/package.json |  3 ++-
 java/java.lsp.server/vscode/src/explorer.ts  | 35 +---
 java/java.lsp.server/vscode/src/extension.ts |  8 +++
 3 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/java/java.lsp.server/vscode/package.json 
b/java/java.lsp.server/vscode/package.json
index 59eaea0505..b71c9c8fbc 100644
--- a/java/java.lsp.server/vscode/package.json
+++ b/java/java.lsp.server/vscode/package.json
@@ -88,7 +88,8 @@
"viewsWelcome": [
{
"view": "database.connections",
-   "contents": "No database connections 
found.\n[Add Database Connection](command:db.add.connection)\n[Add Oracle 
Autonomous 
DB](command:nbls:Tools:org.netbeans.modules.cloud.oracle.actions.AddADBAction)"
+   "contents": "No database connections 
found.\n[Add Database Connection](command:db.add.connection)\n[Add Oracle 
Autonomous 
DB](command:nbls:Tools:org.netbeans.modules.cloud.oracle.actions.AddADBAction)",
+   "when": "nb.database.view.active"
}
],
"configuration": {
diff --git a/java/java.lsp.server/vscode/src/explorer.ts 
b/java/java.lsp.server/vscode/src/explorer.ts
index c6e521ae45..ba4a252a05 100644
--- a/java/java.lsp.server/vscode/src/explorer.ts
+++ b/java/java.lsp.server/vscode/src/explorer.ts
@@ -279,11 +279,13 @@ export class TreeViewService extends vscode.Disposable {
 
 export interface TreeItemDecorator extends vscode.Disposable {
   decorateTreeItem(element: T, item : vscode.TreeItem): vscode.TreeItem | 
Thenable;
+  decorateChildren(element: T, children: Visualizer[]): Visualizer[] | 
Thenable;
 }
 
 export interface CustomizableTreeDataProvider extends 
vscode.TreeDataProvider {
   fireItemChange(item? : T) : void;
   addItemDecorator(deco : TreeItemDecorator) : vscode.Disposable;
+  getRoot() : T;
 }
 
 class VisualizerProvider extends vscode.Disposable implements 
CustomizableTreeDataProvider {
@@ -583,6 +585,8 @@ class VisualizerProvider extends vscode.Disposable 
implements CustomizableTreeDa
   this.log.appendLine(`Doing getChildren on ${e?.idstring()}`);
 }
 
+let decos : TreeItemDecorator[] = [...this.decorators];
+const parent = e || this.root;
 async function collectResults(list : Visualizer[], arr: any, element: 
Visualizer): Promise {
   let res : Visualizer[] = [];
   let now : Visualizer[] | undefined;
@@ -594,6 +598,25 @@ class VisualizerProvider extends vscode.Disposable 
implements CustomizableTreeDa
   res.push(v);
 }
   }
+
+  if (decos.length > 0) {
+async function f(orig: Visualizer[]) : Promise {
+  const deco = decos.shift();
+  if (!deco) {
+return orig;
+  }
+  // decorateChildren(element: T, item : Visualizer, children: 
Visualizer[]): Visualizer[] | Thenable;
+  const decorated = deco.decorateChildren(parent, orig);
+  if (Array.isArray(decorated)) {
+  return f(decorated);
+  } else {
+  return (decorated as Thenable).then(f);
+  }
+}
+
+res = await f(res);
+  }
+
   now = element.updateChildren(res, self);
   for (let i = 0; i < now.length; i++) {
 const v = now[i];
@@ -605,15 +628,9 @@ class VisualizerProvider extends vscode.Disposable 
implements CustomizableTreeDa
 }
 
 return self.wrap((list) => self.queryVisualizer(e, list, () => {
-if (e) {
-  return this.client.sendRequest(NodeInfoRequest.children, { nodeId : 
e.data.id}).then(async (arr) => {
-return collectResults(list, arr, e);
-  });
-} else {
-  return this.client.sendRequest(NodeInfoRequest.children, { nodeId: 
this.root.data.id}).then(async (arr) => {
-return collectResults(list, arr, this.root);
-  });
-}
+return this.client.sendRequest(NodeInfoRequest.children, { nodeId : 
parent.data.id}).then(async (arr) => {
+  return collectResults(list, arr, parent);
+});
   }
 ));
   }
diff --git a/java/java.lsp.server/vscode/src/extension.ts 
b/java/java.lsp.server/vscode/src/extension.ts
index f74dde140b..745bb50458 100644
---