author | wenzelm |
Tue, 20 Jun 2017 15:04:34 +0200 | |
changeset 66138 | f7ef4c50b747 |
parent 66096 | 6187612e83c1 |
child 66139 | 6a8f8be2741c |
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 |
||
66138 | 261 |
/* commands */ |
262 |
||
263 |
sealed case class Command(title: String, command: String, arguments: List[JSON.T] = Nil) |
|
264 |
{ |
|
265 |
def json: JSON.T = |
|
266 |
Map("title" -> title, "command" -> command, "arguments" -> arguments) |
|
267 |
} |
|
268 |
||
269 |
||
64605 | 270 |
/* document edits */ |
271 |
||
272 |
object DidOpenTextDocument |
|
273 |
{ |
|
64777
ca09695eb43c
clarified Document.Node.Name (again): canonical platform file;
wenzelm
parents:
64767
diff
changeset
|
274 |
def unapply(json: JSON.T): Option[(JFile, String, Long, String)] = |
64605 | 275 |
json match { |
276 |
case Notification("textDocument/didOpen", Some(params)) => |
|
277 |
for { |
|
278 |
doc <- JSON.value(params, "textDocument") |
|
279 |
uri <- JSON.string(doc, "uri") |
|
280 |
lang <- JSON.string(doc, "languageId") |
|
281 |
version <- JSON.long(doc, "version") |
|
282 |
text <- JSON.string(doc, "text") |
|
64777
ca09695eb43c
clarified Document.Node.Name (again): canonical platform file;
wenzelm
parents:
64767
diff
changeset
|
283 |
} yield (Url.canonical_file(uri), lang, version, text) |
64605 | 284 |
case _ => None |
285 |
} |
|
286 |
} |
|
287 |
||
288 |
||
65160 | 289 |
sealed case class TextDocumentChange(range: Option[Line.Range], text: String) |
64605 | 290 |
|
291 |
object DidChangeTextDocument |
|
292 |
{ |
|
65160 | 293 |
def unapply_change(json: JSON.T): Option[TextDocumentChange] = |
294 |
for { text <- JSON.string(json, "text") } |
|
295 |
yield TextDocumentChange(JSON.value(json, "range", Range.unapply _), text) |
|
296 |
||
297 |
def unapply(json: JSON.T): Option[(JFile, Long, List[TextDocumentChange])] = |
|
64605 | 298 |
json match { |
299 |
case Notification("textDocument/didChange", Some(params)) => |
|
300 |
for { |
|
301 |
doc <- JSON.value(params, "textDocument") |
|
302 |
uri <- JSON.string(doc, "uri") |
|
303 |
version <- JSON.long(doc, "version") |
|
65160 | 304 |
changes <- JSON.array(params, "contentChanges", unapply_change _) |
64777
ca09695eb43c
clarified Document.Node.Name (again): canonical platform file;
wenzelm
parents:
64767
diff
changeset
|
305 |
} yield (Url.canonical_file(uri), version, changes) |
64605 | 306 |
case _ => None |
307 |
} |
|
308 |
} |
|
309 |
||
310 |
class TextDocumentNotification(name: String) |
|
311 |
{ |
|
64777
ca09695eb43c
clarified Document.Node.Name (again): canonical platform file;
wenzelm
parents:
64767
diff
changeset
|
312 |
def unapply(json: JSON.T): Option[JFile] = |
64605 | 313 |
json match { |
314 |
case Notification(method, Some(params)) if method == name => |
|
315 |
for { |
|
316 |
doc <- JSON.value(params, "textDocument") |
|
317 |
uri <- JSON.string(doc, "uri") |
|
64777
ca09695eb43c
clarified Document.Node.Name (again): canonical platform file;
wenzelm
parents:
64767
diff
changeset
|
318 |
} yield Url.canonical_file(uri) |
64605 | 319 |
case _ => None |
320 |
} |
|
321 |
} |
|
322 |
||
323 |
object DidCloseTextDocument extends TextDocumentNotification("textDocument/didClose") |
|
324 |
object DidSaveTextDocument extends TextDocumentNotification("textDocument/didSave") |
|
325 |
||
326 |
||
64877 | 327 |
/* completion */ |
328 |
||
329 |
sealed case class CompletionItem( |
|
330 |
label: String, |
|
331 |
kind: Option[Int] = None, |
|
332 |
detail: Option[String] = None, |
|
333 |
documentation: Option[String] = None, |
|
334 |
insertText: Option[String] = None, |
|
66138 | 335 |
range: Option[Line.Range] = None, |
336 |
command: Option[Command] = None) |
|
64877 | 337 |
{ |
338 |
def json: JSON.T = |
|
66061 | 339 |
Map("label" -> label) ++ |
340 |
JSON.optional("kind" -> kind) ++ |
|
341 |
JSON.optional("detail" -> detail) ++ |
|
342 |
JSON.optional("documentation" -> documentation) ++ |
|
343 |
JSON.optional("insertText" -> insertText) ++ |
|
66062
175772371cd0
use old-style "textEdit" for the sake of the external protocol (see also vscode-languageserver-node/issues/188);
wenzelm
parents:
66061
diff
changeset
|
344 |
JSON.optional("range" -> range.map(Range(_))) ++ |
175772371cd0
use old-style "textEdit" for the sake of the external protocol (see also vscode-languageserver-node/issues/188);
wenzelm
parents:
66061
diff
changeset
|
345 |
JSON.optional("textEdit" -> |
66138 | 346 |
range.map(r => Map("range" -> Range(r), "newText" -> insertText.getOrElse(label)))) ++ |
347 |
JSON.optional("command" -> command.map(_.json)) |
|
64877 | 348 |
} |
349 |
||
350 |
object Completion extends RequestTextDocumentPosition("textDocument/completion") |
|
351 |
{ |
|
352 |
def reply(id: Id, result: List[CompletionItem]): JSON.T = |
|
353 |
ResponseMessage(id, Some(result.map(_.json))) |
|
354 |
} |
|
355 |
||
356 |
||
66138 | 357 |
/* spell checker */ |
358 |
||
359 |
object Include_Word extends Notification0("PIDE/include_word") |
|
360 |
object Include_Word_Permanently extends Notification0("PIDE/include_word_permanently") |
|
361 |
object Exclude_Word extends Notification0("PIDE/exclude_word") |
|
362 |
object Exclude_Word_Permanently extends Notification0("PIDE/exclude_word_permanently") |
|
363 |
object Reset_Words extends Notification0("PIDE/reset_words") |
|
364 |
||
365 |
||
64605 | 366 |
/* hover request */ |
367 |
||
64648
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
368 |
object Hover extends RequestTextDocumentPosition("textDocument/hover") |
64605 | 369 |
{ |
65093 | 370 |
def reply(id: Id, result: Option[(Line.Range, List[MarkedString])]): JSON.T = |
64605 | 371 |
{ |
372 |
val res = |
|
373 |
result match { |
|
64747 | 374 |
case Some((range, contents)) => |
65103 | 375 |
Map("contents" -> MarkedStrings.json(contents).getOrElse(Nil), "range" -> Range(range)) |
64605 | 376 |
case None => Map("contents" -> Nil) |
377 |
} |
|
378 |
ResponseMessage(id, Some(res)) |
|
379 |
} |
|
380 |
} |
|
64648
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
381 |
|
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
382 |
|
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
383 |
/* goto definition request */ |
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
384 |
|
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
385 |
object GotoDefinition extends RequestTextDocumentPosition("textDocument/definition") |
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
386 |
{ |
64651 | 387 |
def reply(id: Id, result: List[Line.Node_Range]): JSON.T = |
64649 | 388 |
ResponseMessage(id, Some(result.map(Location.apply(_)))) |
64648
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
389 |
} |
64675 | 390 |
|
391 |
||
64767 | 392 |
/* document highlights request */ |
393 |
||
394 |
object DocumentHighlight |
|
395 |
{ |
|
396 |
def text(range: Line.Range): DocumentHighlight = DocumentHighlight(range, Some(1)) |
|
397 |
def read(range: Line.Range): DocumentHighlight = DocumentHighlight(range, Some(2)) |
|
398 |
def write(range: Line.Range): DocumentHighlight = DocumentHighlight(range, Some(3)) |
|
399 |
} |
|
400 |
||
401 |
sealed case class DocumentHighlight(range: Line.Range, kind: Option[Int] = None) |
|
402 |
{ |
|
403 |
def json: JSON.T = |
|
404 |
kind match { |
|
405 |
case None => Map("range" -> Range(range)) |
|
406 |
case Some(k) => Map("range" -> Range(range), "kind" -> k) |
|
407 |
} |
|
408 |
} |
|
409 |
||
410 |
object DocumentHighlights extends RequestTextDocumentPosition("textDocument/documentHighlight") |
|
411 |
{ |
|
412 |
def reply(id: Id, result: List[DocumentHighlight]): JSON.T = |
|
413 |
ResponseMessage(id, Some(result.map(_.json))) |
|
414 |
} |
|
415 |
||
416 |
||
64675 | 417 |
/* diagnostics */ |
418 |
||
419 |
sealed case class Diagnostic(range: Line.Range, message: String, |
|
420 |
severity: Option[Int] = None, code: Option[Int] = None, source: Option[String] = None) |
|
421 |
{ |
|
422 |
def json: JSON.T = |
|
423 |
Message.empty + ("range" -> Range(range)) + ("message" -> message) ++ |
|
64878 | 424 |
JSON.optional("severity" -> severity) ++ |
425 |
JSON.optional("code" -> code) ++ |
|
426 |
JSON.optional("source" -> source) |
|
64675 | 427 |
} |
428 |
||
429 |
object DiagnosticSeverity |
|
430 |
{ |
|
64762
cd545bec3fd0
clarified message severity, based on empirical observation of VSCode 1.8.1;
wenzelm
parents:
64747
diff
changeset
|
431 |
val Error = 1 |
cd545bec3fd0
clarified message severity, based on empirical observation of VSCode 1.8.1;
wenzelm
parents:
64747
diff
changeset
|
432 |
val Warning = 2 |
cd545bec3fd0
clarified message severity, based on empirical observation of VSCode 1.8.1;
wenzelm
parents:
64747
diff
changeset
|
433 |
val Information = 3 |
cd545bec3fd0
clarified message severity, based on empirical observation of VSCode 1.8.1;
wenzelm
parents:
64747
diff
changeset
|
434 |
val Hint = 4 |
64675 | 435 |
} |
436 |
||
437 |
object PublishDiagnostics |
|
438 |
{ |
|
64777
ca09695eb43c
clarified Document.Node.Name (again): canonical platform file;
wenzelm
parents:
64767
diff
changeset
|
439 |
def apply(file: JFile, diagnostics: List[Diagnostic]): JSON.T = |
64675 | 440 |
Notification("textDocument/publishDiagnostics", |
64777
ca09695eb43c
clarified Document.Node.Name (again): canonical platform file;
wenzelm
parents:
64767
diff
changeset
|
441 |
Map("uri" -> Url.print_file(file), "diagnostics" -> diagnostics.map(_.json))) |
64675 | 442 |
} |
65094 | 443 |
|
444 |
||
445 |
/* decorations */ |
|
446 |
||
65173 | 447 |
sealed case class DecorationOpts(range: Line.Range, hover_message: List[MarkedString]) |
65094 | 448 |
{ |
449 |
def json: JSON.T = |
|
65173 | 450 |
Map("range" -> Range.compact(range)) ++ |
451 |
JSON.optional("hover_message" -> MarkedStrings.json(hover_message)) |
|
65094 | 452 |
} |
453 |
||
65173 | 454 |
sealed case class Decoration(typ: String, content: List[DecorationOpts]) |
65094 | 455 |
{ |
65095 | 456 |
def json(file: JFile): JSON.T = |
65094 | 457 |
Notification("PIDE/decoration", |
65173 | 458 |
Map("uri" -> Url.print_file(file), "type" -> typ, "content" -> content.map(_.json))) |
65094 | 459 |
} |
65189 | 460 |
|
461 |
||
65201 | 462 |
/* caret handling */ |
65189 | 463 |
|
464 |
object Caret_Update |
|
465 |
{ |
|
466 |
def unapply(json: JSON.T): Option[Option[(JFile, Line.Position)]] = |
|
467 |
json match { |
|
468 |
case Notification("PIDE/caret_update", Some(params)) => |
|
469 |
val caret = |
|
470 |
for { |
|
471 |
uri <- JSON.string(params, "uri") |
|
472 |
if Url.is_wellformed_file(uri) |
|
473 |
pos <- Position.unapply(params) |
|
474 |
} yield (Url.canonical_file(uri), pos) |
|
475 |
Some(caret) |
|
476 |
case _ => None |
|
477 |
} |
|
478 |
} |
|
479 |
||
65201 | 480 |
|
481 |
/* dynamic output */ |
|
482 |
||
65189 | 483 |
object Dynamic_Output |
484 |
{ |
|
66090 | 485 |
def apply(content: String): JSON.T = |
486 |
Notification("PIDE/dynamic_output", Map("content" -> content)) |
|
65189 | 487 |
} |
65977
c51b74be23b6
provide preview content on Scala side (similar to output);
wenzelm
parents:
65924
diff
changeset
|
488 |
|
c51b74be23b6
provide preview content on Scala side (similar to output);
wenzelm
parents:
65924
diff
changeset
|
489 |
|
66096 | 490 |
/* state output */ |
491 |
||
492 |
object State_Output |
|
493 |
{ |
|
494 |
def apply(id: Counter.ID, content: String): JSON.T = |
|
495 |
Notification("PIDE/state_output", Map("id" -> id, "content" -> content)) |
|
496 |
} |
|
497 |
||
498 |
class State_Id_Notification(name: String) |
|
499 |
{ |
|
500 |
def unapply(json: JSON.T): Option[Counter.ID] = |
|
501 |
json match { |
|
502 |
case Notification(method, Some(params)) if method == name => JSON.long(params, "id") |
|
503 |
case _ => None |
|
504 |
} |
|
505 |
} |
|
506 |
||
507 |
object State_Init extends Notification0("PIDE/state_init") |
|
508 |
object State_Exit extends State_Id_Notification("PIDE/state_exit") |
|
509 |
object State_Locate extends State_Id_Notification("PIDE/state_locate") |
|
510 |
object State_Update extends State_Id_Notification("PIDE/state_update") |
|
511 |
||
512 |
||
65983 | 513 |
/* preview */ |
65977
c51b74be23b6
provide preview content on Scala side (similar to output);
wenzelm
parents:
65924
diff
changeset
|
514 |
|
65983 | 515 |
object Preview_Request |
65977
c51b74be23b6
provide preview content on Scala side (similar to output);
wenzelm
parents:
65924
diff
changeset
|
516 |
{ |
65983 | 517 |
def unapply(json: JSON.T): Option[(JFile, Int)] = |
518 |
json match { |
|
519 |
case Notification("PIDE/preview_request", Some(params)) => |
|
520 |
for { |
|
521 |
uri <- JSON.string(params, "uri") |
|
522 |
if Url.is_wellformed_file(uri) |
|
523 |
column <- JSON.int(params, "column") |
|
524 |
} yield (Url.canonical_file(uri), column) |
|
525 |
case _ => None |
|
526 |
} |
|
527 |
} |
|
528 |
||
529 |
object Preview_Response |
|
530 |
{ |
|
531 |
def apply(file: JFile, column: Int, label: String, content: String): JSON.T = |
|
532 |
Notification("PIDE/preview_response", |
|
533 |
Map( |
|
534 |
"uri" -> Url.print_file(file), |
|
535 |
"column" -> column, |
|
536 |
"label" -> label, |
|
537 |
"content" -> content)) |
|
65977
c51b74be23b6
provide preview content on Scala side (similar to output);
wenzelm
parents:
65924
diff
changeset
|
538 |
} |
66052
39eb61b1fa51
provide information about Isabelle symbols within VSCode;
wenzelm
parents:
65983
diff
changeset
|
539 |
|
39eb61b1fa51
provide information about Isabelle symbols within VSCode;
wenzelm
parents:
65983
diff
changeset
|
540 |
|
39eb61b1fa51
provide information about Isabelle symbols within VSCode;
wenzelm
parents:
65983
diff
changeset
|
541 |
/* Isabelle symbols */ |
39eb61b1fa51
provide information about Isabelle symbols within VSCode;
wenzelm
parents:
65983
diff
changeset
|
542 |
|
39eb61b1fa51
provide information about Isabelle symbols within VSCode;
wenzelm
parents:
65983
diff
changeset
|
543 |
object Symbols_Request extends Notification0("PIDE/symbols_request") |
39eb61b1fa51
provide information about Isabelle symbols within VSCode;
wenzelm
parents:
65983
diff
changeset
|
544 |
|
39eb61b1fa51
provide information about Isabelle symbols within VSCode;
wenzelm
parents:
65983
diff
changeset
|
545 |
object Symbols |
39eb61b1fa51
provide information about Isabelle symbols within VSCode;
wenzelm
parents:
65983
diff
changeset
|
546 |
{ |
39eb61b1fa51
provide information about Isabelle symbols within VSCode;
wenzelm
parents:
65983
diff
changeset
|
547 |
def apply(): JSON.T = |
39eb61b1fa51
provide information about Isabelle symbols within VSCode;
wenzelm
parents:
65983
diff
changeset
|
548 |
{ |
39eb61b1fa51
provide information about Isabelle symbols within VSCode;
wenzelm
parents:
65983
diff
changeset
|
549 |
val entries = |
39eb61b1fa51
provide information about Isabelle symbols within VSCode;
wenzelm
parents:
65983
diff
changeset
|
550 |
for ((sym, code) <- Symbol.codes) |
39eb61b1fa51
provide information about Isabelle symbols within VSCode;
wenzelm
parents:
65983
diff
changeset
|
551 |
yield Map("symbol" -> sym, "name" -> Symbol.names(sym), "code" -> code) |
39eb61b1fa51
provide information about Isabelle symbols within VSCode;
wenzelm
parents:
65983
diff
changeset
|
552 |
Notification("PIDE/symbols", Map("entries" -> entries)) |
39eb61b1fa51
provide information about Isabelle symbols within VSCode;
wenzelm
parents:
65983
diff
changeset
|
553 |
} |
39eb61b1fa51
provide information about Isabelle symbols within VSCode;
wenzelm
parents:
65983
diff
changeset
|
554 |
} |
64605 | 555 |
} |