Skip to content

Commit

Permalink
Title in docs in IDE (#1904)
Browse files Browse the repository at this point in the history
  • Loading branch information
BinarySoftware authored Aug 16, 2021
1 parent 98eab28 commit 6652a00
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 132 deletions.
2 changes: 2 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
propagate error information
([#1941](https://github.com/enso-org/enso/pull/1941)).
- Fixed inaproppriate parsing of code blocks in documentation.
- Documentation in IDE now shows names of suggestions
([#1904](https://github.com/enso-org/enso/pull/1904)).

## Tooling

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ final class SuggestionBuilder[A: IndexedSource](val source: A) {
selfType = selfType.toString,
returnType = buildReturnType(returnTypeDef),
documentation = doc,
documentationHtml = doc.map(DocParserWrapper.runOnPureDoc),
documentationHtml = doc.map(DocParserWrapper.runOnPureDoc(_, name.name)),
reexport = None
)
}
Expand Down Expand Up @@ -216,10 +216,11 @@ final class SuggestionBuilder[A: IndexedSource](val source: A) {
doc: Option[String]
): Suggestion =
Suggestion.Module(
module = module.toString,
documentation = doc,
documentationHtml = doc.map(DocParserWrapper.runOnPureDoc),
reexport = None
module = module.toString,
documentation = doc,
documentationHtml =
doc.map(DocParserWrapper.runOnPureDoc(_, module.toString)),
reexport = None
)

/** Build suggestions for an atom definition. */
Expand Down Expand Up @@ -247,7 +248,7 @@ final class SuggestionBuilder[A: IndexedSource](val source: A) {
arguments = arguments.map(buildArgument),
returnType = module.createChild(name).toString,
documentation = doc,
documentationHtml = doc.map(DocParserWrapper.runOnPureDoc),
documentationHtml = doc.map(DocParserWrapper.runOnPureDoc(_, name)),
reexport = None
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,15 @@ class SuggestionBuilderTest extends CompilerTest {
private val moduleDoc = "Module doc"
private val DoccedModuleNode = Tree.Node(
Suggestion.Module(
module = Module.toString,
documentation = Some(" " + moduleDoc),
documentationHtml = Some(DocParserWrapper.runOnPureDoc(moduleDoc)),
reexport = None
module = Module.toString,
documentation = Some(" " + moduleDoc),
documentationHtml =
Some(DocParserWrapper.runOnPureDoc(moduleDoc, Module.toString)),
reexport = None
),
Vector()
)

private def htmlDoc(inner: String): String = {
"<html><body><div class=\"doc\" style=\"font-size: 13px;\"><div><div class=\"\">" + inner + "</div></div></div></body></html>"
}

"SuggestionBuilder" should {

"build method without explicit arguments" in {
Expand Down Expand Up @@ -96,10 +93,11 @@ class SuggestionBuilderTest extends CompilerTest {
arguments = Seq(
Suggestion.Argument("this", "Unnamed.Test", false, false, None)
),
selfType = "Unnamed.Test",
returnType = SuggestionBuilder.Any,
documentation = Some(" The foo"),
documentationHtml = Some(htmlDoc("<p>The foo</p>"))
selfType = "Unnamed.Test",
returnType = SuggestionBuilder.Any,
documentation = Some(" The foo"),
documentationHtml =
Some(DocParserWrapper.runOnPureDoc(" The foo", "foo"))
),
Vector()
)
Expand Down Expand Up @@ -129,10 +127,11 @@ class SuggestionBuilderTest extends CompilerTest {
arguments = Seq(
Suggestion.Argument("this", "Unnamed.Test", false, false, None)
),
selfType = "Unnamed.Test",
returnType = "Number",
documentation = Some(" The foo"),
documentationHtml = Some(htmlDoc("<p>The foo</p>"))
selfType = "Unnamed.Test",
returnType = "Number",
documentation = Some(" The foo"),
documentationHtml =
Some(DocParserWrapper.runOnPureDoc(" The foo", "foo"))
),
Vector()
)
Expand Down Expand Up @@ -460,10 +459,11 @@ class SuggestionBuilderTest extends CompilerTest {
Suggestion.Argument("a", "Number", false, false, None),
Suggestion.Argument("b", "Number", false, false, None)
),
selfType = "Unnamed.Test.MyAtom",
returnType = "Number",
documentation = Some(" My bar"),
documentationHtml = Some(htmlDoc("<p>My bar</p>"))
selfType = "Unnamed.Test.MyAtom",
returnType = "Number",
documentation = Some(" My bar"),
documentationHtml =
Some(DocParserWrapper.runOnPureDoc(" My bar", "bar"))
),
Vector()
)
Expand Down Expand Up @@ -1172,9 +1172,10 @@ class SuggestionBuilderTest extends CompilerTest {
Suggestion
.Argument("b", SuggestionBuilder.Any, false, false, None)
),
returnType = "Unnamed.Test.MyType",
documentation = Some(" My sweet type"),
documentationHtml = Some(htmlDoc("<p>My sweet type</p>"))
returnType = "Unnamed.Test.MyType",
documentation = Some(" My sweet type"),
documentationHtml =
Some(DocParserWrapper.runOnPureDoc(" My sweet type", "MyType"))
),
Vector()
),
Expand Down Expand Up @@ -1292,13 +1293,15 @@ class SuggestionBuilderTest extends CompilerTest {
DoccedModuleNode,
Tree.Node(
Suggestion.Atom(
externalId = None,
module = "Unnamed.Test",
name = "Nothing",
arguments = Seq(),
returnType = "Unnamed.Test.Nothing",
documentation = Some(" Nothing here"),
documentationHtml = Some(htmlDoc("<p>Nothing here</p>"))
externalId = None,
module = "Unnamed.Test",
name = "Nothing",
arguments = Seq(),
returnType = "Unnamed.Test.Nothing",
documentation = Some(" Nothing here"),
documentationHtml = Some(
DocParserWrapper.runOnPureDoc(" Nothing here", "Nothing")
)
),
Vector()
),
Expand All @@ -1311,9 +1314,11 @@ class SuggestionBuilderTest extends CompilerTest {
Suggestion
.Argument("a", SuggestionBuilder.Any, false, false, None)
),
returnType = "Unnamed.Test.Just",
documentation = Some(" Something there"),
documentationHtml = Some(htmlDoc("<p>Something there</p>"))
returnType = "Unnamed.Test.Just",
documentation = Some(" Something there"),
documentationHtml = Some(
DocParserWrapper.runOnPureDoc(" Something there", "Just")
)
),
Vector()
),
Expand Down Expand Up @@ -1357,25 +1362,27 @@ class SuggestionBuilderTest extends CompilerTest {
ModuleNode,
Tree.Node(
Suggestion.Atom(
externalId = None,
module = "Unnamed.Test",
name = "Cons",
arguments = Seq(),
returnType = "Unnamed.Test.Cons",
documentation = Some(" And more"),
documentationHtml = Some(htmlDoc("<p>And more</p>"))
externalId = None,
module = "Unnamed.Test",
name = "Cons",
arguments = Seq(),
returnType = "Unnamed.Test.Cons",
documentation = Some(" And more"),
documentationHtml =
Some(DocParserWrapper.runOnPureDoc(" And more", "Cons"))
),
Vector()
),
Tree.Node(
Suggestion.Atom(
externalId = None,
module = "Unnamed.Test",
name = "Nil",
arguments = Seq(),
returnType = "Unnamed.Test.Nil",
documentation = Some(" End"),
documentationHtml = Some(htmlDoc("<p>End</p>"))
externalId = None,
module = "Unnamed.Test",
name = "Nil",
arguments = Seq(),
returnType = "Unnamed.Test.Nil",
documentation = Some(" End"),
documentationHtml =
Some(DocParserWrapper.runOnPureDoc(" End", "Nil"))
),
Vector()
),
Expand All @@ -1388,10 +1395,11 @@ class SuggestionBuilderTest extends CompilerTest {
Suggestion
.Argument("this", "Unnamed.Test.Cons", false, false, None)
),
selfType = "Unnamed.Test.Cons",
returnType = "List",
documentation = Some(" a method"),
documentationHtml = Some(htmlDoc("<p>a method</p>"))
selfType = "Unnamed.Test.Cons",
returnType = "List",
documentation = Some(" a method"),
documentationHtml =
Some(DocParserWrapper.runOnPureDoc(" a method", "empty"))
),
Vector()
),
Expand All @@ -1404,10 +1412,11 @@ class SuggestionBuilderTest extends CompilerTest {
Suggestion
.Argument("this", "Unnamed.Test.Nil", false, false, None)
),
selfType = "Unnamed.Test.Nil",
returnType = "List",
documentation = Some(" a method"),
documentationHtml = Some(htmlDoc("<p>a method</p>"))
selfType = "Unnamed.Test.Nil",
returnType = "List",
documentation = Some(" a method"),
documentationHtml =
Some(DocParserWrapper.runOnPureDoc(" a method", "empty"))
),
Vector()
)
Expand Down Expand Up @@ -1897,7 +1906,7 @@ class SuggestionBuilderTest extends CompilerTest {
"Unnamed.Test",
Some(" Module doc"),
Some(
"<html><body><div class=\"doc\" style=\"font-size: 13px;\"><div><div class=\"\"><p>Module doc</p></div></div></div></body></html>"
DocParserWrapper.runOnPureDoc(" Module doc", "Unnamed.Test")
),
None
),
Expand All @@ -1911,10 +1920,11 @@ class SuggestionBuilderTest extends CompilerTest {
arguments = Seq(
Suggestion.Argument("this", "Unnamed.Test", false, false, None)
),
selfType = "Unnamed.Test",
returnType = SuggestionBuilder.Any,
documentation = Some(" The foo"),
documentationHtml = Some(htmlDoc("<p>The foo</p>"))
selfType = "Unnamed.Test",
returnType = SuggestionBuilder.Any,
documentation = Some(" The foo"),
documentationHtml =
Some(DocParserWrapper.runOnPureDoc(" The foo", "foo"))
),
Vector()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.enso.compiler.core.IR
import org.enso.compiler.pass.resolve.GenerateDocumentation
import org.enso.compiler.pass.{PassConfiguration, PassGroup, PassManager}
import org.enso.compiler.test.CompilerTest
import org.enso.docs.generator.DocParserWrapper
import org.scalatest.Inside
import pprint.pprintln

Expand Down Expand Up @@ -79,24 +80,6 @@ class GenerateDocumentationTest extends CompilerTest with Inside {
meta.get.documentation
}

/** Creates full html doc generator output from the `inner` string, the one
* that will only change during the test.
*/
def unfoldedDocumentationForAssertion(inner: String): String =
s"""<html>
| <body>
| <div class="doc" style="font-size: 13px;">
| <div>
| <div class="">
| $inner
| </div>
| </div>
| </div>
| </body>
|</html>""".stripMargin
.replaceAll(System.lineSeparator(), "")
.replaceAll(">[ ]+<", "><")

// === The Tests ============================================================

"Documentation comments in the top scope" should {
Expand All @@ -117,11 +100,11 @@ class GenerateDocumentationTest extends CompilerTest with Inside {
ir.bindings(0) shouldBe an[IR.Module.Scope.Definition.Atom]
ir.bindings(1) shouldBe an[IR.Module.Scope.Definition.Method]

getDoc(ir.bindings(0)) shouldEqual unfoldedDocumentationForAssertion(
"<p>This is doc for My<div class=\"Unclosed\"><i>Atom</i></div></p>"
getDoc(ir.bindings(0)) shouldEqual DocParserWrapper.runOnPureDoc(
" This is doc for My_Atom"
)
getDoc(ir.bindings(1)) shouldEqual unfoldedDocumentationForAssertion(
"<p>This is doc for my<div class=\"Unclosed\"><i>method</i></div></p>"
getDoc(ir.bindings(1)) shouldEqual DocParserWrapper.runOnPureDoc(
" This is doc for my_method"
)
}
}
Expand All @@ -148,11 +131,11 @@ class GenerateDocumentationTest extends CompilerTest with Inside {

pprintln(body)
body.expressions.length shouldEqual 1
getDoc(body.expressions(0)) shouldEqual unfoldedDocumentationForAssertion(
"<p>Do thing</p>"
getDoc(body.expressions(0)) shouldEqual DocParserWrapper.runOnPureDoc(
" Do thing"
)
getDoc(body.returnValue) shouldEqual unfoldedDocumentationForAssertion(
"<p>Do another thing</p>"
getDoc(body.returnValue) shouldEqual DocParserWrapper.runOnPureDoc(
" Do another thing"
)
}

Expand All @@ -178,11 +161,11 @@ class GenerateDocumentationTest extends CompilerTest with Inside {

body.expressions.length shouldEqual 2
body.expressions(0) shouldBe an[IR.Application.Operator.Binary]
getDoc(body.expressions(0)) shouldEqual unfoldedDocumentationForAssertion(
"<p>Id</p>"
getDoc(body.expressions(0)) shouldEqual DocParserWrapper.runOnPureDoc(
" Id"
)
getDoc(body.returnValue) shouldEqual unfoldedDocumentationForAssertion(
"<p>Return thing</p>"
getDoc(body.returnValue) shouldEqual DocParserWrapper.runOnPureDoc(
" Return thing"
)
}
}
Expand All @@ -208,31 +191,30 @@ class GenerateDocumentationTest extends CompilerTest with Inside {
| ## the return
| 0
|""".stripMargin.preprocessModule.resolve
// pprintln(ir)
val tp = ir.bindings(0).asInstanceOf[IR.Module.Scope.Definition.Type]
getDoc(tp) shouldEqual unfoldedDocumentationForAssertion(
"<p>the type Foo</p>"
getDoc(tp) shouldEqual DocParserWrapper.runOnPureDoc(
" the type Foo"
)
val t1 = tp.body(0)
getDoc(t1) shouldEqual unfoldedDocumentationForAssertion(
"<p>the constructor Bar</p>"
getDoc(t1) shouldEqual DocParserWrapper.runOnPureDoc(
" the constructor Bar"
)
val t2 = tp.body(1)
getDoc(t2) shouldEqual unfoldedDocumentationForAssertion(
"<p>the included Unit</p>"
getDoc(t2) shouldEqual DocParserWrapper.runOnPureDoc(
" the included Unit"
)
val method = tp.body(2).asInstanceOf[IR.Function.Binding]
getDoc(method) shouldEqual unfoldedDocumentationForAssertion(
"<p>a method</p>"
getDoc(method) shouldEqual DocParserWrapper.runOnPureDoc(
" a method"
)
val block = method.body.asInstanceOf[IR.Expression.Block]
getDoc(
block.expressions(0)
) shouldEqual unfoldedDocumentationForAssertion(
"<p>a statement</p>"
) shouldEqual DocParserWrapper.runOnPureDoc(
" a statement"
)
getDoc(block.returnValue) shouldEqual unfoldedDocumentationForAssertion(
"<p>the return</p>"
getDoc(block.returnValue) shouldEqual DocParserWrapper.runOnPureDoc(
" the return"
)
}
}
Expand Down
Loading

0 comments on commit 6652a00

Please sign in to comment.