mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
show source text as value name, part of "WEB-6069 CoffeeScript Debugger doesn't show value of the variables"
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed 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 com.intellij.xdebugger.evaluation;
|
||||
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ExpressionInfo {
|
||||
private final TextRange textRange;
|
||||
private final String expressionText;
|
||||
private final String displayText;
|
||||
|
||||
public ExpressionInfo(@NotNull TextRange textRange) {
|
||||
this(textRange, null);
|
||||
}
|
||||
|
||||
public ExpressionInfo(@NotNull TextRange textRange, @Nullable String expressionText) {
|
||||
this(textRange, expressionText, expressionText);
|
||||
}
|
||||
|
||||
public ExpressionInfo(@NotNull TextRange textRange, @Nullable String expressionText, @Nullable String displayText) {
|
||||
this.textRange = textRange;
|
||||
this.expressionText = expressionText;
|
||||
this.displayText = displayText;
|
||||
}
|
||||
|
||||
/**
|
||||
* Text range to highlight as link,
|
||||
* will be used to compute evaluation and display text if these values not specified.
|
||||
*/
|
||||
@NotNull
|
||||
public TextRange getTextRange() {
|
||||
return textRange;
|
||||
}
|
||||
|
||||
/**
|
||||
* Expression to evaluate
|
||||
*/
|
||||
@Nullable
|
||||
public String getExpressionText() {
|
||||
return expressionText;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getDisplayText() {
|
||||
return displayText;
|
||||
}
|
||||
}
|
||||
+19
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -108,6 +108,8 @@ public abstract class XDebuggerEvaluator {
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #getExpressionInfoAtOffset(com.intellij.openapi.project.Project, com.intellij.openapi.editor.Document, int, boolean)}
|
||||
*
|
||||
* Return text range of expression which can be evaluated.
|
||||
*
|
||||
* @param project project
|
||||
@@ -118,6 +120,7 @@ public abstract class XDebuggerEvaluator {
|
||||
* @return pair of text range of expression (to highlight as link) and actual expression to evaluate (optional, could be null)
|
||||
*/
|
||||
@Nullable
|
||||
@Deprecated
|
||||
public Pair<TextRange, String> getExpressionAtOffset(@NotNull Project project, @NotNull Document document, int offset, boolean sideEffectsAllowed) {
|
||||
TextRange range = getExpressionRangeAtOffset(project, document, offset, sideEffectsAllowed);
|
||||
if (range == null) {
|
||||
@@ -128,6 +131,21 @@ public abstract class XDebuggerEvaluator {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param project project
|
||||
* @param document document
|
||||
* @param offset offset
|
||||
* @param sideEffectsAllowed if this parameter is false, the expression should not have any side effects when evaluated
|
||||
* (such expressions are evaluated in quick popups)
|
||||
* @return {@link com.intellij.xdebugger.evaluation.ExpressionInfo} of expression which can be evaluated
|
||||
*/
|
||||
@Nullable
|
||||
public ExpressionInfo getExpressionInfoAtOffset(@NotNull Project project, @NotNull Document document, int offset, boolean sideEffectsAllowed) {
|
||||
@SuppressWarnings("deprecation")
|
||||
Pair<TextRange, String> result = getExpressionAtOffset(project, document, offset, sideEffectsAllowed);
|
||||
return result == null ? null : new ExpressionInfo(result.first, result.second);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this method to format selected text before it is shown in 'Evaluate' dialog
|
||||
*/
|
||||
|
||||
+16
-6
@@ -20,10 +20,9 @@ import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.xdebugger.XDebugSession;
|
||||
import com.intellij.xdebugger.evaluation.ExpressionInfo;
|
||||
import com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider;
|
||||
import com.intellij.xdebugger.evaluation.XDebuggerEvaluator;
|
||||
import com.intellij.xdebugger.frame.XStackFrame;
|
||||
@@ -46,7 +45,7 @@ public class XDebuggerEvaluateActionHandler extends XDebuggerActionHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
@Nullable Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
|
||||
Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
|
||||
|
||||
String selectedText = editor != null ? editor.getSelectionModel().getSelectedText() : null;
|
||||
if (selectedText != null) {
|
||||
@@ -74,14 +73,25 @@ public class XDebuggerEvaluateActionHandler extends XDebuggerActionHandler {
|
||||
}
|
||||
|
||||
Document document = editor.getDocument();
|
||||
return getExpressionText(evaluator.getExpressionAtOffset(project, document, editor.getCaretModel().getOffset(), true), document);
|
||||
return getExpressionText(evaluator.getExpressionInfoAtOffset(project, document, editor.getCaretModel().getOffset(), true), document);
|
||||
}
|
||||
|
||||
public static String getExpressionText(@Nullable Pair<TextRange, String> expressionInfo, @NotNull Document document) {
|
||||
@Nullable
|
||||
public static String getExpressionText(@Nullable ExpressionInfo expressionInfo, @NotNull Document document) {
|
||||
if (expressionInfo == null) {
|
||||
return null;
|
||||
}
|
||||
return expressionInfo.second == null ? document.getText(expressionInfo.first) : expressionInfo.second;
|
||||
String text = expressionInfo.getExpressionText();
|
||||
return text == null ? document.getText(expressionInfo.getTextRange()) : text;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getDisplayText(@Nullable ExpressionInfo expressionInfo, @NotNull Document document) {
|
||||
if (expressionInfo == null) {
|
||||
return null;
|
||||
}
|
||||
String text = expressionInfo.getDisplayText();
|
||||
return text == null ? document.getText(expressionInfo.getTextRange()) : text;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-3
@@ -9,11 +9,11 @@ import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.actionSystem.ex.ActionUtil;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.xdebugger.XDebugSession;
|
||||
import com.intellij.xdebugger.evaluation.ExpressionInfo;
|
||||
import com.intellij.xdebugger.evaluation.XDebuggerEvaluator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -60,13 +60,13 @@ public class XEvaluateInConsoleFromEditorActionHandler extends XAddToWatchesFrom
|
||||
else {
|
||||
XDebuggerEvaluator evaluator = session.getDebugProcess().getEvaluator();
|
||||
if (evaluator != null) {
|
||||
Pair<TextRange, String> expressionInfo = evaluator.getExpressionAtOffset(session.getProject(), editor.getDocument(), selectionStart, true);
|
||||
ExpressionInfo expressionInfo = evaluator.getExpressionInfoAtOffset(session.getProject(), editor.getDocument(), selectionStart, true);
|
||||
if (expressionInfo == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// todo check - is it wrong in case of not-null expressionInfo.second - copied (to console history document) text (text range) could be not correct statement?
|
||||
range = expressionInfo.first;
|
||||
range = expressionInfo.getTextRange();
|
||||
text = XDebuggerEvaluateActionHandler.getExpressionText(expressionInfo, editor.getDocument());
|
||||
}
|
||||
else {
|
||||
|
||||
+10
-10
@@ -20,11 +20,11 @@ import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.SelectionModel;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.xdebugger.XDebugSession;
|
||||
import com.intellij.xdebugger.XDebuggerManager;
|
||||
import com.intellij.xdebugger.evaluation.ExpressionInfo;
|
||||
import com.intellij.xdebugger.evaluation.XDebuggerEvaluator;
|
||||
import com.intellij.xdebugger.impl.evaluate.quick.common.AbstractValueHint;
|
||||
import com.intellij.xdebugger.impl.evaluate.quick.common.QuickEvaluateHandler;
|
||||
@@ -62,35 +62,35 @@ public class XQuickEvaluateHandler extends QuickEvaluateHandler {
|
||||
@Override
|
||||
public XValueHint compute() {
|
||||
int offset = AbstractValueHint.calculateOffset(editor, point);
|
||||
Pair<TextRange, String> expressionData = getExpressionRange(evaluator, project, type, editor, offset);
|
||||
if (expressionData == null) {
|
||||
ExpressionInfo expressionInfo = getExpressionInfo(evaluator, project, type, editor, offset);
|
||||
if (expressionInfo == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int textLength = editor.getDocument().getTextLength();
|
||||
TextRange range = expressionData.first;
|
||||
TextRange range = expressionInfo.getTextRange();
|
||||
if (range.getStartOffset() > range.getEndOffset() || range.getStartOffset() < 0 || range.getEndOffset() > textLength) {
|
||||
LOG.error("invalid range: " + range + ", text length = " + textLength + ", evaluator: " + evaluator);
|
||||
return null;
|
||||
}
|
||||
|
||||
return new XValueHint(project, editor, point, type, expressionData, evaluator, session);
|
||||
return new XValueHint(project, editor, point, type, expressionInfo, evaluator, session);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Pair<TextRange, String> getExpressionRange(final XDebuggerEvaluator evaluator, final Project project,
|
||||
final ValueHintType type,
|
||||
final Editor editor, final int offset) {
|
||||
private static ExpressionInfo getExpressionInfo(final XDebuggerEvaluator evaluator, final Project project,
|
||||
final ValueHintType type,
|
||||
final Editor editor, final int offset) {
|
||||
SelectionModel selectionModel = editor.getSelectionModel();
|
||||
int selectionStart = selectionModel.getSelectionStart();
|
||||
int selectionEnd = selectionModel.getSelectionEnd();
|
||||
if ((type == ValueHintType.MOUSE_CLICK_HINT || type == ValueHintType.MOUSE_ALT_OVER_HINT) && selectionModel.hasSelection()
|
||||
&& selectionStart <= offset && offset <= selectionEnd) {
|
||||
return Pair.create(new TextRange(selectionStart, selectionEnd), null);
|
||||
return new ExpressionInfo(new TextRange(selectionStart, selectionEnd));
|
||||
}
|
||||
return evaluator.getExpressionAtOffset(project, editor.getDocument(), offset, false);
|
||||
return evaluator.getExpressionInfoAtOffset(project, editor.getDocument(), offset, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+12
-11
@@ -25,7 +25,6 @@ import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.vcs.changes.issueLinks.LinkMouseListenerBase;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.ui.SimpleColoredComponent;
|
||||
@@ -34,6 +33,7 @@ import com.intellij.util.Consumer;
|
||||
import com.intellij.xdebugger.XDebugSession;
|
||||
import com.intellij.xdebugger.XDebuggerUtil;
|
||||
import com.intellij.xdebugger.XSourcePosition;
|
||||
import com.intellij.xdebugger.evaluation.ExpressionInfo;
|
||||
import com.intellij.xdebugger.evaluation.XDebuggerEvaluator;
|
||||
import com.intellij.xdebugger.frame.XDebuggerTreeNodeHyperlink;
|
||||
import com.intellij.xdebugger.frame.XFullValueEvaluator;
|
||||
@@ -66,16 +66,18 @@ public class XValueHint extends AbstractValueHint {
|
||||
private final XDebuggerEvaluator myEvaluator;
|
||||
private final XDebugSession myDebugSession;
|
||||
private final String myExpression;
|
||||
private final String myValueName;
|
||||
private final @Nullable XSourcePosition myExpressionPosition;
|
||||
|
||||
public XValueHint(@NotNull Project project, @NotNull Editor editor, @NotNull Point point, @NotNull ValueHintType type,
|
||||
@NotNull Pair<TextRange, String> expressionData, @NotNull XDebuggerEvaluator evaluator,
|
||||
@NotNull ExpressionInfo expressionInfo, @NotNull XDebuggerEvaluator evaluator,
|
||||
@NotNull XDebugSession session) {
|
||||
super(project, editor, point, type, expressionData.first);
|
||||
super(project, editor, point, type, expressionInfo.getTextRange());
|
||||
|
||||
myEvaluator = evaluator;
|
||||
myDebugSession = session;
|
||||
myExpression = XDebuggerEvaluateActionHandler.getExpressionText(expressionData, editor.getDocument());
|
||||
myExpression = XDebuggerEvaluateActionHandler.getExpressionText(expressionInfo, editor.getDocument());
|
||||
myValueName = XDebuggerEvaluateActionHandler.getDisplayText(expressionInfo, editor.getDocument());
|
||||
|
||||
VirtualFile file;
|
||||
ConsoleView consoleView = ConsoleViewImpl.CONSOLE_VIEW_IN_EDITOR_VIEW.get(editor);
|
||||
@@ -87,7 +89,7 @@ public class XValueHint extends AbstractValueHint {
|
||||
file = FileDocumentManager.getInstance().getFile(editor.getDocument());
|
||||
}
|
||||
|
||||
myExpressionPosition = file != null ? XDebuggerUtil.getInstance().createPositionByOffset(file, expressionData.first.getStartOffset()) : null;
|
||||
myExpressionPosition = file != null ? XDebuggerUtil.getInstance().createPositionByOffset(file, expressionInfo.getTextRange().getStartOffset()) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -112,7 +114,7 @@ public class XValueHint extends AbstractValueHint {
|
||||
}
|
||||
|
||||
SimpleColoredText text = new SimpleColoredText();
|
||||
text.append(myExpression, XDebuggerUIConstants.VALUE_NAME_ATTRIBUTES);
|
||||
text.append(myValueName, XDebuggerUIConstants.VALUE_NAME_ATTRIBUTES);
|
||||
XValueNodeImpl.buildText(valuePresenter, text);
|
||||
|
||||
if (!hasChildren) {
|
||||
@@ -130,13 +132,13 @@ public class XValueHint extends AbstractValueHint {
|
||||
showHint(component);
|
||||
}
|
||||
else if (getType() == ValueHintType.MOUSE_CLICK_HINT) {
|
||||
showTree(result, myExpression);
|
||||
showTree(result);
|
||||
}
|
||||
else {
|
||||
JComponent component = createExpandableHintComponent(text, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
showTree(result, myExpression);
|
||||
showTree(result);
|
||||
}
|
||||
});
|
||||
showHint(component);
|
||||
@@ -162,11 +164,10 @@ public class XValueHint extends AbstractValueHint {
|
||||
}, myExpressionPosition);
|
||||
}
|
||||
|
||||
private void showTree(final XValue value, final String name) {
|
||||
private void showTree(@NotNull XValue value) {
|
||||
XValueMarkers<?,?> valueMarkers = ((XDebugSessionImpl)myDebugSession).getValueMarkers();
|
||||
Pair<XValue, String> pair = Pair.create(value, name);
|
||||
XDebuggerTreeCreator creator = new XDebuggerTreeCreator(myDebugSession.getProject(), myDebugSession.getDebugProcess().getEditorsProvider(),
|
||||
myDebugSession.getCurrentPosition(), valueMarkers);
|
||||
showTreePopup(creator, pair);
|
||||
showTreePopup(creator, Pair.create(value, myValueName));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user