30 var text_length = Text.Length.encoding(default_text_length) |
30 var text_length = Text.Length.encoding(default_text_length) |
31 var dirs: List[Path] = Nil |
31 var dirs: List[Path] = Nil |
32 var logic = default_logic |
32 var logic = default_logic |
33 var modes: List[String] = Nil |
33 var modes: List[String] = Nil |
34 var options = Options.init() |
34 var options = Options.init() |
|
35 var system_mode = false |
35 |
36 |
36 def text_length_choice: String = |
37 def text_length_choice: String = |
37 commas(Text.Length.encodings.map( |
38 commas(Text.Length.encodings.map( |
38 { case (a, _) => if (a == default_text_length) a + " (default)" else a })) |
39 { case (a, _) => if (a == default_text_length) a + " (default)" else a })) |
39 |
40 |
45 -T LENGTH text length encoding: """ + text_length_choice + """ |
46 -T LENGTH text length encoding: """ + text_length_choice + """ |
46 -d DIR include session directory |
47 -d DIR include session directory |
47 -l NAME logic session name (default ISABELLE_LOGIC=""" + quote(logic) + """) |
48 -l NAME logic session name (default ISABELLE_LOGIC=""" + quote(logic) + """) |
48 -m MODE add print mode for output |
49 -m MODE add print mode for output |
49 -o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
50 -o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
|
51 -s system build mode for session image |
50 |
52 |
51 Run the VSCode Language Server protocol (JSON RPC) over stdin/stdout. |
53 Run the VSCode Language Server protocol (JSON RPC) over stdin/stdout. |
52 """, |
54 """, |
53 "L:" -> (arg => log_file = Some(Path.explode(arg))), |
55 "L:" -> (arg => log_file = Some(Path.explode(arg))), |
54 "T:" -> (arg => Text.Length.encoding(arg)), |
56 "T:" -> (arg => Text.Length.encoding(arg)), |
55 "d:" -> (arg => dirs = dirs ::: List(Path.explode(arg))), |
57 "d:" -> (arg => dirs = dirs ::: List(Path.explode(arg))), |
56 "l:" -> (arg => logic = arg), |
58 "l:" -> (arg => logic = arg), |
57 "m:" -> (arg => modes = arg :: modes), |
59 "m:" -> (arg => modes = arg :: modes), |
58 "o:" -> (arg => options = options + arg)) |
60 "o:" -> (arg => options = options + arg), |
|
61 "s" -> (_ => system_mode = true)) |
59 |
62 |
60 val more_args = getopts(args) |
63 val more_args = getopts(args) |
61 if (more_args.nonEmpty) getopts.usage() |
64 if (more_args.nonEmpty) getopts.usage() |
62 |
65 |
63 if (!Build.build(options = options, build_heap = true, no_build = true, |
|
64 dirs = dirs, sessions = List(logic)).ok) |
|
65 error("Missing logic image " + quote(logic)) |
|
66 |
|
67 val log = Logger.make(log_file) |
66 val log = Logger.make(log_file) |
68 val channel = new Channel(System.in, System.out, log) |
67 val channel = new Channel(System.in, System.out, log) |
69 val server = new Server(channel, options, text_length, logic, dirs, modes, log) |
68 val server = new Server(channel, options, text_length, logic, dirs, modes, system_mode, log) |
70 |
69 |
71 // prevent spurious garbage on the main protocol channel |
70 // prevent spurious garbage on the main protocol channel |
72 val orig_out = System.out |
71 val orig_out = System.out |
73 try { |
72 try { |
74 System.setOut(new PrintStream(new OutputStream { def write(n: Int) {} })) |
73 System.setOut(new PrintStream(new OutputStream { def write(n: Int) {} })) |
90 options: Options, |
89 options: Options, |
91 text_length: Text.Length = Text.Length.encoding(Server.default_text_length), |
90 text_length: Text.Length = Text.Length.encoding(Server.default_text_length), |
92 session_name: String = Server.default_logic, |
91 session_name: String = Server.default_logic, |
93 session_dirs: List[Path] = Nil, |
92 session_dirs: List[Path] = Nil, |
94 modes: List[String] = Nil, |
93 modes: List[String] = Nil, |
|
94 system_mode: Boolean = false, |
95 log: Logger = No_Logger) |
95 log: Logger = No_Logger) |
96 { |
96 { |
97 /* prover session */ |
97 /* prover session */ |
98 |
98 |
99 private val session_ = Synchronized(None: Option[Session]) |
99 private val session_ = Synchronized(None: Option[Session]) |
178 else channel.error_message(err) |
178 else channel.error_message(err) |
179 } |
179 } |
180 |
180 |
181 val try_session = |
181 val try_session = |
182 try { |
182 try { |
|
183 if (!Build.build(options = options, build_heap = true, no_build = true, |
|
184 system_mode = system_mode, dirs = session_dirs, sessions = List(session_name)).ok) |
|
185 { |
|
186 val start_msg = "Build started for Isabelle/" + session_name + " ..." |
|
187 val fail_msg = "Session build failed -- prover process remains inactive!" |
|
188 |
|
189 val progress = channel.make_progress(verbose = true) |
|
190 progress.echo(start_msg); channel.writeln(start_msg) |
|
191 |
|
192 if (!Build.build(options = options, progress = progress, build_heap = true, |
|
193 system_mode = system_mode, dirs = session_dirs, sessions = List(session_name)).ok) |
|
194 { |
|
195 progress.echo(fail_msg); error(fail_msg) |
|
196 } |
|
197 } |
|
198 |
183 val content = Build.session_content(options, false, session_dirs, session_name) |
199 val content = Build.session_content(options, false, session_dirs, session_name) |
184 val resources = |
200 val resources = |
185 new VSCode_Resources(options, text_length, content.loaded_theories, |
201 new VSCode_Resources(options, text_length, content.loaded_theories, |
186 content.known_theories, content.syntax, log) { |
202 content.known_theories, content.syntax, log) { |
187 override def commit(change: Session.Change): Unit = |
203 override def commit(change: Session.Change): Unit = |