| author | wenzelm |
| Sat, 01 Nov 2025 17:54:44 +0100 | |
| changeset 83446 | c0c0d860acd2 |
| parent 83445 | ed531427234a |
| child 83454 | 62178604511c |
| permissions | -rw-r--r-- |
| 72761 | 1 |
/* Title: Tools/VSCode/src/lsp.scala |
| 64605 | 2 |
Author: Makarius |
| 83377 | 3 |
Author: Thomas Lindae, TU Muenchen |
4 |
Author: Diana Korchmar, LMU Muenchen |
|
| 64605 | 5 |
|
|
75201
8f6b8a46f54c
clarified modules: more uniform .scala vs. ts (amending 4519eeefe3b5);
wenzelm
parents:
75199
diff
changeset
|
6 |
Message formats for Language Server Protocol, with adhoc PIDE extensions. |
|
8f6b8a46f54c
clarified modules: more uniform .scala vs. ts (amending 4519eeefe3b5);
wenzelm
parents:
75199
diff
changeset
|
7 |
See https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md |
| 64605 | 8 |
*/ |
9 |
||
10 |
package isabelle.vscode |
|
11 |
||
12 |
||
13 |
import isabelle._ |
|
14 |
||
|
64777
ca09695eb43c
clarified Document.Node.Name (again): canonical platform file;
wenzelm
parents:
64767
diff
changeset
|
15 |
import java.io.{File => JFile}
|
|
ca09695eb43c
clarified Document.Node.Name (again): canonical platform file;
wenzelm
parents:
64767
diff
changeset
|
16 |
|
|
ca09695eb43c
clarified Document.Node.Name (again): canonical platform file;
wenzelm
parents:
64767
diff
changeset
|
17 |
|
| 75393 | 18 |
object LSP {
|
| 64605 | 19 |
/* abstract message */ |
20 |
||
| 75393 | 21 |
object Message {
|
| 67850 | 22 |
val empty: JSON.Object.T = JSON.Object("jsonrpc" -> "2.0")
|
| 65922 | 23 |
|
| 75393 | 24 |
def log(prefix: String, json: JSON.T, logger: Logger, verbose: Boolean): Unit = {
|
| 67851 | 25 |
val header = |
| 65922 | 26 |
json match {
|
| 67851 | 27 |
case JSON.Object(obj) => obj -- (obj.keySet - "method" - "id") |
| 67850 | 28 |
case _ => JSON.Object.empty |
| 65922 | 29 |
} |
30 |
if (verbose || header.isEmpty) logger(prefix + "\n" + JSON.Format(json)) |
|
31 |
else logger(prefix + " " + JSON.Format(header)) |
|
32 |
} |
|
| 64605 | 33 |
} |
34 |
||
35 |
||
36 |
/* notification */ |
|
37 |
||
| 75393 | 38 |
object Notification {
|
| 64605 | 39 |
def apply(method: String, params: JSON.T): JSON.T = |
40 |
Message.empty + ("method" -> method) + ("params" -> params)
|
|
41 |
||
42 |
def unapply(json: JSON.T): Option[(String, Option[JSON.T])] = |
|
43 |
for {
|
|
44 |
method <- JSON.string(json, "method") |
|
45 |
params = JSON.value(json, "params") |
|
46 |
} yield (method, params) |
|
47 |
} |
|
48 |
||
| 75393 | 49 |
class Notification0(name: String) {
|
| 83422 | 50 |
def unapply(json: JSON.T): Boolean = |
| 64605 | 51 |
json match {
|
| 83422 | 52 |
case Notification(method, _) => method == name |
53 |
case _ => false |
|
| 64605 | 54 |
} |
55 |
} |
|
56 |
||
57 |
||
58 |
/* request message */ |
|
59 |
||
| 75393 | 60 |
object Id {
|
| 66675 | 61 |
def empty: Id = Id("")
|
62 |
} |
|
63 |
||
| 75393 | 64 |
sealed case class Id(id: Any) {
|
| 64605 | 65 |
require( |
66 |
id.isInstanceOf[Int] || |
|
67 |
id.isInstanceOf[Long] || |
|
68 |
id.isInstanceOf[Double] || |
|
|
73120
c3589f2dff31
more informative errors: simplify diagnosis of spurious failures reported by users;
wenzelm
parents:
72761
diff
changeset
|
69 |
id.isInstanceOf[String], "bad id type") |
| 64605 | 70 |
|
71 |
override def toString: String = id.toString |
|
72 |
} |
|
73 |
||
| 75393 | 74 |
object RequestMessage {
|
| 64605 | 75 |
def apply(id: Id, method: String, params: JSON.T): JSON.T = |
76 |
Message.empty + ("id" -> id.id) + ("method" -> method) + ("params" -> params)
|
|
77 |
||
78 |
def unapply(json: JSON.T): Option[(Id, String, Option[JSON.T])] = |
|
79 |
for {
|
|
80 |
id <- JSON.long(json, "id") orElse JSON.double(json, "id") orElse JSON.string(json, "id") |
|
81 |
method <- JSON.string(json, "method") |
|
82 |
params = JSON.value(json, "params") |
|
83 |
} yield (Id(id), method, params) |
|
84 |
} |
|
85 |
||
| 75393 | 86 |
class Request0(name: String) {
|
| 64605 | 87 |
def unapply(json: JSON.T): Option[Id] = |
88 |
json match {
|
|
89 |
case RequestMessage(id, method, _) if method == name => Some(id) |
|
90 |
case _ => None |
|
91 |
} |
|
92 |
} |
|
93 |
||
| 75393 | 94 |
class RequestTextDocumentPosition(name: String) {
|
| 64651 | 95 |
def unapply(json: JSON.T): Option[(Id, Line.Node_Position)] = |
|
64648
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
96 |
json match {
|
| 64651 | 97 |
case RequestMessage(id, method, Some(TextDocumentPosition(node_pos))) if method == name => |
98 |
Some((id, node_pos)) |
|
|
64648
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
99 |
case _ => None |
|
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
100 |
} |
|
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
101 |
} |
|
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
102 |
|
| 64605 | 103 |
|
104 |
/* response message */ |
|
105 |
||
| 75393 | 106 |
object ResponseMessage {
|
| 64605 | 107 |
def apply(id: Id, result: Option[JSON.T] = None, error: Option[ResponseError] = None): JSON.T = |
108 |
Message.empty + ("id" -> id.id) ++
|
|
| 64878 | 109 |
JSON.optional("result" -> result) ++
|
110 |
JSON.optional("error" -> error.map(_.json))
|
|
| 64605 | 111 |
|
112 |
def strict(id: Id, result: Option[JSON.T] = None, error: String = ""): JSON.T = |
|
113 |
if (error == "") apply(id, result = result) |
|
| 81084 | 114 |
else {
|
115 |
apply(id, error = |
|
116 |
Some(ResponseError(code = ErrorCodes.jsonrpcReservedErrorRangeEnd, message = error))) |
|
117 |
} |
|
| 66675 | 118 |
|
119 |
def is_empty(json: JSON.T): Boolean = |
|
120 |
JSON.string(json, "id") == Some("") && JSON.value(json, "result").isDefined
|
|
| 64605 | 121 |
} |
122 |
||
| 75393 | 123 |
sealed case class ResponseError(code: Int, message: String, data: Option[JSON.T] = None) {
|
| 64605 | 124 |
def json: JSON.T = |
| 67850 | 125 |
JSON.Object("code" -> code, "message" -> message) ++ JSON.optional("data" -> data)
|
| 64605 | 126 |
} |
127 |
||
| 75393 | 128 |
object ErrorCodes {
|
| 64605 | 129 |
val ParseError = -32700 |
130 |
val InvalidRequest = -32600 |
|
131 |
val MethodNotFound = -32601 |
|
132 |
val InvalidParams = -32602 |
|
133 |
val InternalError = -32603 |
|
|
81026
c4bc259393f6
lsp: updated ErrorCodes;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81021
diff
changeset
|
134 |
|
|
c4bc259393f6
lsp: updated ErrorCodes;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81021
diff
changeset
|
135 |
val jsonrpcReservedErrorRangeStart = -32099 |
|
c4bc259393f6
lsp: updated ErrorCodes;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81021
diff
changeset
|
136 |
val ServerNotInitialized = -32002 |
|
c4bc259393f6
lsp: updated ErrorCodes;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81021
diff
changeset
|
137 |
val UnknownErrorCode = -32001 |
|
c4bc259393f6
lsp: updated ErrorCodes;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81021
diff
changeset
|
138 |
val jsonrpcReservedErrorRangeEnd = -32000 |
|
c4bc259393f6
lsp: updated ErrorCodes;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81021
diff
changeset
|
139 |
|
|
c4bc259393f6
lsp: updated ErrorCodes;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81021
diff
changeset
|
140 |
val lspReservedErrorRangeStart = -32899 |
|
c4bc259393f6
lsp: updated ErrorCodes;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81021
diff
changeset
|
141 |
val RequestFailed = -32803 |
|
c4bc259393f6
lsp: updated ErrorCodes;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81021
diff
changeset
|
142 |
val ServerCancelled = -32802 |
|
c4bc259393f6
lsp: updated ErrorCodes;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81021
diff
changeset
|
143 |
val ContentModified = -32801 |
|
c4bc259393f6
lsp: updated ErrorCodes;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81021
diff
changeset
|
144 |
val RequestCancelled = -32800 |
|
c4bc259393f6
lsp: updated ErrorCodes;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81021
diff
changeset
|
145 |
val lspReservedErrorRangeEnd = -32800 |
| 64605 | 146 |
} |
| 83377 | 147 |
|
| 64605 | 148 |
|
149 |
/* init and exit */ |
|
150 |
||
| 75393 | 151 |
object Initialize extends Request0("initialize") {
|
| 64605 | 152 |
def reply(id: Id, error: String): JSON.T = |
| 67850 | 153 |
ResponseMessage.strict( |
154 |
id, Some(JSON.Object("capabilities" -> ServerCapabilities.json)), error)
|
|
| 64605 | 155 |
} |
156 |
||
| 75393 | 157 |
object ServerCapabilities {
|
| 64605 | 158 |
val json: JSON.T = |
| 67850 | 159 |
JSON.Object( |
| 65160 | 160 |
"textDocumentSync" -> 2, |
|
75126
da1108a6d249
various improvements to Isabelle/VSCode (by Denis Paluca and Fabian Huch);
wenzelm
parents:
73541
diff
changeset
|
161 |
"completionProvider" -> JSON.Object( |
|
da1108a6d249
various improvements to Isabelle/VSCode (by Denis Paluca and Fabian Huch);
wenzelm
parents:
73541
diff
changeset
|
162 |
"resolveProvider" -> false, |
|
da1108a6d249
various improvements to Isabelle/VSCode (by Denis Paluca and Fabian Huch);
wenzelm
parents:
73541
diff
changeset
|
163 |
"triggerCharacters" -> |
|
81081
6aafcdc0217f
lsp: added more triggerCharacters to make completion popups more consistent;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81079
diff
changeset
|
164 |
(Symbol.symbols.entries.flatMap(_.abbrevs).flatMap(_.toList).map(_.toString) |
|
6aafcdc0217f
lsp: added more triggerCharacters to make completion popups more consistent;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81079
diff
changeset
|
165 |
++ Symbol.symbols.entries.map(_.name).flatMap(_.toList).map(_.toString)).distinct |
|
75126
da1108a6d249
various improvements to Isabelle/VSCode (by Denis Paluca and Fabian Huch);
wenzelm
parents:
73541
diff
changeset
|
166 |
), |
|
64648
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
167 |
"hoverProvider" -> true, |
| 64767 | 168 |
"definitionProvider" -> true, |
|
81067
1b1d72c45ff4
lsp: added support for code actions to apply active sendback markups;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81066
diff
changeset
|
169 |
"documentHighlightProvider" -> true, |
|
1b1d72c45ff4
lsp: added support for code actions to apply active sendback markups;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81066
diff
changeset
|
170 |
"codeActionProvider" -> true) |
| 64605 | 171 |
} |
172 |
||
| 65229 | 173 |
object Initialized extends Notification0("initialized")
|
174 |
||
| 75393 | 175 |
object Shutdown extends Request0("shutdown") {
|
| 64605 | 176 |
def reply(id: Id, error: String): JSON.T = |
177 |
ResponseMessage.strict(id, Some("OK"), error)
|
|
178 |
} |
|
179 |
||
180 |
object Exit extends Notification0("exit")
|
|
181 |
||
182 |
||
183 |
/* document positions */ |
|
184 |
||
| 75393 | 185 |
object Position {
|
| 64605 | 186 |
def apply(pos: Line.Position): JSON.T = |
| 67850 | 187 |
JSON.Object("line" -> pos.line, "character" -> pos.column)
|
| 64605 | 188 |
|
189 |
def unapply(json: JSON.T): Option[Line.Position] = |
|
190 |
for {
|
|
191 |
line <- JSON.int(json, "line") |
|
192 |
column <- JSON.int(json, "character") |
|
193 |
} yield Line.Position(line, column) |
|
194 |
} |
|
195 |
||
| 75393 | 196 |
object Range {
|
| 65173 | 197 |
def compact(range: Line.Range): List[Int] = |
198 |
List(range.start.line, range.start.column, range.stop.line, range.stop.column) |
|
199 |
||
| 64605 | 200 |
def apply(range: Line.Range): JSON.T = |
| 67850 | 201 |
JSON.Object("start" -> Position(range.start), "end" -> Position(range.stop))
|
| 64605 | 202 |
|
203 |
def unapply(json: JSON.T): Option[Line.Range] = |
|
| 83423 | 204 |
for {
|
205 |
case Position(start) <- JSON.value(json, "start") |
|
206 |
case Position(stop) <- JSON.value(json, "end") |
|
207 |
} yield Line.Range(start, stop) |
|
| 64605 | 208 |
} |
209 |
||
| 75393 | 210 |
object Location {
|
| 64651 | 211 |
def apply(loc: Line.Node_Range): JSON.T = |
| 67850 | 212 |
JSON.Object("uri" -> Url.print_file_name(loc.name), "range" -> Range(loc.range))
|
| 64605 | 213 |
|
| 64651 | 214 |
def unapply(json: JSON.T): Option[Line.Node_Range] = |
| 64605 | 215 |
for {
|
| 83423 | 216 |
uri <- JSON.string(json, "uri") if Url.is_wellformed_file(uri) |
217 |
case Range(range) <- JSON.value(json, "range") |
|
|
66235
d4fa51e7c4ff
retain symlinks in file names from VSCode: relevant for proper file locations in decorations etc.;
wenzelm
parents:
66216
diff
changeset
|
218 |
} yield Line.Node_Range(Url.absolute_file_name(uri), range) |
| 64605 | 219 |
} |
220 |
||
| 75393 | 221 |
object TextDocumentPosition {
|
| 64651 | 222 |
def unapply(json: JSON.T): Option[Line.Node_Position] = |
| 64605 | 223 |
for {
|
224 |
doc <- JSON.value(json, "textDocument") |
|
225 |
uri <- JSON.string(doc, "uri") |
|
|
75126
da1108a6d249
various improvements to Isabelle/VSCode (by Denis Paluca and Fabian Huch);
wenzelm
parents:
73541
diff
changeset
|
226 |
if Url.is_wellformed_file(uri) |
| 64605 | 227 |
pos_json <- JSON.value(json, "position") |
228 |
pos <- Position.unapply(pos_json) |
|
|
66235
d4fa51e7c4ff
retain symlinks in file names from VSCode: relevant for proper file locations in decorations etc.;
wenzelm
parents:
66216
diff
changeset
|
229 |
} yield Line.Node_Position(Url.absolute_file_name(uri), pos) |
| 64605 | 230 |
} |
231 |
||
232 |
||
| 65103 | 233 |
/* marked strings */ |
| 65093 | 234 |
|
| 75393 | 235 |
sealed case class MarkedString(text: String, language: String = "plaintext") {
|
| 67850 | 236 |
def json: JSON.T = JSON.Object("language" -> language, "value" -> text)
|
| 65093 | 237 |
} |
238 |
||
| 75393 | 239 |
object MarkedStrings {
|
| 65103 | 240 |
def json(msgs: List[MarkedString]): Option[JSON.T] = |
241 |
msgs match {
|
|
242 |
case Nil => None |
|
243 |
case List(msg) => Some(msg.json) |
|
244 |
case _ => Some(msgs.map(_.json)) |
|
245 |
} |
|
246 |
} |
|
247 |
||
| 65093 | 248 |
|
| 64605 | 249 |
/* diagnostic messages */ |
250 |
||
| 75393 | 251 |
object MessageType {
|
| 64605 | 252 |
val Error = 1 |
253 |
val Warning = 2 |
|
254 |
val Info = 3 |
|
255 |
val Log = 4 |
|
256 |
} |
|
257 |
||
| 75393 | 258 |
object DisplayMessage {
|
| 73541 | 259 |
def apply(message_type: Int, message: String, show: Boolean): JSON.T = |
| 64605 | 260 |
Notification(if (show) "window/showMessage" else "window/logMessage", |
| 67850 | 261 |
JSON.Object("type" -> message_type, "message" -> message))
|
| 64605 | 262 |
} |
263 |
||
264 |
||
| 66138 | 265 |
/* commands */ |
266 |
||
| 75393 | 267 |
sealed case class Command(title: String, command: String, arguments: List[JSON.T] = Nil) {
|
| 66138 | 268 |
def json: JSON.T = |
| 67850 | 269 |
JSON.Object("title" -> title, "command" -> command, "arguments" -> arguments)
|
| 66138 | 270 |
} |
271 |
||
272 |
||
| 64605 | 273 |
/* document edits */ |
274 |
||
| 75393 | 275 |
object DidOpenTextDocument {
|
|
64777
ca09695eb43c
clarified Document.Node.Name (again): canonical platform file;
wenzelm
parents:
64767
diff
changeset
|
276 |
def unapply(json: JSON.T): Option[(JFile, String, Long, String)] = |
| 64605 | 277 |
json match {
|
278 |
case Notification("textDocument/didOpen", Some(params)) =>
|
|
279 |
for {
|
|
280 |
doc <- JSON.value(params, "textDocument") |
|
281 |
uri <- JSON.string(doc, "uri") |
|
|
75126
da1108a6d249
various improvements to Isabelle/VSCode (by Denis Paluca and Fabian Huch);
wenzelm
parents:
73541
diff
changeset
|
282 |
if Url.is_wellformed_file(uri) |
| 64605 | 283 |
lang <- JSON.string(doc, "languageId") |
284 |
version <- JSON.long(doc, "version") |
|
285 |
text <- JSON.string(doc, "text") |
|
|
66235
d4fa51e7c4ff
retain symlinks in file names from VSCode: relevant for proper file locations in decorations etc.;
wenzelm
parents:
66216
diff
changeset
|
286 |
} yield (Url.absolute_file(uri), lang, version, text) |
| 64605 | 287 |
case _ => None |
288 |
} |
|
289 |
} |
|
290 |
||
291 |
||
| 65160 | 292 |
sealed case class TextDocumentChange(range: Option[Line.Range], text: String) |
| 64605 | 293 |
|
| 75393 | 294 |
object DidChangeTextDocument {
|
| 65160 | 295 |
def unapply_change(json: JSON.T): Option[TextDocumentChange] = |
| 83423 | 296 |
for (text <- JSON.string(json, "text")) |
| 75204 | 297 |
yield TextDocumentChange(JSON.value(json, "range", Range.unapply), text) |
| 65160 | 298 |
|
299 |
def unapply(json: JSON.T): Option[(JFile, Long, List[TextDocumentChange])] = |
|
| 64605 | 300 |
json match {
|
301 |
case Notification("textDocument/didChange", Some(params)) =>
|
|
302 |
for {
|
|
303 |
doc <- JSON.value(params, "textDocument") |
|
304 |
uri <- JSON.string(doc, "uri") |
|
|
75126
da1108a6d249
various improvements to Isabelle/VSCode (by Denis Paluca and Fabian Huch);
wenzelm
parents:
73541
diff
changeset
|
305 |
if Url.is_wellformed_file(uri) |
| 64605 | 306 |
version <- JSON.long(doc, "version") |
| 75204 | 307 |
changes <- JSON.list(params, "contentChanges", unapply_change) |
|
66235
d4fa51e7c4ff
retain symlinks in file names from VSCode: relevant for proper file locations in decorations etc.;
wenzelm
parents:
66216
diff
changeset
|
308 |
} yield (Url.absolute_file(uri), version, changes) |
| 64605 | 309 |
case _ => None |
310 |
} |
|
311 |
} |
|
312 |
||
| 75393 | 313 |
class TextDocumentNotification(name: String) {
|
|
64777
ca09695eb43c
clarified Document.Node.Name (again): canonical platform file;
wenzelm
parents:
64767
diff
changeset
|
314 |
def unapply(json: JSON.T): Option[JFile] = |
| 64605 | 315 |
json match {
|
316 |
case Notification(method, Some(params)) if method == name => |
|
317 |
for {
|
|
318 |
doc <- JSON.value(params, "textDocument") |
|
319 |
uri <- JSON.string(doc, "uri") |
|
|
75126
da1108a6d249
various improvements to Isabelle/VSCode (by Denis Paluca and Fabian Huch);
wenzelm
parents:
73541
diff
changeset
|
320 |
if Url.is_wellformed_file(uri) |
|
66235
d4fa51e7c4ff
retain symlinks in file names from VSCode: relevant for proper file locations in decorations etc.;
wenzelm
parents:
66216
diff
changeset
|
321 |
} yield Url.absolute_file(uri) |
| 64605 | 322 |
case _ => None |
323 |
} |
|
324 |
} |
|
325 |
||
326 |
object DidCloseTextDocument extends TextDocumentNotification("textDocument/didClose")
|
|
327 |
object DidSaveTextDocument extends TextDocumentNotification("textDocument/didSave")
|
|
328 |
||
329 |
||
| 66675 | 330 |
/* workspace edits */ |
331 |
||
| 75393 | 332 |
sealed case class TextEdit(range: Line.Range, new_text: String) {
|
| 67850 | 333 |
def json: JSON.T = JSON.Object("range" -> Range(range), "newText" -> new_text)
|
| 66675 | 334 |
} |
335 |
||
|
81065
37590e377db6
lsp: made TextDocumentEdit accept optional versions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81060
diff
changeset
|
336 |
sealed case class TextDocumentEdit(file: JFile, version: Option[Long], edits: List[TextEdit]) {
|
| 66675 | 337 |
def json: JSON.T = |
| 67850 | 338 |
JSON.Object( |
|
81065
37590e377db6
lsp: made TextDocumentEdit accept optional versions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81060
diff
changeset
|
339 |
"textDocument" -> ( |
|
37590e377db6
lsp: made TextDocumentEdit accept optional versions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81060
diff
changeset
|
340 |
JSON.Object("uri" -> Url.print_file(file)) ++
|
|
37590e377db6
lsp: made TextDocumentEdit accept optional versions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81060
diff
changeset
|
341 |
JSON.optional("version" -> version)
|
|
37590e377db6
lsp: made TextDocumentEdit accept optional versions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81060
diff
changeset
|
342 |
), |
|
37590e377db6
lsp: made TextDocumentEdit accept optional versions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81060
diff
changeset
|
343 |
"edits" -> edits.map(_.json) |
|
37590e377db6
lsp: made TextDocumentEdit accept optional versions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81060
diff
changeset
|
344 |
) |
| 66675 | 345 |
} |
346 |
||
| 75393 | 347 |
object WorkspaceEdit {
|
| 66675 | 348 |
def apply(edits: List[TextDocumentEdit]): JSON.T = |
|
81066
18c98588388d
lsp: clarified WorkspaceEdit;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81065
diff
changeset
|
349 |
JSON.Object("documentChanges" -> edits.map(_.json))
|
|
18c98588388d
lsp: clarified WorkspaceEdit;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81065
diff
changeset
|
350 |
} |
|
18c98588388d
lsp: clarified WorkspaceEdit;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81065
diff
changeset
|
351 |
|
|
18c98588388d
lsp: clarified WorkspaceEdit;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81065
diff
changeset
|
352 |
object ApplyWorkspaceEdit {
|
|
18c98588388d
lsp: clarified WorkspaceEdit;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81065
diff
changeset
|
353 |
def apply(edits: List[TextDocumentEdit]): JSON.T = |
| 66675 | 354 |
RequestMessage(Id.empty, "workspace/applyEdit", |
|
81066
18c98588388d
lsp: clarified WorkspaceEdit;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81065
diff
changeset
|
355 |
JSON.Object("edit" -> WorkspaceEdit(edits))
|
|
18c98588388d
lsp: clarified WorkspaceEdit;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81065
diff
changeset
|
356 |
) |
| 66675 | 357 |
} |
358 |
||
359 |
||
| 64877 | 360 |
/* completion */ |
| 83377 | 361 |
|
|
81079
ff813e8a3271
lsp: improved completions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81075
diff
changeset
|
362 |
object CompletionItemKind {
|
|
ff813e8a3271
lsp: improved completions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81075
diff
changeset
|
363 |
val Text = 1; |
|
ff813e8a3271
lsp: improved completions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81075
diff
changeset
|
364 |
val Method = 2; |
|
ff813e8a3271
lsp: improved completions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81075
diff
changeset
|
365 |
val Function = 3; |
|
ff813e8a3271
lsp: improved completions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81075
diff
changeset
|
366 |
val Constructor = 4; |
|
ff813e8a3271
lsp: improved completions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81075
diff
changeset
|
367 |
val Field = 5; |
|
ff813e8a3271
lsp: improved completions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81075
diff
changeset
|
368 |
val Variable = 6; |
|
ff813e8a3271
lsp: improved completions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81075
diff
changeset
|
369 |
val Class = 7; |
|
ff813e8a3271
lsp: improved completions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81075
diff
changeset
|
370 |
val Interface = 8; |
|
ff813e8a3271
lsp: improved completions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81075
diff
changeset
|
371 |
val Module = 9; |
|
ff813e8a3271
lsp: improved completions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81075
diff
changeset
|
372 |
val Property = 10; |
|
ff813e8a3271
lsp: improved completions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81075
diff
changeset
|
373 |
val Unit = 11; |
|
ff813e8a3271
lsp: improved completions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81075
diff
changeset
|
374 |
val Value = 12; |
|
ff813e8a3271
lsp: improved completions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81075
diff
changeset
|
375 |
val Enum = 13; |
|
ff813e8a3271
lsp: improved completions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81075
diff
changeset
|
376 |
val Keyword = 14; |
|
ff813e8a3271
lsp: improved completions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81075
diff
changeset
|
377 |
val Snippet = 15; |
|
ff813e8a3271
lsp: improved completions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81075
diff
changeset
|
378 |
val Color = 16; |
|
ff813e8a3271
lsp: improved completions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81075
diff
changeset
|
379 |
val File = 17; |
|
ff813e8a3271
lsp: improved completions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81075
diff
changeset
|
380 |
val Reference = 18; |
|
ff813e8a3271
lsp: improved completions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81075
diff
changeset
|
381 |
val Folder = 19; |
|
ff813e8a3271
lsp: improved completions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81075
diff
changeset
|
382 |
val EnumMember = 20; |
|
ff813e8a3271
lsp: improved completions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81075
diff
changeset
|
383 |
val Constant = 21; |
|
ff813e8a3271
lsp: improved completions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81075
diff
changeset
|
384 |
val Struct = 22; |
|
ff813e8a3271
lsp: improved completions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81075
diff
changeset
|
385 |
val Event = 23; |
|
ff813e8a3271
lsp: improved completions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81075
diff
changeset
|
386 |
val Operator = 24; |
|
ff813e8a3271
lsp: improved completions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81075
diff
changeset
|
387 |
val TypeParameter = 25; |
|
ff813e8a3271
lsp: improved completions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81075
diff
changeset
|
388 |
} |
| 64877 | 389 |
|
390 |
sealed case class CompletionItem( |
|
391 |
label: String, |
|
392 |
kind: Option[Int] = None, |
|
393 |
detail: Option[String] = None, |
|
394 |
documentation: Option[String] = None, |
|
|
81079
ff813e8a3271
lsp: improved completions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81075
diff
changeset
|
395 |
filter_text: Option[String] = None, |
|
ff813e8a3271
lsp: improved completions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81075
diff
changeset
|
396 |
commit_characters: Option[List[String]] = None, |
| 66140 | 397 |
text: Option[String] = None, |
| 66138 | 398 |
range: Option[Line.Range] = None, |
| 75393 | 399 |
command: Option[Command] = None |
400 |
) {
|
|
| 64877 | 401 |
def json: JSON.T = |
| 67850 | 402 |
JSON.Object("label" -> label) ++
|
| 66061 | 403 |
JSON.optional("kind" -> kind) ++
|
404 |
JSON.optional("detail" -> detail) ++
|
|
405 |
JSON.optional("documentation" -> documentation) ++
|
|
|
81079
ff813e8a3271
lsp: improved completions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81075
diff
changeset
|
406 |
JSON.optional("filterText" -> filter_text) ++
|
| 81084 | 407 |
JSON.optional("textEdit" -> range.map(TextEdit(_, text.getOrElse(label)).json)) ++
|
|
81079
ff813e8a3271
lsp: improved completions;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81075
diff
changeset
|
408 |
JSON.optional("commitCharacters" -> commit_characters) ++
|
| 66138 | 409 |
JSON.optional("command" -> command.map(_.json))
|
| 64877 | 410 |
} |
411 |
||
| 75393 | 412 |
object Completion extends RequestTextDocumentPosition("textDocument/completion") {
|
| 64877 | 413 |
def reply(id: Id, result: List[CompletionItem]): JSON.T = |
414 |
ResponseMessage(id, Some(result.map(_.json))) |
|
415 |
} |
|
416 |
||
417 |
||
| 66138 | 418 |
/* spell checker */ |
419 |
||
| 75393 | 420 |
object Include_Word extends Notification0("PIDE/include_word") {
|
|
66139
6a8f8be2741c
provide spell-checker menu via completion commands;
wenzelm
parents:
66138
diff
changeset
|
421 |
val command = Command("Include word", "isabelle.include-word")
|
|
6a8f8be2741c
provide spell-checker menu via completion commands;
wenzelm
parents:
66138
diff
changeset
|
422 |
} |
|
6a8f8be2741c
provide spell-checker menu via completion commands;
wenzelm
parents:
66138
diff
changeset
|
423 |
|
| 75393 | 424 |
object Include_Word_Permanently extends Notification0("PIDE/include_word_permanently") {
|
|
66139
6a8f8be2741c
provide spell-checker menu via completion commands;
wenzelm
parents:
66138
diff
changeset
|
425 |
val command = Command("Include word permanently", "isabelle.include-word-permanently")
|
|
6a8f8be2741c
provide spell-checker menu via completion commands;
wenzelm
parents:
66138
diff
changeset
|
426 |
} |
|
6a8f8be2741c
provide spell-checker menu via completion commands;
wenzelm
parents:
66138
diff
changeset
|
427 |
|
| 75393 | 428 |
object Exclude_Word extends Notification0("PIDE/exclude_word") {
|
|
66139
6a8f8be2741c
provide spell-checker menu via completion commands;
wenzelm
parents:
66138
diff
changeset
|
429 |
val command = Command("Exclude word", "isabelle.exclude-word")
|
|
6a8f8be2741c
provide spell-checker menu via completion commands;
wenzelm
parents:
66138
diff
changeset
|
430 |
} |
|
6a8f8be2741c
provide spell-checker menu via completion commands;
wenzelm
parents:
66138
diff
changeset
|
431 |
|
| 75393 | 432 |
object Exclude_Word_Permanently extends Notification0("PIDE/exclude_word_permanently") {
|
|
66139
6a8f8be2741c
provide spell-checker menu via completion commands;
wenzelm
parents:
66138
diff
changeset
|
433 |
val command = Command("Exclude word permanently", "isabelle.exclude-word-permanently")
|
|
6a8f8be2741c
provide spell-checker menu via completion commands;
wenzelm
parents:
66138
diff
changeset
|
434 |
} |
|
6a8f8be2741c
provide spell-checker menu via completion commands;
wenzelm
parents:
66138
diff
changeset
|
435 |
|
| 75393 | 436 |
object Reset_Words extends Notification0("PIDE/reset_words") {
|
|
66139
6a8f8be2741c
provide spell-checker menu via completion commands;
wenzelm
parents:
66138
diff
changeset
|
437 |
val command = Command("Reset non-permanent words", "isabelle.reset-words")
|
|
6a8f8be2741c
provide spell-checker menu via completion commands;
wenzelm
parents:
66138
diff
changeset
|
438 |
} |
| 66138 | 439 |
|
440 |
||
| 64605 | 441 |
/* hover request */ |
442 |
||
| 75393 | 443 |
object Hover extends RequestTextDocumentPosition("textDocument/hover") {
|
444 |
def reply(id: Id, result: Option[(Line.Range, List[MarkedString])]): JSON.T = {
|
|
| 64605 | 445 |
val res = |
446 |
result match {
|
|
| 64747 | 447 |
case Some((range, contents)) => |
| 67850 | 448 |
JSON.Object( |
449 |
"contents" -> MarkedStrings.json(contents).getOrElse(Nil), |
|
450 |
"range" -> Range(range)) |
|
451 |
case None => JSON.Object("contents" -> Nil)
|
|
| 64605 | 452 |
} |
453 |
ResponseMessage(id, Some(res)) |
|
454 |
} |
|
455 |
} |
|
|
64648
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
456 |
|
|
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
457 |
|
|
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
458 |
/* goto definition request */ |
|
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
459 |
|
| 75393 | 460 |
object GotoDefinition extends RequestTextDocumentPosition("textDocument/definition") {
|
| 64651 | 461 |
def reply(id: Id, result: List[Line.Node_Range]): JSON.T = |
| 75204 | 462 |
ResponseMessage(id, Some(result.map(Location.apply))) |
|
64648
5d7f741aaccb
basic support for hyperlinks / Goto Definition Request;
wenzelm
parents:
64605
diff
changeset
|
463 |
} |
| 64675 | 464 |
|
465 |
||
| 64767 | 466 |
/* document highlights request */ |
467 |
||
| 75393 | 468 |
object DocumentHighlight {
|
| 64767 | 469 |
def text(range: Line.Range): DocumentHighlight = DocumentHighlight(range, Some(1)) |
470 |
def read(range: Line.Range): DocumentHighlight = DocumentHighlight(range, Some(2)) |
|
471 |
def write(range: Line.Range): DocumentHighlight = DocumentHighlight(range, Some(3)) |
|
472 |
} |
|
473 |
||
| 75393 | 474 |
sealed case class DocumentHighlight(range: Line.Range, kind: Option[Int] = None) {
|
| 64767 | 475 |
def json: JSON.T = |
476 |
kind match {
|
|
| 67850 | 477 |
case None => JSON.Object("range" -> Range(range))
|
478 |
case Some(k) => JSON.Object("range" -> Range(range), "kind" -> k)
|
|
| 64767 | 479 |
} |
480 |
} |
|
481 |
||
| 75393 | 482 |
object DocumentHighlights extends RequestTextDocumentPosition("textDocument/documentHighlight") {
|
| 64767 | 483 |
def reply(id: Id, result: List[DocumentHighlight]): JSON.T = |
484 |
ResponseMessage(id, Some(result.map(_.json))) |
|
485 |
} |
|
486 |
||
487 |
||
| 64675 | 488 |
/* diagnostics */ |
489 |
||
| 75393 | 490 |
sealed case class Diagnostic( |
491 |
range: Line.Range, |
|
492 |
message: String, |
|
493 |
severity: Option[Int] = None, |
|
494 |
code: Option[Int] = None, |
|
495 |
source: Option[String] = None |
|
496 |
) {
|
|
| 64675 | 497 |
def json: JSON.T = |
498 |
Message.empty + ("range" -> Range(range)) + ("message" -> message) ++
|
|
| 64878 | 499 |
JSON.optional("severity" -> severity) ++
|
500 |
JSON.optional("code" -> code) ++
|
|
501 |
JSON.optional("source" -> source)
|
|
| 64675 | 502 |
} |
503 |
||
| 75393 | 504 |
object DiagnosticSeverity {
|
|
64762
cd545bec3fd0
clarified message severity, based on empirical observation of VSCode 1.8.1;
wenzelm
parents:
64747
diff
changeset
|
505 |
val Error = 1 |
|
cd545bec3fd0
clarified message severity, based on empirical observation of VSCode 1.8.1;
wenzelm
parents:
64747
diff
changeset
|
506 |
val Warning = 2 |
|
cd545bec3fd0
clarified message severity, based on empirical observation of VSCode 1.8.1;
wenzelm
parents:
64747
diff
changeset
|
507 |
val Information = 3 |
|
cd545bec3fd0
clarified message severity, based on empirical observation of VSCode 1.8.1;
wenzelm
parents:
64747
diff
changeset
|
508 |
val Hint = 4 |
| 64675 | 509 |
} |
510 |
||
| 75393 | 511 |
object PublishDiagnostics {
|
|
64777
ca09695eb43c
clarified Document.Node.Name (again): canonical platform file;
wenzelm
parents:
64767
diff
changeset
|
512 |
def apply(file: JFile, diagnostics: List[Diagnostic]): JSON.T = |
| 64675 | 513 |
Notification("textDocument/publishDiagnostics",
|
| 67850 | 514 |
JSON.Object("uri" -> Url.print_file(file), "diagnostics" -> diagnostics.map(_.json)))
|
| 64675 | 515 |
} |
| 65094 | 516 |
|
517 |
||
|
81067
1b1d72c45ff4
lsp: added support for code actions to apply active sendback markups;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81066
diff
changeset
|
518 |
/* code actions */ |
|
1b1d72c45ff4
lsp: added support for code actions to apply active sendback markups;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81066
diff
changeset
|
519 |
|
|
1b1d72c45ff4
lsp: added support for code actions to apply active sendback markups;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81066
diff
changeset
|
520 |
sealed case class CodeAction(title: String, edits: List[TextDocumentEdit]) {
|
|
1b1d72c45ff4
lsp: added support for code actions to apply active sendback markups;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81066
diff
changeset
|
521 |
def json: JSON.T = |
|
1b1d72c45ff4
lsp: added support for code actions to apply active sendback markups;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81066
diff
changeset
|
522 |
JSON.Object("title" -> title, "edit" -> WorkspaceEdit(edits))
|
|
1b1d72c45ff4
lsp: added support for code actions to apply active sendback markups;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81066
diff
changeset
|
523 |
} |
|
1b1d72c45ff4
lsp: added support for code actions to apply active sendback markups;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81066
diff
changeset
|
524 |
|
|
1b1d72c45ff4
lsp: added support for code actions to apply active sendback markups;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81066
diff
changeset
|
525 |
object CodeActionRequest {
|
|
1b1d72c45ff4
lsp: added support for code actions to apply active sendback markups;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81066
diff
changeset
|
526 |
def unapply(json: JSON.T): Option[(Id, JFile, Line.Range)] = |
|
1b1d72c45ff4
lsp: added support for code actions to apply active sendback markups;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81066
diff
changeset
|
527 |
json match {
|
|
1b1d72c45ff4
lsp: added support for code actions to apply active sendback markups;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81066
diff
changeset
|
528 |
case RequestMessage(id, "textDocument/codeAction", Some(params)) => |
|
1b1d72c45ff4
lsp: added support for code actions to apply active sendback markups;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81066
diff
changeset
|
529 |
for {
|
|
1b1d72c45ff4
lsp: added support for code actions to apply active sendback markups;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81066
diff
changeset
|
530 |
doc <- JSON.value(params, "textDocument") |
|
1b1d72c45ff4
lsp: added support for code actions to apply active sendback markups;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81066
diff
changeset
|
531 |
uri <- JSON.string(doc, "uri") |
|
1b1d72c45ff4
lsp: added support for code actions to apply active sendback markups;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81066
diff
changeset
|
532 |
if Url.is_wellformed_file(uri) |
| 83423 | 533 |
case Range(range) <- JSON.value(params, "range") |
|
81067
1b1d72c45ff4
lsp: added support for code actions to apply active sendback markups;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81066
diff
changeset
|
534 |
} yield (id, Url.absolute_file(uri), range) |
|
1b1d72c45ff4
lsp: added support for code actions to apply active sendback markups;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81066
diff
changeset
|
535 |
case _ => None |
|
1b1d72c45ff4
lsp: added support for code actions to apply active sendback markups;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81066
diff
changeset
|
536 |
} |
|
1b1d72c45ff4
lsp: added support for code actions to apply active sendback markups;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81066
diff
changeset
|
537 |
|
|
1b1d72c45ff4
lsp: added support for code actions to apply active sendback markups;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81066
diff
changeset
|
538 |
def reply(id: Id, actions: List[CodeAction]): JSON.T = |
|
1b1d72c45ff4
lsp: added support for code actions to apply active sendback markups;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81066
diff
changeset
|
539 |
ResponseMessage(id, Some(actions.map(_.json))) |
|
1b1d72c45ff4
lsp: added support for code actions to apply active sendback markups;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81066
diff
changeset
|
540 |
} |
|
1b1d72c45ff4
lsp: added support for code actions to apply active sendback markups;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81066
diff
changeset
|
541 |
|
|
1b1d72c45ff4
lsp: added support for code actions to apply active sendback markups;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81066
diff
changeset
|
542 |
|
| 65094 | 543 |
/* decorations */ |
544 |
||
| 75393 | 545 |
sealed case class Decoration_Options(range: Line.Range, hover_message: List[MarkedString]) {
|
| 65094 | 546 |
def json: JSON.T = |
| 67850 | 547 |
JSON.Object("range" -> Range.compact(range)) ++
|
| 65173 | 548 |
JSON.optional("hover_message" -> MarkedStrings.json(hover_message))
|
| 65094 | 549 |
} |
550 |
||
|
81051
4fa6e5f9d393
lsp: extracted panel content generation logic;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81043
diff
changeset
|
551 |
type Decoration_List = List[(String, List[Decoration_Options])] |
|
4fa6e5f9d393
lsp: extracted panel content generation logic;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81043
diff
changeset
|
552 |
|
|
4fa6e5f9d393
lsp: extracted panel content generation logic;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81043
diff
changeset
|
553 |
sealed case class Decoration(decorations: Decoration_List) {
|
|
81060
159d1b09fe66
lsp: refactored conversion from Decoration_List to JSON;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
554 |
def json_entries: JSON.T = |
| 83377 | 555 |
decorations.map(decoration => |
556 |
JSON.Object( |
|
557 |
"type" -> decoration._1, |
|
558 |
"content" -> decoration._2.map(_.json))) |
|
|
81060
159d1b09fe66
lsp: refactored conversion from Decoration_List to JSON;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
559 |
|
| 65095 | 560 |
def json(file: JFile): JSON.T = |
| 65094 | 561 |
Notification("PIDE/decoration",
|
|
75126
da1108a6d249
various improvements to Isabelle/VSCode (by Denis Paluca and Fabian Huch);
wenzelm
parents:
73541
diff
changeset
|
562 |
JSON.Object( |
|
da1108a6d249
various improvements to Isabelle/VSCode (by Denis Paluca and Fabian Huch);
wenzelm
parents:
73541
diff
changeset
|
563 |
"uri" -> Url.print_file(file), |
| 81084 | 564 |
"entries" -> json_entries)) |
| 65094 | 565 |
} |
| 83377 | 566 |
|
|
81043
2174ec5f0d0c
lsp: added decoration_request notification;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81042
diff
changeset
|
567 |
object Decoration_Request {
|
|
2174ec5f0d0c
lsp: added decoration_request notification;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81042
diff
changeset
|
568 |
def unapply(json: JSON.T): Option[JFile] = |
|
2174ec5f0d0c
lsp: added decoration_request notification;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81042
diff
changeset
|
569 |
json match {
|
|
2174ec5f0d0c
lsp: added decoration_request notification;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81042
diff
changeset
|
570 |
case Notification("PIDE/decoration_request", Some(params)) =>
|
|
2174ec5f0d0c
lsp: added decoration_request notification;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81042
diff
changeset
|
571 |
for {
|
|
2174ec5f0d0c
lsp: added decoration_request notification;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81042
diff
changeset
|
572 |
uri <- JSON.string(params, "uri") |
|
2174ec5f0d0c
lsp: added decoration_request notification;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81042
diff
changeset
|
573 |
if Url.is_wellformed_file(uri) |
|
2174ec5f0d0c
lsp: added decoration_request notification;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81042
diff
changeset
|
574 |
} yield Url.absolute_file(uri) |
|
2174ec5f0d0c
lsp: added decoration_request notification;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81042
diff
changeset
|
575 |
case _ => None |
|
2174ec5f0d0c
lsp: added decoration_request notification;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81042
diff
changeset
|
576 |
} |
|
2174ec5f0d0c
lsp: added decoration_request notification;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81042
diff
changeset
|
577 |
} |
| 65189 | 578 |
|
579 |
||
|
66215
9a8b6b86350c
proper hyperlink_command, notably for locate_query;
wenzelm
parents:
66211
diff
changeset
|
580 |
/* caret update: bidirectional */ |
| 65189 | 581 |
|
| 75393 | 582 |
object Caret_Update {
|
| 66216 | 583 |
def apply(node_pos: Line.Node_Position, focus: Boolean): JSON.T = |
|
66215
9a8b6b86350c
proper hyperlink_command, notably for locate_query;
wenzelm
parents:
66211
diff
changeset
|
584 |
Notification("PIDE/caret_update",
|
| 67850 | 585 |
JSON.Object( |
586 |
"uri" -> Url.print_file_name(node_pos.name), |
|
|
66215
9a8b6b86350c
proper hyperlink_command, notably for locate_query;
wenzelm
parents:
66211
diff
changeset
|
587 |
"line" -> node_pos.pos.line, |
| 66216 | 588 |
"character" -> node_pos.pos.column, |
589 |
"focus" -> focus)) |
|
|
66215
9a8b6b86350c
proper hyperlink_command, notably for locate_query;
wenzelm
parents:
66211
diff
changeset
|
590 |
|
| 65189 | 591 |
def unapply(json: JSON.T): Option[Option[(JFile, Line.Position)]] = |
592 |
json match {
|
|
593 |
case Notification("PIDE/caret_update", Some(params)) =>
|
|
594 |
val caret = |
|
595 |
for {
|
|
| 83432 | 596 |
uri <- JSON.string(params, "uri") if Url.is_wellformed_file(uri) |
| 65189 | 597 |
pos <- Position.unapply(params) |
|
66235
d4fa51e7c4ff
retain symlinks in file names from VSCode: relevant for proper file locations in decorations etc.;
wenzelm
parents:
66216
diff
changeset
|
598 |
} yield (Url.absolute_file(uri), pos) |
| 65189 | 599 |
Some(caret) |
600 |
case _ => None |
|
601 |
} |
|
602 |
} |
|
603 |
||
| 65201 | 604 |
|
605 |
/* dynamic output */ |
|
606 |
||
| 75393 | 607 |
object Dynamic_Output {
|
|
81060
159d1b09fe66
lsp: refactored conversion from Decoration_List to JSON;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
608 |
def apply(content: String, decoration: Option[Decoration] = None): JSON.T = |
|
81037
f1aef7110329
lsp: added decorations to dynamic output;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81032
diff
changeset
|
609 |
Notification("PIDE/dynamic_output",
|
|
f1aef7110329
lsp: added decorations to dynamic output;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81032
diff
changeset
|
610 |
JSON.Object("content" -> content) ++
|
| 81084 | 611 |
JSON.optional("decorations" -> decoration.map(_.json_entries)))
|
| 65189 | 612 |
} |
|
65977
c51b74be23b6
provide preview content on Scala side (similar to output);
wenzelm
parents:
65924
diff
changeset
|
613 |
|
|
81029
f4cb1e35c63e
lsp: added Output_Set_Margin and State_Set_Margin Notifications;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81028
diff
changeset
|
614 |
object Output_Set_Margin {
|
|
f4cb1e35c63e
lsp: added Output_Set_Margin and State_Set_Margin Notifications;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81028
diff
changeset
|
615 |
def unapply(json: JSON.T): Option[Double] = |
|
f4cb1e35c63e
lsp: added Output_Set_Margin and State_Set_Margin Notifications;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81028
diff
changeset
|
616 |
json match {
|
|
f4cb1e35c63e
lsp: added Output_Set_Margin and State_Set_Margin Notifications;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81028
diff
changeset
|
617 |
case Notification("PIDE/output_set_margin", Some(params)) =>
|
| 81032 | 618 |
JSON.double(params, "margin") |
|
81029
f4cb1e35c63e
lsp: added Output_Set_Margin and State_Set_Margin Notifications;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81028
diff
changeset
|
619 |
case _ => None |
|
f4cb1e35c63e
lsp: added Output_Set_Margin and State_Set_Margin Notifications;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81028
diff
changeset
|
620 |
} |
|
f4cb1e35c63e
lsp: added Output_Set_Margin and State_Set_Margin Notifications;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81028
diff
changeset
|
621 |
} |
|
f4cb1e35c63e
lsp: added Output_Set_Margin and State_Set_Margin Notifications;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81028
diff
changeset
|
622 |
|
|
65977
c51b74be23b6
provide preview content on Scala side (similar to output);
wenzelm
parents:
65924
diff
changeset
|
623 |
|
| 66096 | 624 |
/* state output */ |
625 |
||
| 75393 | 626 |
object State_Output {
|
|
81042
f1e0ca5aaa6b
lsp: added decorations to state updates;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81039
diff
changeset
|
627 |
def apply( |
|
f1e0ca5aaa6b
lsp: added decorations to state updates;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81039
diff
changeset
|
628 |
id: Counter.ID, |
|
f1e0ca5aaa6b
lsp: added decorations to state updates;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81039
diff
changeset
|
629 |
content: String, |
|
f1e0ca5aaa6b
lsp: added decorations to state updates;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81039
diff
changeset
|
630 |
auto_update: Boolean, |
|
81060
159d1b09fe66
lsp: refactored conversion from Decoration_List to JSON;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81051
diff
changeset
|
631 |
decorations: Option[Decoration] = None |
|
81042
f1e0ca5aaa6b
lsp: added decorations to state updates;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81039
diff
changeset
|
632 |
): JSON.T = |
| 75393 | 633 |
Notification("PIDE/state_output",
|
|
81042
f1e0ca5aaa6b
lsp: added decorations to state updates;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81039
diff
changeset
|
634 |
JSON.Object("id" -> id, "content" -> content, "auto_update" -> auto_update) ++
|
| 81084 | 635 |
JSON.optional("decorations" -> decorations.map(_.json_entries)))
|
| 66096 | 636 |
} |
637 |
||
| 75393 | 638 |
class State_Id_Notification(name: String) {
|
| 66096 | 639 |
def unapply(json: JSON.T): Option[Counter.ID] = |
640 |
json match {
|
|
641 |
case Notification(method, Some(params)) if method == name => JSON.long(params, "id") |
|
642 |
case _ => None |
|
643 |
} |
|
644 |
} |
|
645 |
||
|
81028
84f6f17274d0
lsp: changed State_Init notification into a request and removed State_Init_Response;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81026
diff
changeset
|
646 |
object State_Init extends Request0("PIDE/state_init") {
|
|
84f6f17274d0
lsp: changed State_Init notification into a request and removed State_Init_Response;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81026
diff
changeset
|
647 |
def reply(id: Id, state_id: Counter.ID): JSON.T = |
|
84f6f17274d0
lsp: changed State_Init notification into a request and removed State_Init_Response;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81026
diff
changeset
|
648 |
ResponseMessage(id, Some(JSON.Object("state_id" -> state_id)))
|
|
84f6f17274d0
lsp: changed State_Init notification into a request and removed State_Init_Response;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81026
diff
changeset
|
649 |
} |
|
84f6f17274d0
lsp: changed State_Init notification into a request and removed State_Init_Response;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81026
diff
changeset
|
650 |
|
| 66096 | 651 |
object State_Exit extends State_Id_Notification("PIDE/state_exit")
|
652 |
object State_Locate extends State_Id_Notification("PIDE/state_locate")
|
|
653 |
object State_Update extends State_Id_Notification("PIDE/state_update")
|
|
654 |
||
| 75393 | 655 |
object State_Auto_Update {
|
| 66211 | 656 |
def unapply(json: JSON.T): Option[(Counter.ID, Boolean)] = |
657 |
json match {
|
|
658 |
case Notification("PIDE/state_auto_update", Some(params)) =>
|
|
659 |
for {
|
|
660 |
id <- JSON.long(params, "id") |
|
661 |
enabled <- JSON.bool(params, "enabled") |
|
662 |
} yield (id, enabled) |
|
663 |
case _ => None |
|
664 |
} |
|
665 |
} |
|
666 |
||
|
81029
f4cb1e35c63e
lsp: added Output_Set_Margin and State_Set_Margin Notifications;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81028
diff
changeset
|
667 |
object State_Set_Margin {
|
|
f4cb1e35c63e
lsp: added Output_Set_Margin and State_Set_Margin Notifications;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81028
diff
changeset
|
668 |
def unapply(json: JSON.T): Option[(Counter.ID, Double)] = |
|
f4cb1e35c63e
lsp: added Output_Set_Margin and State_Set_Margin Notifications;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81028
diff
changeset
|
669 |
json match {
|
|
f4cb1e35c63e
lsp: added Output_Set_Margin and State_Set_Margin Notifications;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81028
diff
changeset
|
670 |
case Notification("PIDE/state_set_margin", Some(params)) =>
|
|
f4cb1e35c63e
lsp: added Output_Set_Margin and State_Set_Margin Notifications;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81028
diff
changeset
|
671 |
for {
|
|
f4cb1e35c63e
lsp: added Output_Set_Margin and State_Set_Margin Notifications;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81028
diff
changeset
|
672 |
id <- JSON.long(params, "id") |
|
f4cb1e35c63e
lsp: added Output_Set_Margin and State_Set_Margin Notifications;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81028
diff
changeset
|
673 |
margin <- JSON.double(params, "margin") |
|
f4cb1e35c63e
lsp: added Output_Set_Margin and State_Set_Margin Notifications;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81028
diff
changeset
|
674 |
} yield (id, margin) |
|
f4cb1e35c63e
lsp: added Output_Set_Margin and State_Set_Margin Notifications;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81028
diff
changeset
|
675 |
case _ => None |
|
f4cb1e35c63e
lsp: added Output_Set_Margin and State_Set_Margin Notifications;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81028
diff
changeset
|
676 |
} |
|
f4cb1e35c63e
lsp: added Output_Set_Margin and State_Set_Margin Notifications;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81028
diff
changeset
|
677 |
} |
|
f4cb1e35c63e
lsp: added Output_Set_Margin and State_Set_Margin Notifications;
Thomas Lindae <thomas.lindae@in.tum.de>
parents:
81028
diff
changeset
|
678 |
|
| 66096 | 679 |
|
| 65983 | 680 |
/* preview */ |
|
65977
c51b74be23b6
provide preview content on Scala side (similar to output);
wenzelm
parents:
65924
diff
changeset
|
681 |
|
| 75393 | 682 |
object Preview_Request {
|
| 65983 | 683 |
def unapply(json: JSON.T): Option[(JFile, Int)] = |
684 |
json match {
|
|
685 |
case Notification("PIDE/preview_request", Some(params)) =>
|
|
686 |
for {
|
|
687 |
uri <- JSON.string(params, "uri") |
|
688 |
if Url.is_wellformed_file(uri) |
|
689 |
column <- JSON.int(params, "column") |
|
|
66235
d4fa51e7c4ff
retain symlinks in file names from VSCode: relevant for proper file locations in decorations etc.;
wenzelm
parents:
66216
diff
changeset
|
690 |
} yield (Url.absolute_file(uri), column) |
| 65983 | 691 |
case _ => None |
692 |
} |
|
693 |
} |
|
694 |
||
| 75393 | 695 |
object Preview_Response {
|
| 65983 | 696 |
def apply(file: JFile, column: Int, label: String, content: String): JSON.T = |
697 |
Notification("PIDE/preview_response",
|
|
| 67850 | 698 |
JSON.Object( |
| 65983 | 699 |
"uri" -> Url.print_file(file), |
700 |
"column" -> column, |
|
701 |
"label" -> label, |
|
702 |
"content" -> content)) |
|
|
65977
c51b74be23b6
provide preview content on Scala side (similar to output);
wenzelm
parents:
65924
diff
changeset
|
703 |
} |
|
83363
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
704 |
|
| 83377 | 705 |
|
706 |
/* symbols */ |
|
707 |
||
708 |
object Symbols_Request extends Request0("PIDE/symbols_request") {
|
|
709 |
def reply(id: Id, symbols: Symbol.Symbols): JSON.T = {
|
|
710 |
def json(symbol: Symbol.Entry): JSON.T = |
|
711 |
JSON.Object( |
|
712 |
"symbol" -> symbol.symbol, |
|
713 |
"name" -> symbol.name, |
|
714 |
"argument" -> symbol.argument.toString) ++ |
|
715 |
JSON.optional("code", symbol.code) ++
|
|
716 |
JSON.optional("font", symbol.font) ++
|
|
717 |
JSON.Object( |
|
718 |
"groups" -> symbol.groups, |
|
719 |
"abbrevs" -> symbol.abbrevs) |
|
720 |
||
721 |
ResponseMessage(id, Some(symbols.entries.map(s => json(s)))) |
|
722 |
} |
|
723 |
} |
|
724 |
||
725 |
object Symbols_Convert_Request {
|
|
726 |
def unapply(json: JSON.T): Option[(Id, String, Boolean)] = |
|
727 |
json match {
|
|
728 |
case RequestMessage(id, "PIDE/symbols_convert_request", Some(params)) => |
|
729 |
for {
|
|
| 83379 | 730 |
text <- JSON.string(params, "text") |
| 83377 | 731 |
unicode <- JSON.bool(params, "unicode") |
| 83379 | 732 |
} yield (id, text, unicode) |
| 83377 | 733 |
case _ => None |
734 |
} |
|
735 |
||
736 |
def reply(id: Id, new_string: String): JSON.T = |
|
737 |
ResponseMessage(id, Some(JSON.Object("text" -> new_string)))
|
|
738 |
} |
|
739 |
||
| 83406 | 740 |
object Symbols_Panel_Request |
741 |
extends Notification0("PIDE/symbols_panel_request")
|
|
|
83363
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
742 |
|
|
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
743 |
object Symbols_Response {
|
|
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
744 |
def apply(symbols: Symbol.Symbols, abbrevs: List[(String, String)]): JSON.T = {
|
|
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
745 |
def json(symbol: Symbol.Entry): JSON.T = {
|
|
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
746 |
val decoded = Symbol.decode(symbol.symbol) |
|
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
747 |
JSON.Object( |
|
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
748 |
"symbol" -> symbol.symbol, |
|
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
749 |
"name" -> symbol.name, |
|
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
750 |
"argument" -> symbol.argument.toString, |
| 83379 | 751 |
"decoded" -> decoded) ++ |
752 |
JSON.optional("code", symbol.code) ++
|
|
753 |
JSON.optional("font", symbol.font) ++
|
|
754 |
JSON.Object( |
|
755 |
"groups" -> symbol.groups, |
|
756 |
"abbrevs" -> symbol.abbrevs) |
|
|
83363
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
757 |
} |
|
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
758 |
|
| 83377 | 759 |
Notification("PIDE/symbols_response",
|
760 |
JSON.Object( |
|
761 |
"symbols" -> symbols.entries.map(json), |
|
| 83379 | 762 |
"abbrevs_from_Thy" -> (for ((a, b) <- abbrevs) yield List(a, b)))) |
|
83363
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
763 |
} |
|
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
764 |
} |
|
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
765 |
|
|
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
766 |
|
| 83377 | 767 |
/* documentation */ |
768 |
||
| 83413 | 769 |
object Documentation_Request |
770 |
extends Notification0("PIDE/documentation_request")
|
|
| 83377 | 771 |
|
| 83378 | 772 |
object Doc_Entry {
|
773 |
def apply(entry: Doc.Entry): JSON.T = |
|
|
83388
8d90bd0e4f39
more accurate Doc_Entry: print_html like Isabelle/jEdit, proper platform_path;
wenzelm
parents:
83380
diff
changeset
|
774 |
JSON.Object( |
|
8d90bd0e4f39
more accurate Doc_Entry: print_html like Isabelle/jEdit, proper platform_path;
wenzelm
parents:
83380
diff
changeset
|
775 |
"print_html" -> entry.print_html, |
|
8d90bd0e4f39
more accurate Doc_Entry: print_html like Isabelle/jEdit, proper platform_path;
wenzelm
parents:
83380
diff
changeset
|
776 |
"platform_path" -> File.platform_path(entry.path)) |
| 83378 | 777 |
} |
778 |
||
779 |
object Doc_Section {
|
|
780 |
def apply(section: Doc.Section): JSON.T = |
|
781 |
JSON.Object( |
|
782 |
"title" -> section.title, |
|
783 |
"important" -> section.important, |
|
784 |
"entries" -> section.entries.map(Doc_Entry.apply)) |
|
785 |
} |
|
786 |
||
|
83363
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
787 |
object Documentation_Response {
|
| 83380 | 788 |
def apply(ml_settings: ML_Settings): JSON.T = {
|
|
83363
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
789 |
val doc_contents = Doc.contents(ml_settings) |
| 83378 | 790 |
Notification("PIDE/documentation_response",
|
791 |
JSON.Object("sections" -> doc_contents.sections.map(Doc_Section.apply)))
|
|
|
83363
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
792 |
} |
|
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
793 |
} |
|
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
794 |
|
| 83377 | 795 |
|
796 |
/* sledgehammer */ |
|
797 |
||
| 83410 | 798 |
object Sledgehammer_Provers_Request |
|
83401
1d9b1ca7977e
dismantle redundant sledgehammer history in Isabelle/Scala, which does not quite work --- and is already done via vscode.setState / vscode.getState;
wenzelm
parents:
83388
diff
changeset
|
799 |
extends Notification0("PIDE/sledgehammer_provers_request")
|
| 83377 | 800 |
|
| 83410 | 801 |
object Sledgehammer_Provers_Response {
|
802 |
def apply(provers: String): JSON.T = |
|
803 |
Notification("PIDE/sledgehammer_provers_response", JSON.Object("provers" -> provers))
|
|
804 |
} |
|
805 |
||
|
83363
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
806 |
object Sledgehammer_Request {
|
| 83446 | 807 |
def unapply(json: JSON.T): Option[List[String]] = |
|
83363
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
808 |
json match {
|
|
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
809 |
case Notification("PIDE/sledgehammer_request", Some(params)) =>
|
|
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
810 |
for {
|
|
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
811 |
provers <- JSON.string(params, "provers") |
|
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
812 |
isar <- JSON.bool(params, "isar") |
|
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
813 |
try0 <- JSON.bool(params, "try0") |
| 83446 | 814 |
} yield List(provers, isar.toString, try0.toString) |
|
83363
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
815 |
case _ => None |
|
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
816 |
} |
|
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
817 |
} |
|
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
818 |
|
| 83421 | 819 |
object Sledgehammer_Status {
|
820 |
def apply(message: String): JSON.T = |
|
821 |
Notification("PIDE/sledgehammer_status", JSON.Object("message" -> message))
|
|
822 |
} |
|
823 |
||
824 |
object Sledgehammer_Output {
|
|
825 |
def apply(json: JSON.Object.T): JSON.T = |
|
826 |
Notification("PIDE/sledgehammer_output", json)
|
|
827 |
} |
|
828 |
||
| 83414 | 829 |
object Sledgehammer_Cancel extends Notification0("PIDE/sledgehammer_cancel")
|
|
83363
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
830 |
|
|
83416
c7849fa2ece0
more direct sledgehammer "locate" operation via official Query_Operation interface;
wenzelm
parents:
83414
diff
changeset
|
831 |
object Sledgehammer_Locate extends Notification0("PIDE/sledgehammer_locate")
|
|
c7849fa2ece0
more direct sledgehammer "locate" operation via official Query_Operation interface;
wenzelm
parents:
83414
diff
changeset
|
832 |
|
| 83421 | 833 |
object Sledgehammer_Insert extends Notification0("PIDE/sledgehammer_insert")
|
|
83363
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
834 |
|
| 83410 | 835 |
object Sledgehammer_Insert_Position_Response {
|
| 83379 | 836 |
def apply(json: JSON.Object.T): JSON.T = |
837 |
Notification("PIDE/sledgehammer_insert_position_response", json)
|
|
|
83363
486e094b676c
various improvements of Isabelle/VSCode: original changeset by Diana Korchmar, LMU München;
wenzelm
parents:
81084
diff
changeset
|
838 |
} |
| 64605 | 839 |
} |