Skip to content

Commit 204f8b6

Browse files
committed
default to project root URI for diagnostics (#169)
If a diagnostic is not associated with a file, associate it with the project root folder, rather than sending "null"
1 parent 4f7e35a commit 204f8b6

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/server.vala

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ class Vls.Server : Object {
344344
project.build_if_stale ();
345345
debug ("Publishing diagnostics ...");
346346
foreach (var compilation in project.get_compilations ())
347-
publishDiagnostics (compilation, client);
347+
publishDiagnostics (project, compilation, client);
348348
} catch (Error e) {
349349
showMessage (client, @"Failed to build project - $(e.message)", MessageType.Error);
350350
}
@@ -606,7 +606,7 @@ class Vls.Server : Object {
606606
* one of our JSON-RPC callbacks through g_main_context_iteration (),
607607
* if we get a new message while sending the textDocument/publishDiagnostics
608608
* notifications. */
609-
publishDiagnostics (compilation, update_context_client);
609+
publishDiagnostics (project, compilation, update_context_client);
610610
} catch (Error e) {
611611
warning ("Failed to rebuild and/or reconfigure project: %s", e.message);
612612
}
@@ -661,7 +661,7 @@ class Vls.Server : Object {
661661
}
662662
}
663663

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

@@ -675,6 +675,16 @@ class Vls.Server : Object {
675675
target.reporter.messages.foreach (err => {
676676
if (err.loc == null) {
677677
diags_without_source.add_element (Json.gobject_serialize (new Diagnostic () {
678+
range = new Range () {
679+
start = new Position () {
680+
line = 1,
681+
character = 1
682+
},
683+
end = new Position () {
684+
line = 1,
685+
character = 1
686+
}
687+
},
678688
severity = err.severity,
679689
message = err.message
680690
}));
@@ -774,6 +784,8 @@ class Vls.Server : Object {
774784
client.send_notification (
775785
"textDocument/publishDiagnostics",
776786
buildDict (
787+
// use the project root as the URI if the diagnostic is not associated with a file
788+
uri: new Variant.string (File.new_for_path(project.root_path).get_uri ()),
777789
diagnostics: diags_wo_src_variant_array
778790
),
779791
cancellable);

0 commit comments

Comments
 (0)