Skip to content

Commit 4e79eac

Browse files
committed
Inline values for debugger variables.
1 parent 3c85270 commit 4e79eac

27 files changed

Lines changed: 1262 additions & 46 deletions

File tree

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,8 +1551,8 @@ jobs:
15511551
# - name: debugger.jpda.truffle
15521552
# run: ant $OPTS -f java/debugger.jpda.truffle test
15531553

1554-
# - name: debugger.jpda.ui
1555-
# run: ant $OPTS -f java/debugger.jpda.ui test
1554+
- name: debugger.jpda.ui
1555+
run: ant $OPTS -f java/debugger.jpda.ui test-unit
15561556

15571557
- name: Create Test Summary
15581558
uses: test-summary/action@31493c76ec9e7aa675f1585d3ed6f1da69269a86 # v2.4

ide/api.lsp/manifest.mf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Manifest-Version: 1.0
22
OpenIDE-Module: org.netbeans.api.lsp/1
33
OpenIDE-Module-Localizing-Bundle: org/netbeans/api/lsp/Bundle.properties
4-
OpenIDE-Module-Specification-Version: 1.32
4+
OpenIDE-Module-Specification-Version: 1.33
55
AutoUpdate-Show-In-Client: false
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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.api.lsp;
20+
21+
/**
22+
* An expression whose value may be show inline while debugging.
23+
*
24+
* @since 1.33
25+
*/
26+
public final class InlineValue {
27+
private final Range range;
28+
private final String expression;
29+
30+
private InlineValue(Range range, String expression) {
31+
this.range = range;
32+
this.expression = expression;
33+
}
34+
35+
/**
36+
* {@return Range to which the inline value applies}
37+
*/
38+
public Range getRange() {
39+
return range;
40+
}
41+
42+
/**
43+
* {@return The expression of that should be evaluated for the inline value.}
44+
*/
45+
public String getExpression() {
46+
return expression;
47+
}
48+
49+
/**
50+
* {@return a new instance of {@code InlineValue}, based on the provided information.}
51+
*
52+
* @param range range to which the inline value should apply
53+
* @param expression expression that should be evaluted
54+
*/
55+
public static InlineValue createInlineVariable(Range range, String expression) {
56+
return new InlineValue(range, expression);
57+
}
58+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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.spi.lsp;
20+
21+
import java.util.List;
22+
import java.util.concurrent.CompletableFuture;
23+
import org.netbeans.api.annotations.common.NonNull;
24+
import org.netbeans.api.lsp.InlineValue;
25+
import org.openide.filesystems.FileObject;
26+
27+
/**
28+
* Compute {@link InlineValue}s for the given file and offset.
29+
*/
30+
public interface InlineValuesProvider {
31+
32+
/**
33+
* Compute {@linkplain InlineValue}s for the given file and location.
34+
*
35+
* @param file file for which the inline values should be computed
36+
* @param currentExecutionPosition position for which the inline values should be computed
37+
* @return the computed inline values
38+
*/
39+
public CompletableFuture<List<? extends InlineValue>> inlineValues(@NonNull FileObject file, int currentExecutionPosition);
40+
}

ide/editor.actions/src/org/netbeans/modules/editor/actions/ShowInlineHintsAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
@EditorActionRegistration(name="toggle-inline-hints",
2626
menuPath="View",
27-
menuPosition=899,
27+
menuPosition=897,
2828
preferencesKey=ShowInlineHintsAction.KEY_LINES,
2929
preferencesDefault=ShowInlineHintsAction.DEF_LINES)
3030
public class ShowInlineHintsAction extends AbstractAction {

ide/editor.actions/src/org/netbeans/modules/editor/actions/ShowLinesAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
@EditorActionRegistration(name="toggle-lines-view",
2626
menuPath="View",
27-
menuPosition=898,
27+
menuPosition=895,
2828
preferencesKey=ShowLinesAction.KEY_LINES,
2929
preferencesDefault=ShowLinesAction.DEF_LINES)
3030
public class ShowLinesAction extends AbstractAction {

ide/editor.lib2/src/org/netbeans/modules/editor/lib2/highlighting/HighlightsList.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public void add(HighlightItem item) {
121121
* @param usePrependText reflect the prepended text setting.
122122
* @return either simple or compound attribute set.
123123
*/
124-
public AttributeSet cutSameFont(Font defaultFont, int maxEndOffset, int wsEndOffset, CharSequence docText, boolean usePrependText) {
124+
public AttributeSet cutSameFont(Font defaultFont, int maxEndOffset, int wsEndOffset, CharSequence docText) {
125125
assert (maxEndOffset <= endOffset()) :
126126
"maxEndOffset=" + maxEndOffset + " > endOffset()=" + endOffset() + ", " + this; // NOI18N
127127
HighlightItem item = get(0);
@@ -159,13 +159,13 @@ public AttributeSet cutSameFont(Font defaultFont, int maxEndOffset, int wsEndOff
159159

160160
// Extends beyond first highlight
161161
Font firstFont = ViewUtils.getFont(firstAttrs, defaultFont);
162-
Object firstPrependText = usePrependText && firstAttrs != null ? firstAttrs.getAttribute(ViewUtils.KEY_VIRTUAL_TEXT_PREPEND) : null;
162+
Object firstPrependText = firstAttrs != null ? firstAttrs.getAttribute(ViewUtils.KEY_VIRTUAL_TEXT_PREPEND) : null;
163163
int index = 1;
164164
while (true) {
165165
item = get(index);
166166
AttributeSet attrs = item.getAttributes();
167167
Font font = ViewUtils.getFont(attrs, defaultFont);
168-
Object prependText = usePrependText && attrs != null ? attrs.getAttribute(ViewUtils.KEY_VIRTUAL_TEXT_PREPEND) : null;
168+
Object prependText = attrs != null ? attrs.getAttribute(ViewUtils.KEY_VIRTUAL_TEXT_PREPEND) : null;
169169
if (!font.equals(firstFont) || !Objects.equals(firstPrependText, prependText)) { // Stop at itemEndOffset
170170
if (index == 1) { // Just single attribute set
171171
cutStartItems(1);

ide/editor.lib2/src/org/netbeans/modules/editor/lib2/view/DocumentViewOp.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@ public final class DocumentViewOp
317317
boolean asTextField;
318318

319319
private boolean guideLinesEnable;
320-
private boolean inlineHintsEnable;
321320

322321
private int indentLevelSize;
323322

@@ -924,13 +923,10 @@ public void run() {
924923
// Line height correction
925924
float lineHeightCorrectionOrig = rowHeightCorrection;
926925
rowHeightCorrection = prefs.getFloat(SimpleValueNames.LINE_HEIGHT_CORRECTION, 1.0f);
927-
boolean inlineHintsEnableOrig = inlineHintsEnable;
928-
inlineHintsEnable = prefs.getBoolean("enable.inline.hints", false); // NOI18N
929926
boolean updateMetrics = (rowHeightCorrection != lineHeightCorrectionOrig);
930927
boolean releaseChildren = nonInitialUpdate &&
931928
((nonPrintableCharactersVisible != nonPrintableCharactersVisibleOrig) ||
932-
(rowHeightCorrection != lineHeightCorrectionOrig) ||
933-
(inlineHintsEnable != inlineHintsEnableOrig));
929+
(rowHeightCorrection != lineHeightCorrectionOrig));
934930
indentLevelSize = getIndentSize();
935931
tabSize = prefs.getInt(SimpleValueNames.TAB_SIZE, EditorPreferencesDefaults.defaultTabSize);
936932
if (updateMetrics) {
@@ -1172,10 +1168,6 @@ public boolean isGuideLinesEnable() {
11721168
return guideLinesEnable && !asTextField;
11731169
}
11741170

1175-
public boolean isInlineHintsEnable() {
1176-
return inlineHintsEnable;
1177-
}
1178-
11791171
public int getIndentLevelSize() {
11801172
return indentLevelSize;
11811173
}

ide/editor.lib2/src/org/netbeans/modules/editor/lib2/view/HighlightsViewFactory.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,7 @@ public EditorView createView(int startOffset, int limitOffset, boolean forcedLim
218218
}
219219

220220
}
221-
boolean inlineHints = documentView().op.isInlineHintsEnable();
222-
AttributeSet attrs = hList.cutSameFont(defaultFont, limitOffset, wsEndOffset, docText, inlineHints);
221+
AttributeSet attrs = hList.cutSameFont(defaultFont, limitOffset, wsEndOffset, docText);
223222
int length = hList.startOffset() - startOffset;
224223
EditorView view = wrapWithPrependedText(new HighlightsView(length, attrs), attrs);
225224
EditorView origViewUnwrapped = origView instanceof PrependedTextView ? ((PrependedTextView) origView).getDelegate() : origView;
@@ -255,9 +254,7 @@ public EditorView createView(int startOffset, int limitOffset, boolean forcedLim
255254
}
256255

257256
private @NonNull EditorView wrapWithPrependedText(@NonNull EditorView origView, @NullAllowed AttributeSet attrs) {
258-
boolean inlineHints = documentView().op.isInlineHintsEnable();
259-
260-
if (attrs != null && inlineHints && attrs.getAttribute(ViewUtils.KEY_VIRTUAL_TEXT_PREPEND) instanceof String) {
257+
if (attrs != null && attrs.getAttribute(ViewUtils.KEY_VIRTUAL_TEXT_PREPEND) instanceof String) {
261258
return new PrependedTextView(documentView().op, attrs, origView);
262259
}
263260

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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.spi.editor.highlighting.support;
20+
21+
import java.util.prefs.PreferenceChangeEvent;
22+
import java.util.prefs.PreferenceChangeListener;
23+
import java.util.prefs.Preferences;
24+
import javax.swing.text.Document;
25+
import org.netbeans.api.editor.mimelookup.MimeLookup;
26+
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
27+
import org.netbeans.spi.editor.highlighting.HighlightsContainer;
28+
import org.netbeans.spi.editor.highlighting.HighlightsSequence;
29+
import org.openide.util.WeakListeners;
30+
31+
public class HighlightsContainers {
32+
public static HighlightsContainer inlineHintsSettingAwareContainer(Document doc, HighlightsContainer delegate) {
33+
class InlineHintsSettingsAwareContainer extends AbstractHighlightsContainer implements PreferenceChangeListener {
34+
private static final String KEY_ENABLE_INLINE_HINTS = "enable.inline.hints";
35+
36+
private final Preferences prefs;
37+
private boolean enabled;
38+
39+
public InlineHintsSettingsAwareContainer() {
40+
String mimeType = DocumentUtilities.getMimeType(doc);
41+
prefs = MimeLookup.getLookup(mimeType).lookup(Preferences.class);
42+
prefs.addPreferenceChangeListener(WeakListeners.create(PreferenceChangeListener.class, this, prefs));
43+
inlineSettingChanged();
44+
}
45+
46+
@Override
47+
public HighlightsSequence getHighlights(int startOffset, int endOffset) {
48+
synchronized (this) {
49+
if (!enabled) {
50+
return HighlightsSequence.EMPTY;
51+
}
52+
}
53+
return delegate.getHighlights(startOffset, endOffset);
54+
}
55+
56+
@Override
57+
public void preferenceChange(PreferenceChangeEvent evt) {
58+
if (KEY_ENABLE_INLINE_HINTS.equals(evt.getKey())) {
59+
inlineSettingChanged();
60+
}
61+
}
62+
63+
private void inlineSettingChanged() {
64+
synchronized (this) {
65+
boolean newValue = prefs.getBoolean(KEY_ENABLE_INLINE_HINTS, false);
66+
67+
if (enabled == newValue) {
68+
return ;
69+
}
70+
71+
enabled = newValue;
72+
}
73+
74+
fireHighlightsChange(0, doc.getLength());
75+
}
76+
}
77+
78+
return new InlineHintsSettingsAwareContainer();
79+
}
80+
}

0 commit comments

Comments
 (0)