@@ -5,7 +5,6 @@ import com.intellij.openapi.project.Project
55import com.intellij.openapi.wm.ToolWindow
66import com.intellij.openapi.wm.ToolWindowFactory
77import com.intellij.psi.PsiElement
8- import com.intellij.psi.PsiManager
98import com.intellij.ui.content.ContentFactory
109import com.intellij.util.ui.UIUtil
1110import org.apache.commons.lang.StringEscapeUtils
@@ -28,25 +27,42 @@ class JuliaDocumentProvider : AbstractDocumentationProvider() {
2827 override fun generateDoc (element : PsiElement ? , originalElement : PsiElement ? ): String? {
2928 val symbol = element ? : return null
3029 val parent = symbol.parent as ? DocStringOwner
30+ val name = " # ${symbol.text} \n "
3131 return when {
3232 // function declaration by written
3333 parent != null -> {
34- val name = " # ${symbol.text} \n "
35- parent.docString?.text?.trim(' "' )?.let {
36- STYLE_HTML + SimplifyJBMarkdownUtil .generateMarkdownHtml(name + it)
37- }
34+ val content = parent.docString?.text
35+ buildDocument(content, name)
3836 }
39- // if Docs.doc can find
4037 symbol is JuliaSymbol -> {
41- val ret = symbol.project.languageServer.searchDocsByName(symbol.text) ? : return null
42- val unescaped = StringEscapeUtils .unescapeJava(ret.trim(' "' ))
43- if (unescaped.startsWith(" __INTELLIJ__" )) return null
44- STYLE_HTML + SimplifyJBMarkdownUtil .generateMarkdownHtml(unescaped)
38+ // find previous docs
39+ val symbolOrLhs = symbol.parent.takeIf { it is JuliaSymbolLhs } ? : symbol
40+ when {
41+ symbolOrLhs.parent is JuliaAssignOp -> {
42+ val stringElement = symbolOrLhs.parent.prevRealSibling?.takeIf { it is JuliaString }
43+ return buildDocument(stringElement?.text, name) ? : searchFromLanguageServer(symbol)
44+ }
45+ else -> // else use LanguageServer
46+ return searchFromLanguageServer(symbol)
47+ }
4548 }
4649 else -> null
4750 }
4851 }
4952
53+ private fun buildDocument (content : String? , symbolName : String ): String? {
54+ return content?.trim(' "' )?.let {
55+ STYLE_HTML + SimplifyJBMarkdownUtil .generateMarkdownHtml(symbolName + it)
56+ }
57+ }
58+
59+ private fun searchFromLanguageServer (symbol : JuliaSymbol ): String? {
60+ val ret = symbol.project.languageServer.searchDocsByName(symbol.text) ? : return null
61+ val unescaped = StringEscapeUtils .unescapeJava(ret.trim(' "' ))
62+ if (unescaped.startsWith(" __INTELLIJ__" )) return null
63+ else return STYLE_HTML + SimplifyJBMarkdownUtil .generateMarkdownHtml(unescaped)
64+ }
65+
5066 companion object {
5167 // language=HTML
5268 val STYLE_HTML : String
0 commit comments