Skip to content

Commit

Permalink
default to project root URI for diagnostics (#169)
Browse files Browse the repository at this point in the history
If a diagnostic is not associated with a file, associate it with the
project root folder, rather than sending "null"
  • Loading branch information
Prince781 committed Mar 5, 2021
1 parent 4f7e35a commit 204f8b6
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/server.vala
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ class Vls.Server : Object {
project.build_if_stale ();
debug ("Publishing diagnostics ...");
foreach (var compilation in project.get_compilations ())
publishDiagnostics (compilation, client);
publishDiagnostics (project, compilation, client);
} catch (Error e) {
showMessage (client, @"Failed to build project - $(e.message)", MessageType.Error);
}
Expand Down Expand Up @@ -606,7 +606,7 @@ class Vls.Server : Object {
* one of our JSON-RPC callbacks through g_main_context_iteration (),
* if we get a new message while sending the textDocument/publishDiagnostics
* notifications. */
publishDiagnostics (compilation, update_context_client);
publishDiagnostics (project, compilation, update_context_client);
} catch (Error e) {
warning ("Failed to rebuild and/or reconfigure project: %s", e.message);
}
Expand Down Expand Up @@ -661,7 +661,7 @@ class Vls.Server : Object {
}
}

void publishDiagnostics (Compilation target, Jsonrpc.Client client) {
void publishDiagnostics (Project project, Compilation target, Jsonrpc.Client client) {
var files_not_published = new HashSet<Vala.SourceFile> (Util.source_file_hash, Util.source_file_equal);
var diags_without_source = new Json.Array ();

Expand All @@ -675,6 +675,16 @@ class Vls.Server : Object {
target.reporter.messages.foreach (err => {
if (err.loc == null) {
diags_without_source.add_element (Json.gobject_serialize (new Diagnostic () {
range = new Range () {
start = new Position () {
line = 1,
character = 1
},
end = new Position () {
line = 1,
character = 1
}
},
severity = err.severity,
message = err.message
}));
Expand Down Expand Up @@ -774,6 +784,8 @@ class Vls.Server : Object {
client.send_notification (
"textDocument/publishDiagnostics",
buildDict (
// use the project root as the URI if the diagnostic is not associated with a file
uri: new Variant.string (File.new_for_path(project.root_path).get_uri ()),
diagnostics: diags_wo_src_variant_array
),
cancellable);
Expand Down

0 comments on commit 204f8b6

Please sign in to comment.