summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/Global.scala8
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Parsers.scala13
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Scanners.scala18
-rw-r--r--src/compiler/scala/tools/nsc/interactive/Global.scala22
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala11
-rw-r--r--test/files/positions/ExcludedPrefix1.scala41
-rw-r--r--test/files/positions/MultipleDefs1.scala3
-rw-r--r--test/files/positions/Scaladoc1.scala8
-rw-r--r--test/files/positions/Scaladoc2.scala16
-rw-r--r--test/files/positions/Scaladoc3.scala8
-rw-r--r--test/files/positions/Scaladoc4.scala8
-rw-r--r--test/files/positions/Scaladoc5.scala8
12 files changed, 146 insertions, 18 deletions
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala
index bcf81c56e6..f447cf4327 100644
--- a/src/compiler/scala/tools/nsc/Global.scala
+++ b/src/compiler/scala/tools/nsc/Global.scala
@@ -125,6 +125,14 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
if (onlyPresentation) new HashMap[Symbol,String]
else null
+ /** A map of all doc comments source file offsets,
+ * indexed by symbols.
+ * Only active in onlyPresentation mode
+ */
+ val commentOffsets =
+ if (onlyPresentation) new HashMap[Symbol,Int]
+ else null
+
/** A map of argument names for methods
* !!! can be dropped once named method arguments are in !!!
*/
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
index 6bd9371c2a..8f94c64a4e 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
@@ -420,8 +420,17 @@ self =>
/** Join the comment associated with a definition
*/
def joinComment(trees: => List[Tree]): List[Tree] = {
- val buf = in.flushDoc
- if ((buf ne null) && buf.length > 0) trees map (t => DocDef(buf, t) setPos t.pos) // !!! take true comment position
+ val doc = in.flushDoc
+ if ((doc ne null) && doc._1.length > 0) {
+ val ts = trees
+ val main = ts.find(_.pos.isOpaqueRange)
+ ts map {
+ t =>
+ val dd = DocDef(doc._1, t)
+ val pos = doc._2.withEnd(t.pos.endOrPoint)
+ dd setPos (if (t eq main) pos else pos.makeTransparent)
+ }
+ }
else trees
}
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala
index 570bb1f0c9..c966a23fcb 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Scanners.scala
@@ -103,10 +103,11 @@ trait Scanners {
/** buffer for the documentation comment
*/
var docBuffer: StringBuilder = null
+ var docOffset: Position = null
/** Return current docBuffer and set docBuffer to null */
def flushDoc = {
- val ret = if (docBuffer != null) docBuffer.toString else null
+ val ret = if (docBuffer != null) (docBuffer.toString, docOffset) else null
docBuffer = null
ret
}
@@ -119,6 +120,8 @@ trait Scanners {
protected def foundComment(value: String, start: Int, end: Int) = ()
+ protected def foundDocComment(value: String, start: Int, end: Int) = ()
+
private class TokenData0 extends TokenData
/** we need one token lookahead and one token history
@@ -411,8 +414,11 @@ trait Scanners {
var openComments = 1
nextChar()
appendToComment()
- if (ch == '*' && buildDocs)
+ var buildingDocComment = false
+ if (ch == '*' && buildDocs) {
+ buildingDocComment = true
docBuffer = new StringBuilder("/**")
+ }
while (openComments > 0) {
do {
do {
@@ -435,7 +441,11 @@ trait Scanners {
else incompleteInputError("unclosed comment")
openComments -= 1
}
+
+ if (buildingDocComment)
+ foundDocComment(comment.toString, offset, charOffset - 2)
}
+
foundComment(comment.toString, offset, charOffset - 2)
true
} else {
@@ -1059,6 +1069,10 @@ trait Scanners {
override def foundComment(value: String, start: Int, end: Int) {
unit.comments += unit.Comment(value, new RangePosition(unit.source, start, start, end))
}
+
+ override def foundDocComment(value: String, start: Int, end: Int) {
+ docOffset = new RangePosition(unit.source, start, start, end)
+ }
}
class ParensAnalyzer(unit: CompilationUnit, patches: List[BracePatch]) extends UnitScanner(unit, patches) {
diff --git a/src/compiler/scala/tools/nsc/interactive/Global.scala b/src/compiler/scala/tools/nsc/interactive/Global.scala
index b0b82e5743..8444065004 100644
--- a/src/compiler/scala/tools/nsc/interactive/Global.scala
+++ b/src/compiler/scala/tools/nsc/interactive/Global.scala
@@ -200,6 +200,7 @@ self =>
outOfDate = false
compileRunner = newRunnerThread
ex match {
+ case _ : FreshRunReq => // This shouldn't be reported
case _ : ValidateError => // This will have been reported elsewhere
case _ => ex.printStackTrace(); inform("Fatal Error: "+ex)
}
@@ -265,16 +266,17 @@ self =>
// ----------------- Implementations of client commmands -----------------------
def respond[T](result: Response[T])(op: => T): Unit =
- while(true)
- try {
- result set Left(op)
- return
- } catch {
- case ex : ControlException =>
- case ex =>
- result set Right(ex)
- throw ex
- }
+ try {
+ result set Left(op)
+ return
+ } catch {
+ case ex : FreshRunReq =>
+ scheduler.postWorkItem(() => respond(result)(op))
+ throw ex
+ case ex =>
+ result set Right(ex)
+ throw ex
+ }
/** Make sure a set of compilation units is loaded and parsed */
def reloadSources(sources: List[SourceFile]) {
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index ebcd18082d..e07d1e252d 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -1392,8 +1392,8 @@ trait Typers { self: Analyzer =>
}
if (mods hasFlag DEFERRED) gs.toList else vdef :: gs.toList
}
- case DocDef(comment, defn) =>
- addGetterSetter(defn) map (stat => DocDef(comment, stat))
+ case dd @ DocDef(comment, defn) =>
+ addGetterSetter(defn) map (stat => DocDef(comment, stat) setPos dd.pos)
case Annotated(annot, defn) =>
addGetterSetter(defn) map (stat => Annotated(annot, stat))
@@ -3519,9 +3519,12 @@ trait Typers { self: Analyzer =>
case ldef @ LabelDef(_, _, _) =>
labelTyper(ldef).typedLabelDef(ldef)
- case DocDef(comment, defn) =>
+ case ddef @ DocDef(comment, defn) =>
val ret = typed(defn, mode, pt)
- if ((comments ne null) && (defn.symbol ne null) && (defn.symbol ne NoSymbol)) comments(defn.symbol) = comment
+ if ((comments ne null) && (defn.symbol ne null) && (defn.symbol ne NoSymbol)) {
+ comments(defn.symbol) = comment
+ commentOffsets(defn.symbol) = ddef.pos.startOrPoint
+ }
ret
case Annotated(constr, arg) =>
diff --git a/test/files/positions/ExcludedPrefix1.scala b/test/files/positions/ExcludedPrefix1.scala
new file mode 100644
index 0000000000..f3562c37f0
--- /dev/null
+++ b/test/files/positions/ExcludedPrefix1.scala
@@ -0,0 +1,41 @@
+object ExcludedPrefix1 {
+ case
+ class Foo
+
+ case
+ object
+ BLAH
+
+ val
+ a = 1
+
+ var
+ b = 2
+
+ def
+ c = 23
+
+ private
+ def
+ d = 23
+
+ lazy
+ val
+ e = 23
+
+ private
+ type
+ f = Int
+
+ val
+ g,
+ h = 23
+
+ val
+ (i,
+ j) = (0, 0)
+
+ val Pair(
+ k,
+ l) = (0, 0)
+}
diff --git a/test/files/positions/MultipleDefs1.scala b/test/files/positions/MultipleDefs1.scala
new file mode 100644
index 0000000000..10c0a77fea
--- /dev/null
+++ b/test/files/positions/MultipleDefs1.scala
@@ -0,0 +1,3 @@
+object MultipleDefs1 {
+ val a, b = 23
+}
diff --git a/test/files/positions/Scaladoc1.scala b/test/files/positions/Scaladoc1.scala
new file mode 100644
index 0000000000..9306e2ce9f
--- /dev/null
+++ b/test/files/positions/Scaladoc1.scala
@@ -0,0 +1,8 @@
+object Scaladoc1 {
+ /**
+ * Foo
+ */
+ val (a, b) = (1, 2)
+ a
+ b
+}
diff --git a/test/files/positions/Scaladoc2.scala b/test/files/positions/Scaladoc2.scala
new file mode 100644
index 0000000000..e52263d86c
--- /dev/null
+++ b/test/files/positions/Scaladoc2.scala
@@ -0,0 +1,16 @@
+object Scaladoc2 {
+ def f {
+ /**
+ * Foo
+ */
+ def g {}
+
+ /*
+ * Blah blah
+ */
+ def h{}
+ h
+ }
+
+ def h {}
+}
diff --git a/test/files/positions/Scaladoc3.scala b/test/files/positions/Scaladoc3.scala
new file mode 100644
index 0000000000..c331b7e396
--- /dev/null
+++ b/test/files/positions/Scaladoc3.scala
@@ -0,0 +1,8 @@
+object Scaladoc3 {
+ /**
+ * Foo
+ */
+ import scala.collection.mutable.ArrayBuffer
+
+ def f {}
+}
diff --git a/test/files/positions/Scaladoc4.scala b/test/files/positions/Scaladoc4.scala
new file mode 100644
index 0000000000..133cde1c85
--- /dev/null
+++ b/test/files/positions/Scaladoc4.scala
@@ -0,0 +1,8 @@
+object Scaladoc4 {
+ /**
+ * Foo
+ */
+ 2+2
+
+ def f {}
+}
diff --git a/test/files/positions/Scaladoc5.scala b/test/files/positions/Scaladoc5.scala
new file mode 100644
index 0000000000..c33828c691
--- /dev/null
+++ b/test/files/positions/Scaladoc5.scala
@@ -0,0 +1,8 @@
+/**
+ * Foo
+ */
+package positions
+
+object Scaladoc5 {
+
+}