-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Snippet compiler #11582
Merged
Merged
Snippet compiler #11582
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
f7c8f52
Snippet compiler PoC
pikinier20 80a4014
Reporter fix. Message levels
pikinier20 825f6c3
Fix snippet wrapper. Integrate snippet checker with Wiki and Markdown…
pikinier20 2c7c92d
Further implementation of snippet compiler. Add package name and self…
pikinier20 9584098
Add arguments to control snippet compiler.
pikinier20 ecb4b21
Start work on handling hide directives in code snippets
BarkingBad 506c538
Hide irrelevant code snippet fragments in scaladoc
KacperFKorban 82dad66
Apply review suggestions from PR #11822
KacperFKorban b1cc5da
Add returning real line of error in source file of snippet for snippe…
BarkingBad 56e8b0c
Add failing flag
pikinier20 b3b7d0b
Add debug flag.
pikinier20 78676bc
Add addition operation for snippet compiler arg
pikinier20 2fe91f3
Refactor snippet compiler args
pikinier20 e8a5df9
Move snippet compiler logic to parsing phase.
pikinier20 ac76ac6
Refactor debug flag
pikinier20 94f77cb
Display snippet compilation messages in scaladoc
KacperFKorban bcea268
Apply review changes
KacperFKorban 8ddb298
Run snippet compiler on static sites
pikinier20 3e8995c
Further enhancements of snippet contexts
pikinier20 d27e377
Filter non-scala snippets. Report errors in parsing override flags
pikinier20 bb07b46
Fix positions in static sites. Enchance snippet wrapping
pikinier20 30eec69
CRs
pikinier20 d0bf391
Add and update tests for snippet compiler. Bugfixes found during testing
pikinier20 3b0e11e
Wrap compiler messages into Try block to avoid lazy exceptions
pikinier20 975065b
Update branch
pikinier20 7d0e477
Fix classpath problems. Add support for scala.js. Add bootclasspath t…
pikinier20 ac8531d
Temporarily turn off snippet checking for scala3 library
pikinier20 946752f
Change requests from reviews
pikinier20 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ package dotty.tools.scaladoc | |
object Main extends App { | ||
Searchbar() | ||
SocialLinks() | ||
CodeSnippets() | ||
} |
27 changes: 27 additions & 0 deletions
27
scaladoc-js/src/searchbar/code-snippets/CodeSnippets.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package dotty.tools.scaladoc | ||
|
||
import org.scalajs.dom._ | ||
import org.scalajs.dom.ext._ | ||
|
||
class CodeSnippets: | ||
def toggleHide(e: html.Element | html.Document) = e.querySelectorAll("code span.hideable").foreach { | ||
case e: html.Element if e.style.getPropertyValue("display").isEmpty => e.style.setProperty("display", "none") | ||
case e: html.Element => e.style.removeProperty("display") | ||
} | ||
|
||
toggleHide(document) | ||
|
||
document.querySelectorAll("pre").foreach { | ||
case e: html.Element if e.querySelectorAll("code span.hideable").nonEmpty => | ||
val a = document.createElement("a") | ||
a.addEventListener("click", { (_: MouseEvent) => | ||
if(a.classList.contains("hide-snippet-comments-button")) { | ||
a.classList.remove("hide-snippet-comments-button") | ||
} else { | ||
a.classList.add("hide-snippet-comments-button") | ||
} | ||
toggleHide(e) | ||
}) | ||
a.classList.add("snippet-comment-button") | ||
e.insertBefore(a, e.firstChild) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
|
||
|
||
--- | ||
|
||
```scala sc:compile | ||
2 + List(0) | ||
``` | ||
|
||
```scala sc:compile | ||
new snippetCompiler.Snippet0 { } | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package tests.snippetComments | ||
|
||
|
||
/** | ||
* This is my codeblock | ||
* | ||
* ``` | ||
* //{{ | ||
* import xd | ||
* import xd2 | ||
* //}} | ||
* | ||
* | ||
* val x = 1 // This is my valid comment | ||
* | ||
* /* | ||
* multi line comment | ||
* */ | ||
* val reallyFLongDeclaration = "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" | ||
* val y = 2 // comment in the same line | ||
* // comment in new line | ||
* val z = 3 | ||
* | ||
* //{{ | ||
* val hideMe = 7 | ||
* //}} | ||
* ``` | ||
* | ||
* The end of my codeblock | ||
*/ | ||
class A |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package tests | ||
package snippetCompilerTests | ||
|
||
/** | ||
* ```scala sc:compile | ||
* //{ | ||
* import scala.collection.Seq | ||
* //} | ||
* | ||
* def a = 2 | ||
* val x = 1 + List() | ||
* a | ||
* | ||
* try { | ||
* 2+3 | ||
* } | ||
* | ||
* /* | ||
* Huge comment | ||
* */ | ||
* val xd: String = 42 | ||
* | ||
* def a(i: Int): Boolean = i match // This is a function | ||
* case 1 => true | ||
* | ||
* val b: Int = 2.3 /* Also quite a big comment */ | ||
* | ||
* val d: Long = "asd" | ||
* ``` | ||
* | ||
* ```scala sc:fail | ||
* def a = 2 | ||
* val x = 1 + List() | ||
* a | ||
* ``` | ||
* | ||
* ```scala sc:fail | ||
* def a = 2 | ||
* ``` | ||
* | ||
* ```scala sc:nocompile | ||
* def a = 3 | ||
* a() | ||
* ``` | ||
*/ | ||
class A { | ||
trait B | ||
} | ||
|
||
/** | ||
* ```scala sc:compile | ||
* val c: Int = 4.5 | ||
* ``` | ||
*/ | ||
class B { } | ||
|
||
trait Quotes { | ||
val reflect: reflectModule = ??? | ||
trait reflectModule { self: reflect.type => | ||
/** | ||
* ```scala sc:compile | ||
* 2 + List() | ||
* ``` | ||
* | ||
*/ | ||
def a = 3 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package tests.snippetTestcase1 | ||
|
||
class SnippetTestcase1: | ||
/** | ||
* SNIPPET(OUTERLINEOFFSET:8,OUTERCOLUMNOFFSET:6,INNERLINEOFFSET:3,INNERCOLUMNOFFSET:2) | ||
* ERROR(LINE:8,COLUMN:8) | ||
* ```scala sc:compile | ||
* 2 + List() | ||
* ``` | ||
* | ||
*/ | ||
def a = 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package tests | ||
package snippetTestcase2 | ||
|
||
trait Quotes2[A] { | ||
val r1: r1Module[_] = ??? | ||
trait r1Module[A] { | ||
type X | ||
object Y { | ||
/** | ||
* SNIPPET(OUTERLINEOFFSET:13,OUTERCOLUMNOFFSET:10,INNERLINEOFFSET:6,INNERCOLUMNOFFSET:6) | ||
* ERROR(LINE:13,COLUMN:12) | ||
* ```scala sc:compile | ||
* 2 + List() | ||
* ``` | ||
* | ||
*/ | ||
type YY | ||
} | ||
val z: zModule = ??? | ||
trait zModule { | ||
/** | ||
* SNIPPET(OUTERLINEOFFSET:25,OUTERCOLUMNOFFSET:10,INNERLINEOFFSET:7,INNERCOLUMNOFFSET:6) | ||
* ERROR(LINE:25,COLUMN:12) | ||
* ```scala sc:compile | ||
* 2 + List() | ||
* ``` | ||
* | ||
*/ | ||
type ZZ | ||
} | ||
} | ||
object r2 { | ||
type X | ||
object Y { | ||
/** | ||
* SNIPPET(OUTERLINEOFFSET:39,OUTERCOLUMNOFFSET:10,INNERLINEOFFSET:5,INNERCOLUMNOFFSET:6) | ||
* ERROR(LINE:39,COLUMN:12) | ||
* ```scala sc:compile | ||
* 2 + List() | ||
* ``` | ||
* | ||
*/ | ||
type YY | ||
} | ||
val z: zModule = ??? | ||
trait zModule { | ||
/** | ||
* SNIPPET(OUTERLINEOFFSET:51,OUTERCOLUMNOFFSET:10,INNERLINEOFFSET:6,INNERCOLUMNOFFSET:6) | ||
* ERROR(LINE:51,COLUMN:12) | ||
* ```scala sc:compile | ||
* 2 + List() | ||
* ``` | ||
* | ||
*/ | ||
type ZZ | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be fixed later but do you know why we need usingScript in some situations and couldn't just always use Compile/run ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was my idea to have some coverage for scripts. Beside that there are no blockers to switch all cases to running
Compile/run
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, for consistency I suggest always using Compile/run and instead test the scaladoc binary from https://github.com/lampepfl/dotty/blob/master/project/scripts/cmdTests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pikinier20 can we change that in follow up PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure