completion supports theory header imports;
authorwenzelm
Thu Oct 05 17:37:47 2017 +0200 (18 months ago)
changeset 66768f27488f47a47
parent 66767 294c2e9a689e
child 66769 97f16ada519c
completion supports theory header imports;
tuned;
NEWS
src/Pure/General/completion.scala
src/Pure/PIDE/command.scala
     1.1 --- a/NEWS	Thu Oct 05 16:33:36 2017 +0200
     1.2 +++ b/NEWS	Thu Oct 05 17:37:47 2017 +0200
     1.3 @@ -30,6 +30,11 @@
     1.4    isabelle build -D '~~/src/ZF'
     1.5  
     1.6  
     1.7 +*** Prover IDE -- Isabelle/Scala/jEdit ***
     1.8 +
     1.9 +* Completion supports theory header imports.
    1.10 +
    1.11 +
    1.12  *** HOL ***
    1.13  
    1.14  * SMT module:
     2.1 --- a/src/Pure/General/completion.scala	Thu Oct 05 16:33:36 2017 +0200
     2.2 +++ b/src/Pure/General/completion.scala	Thu Oct 05 17:37:47 2017 +0200
     2.3 @@ -138,11 +138,19 @@
     2.4      if (s == "" || s == "_") None
     2.5      else Some(s.reverseIterator.dropWhile(_ == '_').toList.reverse.mkString)
     2.6  
     2.7 +  def completed(input: String): String => Boolean =
     2.8 +    clean_name(input) match {
     2.9 +      case None => (name: String) => false
    2.10 +      case Some(prefix) => (name: String) => name.startsWith(prefix)
    2.11 +    }
    2.12 +
    2.13    def report_no_completion(pos: Position.T): String =
    2.14      YXML.string_of_tree(Semantic.Info(pos, No_Completion))
    2.15  
    2.16    def report_names(pos: Position.T, names: List[(String, (String, String))], total: Int = 0): String =
    2.17 -    YXML.string_of_tree(Semantic.Info(pos, Names(if (total > 0) total else names.length, names)))
    2.18 +    if (names.isEmpty) ""
    2.19 +    else
    2.20 +      YXML.string_of_tree(Semantic.Info(pos, Names(if (total > 0) total else names.length, names)))
    2.21  
    2.22    def report_theories(pos: Position.T, thys: List[String], total: Int = 0): String =
    2.23      report_names(pos, thys.map(name => (name, ("theory", name))), total)
     3.1 --- a/src/Pure/PIDE/command.scala	Thu Oct 05 16:33:36 2017 +0200
     3.2 +++ b/src/Pure/PIDE/command.scala	Thu Oct 05 17:37:47 2017 +0200
     3.3 @@ -438,12 +438,32 @@
     3.4        // inlined errors
     3.5        case Thy_Header.THEORY =>
     3.6          val reader = Scan.char_reader(Token.implode(span.content))
     3.7 -        val header = resources.check_thy_reader(node_name, reader)
     3.8 +        val imports = resources.check_thy_reader(node_name, reader).imports
     3.9 +        val raw_imports =
    3.10 +          try {
    3.11 +            val imports1 = Thy_Header.read(reader, Token.Pos.none).imports
    3.12 +            if (imports.length == imports1.length) imports1.map(_._1) else error("")
    3.13 +          }
    3.14 +          catch { case exn: Throwable => List.fill(imports.length)("") }
    3.15 +
    3.16          val errors =
    3.17 -          for ((imp, pos) <- header.imports if !can_import(imp)) yield {
    3.18 +          for { ((import_name, pos), s) <- imports zip raw_imports if !can_import(import_name) }
    3.19 +          yield {
    3.20 +            val completion =
    3.21 +              if (Thy_Header.is_base_name(s)) {
    3.22 +                val completed = Completion.completed(import_name.theory_base_name)
    3.23 +                val qualifier = resources.theory_qualifier(node_name)
    3.24 +                val dir = node_name.master_dir
    3.25 +                for {
    3.26 +                  (_, known_name) <- resources.session_base.known.theories.toList
    3.27 +                  if completed(known_name.theory_base_name)
    3.28 +                } yield resources.standard_import(resources, qualifier, dir, known_name.theory)
    3.29 +              }.sorted
    3.30 +              else Nil
    3.31              val msg =
    3.32                "Bad theory import " +
    3.33 -                Markup.Path(imp.node).markup(quote(imp.toString)) + Position.here(pos)
    3.34 +                Markup.Path(import_name.node).markup(quote(import_name.toString)) +
    3.35 +                Position.here(pos) + Completion.report_theories(pos, completion)
    3.36              Exn.Exn(ERROR(msg)): Command.Blob
    3.37            }
    3.38          (errors, -1)