use of com.intellij.openapi.util.ProperTextRange in project intellij-community by JetBrains.
the class DaemonRespondToChangesTest method testErrorDisappearsRightAfterTypingInsideVisibleAreaWhileDaemonContinuesToChugAlong.
public void testErrorDisappearsRightAfterTypingInsideVisibleAreaWhileDaemonContinuesToChugAlong() throws Throwable {
String text = "class X{\nint xxx;\n{\nint i = <selection>null</selection><caret>;\n" + StringUtil.repeat("{ this.hashCode(); }\n\n\n", 10000) + "}}";
configureByText(StdFileTypes.JAVA, text);
((EditorImpl) myEditor).getScrollPane().getViewport().setSize(100, 100);
DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(true);
myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
((EditorImpl) myEditor).getScrollPane().getViewport().setViewPosition(new Point(0, 0));
((EditorImpl) myEditor).getScrollPane().getViewport().setExtentSize(new Dimension(100, 100000));
ProperTextRange visibleRange = VisibleHighlightingPassFactory.calculateVisibleRange(getEditor());
assertTrue(visibleRange.getLength() > 0);
final Document document = myEditor.getDocument();
assertTrue(visibleRange.getLength() < document.getTextLength());
List<HighlightInfo> err1 = highlightErrors();
HighlightInfo info = assertOneElement(err1);
final String errorDescription = "Incompatible types. Found: 'null', required: 'int'";
assertEquals(errorDescription, info.getDescription());
MarkupModelEx model = (MarkupModelEx) DocumentMarkupModel.forDocument(document, myProject, false);
final boolean[] errorRemoved = { false };
model.addMarkupModelListener(getTestRootDisposable(), new MarkupModelListener.Adapter() {
@Override
public void beforeRemoved(@NotNull RangeHighlighterEx highlighter) {
Object tt = highlighter.getErrorStripeTooltip();
if (!(tt instanceof HighlightInfo))
return;
String description = ((HighlightInfo) tt).getDescription();
if (errorDescription.equals(description)) {
errorRemoved[0] = true;
List<TextEditorHighlightingPass> passes = myDaemonCodeAnalyzer.getPassesToShowProgressFor(document);
GeneralHighlightingPass ghp = null;
for (TextEditorHighlightingPass pass : passes) {
if (pass instanceof GeneralHighlightingPass && pass.getId() == Pass.UPDATE_ALL) {
assert ghp == null : ghp;
ghp = (GeneralHighlightingPass) pass;
}
}
assertNotNull(ghp);
boolean finished = ghp.isFinished();
assertFalse(finished);
}
}
});
type("1");
List<HighlightInfo> errors = highlightErrors();
assertEmpty(errors);
assertTrue(errorRemoved[0]);
}
use of com.intellij.openapi.util.ProperTextRange in project intellij-community by JetBrains.
the class InjectedSelfElementInfo method restoreElement.
@Override
public PsiElement restoreElement() {
PsiFile hostFile = myHostContext.getContainingFile();
if (hostFile == null || !hostFile.isValid())
return null;
PsiElement hostContext = myHostContext.getElement();
if (hostContext == null)
return null;
Segment segment = myInjectedFileRangeInHostFile.getPsiRange();
if (segment == null)
return null;
PsiFile injectedPsi = getInjectedFileIn(hostContext, hostFile, TextRange.create(segment));
ProperTextRange rangeInInjected = hostToInjected(true, segment, injectedPsi, myAffixOffsets);
if (rangeInInjected == null)
return null;
return myType.findPsiElement(injectedPsi, rangeInInjected.getStartOffset(), rangeInInjected.getEndOffset());
}
use of com.intellij.openapi.util.ProperTextRange in project intellij-community by JetBrains.
the class UsageSerializable method serializeMe.
@Override
public void serializeMe(UsageInfo info, StringBuilder os) throws IOException {
//final SmartPsiElementPointer<?> pointer = info.getSmartPointer();
final GenericElementSignatureProvider provider = new GenericElementSignatureProvider();
final String signature = provider.getSignature(info.getElement());
append(os, info.getFile().getVirtualFile().getPath());
os.append(separator);
append(os, signature);
os.append(separator);
final ProperTextRange rangeInElement = info.getRangeInElement();
if (rangeInElement == null) {
append(os, "-1");
os.append(separator);
append(os, "-1");
os.append(separator);
} else {
append(os, String.valueOf(rangeInElement.getStartOffset()));
os.append(separator);
append(os, String.valueOf(rangeInElement.getEndOffset()));
os.append(separator);
}
append(os, String.valueOf(info.isNonCodeUsage()));
os.append(separator);
append(os, String.valueOf(info.isDynamicUsage()));
os.append(separator);
final String text = new UsageInfo2UsageAdapter(info).getPlainText();
append(os, text);
os.append(separator);
}
use of com.intellij.openapi.util.ProperTextRange in project intellij-community by JetBrains.
the class ShredImpl method getRangeInsideHost.
@Override
@NotNull
public TextRange getRangeInsideHost() {
PsiLanguageInjectionHost host = getHost();
Segment psiRange = relevantRangeInHost.getPsiRange();
TextRange textRange = psiRange == null ? null : TextRange.create(psiRange);
if (host == null) {
if (textRange != null)
return textRange;
Segment fromSP = hostElementPointer.getPsiRange();
if (fromSP != null)
return TextRange.create(fromSP);
return new TextRange(0, 0);
}
TextRange hostTextRange = host.getTextRange();
textRange = textRange == null ? null : textRange.intersection(hostTextRange);
if (textRange == null)
return new ProperTextRange(0, hostTextRange.getLength());
return textRange.shiftRight(-hostTextRange.getStartOffset());
}
use of com.intellij.openapi.util.ProperTextRange in project intellij-community by JetBrains.
the class SelectionModelWindow method setSelection.
@Override
public void setSelection(@Nullable VisualPosition startPosition, int startOffset, @Nullable VisualPosition endPosition, int endOffset) {
TextRange hostRange = myDocument.injectedToHost(new ProperTextRange(startOffset, endOffset));
myHostModel.setSelection(startPosition, hostRange.getStartOffset(), endPosition, hostRange.getEndOffset());
}
Aggregations