-
Notifications
You must be signed in to change notification settings - Fork 77
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
Roll-back snippet indentation #245
Conversation
@@ -28,16 +26,40 @@ object Snippet { | |||
class SnippetException(message: String) extends RuntimeException(message) | |||
|
|||
def apply(file: File, labels: Seq[String]): (String, String) = { | |||
(extract(file, labels), language(file)) | |||
val lines = Source.fromFile(file)("UTF-8").getLines.toSeq |
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 leaks file descriptor doesnt it?
gotta close the source
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.
Good point, the lines used to be read multiple times like this...
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.
There's a few spots below as well, please skim for the leak :)
(extract(file, lines, labels), language(file)) | ||
} | ||
|
||
def extract(file: File, lines: Seq[String], labels: Seq[String]): String = { |
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.
extractSnippet right?
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.
(just a nitpick on naming)
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 guess Snippet.extract
is OK.
} | ||
|
||
def extractLabelRange(file: File, label: String): Option[(Int, Int)] = { | ||
val lineNumbers = extractState(file, label).lines.map(_._1) | ||
val lines = Source.fromFile(file)("UTF-8").getLines.toSeq |
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.
here too, watch out to close the source
@@ -89,7 +89,7 @@ class SnipDirectiveSpec extends MarkdownBaseSpec { | |||
|<pre class="prettyprint"> | |||
|<code class="language-scala"> | |||
|case object Dent | |||
|case object DoubleDent</code> | |||
| case object DoubleDent</code> |
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 one seems suprising?
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.
That's what Akka asked for...
The example is for how Alpakka wanted it to be.
val in = inString.split("\n").toList | ||
Snippet.extract(new File(""), in, Seq(label)) | ||
} | ||
} |
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.
nice test additions
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.
LGTM
This rolls back the snippet indentation logic introduced by #201. But has special handling for
import
lines, so that they become aligned with the left-most code in other snippets with the same label.Relates to:
akka/akka#25564
#242