@Override public void mouseMoved(final EditorMouseEvent e) { if (e.isConsumed() || !myProject.isInitialized() || myProject.isDisposed()) { return; } MouseEvent mouseEvent = e.getMouseEvent(); if (isMouseOverTooltip(mouseEvent.getLocationOnScreen()) || ScreenUtil.isMovementTowards( myPrevMouseLocation, mouseEvent.getLocationOnScreen(), getHintBounds())) { myPrevMouseLocation = mouseEvent.getLocationOnScreen(); return; } myPrevMouseLocation = mouseEvent.getLocationOnScreen(); Editor editor = e.getEditor(); if (editor.getProject() != null && editor.getProject() != myProject) return; PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myProject); PsiFile psiFile = documentManager.getPsiFile(editor.getDocument()); Point point = new Point(mouseEvent.getPoint()); if (documentManager.isCommitted(editor.getDocument())) { // when document is committed, try to check injected stuff - it's fast int offset = editor.logicalPositionToOffset(editor.xyToLogicalPosition(point)); editor = InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(editor, psiFile, offset); } LogicalPosition pos = editor.xyToLogicalPosition(point); int offset = editor.logicalPositionToOffset(pos); int selStart = editor.getSelectionModel().getSelectionStart(); int selEnd = editor.getSelectionModel().getSelectionEnd(); myStoredModifiers = mouseEvent.getModifiers(); BrowseMode browseMode = getBrowseMode(myStoredModifiers); cancelPreviousTooltip(); if (browseMode == BrowseMode.None || offset >= selStart && offset < selEnd) { disposeHighlighter(); return; } myTooltipProvider = new TooltipProvider(editor, pos); myTooltipProvider.execute(browseMode); }
public void mouseMoved(final EditorMouseEvent e) { if (e.isConsumed() || !myProject.isInitialized()) { return; } MouseEvent mouseEvent = e.getMouseEvent(); Editor editor = e.getEditor(); if (editor.getProject() != null && editor.getProject() != myProject) return; PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(editor.getDocument()); Point point = new Point(mouseEvent.getPoint()); if (!PsiDocumentManager.getInstance(myProject).isUncommited(editor.getDocument())) { // when document is committed, try to check injected stuff - it's fast editor = InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit( editor, psiFile, editor.logicalPositionToOffset(editor.xyToLogicalPosition(point))); } LogicalPosition pos = editor.xyToLogicalPosition(point); int offset = editor.logicalPositionToOffset(pos); int selStart = editor.getSelectionModel().getSelectionStart(); int selEnd = editor.getSelectionModel().getSelectionEnd(); myStoredModifiers = mouseEvent.getModifiers(); BrowseMode browseMode = getBrowseMode(myStoredModifiers); if (myTooltipProvider != null) { myTooltipProvider.dispose(); } if (browseMode == BrowseMode.None || offset >= selStart && offset < selEnd) { disposeHighlighter(); myTooltipProvider = null; return; } myTooltipProvider = new TooltipProvider(editor, pos); myTooltipProvider.execute(browseMode); }
@Override public void doCollectInformation(@NotNull final ProgressIndicator progress) { @SuppressWarnings("unchecked") HighlightUsagesHandlerBase<PsiElement> handler = HighlightUsagesHandler.createCustomHandler(myEditor, myFile); if (handler != null) { List<PsiElement> targets = handler.getTargets(); handler.computeUsages(targets); final List<TextRange> readUsages = handler.getReadUsages(); for (TextRange readUsage : readUsages) { LOG.assertTrue(readUsage != null, "null text range from " + handler); } myReadAccessRanges.addAll(readUsages); final List<TextRange> writeUsages = handler.getWriteUsages(); for (TextRange writeUsage : writeUsages) { LOG.assertTrue(writeUsage != null, "null text range from " + handler); } myWriteAccessRanges.addAll(writeUsages); if (!handler.highlightReferences()) return; } int flags = TargetElementUtil.ELEMENT_NAME_ACCEPTED | TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED; PsiElement myTarget; try { myTarget = TargetElementUtil.getInstance().findTargetElement(myEditor, flags, myCaretOffset); } catch (IndexNotReadyException e) { return; } if (myTarget == null) { if (!PsiDocumentManager.getInstance(myProject).isUncommited(myEditor.getDocument())) { // when document is committed, try to check injected stuff - it's fast Editor injectedEditor = InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit( myEditor, myFile, myCaretOffset); myTarget = TargetElementUtil.getInstance() .findTargetElement( injectedEditor, flags, injectedEditor.getCaretModel().getOffset()); } } if (myTarget != null) { highlightTargetUsages(myTarget); } else { PsiReference ref = TargetElementUtil.findReference(myEditor); if (ref instanceof PsiPolyVariantReference) { if (!ref.getElement().isValid()) { throw new PsiInvalidElementAccessException( ref.getElement(), "Invalid element in " + ref + " of " + ref.getClass() + "; editor=" + myEditor); } ResolveResult[] results = ((PsiPolyVariantReference) ref).multiResolve(false); if (results.length > 0) { for (ResolveResult result : results) { PsiElement target = result.getElement(); if (target != null) { if (!target.isValid()) { throw new PsiInvalidElementAccessException( target, "Invalid element returned from " + ref + " of " + ref.getClass() + "; editor=" + myEditor); } highlightTargetUsages(target); } } } } } }