src/Tools/jEdit/src/rendering.scala
changeset 55615 bf4bbe72f740
parent 55552 bcc643ac071a
child 55616 25a7a998852a
     1.1 --- a/src/Tools/jEdit/src/rendering.scala	Wed Feb 19 21:38:44 2014 +0100
     1.2 +++ b/src/Tools/jEdit/src/rendering.scala	Thu Feb 20 12:53:12 2014 +0100
     1.3 @@ -200,6 +200,31 @@
     1.4    val dynamic_color = color_value("dynamic_color")
     1.5  
     1.6  
     1.7 +  /* completion context */
     1.8 +
     1.9 +  private val completion_elements =
    1.10 +    Set(Markup.STRING, Markup.ALTSTRING, Markup.VERBATIM, Markup.CARTOUCHE,
    1.11 +      Markup.COMMENT, Markup.LANGUAGE)
    1.12 +
    1.13 +  def completion_context(caret: Text.Offset): Completion.Context =
    1.14 +    if (caret > 0) {
    1.15 +      val result =
    1.16 +        snapshot.select_markup(Text.Range(caret - 1, caret + 1), Some(completion_elements), _ =>
    1.17 +          {
    1.18 +            case Text.Info(_, XML.Elem(Markup.Language(language, symbols), _)) =>
    1.19 +              Some(Completion.Context(language, symbols))
    1.20 +            case Text.Info(_, XML.Elem(markup, _)) =>
    1.21 +              if (completion_elements(markup.name)) Some(Completion.Context("unknown", true))
    1.22 +              else None
    1.23 +          })
    1.24 +      result match {
    1.25 +        case Text.Info(_, context) :: _ => context
    1.26 +        case Nil => Completion.Context.default
    1.27 +      }
    1.28 +    }
    1.29 +    else Completion.Context.default
    1.30 +
    1.31 +
    1.32    /* command overview */
    1.33  
    1.34    val overview_limit = options.int("jedit_text_overview_limit")
    1.35 @@ -429,8 +454,8 @@
    1.36              Some(add(prev, r, (true, pretty_typing("::", body))))
    1.37            case (prev, Text.Info(r, XML.Elem(Markup(Markup.ML_TYPING, _), body))) =>
    1.38              Some(add(prev, r, (false, pretty_typing("ML:", body))))
    1.39 -          case (prev, Text.Info(r, XML.Elem(Markup.Language(name), _))) =>
    1.40 -            Some(add(prev, r, (true, XML.Text("language: " + name))))
    1.41 +          case (prev, Text.Info(r, XML.Elem(Markup.Language(language, _), _))) =>
    1.42 +            Some(add(prev, r, (true, XML.Text("language: " + language))))
    1.43            case (prev, Text.Info(r, XML.Elem(Markup(name, _), _))) =>
    1.44              if (tooltips.isDefinedAt(name))
    1.45                Some(add(prev, r, (true, XML.Text(tooltips(name)))))