Skip to content

Commit

Permalink
#8098: Extending lsp.client with support for DAP
Browse files Browse the repository at this point in the history
  • Loading branch information
jtulach authored Jan 8, 2025
2 parents 6c17cc6 + bf75e98 commit b080e1e
Show file tree
Hide file tree
Showing 51 changed files with 6,579 additions and 22 deletions.
2 changes: 1 addition & 1 deletion ide/lsp.client/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ release.external/org.eclipse.lsp4j.jsonrpc.debug-0.13.0.jar=modules/ext/org.ecli
release.external/org.eclipse.xtend.lib-2.24.0.jar=modules/ext/org.eclipse.xtend.lib-2.24.0.jar
release.external/org.eclipse.xtend.lib.macro-2.24.0.jar=modules/ext/org.eclipse.xtend.lib.macro-2.24.0.jar
release.external/org.eclipse.xtext.xbase.lib-2.24.0.jar=modules/ext/org.eclipse.xtext.xbase.lib-2.24.0.jar
spec.version.base=1.28.0
spec.version.base=1.29.0
29 changes: 29 additions & 0 deletions ide/lsp.client/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@
<specification-version>1.30</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.api.debugger</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>1</release-version>
<specification-version>1.82</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.api.io</code-name-base>
<build-prerequisite/>
Expand Down Expand Up @@ -261,6 +270,15 @@
<implementation-version/>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.spi.debugger.ui</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>1</release-version>
<specification-version>2.85</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.spi.editor.hints</code-name-base>
<build-prerequisite/>
Expand All @@ -279,6 +297,15 @@
<specification-version>1.40</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.spi.viewmodel</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>2</release-version>
<specification-version>1.78</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.awt</code-name-base>
<build-prerequisite/>
Expand Down Expand Up @@ -429,6 +456,8 @@
</test-type>
</test-dependencies>
<public-packages>
<package>org.netbeans.modules.lsp.client.debugger.api</package>
<package>org.netbeans.modules.lsp.client.debugger.spi</package>
<package>org.netbeans.modules.lsp.client.spi</package>
</public-packages>
<class-path-extension>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.netbeans.modules.lsp.client.debugger.DAPDebugger
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.netbeans.modules.lsp.client.debugger.DAPDebuggerEngineProvider
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.netbeans.modules.lsp.client.debugger;

import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import org.netbeans.api.debugger.ActionsManager;
import org.netbeans.spi.debugger.ActionsProvider;
import org.netbeans.spi.debugger.ActionsProviderSupport;
import org.netbeans.spi.debugger.ContextProvider;
import org.openide.util.RequestProcessor;

@ActionsProvider.Registration(path=DAPDebugger.SESSION_TYPE_ID, actions={"start", "stepInto", "stepOver", "stepOut",
"pause", "continue", "kill"})
public final class DAPActionsProvider extends ActionsProviderSupport implements ChangeListener {

private static final Logger LOGGER = Logger.getLogger(DAPActionsProvider.class.getName());

private static final Set<Object> ACTIONS = new HashSet<>();
private static final Set<Object> ACTIONS_TO_DISABLE = new HashSet<>();

static {
ACTIONS.add (ActionsManager.ACTION_KILL);
ACTIONS.add (ActionsManager.ACTION_CONTINUE);
ACTIONS.add (ActionsManager.ACTION_PAUSE);
ACTIONS.add (ActionsManager.ACTION_START);
ACTIONS.add (ActionsManager.ACTION_STEP_INTO);
ACTIONS.add (ActionsManager.ACTION_STEP_OVER);
ACTIONS.add (ActionsManager.ACTION_STEP_OUT);
ACTIONS_TO_DISABLE.addAll(ACTIONS);
// Ignore the KILL action
ACTIONS_TO_DISABLE.remove(ActionsManager.ACTION_KILL);
}

/** The ReqeustProcessor used by action performers. */
private static final RequestProcessor ACTIONS_WORKER = new RequestProcessor("DAP debugger actions RP", 1);
private static RequestProcessor killRequestProcessor;

private final DAPDebugger debugger;

public DAPActionsProvider(ContextProvider contextProvider) {
debugger = contextProvider.lookupFirst(null, DAPDebugger.class);
// init actions
for (Object action : ACTIONS) {
setEnabled (action, true);
}
debugger.addChangeListener(this);
}

@Override
public Set<Object> getActions () {
return ACTIONS;
}

@Override
public void doAction (Object action) {
LOGGER.log(Level.FINE, "DAPDebugger.doAction({0}), is kill = {1}", new Object[]{action, action == ActionsManager.ACTION_KILL});
if (action == ActionsManager.ACTION_KILL) {
debugger.finish();
} else if (action == ActionsManager.ACTION_CONTINUE) {
debugger.resume();
} else if (action == ActionsManager.ACTION_STEP_OVER) {
debugger.stepOver();
} else if (action == ActionsManager.ACTION_STEP_INTO) {
debugger.stepInto();
} else if (action == ActionsManager.ACTION_STEP_OUT) {
debugger.stepOut();
} else if (action == ActionsManager.ACTION_PAUSE) {
debugger.pause();
}
}

@Override
public void postAction(final Object action, final Runnable actionPerformedNotifier) {
setDebugActionsEnabled(false);
ACTIONS_WORKER.post(new Runnable() {
@Override
public void run() {
try {
doAction(action);
} finally {
actionPerformedNotifier.run();
setDebugActionsEnabled(true);
}
}
});
}

private void setDebugActionsEnabled(boolean enabled) {
if (!enabled) {
for (Object action : ACTIONS_TO_DISABLE) {
setEnabled(action, enabled);
}
} else {
setEnabled(ActionsManager.ACTION_CONTINUE, debugger.isSuspended());
setEnabled(ActionsManager.ACTION_PAUSE, !debugger.isSuspended());
setEnabled(ActionsManager.ACTION_STEP_INTO, debugger.isSuspended());
setEnabled(ActionsManager.ACTION_STEP_OUT, debugger.isSuspended());
setEnabled(ActionsManager.ACTION_STEP_OVER, debugger.isSuspended());
}
}

@Override
public void stateChanged(ChangeEvent e) {
setDebugActionsEnabled(true); //TODO...
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.netbeans.modules.lsp.client.debugger;

import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
import org.netbeans.modules.lsp.client.debugger.api.DAPConfiguration;
import org.openide.util.Exceptions;

public abstract class DAPConfigurationAccessor {
private static DAPConfigurationAccessor instance;

public static DAPConfigurationAccessor getInstance() {
try {
Class.forName(DAPConfiguration.class.getName(), true, DAPConfiguration.class.getClassLoader());
} catch (ClassNotFoundException ex) {
Exceptions.printStackTrace(ex);
}
return instance;
}

public static void setInstance(DAPConfigurationAccessor instance) {
DAPConfigurationAccessor.instance = instance;
}

public abstract OutputStream getOut(DAPConfiguration config);
public abstract InputStream getIn(DAPConfiguration config);
public abstract boolean getDelayLaunch(DAPConfiguration config);
public abstract Map<String, Object> getConfiguration(DAPConfiguration config);
public abstract String getSessionName(DAPConfiguration config);

}
Loading

0 comments on commit b080e1e

Please sign in to comment.