Skip to content

Commit

Permalink
fix: Single/double quotes displayed not correctly in warch area when
Browse files Browse the repository at this point in the history
debug TypeScript file

Fixes redhat-developer#812

Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Feb 7, 2025
1 parent 8363e8c commit 2a1f0e2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,34 +92,11 @@ private XValuePresentation getPresentation() {
public void computeSourcePosition(@NotNull XNavigatable navigatable) {
stackFrame
.getSourcePositionFor(variable)
.thenAccept(sourcePosition -> {
if (sourcePosition != null) {
navigatable.setSourcePosition(sourcePosition);
}
});

/*@Nullable
private XSourcePosition findPosition() {
XDebugSession debugSession = client.getSession();
if (debugSession == null) {
return null;
}
XStackFrame stackFrame = debugSession.getCurrentStackFrame();
if (stackFrame == null) {
return null;
}
Project project = debugSession.getProject();
XSourcePosition position = debugSession.getCurrentPosition();
Editor editor = ((FileEditorManagerImpl) FileEditorManager.getInstance(project))
.getSelectedTextEditor(true);
if (editor == null || position == null) {
return null;
}
VirtualFile virtualFile = null;
int offset = 0;
return XDebuggerUtil.getInstance().createPositionByOffset(virtualFile, resolved.getTextOffset());
}*/

.thenAccept(sourcePosition -> {
if (sourcePosition != null) {
navigatable.setSourcePosition(sourcePosition);
}
});
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@
package com.redhat.devtools.lsp4ij.dap.descriptors;

import com.intellij.icons.AllIcons;
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors;
import com.intellij.xdebugger.frame.presentation.XRegularValuePresentation;
import com.intellij.xdebugger.frame.presentation.XStringValuePresentation;
import com.intellij.xdebugger.frame.presentation.XValuePresentation;
import com.redhat.devtools.lsp4ij.dap.client.variables.providers.HighlighterDebugVariablePositionProvider;
import com.intellij.xdebugger.frame.presentation.*;
import com.redhat.devtools.lsp4ij.dap.client.variables.providers.DebugVariablePositionProvider;
import com.redhat.devtools.lsp4ij.dap.client.variables.providers.HighlighterDebugVariablePositionProvider;
import com.redhat.devtools.lsp4ij.internal.StringUtils;
import org.eclipse.lsp4j.debug.Variable;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -45,7 +42,7 @@ public Icon getIcon(@NotNull Variable variable) {
if (StringUtils.isEmpty(type)) {
return AllIcons.Nodes.Variable;
}
if (isStringType(type) || isNumberType(type) || isBooleanType(type)) {
if (isStringType(type) || isNumericType(type) || isBooleanType(type)) {
return AllIcons.Debugger.Db_primitive;
}
if (isObjectType(type)) {
Expand All @@ -71,33 +68,39 @@ public Icon getIcon(@NotNull Variable variable) {
* @return value representation for the given variable.
*/
public @NotNull XValuePresentation getValuePresentation(@NotNull Variable variable) {
final String value = variable.getValue() != null ? variable.getValue() : "";
final String type = variable.getType() != null ? variable.getType() : "";
final String formattedValue = formatValue(variable);

// String type
if (isStringType(type)) {
String stringValue = value.replaceAll("^\"+|\"+$", "");
return new XStringValuePresentation(stringValue);
return new XStringValuePresentation(formattedValue);
}

if (isNumberType(type)) {
return new XRegularValuePresentation(value, type) {
@Override
public void renderValue(@NotNull XValueTextRenderer renderer) {
renderer.renderValue(value, DefaultLanguageHighlighterColors.NUMBER);
}
};
// Numeric type
if (isNumericType(type)) {
return new XNumericValuePresentation(formattedValue);
}

// Boolean type
if (isBooleanType(type)) {
return new XValuePresentation() {
@Override
public void renderValue(@NotNull XValueTextRenderer renderer) {
renderer.renderValue(value, DefaultLanguageHighlighterColors.KEYWORD);
}
};
return new XKeywordValuePresentation(formattedValue);
}

return new XRegularValuePresentation(value, type);
// Other type
return new XRegularValuePresentation(formattedValue, type);
}

@NotNull
protected String formatValue(@NotNull Variable variable) {
final String value = variable.getValue() != null ? variable.getValue() : "";
final String type = variable.getType() != null ? variable.getType() : "";
if (isStringType(type)) {
// String type (ex:value='foo' or "foo")
// Remove start/end simple and double quote
// to display only foo
return removeQuotes(value);
}
return value;
}

protected boolean isStringType(@NotNull String type) {
Expand All @@ -109,7 +112,7 @@ protected boolean isBooleanType(@NotNull String type) {
"bool".equalsIgnoreCase(type);
}

protected boolean isNumberType(@NotNull String type) {
protected boolean isNumericType(@NotNull String type) {
return "number".equalsIgnoreCase(type) ||
"int".equalsIgnoreCase(type) ||
"long".equalsIgnoreCase(type) ||
Expand Down Expand Up @@ -144,4 +147,11 @@ public void setServerDescriptor(@NotNull DebugAdapterDescriptor serverDescriptor
public @NotNull Collection<DebugVariablePositionProvider> getDebugVariablePositionProvider() {
return Collections.singletonList(new HighlighterDebugVariablePositionProvider());
}

@NotNull
private static String removeQuotes(@NotNull String value) {
return value
.replaceAll("^\"+|\"+$", "")
.replaceAll("^\'+|\'+$", "");
}
}

0 comments on commit 2a1f0e2

Please sign in to comment.