added admin tool "isabelle build_vscode";
authorwenzelm
Tue Mar 07 13:55:49 2017 +0100 (2017-03-07)
changeset 6513864dfee6bd243
parent 65137 812c35fbffa8
child 65139 0a2c0712e432
added admin tool "isabelle build_vscode";
src/Pure/System/isabelle_tool.scala
src/Pure/build-jars
src/Tools/VSCode/README.md
src/Tools/VSCode/extension/README.md
src/Tools/VSCode/src/build_vscode.scala
src/Tools/VSCode/src/grammar.scala
src/Tools/VSCode/src/symbols.scala
     1.1 --- a/src/Pure/System/isabelle_tool.scala	Tue Mar 07 10:52:04 2017 +0100
     1.2 +++ b/src/Pure/System/isabelle_tool.scala	Tue Mar 07 13:55:49 2017 +0100
     1.3 @@ -117,9 +117,9 @@
     1.4        Update_Header.isabelle_tool,
     1.5        Update_Then.isabelle_tool,
     1.6        Update_Theorems.isabelle_tool,
     1.7 +      isabelle.vscode.Build_VSCode.isabelle_tool,
     1.8        isabelle.vscode.Grammar.isabelle_tool,
     1.9 -      isabelle.vscode.Server.isabelle_tool,
    1.10 -      isabelle.vscode.Symbols.isabelle_tool)
    1.11 +      isabelle.vscode.Server.isabelle_tool)
    1.12  
    1.13    private def list_internal(): List[(String, String)] =
    1.14      for (tool <- internal_tools.toList if tool.accessible)
     2.1 --- a/src/Pure/build-jars	Tue Mar 07 10:52:04 2017 +0100
     2.2 +++ b/src/Pure/build-jars	Tue Mar 07 13:55:49 2017 +0100
     2.3 @@ -160,12 +160,12 @@
     2.4    ../Tools/Graphview/popups.scala
     2.5    ../Tools/Graphview/shapes.scala
     2.6    ../Tools/Graphview/tree_panel.scala
     2.7 +  ../Tools/VSCode/src/build_vscode.scala
     2.8    ../Tools/VSCode/src/channel.scala
     2.9    ../Tools/VSCode/src/document_model.scala
    2.10    ../Tools/VSCode/src/grammar.scala
    2.11    ../Tools/VSCode/src/protocol.scala
    2.12    ../Tools/VSCode/src/server.scala
    2.13 -  ../Tools/VSCode/src/symbols.scala
    2.14    ../Tools/VSCode/src/vscode_rendering.scala
    2.15    ../Tools/VSCode/src/vscode_resources.scala
    2.16  )
     3.1 --- a/src/Tools/VSCode/README.md	Tue Mar 07 10:52:04 2017 +0100
     3.2 +++ b/src/Tools/VSCode/README.md	Tue Mar 07 13:55:49 2017 +0100
     3.3 @@ -25,13 +25,9 @@
     3.4  
     3.5  ## Build ##
     3.6  
     3.7 -* shell> `cd src/Tools/VSCode/extension`
     3.8 -
     3.9 -* shell> `isabelle vscode_grammar`
    3.10 +* shell> `isabelle build_vscode`
    3.11  
    3.12 -* shell> `isabelle vscode_symbols`
    3.13 -
    3.14 -* shell> `vsce package`
    3.15 +* Extensions / ... / Install from VSIX: src/Tools/VSCode/extension/isabelle-X.Y.Z.vsix
    3.16  
    3.17  
    3.18  ## Relevant links ##
     4.1 --- a/src/Tools/VSCode/extension/README.md	Tue Mar 07 10:52:04 2017 +0100
     4.2 +++ b/src/Tools/VSCode/extension/README.md	Tue Mar 07 13:55:49 2017 +0100
     4.3 @@ -28,5 +28,5 @@
     4.4  Symbols Mode. It needs to be configured manually as follows:
     4.5  
     4.6  $ISABELLE_HOME/src/Tools/VSCode/extension/isabelle-symbols.json contains a
     4.7 -configuration (generated via `isabelle vscode_symbols`). Its content needs to
     4.8 +configuration (generated via `isabelle build_vscode`). Its content needs to
     4.9  be copied carefully into the regular VSCode User Preferences.
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/Tools/VSCode/src/build_vscode.scala	Tue Mar 07 13:55:49 2017 +0100
     5.3 @@ -0,0 +1,103 @@
     5.4 +/*  Title:      Pure/Admin/build_vscode.scala
     5.5 +    Author:     Makarius
     5.6 +
     5.7 +Build VSCode configuration and extension module for Isabelle.
     5.8 +*/
     5.9 +
    5.10 +package isabelle.vscode
    5.11 +
    5.12 +
    5.13 +import isabelle._
    5.14 +
    5.15 +
    5.16 +object Build_VSCode
    5.17 +{
    5.18 +  val extension_dir = Path.explode("~~/src/Tools/VSCode/extension")
    5.19 +
    5.20 +
    5.21 +  /* Prettify Symbols Mode */
    5.22 +
    5.23 +  def prettify_config: String =
    5.24 +    """{
    5.25 +  "prettifySymbolsMode.substitutions": [
    5.26 +      {
    5.27 +        "language": "isabelle",
    5.28 +        "revealOn": "none",
    5.29 +        "adjustCursorMovement": true,
    5.30 +        "substitutions": [""" +
    5.31 +          (for ((s, c) <- Symbol.codes)
    5.32 +           yield
    5.33 +            JSON.Format(
    5.34 +              Map("ugly" -> Library.escape_regex(s),
    5.35 +                "pretty" -> Library.escape_regex(Codepoint.string(c)))))
    5.36 +            .mkString("\n          ", ",\n          ", "") +
    5.37 +        """]
    5.38 +      }
    5.39 +    ]
    5.40 +}"""
    5.41 +
    5.42 +  def build_symbols(progress: Progress = No_Progress)
    5.43 +  {
    5.44 +    val output_path = extension_dir + Path.explode("isabelle-symbols.json")
    5.45 +    progress.echo(output_path.implode)
    5.46 +    File.write_backup(output_path, prettify_config)
    5.47 +  }
    5.48 +
    5.49 +
    5.50 +  /* grammar */
    5.51 +
    5.52 +  def build_grammar(options: Options, progress: Progress = No_Progress)
    5.53 +  {
    5.54 +    val logic = Grammar.default_logic
    5.55 +    val keywords = Build.outer_syntax(options, Nil, logic).keywords
    5.56 +
    5.57 +    val output_path = extension_dir + Path.explode(Grammar.default_output(logic))
    5.58 +    progress.echo(output_path.implode)
    5.59 +    File.write_backup(output_path, Grammar.generate(keywords))
    5.60 +  }
    5.61 +
    5.62 +
    5.63 +  /* extension */
    5.64 +
    5.65 +  def build_extension(progress: Progress = No_Progress, publish: Boolean = false)
    5.66 +  {
    5.67 +    val output_path = extension_dir + Path.explode("out")
    5.68 +    progress.echo(output_path.implode)
    5.69 +
    5.70 +    val cmd = "vsce " + (if (publish) "publish" else "package")
    5.71 +    progress.bash(cmd, cwd = extension_dir.file, echo = true).check
    5.72 +  }
    5.73 +
    5.74 +
    5.75 +  /* Isabelle tool wrapper */
    5.76 +
    5.77 +  val isabelle_tool =
    5.78 +    Isabelle_Tool("build_vscode", "build Isabelle/VSCode extension module", args =>
    5.79 +    {
    5.80 +      var publish = false
    5.81 +
    5.82 +      val getopts = Getopts("""
    5.83 +Usage: isabelle build_vscode
    5.84 +
    5.85 +  Options are:
    5.86 +    -P           publish the package
    5.87 +
    5.88 +Build Isabelle/VSCode extension module in directory
    5.89 +""" + extension_dir.expand + """
    5.90 +
    5.91 +This requires npm and the vsce build and publishing tool, see also
    5.92 +https://code.visualstudio.com/docs/tools/vscecli
    5.93 +""",
    5.94 +        "P" -> (_ => publish = true))
    5.95 +
    5.96 +      val more_args = getopts(args)
    5.97 +      if (more_args.nonEmpty) getopts.usage()
    5.98 +
    5.99 +      val options = Options.init()
   5.100 +      val progress = new Console_Progress()
   5.101 +
   5.102 +      build_symbols(progress)
   5.103 +      build_grammar(options, progress)
   5.104 +      build_extension(progress, publish = publish)
   5.105 +    }, admin = true)
   5.106 +}
     6.1 --- a/src/Tools/VSCode/src/grammar.scala	Tue Mar 07 10:52:04 2017 +0100
     6.2 +++ b/src/Tools/VSCode/src/grammar.scala	Tue Mar 07 13:55:49 2017 +0100
     6.3 @@ -16,9 +16,9 @@
     6.4  {
     6.5    /* generate grammar */
     6.6  
     6.7 -  private lazy val default_logic = Isabelle_System.getenv("ISABELLE_LOGIC")
     6.8 +  lazy val default_logic = Isabelle_System.getenv("ISABELLE_LOGIC")
     6.9  
    6.10 -  private def default_output(logic: String = ""): String =
    6.11 +  def default_output(logic: String = ""): String =
    6.12      if (logic == "" || logic == default_logic) "isabelle-grammar.json"
    6.13      else "isabelle-" + logic + "-grammar.json"
    6.14  
     7.1 --- a/src/Tools/VSCode/src/symbols.scala	Tue Mar 07 10:52:04 2017 +0100
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,55 +0,0 @@
     7.4 -/*  Title:      Tools/VSCode/src/symbols.scala
     7.5 -    Author:     Makarius
     7.6 -
     7.7 -Generate configuration for VSCode editor extension Prettify Symbols Mode.
     7.8 -*/
     7.9 -
    7.10 -package isabelle.vscode
    7.11 -
    7.12 -
    7.13 -import isabelle._
    7.14 -
    7.15 -
    7.16 -object Symbols
    7.17 -{
    7.18 -  /* generate configuration */
    7.19 -
    7.20 -  def prettify_config: String =
    7.21 -    """{
    7.22 -  "prettifySymbolsMode.substitutions": [
    7.23 -      {
    7.24 -        "language": "isabelle",
    7.25 -        "revealOn": "none",
    7.26 -        "adjustCursorMovement": true,
    7.27 -        "substitutions": [""" +
    7.28 -          (for ((s, c) <- Symbol.codes)
    7.29 -           yield
    7.30 -            JSON.Format(
    7.31 -              Map("ugly" -> Library.escape_regex(s),
    7.32 -                "pretty" -> Library.escape_regex(Codepoint.string(c)))))
    7.33 -            .mkString("\n          ", ",\n          ", "") +
    7.34 -        """]
    7.35 -      }
    7.36 -    ]
    7.37 -}"""
    7.38 -
    7.39 -
    7.40 -  /* Isabelle tool wrapper */
    7.41 -
    7.42 -  val isabelle_tool = Isabelle_Tool("vscode_symbols",
    7.43 -    "generate configuration for VSCode Prettify Symbols Mode", args =>
    7.44 -  {
    7.45 -    val getopts = Getopts("""
    7.46 -Usage: isabelle vscode_symbols
    7.47 -
    7.48 -  Generate configuration for VSCode editor extension Prettify Symbols Mode.
    7.49 -""")
    7.50 -
    7.51 -    val more_args = getopts(args)
    7.52 -    if (more_args.nonEmpty) getopts.usage()
    7.53 -
    7.54 -    val output_path = Path.explode("isabelle-symbols.json")
    7.55 -    Output.writeln(output_path.implode)
    7.56 -    File.write_backup(output_path, prettify_config)
    7.57 -  })
    7.58 -}