From 6e2b43dd18af85f98d267d9d89326672e87702f2 Mon Sep 17 00:00:00 2001 From: Nipuna Ranasinghe Date: Wed, 4 Dec 2024 14:34:03 +0530 Subject: [PATCH] Refactor code to remove redundancies --- .../workspace/BallerinaWorkspaceManager.java | 1 - .../debugadapter/JBallerinaDebugServer.java | 47 ++++++++----------- 2 files changed, 19 insertions(+), 29 deletions(-) diff --git a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/workspace/BallerinaWorkspaceManager.java b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/workspace/BallerinaWorkspaceManager.java index 1855052be203..97a9f13575f3 100644 --- a/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/workspace/BallerinaWorkspaceManager.java +++ b/language-server/modules/langserver-core/src/main/java/org/ballerinalang/langserver/workspace/BallerinaWorkspaceManager.java @@ -629,7 +629,6 @@ public Optional run(Path filePath, List mainFuncArgs) throws IO commands.add(System.getProperty("java.command")); commands.add("-XX:+HeapDumpOnOutOfMemoryError"); commands.add("-XX:HeapDumpPath=" + System.getProperty(USER_DIR)); - commands.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005"); commands.add("-cp"); commands.add(getAllClassPaths(jarResolver)); commands.add(initClassName); diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/JBallerinaDebugServer.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/JBallerinaDebugServer.java index 380567b7f0a4..f7ff674fe27e 100755 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/JBallerinaDebugServer.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/JBallerinaDebugServer.java @@ -265,21 +265,8 @@ public CompletableFuture configurationDone(ConfigurationDoneArguments args @Override public CompletableFuture launch(Map args) { try { - context.setDebugMode(ExecutionContext.DebugMode.LAUNCH); clientConfigHolder = new ClientLaunchConfigHolder(args); - Project sourceProject = context.getProjectCache().getProject(Path.of(clientConfigHolder.getSourcePath())); - context.setSourceProject(sourceProject); - String sourceProjectRoot = context.getSourceProjectRoot(); - BProgramRunner programRunner = context.getSourceProject() instanceof SingleFileProject ? - new BSingleFileRunner((ClientLaunchConfigHolder) clientConfigHolder, sourceProjectRoot) : - new BPackageRunner((ClientLaunchConfigHolder) clientConfigHolder, sourceProjectRoot); - - if (context.getSupportsRunInTerminalRequest() && clientConfigHolder.getRunInTerminalKind() != null) { - launchInTerminal(programRunner); - } else { - context.setLaunchedProcess(programRunner.start()); - startListeningToProgramOutput(); - } + launchDebuggee(); return CompletableFuture.completedFuture(null); } catch (Exception e) { outputLogger.sendErrorOutput("Failed to launch the ballerina program due to: " + e); @@ -466,20 +453,7 @@ public CompletableFuture restart(RestartArguments args) { try { resetServer(); - context.setDebugMode(ExecutionContext.DebugMode.LAUNCH); - Project sourceProject = context.getProjectCache().getProject(Path.of(clientConfigHolder.getSourcePath())); - context.setSourceProject(sourceProject); - String sourceProjectRoot = context.getSourceProjectRoot(); - BProgramRunner programRunner = context.getSourceProject() instanceof SingleFileProject ? - new BSingleFileRunner((ClientLaunchConfigHolder) clientConfigHolder, sourceProjectRoot) : - new BPackageRunner((ClientLaunchConfigHolder) clientConfigHolder, sourceProjectRoot); - - if (context.getSupportsRunInTerminalRequest() && clientConfigHolder.getRunInTerminalKind() != null) { - launchInTerminal(programRunner); - } else { - context.setLaunchedProcess(programRunner.start()); - startListeningToProgramOutput(); - } + launchDebuggee(); return CompletableFuture.completedFuture(null); } catch (Throwable e) { outputLogger.sendErrorOutput("Failed to restart the ballerina program due to: " + e); @@ -487,6 +461,23 @@ public CompletableFuture restart(RestartArguments args) { } } + private void launchDebuggee() throws Exception { + context.setDebugMode(ExecutionContext.DebugMode.LAUNCH); + Project sourceProject = context.getProjectCache().getProject(Path.of(clientConfigHolder.getSourcePath())); + context.setSourceProject(sourceProject); + String sourceProjectRoot = context.getSourceProjectRoot(); + BProgramRunner programRunner = context.getSourceProject() instanceof SingleFileProject ? + new BSingleFileRunner((ClientLaunchConfigHolder) clientConfigHolder, sourceProjectRoot) : + new BPackageRunner((ClientLaunchConfigHolder) clientConfigHolder, sourceProjectRoot); + + if (context.getSupportsRunInTerminalRequest() && clientConfigHolder.getRunInTerminalKind() != null) { + launchInTerminal(programRunner); + } else { + context.setLaunchedProcess(programRunner.start()); + startListeningToProgramOutput(); + } + } + @Override public CompletableFuture setExceptionBreakpoints(SetExceptionBreakpointsArguments args) { return CompletableFuture.completedFuture(null);