IDEA-219488: update quickdoc decoration part with newly changed element, not an old one

GitOrigin-RevId: 43d49d141870ab3829bf8f02007aa7fd9617265b
This commit is contained in:
Valentin Fondaratov
2019-07-30 20:05:38 +03:00
committed by intellij-monorepo-bot
parent ccfa31ed30
commit 92001a67bc
4 changed files with 60 additions and 7 deletions
@@ -216,6 +216,40 @@ class Bar {
assert actual == expected
}
void "test navigation updates decoration"() {
def input = """\
class Foo {
void foo(String s) {
s.region<caret>Matches()
}
}""".stripIndent()
def documentationManager = DocumentationManager.getInstance(myFixture.project)
JavaExternalDocumentationTest.getDocumentationText(myFixture.project, input) { component ->
def expected =
"<html><div class='content-only'>Candidates for method call <b>s.regionMatches()</b> are:<br>" +
"<br>" +
"&nbsp;&nbsp;<a href=\"psi_element://java.lang.String#regionMatches(int, java.lang.String, int, int)\">boolean regionMatches(int, String, int, int)</a><br>" +
"&nbsp;&nbsp;<a href=\"psi_element://java.lang.String#regionMatches(boolean, int, java.lang.String, int, int)\">boolean regionMatches(boolean, int, String, int, int)</a><br>" +
"</div>"
assert component.decoratedText == expected
documentationManager.navigateByLink(component, "psi_element://java.lang.String#regionMatches(int, java.lang.String, int, int)")
try {
JavaExternalDocumentationTest.waitTillDone(documentationManager.getLastAction())
}
catch (InterruptedException e) {
throw new RuntimeException(e)
}
// Here we check that the covering module (SDK in this case) is rendered in decorated info
assert component.decoratedText.contains("<div class='bottom'><icon src='AllIcons.Nodes.PpLibFolder'>&nbsp;&lt; java 1.7 ></div>")
}
}
private void configure(String text) {
myFixture.configureByText 'a.java', text
}
@@ -28,6 +28,7 @@ import com.intellij.testFramework.LightPlatformTestCase;
import com.intellij.testFramework.LightProjectDescriptor;
import com.intellij.testFramework.PsiTestUtil;
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor;
import com.intellij.util.Function;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -118,7 +119,7 @@ public class JavaExternalDocumentationTest extends LightPlatformTestCase {
return LOCALHOST_URL_PATTERN.matcher(actualText).replaceAll("placeholder");
}
private static void waitTillDone(ActionCallback actionCallback) throws InterruptedException {
static void waitTillDone(ActionCallback actionCallback) throws InterruptedException {
if (actionCallback == null) return;
long start = System.currentTimeMillis();
while (System.currentTimeMillis() - start < 300000) {
@@ -147,17 +148,30 @@ public class JavaExternalDocumentationTest extends LightPlatformTestCase {
return getDocumentationText(getProject(), sourceEditorText);
}
public static String getDocumentationText(Project project, String sourceEditorText) {
public static String getDocumentationText(Project project,
String sourceEditorText) {
return getDocumentationText(project, sourceEditorText, DocumentationComponent::getDecoratedText);
}
public static String getDocumentationText(Project project,
String sourceEditorText,
@NotNull Function<? super DocumentationComponent, String> componentEvaluator) {
int caretPosition = sourceEditorText.indexOf(EditorTestUtil.CARET_TAG);
if (caretPosition >= 0) {
sourceEditorText = sourceEditorText.substring(0, caretPosition) +
sourceEditorText.substring(caretPosition + EditorTestUtil.CARET_TAG.length());
}
PsiFile psiFile = PsiFileFactory.getInstance(project).createFileFromText(JavaLanguage.INSTANCE, sourceEditorText);
return getDocumentationText(psiFile, caretPosition);
return getDocumentationText(psiFile, caretPosition, componentEvaluator);
}
public static String getDocumentationText(@NotNull PsiFile psiFile, int caretPosition) {
return getDocumentationText(psiFile, caretPosition, DocumentationComponent::getDecoratedText);
}
public static String getDocumentationText(@NotNull PsiFile psiFile,
int caretPosition,
@NotNull Function<? super DocumentationComponent, String> componentEvaluator) {
Project project = psiFile.getProject();
Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
assertNotNull(document);
@@ -166,7 +180,7 @@ public class JavaExternalDocumentationTest extends LightPlatformTestCase {
if (caretPosition >= 0) {
editor.getCaretModel().moveToOffset(caretPosition);
}
return getDocumentationText(editor);
return getDocumentationText(editor, componentEvaluator);
}
finally {
EditorFactory.getInstance().releaseEditor(editor);
@@ -174,6 +188,11 @@ public class JavaExternalDocumentationTest extends LightPlatformTestCase {
}
public static String getDocumentationText(@NotNull Editor editor) {
return getDocumentationText(editor, DocumentationComponent::getDecoratedText);
}
public static String getDocumentationText(@NotNull Editor editor,
@NotNull Function<? super DocumentationComponent, String> componentEvaluator) {
Project project = editor.getProject();
PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
DocumentationManager documentationManager = DocumentationManager.getInstance(project);
@@ -187,7 +206,7 @@ public class JavaExternalDocumentationTest extends LightPlatformTestCase {
catch (InterruptedException e) {
throw new RuntimeException(e);
}
return documentationComponent.getDecoratedText();
return componentEvaluator.fun(documentationComponent);
}
finally {
JBPopup hint = documentationComponent.getHint();
@@ -779,8 +779,8 @@ public class DocumentationComponent extends JPanel implements Disposable, DataPr
if (myManager == null) return;
myText = text;
myDecoratedText = decorate(text);
setElement(element);
myDecoratedText = decorate(text);
showHint(viewRect, ref);
}
@@ -924,7 +924,7 @@ public class DocumentationManager extends DockablePopupManager<DocumentationComp
return originalElementPointer != null ? originalElementPointer.getElement() : null;
}
void navigateByLink(DocumentationComponent component, String url) {
public void navigateByLink(DocumentationComponent component, String url) {
component.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
PsiElement psiElement = component.getElement();
if (psiElement == null) {