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