src/Pure/PIDE/command.scala
changeset 72745 5a6f7212fc4d
parent 72744 0017eb17ac1c
child 72747 5f9d66155081
equal deleted inserted replaced
72744:0017eb17ac1c 72745:5a6f7212fc4d
    14 
    14 
    15 object Command
    15 object Command
    16 {
    16 {
    17   type Edit = (Option[Command], Option[Command])
    17   type Edit = (Option[Command], Option[Command])
    18 
    18 
    19   type Blob = Exn.Result[(Document.Node.Name, Option[(SHA1.Digest, Symbol.Text_Chunk)])]
    19   sealed case class Blob(
    20   type Blobs_Info = (List[Blob], Int)
    20     name: Document.Node.Name,
       
    21     content: Option[(SHA1.Digest, Symbol.Text_Chunk)])
       
    22 
       
    23   type Blobs_Info = (List[Exn.Result[Blob]], Int)
    21   val no_blobs: Blobs_Info = (Nil, -1)
    24   val no_blobs: Blobs_Info = (Nil, -1)
    22 
    25 
    23 
    26 
    24   /** accumulated results from prover **/
    27   /** accumulated results from prover **/
    25 
    28 
   426               if (Thy_Header.is_base_name(s)) resources.complete_import_name(node_name, s) else Nil
   429               if (Thy_Header.is_base_name(s)) resources.complete_import_name(node_name, s) else Nil
   427             val msg =
   430             val msg =
   428               "Bad theory import " +
   431               "Bad theory import " +
   429                 Markup.Path(import_name.node).markup(quote(import_name.toString)) +
   432                 Markup.Path(import_name.node).markup(quote(import_name.toString)) +
   430                 Position.here(pos) + Completion.report_theories(pos, completion)
   433                 Position.here(pos) + Completion.report_theories(pos, completion)
   431             Exn.Exn(ERROR(msg)): Command.Blob
   434             Exn.Exn[Command.Blob](ERROR(msg))
   432           }
   435           }
   433         (errors, -1)
   436         (errors, -1)
   434 
   437 
   435       // auxiliary files
   438       // auxiliary files
   436       case _ =>
   439       case _ =>
   437         val (files, index) = span.loaded_files(syntax)
   440         val (files, index) = span.loaded_files(syntax)
   438         val blobs =
   441         val blobs =
   439           files.map(file =>
   442           files.map(file =>
   440             (Exn.capture {
   443             (Exn.capture {
   441               val name = Document.Node.Name(resources.append(node_name, Path.explode(file)))
   444               val name = Document.Node.Name(resources.append(node_name, Path.explode(file)))
   442               val blob = get_blob(name).map(blob => (blob.bytes.sha1_digest, blob.chunk))
   445               val content = get_blob(name).map(blob => (blob.bytes.sha1_digest, blob.chunk))
   443               (name, blob)
   446               Blob(name, content)
   444             }).user_error)
   447             }).user_error)
   445         (blobs, index)
   448         (blobs, index)
   446     }
   449     }
   447   }
   450   }
   448 }
   451 }
   472   def potentially_initialized: Boolean = span.name == Thy_Header.THEORY
   475   def potentially_initialized: Boolean = span.name == Thy_Header.THEORY
   473 
   476 
   474 
   477 
   475   /* blobs */
   478   /* blobs */
   476 
   479 
   477   def blobs: List[Command.Blob] = blobs_info._1
   480   def blobs: List[Exn.Result[Command.Blob]] = blobs_info._1
   478   def blobs_index: Int = blobs_info._2
   481   def blobs_index: Int = blobs_info._2
   479 
   482 
   480   def blobs_ok: Boolean =
   483   def blobs_ok: Boolean =
   481     blobs.forall({ case Exn.Res(_) => true case _ => false })
   484     blobs.forall({ case Exn.Res(_) => true case _ => false })
   482 
   485 
   483   def blobs_names: List[Document.Node.Name] =
   486   def blobs_names: List[Document.Node.Name] =
   484     for (Exn.Res((name, _)) <- blobs) yield name
   487     for (Exn.Res(blob) <- blobs) yield blob.name
   485 
   488 
   486   def blobs_undefined: List[Document.Node.Name] =
   489   def blobs_undefined: List[Document.Node.Name] =
   487     for (Exn.Res((name, None)) <- blobs) yield name
   490     for (Exn.Res(blob) <- blobs if blob.content.isEmpty) yield blob.name
   488 
   491 
   489   def blobs_defined: List[(Document.Node.Name, SHA1.Digest)] =
   492   def blobs_defined: List[(Document.Node.Name, SHA1.Digest)] =
   490     for (Exn.Res((name, Some((digest, _)))) <- blobs) yield (name, digest)
   493     for (Exn.Res(blob) <- blobs; (digest, _) <- blob.content) yield (blob.name, digest)
   491 
   494 
   492   def blobs_changed(doc_blobs: Document.Blobs): Boolean =
   495   def blobs_changed(doc_blobs: Document.Blobs): Boolean =
   493     blobs.exists({ case Exn.Res((name, _)) => doc_blobs.changed(name) case _ => false })
   496     blobs.exists({ case Exn.Res(blob) => doc_blobs.changed(blob.name) case _ => false })
   494 
   497 
   495 
   498 
   496   /* source chunks */
   499   /* source chunks */
   497 
   500 
   498   val chunk: Symbol.Text_Chunk = Symbol.Text_Chunk(source)
   501   val chunk: Symbol.Text_Chunk = Symbol.Text_Chunk(source)
   499 
   502 
   500   val chunks: Map[Symbol.Text_Chunk.Name, Symbol.Text_Chunk] =
   503   val chunks: Map[Symbol.Text_Chunk.Name, Symbol.Text_Chunk] =
   501     ((Symbol.Text_Chunk.Default -> chunk) ::
   504     ((Symbol.Text_Chunk.Default -> chunk) ::
   502       (for (Exn.Res((name, Some((_, file)))) <- blobs)
   505       (for (Exn.Res(blob) <- blobs; (_, file) <- blob.content)
   503         yield Symbol.Text_Chunk.File(name.node) -> file)).toMap
   506         yield Symbol.Text_Chunk.File(blob.name.node) -> file)).toMap
   504 
   507 
   505   def length: Int = source.length
   508   def length: Int = source.length
   506   def range: Text.Range = chunk.range
   509   def range: Text.Range = chunk.range
   507 
   510 
   508   val core_range: Text.Range =
   511   val core_range: Text.Range =