Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintain order of DiagnosticRelatedInformation objects in Diagnostic.relatedInformation #63710

Closed
vector-of-bool opened this issue Nov 24, 2018 · 7 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug error-list Problems view verified Verification succeeded
Milestone

Comments

@vector-of-bool
Copy link

Hello! Thank you for all your hard work!

This is a request regarding the diagnostics API. I was watching closely for #10271, and this may relate to some usages of #1927.

I'm not sure if this is "by design" or just incidental to the way it was implemented, but the ordering of items in the relatedInformation array property of vscode.Diagnostic objects seems to be ignored when VSCode displays this information in the problems panel.

It seems that the ordering within a single file is honored, but related information objects from different files are not ordered relative to each other.

On a barely related note: Is there any push for arbitrary hierarchies of diagnostics?

@jrieken jrieken assigned sandy081 and unassigned jrieken Nov 26, 2018
@sandy081
Copy link
Member

@vector-of-bool Can you please provide us an example for related informations from different files and what is the expected order to be?

@sandy081 sandy081 added info-needed Issue requires more information from poster error-list Problems view languages-diagnostics Source problems reporting labels Nov 26, 2018
@vector-of-bool
Copy link
Author

vector-of-bool commented Nov 27, 2018

Here's an example:

selection_035

Here's the relevant code snippet which generates this information:

const diags = vscode.languages.createDiagnosticCollection('repro-with-related');
const diag = new vscode.Diagnostic(new vscode.Range(0, 0, 999, 999), 'I am an example diagnostic');
diag.relatedInformation = [];
const files = ['file1', 'file2', 'file3'];
for (const i of [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) {
    const related = new vscode.DiagnosticRelatedInformation(
        new vscode.Location(
            vscode.Uri.file(files[i % files.length]),
            new vscode.Position(10, 40),
        ),
        `Message number ${i}`,
    );
    diag.relatedInformation.push(related);
}
diags.set(vscode.Uri.file('file.txt'), [diag]);

Looking at it, it appears to sort them first lexicographically by filename, then by original insertion order. Calling diag.relatedInformation.reverse() before diags.set produces this order:

selection_036

My intuition is that the original order of the relatedInformation array object would be preserved.

I am also seeing that sometimes a large amount of relatedInformation can produce wacky layouts in the tree view, but that is probably a different issue.

Also, here's a minimal extension that will reproduce this:

diag-related-order-repro.zip

@sandy081
Copy link
Member

Should the source of these diagnostics give this information in the correct order? Since it is related info, the source has more context to provide the right order.

@vector-of-bool
Copy link
Author

In my real use case, I'm generating the relatedInformation array from the output of a tool (a compiler), so I do have the order. Between multiple files that order is not maintained in the problems view.

@fredriklengstrand
Copy link

Hi,

First I just wanted to say thank you for creating this project and it's excellent extension support.

Now, onto the topic of my response, I'm facing the same issue as well. I'm trying to use the relatedInformation array to show the whole include chain for a file that generated an error in our linter (so you can follow it from the entry point up to where the error was generated). This of course gets quite confusing if you cannot control the order in which the entries appear. One thing I noticed was that it seems like the hover provider does keeps the original order intact when displaying the relatedInformation array.

Here are some screenshots of what I'm working on to maybe better illustrate my use case:

Incorrect order in problems tab:
screenshot 2018-11-27 at 21 34 54

Correct order in hover provider:
screenshot 2018-11-27 at 21 34 46

@sandy081 sandy081 added bug Issue identified by VS Code Team member as probable bug and removed languages-diagnostics Source problems reporting info-needed Issue requires more information from poster labels Nov 29, 2018
@sandy081 sandy081 added this to the November 2018 milestone Nov 29, 2018
@sandy081
Copy link
Member

Yes, I can repro it. Problems view is changing the order. Fixed.

@vector-of-bool
Copy link
Author

I thank you kindly for the prompt fix!

@mjbvz mjbvz added the verified Verification succeeded label Dec 6, 2018
@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug error-list Problems view verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

5 participants