use of com.intellij.openapi.util.ProperTextRange in project intellij-community by JetBrains.
the class DaemonRespondToChangesTest method testRehighlightInDebuggerExpressionFragment.
public void testRehighlightInDebuggerExpressionFragment() throws Exception {
PsiExpressionCodeFragment fragment = JavaCodeFragmentFactory.getInstance(getProject()).createExpressionCodeFragment("+ <caret>\"a\"", null, PsiType.getJavaLangObject(getPsiManager(), GlobalSearchScope.allScope(getProject())), true);
myFile = fragment;
Document document = PsiDocumentManager.getInstance(getProject()).getDocument(fragment);
myEditor = EditorFactory.getInstance().createEditor(document, getProject(), StdFileTypes.JAVA, false);
ProperTextRange visibleRange = makeEditorWindowVisible(new Point(0, 0), myEditor);
assertEquals(document.getTextLength(), visibleRange.getLength());
try {
final EditorInfo editorInfo = new EditorInfo(document.getText());
final String newFileText = editorInfo.getNewFileText();
ApplicationManager.getApplication().runWriteAction(() -> {
if (!document.getText().equals(newFileText)) {
document.setText(newFileText);
}
editorInfo.applyToEditor(myEditor);
});
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
List<HighlightInfo> errors = highlightErrors();
HighlightInfo error = assertOneElement(errors);
assertEquals("Operator '+' cannot be applied to 'java.lang.String'", error.getDescription());
type(" ");
Collection<HighlightInfo> afterTyping = highlightErrors();
HighlightInfo after = assertOneElement(afterTyping);
assertEquals("Operator '+' cannot be applied to 'java.lang.String'", after.getDescription());
} finally {
EditorFactory.getInstance().releaseEditor(myEditor);
}
}
use of com.intellij.openapi.util.ProperTextRange in project intellij-community by JetBrains.
the class DaemonRespondToChangesTest method testErrorInTheEndOutsideVisibleArea.
public void testErrorInTheEndOutsideVisibleArea() throws Throwable {
String text = "<xml> \n" + StringUtil.repeatSymbol('\n', 1000) + "</xml>\nxxxxx<caret>";
configureByText(StdFileTypes.XML, text);
ProperTextRange visibleRange = makeEditorWindowVisible(new Point(0, 1000), myEditor);
assertTrue(visibleRange.getStartOffset() > 0);
List<HighlightInfo> warns = highlightErrors();
HighlightInfo info = assertOneElement(warns);
assertEquals("Top level element is not completed", info.getDescription());
type("xxx");
List<HighlightInfo> errors = highlightErrors();
info = assertOneElement(errors);
assertEquals("Top level element is not completed", info.getDescription());
}
use of com.intellij.openapi.util.ProperTextRange in project intellij-community by JetBrains.
the class VisibleHighlightingPassFactory method calculateVisibleRange.
@NotNull
public static ProperTextRange calculateVisibleRange(@NotNull Editor editor) {
Rectangle rect = editor.getScrollingModel().getVisibleArea();
LogicalPosition startPosition = editor.xyToLogicalPosition(new Point(rect.x, rect.y));
int visibleStart = editor.logicalPositionToOffset(startPosition);
LogicalPosition endPosition = editor.xyToLogicalPosition(new Point(rect.x + rect.width, rect.y + rect.height));
int visibleEnd = editor.logicalPositionToOffset(new LogicalPosition(endPosition.line + 1, 0));
return new ProperTextRange(visibleStart, Math.max(visibleEnd, visibleStart));
}
use of com.intellij.openapi.util.ProperTextRange in project intellij-community by JetBrains.
the class Divider method divideInsideAndOutsideInOneRoot.
private static void divideInsideAndOutsideInOneRoot(@NotNull PsiFile root, @NotNull TextRange restrictRange, @NotNull TextRange priorityRange, @NotNull List<PsiElement> inside, @NotNull List<ProperTextRange> insideRanges, @NotNull List<PsiElement> outside, @NotNull List<ProperTextRange> outsideRanges, @NotNull List<PsiElement> outParents, @NotNull List<ProperTextRange> outParentRanges, boolean includeParents) {
int startOffset = restrictRange.getStartOffset();
int endOffset = restrictRange.getEndOffset();
final Condition<PsiElement>[] filters = Extensions.getExtensions(CollectHighlightsUtil.EP_NAME);
final TIntStack starts = new TIntStack(STARTING_TREE_HEIGHT);
starts.push(startOffset);
final Stack<PsiElement> elements = new Stack<>(STARTING_TREE_HEIGHT);
final Stack<PsiElement> children = new Stack<>(STARTING_TREE_HEIGHT);
PsiElement element = root;
PsiElement child = HAVE_TO_GET_CHILDREN;
int offset = 0;
while (true) {
ProgressManager.checkCanceled();
for (Condition<PsiElement> filter : filters) {
if (!filter.value(element)) {
assert child == HAVE_TO_GET_CHILDREN;
// do not want to process children
child = null;
break;
}
}
boolean startChildrenVisiting;
if (child == HAVE_TO_GET_CHILDREN) {
startChildrenVisiting = true;
child = element.getFirstChild();
} else {
startChildrenVisiting = false;
}
if (child == null) {
if (startChildrenVisiting) {
// leaf element
offset += element.getTextLength();
}
int start = starts.pop();
if (startOffset <= start && offset <= endOffset) {
if (priorityRange.containsRange(start, offset)) {
inside.add(element);
insideRanges.add(new ProperTextRange(start, offset));
} else {
outside.add(element);
outsideRanges.add(new ProperTextRange(start, offset));
}
}
if (elements.isEmpty())
break;
element = elements.pop();
child = children.pop();
} else {
// composite element
if (offset > endOffset)
break;
children.push(child.getNextSibling());
starts.push(offset);
elements.push(element);
element = child;
child = HAVE_TO_GET_CHILDREN;
}
}
if (includeParents) {
PsiElement parent = !outside.isEmpty() ? outside.get(outside.size() - 1) : !inside.isEmpty() ? inside.get(inside.size() - 1) : CollectHighlightsUtil.findCommonParent(root, startOffset, endOffset);
while (parent != null && !(parent instanceof PsiFile)) {
parent = parent.getParent();
if (parent != null) {
outParents.add(parent);
TextRange textRange = parent.getTextRange();
assert textRange != null : "Text range for " + parent + " is null. " + parent.getClass() + "; root: " + root + ": " + root.getVirtualFile();
outParentRanges.add(ProperTextRange.create(textRange));
}
}
}
assert inside.size() == insideRanges.size();
assert outside.size() == outsideRanges.size();
assert outParents.size() == outParentRanges.size();
}
use of com.intellij.openapi.util.ProperTextRange in project intellij-community by JetBrains.
the class SelectInEditorManagerImpl method selectInEditor.
@Override
public void selectInEditor(VirtualFile file, final int startOffset, final int endOffset, final boolean toSelectLine, final boolean toUseNormalSelection) {
releaseAll();
final TextRange textRange;
if (file instanceof VirtualFileWindow) {
DocumentWindow documentWindow = ((VirtualFileWindow) file).getDocumentWindow();
textRange = documentWindow.injectedToHost(new TextRange(startOffset, endOffset));
file = ((VirtualFileWindow) file).getDelegate();
} else {
textRange = new ProperTextRange(startOffset, endOffset);
}
openEditor(file, endOffset);
final Editor editor = openEditor(file, textRange.getStartOffset());
SwingUtilities.invokeLater(() -> {
if (editor != null && !editor.isDisposed()) {
doSelect(toUseNormalSelection, editor, toSelectLine, textRange);
}
});
}
Aggregations