Skip to content
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

Merged
merged 3 commits into from
Sep 11, 2018
Merged

Conversation

ennru
Copy link
Member

@ennru ennru commented Sep 11, 2018

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

@@ -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
Copy link
Contributor

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

Copy link
Member Author

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...

Copy link
Contributor

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 = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extractSnippet right?

Copy link
Contributor

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)

Copy link
Member Author

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
Copy link
Contributor

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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one seems suprising?

Copy link
Member Author

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))
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice test additions

Copy link
Contributor

@ktoso ktoso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ennru ennru merged commit b423e76 into lightbend:master Sep 11, 2018
@ennru ennru deleted the ennru_indent-correctly branch September 11, 2018 06:10
@ennru ennru added this to the 0.4.2 milestone Sep 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants