author | wenzelm |
Tue, 22 Mar 2022 12:48:27 +0100 | |
changeset 75292 | 4ce0a4d90dfa |
parent 75285 | src/Tools/VSCode/src/vscode_setup.scala@2b64d5657592 |
child 75293 | c5da08c5b01b |
permissions | -rw-r--r-- |
75292 | 1 |
/* Title: Tools/VSCode/src/vscode_main.scala |
75083 | 2 |
Author: Makarius |
3 |
||
75292 | 4 |
Main application entry point for Isabelle/VSCode. |
75083 | 5 |
*/ |
6 |
||
7 |
package isabelle.vscode |
|
8 |
||
9 |
||
10 |
import isabelle._ |
|
11 |
||
12 |
||
75292 | 13 |
object VSCode_Main |
75083 | 14 |
{ |
75292 | 15 |
/* command-line interface */ |
16 |
||
17 |
private def platform_path(s: String): String = File.platform_path(Path.explode(s)) |
|
18 |
||
19 |
def run_cli(args: List[String], |
|
20 |
environment: Iterable[(String, String)] = Nil, |
|
21 |
background: Boolean = false, |
|
22 |
progress: Progress = new Progress): Process_Result = |
|
23 |
{ |
|
24 |
val env = new java.util.HashMap(Isabelle_System.settings()) |
|
25 |
for ((a, b) <- environment) env.put(a, b) |
|
26 |
env.put("ISABELLE_VSCODIUM_APP", platform_path("$ISABELLE_VSCODIUM_RESOURCES/vscodium")) |
|
27 |
env.put("ELECTRON_RUN_AS_NODE", "1") |
|
75083 | 28 |
|
75292 | 29 |
val electron = Isabelle_System.getenv("ISABELLE_VSCODIUM_ELECTRON") |
30 |
if (electron.isEmpty) { |
|
31 |
error("""Undefined $ISABELLE_VSCODIUM_ELECTRON: missing "vscodium" component""") |
|
32 |
} |
|
33 |
val args0 = |
|
34 |
List(platform_path("$ISABELLE_VSCODIUM_RESOURCES/vscodium/out/cli.js"), |
|
35 |
"--ms-enable-electron-run-as-node", "--locale", "en-US", |
|
36 |
"--user-data-dir", platform_path("$ISABELLE_VSCODE_SETTINGS/user-data"), |
|
37 |
"--extensions-dir", platform_path("$ISABELLE_VSCODE_SETTINGS/extensions")) |
|
38 |
val script = |
|
39 |
Bash.strings(electron :: args0 ::: args) + |
|
40 |
(if (background) " > /dev/null 2> /dev/null &" else "") |
|
41 |
||
42 |
Isabelle_System.bash(script, env = env) |
|
43 |
} |
|
44 |
||
45 |
||
46 |
/* settings */ |
|
47 |
||
48 |
def settings_path: Path = |
|
75257
d1e5f9dbf885
clarified startup of "isabelle vscode": vscodium component is required, with patches for Isabelle/VSCode;
wenzelm
parents:
75252
diff
changeset
|
49 |
Path.explode("$ISABELLE_VSCODE_SETTINGS/user-data/User/settings.json") |
75083 | 50 |
|
75292 | 51 |
private val default_settings = """ { |
75166 | 52 |
"editor.fontFamily": "'Isabelle DejaVu Sans Mono'", |
53 |
"editor.fontSize": 18, |
|
54 |
"editor.lineNumbers": "off", |
|
55 |
"editor.renderIndentGuides": false, |
|
56 |
"editor.rulers": [80, 100], |
|
75171 | 57 |
"editor.unicodeHighlight.ambiguousCharacters": false, |
75166 | 58 |
"extensions.autoCheckUpdates": false, |
75167 | 59 |
"extensions.autoUpdate": false, |
75178 | 60 |
"terminal.integrated.fontFamily": "monospace", |
75167 | 61 |
"update.mode": "none" |
75166 | 62 |
} |
63 |
""" |
|
64 |
||
75292 | 65 |
def init_settings(): Unit = |
75083 | 66 |
{ |
75292 | 67 |
if (!settings_path.is_file) { |
68 |
Isabelle_System.make_directory(settings_path.dir) |
|
69 |
File.write(settings_path, default_settings) |
|
75163 | 70 |
} |
75083 | 71 |
} |
72 |
||
73 |
||
74 |
/* Isabelle tool wrapper */ |
|
75 |
||
76 |
val isabelle_tool = |
|
75292 | 77 |
Isabelle_Tool("vscode", "Isabelle/VSCode interface wrapper", Scala_Project.here, args => |
75083 | 78 |
{ |
79 |
val getopts = Getopts(""" |
|
75292 | 80 |
Usage: isabelle vscode -- VSCODE_OPTIONS |
75083 | 81 |
|
75292 | 82 |
Start Isabelle/VSCode application, with automatic configuration of |
83 |
user settings. |
|
75163 | 84 |
|
85 |
The following initial settings are provided for a fresh installation: |
|
75292 | 86 |
""" + default_settings) |
75083 | 87 |
|
88 |
val more_args = getopts(args) |
|
75292 | 89 |
|
90 |
val progress = new Console_Progress() |
|
75083 | 91 |
|
75292 | 92 |
init_settings() |
93 |
run_cli(List("--version")).check |
|
94 |
run_cli(more_args, background = true, progress = progress).check |
|
75083 | 95 |
}) |
96 |
} |