author | wenzelm |
Thu, 25 May 2017 18:07:29 +0200 | |
changeset 65922 | d2f19f05c0e9 |
parent 65229 | cc96b8c3b8cb |
child 65924 | 9140c9cce351 |
permissions | -rw-r--r-- |
64605 | 1 |
/* Title: Tools/VSCode/src/protocol.scala |
2 |
Author: Makarius |
|
3 |
||
65165 | 4 |
Message formats for Language Server Protocol 3.0, see |
64605 | 5 |
https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md |
6 |
*/ |
|
7 |
||
8 |
package isabelle.vscode |
|
9 |
||
10 |
||
11 |
import isabelle._ |
|
12 |
||
64777
ca09695eb43c
clarified Document.Node.Name (again): canonical platform file;
wenzelm
parents:
64767
diff
changeset
|
13 |
import java.io.{File => JFile} |
ca09695eb43c
clarified Document.Node.Name (again): canonical platform file;
wenzelm
parents:
64767
diff
changeset
|
14 |
|
ca09695eb43c
clarified Document.Node.Name (again): canonical platform file;
wenzelm
parents:
64767
diff
changeset
|
15 |
|
64605 | 16 |
object Protocol |
17 |
{ |
|
18 |
/* abstract message */ |
|
19 |
||
20 |
object Message |
|
21 |
{ |
|
22 |
val empty: Map[String, JSON.T] = Map("jsonrpc" -> "2.0") |
|
65922 | 23 |
|
24 |
def log(prefix: String, json: JSON.T, logger: Logger, verbose: Boolean) |
|
25 |
{ |
|
26 |
val header: Map[String, Any] = |
|
27 |
json match { |
|
28 |
case obj: Map[Any, Any] => |
|
29 |
(obj.get("method"), obj.get("id")) match { |
|
30 |
case (Some(method), Some(id)) => Map("method" -> method, "id" -> id) |
|
31 |
case (Some(method), None) => Map("method" -> method) |
|
32 |
case _ => Map.empty |
|
33 |
} |
|
34 |
case _ => Map.empty |
|
35 |
} |
|
36 |
if (verbose || header.isEmpty) logger(prefix + "\n" + JSON.Format(json)) |
|
37 |
else logger(prefix + " " + JSON.Format(header)) |
|
38 |
} |
|
64605 | 39 |
} |
40 |
||
41 |
||
42 |
/* notification */ |
|
43 |
||
44 |
object Notification |
|
45 |
{ |
|
46 |
def apply(method: String, params: JSON.T): JSON.T = |
|
47 |
Message.empty + ("method" -> method) + ("params" -> params) |
|
48 |
||
49 |
def unapply(json: JSON.T): Option[(String, Option[JSON.T])] = |
|
50 |
for { |
|
51 |
method <- JSON.string(json, "method") |
|
52 |
params = JSON.value(json, "params") |
|
53 |
} yield (method, params) |
|
54 |
} |
|
55 |
||
56 |
class Notification0(name: String) |
|
57 |
{ |
|
58 |
def unapply(json: JSON.T): Option[Unit] = |
|
59 |
json match { |
|
60 |
case Notification(method, _) if method == name => Some(()) |
|
61 |
case _ => None |
|
62 |
} |
|
63 |
} |
|
64 |
||
65 |
||
66 |
/* request message */ |
|
67 |
||
68 |
sealed case class Id(id: Any) |
|
69 |
{ |
|
70 |
require( |
|
71 |
id.isInstanceOf[Int] || |
|
72 |
id.isInstanceOf[Long] || |
|
73 |
id.isInstanceOf[Double] || |
|
74 |
id.isInstanceOf[String]) |
|
75 |
||
76 |
override def toString: String = id.toString |
|
77 |
} |
|
78 |
||
79 |
object RequestMessage |
|
80 |
{ |
|
81 |
def apply(id: Id, method: String, params: JSON.T): JSON.T = |
|
82 |
Message.empty + ("id" -> id.id) + ("method" -> method) + ("params" -> params) |
|
83 |
||
84 |
def unapply(json: JSON.T): Option[(Id, String, Option[JSON.T])] = |
|
85 |
for { |
|
86 |
id <- JSON.long(json, "id") orElse JSON.double(json, "id") orElse JSON.string(json, "id") |
|
87 |
method <- JSON.string(json, "method") |
|
88 |
params = JSON.value(json, "params") |
|
89 |
} yield (Id(id), method, params) |
|
90 |
} |
|
91 |
||
92 |
class Request0(name: String) |
|
93 |
{ |
|
94 |
def unapply(json: JSON.T): Option[Id] = |
|
95 |
json match { |
|
96 |
case RequestMessage(id, method, _) if method == name => Some(id) |
|
97 |
case _ => None |
|
98 |
} |
|
99 |
} |
|
100 |
||
64648
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
101 |
class RequestTextDocumentPosition(name: String) |
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
102 |
{ |
64651 | 103 |
def unapply(json: JSON.T): Option[(Id, Line.Node_Position)] = |
64648
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
104 |
json match { |
64651 | 105 |
case RequestMessage(id, method, Some(TextDocumentPosition(node_pos))) if method == name => |
106 |
Some((id, node_pos)) |
|
64648
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
107 |
case _ => None |
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
108 |
} |
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
109 |
} |
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
110 |
|
64605 | 111 |
|
112 |
/* response message */ |
|
113 |
||
114 |
object ResponseMessage |
|
115 |
{ |
|
116 |
def apply(id: Id, result: Option[JSON.T] = None, error: Option[ResponseError] = None): JSON.T = |
|
117 |
Message.empty + ("id" -> id.id) ++ |
|
64878 | 118 |
JSON.optional("result" -> result) ++ |
119 |
JSON.optional("error" -> error.map(_.json)) |
|
64605 | 120 |
|
121 |
def strict(id: Id, result: Option[JSON.T] = None, error: String = ""): JSON.T = |
|
122 |
if (error == "") apply(id, result = result) |
|
123 |
else apply(id, error = Some(ResponseError(code = ErrorCodes.serverErrorEnd, message = error))) |
|
124 |
} |
|
125 |
||
126 |
sealed case class ResponseError(code: Int, message: String, data: Option[JSON.T] = None) |
|
127 |
{ |
|
128 |
def json: JSON.T = |
|
64878 | 129 |
Map("code" -> code, "message" -> message) ++ JSON.optional("data" -> data) |
64605 | 130 |
} |
131 |
||
132 |
object ErrorCodes |
|
133 |
{ |
|
134 |
val ParseError = -32700 |
|
135 |
val InvalidRequest = -32600 |
|
136 |
val MethodNotFound = -32601 |
|
137 |
val InvalidParams = -32602 |
|
138 |
val InternalError = -32603 |
|
139 |
val serverErrorStart = -32099 |
|
140 |
val serverErrorEnd = -32000 |
|
141 |
} |
|
142 |
||
143 |
||
144 |
/* init and exit */ |
|
145 |
||
146 |
object Initialize extends Request0("initialize") |
|
147 |
{ |
|
148 |
def reply(id: Id, error: String): JSON.T = |
|
149 |
ResponseMessage.strict(id, Some(Map("capabilities" -> ServerCapabilities.json)), error) |
|
150 |
} |
|
151 |
||
152 |
object ServerCapabilities |
|
153 |
{ |
|
154 |
val json: JSON.T = |
|
64648
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
155 |
Map( |
65160 | 156 |
"textDocumentSync" -> 2, |
64877 | 157 |
"completionProvider" -> Map("resolveProvider" -> false, "triggerCharacters" -> Nil), |
64648
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
158 |
"hoverProvider" -> true, |
64767 | 159 |
"definitionProvider" -> true, |
160 |
"documentHighlightProvider" -> true) |
|
64605 | 161 |
} |
162 |
||
65229 | 163 |
object Initialized extends Notification0("initialized") |
164 |
||
64605 | 165 |
object Shutdown extends Request0("shutdown") |
166 |
{ |
|
167 |
def reply(id: Id, error: String): JSON.T = |
|
168 |
ResponseMessage.strict(id, Some("OK"), error) |
|
169 |
} |
|
170 |
||
171 |
object Exit extends Notification0("exit") |
|
172 |
||
173 |
||
174 |
/* document positions */ |
|
175 |
||
176 |
object Position |
|
177 |
{ |
|
178 |
def apply(pos: Line.Position): JSON.T = |
|
179 |
Map("line" -> pos.line, "character" -> pos.column) |
|
180 |
||
181 |
def unapply(json: JSON.T): Option[Line.Position] = |
|
182 |
for { |
|
183 |
line <- JSON.int(json, "line") |
|
184 |
column <- JSON.int(json, "character") |
|
185 |
} yield Line.Position(line, column) |
|
186 |
} |
|
187 |
||
188 |
object Range |
|
189 |
{ |
|
65173 | 190 |
def compact(range: Line.Range): List[Int] = |
191 |
List(range.start.line, range.start.column, range.stop.line, range.stop.column) |
|
192 |
||
64605 | 193 |
def apply(range: Line.Range): JSON.T = |
194 |
Map("start" -> Position(range.start), "end" -> Position(range.stop)) |
|
195 |
||
196 |
def unapply(json: JSON.T): Option[Line.Range] = |
|
197 |
(JSON.value(json, "start"), JSON.value(json, "end")) match { |
|
198 |
case (Some(Position(start)), Some(Position(stop))) => Some(Line.Range(start, stop)) |
|
199 |
case _ => None |
|
200 |
} |
|
201 |
} |
|
202 |
||
203 |
object Location |
|
204 |
{ |
|
64651 | 205 |
def apply(loc: Line.Node_Range): JSON.T = |
64777
ca09695eb43c
clarified Document.Node.Name (again): canonical platform file;
wenzelm
parents:
64767
diff
changeset
|
206 |
Map("uri" -> Url.print_file_name(loc.name), "range" -> Range(loc.range)) |
64605 | 207 |
|
64651 | 208 |
def unapply(json: JSON.T): Option[Line.Node_Range] = |
64605 | 209 |
for { |
210 |
uri <- JSON.string(json, "uri") |
|
211 |
range_json <- JSON.value(json, "range") |
|
212 |
range <- Range.unapply(range_json) |
|
64777
ca09695eb43c
clarified Document.Node.Name (again): canonical platform file;
wenzelm
parents:
64767
diff
changeset
|
213 |
} yield Line.Node_Range(Url.canonical_file_name(uri), range) |
64605 | 214 |
} |
215 |
||
216 |
object TextDocumentPosition |
|
217 |
{ |
|
64651 | 218 |
def unapply(json: JSON.T): Option[Line.Node_Position] = |
64605 | 219 |
for { |
220 |
doc <- JSON.value(json, "textDocument") |
|
221 |
uri <- JSON.string(doc, "uri") |
|
222 |
pos_json <- JSON.value(json, "position") |
|
223 |
pos <- Position.unapply(pos_json) |
|
64777
ca09695eb43c
clarified Document.Node.Name (again): canonical platform file;
wenzelm
parents:
64767
diff
changeset
|
224 |
} yield Line.Node_Position(Url.canonical_file_name(uri), pos) |
64605 | 225 |
} |
226 |
||
227 |
||
65103 | 228 |
/* marked strings */ |
65093 | 229 |
|
230 |
sealed case class MarkedString(text: String, language: String = "plaintext") |
|
231 |
{ |
|
232 |
def json: JSON.T = Map("language" -> language, "value" -> text) |
|
233 |
} |
|
234 |
||
65103 | 235 |
object MarkedStrings |
236 |
{ |
|
237 |
def json(msgs: List[MarkedString]): Option[JSON.T] = |
|
238 |
msgs match { |
|
239 |
case Nil => None |
|
240 |
case List(msg) => Some(msg.json) |
|
241 |
case _ => Some(msgs.map(_.json)) |
|
242 |
} |
|
243 |
} |
|
244 |
||
65093 | 245 |
|
64605 | 246 |
/* diagnostic messages */ |
247 |
||
248 |
object MessageType |
|
249 |
{ |
|
250 |
val Error = 1 |
|
251 |
val Warning = 2 |
|
252 |
val Info = 3 |
|
253 |
val Log = 4 |
|
254 |
} |
|
255 |
||
256 |
object DisplayMessage |
|
257 |
{ |
|
258 |
def apply(message_type: Int, message: String, show: Boolean = true): JSON.T = |
|
259 |
Notification(if (show) "window/showMessage" else "window/logMessage", |
|
260 |
Map("type" -> message_type, "message" -> message)) |
|
261 |
} |
|
262 |
||
263 |
||
264 |
/* document edits */ |
|
265 |
||
266 |
object DidOpenTextDocument |
|
267 |
{ |
|
64777
ca09695eb43c
clarified Document.Node.Name (again): canonical platform file;
wenzelm
parents:
64767
diff
changeset
|
268 |
def unapply(json: JSON.T): Option[(JFile, String, Long, String)] = |
64605 | 269 |
json match { |
270 |
case Notification("textDocument/didOpen", Some(params)) => |
|
271 |
for { |
|
272 |
doc <- JSON.value(params, "textDocument") |
|
273 |
uri <- JSON.string(doc, "uri") |
|
274 |
lang <- JSON.string(doc, "languageId") |
|
275 |
version <- JSON.long(doc, "version") |
|
276 |
text <- JSON.string(doc, "text") |
|
64777
ca09695eb43c
clarified Document.Node.Name (again): canonical platform file;
wenzelm
parents:
64767
diff
changeset
|
277 |
} yield (Url.canonical_file(uri), lang, version, text) |
64605 | 278 |
case _ => None |
279 |
} |
|
280 |
} |
|
281 |
||
282 |
||
65160 | 283 |
sealed case class TextDocumentChange(range: Option[Line.Range], text: String) |
64605 | 284 |
|
285 |
object DidChangeTextDocument |
|
286 |
{ |
|
65160 | 287 |
def unapply_change(json: JSON.T): Option[TextDocumentChange] = |
288 |
for { text <- JSON.string(json, "text") } |
|
289 |
yield TextDocumentChange(JSON.value(json, "range", Range.unapply _), text) |
|
290 |
||
291 |
def unapply(json: JSON.T): Option[(JFile, Long, List[TextDocumentChange])] = |
|
64605 | 292 |
json match { |
293 |
case Notification("textDocument/didChange", Some(params)) => |
|
294 |
for { |
|
295 |
doc <- JSON.value(params, "textDocument") |
|
296 |
uri <- JSON.string(doc, "uri") |
|
297 |
version <- JSON.long(doc, "version") |
|
65160 | 298 |
changes <- JSON.array(params, "contentChanges", unapply_change _) |
64777
ca09695eb43c
clarified Document.Node.Name (again): canonical platform file;
wenzelm
parents:
64767
diff
changeset
|
299 |
} yield (Url.canonical_file(uri), version, changes) |
64605 | 300 |
case _ => None |
301 |
} |
|
302 |
} |
|
303 |
||
304 |
class TextDocumentNotification(name: String) |
|
305 |
{ |
|
64777
ca09695eb43c
clarified Document.Node.Name (again): canonical platform file;
wenzelm
parents:
64767
diff
changeset
|
306 |
def unapply(json: JSON.T): Option[JFile] = |
64605 | 307 |
json match { |
308 |
case Notification(method, Some(params)) if method == name => |
|
309 |
for { |
|
310 |
doc <- JSON.value(params, "textDocument") |
|
311 |
uri <- JSON.string(doc, "uri") |
|
64777
ca09695eb43c
clarified Document.Node.Name (again): canonical platform file;
wenzelm
parents:
64767
diff
changeset
|
312 |
} yield Url.canonical_file(uri) |
64605 | 313 |
case _ => None |
314 |
} |
|
315 |
} |
|
316 |
||
317 |
object DidCloseTextDocument extends TextDocumentNotification("textDocument/didClose") |
|
318 |
object DidSaveTextDocument extends TextDocumentNotification("textDocument/didSave") |
|
319 |
||
320 |
||
64877 | 321 |
/* completion */ |
322 |
||
323 |
sealed case class CompletionItem( |
|
324 |
label: String, |
|
325 |
kind: Option[Int] = None, |
|
326 |
detail: Option[String] = None, |
|
327 |
documentation: Option[String] = None, |
|
328 |
insertText: Option[String] = None, |
|
329 |
range: Option[Line.Range] = None) |
|
330 |
{ |
|
331 |
def json: JSON.T = |
|
332 |
Message.empty + ("label" -> label) ++ |
|
64878 | 333 |
JSON.optional("kind" -> kind) ++ |
334 |
JSON.optional("detail" -> detail) ++ |
|
335 |
JSON.optional("documentation" -> documentation) ++ |
|
336 |
JSON.optional("insertText" -> insertText) ++ |
|
337 |
JSON.optional("range" -> range.map(Range(_))) |
|
64877 | 338 |
} |
339 |
||
340 |
object Completion extends RequestTextDocumentPosition("textDocument/completion") |
|
341 |
{ |
|
342 |
def reply(id: Id, result: List[CompletionItem]): JSON.T = |
|
343 |
ResponseMessage(id, Some(result.map(_.json))) |
|
344 |
} |
|
345 |
||
346 |
||
64605 | 347 |
/* hover request */ |
348 |
||
64648
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
349 |
object Hover extends RequestTextDocumentPosition("textDocument/hover") |
64605 | 350 |
{ |
65093 | 351 |
def reply(id: Id, result: Option[(Line.Range, List[MarkedString])]): JSON.T = |
64605 | 352 |
{ |
353 |
val res = |
|
354 |
result match { |
|
64747 | 355 |
case Some((range, contents)) => |
65103 | 356 |
Map("contents" -> MarkedStrings.json(contents).getOrElse(Nil), "range" -> Range(range)) |
64605 | 357 |
case None => Map("contents" -> Nil) |
358 |
} |
|
359 |
ResponseMessage(id, Some(res)) |
|
360 |
} |
|
361 |
} |
|
64648
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
362 |
|
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
363 |
|
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
364 |
/* goto definition request */ |
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
365 |
|
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
366 |
object GotoDefinition extends RequestTextDocumentPosition("textDocument/definition") |
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
367 |
{ |
64651 | 368 |
def reply(id: Id, result: List[Line.Node_Range]): JSON.T = |
64649 | 369 |
ResponseMessage(id, Some(result.map(Location.apply(_)))) |
64648
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
370 |
} |
64675 | 371 |
|
372 |
||
64767 | 373 |
/* document highlights request */ |
374 |
||
375 |
object DocumentHighlight |
|
376 |
{ |
|
377 |
def text(range: Line.Range): DocumentHighlight = DocumentHighlight(range, Some(1)) |
|
378 |
def read(range: Line.Range): DocumentHighlight = DocumentHighlight(range, Some(2)) |
|
379 |
def write(range: Line.Range): DocumentHighlight = DocumentHighlight(range, Some(3)) |
|
380 |
} |
|
381 |
||
382 |
sealed case class DocumentHighlight(range: Line.Range, kind: Option[Int] = None) |
|
383 |
{ |
|
384 |
def json: JSON.T = |
|
385 |
kind match { |
|
386 |
case None => Map("range" -> Range(range)) |
|
387 |
case Some(k) => Map("range" -> Range(range), "kind" -> k) |
|
388 |
} |
|
389 |
} |
|
390 |
||
391 |
object DocumentHighlights extends RequestTextDocumentPosition("textDocument/documentHighlight") |
|
392 |
{ |
|
393 |
def reply(id: Id, result: List[DocumentHighlight]): JSON.T = |
|
394 |
ResponseMessage(id, Some(result.map(_.json))) |
|
395 |
} |
|
396 |
||
397 |
||
64675 | 398 |
/* diagnostics */ |
399 |
||
400 |
sealed case class Diagnostic(range: Line.Range, message: String, |
|
401 |
severity: Option[Int] = None, code: Option[Int] = None, source: Option[String] = None) |
|
402 |
{ |
|
403 |
def json: JSON.T = |
|
404 |
Message.empty + ("range" -> Range(range)) + ("message" -> message) ++ |
|
64878 | 405 |
JSON.optional("severity" -> severity) ++ |
406 |
JSON.optional("code" -> code) ++ |
|
407 |
JSON.optional("source" -> source) |
|
64675 | 408 |
} |
409 |
||
410 |
object DiagnosticSeverity |
|
411 |
{ |
|
64762
cd545bec3fd0
clarified message severity, based on empirical observation of VSCode 1.8.1;
wenzelm
parents:
64747
diff
changeset
|
412 |
val Error = 1 |
cd545bec3fd0
clarified message severity, based on empirical observation of VSCode 1.8.1;
wenzelm
parents:
64747
diff
changeset
|
413 |
val Warning = 2 |
cd545bec3fd0
clarified message severity, based on empirical observation of VSCode 1.8.1;
wenzelm
parents:
64747
diff
changeset
|
414 |
val Information = 3 |
cd545bec3fd0
clarified message severity, based on empirical observation of VSCode 1.8.1;
wenzelm
parents:
64747
diff
changeset
|
415 |
val Hint = 4 |
64675 | 416 |
} |
417 |
||
418 |
object PublishDiagnostics |
|
419 |
{ |
|
64777
ca09695eb43c
clarified Document.Node.Name (again): canonical platform file;
wenzelm
parents:
64767
diff
changeset
|
420 |
def apply(file: JFile, diagnostics: List[Diagnostic]): JSON.T = |
64675 | 421 |
Notification("textDocument/publishDiagnostics", |
64777
ca09695eb43c
clarified Document.Node.Name (again): canonical platform file;
wenzelm
parents:
64767
diff
changeset
|
422 |
Map("uri" -> Url.print_file(file), "diagnostics" -> diagnostics.map(_.json))) |
64675 | 423 |
} |
65094 | 424 |
|
425 |
||
426 |
/* decorations */ |
|
427 |
||
65173 | 428 |
sealed case class DecorationOpts(range: Line.Range, hover_message: List[MarkedString]) |
65094 | 429 |
{ |
430 |
def json: JSON.T = |
|
65173 | 431 |
Map("range" -> Range.compact(range)) ++ |
432 |
JSON.optional("hover_message" -> MarkedStrings.json(hover_message)) |
|
65094 | 433 |
} |
434 |
||
65173 | 435 |
sealed case class Decoration(typ: String, content: List[DecorationOpts]) |
65094 | 436 |
{ |
65095 | 437 |
def json(file: JFile): JSON.T = |
65094 | 438 |
Notification("PIDE/decoration", |
65173 | 439 |
Map("uri" -> Url.print_file(file), "type" -> typ, "content" -> content.map(_.json))) |
65094 | 440 |
} |
65189 | 441 |
|
442 |
||
65201 | 443 |
/* caret handling */ |
65189 | 444 |
|
445 |
object Caret_Update |
|
446 |
{ |
|
447 |
def unapply(json: JSON.T): Option[Option[(JFile, Line.Position)]] = |
|
448 |
json match { |
|
449 |
case Notification("PIDE/caret_update", Some(params)) => |
|
450 |
val caret = |
|
451 |
for { |
|
452 |
uri <- JSON.string(params, "uri") |
|
453 |
if Url.is_wellformed_file(uri) |
|
454 |
pos <- Position.unapply(params) |
|
455 |
} yield (Url.canonical_file(uri), pos) |
|
456 |
Some(caret) |
|
457 |
case _ => None |
|
458 |
} |
|
459 |
} |
|
460 |
||
65201 | 461 |
|
462 |
/* dynamic output */ |
|
463 |
||
65189 | 464 |
object Dynamic_Output |
465 |
{ |
|
466 |
def apply(body: String): JSON.T = |
|
65200
1227a68fac7a
more explicit message type: allows body to become empty;
wenzelm
parents:
65189
diff
changeset
|
467 |
Notification("PIDE/dynamic_output", Map("body" -> body)) |
65189 | 468 |
} |
64605 | 469 |
} |