-
Notifications
You must be signed in to change notification settings - Fork 2
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
Fix crash on method names that break regex patterns #12
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
package co.pjrt.stags | ||
|
||
import java.io.File | ||
|
||
import scala.meta._ | ||
|
||
import co.pjrt.stags.paths.Path | ||
|
||
object TagGenerator { | ||
|
||
|
||
/** | ||
* Given a Scalameta Source, generate a sequence of [[Tag]]s for it | ||
*/ | ||
|
@@ -143,6 +143,7 @@ object TagGenerator { | |
|
||
val static = staticParent || isStatic(scope, mods) | ||
def getFromPat(p: Pat) = getFromPats(scope, mods, p, staticParent, parent) | ||
|
||
pat match { | ||
case p: Pat.Var => Seq(patTag(scope, parent, p, static)) | ||
case Pat.Typed(p, _) => getFromPat(p) | ||
|
@@ -160,6 +161,9 @@ object TagGenerator { | |
// DESNOTE(2017-07-14, pjrt): This is for patterns like `val 1 = x` | ||
// For those, we should not generate tags (of course) | ||
Seq.empty | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
case _ => | ||
Console.err.println(s"Error matching $pat in line ${parent.syntax}") | ||
Seq.empty | ||
} | ||
} | ||
|
||
|
@@ -332,8 +336,8 @@ private object AddressGen { | |
val line = tree.tokens.syntax.lines.toList(lineWithTagName).trim | ||
|
||
val name = tagName.value | ||
val replacement = s"\\\\zs$name" | ||
val nameW = s"\\b$name\\b" | ||
val replacement = s"\\\\zs$name".replaceAllLiterally("$","\\$") | ||
val nameW = s"\\b\\Q$name\\E\\b" // wrap $name with regex quote \Q\E; and word bound \b\b | ||
val search = line.replaceFirst(nameW, replacement) | ||
s"/$search/" | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,8 +59,9 @@ class TagLineTest extends FreeSpec with Matchers { | |
TagLine(tag, filePath) | ||
.relativize(target) | ||
.filePath | ||
.toString shouldBe expectedS | ||
|
||
.toString | ||
.replaceAllLiterally("\\","/") //windows path sep is backwards | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand this change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I get that, I don't get why this was needed. Are u running this test on windows and it is failing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was testing this on a Windows machine. In order to make the test work, I had to make the backward paths match the tests specified in a unix style path. the |
||
.shouldBe(expectedS) | ||
} | ||
|
||
"should modify the filepath to be relative from the target in" - { | ||
|
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.
What's with all the empty new lines?
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.
Sorry, the empty lines are remnants of some debug harness that I removed; but didn't catch the empty lines.