Skip to content

Commit b080e1e

Browse files
authored
#8098: Extending lsp.client with support for DAP
2 parents 6c17cc6 + bf75e98 commit b080e1e

File tree

51 files changed

+6579
-22
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+6579
-22
lines changed

ide/lsp.client/nbproject/project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ release.external/org.eclipse.lsp4j.jsonrpc.debug-0.13.0.jar=modules/ext/org.ecli
2626
release.external/org.eclipse.xtend.lib-2.24.0.jar=modules/ext/org.eclipse.xtend.lib-2.24.0.jar
2727
release.external/org.eclipse.xtend.lib.macro-2.24.0.jar=modules/ext/org.eclipse.xtend.lib.macro-2.24.0.jar
2828
release.external/org.eclipse.xtext.xbase.lib-2.24.0.jar=modules/ext/org.eclipse.xtext.xbase.lib-2.24.0.jar
29-
spec.version.base=1.28.0
29+
spec.version.base=1.29.0

ide/lsp.client/nbproject/project.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@
5050
<specification-version>1.30</specification-version>
5151
</run-dependency>
5252
</dependency>
53+
<dependency>
54+
<code-name-base>org.netbeans.api.debugger</code-name-base>
55+
<build-prerequisite/>
56+
<compile-dependency/>
57+
<run-dependency>
58+
<release-version>1</release-version>
59+
<specification-version>1.82</specification-version>
60+
</run-dependency>
61+
</dependency>
5362
<dependency>
5463
<code-name-base>org.netbeans.api.io</code-name-base>
5564
<build-prerequisite/>
@@ -261,6 +270,15 @@
261270
<implementation-version/>
262271
</run-dependency>
263272
</dependency>
273+
<dependency>
274+
<code-name-base>org.netbeans.spi.debugger.ui</code-name-base>
275+
<build-prerequisite/>
276+
<compile-dependency/>
277+
<run-dependency>
278+
<release-version>1</release-version>
279+
<specification-version>2.85</specification-version>
280+
</run-dependency>
281+
</dependency>
264282
<dependency>
265283
<code-name-base>org.netbeans.spi.editor.hints</code-name-base>
266284
<build-prerequisite/>
@@ -279,6 +297,15 @@
279297
<specification-version>1.40</specification-version>
280298
</run-dependency>
281299
</dependency>
300+
<dependency>
301+
<code-name-base>org.netbeans.spi.viewmodel</code-name-base>
302+
<build-prerequisite/>
303+
<compile-dependency/>
304+
<run-dependency>
305+
<release-version>2</release-version>
306+
<specification-version>1.78</specification-version>
307+
</run-dependency>
308+
</dependency>
282309
<dependency>
283310
<code-name-base>org.openide.awt</code-name-base>
284311
<build-prerequisite/>
@@ -429,6 +456,8 @@
429456
</test-type>
430457
</test-dependencies>
431458
<public-packages>
459+
<package>org.netbeans.modules.lsp.client.debugger.api</package>
460+
<package>org.netbeans.modules.lsp.client.debugger.spi</package>
432461
<package>org.netbeans.modules.lsp.client.spi</package>
433462
</public-packages>
434463
<class-path-extension>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.netbeans.modules.lsp.client.debugger.DAPDebugger
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.netbeans.modules.lsp.client.debugger.DAPDebuggerEngineProvider
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.netbeans.modules.lsp.client.debugger;
20+
21+
import java.util.HashSet;
22+
import java.util.Set;
23+
import java.util.logging.Level;
24+
import java.util.logging.Logger;
25+
import javax.swing.event.ChangeEvent;
26+
import javax.swing.event.ChangeListener;
27+
28+
import org.netbeans.api.debugger.ActionsManager;
29+
import org.netbeans.spi.debugger.ActionsProvider;
30+
import org.netbeans.spi.debugger.ActionsProviderSupport;
31+
import org.netbeans.spi.debugger.ContextProvider;
32+
import org.openide.util.RequestProcessor;
33+
34+
@ActionsProvider.Registration(path=DAPDebugger.SESSION_TYPE_ID, actions={"start", "stepInto", "stepOver", "stepOut",
35+
"pause", "continue", "kill"})
36+
public final class DAPActionsProvider extends ActionsProviderSupport implements ChangeListener {
37+
38+
private static final Logger LOGGER = Logger.getLogger(DAPActionsProvider.class.getName());
39+
40+
private static final Set<Object> ACTIONS = new HashSet<>();
41+
private static final Set<Object> ACTIONS_TO_DISABLE = new HashSet<>();
42+
43+
static {
44+
ACTIONS.add (ActionsManager.ACTION_KILL);
45+
ACTIONS.add (ActionsManager.ACTION_CONTINUE);
46+
ACTIONS.add (ActionsManager.ACTION_PAUSE);
47+
ACTIONS.add (ActionsManager.ACTION_START);
48+
ACTIONS.add (ActionsManager.ACTION_STEP_INTO);
49+
ACTIONS.add (ActionsManager.ACTION_STEP_OVER);
50+
ACTIONS.add (ActionsManager.ACTION_STEP_OUT);
51+
ACTIONS_TO_DISABLE.addAll(ACTIONS);
52+
// Ignore the KILL action
53+
ACTIONS_TO_DISABLE.remove(ActionsManager.ACTION_KILL);
54+
}
55+
56+
/** The ReqeustProcessor used by action performers. */
57+
private static final RequestProcessor ACTIONS_WORKER = new RequestProcessor("DAP debugger actions RP", 1);
58+
private static RequestProcessor killRequestProcessor;
59+
60+
private final DAPDebugger debugger;
61+
62+
public DAPActionsProvider(ContextProvider contextProvider) {
63+
debugger = contextProvider.lookupFirst(null, DAPDebugger.class);
64+
// init actions
65+
for (Object action : ACTIONS) {
66+
setEnabled (action, true);
67+
}
68+
debugger.addChangeListener(this);
69+
}
70+
71+
@Override
72+
public Set<Object> getActions () {
73+
return ACTIONS;
74+
}
75+
76+
@Override
77+
public void doAction (Object action) {
78+
LOGGER.log(Level.FINE, "DAPDebugger.doAction({0}), is kill = {1}", new Object[]{action, action == ActionsManager.ACTION_KILL});
79+
if (action == ActionsManager.ACTION_KILL) {
80+
debugger.finish();
81+
} else if (action == ActionsManager.ACTION_CONTINUE) {
82+
debugger.resume();
83+
} else if (action == ActionsManager.ACTION_STEP_OVER) {
84+
debugger.stepOver();
85+
} else if (action == ActionsManager.ACTION_STEP_INTO) {
86+
debugger.stepInto();
87+
} else if (action == ActionsManager.ACTION_STEP_OUT) {
88+
debugger.stepOut();
89+
} else if (action == ActionsManager.ACTION_PAUSE) {
90+
debugger.pause();
91+
}
92+
}
93+
94+
@Override
95+
public void postAction(final Object action, final Runnable actionPerformedNotifier) {
96+
setDebugActionsEnabled(false);
97+
ACTIONS_WORKER.post(new Runnable() {
98+
@Override
99+
public void run() {
100+
try {
101+
doAction(action);
102+
} finally {
103+
actionPerformedNotifier.run();
104+
setDebugActionsEnabled(true);
105+
}
106+
}
107+
});
108+
}
109+
110+
private void setDebugActionsEnabled(boolean enabled) {
111+
if (!enabled) {
112+
for (Object action : ACTIONS_TO_DISABLE) {
113+
setEnabled(action, enabled);
114+
}
115+
} else {
116+
setEnabled(ActionsManager.ACTION_CONTINUE, debugger.isSuspended());
117+
setEnabled(ActionsManager.ACTION_PAUSE, !debugger.isSuspended());
118+
setEnabled(ActionsManager.ACTION_STEP_INTO, debugger.isSuspended());
119+
setEnabled(ActionsManager.ACTION_STEP_OUT, debugger.isSuspended());
120+
setEnabled(ActionsManager.ACTION_STEP_OVER, debugger.isSuspended());
121+
}
122+
}
123+
124+
@Override
125+
public void stateChanged(ChangeEvent e) {
126+
setDebugActionsEnabled(true); //TODO...
127+
}
128+
129+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.netbeans.modules.lsp.client.debugger;
20+
21+
import java.io.InputStream;
22+
import java.io.OutputStream;
23+
import java.util.Map;
24+
import org.netbeans.modules.lsp.client.debugger.api.DAPConfiguration;
25+
import org.openide.util.Exceptions;
26+
27+
public abstract class DAPConfigurationAccessor {
28+
private static DAPConfigurationAccessor instance;
29+
30+
public static DAPConfigurationAccessor getInstance() {
31+
try {
32+
Class.forName(DAPConfiguration.class.getName(), true, DAPConfiguration.class.getClassLoader());
33+
} catch (ClassNotFoundException ex) {
34+
Exceptions.printStackTrace(ex);
35+
}
36+
return instance;
37+
}
38+
39+
public static void setInstance(DAPConfigurationAccessor instance) {
40+
DAPConfigurationAccessor.instance = instance;
41+
}
42+
43+
public abstract OutputStream getOut(DAPConfiguration config);
44+
public abstract InputStream getIn(DAPConfiguration config);
45+
public abstract boolean getDelayLaunch(DAPConfiguration config);
46+
public abstract Map<String, Object> getConfiguration(DAPConfiguration config);
47+
public abstract String getSessionName(DAPConfiguration config);
48+
49+
}

0 commit comments

Comments
 (0)