From 5d6f1cf3faabecaaf839236cb5990475d7492862 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 27 Oct 2016 14:23:04 +0200 Subject: [PATCH] Fix handling of underscores in Markdown links (KT-14452) --- .../org/jetbrains/kotlin/idea/kdoc/KDocRenderer.kt | 8 ++++++-- .../editor/quickDoc/AtConstantWithUnderscore.kt | 12 ++++++++++++ .../quickDoc/QuickDocProviderTestGenerated.java | 6 ++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 idea/testData/editor/quickDoc/AtConstantWithUnderscore.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/kdoc/KDocRenderer.kt b/idea/src/org/jetbrains/kotlin/idea/kdoc/KDocRenderer.kt index ebea243f86d..43f72f1c3ef 100644 --- a/idea/src/org/jetbrains/kotlin/idea/kdoc/KDocRenderer.kt +++ b/idea/src/org/jetbrains/kotlin/idea/kdoc/KDocRenderer.kt @@ -170,8 +170,12 @@ object KDocRenderer { } MarkdownElementTypes.SHORT_REFERENCE_LINK, MarkdownElementTypes.FULL_REFERENCE_LINK -> { - val label = node.child(MarkdownElementTypes.LINK_LABEL)?.child(MarkdownTokenTypes.TEXT)?.text - if (label != null) { + val linkLabelNode = node.child(MarkdownElementTypes.LINK_LABEL) + val linkLabelContent = linkLabelNode?.children + ?.dropWhile { it.type == MarkdownTokenTypes.LBRACKET } + ?.dropLastWhile { it.type == MarkdownTokenTypes.RBRACKET } + if (linkLabelContent != null) { + val label = linkLabelContent.joinToString(separator = "") { it.text } val linkText = node.child(MarkdownElementTypes.LINK_TEXT)?.toHtml() ?: label DocumentationManagerUtil.createHyperlink(sb, label, linkText, true) } diff --git a/idea/testData/editor/quickDoc/AtConstantWithUnderscore.kt b/idea/testData/editor/quickDoc/AtConstantWithUnderscore.kt new file mode 100644 index 00000000000..4c5cae454a8 --- /dev/null +++ b/idea/testData/editor/quickDoc/AtConstantWithUnderscore.kt @@ -0,0 +1,12 @@ +class C { + /** Use [SOME_REFERENCED_VAL] to do something */ + fun foo() { + + } + + companion object { + val SOME_REFERENCED_VAL = 1 + } +} + +//INFO: public final fun foo(): Unit defined in C

Use SOME_REFERENCED_VAL to do something

diff --git a/idea/tests/org/jetbrains/kotlin/idea/editor/quickDoc/QuickDocProviderTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/editor/quickDoc/QuickDocProviderTestGenerated.java index 8af3608c545..11797acca8b 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/editor/quickDoc/QuickDocProviderTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/editor/quickDoc/QuickDocProviderTestGenerated.java @@ -35,6 +35,12 @@ public class QuickDocProviderTestGenerated extends AbstractQuickDocProviderTest KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/editor/quickDoc"), Pattern.compile("^([^_]+)\\.[^\\.]*$"), true); } + @TestMetadata("AtConstantWithUnderscore.kt") + public void testAtConstantWithUnderscore() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/editor/quickDoc/AtConstantWithUnderscore.kt"); + doTest(fileName); + } + @TestMetadata("AtFunctionParameter.kt") public void testAtFunctionParameter() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/editor/quickDoc/AtFunctionParameter.kt");