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

Fadeout based on roslyn tag 'unnecessary'. #2873

Merged
merged 60 commits into from
Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
582e745
Initial prototype.
savpek Feb 24, 2019
d09f936
Merge from master.
savpek Feb 24, 2019
45630c2
Tweaks.
savpek Feb 24, 2019
816c178
Updates and tweaks.
savpek Feb 24, 2019
5c3b0b2
Rethinked how diagnostics should be handled a bit.
savpek Feb 24, 2019
d8e3266
Fixes.
savpek Feb 24, 2019
d655061
Refactoring.
savpek Feb 25, 2019
e01ce48
Removed hard coded CS diagnostics.
savpek Feb 26, 2019
624190d
Merge branch 'master' into feature/fadeout-with-roslyn-diag
savpek Mar 2, 2019
a3e0d5f
Merge branch 'master' into feature/fadeout-with-roslyn-diag
savpek Mar 14, 2019
8093eab
Merge branch 'master' into feature/fadeout-with-roslyn-diag
savpek Mar 17, 2019
80ae3fc
Merge branch 'master' into feature/fadeout-with-roslyn-diag
savpek Mar 19, 2019
dda8586
Merge upstream/master.
savpek Mar 20, 2019
3f9e955
Merge branch 'master' into feature/fadeout-with-roslyn-diag
savpek Mar 22, 2019
d8526c4
Merge branch 'master' into feature/fadeout-with-roslyn-diag
savpek Mar 30, 2019
6f8e1bd
Trigger build.
savpek Apr 5, 2019
358abbe
Merge branch 'master' into feature/fadeout-with-roslyn-diag
savpek Apr 8, 2019
eea2114
Renamed badly named variables.
savpek Apr 8, 2019
c2f32b8
Merge branch 'feature/fadeout-with-roslyn-diag' of https://github.com…
savpek Apr 8, 2019
b2b2da0
Added dummy diagnostic integration test.
savpek Apr 8, 2019
bbf41ab
Test that actually returns diagnostics.
savpek Apr 8, 2019
f5ade23
Updates for diagnostic tests.
savpek Apr 10, 2019
8422d3d
Updates for diagnostic.cs
savpek Apr 10, 2019
c8e8dd2
Added test that fadeout diagnostics are returned.
savpek Apr 10, 2019
7a24182
Implemented version without 'suppressHiddenDiagnostics' and returned …
savpek Apr 10, 2019
3630b1d
Moved omnisharp config before host init.
savpek Apr 10, 2019
19ffdbc
Merge branch 'master' into feature/fadeout-with-roslyn-diag
savpek Apr 11, 2019
8925593
Revert "Implemented version without 'suppressHiddenDiagnostics' and r…
savpek Apr 11, 2019
8a1b06b
Hardcoded non analyzer ones.
savpek Apr 11, 2019
9d04cc7
supress now supresses hint instead of original information level.
savpek Apr 11, 2019
789acb0
Merge branch 'feature/fadeout-with-roslyn-diag' of https://github.com…
savpek Apr 11, 2019
7dab7f0
Merge branch 'master' into feature/fadeout-with-roslyn-diag
savpek Apr 12, 2019
8e9a2af
Merge branch 'master' into feature/fadeout-with-roslyn-diag
savpek Apr 13, 2019
9f46187
Testing to set enableRoslynAnalyzers as default.
savpek Apr 13, 2019
dd960c6
Merge branch 'feature/fadeout-with-roslyn-diag' of https://github.com…
savpek Apr 13, 2019
c78770a
Few small review fixes.
savpek Apr 13, 2019
56e2514
Refactoring based on review.
savpek Apr 13, 2019
faf036b
Added enableRoslynAnalyzers as test default.
savpek Apr 13, 2019
4b0164d
Testing build.
savpek Apr 13, 2019
bd08a84
Attempt to fix tests.
savpek Apr 13, 2019
4329a12
Disabled analyzers and linked issue.
savpek Apr 14, 2019
1aa2f4c
Rebuild and restored subtle change.
savpek Apr 14, 2019
dc55430
Fixed invalid skip method.
savpek Apr 14, 2019
eeba8d3
Removed excess dot.
savpek Apr 14, 2019
7360718
Refactored rename test to use same routines as other tests.
savpek Apr 14, 2019
a036453
Merge branch 'master' into feature/fadeout-with-roslyn-diag
savpek Apr 16, 2019
6afd672
Merge branch 'master' into feature/fadeout-with-roslyn-diag
savpek Apr 26, 2019
2e54378
Test build.
savpek Apr 27, 2019
ba94620
Merge branch 'master' into feature/fadeout-with-roslyn-diag
savpek Apr 28, 2019
f592a9f
Merge branch 'master' into feature/fadeout-with-roslyn-diag
savpek May 5, 2019
3641770
Merge branch 'master' into feature/fadeout-with-roslyn-diag
savpek May 7, 2019
e7285f5
Merge branch 'master' into feature/fadeout-with-roslyn-diag
savpek May 18, 2019
7cd8334
Merge branch 'master' into feature/fadeout-with-roslyn-diag
savpek May 22, 2019
778191e
Merge branch 'master' into feature/fadeout-with-roslyn-diag
savpek May 25, 2019
5b59092
Merge branch 'master' into feature/fadeout-with-roslyn-diag
savpek May 30, 2019
1e85ed4
Merge branch 'master' into feature/fadeout-with-roslyn-diag
akshita31 Jun 7, 2019
f5f293c
Merge branch 'master' into feature/fadeout-with-roslyn-diag
akshita31 Jun 7, 2019
0537553
Merge branch 'master' into feature/fadeout-with-roslyn-diag
savpek Jun 8, 2019
a9920ec
Rebuild.
savpek Jun 9, 2019
cfad848
Rebuild.
savpek Jun 9, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 46 additions & 27 deletions src/features/diagnosticsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class DiagnosticsProvider extends AbstractSupport {
let handle = setTimeout(async () => {
try {
let value = await serverUtils.codeCheck(this._server, { FileName: document.fileName }, source.token);
let quickFixes = value.QuickFixes.filter(DiagnosticsProvider._shouldInclude);
let quickFixes = value.QuickFixes;
// Easy case: If there are no diagnostics in the file, we can clear it quickly.
if (quickFixes.length === 0) {
if (this._diagnostics.has(document.uri)) {
Expand All @@ -247,8 +247,9 @@ class DiagnosticsProvider extends AbstractSupport {
}

// (re)set new diagnostics for this document
let diagnostics = quickFixes.map(DiagnosticsProvider._asDiagnostic);
this._diagnostics.set(document.uri, diagnostics);
let diagnostics = this._mapQuickFixesAsDiagnostics(quickFixes);

this._diagnostics.set(document.uri, diagnostics.map(x => x.diag));
}
catch (error) {
return;
Expand All @@ -259,6 +260,13 @@ class DiagnosticsProvider extends AbstractSupport {
this._documentValidations[key] = source;
}

private _mapQuickFixesAsDiagnostics(quickFixes: protocol.QuickFix[]): { diag: vscode.Diagnostic, fileName: string }[]
{
return quickFixes
.map(qf => ({ diag: this._asDiagnostic(qf), fileName: qf.FileName }))
.filter(item => item.diag !== undefined);
savpek marked this conversation as resolved.
Show resolved Hide resolved
}

private _validateProject(): void {
// If we've already started computing for this project, cancel that work.
if (this._projectValidation) {
Expand All @@ -275,25 +283,22 @@ class DiagnosticsProvider extends AbstractSupport {
let value = await serverUtils.codeCheck(this._server, { FileName: null }, this._projectValidation.token);

let quickFixes = value.QuickFixes
.filter(DiagnosticsProvider._shouldInclude)
.sort((a, b) => a.FileName.localeCompare(b.FileName));

let entries: [vscode.Uri, vscode.Diagnostic[]][] = [];
let lastEntry: [vscode.Uri, vscode.Diagnostic[]];

for (let quickFix of quickFixes) {

let diag = DiagnosticsProvider._asDiagnostic(quickFix);
let uri = vscode.Uri.file(quickFix.FileName);
for (let quickFix of this._mapQuickFixesAsDiagnostics(quickFixes)) {
akshita31 marked this conversation as resolved.
Show resolved Hide resolved
let uri = vscode.Uri.file(quickFix.fileName);

if (lastEntry && lastEntry[0].toString() === uri.toString()) {
lastEntry[1].push(diag);
lastEntry[1].push(quickFix.diag);
} else {
// We're replacing all diagnostics in this file. Pushing an entry with undefined for
// the diagnostics first ensures that the previous diagnostics for this file are
// cleared. Otherwise, new entries will be merged with the old ones.
entries.push([uri, undefined]);
lastEntry = [uri, [diag]];
lastEntry = [uri, [quickFix.diag]];
entries.push(lastEntry);
}
}
Expand All @@ -319,36 +324,50 @@ class DiagnosticsProvider extends AbstractSupport {
});
}

private static _shouldInclude(quickFix: protocol.QuickFix): boolean {
const config = vscode.workspace.getConfiguration('csharp');
akshita31 marked this conversation as resolved.
Show resolved Hide resolved
if (config.get('suppressHiddenDiagnostics', true)) {
return quickFix.LogLevel.toLowerCase() !== 'hidden';
} else {
return true;
private _asDiagnostic(quickFix: protocol.QuickFix): vscode.Diagnostic | undefined {
let isFadeout = (quickFix.Tags && !!quickFix.Tags.find(x => x.toLowerCase() == 'unnecessary'));

let severity = this._asDiagnosticSeverity(quickFix, isFadeout);

if(severity === undefined)
savpek marked this conversation as resolved.
Show resolved Hide resolved
{
return undefined;
}
}

// --- data converter
let message = `${quickFix.Text} [${quickFix.Projects.map(n => this._asProjectLabel(n)).join(', ')}]`;

private static _asDiagnostic(quickFix: protocol.QuickFix): vscode.Diagnostic {
let severity = DiagnosticsProvider._asDiagnosticSeverity(quickFix.LogLevel);
let message = `${quickFix.Text} [${quickFix.Projects.map(n => DiagnosticsProvider._asProjectLabel(n)).join(', ')}]`;
return new vscode.Diagnostic(toRange(quickFix), message, severity);
let diagnostic = new vscode.Diagnostic(toRange(quickFix), message, severity);

if(isFadeout)
savpek marked this conversation as resolved.
Show resolved Hide resolved
{
diagnostic.tags = [vscode.DiagnosticTag.Unnecessary];
}

return diagnostic;
}

private static _asDiagnosticSeverity(logLevel: string): vscode.DiagnosticSeverity {
switch (logLevel.toLowerCase()) {
private _asDiagnosticSeverity(quickFix: protocol.QuickFix, fadeOut: boolean): vscode.DiagnosticSeverity | undefined {
if(fadeOut && quickFix.LogLevel.toLowerCase() === 'hidden' || quickFix.LogLevel.toLowerCase() === 'none')
savpek marked this conversation as resolved.
Show resolved Hide resolved
{
// Theres no such thing as hidden severity in VSCode,
// however roslyn uses commonly analyzer with hidden to fade out things.
// Without this any of those doesn't fade anything in vscode.
return vscode.DiagnosticSeverity.Hint;
}

switch (quickFix.LogLevel.toLowerCase()) {
case 'error':
return vscode.DiagnosticSeverity.Error;
case 'warning':
return vscode.DiagnosticSeverity.Warning;
// info and hidden
default:
case 'info':
return vscode.DiagnosticSeverity.Information;
default:
return undefined;
savpek marked this conversation as resolved.
Show resolved Hide resolved
}
}

private static _asProjectLabel(projectName: string): string {
private _asProjectLabel(projectName: string): string {
const idx = projectName.indexOf('+');
return projectName.substr(idx + 1);
}
Expand Down
2 changes: 2 additions & 0 deletions src/omnisharp/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ export interface QuickFix {
EndColumn: number;
Text: string;
Projects: string[];
Tags: string[];
Id: string;
}

export interface SymbolLocation extends QuickFix {
Expand Down