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 d29a5ae78d Use vscode's selected launch config for project launch and 
codelens run/debug
     new 409ff48d73 Merge pull request #6813 from 
sdedic/vscode/select-run-config
d29a5ae78d is described below

commit d29a5ae78d3d0220e332c41aa2c6fa697208c270
Author: Svata Dedic <[email protected]>
AuthorDate: Thu Dec 7 15:46:51 2023 +0100

    Use vscode's selected launch config for project launch and codelens 
run/debug
---
 .../server/protocol/TextDocumentServiceImpl.java   |  5 +-
 java/java.lsp.server/vscode/src/extension.ts       | 78 ++++++++++++++--------
 2 files changed, 56 insertions(+), 27 deletions(-)

diff --git 
a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java
 
b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java
index a21dd42572..40946c3c6f 100644
--- 
a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java
+++ 
b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java
@@ -1220,7 +1220,10 @@ public class TextDocumentServiceImpl implements 
TextDocumentService, LanguageCli
                                         int start = (int) 
cc.getTrees().getSourcePositions().getStartPosition(cc.getCompilationUnit(), 
tree);
                                         int end = (int) 
cc.getTrees().getSourcePositions().getEndPosition(cc.getCompilationUnit(), 
tree);
                                         org.netbeans.api.lsp.Range range = new 
org.netbeans.api.lsp.Range(start, end);
-                                        List<Object> arguments = 
Collections.singletonList(uri);
+                                        List<Object> arguments = new 
ArrayList<>();
+                                        arguments.add(uri);
+                                        arguments.add(null);
+                                        arguments.add("");
                                         String method = 
el.getSimpleName().toString();
                                         lens.add(new 
org.netbeans.api.lsp.CodeLens(range,
                                                               new 
org.netbeans.api.lsp.Command(Bundle.LBL_Run(method), COMMAND_RUN_SINGLE, 
arguments),
diff --git a/java/java.lsp.server/vscode/src/extension.ts 
b/java/java.lsp.server/vscode/src/extension.ts
index 29a6ac1ed5..9c58afe7dd 100644
--- a/java/java.lsp.server/vscode/src/extension.ts
+++ b/java/java.lsp.server/vscode/src/extension.ts
@@ -550,50 +550,75 @@ export function activate(context: ExtensionContext): 
VSNetBeansAPI {
             await 
commands.executeCommand('nbls:Tools:org.netbeans.modules.cloud.oracle.actions.AddADBAction');
         }
     }));
-    const mergeWithLaunchConfig = (dconfig : vscode.DebugConfiguration) => {
-        const folder = vscode.workspace.workspaceFolders?.[0];
-        const uri = folder?.uri;
-        if (uri) {
-            const launchConfig = workspace.getConfiguration('launch', uri);
-            // retrieve values
-            const configurations = launchConfig.get('configurations') as 
(any[] | undefined);
-            if (configurations) {
-                for (let config of configurations) {
-                    if (config["type"] == dconfig.type) {
-                        for (let key in config) {
-                            if (!dconfig[key]) {
-                                dconfig[key] = config[key];
-                            }
-                        }
-                        break;
-                    }
-                }
+
+    async function findRunConfiguration(uri : vscode.Uri) : 
Promise<vscode.DebugConfiguration|undefined> {
+        // do not invoke debug start with no (java+) configurations, as it 
would probably create an user prompt
+        let cfg = vscode.workspace.getConfiguration("launch");
+        let c = cfg.get('configurations');
+        if (!Array.isArray(c)) {
+            return undefined;
+        }
+        let f = c.filter((v) => v['type'] === 'java+');
+        if (!f.length) {
+            return undefined;
+        }
+        class P implements vscode.DebugConfigurationProvider {
+            config : vscode.DebugConfiguration | undefined;
+            
+            resolveDebugConfigurationWithSubstitutedVariables(folder: 
vscode.WorkspaceFolder | undefined, debugConfiguration: 
vscode.DebugConfiguration, token?: vscode.CancellationToken): 
vscode.ProviderResult<vscode.DebugConfiguration> {
+                this.config = debugConfiguration;
+                return undefined;
             }
         }
+        let provider = new P();
+        let d = vscode.debug.registerDebugConfigurationProvider('java+', 
provider);
+        // let vscode to select a debug config
+        return await 
vscode.commands.executeCommand('workbench.action.debug.start', { config: {
+            type: 'java+',
+            mainClass: uri.toString()
+        }, noDebug: true}).then((v) => {
+            d.dispose();
+            return provider.config;
+        }, (err) => {
+            d.dispose();
+            return undefined;
+        });
     }
 
     const runDebug = async (noDebug: boolean, testRun: boolean, uri: any, 
methodName?: string, launchConfiguration?: string, project : boolean = false, ) 
=> {
-        const docUri = contextUri(uri);
+    const docUri = contextUri(uri);
         if (docUri) {
-            const workspaceFolder = 
vscode.workspace.getWorkspaceFolder(docUri);
-            const debugConfig : vscode.DebugConfiguration = {
+            // attempt to find the active configuration in the vsode launch 
settings; undefined if no config is there.
+            let debugConfig : vscode.DebugConfiguration = await 
findRunConfiguration(docUri) || {
                 type: "java+",
                 name: "Java Single Debug",
-                request: "launch",
-                methodName,
-                launchConfiguration,
-                testRun
+                request: "launch"
             };
+            if (!methodName) {
+                debugConfig['methodName'] = methodName;
+            }
+            if (launchConfiguration == '') {
+                if (debugConfig['launchConfiguration']) {
+                    delete debugConfig['launchConfiguration'];
+                }
+            } else {
+                debugConfig['launchConfiguration'] = launchConfiguration;
+            }
+            debugConfig['testRun'] = testRun;
+
+            const workspaceFolder = 
vscode.workspace.getWorkspaceFolder(docUri);
             if (project) {
                 debugConfig['projectFile'] = docUri.toString();
                 debugConfig['project'] = true;
             } else {
                 debugConfig['mainClass'] =  docUri.toString();
             }
-            mergeWithLaunchConfig(debugConfig);
+            
             const debugOptions : vscode.DebugSessionOptions = {
                 noDebug: noDebug,
             }
+            
+            
             const ret = await vscode.debug.startDebugging(workspaceFolder, 
debugConfig, debugOptions);
             return ret ? new Promise((resolve) => {
                 const listener = vscode.debug.onDidTerminateDebugSession(() => 
{
@@ -603,6 +628,7 @@ export function activate(context: ExtensionContext): 
VSNetBeansAPI {
             }) : ret;
         }
     };
+    
     context.subscriptions.push(commands.registerCommand(COMMAND_PREFIX + 
'.run.test', async (uri, methodName?, launchConfiguration?) => {
         await runDebug(true, true, uri, methodName, launchConfiguration);
     }));


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

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

Reply via email to