Skip to content

Commit dba105c

Browse files
committed
When resolving import symbols, look in the original folder first
1 parent a32b725 commit dba105c

File tree

1 file changed

+5
-4
lines changed
  • scalabuff-compiler/src/main/net/sandrogrzicic/scalabuff/compiler

1 file changed

+5
-4
lines changed

scalabuff-compiler/src/main/net/sandrogrzicic/scalabuff/compiler/ScalaBuff.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ object ScalaBuff {
3232
*/
3333
def apply(file: File)(implicit settings: Settings = defaultSettings) = {
3434
val tree = parse(file)
35-
val symbols = processImportSymbols(tree)
35+
val symbols = processImportSymbols(tree, file.getParentFile)
3636
Generator(tree, file.getName, symbols, settings.generateJsonMethod, settings.targetScalaVersion)
3737
}
3838

@@ -59,7 +59,8 @@ object ScalaBuff {
5959
* Process "import" statements in a protobuf AST by scanning the imported
6060
* files and building a map of their exported symbols.
6161
*/
62-
def processImportSymbols(tree: List[Node])(implicit settings: Settings = defaultSettings): Map[String, ImportedSymbol] = {
62+
def processImportSymbols(tree: List[Node], parentFolder: File)(implicit settings: Settings = defaultSettings): Map[String, ImportedSymbol] = {
63+
implicit val searchInFirst = Some(parentFolder)
6364
def dig(name: String): List[(String, ImportedSymbol)] = {
6465
val tree = parse(searchPath(name).getOrElse { throw new IOException("Unable to import: " + name) })
6566
val packageName = tree.collectFirst {
@@ -94,13 +95,13 @@ object ScalaBuff {
9495
recurse(startAt)
9596
}
9697

97-
def searchPath(filename: String)(implicit settings: Settings = defaultSettings): Option[File] = {
98+
def searchPath(filename: String)(implicit settings: Settings = defaultSettings, searchInFirst: Option[File] = None): Option[File] = {
9899
val file = new File(filename)
99100

100101
if (file.isAbsolute) {
101102
Option(file).filter(_.exists)
102103
} else {
103-
settings.importDirectories.map { folder =>
104+
(searchInFirst.toSeq ++ settings.importDirectories).map { folder =>
104105
new File(folder, filename)
105106
}.find(_.exists)
106107
}

0 commit comments

Comments
 (0)