author | Fabian Huch <huch@in.tum.de> |
Wed, 02 Oct 2024 10:39:32 +0200 | |
changeset 81084 | 96eb20106a34 |
parent 81074 | c87d2fa560dd |
child 81085 | fe69241e8786 |
permissions | -rw-r--r-- |
77566
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents:
77208
diff
changeset
|
1 |
/* Title: Tools/VSCode/src/component_vscode_extension.scala |
65138 | 2 |
Author: Makarius |
3 |
||
75333
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
4 |
Build the Isabelle/VSCode extension as component. |
65138 | 5 |
*/ |
6 |
||
7 |
package isabelle.vscode |
|
8 |
||
9 |
||
10 |
import isabelle._ |
|
11 |
||
12 |
||
77566
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents:
77208
diff
changeset
|
13 |
object Component_VSCode { |
75289
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
14 |
/* build grammar */ |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
15 |
|
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
16 |
def default_logic: String = Isabelle_System.getenv("ISABELLE_LOGIC") |
65138 | 17 |
|
75290
c9ee3028c125
clean build from explicit MANIFEST: avoid accidental garbage in vsix package;
wenzelm
parents:
75289
diff
changeset
|
18 |
def build_grammar(options: Options, build_dir: Path, |
75289
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
19 |
logic: String = default_logic, |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
20 |
dirs: List[Path] = Nil, |
75393 | 21 |
progress: Progress = new Progress |
22 |
): Unit = { |
|
75289
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
23 |
val keywords = |
76656 | 24 |
Sessions.background(options, logic, dirs = dirs).check_errors.base.overall_syntax.keywords |
75289
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
25 |
|
75290
c9ee3028c125
clean build from explicit MANIFEST: avoid accidental garbage in vsix package;
wenzelm
parents:
75289
diff
changeset
|
26 |
val output_path = build_dir + Path.explode("isabelle-grammar.json") |
76883 | 27 |
progress.echo(File.standard_path(output_path)) |
75289
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
28 |
|
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
29 |
val (minor_keywords, operators) = |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
30 |
keywords.minor.iterator.toList.partition(Symbol.is_ascii_identifier) |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
31 |
|
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
32 |
def major_keywords(pred: String => Boolean): List[String] = |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
33 |
(for { |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
34 |
k <- keywords.major.iterator |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
35 |
kind <- keywords.kinds.get(k) |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
36 |
if pred(kind) |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
37 |
} yield k).toList |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
38 |
|
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
39 |
val keywords1 = |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
40 |
major_keywords(k => k != Keyword.THY_END && k != Keyword.PRF_ASM && k != Keyword.PRF_ASM_GOAL) |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
41 |
val keywords2 = minor_keywords ::: major_keywords(Set(Keyword.THY_END)) |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
42 |
val keywords3 = major_keywords(Set(Keyword.PRF_ASM, Keyword.PRF_ASM_GOAL)) |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
43 |
|
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
44 |
def grouped_names(as: List[String]): String = |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
45 |
JSON.Format("\\b(" + as.sorted.map(Library.escape_regex).mkString("|") + ")\\b") |
65138 | 46 |
|
75289
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
47 |
File.write_backup(output_path, """{ |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
48 |
"name": "Isabelle", |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
49 |
"scopeName": "source.isabelle", |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
50 |
"fileTypes": ["thy"], |
79717 | 51 |
"uuid": """ + JSON.Format(UUID.random_string()) + """, |
75289
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
52 |
"repository": { |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
53 |
"comment": { |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
54 |
"patterns": [ |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
55 |
{ |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
56 |
"name": "comment.block.isabelle", |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
57 |
"begin": "\\(\\*", |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
58 |
"patterns": [{ "include": "#comment" }], |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
59 |
"end": "\\*\\)" |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
60 |
} |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
61 |
] |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
62 |
}, |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
63 |
"cartouche": { |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
64 |
"patterns": [ |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
65 |
{ |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
66 |
"name": "string.quoted.other.multiline.isabelle", |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
67 |
"begin": "(?:\\\\<open>|‹)", |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
68 |
"patterns": [{ "include": "#cartouche" }], |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
69 |
"end": "(?:\\\\<close>|›)" |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
70 |
} |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
71 |
] |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
72 |
} |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
73 |
}, |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
74 |
"patterns": [ |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
75 |
{ |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
76 |
"include": "#comment" |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
77 |
}, |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
78 |
{ |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
79 |
"include": "#cartouche" |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
80 |
}, |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
81 |
{ |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
82 |
"name": "keyword.control.isabelle", |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
83 |
"match": """ + grouped_names(keywords1) + """ |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
84 |
}, |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
85 |
{ |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
86 |
"name": "keyword.other.unit.isabelle", |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
87 |
"match": """ + grouped_names(keywords2) + """ |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
88 |
}, |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
89 |
{ |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
90 |
"name": "keyword.operator.isabelle", |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
91 |
"match": """ + grouped_names(operators) + """ |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
92 |
}, |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
93 |
{ |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
94 |
"name": "entity.name.type.isabelle", |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
95 |
"match": """ + grouped_names(keywords3) + """ |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
96 |
}, |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
97 |
{ |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
98 |
"name": "constant.numeric.isabelle", |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
99 |
"match": "\\b\\d*\\.?\\d+\\b" |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
100 |
}, |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
101 |
{ |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
102 |
"name": "string.quoted.double.isabelle", |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
103 |
"begin": "\"", |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
104 |
"patterns": [ |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
105 |
{ |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
106 |
"name": "constant.character.escape.isabelle", |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
107 |
"match": """ + JSON.Format("""\\[\"]|\\\d\d\d""") + """ |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
108 |
} |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
109 |
], |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
110 |
"end": "\"" |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
111 |
}, |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
112 |
{ |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
113 |
"name": "string.quoted.backtick.isabelle", |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
114 |
"begin": "`", |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
115 |
"patterns": [ |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
116 |
{ |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
117 |
"name": "constant.character.escape.isabelle", |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
118 |
"match": """ + JSON.Format("""\\[\`]|\\\d\d\d""") + """ |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
119 |
} |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
120 |
], |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
121 |
"end": "`" |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
122 |
}, |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
123 |
{ |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
124 |
"name": "string.quoted.verbatim.isabelle", |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
125 |
"begin": """ + JSON.Format("""\{\*""") + """, |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
126 |
"patterns": [ |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
127 |
{ "match": """ + JSON.Format("""[^*]+|\*(?!\})""") + """ } |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
128 |
], |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
129 |
"end": """ + JSON.Format("""\*\}""") + """ |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
130 |
} |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
131 |
] |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
132 |
} |
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
133 |
""") |
65138 | 134 |
} |
81053
9cedc1fbed0f
vscode: added relevant isabelle options to vscode settings;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81050
diff
changeset
|
135 |
|
9cedc1fbed0f
vscode: added relevant isabelle options to vscode settings;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81050
diff
changeset
|
136 |
|
9cedc1fbed0f
vscode: added relevant isabelle options to vscode settings;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81050
diff
changeset
|
137 |
private def options_json(options: Options): String = { |
81084 | 138 |
val relevant_options = |
139 |
Set( |
|
140 |
"editor_output_state", |
|
141 |
"auto_time_start", |
|
142 |
"auto_time_limit", |
|
143 |
"auto_nitpick", |
|
144 |
"auto_sledgehammer", |
|
145 |
"auto_methods", |
|
146 |
"auto_quickcheck", |
|
147 |
"auto_solve_direct", |
|
148 |
"sledgehammer_provers", |
|
149 |
"sledgehammer_timeout") |
|
150 |
||
151 |
(for { |
|
152 |
opt <- options.iterator |
|
153 |
if opt.for_tag(Options.TAG_VSCODE) || opt.for_content || relevant_options.contains(opt.name) |
|
154 |
} yield { |
|
81053
9cedc1fbed0f
vscode: added relevant isabelle options to vscode settings;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81050
diff
changeset
|
155 |
val (enum_values, enum_descriptions) = opt.typ match { |
9cedc1fbed0f
vscode: added relevant isabelle options to vscode settings;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81050
diff
changeset
|
156 |
case Options.Bool => ( |
9cedc1fbed0f
vscode: added relevant isabelle options to vscode settings;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81050
diff
changeset
|
157 |
Some(List("", "true", "false")), |
81084 | 158 |
Some(List("Use System Preference.", "Enable.", "Disable."))) |
81053
9cedc1fbed0f
vscode: added relevant isabelle options to vscode settings;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81050
diff
changeset
|
159 |
case _ => (None, None) |
9cedc1fbed0f
vscode: added relevant isabelle options to vscode settings;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81050
diff
changeset
|
160 |
} |
9cedc1fbed0f
vscode: added relevant isabelle options to vscode settings;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81050
diff
changeset
|
161 |
|
9cedc1fbed0f
vscode: added relevant isabelle options to vscode settings;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81050
diff
changeset
|
162 |
val default = opt.name match { |
81062
b2df8bf17071
lsp: created distinction for unicode symbols setting between output and edits and clarified output text functions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81057
diff
changeset
|
163 |
case "vscode_unicode_symbols_output" => "true" |
81072
d1beb91bf46d
vscode: changed vscode_unicode_symbols_edits option default to true;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81068
diff
changeset
|
164 |
case "vscode_unicode_symbols_edits" => "true" |
81053
9cedc1fbed0f
vscode: added relevant isabelle options to vscode settings;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81050
diff
changeset
|
165 |
case "vscode_pide_extensions" => "true" |
9cedc1fbed0f
vscode: added relevant isabelle options to vscode settings;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81050
diff
changeset
|
166 |
case "vscode_html_output" => "true" |
9cedc1fbed0f
vscode: added relevant isabelle options to vscode settings;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81050
diff
changeset
|
167 |
case _ => "" |
9cedc1fbed0f
vscode: added relevant isabelle options to vscode settings;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81050
diff
changeset
|
168 |
} |
9cedc1fbed0f
vscode: added relevant isabelle options to vscode settings;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81050
diff
changeset
|
169 |
|
81084 | 170 |
quote("isabelle.options." + opt.name) + ": " + |
171 |
JSON.Format( |
|
172 |
JSON.Object( |
|
173 |
"type" -> "string", |
|
174 |
"default" -> default, |
|
175 |
"description" -> opt.description) ++ |
|
176 |
JSON.optional("enum" -> enum_values) ++ |
|
177 |
JSON.optional("enumDescriptions" -> enum_descriptions)) + "," |
|
81053
9cedc1fbed0f
vscode: added relevant isabelle options to vscode settings;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81050
diff
changeset
|
178 |
}).mkString |
9cedc1fbed0f
vscode: added relevant isabelle options to vscode settings;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81050
diff
changeset
|
179 |
} |
65138 | 180 |
|
181 |
||
75312
e641ac92b489
more formal extension_manifest, with shasum for sources;
wenzelm
parents:
75306
diff
changeset
|
182 |
/* build extension */ |
75290
c9ee3028c125
clean build from explicit MANIFEST: avoid accidental garbage in vsix package;
wenzelm
parents:
75289
diff
changeset
|
183 |
|
c9ee3028c125
clean build from explicit MANIFEST: avoid accidental garbage in vsix package;
wenzelm
parents:
75289
diff
changeset
|
184 |
def build_extension(options: Options, |
75333
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
185 |
target_dir: Path = Path.current, |
75290
c9ee3028c125
clean build from explicit MANIFEST: avoid accidental garbage in vsix package;
wenzelm
parents:
75289
diff
changeset
|
186 |
logic: String = default_logic, |
c9ee3028c125
clean build from explicit MANIFEST: avoid accidental garbage in vsix package;
wenzelm
parents:
75289
diff
changeset
|
187 |
dirs: List[Path] = Nil, |
75393 | 188 |
progress: Progress = new Progress |
189 |
): Unit = { |
|
75259 | 190 |
Isabelle_System.require_command("node") |
191 |
Isabelle_System.require_command("yarn") |
|
192 |
Isabelle_System.require_command("vsce") |
|
193 |
||
75333
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
194 |
|
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
195 |
/* component */ |
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
196 |
|
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
197 |
val component_name = "vscode_extension-" + Date.Format.alt_date(Date.now()) |
76518 | 198 |
val component_dir = |
76547 | 199 |
Components.Directory(target_dir + Path.basic(component_name)).create(progress = progress) |
75333
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
200 |
|
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
201 |
|
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
202 |
/* build */ |
65138 | 203 |
|
75333
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
204 |
val vsix_name = |
75394 | 205 |
Isabelle_System.with_tmp_dir("build") { build_dir => |
75348 | 206 |
val manifest_text = File.read(VSCode_Main.extension_dir + VSCode_Main.MANIFEST) |
207 |
val manifest_entries = split_lines(manifest_text).filter(_.nonEmpty) |
|
77208 | 208 |
for (name <- manifest_entries) { |
209 |
val path = Path.explode(name) |
|
75348 | 210 |
Isabelle_System.copy_file(VSCode_Main.extension_dir + path, |
211 |
Isabelle_System.make_directory(build_dir + path.dir)) |
|
212 |
} |
|
81050
2d3a0728cf1c
vscode: added all fonts to extension;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81045
diff
changeset
|
213 |
|
81084 | 214 |
val fonts_dir = Isabelle_System.make_directory(build_dir + Path.basic("fonts")) |
215 |
for (entry <- Isabelle_Fonts.fonts()) { Isabelle_System.copy_file(entry.path, fonts_dir) } |
|
81050
2d3a0728cf1c
vscode: added all fonts to extension;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81045
diff
changeset
|
216 |
val manifest_text2 = |
2d3a0728cf1c
vscode: added all fonts to extension;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81045
diff
changeset
|
217 |
manifest_text + cat_lines(Isabelle_Fonts.fonts().map(e => "fonts/" + e.path.file_name)) |
2d3a0728cf1c
vscode: added all fonts to extension;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81045
diff
changeset
|
218 |
val manifest_entries2 = split_lines(manifest_text2).filter(_.nonEmpty) |
2d3a0728cf1c
vscode: added all fonts to extension;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81045
diff
changeset
|
219 |
|
2d3a0728cf1c
vscode: added all fonts to extension;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81045
diff
changeset
|
220 |
val manifest_shasum: SHA1.Shasum = { |
2d3a0728cf1c
vscode: added all fonts to extension;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81045
diff
changeset
|
221 |
val a = SHA1.shasum_meta_info(SHA1.digest(manifest_text2)) |
2d3a0728cf1c
vscode: added all fonts to extension;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81045
diff
changeset
|
222 |
val bs = |
2d3a0728cf1c
vscode: added all fonts to extension;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81045
diff
changeset
|
223 |
for (name <- manifest_entries2) |
2d3a0728cf1c
vscode: added all fonts to extension;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81045
diff
changeset
|
224 |
yield SHA1.shasum(SHA1.digest(build_dir + Path.explode(name)), name) |
2d3a0728cf1c
vscode: added all fonts to extension;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81045
diff
changeset
|
225 |
SHA1.flat_shasum(a :: bs) |
2d3a0728cf1c
vscode: added all fonts to extension;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81045
diff
changeset
|
226 |
} |
77208 | 227 |
File.write(build_dir + VSCode_Main.MANIFEST.shasum, manifest_shasum.toString) |
75333
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
228 |
|
81053
9cedc1fbed0f
vscode: added relevant isabelle options to vscode settings;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81050
diff
changeset
|
229 |
|
9cedc1fbed0f
vscode: added relevant isabelle options to vscode settings;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81050
diff
changeset
|
230 |
/* options */ |
9cedc1fbed0f
vscode: added relevant isabelle options to vscode settings;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81050
diff
changeset
|
231 |
|
9cedc1fbed0f
vscode: added relevant isabelle options to vscode settings;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81050
diff
changeset
|
232 |
val opt_json = options_json(options) |
9cedc1fbed0f
vscode: added relevant isabelle options to vscode settings;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81050
diff
changeset
|
233 |
val package_path = build_dir + Path.basic("package.json") |
81074
c87d2fa560dd
vscode: changed how options are inserted into package.json so that one can still call `npm install` without errors;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81072
diff
changeset
|
234 |
val package_body = File.read(package_path).replace("\"ISABELLE_OPTIONS\": {},", opt_json) |
81053
9cedc1fbed0f
vscode: added relevant isabelle options to vscode settings;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81050
diff
changeset
|
235 |
File.write(package_path, package_body) |
9cedc1fbed0f
vscode: added relevant isabelle options to vscode settings;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81050
diff
changeset
|
236 |
|
9cedc1fbed0f
vscode: added relevant isabelle options to vscode settings;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81050
diff
changeset
|
237 |
|
75333
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
238 |
build_grammar(options, build_dir, logic = logic, dirs = dirs, progress = progress) |
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
239 |
|
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
240 |
val result = |
80224
db92e0b6a11a
clarified signature: prefer symbolic isabelle.Path over physical java.io.File;
wenzelm
parents:
79717
diff
changeset
|
241 |
progress.bash("yarn && vsce package", cwd = build_dir, echo = true).check |
75333
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
242 |
val Pattern = """.*Packaged:.*(isabelle-.*\.vsix).*""".r |
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
243 |
val vsix_name = |
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
244 |
result.out_lines.collectFirst({ case Pattern(name) => name }) |
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
245 |
.getOrElse(error("Failed to guess resulting .vsix file name")) |
75143 | 246 |
|
76518 | 247 |
Isabelle_System.copy_file(build_dir + Path.basic(vsix_name), component_dir.path) |
75333
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
248 |
vsix_name |
75394 | 249 |
} |
75333
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
250 |
|
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
251 |
|
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
252 |
/* settings */ |
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
253 |
|
76548 | 254 |
component_dir.write_settings(""" |
75333
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
255 |
ISABELLE_VSCODE_VSIX="$COMPONENT/""" + vsix_name + "\"\n") |
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
256 |
|
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
257 |
|
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
258 |
/* README */ |
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
259 |
|
76518 | 260 |
File.write(component_dir.README, |
75333
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
261 |
"""This the Isabelle/VSCode extension as VSIX package |
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
262 |
|
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
263 |
It has been produced from the sources in $ISABELLE_HOME/src/Tools/extension/. |
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
264 |
|
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
265 |
|
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
266 |
Makarius |
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
267 |
""" + Date.Format.date(Date.now()) + "\n") |
65138 | 268 |
} |
269 |
||
270 |
||
271 |
/* Isabelle tool wrapper */ |
|
272 |
||
273 |
val isabelle_tool = |
|
77566
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents:
77208
diff
changeset
|
274 |
Isabelle_Tool("component_vscode_extension", "build Isabelle/VSCode extension module", |
75393 | 275 |
Scala_Project.here, |
75394 | 276 |
{ args => |
277 |
var target_dir = Path.current |
|
278 |
var dirs: List[Path] = Nil |
|
279 |
var logic = default_logic |
|
65138 | 280 |
|
75394 | 281 |
val getopts = Getopts(""" |
77566
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents:
77208
diff
changeset
|
282 |
Usage: isabelle component_vscode_extension |
65138 | 283 |
|
284 |
Options are: |
|
75333
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
285 |
-D DIR target directory (default ".") |
75290
c9ee3028c125
clean build from explicit MANIFEST: avoid accidental garbage in vsix package;
wenzelm
parents:
75289
diff
changeset
|
286 |
-d DIR include session directory |
75289
9c72957e5c4a
incorporate build_grammar into build_vscode_extension;
wenzelm
parents:
75281
diff
changeset
|
287 |
-l NAME logic session name (default ISABELLE_LOGIC=""" + quote(default_logic) + """) |
65138 | 288 |
|
75333
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
289 |
Build the Isabelle/VSCode extension as component, for inclusion into the |
8f0d94fb8551
provide vscode_extension via component, thus users don't need Node.js development tools;
wenzelm
parents:
75332
diff
changeset
|
290 |
local VSCodium configuration. |
65138 | 291 |
""", |
75394 | 292 |
"D:" -> (arg => target_dir = Path.explode(arg)), |
293 |
"d:" -> (arg => dirs = dirs ::: List(Path.explode(arg))), |
|
294 |
"l:" -> (arg => logic = arg)) |
|
65138 | 295 |
|
75394 | 296 |
val more_args = getopts(args) |
297 |
if (more_args.nonEmpty) getopts.usage() |
|
65138 | 298 |
|
75394 | 299 |
val options = Options.init() |
300 |
val progress = new Console_Progress() |
|
65138 | 301 |
|
75394 | 302 |
build_extension(options, target_dir = target_dir, logic = logic, dirs = dirs, |
303 |
progress = progress) |
|
304 |
}) |
|
65138 | 305 |
} |