Skip to content

Commit

Permalink
fixes #17
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Ring committed Jun 20, 2016
1 parent a68ea10 commit fc84368
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 112 deletions.
2 changes: 1 addition & 1 deletion example/theme/dfki-code.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
.cm-s-dfki-code .cm-attribute { color: #d6bb6d; }
.cm-s-dfki-code .cm-header { color: #FF6400; }
.cm-s-dfki-code .cm-hr { color: #AEAEAE; }
.cm-s-dfki-code .cm-link { color:#ad9361; font-style:italic; text-decoration:none; }
.cm-s-dfki-code .cm-link { text-decoration:underline; }
/*.cm-s-dfki-code .cm-error { }*/

.cm-s-dfki-code .cm-empty-error { border-bottom: : }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ object Annotations {
loop(a.annotations.reverse,o.actions.reverse,Nil).map(Annotations(_,a.responses))
}

/** TODO */
def compose(a: Annotations, b: Annotations): Try[Annotations] = {
@tailrec
def loop(as: List[Annotation], bs: List[Annotation], xs: List[Annotation]): Try[List[Annotation]] = (as,bs,xs) match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ trait ScalaCompiler extends CompilerAccess with PimpedTrees { self: ScalaService

val messages = collection.mutable.Map.empty[String,SortedSet[(Int,Int,String,String)]]
val identifiers = collection.mutable.Map.empty[String,SortedSet[(Int,Int,Option[String],Seq[String])]]
val substitutions = collection.mutable.Map.empty[String,SortedSet[(Int,Int,String)]]
val implicits = collection.mutable.Map.empty[String,SortedSet[(Int,Int,String)]]

def markImplicit(pos: Position, t: String) = if (pos.isDefined) {
Expand All @@ -120,14 +119,6 @@ trait ScalaCompiler extends CompilerAccess with PimpedTrees { self: ScalaService
implicits(pos.source.file.name) += ((start,length,t))
}

def substitute(pos: Position, symbol: String) = if (pos.isDefined) {
if (!substitutions.isDefinedAt(pos.source.file.name))
substitutions(pos.source.file.name) = SortedSet.empty
val (start,length) =
(pos.start, pos.end - pos.start)
substitutions(pos.source.file.name) += ((start,length,symbol))
}

def identifier(pos: Position, kind: String*): Unit = identifier(pos, None, kind :_*)

def identifier(pos: Position, t: Option[String], kind: String*): Unit = if (pos.isDefined && pos.isRange) {
Expand Down Expand Up @@ -202,12 +193,12 @@ trait ScalaCompiler extends CompilerAccess with PimpedTrees { self: ScalaService

def annotationsFromTree(tree: global.Tree): Unit = if (tree.pos.isDefined && tree.pos.isRange) tree match {
case t: global.TypeTree =>
val classes = "ref" :: "type" ::
val classes = "ref" :: "type" :: "variable-3" ::
(if (t.symbol.isTypeParameter) List("param") else Nil)
identifier(t.namePosition, global.docComments.get(t.symbol).map(_.toString).orElse(Some(t.symbol.kindString + " " + t.symbol.nameString + t.symbol.signatureString)), classes :_*)
t.children.foreach(annotationsFromTree(_))
case c: global.TypeDef =>
val classes = "def" :: "type" ::
val classes = "def" :: "type" :: "variable-3" ::
(if (c.symbol.isTypeParameter) List("param") else Nil)
identifier(c.namePosition,Some(c.symbol.kindString + " " + c.symbol.nameString + c.symbol.signatureString), classes :_*)
c.children.foreach(annotationsFromTree(_))
Expand All @@ -224,16 +215,16 @@ trait ScalaCompiler extends CompilerAccess with PimpedTrees { self: ScalaService
identifier(c.pos,Some("literal " + c.toString + ": " + c.tpe.toString().takeWhile(_ != '(')))
case c: global.ValDef =>
val classes = "def" :: "val-def" ::
(if (c.symbol.isLocalToBlock) List("local") else Nil) ++
(if (c.symbol.isParameter) List("param") else Nil) ++
(if (c.symbol.isVar) List("var-def") else Nil)
(if (c.symbol.isLocalToBlock) List("local","em") else Nil) ++
(if (c.symbol.isParameter) List("param","variable-2") else Nil) ++
(if (c.symbol.isVar) List("var-def","variable") else Nil)
global.ask(() => identifier(c.namePosition,Some(c.symbol.kindString + " " + c.symbol.nameString + c.symbol.signatureString), classes :_*))
c.children.foreach(annotationsFromTree(_))
case c: global.DefDef =>
val classes = "def" :: "def-def" ::
(if (c.symbol.isLocalToBlock) List("local") else Nil) ++
(if (c.symbol.isParameter) List("param") else Nil) ++
(if (c.symbol.isVar) List("var-def") else Nil)
(if (c.symbol.isLocalToBlock) List("local","em") else Nil) ++
(if (c.symbol.isParameter) List("param","variable-2") else Nil) ++
(if (c.symbol.isVar) List("var-def","variable") else Nil)
global.ask(() => identifier(c.namePosition,Some(c.symbol.kindString + " " + c.symbol.nameString + c.symbol.signatureString), classes :_*))
c.children.foreach(annotationsFromTree(_))
case a: global.Apply if a.symbol != global.NoSymbol =>
Expand All @@ -243,22 +234,22 @@ trait ScalaCompiler extends CompilerAccess with PimpedTrees { self: ScalaService
a.children.foreach(annotationsFromTree(_))
case c: global.Select if c.symbol != global.NoSymbol =>
val classes = "ref" :: "select" ::
global.ask(() => (if (c.symbol.isDeprecated) List("deprecated") else Nil)) ++
global.ask(() => (if (c.symbol.isDeprecated) List("deprecated", "strikethrough") else Nil)) ++
(if (c.symbol.isVar) List("variable") else Nil) ++
(if (c.symbol.isLocalToBlock) List("local") else Nil) ++
(if (c.symbol.isValueParameter) List("param") else Nil) ++
(if (c.symbol.isModule) List("module") else Nil) ++
(if (c.symbol.isConstructor) List("constructor", "type") else Nil)
(if (c.symbol.isLocalToBlock) List("local","em") else Nil) ++
(if (c.symbol.isValueParameter) List("param","variable-2") else Nil) ++
(if (c.symbol.isModule) List("module","qualifier") else Nil) ++
(if (c.symbol.isConstructor) List("constructor", "variable-3") else Nil)
global.ask(() => identifier(c.namePosition,Some(c.symbol.kindString + " " + c.symbol.nameString + c.symbol.signatureString), classes :_*))
c.children.foreach(annotationsFromTree(_))
case i: global.Ident if i.symbol != global.NoSymbol =>
val classes = "ref" :: "ident" ::
global.ask(() => (if (i.symbol.isDeprecated) List("deprecated") else Nil)) ++
(if (i.symbol.isVar) List("variable") else Nil) ++
(if (i.symbol.isLocalToBlock) List("local") else Nil) ++
(if (i.symbol.isValueParameter) List("param") else Nil) ++
(if (i.symbol.isModule) List("module") else Nil) ++
(if (i.symbol.isType) List("type") else Nil)
(if (i.symbol.isLocalToBlock) List("local","em") else Nil) ++
(if (i.symbol.isValueParameter) List("param","variable-2") else Nil) ++
(if (i.symbol.isModule) List("module", "qualifier") else Nil) ++
(if (i.symbol.isType) List("type", "variable-3") else Nil)
global.ask(() => identifier(i.namePosition,Some(i.symbol.kindString + " " + i.symbol.nameString + i.symbol.signatureString),classes :_*))
i.children.foreach(annotationsFromTree(_))
case t: global.Tree =>
Expand All @@ -277,7 +268,6 @@ trait ScalaCompiler extends CompilerAccess with PimpedTrees { self: ScalaService
tree.get.left.foreach { tree =>
identifiers.get(source.path).foreach(_.clear())
implicits.get(source.path).foreach(_.clear())
substitutions.get(source.path).foreach(_.clear())
annotationsFromTree(tree)
annotateSemantics()
annotate()
Expand All @@ -289,48 +279,27 @@ trait ScalaCompiler extends CompilerAccess with PimpedTrees { self: ScalaService


def annotate() {
messages.collect { case (path,messages) if files.isDefinedAt(path) =>
var annotations = new Annotations()
var last = 0
messages.collect {
case (offset, length, tpe, msg) =>
if (offset > last) {
annotations = annotations.plain(offset - last)
last = offset
}
annotations = annotations.annotate(length,
messages.collect { case (path, messages) if files.isDefinedAt(path) =>
val (state, client) = files(path)
val tlength = state.length
val annotations = messages.collect {
case (offset, length, tpe, msg) if length > 0 =>
new Annotations().plain(offset).annotate(length,
tpe match {
case "error" => AnnotationOptions(classes = Set("error"), messages = List(ErrorMessage(msg)))
case "warning" => AnnotationOptions(classes = Set("warning"), messages = List(WarningMessage(msg)))
case _ => AnnotationOptions(messages = List(InfoMessage(msg)))
}
)
last += length
}
val file = files(path)
annotations = annotations.plain(file._1.length - last)
file._2.localAnnotations("messages", annotations)
).plain(tlength - (offset + length))
}.foldLeft(new Annotations().plain(tlength))(_.compose(_).get)
client.localAnnotations("messages", annotations)
}
}

/*def getInfo(id: String, from: Int, to: Int, state: String) = {
messages.values.foreach(_.clear)
val source = new BatchSourceFile(id, state)
val reloaded = new Response[Unit]
global.askReload(List(source), reloaded)
reloaded.get.left.foreach { _ =>
val tree = new Response[global.Tree]
global.askLoadedTyped(source, tree)
tree.get.left.foreach { tree =>
}
}
}*/

def getInfo(id: String, state: String, from: Int, to: Int, guid: String) = compile(id,state) {
identifiers.get(id).flatMap { messages =>
val msgs = messages.filter {
case (offset,length,tt,tpe) => from <= offset && offset <= to
case (offset,length,tt,tpe) => length > 0 && from <= offset && offset <= to
}
if (msgs.isEmpty) None
else Some {
Expand All @@ -349,61 +318,27 @@ trait ScalaCompiler extends CompilerAccess with PimpedTrees { self: ScalaService

def annotateSemantics() {
identifiers.collect { case (path,messages) if files.isDefinedAt(path) =>
var annotations = new Annotations
var last = 0
messages.collect {
case (offset, length, tt, tpe) =>
if (offset > last) {
annotations = annotations.plain(offset - last)
last = offset
}
annotations = annotations.annotate(length,
val (state,client) = files(path)
val tlength = state.length
val annotations = messages.collect {
case (offset, length, tt, tpe) if length > 0 =>
new Annotations().plain(offset).annotate(length,
(tpe.toList.map{ (x: String) => AnnotationOptions(classes = Set(x)) } ++
tt.toList.map( (x: String) => AnnotationOptions(tooltip = Some(x)) )).reduce(_ ++ _)
)
last += length
}
val file = files(path)
annotations = annotations.plain(file._1.length - last)
file._2.localAnnotations("semantic", annotations)
tt.toList.map( (x: String) => AnnotationOptions(tooltip = Some(x)) )).reduce(_ ++ _)
).plain(tlength - (offset + length))
}.foldLeft(new Annotations().plain(tlength))(_.compose(_).get)
client.localAnnotations("semantic", annotations)
}

implicits.collect { case (path,messages) if files.isDefinedAt(path) =>
var annotations = new Annotations
var last = 0
messages.collect {
case (offset, length, tt) =>
if (offset > last) {
annotations = annotations.plain(offset - last)
last = offset
}
annotations = annotations.annotate(length,
AnnotationOptions(classes=Set("implicit"),messages = List(InfoMessage("implicit conversion: " + tt)))
)
last += length
}
val file = files(path)
annotations = annotations.plain(file._1.length - last)
file._2.localAnnotations("semantic", annotations)
}

substitutions.collect { case (path,messages) if files.isDefinedAt(path) =>
var annotations = new Annotations
var last = 0
messages.collect {
case (offset, length, sym) =>
if (offset > last) {
annotations = annotations.plain(offset - last)
last = offset
}
annotations = annotations.annotate(length,
AnnotationOptions(substitute = Some(sym))
)
last += length
}
val file = files(path)
annotations = annotations.plain(file._1.length - last)
file._2.localAnnotations("semantic", annotations)
val (state,client) = files(path)
val tlength = state.length
val annotations = messages.collect {
case (offset, length, tt) if length > 0 =>
new Annotations().plain(offset).annotate(length,
AnnotationOptions(classes=Set("link"),tooltip = Some("implicit conversion: " + tt))
).plain(tlength - (offset + length))
}.foldLeft(new Annotations().plain(tlength))(_.compose(_).get)
client.localAnnotations("implicits", annotations)
}
}
}

0 comments on commit fc84368

Please sign in to comment.