62 |
62 |
63 if (!Build.build(options = options, build_heap = true, no_build = true, |
63 if (!Build.build(options = options, build_heap = true, no_build = true, |
64 dirs = dirs, sessions = List(logic)).ok) |
64 dirs = dirs, sessions = List(logic)).ok) |
65 error("Missing logic image " + quote(logic)) |
65 error("Missing logic image " + quote(logic)) |
66 |
66 |
67 val channel = new Channel(System.in, System.out, log_file) |
67 val log = Logger.make(log_file) |
68 val server = new Server(channel, options, text_length, logic, dirs, modes) |
68 val channel = new Channel(System.in, System.out, log) |
|
69 val server = new Server(channel, options, text_length, logic, dirs, modes, log) |
69 |
70 |
70 // prevent spurious garbage on the main protocol channel |
71 // prevent spurious garbage on the main protocol channel |
71 val orig_out = System.out |
72 val orig_out = System.out |
72 try { |
73 try { |
73 System.setOut(new PrintStream(new OutputStream { def write(n: Int) {} })) |
74 System.setOut(new PrintStream(new OutputStream { def write(n: Int) {} })) |
75 } |
76 } |
76 finally { System.setOut(orig_out) } |
77 finally { System.setOut(orig_out) } |
77 } |
78 } |
78 catch { |
79 catch { |
79 case exn: Throwable => |
80 case exn: Throwable => |
80 val channel = new Channel(System.in, System.out, None) |
81 val channel = new Channel(System.in, System.out, No_Logger) |
81 channel.error_message(Exn.message(exn)) |
82 channel.error_message(Exn.message(exn)) |
82 throw(exn) |
83 throw(exn) |
83 } |
84 } |
84 }) |
85 }) |
85 } |
86 } |
88 channel: Channel, |
89 channel: Channel, |
89 options: Options, |
90 options: Options, |
90 text_length: Text.Length = Text.Length.encoding(Server.default_text_length), |
91 text_length: Text.Length = Text.Length.encoding(Server.default_text_length), |
91 session_name: String = Server.default_logic, |
92 session_name: String = Server.default_logic, |
92 session_dirs: List[Path] = Nil, |
93 session_dirs: List[Path] = Nil, |
93 modes: List[String] = Nil) |
94 modes: List[String] = Nil, |
|
95 log: Logger = No_Logger) |
94 { |
96 { |
95 /* server session */ |
97 /* server session */ |
96 |
98 |
97 private val session_ = Synchronized(None: Option[Session]) |
99 private val session_ = Synchronized(None: Option[Session]) |
98 def session: Session = session_.value getOrElse error("Server inactive") |
100 def session: Session = session_.value getOrElse error("Server inactive") |
302 update_document(uri, text) |
304 update_document(uri, text) |
303 case Protocol.DidChangeTextDocument(uri, version, List(Protocol.TextDocumentContent(text))) => |
305 case Protocol.DidChangeTextDocument(uri, version, List(Protocol.TextDocumentContent(text))) => |
304 update_document(uri, text) |
306 update_document(uri, text) |
305 case Protocol.DidCloseTextDocument(uri) => |
307 case Protocol.DidCloseTextDocument(uri) => |
306 close_document(uri) |
308 close_document(uri) |
307 case Protocol.DidSaveTextDocument(uri) => channel.log("SAVE " + uri) |
309 case Protocol.DidSaveTextDocument(uri) => log("SAVE " + uri) |
308 case Protocol.Hover(id, node_pos) => hover(id, node_pos) |
310 case Protocol.Hover(id, node_pos) => hover(id, node_pos) |
309 case Protocol.GotoDefinition(id, node_pos) => goto_definition(id, node_pos) |
311 case Protocol.GotoDefinition(id, node_pos) => goto_definition(id, node_pos) |
310 case _ => channel.log("### IGNORED") |
312 case _ => log("### IGNORED") |
311 } |
313 } |
312 } |
314 } |
313 catch { case exn: Throwable => channel.log_error_message(Exn.message(exn)) } |
315 catch { case exn: Throwable => channel.log_error_message(Exn.message(exn)) } |
314 } |
316 } |
315 |
317 |