Commit cf30670c authored by Martin Entlicher's avatar Martin Entlicher
Browse files

Change the Run code lens action to start through debugging with noDebug=true.

parent 664e7ec4
......@@ -118,11 +118,14 @@ public final class NbSourceProvider {
String uri = sourceProvider.getSourceFileURI(fullyQualifiedName, relativeSourcePath);
if (uri == null || uri.isEmpty()) {
for (String path : context.getSourcePaths()) {
Path fullpath = Paths.get(path, relativeSourcePath);
if (Files.isRegularFile(fullpath)) {
uri = fullpath.toString();
break;
String[] sourcePaths = context.getSourcePaths();
if (sourcePaths != null) {
for (String path : sourcePaths) {
Path fullpath = Paths.get(path, relativeSourcePath);
if (Files.isRegularFile(fullpath)) {
uri = fullpath.toString();
break;
}
}
}
}
......
......@@ -39,6 +39,7 @@ import org.eclipse.lsp4j.debug.OutputEventArguments;
import org.eclipse.lsp4j.debug.Source;
import org.eclipse.lsp4j.debug.TerminatedEventArguments;
import org.eclipse.lsp4j.jsonrpc.messages.ResponseErrorCode;
import org.netbeans.api.java.classpath.ClassPath;
import org.netbeans.modules.java.lsp.server.debugging.DebugAdapterContext;
import org.netbeans.modules.java.lsp.server.debugging.NbSourceProvider;
import org.netbeans.modules.java.lsp.server.debugging.utils.ErrorUtilities;
......@@ -113,6 +114,19 @@ public final class NbLaunchRequestHandler {
ResponseErrorCode.serverErrorStart);
return resultFuture;
}
if (!launchArguments.containsKey("sourcePaths")) {
ClassPath sourceCP = ClassPath.getClassPath(file, ClassPath.SOURCE);
if (sourceCP != null) {
FileObject[] roots = sourceCP.getRoots();
String[] sourcePaths = new String[roots.length];
for (int i = 0; i < roots.length; i++) {
sourcePaths[i] = roots[i].getPath();
}
context.setSourcePaths(sourcePaths);
}
} else {
context.setSourcePaths((String[]) launchArguments.get("sourcePaths"));
}
String singleMethod = (String)launchArguments.get("singleMethod");
activeLaunchHandler.nbLaunch(file, singleMethod, context, !noDebug, new OutputListener(context)).thenRun(() -> {
activeLaunchHandler.postLaunch(launchArguments, context);
......@@ -162,7 +176,7 @@ public final class NbLaunchRequestHandler {
protected void handleTerminatedEvent(DebugAdapterContext context) {
CompletableFuture.runAsync(() -> {
try {
waitForDebuggeeConsole.get(5, TimeUnit.SECONDS);
waitForDebuggeeConsole.get(1, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
// do nothing.
}
......
......@@ -322,8 +322,7 @@ public final class Server {
capabilities.setDocumentHighlightProvider(true);
capabilities.setReferencesProvider(true);
List<String> commands = new ArrayList<>(Arrays.asList(
JAVA_BUILD_WORKSPACE, GRAALVM_PAUSE_SCRIPT,
JAVA_TEST_SINGLE_METHOD, JAVA_RUN_MAIN_METHOD));
JAVA_BUILD_WORKSPACE, GRAALVM_PAUSE_SCRIPT));
for (CodeGenerator codeGenerator : Lookup.getDefault().lookupAll(CodeGenerator.class)) {
commands.addAll(codeGenerator.getCommands());
}
......@@ -419,8 +418,6 @@ public final class Server {
}
public static final String JAVA_BUILD_WORKSPACE = "java.build.workspace";
public static final String JAVA_TEST_SINGLE_METHOD = "java.test.single.method";
public static final String JAVA_RUN_MAIN_METHOD = "java.run.main.method";
public static final String GRAALVM_PAUSE_SCRIPT = "graalvm.pause.script";
static final String INDEXING_COMPLETED = "Indexing completed.";
static final String NO_JAVA_SUPPORT = "Cannot initialize Java support on JDK ";
......
......@@ -1375,7 +1375,7 @@ public class TextDocumentServiceImpl implements TextDocumentService, LanguageCli
Utils.createPosition(cc.getCompilationUnit(), method.end().getOffset()));
List<Object> arguments = Arrays.asList(new Object[]{method.method().getFile().toURI(), method.method().getMethodName()});
lens.add(new CodeLens(range,
new Command("Run test", Server.JAVA_TEST_SINGLE_METHOD, arguments),
new Command("Run test", "java.run.codelens", arguments),
null));
lens.add(new CodeLens(range,
new Command("Debug test", "java.debug.codelens", arguments),
......@@ -1391,7 +1391,7 @@ public class TextDocumentServiceImpl implements TextDocumentService, LanguageCli
Range range = Utils.treeRange(cc, tree);
List<Object> arguments = Collections.singletonList(params.getTextDocument().getUri());
lens.add(new CodeLens(range,
new Command("Run main", Server.JAVA_RUN_MAIN_METHOD, arguments),
new Command("Run main", "java.run.codelens", arguments),
null));
lens.add(new CodeLens(range,
new Command("Debug main", "java.debug.codelens", arguments),
......
......@@ -112,33 +112,6 @@ public final class WorkspaceServiceImpl implements WorkspaceService, LanguageCli
progressOfCompilation.checkStatus();
return progressOfCompilation.getFinishFuture();
}
case Server.JAVA_TEST_SINGLE_METHOD:
CommandProgress progressOfCommand = new CommandProgress();
String uriStr = ((JsonPrimitive) params.getArguments().get(0)).getAsString();
FileObject file;
try {
file = URLMapper.findFileObject(new URL(uriStr));
} catch (MalformedURLException ex) {
Exceptions.printStackTrace(ex);
return CompletableFuture.completedFuture(true);
}
String methodName = ((JsonPrimitive) params.getArguments().get(1)).getAsString();
SingleMethod method = new SingleMethod(file, methodName);
runSingleMethodCommand(method, SingleMethod.COMMAND_RUN_SINGLE_METHOD, progressOfCommand);
progressOfCommand.checkStatus();
return progressOfCommand.getFinishFuture();
case Server.JAVA_RUN_MAIN_METHOD:
progressOfCommand = new CommandProgress();
uriStr = ((JsonPrimitive) params.getArguments().get(0)).getAsString();
try {
file = URLMapper.findFileObject(new URL(uriStr));
} catch (MalformedURLException ex) {
Exceptions.printStackTrace(ex);
return CompletableFuture.completedFuture(true);
}
runSingleFile(file, ActionProvider.COMMAND_RUN_SINGLE, progressOfCommand);
progressOfCommand.checkStatus();
return progressOfCommand.getFinishFuture();
default:
for (CodeGenerator codeGenerator : Lookup.getDefault().lookupAll(CodeGenerator.class)) {
if (codeGenerator.getCommands().contains(command)) {
......@@ -149,46 +122,6 @@ public final class WorkspaceServiceImpl implements WorkspaceService, LanguageCli
throw new UnsupportedOperationException("Command not supported: " + params.getCommand());
}
@NbBundle.Messages("No_Method_Found=No method found")
private void runSingleMethodCommand(SingleMethod singleMethod, String command, CommandProgress progressOfCommand) {
if (singleMethod == null) {
StatusDisplayer.getDefault().setStatusText(Bundle.No_Method_Found());
progressOfCommand.getFinishFuture().complete(true);
} else {
Mutex.EVENT.readAccess(new Runnable() {
@Override
public void run() {
Project owner = FileOwnerQuery.getOwner(singleMethod.getFile());
if (owner != null) {
ActionProvider ap = owner.getLookup().lookup(ActionProvider.class);
if (ap != null) {
if (Arrays.asList(ap.getSupportedActions()).contains(command) && ap.isActionEnabled(command, Lookups.singleton(singleMethod))) {
ap.invokeAction(command, Lookups.fixed(singleMethod, progressOfCommand));
}
}
}
}
});
}
}
private void runSingleFile(FileObject file, String command, CommandProgress progressOfCommand) {
Mutex.EVENT.readAccess(new Runnable() {
@Override
public void run() {
Project owner = FileOwnerQuery.getOwner(file);
if (owner != null) {
ActionProvider ap = owner.getLookup().lookup(ActionProvider.class);
if (ap != null) {
if (Arrays.asList(ap.getSupportedActions()).contains(command) && ap.isActionEnabled(command, Lookups.singleton(file))) {
ap.invokeAction(command, Lookups.fixed(file, progressOfCommand));
}
}
}
}
});
}
@Override
public CompletableFuture<List<? extends SymbolInformation>> symbol(WorkspaceSymbolParams params) {
String query = params.getQuery();
......
......@@ -211,7 +211,7 @@ export function activate(context: ExtensionContext): VSNetBeansAPI {
]);
}
}));
context.subscriptions.push(commands.registerCommand('java.debug.codelens', async (uri, methodName) => {
const runCodelens = async (uri, methodName, noDebug) => {
const editor = window.activeTextEditor;
if (editor) {
const docUri = editor.document.uri;
......@@ -223,8 +223,17 @@ export function activate(context: ExtensionContext): VSNetBeansAPI {
mainClass: uri,
singleMethod: methodName,
};
await vscode.debug.startDebugging(workspaceFolder, debugConfig).then();
const debugOptions = {
noDebug: noDebug,
}
await vscode.debug.startDebugging(workspaceFolder, debugConfig, debugOptions).then();
}
};
context.subscriptions.push(commands.registerCommand('java.run.codelens', async (uri, methodName) => {
await runCodelens(uri, methodName, true);
}));
context.subscriptions.push(commands.registerCommand('java.debug.codelens', async (uri, methodName) => {
await runCodelens(uri, methodName, false);
}));
return Object.freeze({
version : API_VERSION
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment