src/Pure/PIDE/document.scala
changeset 64665 00aa710ff7f0
parent 63584 68751fe1c036
child 64681 642b6105e6f4
equal deleted inserted replaced
64664:951507563033 64665:00aa710ff7f0
   451 
   451 
   452     val node_name: Node.Name
   452     val node_name: Node.Name
   453     val node: Node
   453     val node: Node
   454     val load_commands: List[Command]
   454     val load_commands: List[Command]
   455     def is_loaded: Boolean
   455     def is_loaded: Boolean
       
   456 
       
   457     def find_command(id: Document_ID.Generic): Option[(Node, Command)]
       
   458     def find_command_position(id: Document_ID.Generic, offset: Symbol.Offset)
       
   459       : Option[Line.Node_Position]
   456 
   460 
   457     def cumulate[A](
   461     def cumulate[A](
   458       range: Text.Range,
   462       range: Text.Range,
   459       info: A,
   463       info: A,
   460       elements: Markup.Elements,
   464       elements: Markup.Elements,
   544       copy(commands = commands + (id -> command.init_state))
   548       copy(commands = commands + (id -> command.init_state))
   545     }
   549     }
   546 
   550 
   547     def defined_command(id: Document_ID.Command): Boolean = commands.isDefinedAt(id)
   551     def defined_command(id: Document_ID.Command): Boolean = commands.isDefinedAt(id)
   548 
   552 
   549     def find_command(version: Version, id: Document_ID.Generic): Option[(Node, Command)] =
       
   550       commands.get(id) orElse execs.get(id) match {
       
   551         case None => None
       
   552         case Some(st) =>
       
   553           val command = st.command
       
   554           val node = version.nodes(command.node_name)
       
   555           if (node.commands.contains(command)) Some((node, command)) else None
       
   556       }
       
   557 
       
   558     def the_version(id: Document_ID.Version): Version = versions.getOrElse(id, fail)
   553     def the_version(id: Document_ID.Version): Version = versions.getOrElse(id, fail)
   559     def the_static_state(id: Document_ID.Command): Command.State = commands.getOrElse(id, fail)
   554     def the_static_state(id: Document_ID.Command): Command.State = commands.getOrElse(id, fail)
   560     def the_dynamic_state(id: Document_ID.Exec): Command.State = execs.getOrElse(id, fail)
   555     def the_dynamic_state(id: Document_ID.Exec): Command.State = execs.getOrElse(id, fail)
   561     def the_assignment(version: Version): State.Assignment = assignments.getOrElse(version.id, fail)
   556     def the_assignment(version: Version): State.Assignment = assignments.getOrElse(version.id, fail)
   562 
   557 
   789         val load_commands: List[Command] =
   784         val load_commands: List[Command] =
   790           if (node_name.is_theory) Nil
   785           if (node_name.is_theory) Nil
   791           else version.nodes.load_commands(node_name)
   786           else version.nodes.load_commands(node_name)
   792 
   787 
   793         val is_loaded: Boolean = node_name.is_theory || load_commands.nonEmpty
   788         val is_loaded: Boolean = node_name.is_theory || load_commands.nonEmpty
       
   789 
       
   790 
       
   791         /* find command */
       
   792 
       
   793         def find_command(id: Document_ID.Generic): Option[(Node, Command)] =
       
   794           state.commands.get(id) orElse state.execs.get(id) match {
       
   795             case None => None
       
   796             case Some(st) =>
       
   797               val command = st.command
       
   798               val node = version.nodes(command.node_name)
       
   799               if (node.commands.contains(command)) Some((node, command)) else None
       
   800           }
       
   801 
       
   802         def find_command_position(id: Document_ID.Generic, offset: Symbol.Offset)
       
   803             : Option[Line.Node_Position] =
       
   804           for ((node, command) <- find_command(id))
       
   805           yield {
       
   806             val name = command.node_name.node
       
   807             val sources_iterator =
       
   808               node.commands.iterator.takeWhile(_ != command).map(_.source) ++
       
   809                 (if (offset == 0) Iterator.empty
       
   810                  else Iterator.single(command.source(Text.Range(0, command.chunk.decode(offset)))))
       
   811             val pos = (Line.Position.zero /: sources_iterator)(_.advance(_))
       
   812             Line.Node_Position(name, pos)
       
   813           }
   794 
   814 
   795 
   815 
   796         /* cumulate markup */
   816         /* cumulate markup */
   797 
   817 
   798         def cumulate[A](
   818         def cumulate[A](
   851             (if (is_outdated) ", outdated" else "") + ")"
   871             (if (is_outdated) ", outdated" else "") + ")"
   852       }
   872       }
   853     }
   873     }
   854   }
   874   }
   855 }
   875 }
   856