use of com.intellij.injected.editor.EditorWindow in project intellij-community by JetBrains.
the class CompletionAssertions method assertCommitSuccessful.
static void assertCommitSuccessful(Editor editor, PsiFile psiFile) {
Document document = editor.getDocument();
int docLength = document.getTextLength();
int psiLength = psiFile.getTextLength();
PsiDocumentManager manager = PsiDocumentManager.getInstance(psiFile.getProject());
boolean committed = !manager.isUncommited(document);
if (docLength == psiLength && committed) {
return;
}
FileViewProvider viewProvider = psiFile.getViewProvider();
String message = "unsuccessful commit:";
message += "\nmatching=" + (psiFile == manager.getPsiFile(document));
message += "\ninjectedEditor=" + (editor instanceof EditorWindow);
message += "\ninjectedFile=" + InjectedLanguageManager.getInstance(psiFile.getProject()).isInjectedFragment(psiFile);
message += "\ncommitted=" + committed;
message += "\nfile=" + psiFile.getName();
message += "\nfile class=" + psiFile.getClass();
message += "\nfile.valid=" + psiFile.isValid();
message += "\nfile.physical=" + psiFile.isPhysical();
message += "\nfile.eventSystemEnabled=" + viewProvider.isEventSystemEnabled();
message += "\nlanguage=" + psiFile.getLanguage();
message += "\ndoc.length=" + docLength;
message += "\npsiFile.length=" + psiLength;
String fileText = psiFile.getText();
if (fileText != null) {
message += "\npsiFile.text.length=" + fileText.length();
}
FileASTNode node = psiFile.getNode();
if (node != null) {
message += "\nnode.length=" + node.getTextLength();
String nodeText = node.getText();
if (nodeText != null) {
message += "\nnode.text.length=" + nodeText.length();
}
}
VirtualFile virtualFile = viewProvider.getVirtualFile();
message += "\nvirtualFile=" + virtualFile;
message += "\nvirtualFile.class=" + virtualFile.getClass();
message += "\n" + DebugUtil.currentStackTrace();
throw new LogEventException("Commit unsuccessful", message, new Attachment(virtualFile.getPath() + "_file.txt", fileText), createAstAttachment(psiFile, psiFile), new Attachment("docText.txt", document.getText()));
}
use of com.intellij.injected.editor.EditorWindow in project intellij-community by JetBrains.
the class LookupUi method refreshUi.
void refreshUi(boolean selectionVisible, boolean itemsChanged, boolean reused, boolean onExplicitAction) {
Editor editor = myLookup.getTopLevelEditor();
if (editor.getComponent().getRootPane() == null || editor instanceof EditorWindow && !((EditorWindow) editor).isValid()) {
return;
}
updateScrollbarVisibility();
if (myLookup.myResizePending || itemsChanged) {
myMaximumHeight = Integer.MAX_VALUE;
}
Rectangle rectangle = calculatePosition();
myMaximumHeight = rectangle.height;
if (myLookup.myResizePending || itemsChanged) {
myLookup.myResizePending = false;
myLookup.pack();
}
HintManagerImpl.updateLocation(myLookup, editor, rectangle.getLocation());
if (reused || selectionVisible || onExplicitAction) {
myLookup.ensureSelectionVisible(false);
}
}
use of com.intellij.injected.editor.EditorWindow in project intellij-community by JetBrains.
the class LookupImpl method getPsiElement.
@Override
public PsiElement getPsiElement() {
PsiFile file = getPsiFile();
if (file == null)
return null;
int offset = getLookupStart();
Editor editor = getEditor();
if (editor instanceof EditorWindow) {
offset = editor.logicalPositionToOffset(((EditorWindow) editor).hostToInjected(myEditor.offsetToLogicalPosition(offset)));
}
if (offset > 0)
return file.findElementAt(offset - 1);
return file.findElementAt(0);
}
use of com.intellij.injected.editor.EditorWindow in project intellij-community by JetBrains.
the class ShowIntentionActionsHandler method availableFor.
public static boolean availableFor(@NotNull PsiFile psiFile, @NotNull Editor editor, @NotNull IntentionAction action) {
if (!psiFile.isValid())
return false;
int offset = editor.getCaretModel().getOffset();
PsiElement psiElement = psiFile.findElementAt(offset);
boolean inProject = psiFile.getManager().isInProject(psiFile);
try {
Project project = psiFile.getProject();
if (action instanceof SuppressIntentionActionFromFix) {
final ThreeState shouldBeAppliedToInjectionHost = ((SuppressIntentionActionFromFix) action).isShouldBeAppliedToInjectionHost();
if (editor instanceof EditorWindow && shouldBeAppliedToInjectionHost == ThreeState.YES) {
return false;
}
if (!(editor instanceof EditorWindow) && shouldBeAppliedToInjectionHost == ThreeState.NO) {
return false;
}
}
if (action instanceof PsiElementBaseIntentionAction) {
if (!inProject || psiElement == null || !((PsiElementBaseIntentionAction) action).isAvailable(project, editor, psiElement))
return false;
} else if (!action.isAvailable(project, editor, psiFile)) {
return false;
}
} catch (IndexNotReadyException e) {
return false;
}
return true;
}
use of com.intellij.injected.editor.EditorWindow in project intellij-community by JetBrains.
the class GotoDeclarationAction method findTargetElementsNoVS.
@Nullable
public static PsiElement[] findTargetElementsNoVS(Project project, Editor editor, int offset, boolean lookupAccepted) {
Document document = editor.getDocument();
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document);
if (file == null)
return null;
PsiElement elementAt = file.findElementAt(TargetElementUtil.adjustOffset(file, document, offset));
for (GotoDeclarationHandler handler : Extensions.getExtensions(GotoDeclarationHandler.EP_NAME)) {
try {
PsiElement[] result = handler.getGotoDeclarationTargets(elementAt, offset, editor);
if (result != null && result.length > 0) {
for (PsiElement element : result) {
if (element == null) {
LOG.error("Null target element is returned by " + handler.getClass().getName());
return null;
}
}
return result;
}
} catch (AbstractMethodError e) {
LOG.error(new ExtensionException(handler.getClass()));
}
}
int flags = TargetElementUtil.getInstance().getAllAccepted() & ~TargetElementUtil.ELEMENT_NAME_ACCEPTED;
if (!lookupAccepted) {
flags &= ~TargetElementUtil.LOOKUP_ITEM_ACCEPTED;
}
PsiElement element = TargetElementUtil.getInstance().findTargetElement(editor, flags, offset);
if (element != null) {
return new PsiElement[] { element };
}
// if no references found in injected fragment, try outer document
if (editor instanceof EditorWindow) {
EditorWindow window = (EditorWindow) editor;
return findTargetElementsNoVS(project, window.getDelegate(), window.getDocument().injectedToHost(offset), lookupAccepted);
}
return null;
}
Aggregations