Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1563,8 +1563,8 @@ jobs:
# - name: debugger.jpda.truffle
# run: ant $OPTS -f java/debugger.jpda.truffle test

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

- name: Create Test Summary
uses: test-summary/action@31493c76ec9e7aa675f1585d3ed6f1da69269a86 # v2.4
Expand Down
13 changes: 13 additions & 0 deletions ide/api.lsp/apichanges.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@
<!-- ACTUAL CHANGES BEGIN HERE: -->

<changes>
<change id="InlineValuesProvider">
<api name="LSP_API"/>
<summary>Adding InlineValue and InlineValuesProvider</summary>
<version major="1" minor="35"/>
<date day="23" month="4" year="2025"/>
<author login="jlahoda"/>
<compatibility binary="compatible" source="compatible" addition="yes" deletion="no" />
<description>
The <code>InlineValuesProvider</code> is introduced to provide debugger
inline values in the the LSP protocol.
</description>
<class package="org.netbeans.spi.lsp" name="InlineValuesProvider"/>
</change>
<change id="InlayHintsProvider">
<api name="LSP_API"/>
<summary>Adding InlayHintsProvider</summary>
Expand Down
2 changes: 1 addition & 1 deletion ide/api.lsp/manifest.mf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Manifest-Version: 1.0
OpenIDE-Module: org.netbeans.api.lsp/1
OpenIDE-Module-Localizing-Bundle: org/netbeans/api/lsp/Bundle.properties
OpenIDE-Module-Specification-Version: 1.34
OpenIDE-Module-Specification-Version: 1.35
AutoUpdate-Show-In-Client: false
2 changes: 1 addition & 1 deletion ide/api.lsp/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.
is.autoload=true
javac.release=11
javac.release=17
javac.compilerargs=-Xlint -Xlint:-serial
javadoc.name=LSP APIs
javadoc.title=LSP APIs
Expand Down
58 changes: 58 additions & 0 deletions ide/api.lsp/src/org/netbeans/api/lsp/InlineValue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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.api.lsp;

/**
* An expression whose value may be shown inline while debugging.
*
* @since 1.35
*/
public final class InlineValue {
private final Range range;
private final String expression;

private InlineValue(Range range, String expression) {
this.range = range;
this.expression = expression;
}

/**
* {@return Range to which the inline value applies}
*/
public Range getRange() {
return range;
}

/**
* {@return The expression of that should be evaluated for the inline value.}
*/
public String getExpression() {
return expression;
}

/**
* {@return a new instance of {@code InlineValue}, based on the provided information.}
*
* @param range range to which the inline value should apply
* @param expression expression that should be evaluted
*/
public static InlineValue createInlineVariable(Range range, String expression) {
return new InlineValue(range, expression);
}
}
42 changes: 42 additions & 0 deletions ide/api.lsp/src/org/netbeans/spi/lsp/InlineValuesProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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.spi.lsp;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import org.netbeans.api.annotations.common.NonNull;
import org.netbeans.api.lsp.InlineValue;
import org.openide.filesystems.FileObject;

/**
* Compute {@link InlineValue}s for the given file and offset.
*
* @since 1.35
*/
public interface InlineValuesProvider {

/**
* Compute {@linkplain InlineValue}s for the given file and location.
*
* @param file file for which the inline values should be computed
* @param currentExecutionPosition position for which the inline values should be computed
* @return the computed inline values
*/
public CompletableFuture<List<? extends InlineValue>> inlineValues(@NonNull FileObject file, int currentExecutionPosition);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

@EditorActionRegistration(name="toggle-inline-hints",
menuPath="View",
menuPosition=899,
menuPosition=897,
preferencesKey=ShowInlineHintsAction.KEY_LINES,
preferencesDefault=ShowInlineHintsAction.DEF_LINES)
public class ShowInlineHintsAction extends AbstractAction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

@EditorActionRegistration(name="toggle-lines-view",
menuPath="View",
menuPosition=898,
menuPosition=895,
preferencesKey=ShowLinesAction.KEY_LINES,
preferencesDefault=ShowLinesAction.DEF_LINES)
public class ShowLinesAction extends AbstractAction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void add(HighlightItem item) {
* @param usePrependText reflect the prepended text setting.
* @return either simple or compound attribute set.
*/
public AttributeSet cutSameFont(Font defaultFont, int maxEndOffset, int wsEndOffset, CharSequence docText, boolean usePrependText) {
public AttributeSet cutSameFont(Font defaultFont, int maxEndOffset, int wsEndOffset, CharSequence docText) {
assert (maxEndOffset <= endOffset()) :
"maxEndOffset=" + maxEndOffset + " > endOffset()=" + endOffset() + ", " + this; // NOI18N
HighlightItem item = get(0);
Expand Down Expand Up @@ -159,13 +159,13 @@ public AttributeSet cutSameFont(Font defaultFont, int maxEndOffset, int wsEndOff

// Extends beyond first highlight
Font firstFont = ViewUtils.getFont(firstAttrs, defaultFont);
Object firstPrependText = usePrependText && firstAttrs != null ? firstAttrs.getAttribute(ViewUtils.KEY_VIRTUAL_TEXT_PREPEND) : null;
Object firstPrependText = firstAttrs != null ? firstAttrs.getAttribute(ViewUtils.KEY_VIRTUAL_TEXT_PREPEND) : null;
int index = 1;
while (true) {
item = get(index);
AttributeSet attrs = item.getAttributes();
Font font = ViewUtils.getFont(attrs, defaultFont);
Object prependText = usePrependText && attrs != null ? attrs.getAttribute(ViewUtils.KEY_VIRTUAL_TEXT_PREPEND) : null;
Object prependText = attrs != null ? attrs.getAttribute(ViewUtils.KEY_VIRTUAL_TEXT_PREPEND) : null;
if (!font.equals(firstFont) || !Objects.equals(firstPrependText, prependText)) { // Stop at itemEndOffset
if (index == 1) { // Just single attribute set
cutStartItems(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ public final class DocumentViewOp
boolean asTextField;

private boolean guideLinesEnable;
private boolean inlineHintsEnable;

private int indentLevelSize;

Expand Down Expand Up @@ -924,13 +923,10 @@ public void run() {
// Line height correction
float lineHeightCorrectionOrig = rowHeightCorrection;
rowHeightCorrection = prefs.getFloat(SimpleValueNames.LINE_HEIGHT_CORRECTION, 1.0f);
boolean inlineHintsEnableOrig = inlineHintsEnable;
inlineHintsEnable = prefs.getBoolean("enable.inline.hints", false); // NOI18N
boolean updateMetrics = (rowHeightCorrection != lineHeightCorrectionOrig);
boolean releaseChildren = nonInitialUpdate &&
((nonPrintableCharactersVisible != nonPrintableCharactersVisibleOrig) ||
(rowHeightCorrection != lineHeightCorrectionOrig) ||
(inlineHintsEnable != inlineHintsEnableOrig));
(rowHeightCorrection != lineHeightCorrectionOrig));
indentLevelSize = getIndentSize();
tabSize = prefs.getInt(SimpleValueNames.TAB_SIZE, EditorPreferencesDefaults.defaultTabSize);
if (updateMetrics) {
Expand Down Expand Up @@ -1172,10 +1168,6 @@ public boolean isGuideLinesEnable() {
return guideLinesEnable && !asTextField;
}

public boolean isInlineHintsEnable() {
return inlineHintsEnable;
}

public int getIndentLevelSize() {
return indentLevelSize;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ public EditorView createView(int startOffset, int limitOffset, boolean forcedLim
}

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

private @NonNull EditorView wrapWithPrependedText(@NonNull EditorView origView, @NullAllowed AttributeSet attrs) {
boolean inlineHints = documentView().op.isInlineHintsEnable();

if (attrs != null && inlineHints && attrs.getAttribute(ViewUtils.KEY_VIRTUAL_TEXT_PREPEND) instanceof String) {
if (attrs != null && attrs.getAttribute(ViewUtils.KEY_VIRTUAL_TEXT_PREPEND) instanceof String) {
return new PrependedTextView(documentView().op, attrs, origView);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* 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.spi.editor.highlighting.support;

import java.util.prefs.PreferenceChangeEvent;
import java.util.prefs.PreferenceChangeListener;
import java.util.prefs.Preferences;
import javax.swing.text.Document;
import org.netbeans.api.editor.mimelookup.MimeLookup;
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
import org.netbeans.spi.editor.highlighting.HighlightsContainer;
import org.netbeans.spi.editor.highlighting.HighlightsSequence;
import org.openide.util.WeakListeners;

public class HighlightsContainers {
public static HighlightsContainer inlineHintsSettingAwareContainer(Document doc, HighlightsContainer delegate) {
class InlineHintsSettingsAwareContainer extends AbstractHighlightsContainer implements PreferenceChangeListener {
private static final String KEY_ENABLE_INLINE_HINTS = "enable.inline.hints";

private final Preferences prefs;
private boolean enabled;

public InlineHintsSettingsAwareContainer() {
String mimeType = DocumentUtilities.getMimeType(doc);
prefs = MimeLookup.getLookup(mimeType).lookup(Preferences.class);
prefs.addPreferenceChangeListener(WeakListeners.create(PreferenceChangeListener.class, this, prefs));
inlineSettingChanged();
}

@Override
public HighlightsSequence getHighlights(int startOffset, int endOffset) {
synchronized (this) {
if (!enabled) {
return HighlightsSequence.EMPTY;
}
}
return delegate.getHighlights(startOffset, endOffset);
}

@Override
public void preferenceChange(PreferenceChangeEvent evt) {
if (KEY_ENABLE_INLINE_HINTS.equals(evt.getKey())) {
inlineSettingChanged();
}
}

private void inlineSettingChanged() {
synchronized (this) {
boolean newValue = prefs.getBoolean(KEY_ENABLE_INLINE_HINTS, false);

if (enabled == newValue) {
return ;
}

enabled = newValue;
}

fireHighlightsChange(0, doc.getLength());
}
}

return new InlineHintsSettingsAwareContainer();
}
}
Loading
Loading