65138
|
1 |
/* Title: Pure/Admin/build_vscode.scala
|
|
2 |
Author: Makarius
|
|
3 |
|
|
4 |
Build VSCode configuration and extension module for Isabelle.
|
|
5 |
*/
|
|
6 |
|
|
7 |
package isabelle.vscode
|
|
8 |
|
|
9 |
|
|
10 |
import isabelle._
|
|
11 |
|
|
12 |
|
|
13 |
object Build_VSCode
|
|
14 |
{
|
|
15 |
val extension_dir = Path.explode("~~/src/Tools/VSCode/extension")
|
|
16 |
|
|
17 |
|
|
18 |
/* Prettify Symbols Mode */
|
|
19 |
|
|
20 |
def prettify_config: String =
|
|
21 |
"""{
|
|
22 |
"prettifySymbolsMode.substitutions": [
|
|
23 |
{
|
|
24 |
"language": "isabelle",
|
|
25 |
"revealOn": "none",
|
|
26 |
"adjustCursorMovement": true,
|
|
27 |
"substitutions": [""" +
|
|
28 |
(for ((s, c) <- Symbol.codes)
|
|
29 |
yield
|
|
30 |
JSON.Format(
|
|
31 |
Map("ugly" -> Library.escape_regex(s),
|
|
32 |
"pretty" -> Library.escape_regex(Codepoint.string(c)))))
|
|
33 |
.mkString("\n ", ",\n ", "") +
|
|
34 |
"""]
|
|
35 |
}
|
|
36 |
]
|
|
37 |
}"""
|
|
38 |
|
|
39 |
def build_symbols(progress: Progress = No_Progress)
|
|
40 |
{
|
|
41 |
val output_path = extension_dir + Path.explode("isabelle-symbols.json")
|
|
42 |
progress.echo(output_path.implode)
|
|
43 |
File.write_backup(output_path, prettify_config)
|
|
44 |
}
|
|
45 |
|
|
46 |
|
|
47 |
/* grammar */
|
|
48 |
|
|
49 |
def build_grammar(options: Options, progress: Progress = No_Progress)
|
|
50 |
{
|
|
51 |
val logic = Grammar.default_logic
|
65210
|
52 |
val keywords = Build.session_base(options, logic).syntax.keywords
|
65138
|
53 |
|
|
54 |
val output_path = extension_dir + Path.explode(Grammar.default_output(logic))
|
|
55 |
progress.echo(output_path.implode)
|
|
56 |
File.write_backup(output_path, Grammar.generate(keywords))
|
|
57 |
}
|
|
58 |
|
|
59 |
|
|
60 |
/* extension */
|
|
61 |
|
|
62 |
def build_extension(progress: Progress = No_Progress, publish: Boolean = false)
|
|
63 |
{
|
|
64 |
val output_path = extension_dir + Path.explode("out")
|
|
65 |
progress.echo(output_path.implode)
|
|
66 |
|
65164
|
67 |
progress.bash(
|
|
68 |
"npm install && npm update --dev && vsce " + (if (publish) "publish" else "package"),
|
|
69 |
cwd = extension_dir.file, echo = true).check
|
65138
|
70 |
}
|
|
71 |
|
|
72 |
|
|
73 |
/* Isabelle tool wrapper */
|
|
74 |
|
|
75 |
val isabelle_tool =
|
|
76 |
Isabelle_Tool("build_vscode", "build Isabelle/VSCode extension module", args =>
|
|
77 |
{
|
|
78 |
var publish = false
|
|
79 |
|
|
80 |
val getopts = Getopts("""
|
|
81 |
Usage: isabelle build_vscode
|
|
82 |
|
|
83 |
Options are:
|
|
84 |
-P publish the package
|
|
85 |
|
|
86 |
Build Isabelle/VSCode extension module in directory
|
|
87 |
""" + extension_dir.expand + """
|
|
88 |
|
|
89 |
This requires npm and the vsce build and publishing tool, see also
|
|
90 |
https://code.visualstudio.com/docs/tools/vscecli
|
|
91 |
""",
|
|
92 |
"P" -> (_ => publish = true))
|
|
93 |
|
|
94 |
val more_args = getopts(args)
|
|
95 |
if (more_args.nonEmpty) getopts.usage()
|
|
96 |
|
|
97 |
val options = Options.init()
|
|
98 |
val progress = new Console_Progress()
|
|
99 |
|
|
100 |
build_symbols(progress)
|
|
101 |
build_grammar(options, progress)
|
|
102 |
build_extension(progress, publish = publish)
|
|
103 |
}, admin = true)
|
|
104 |
}
|