Skip to content

Commit

Permalink
[scrooge][s] store file path in resolved document
Browse files Browse the repository at this point in the history
**Problem**

Once scrooge resolves the document, we lose information about the path to the Thrift IDL source.

**Solution**

Store path to file in `ResolvedDocument`

JIRA Issues: CSL-11583

Differential Revision: https://phabricator.twitter.biz/D808995
  • Loading branch information
dieu authored and jenkins committed Jan 12, 2022
1 parent 6ce238a commit 1ee7df1
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ package com.twitter.scrooge.frontend

import com.twitter.scrooge.ast._
import scala.collection.mutable.ArrayBuffer
import scala.util.parsing.input.{NoPosition, Positional}
import scala.util.parsing.input.NoPosition
import scala.util.parsing.input.Positional

class PositionalException(message: String, node: Positional)
extends Exception(s"$message\n${node.pos.longString}")
Expand All @@ -36,7 +37,7 @@ case class QualifierNotFoundException(name: String, node: Positional)
case class DuplicatedIdentifierException(message: String, node: Positional)
extends PositionalException(message, node)

case class ResolvedDocument(document: Document, resolver: TypeResolver) {
case class ResolvedDocument(filePath: Option[String], document: Document, resolver: TypeResolver) {

/**
* Given an ID, produce its FQN (e.g. a Java FQN) by appending the namespace.
Expand Down Expand Up @@ -104,6 +105,11 @@ case class ResolvedDocument(document: Document, resolver: TypeResolver) {
}
}

object ResolvedDocument {
def apply(document: Document, resolver: TypeResolver): ResolvedDocument =
ResolvedDocument(None, document, resolver)
}

case class ResolvedService(serviceID: Identifier, service: Service)

case class ResolvedDefinition(definition: Definition, resolver: TypeResolver)
Expand Down Expand Up @@ -161,7 +167,7 @@ case class TypeResolver(
*/
private[scrooge] def withInclude(inc: Include): TypeResolver = {
val resolver = TypeResolver()
val resolvedDocument = resolver(inc.document, Some(inc.prefix))
val resolvedDocument = resolver(inc.document, Some(inc.filePath), Some(inc.prefix))
copy(includeMap = includeMap + (inc.prefix.fullName -> resolvedDocument))
}

Expand Down Expand Up @@ -216,9 +222,14 @@ case class TypeResolver(
/**
* Resolves all types in the given document.
*
* @param filePath fs path to document
* @param scopePrefix the scope of the document if the document is an include
*/
def apply(doc: Document, scopePrefix: Option[Identifier] = None): ResolvedDocument = {
def apply(
doc: Document,
filePath: Option[String] = None,
scopePrefix: Option[Identifier] = None
): ResolvedDocument = {
var resolver = this
val includes = doc.headers.collect { case i: Include => i }
val defBuf = new ArrayBuffer[Definition](doc.defs.size)
Expand Down Expand Up @@ -246,7 +257,7 @@ case class TypeResolver(
defBuf += d2
}

ResolvedDocument(doc.copy(defs = defBuf.toSeq), resolver)
ResolvedDocument(filePath, doc.copy(defs = defBuf.toSeq), resolver)
}

/**
Expand Down

0 comments on commit 1ee7df1

Please sign in to comment.