- public void onNotification(string method, Variant? return_value)
- {
- switch (method) {
- case "textDocument/publishDiagnostics":
- this.onDiagnostic(return_value);
- return;
- default:
- break;
-
- }
- GLib.debug("got notification %s : %s", method , Json.to_string (Json.gvariant_serialize (return_value), true));
-
- }
-
- /***
-
- */
- public void onDiagnostic(Variant? return_value)
- {
-
- var dg = Json.gobject_deserialize (typeof (Lsp.Diagnostics), Json.gvariant_serialize (return_value)) as Lsp.Diagnostics;
- this.log(LanguageClientAction.DIAG, dg.filename);
- var f = this.project.getByPath(dg.filename);
- if (f == null) {
- //GLib.debug("no file %s", dg.uri);
- this.project.updateErrorsforFile(null);
- return;
- }
- foreach(var v in f.errorsByType.values) {
- v.remove_all();
- }
- foreach(var diag in dg.diagnostics) {
- var ce = new CompileError.new_from_diagnostic(f, diag);
- if (!f.errorsByType.has_key(ce.category)) {
- f.errorsByType.set(ce.category, new GLib.ListStore(typeof(CompileError)));
- }
- f.errorsByType.get(ce.category).append(ce);
- }
- f.project.updateErrorsforFile(f);
-
- }
-
- public void document_open (JsRender.JsRender file)
- {
- if (!this.isReady()) {
- return;
- }
- if (!this.open_files.contains(file)) {
- this.open_files.add(file);
- }
-
- GLib.debug ("LS sent open");
- try {
- this.jsonrpc_client.send_notification (
- "textDocument/didOpen",
- this.buildDict (
- textDocument : this.buildDict (
- uri: new Variant.string (file.to_url()),
- languageId : new Variant.string (file.language_id()),
- version : new GLib.Variant.uint64 ( (uint64) file.version),
- text : new Variant.string (file.toSource())
- )
- ),
- null
- );
- this.log(LanguageClientAction.OPEN, file.path);
- } catch( GLib.Error e) {
- this.log(LanguageClientAction.ERROR_RPC, e.message);
- this.onClose();
- GLib.debug ("LS sent open err %s", e.message);
- }
-
- }
-
- public void document_save (JsRender.JsRender file)
- {
- if (!this.isReady()) {
- return;
- }
- this.change_queue_file = null;
- GLib.debug ("LS send save");
- try {
- this.jsonrpc_client.send_notification (
- "textDocument/didChange",
- this.buildDict (
- textDocument : this.buildDict ( ///TextDocumentItem;
- uri: new GLib.Variant.string (file.to_url()),
- version : new GLib.Variant.uint64 ( (uint64) file.version)
- )
- ),
- null
- );
- this.log(LanguageClientAction.SAVE, file.path);
- } catch( GLib.Error e) {
- this.log(LanguageClientAction.ERROR_RPC, e.message);
- GLib.debug ("LS save err %s", e.message);
- this.onClose();
- }
-
-
- }
- public void document_close (JsRender.JsRender file)
- {
- if (!this.isReady()) {
- return;
- }
- this.change_queue_file = null;
-
- if (this.open_files.contains(file)) {
- this.open_files.remove(file);
- }
- this.log(LanguageClientAction.CLOSE, file.path);
- GLib.debug ("LS send close");
- try {
- this.jsonrpc_client.send_notification (
- "textDocument/didChange",
- this.buildDict (
- textDocument : this.buildDict ( ///TextDocumentItem;
- uri: new GLib.Variant.string (file.to_url())
-
- )
- ),
- null
- );
- } catch( GLib.Error e) {
- this.log(LanguageClientAction.ERROR_RPC, e.message);
- GLib.debug ("LS close err %s", e.message);
- this.onClose();
- }
-
-
- }
-
-
- public void document_change (JsRender.JsRender file )
- {
- if (this.change_queue_file != null && this.change_queue_file.path != file.path) {
- this.document_change_real(this.change_queue_file, this.change_queue_file_source);
- }
-
- this.countdown = 3;
- this.change_queue_file = file;
-
-
-
- }
-
-
- public void document_change_real (JsRender.JsRender file, string contents)
- {
- if (!this.isReady()) {
- return;
- }
-
-
- GLib.debug ("LS send change");
- var ar = new Json.Array();
- var obj = new Json.Object();
- obj.set_string_member("text", contents);
- ar.add_object_element(obj);
- var node = new Json.Node(Json.NodeType.ARRAY);
- node.set_array(ar);
- this.log(LanguageClientAction.CHANGE, file.path);
- try {
- this.jsonrpc_client.send_notification (
- "textDocument/didChange",
- this.buildDict (
- textDocument : this.buildDict ( ///TextDocumentItem;
- uri: new GLib.Variant.string (file.to_url()),
- version : new GLib.Variant.uint64 ( (uint64) file.version)
- ),
- contentChanges : Json.gvariant_deserialize (node, null)
-
- ),
- null
- );
- } catch( GLib.Error e) {
- this.log(LanguageClientAction.ERROR_RPC, e.message);
- GLib.debug ("LS change err %s", e.message);
- this.onClose();
- }
-
-
- }
- // called by close window (on last window)...
- public void exit () throws GLib.Error
- {
- if (!this.isReady()) {
-
- return;
- }
- this.log(LanguageClientAction.TERM, "SEND exit");
-
- this.jsonrpc_client.send_notification (
- "exit",
- null,
- null
- );
- this.onClose();
-
- }
- // not used currently..
- public async void shutdown () throws GLib.Error
- {
- if (!this.isReady()) {
- return;
- }
- this.log(LanguageClientAction.TERM, "SEND shutodwn");
- this.sent_shutdown = true;
- Variant? return_value;
- yield this.jsonrpc_client.call_async (
- "shutdown",
- null,
- null,
- out return_value
- );
- GLib.debug ("LS replied with %s", Json.to_string (Json.gvariant_serialize (return_value), true));
- }
- //public async ??/symbol (string symbol) throws GLib.Error {