From 36182572c18fa153834f24f1206c896a07b9344d Mon Sep 17 00:00:00 2001 From: Dryadxon <81884588+Dryadxon@users.noreply.github.com> Date: Wed, 14 Sep 2022 03:16:32 +0200 Subject: [PATCH 1/2] Fix #5171 Replaced the deprecated ProjectDiagnosticStatus event with the newer BackgroundDiagnosticStatus. Now BackgroundWorkStatusBarObserver no longer shows the path to the project file, but this shouldn't be a big deal. --- src/features/diagnosticsProvider.ts | 10 +++++----- .../BackgroundWorkStatusBarObserver.ts | 15 +++++++------- src/omnisharp/EventType.ts | 3 ++- src/omnisharp/loggingEvents.ts | 6 +++--- src/omnisharp/protocol.ts | 16 ++++++++------- src/omnisharp/server.ts | 10 +++++----- .../reAnalyze.integration.test.ts | 20 +++++++++---------- .../integrationTests/testAssets/testAssets.ts | 2 +- .../BackgroundWorkStatusBarObserver.test.ts | 12 +++++------ 9 files changed, 49 insertions(+), 45 deletions(-) diff --git a/src/features/diagnosticsProvider.ts b/src/features/diagnosticsProvider.ts index c45b6c4ad..3dc0a5033 100644 --- a/src/features/diagnosticsProvider.ts +++ b/src/features/diagnosticsProvider.ts @@ -16,7 +16,7 @@ import { TextDocument } from '../vscodeAdapter'; import OptionProvider from '../observers/OptionProvider'; import { Subject, Subscription } from 'rxjs'; import { debounceTime } from 'rxjs/operators'; -import { DiagnosticStatus } from '../omnisharp/protocol'; +import { BackgroundDiagnosticStatus } from '../omnisharp/protocol'; import { LanguageMiddlewareFeature } from '../omnisharp/LanguageMiddlewareFeature'; export class Advisor { @@ -154,7 +154,7 @@ class DiagnosticsProvider extends AbstractSupport { this._disposable = new CompositeDisposable(this._diagnostics, this._server.onPackageRestore(() => this._validateAllPipe.next("onPackageRestore"), this), this._server.onProjectChange(() => this._validateAllPipe.next("onProjectChanged"), this), - this._server.onProjectDiagnosticStatus(this._onProjectAnalysis, this), + this._server.onBackgroundDiagnosticStatus(this._onBackgroundAnalysis, this), vscode.workspace.onDidOpenTextDocument(event => this._onDocumentOpenOrChange(event), this), vscode.workspace.onDidChangeTextDocument(event => this._onDocumentOpenOrChange(event.document), this), vscode.workspace.onDidCloseTextDocument(this._onDocumentClose, this), @@ -210,9 +210,9 @@ class DiagnosticsProvider extends AbstractSupport { } } - private _onProjectAnalysis(event: protocol.ProjectDiagnosticStatus) { - if (event.Status == DiagnosticStatus.Ready && - event.ProjectFilePath === "(100 %)") { + private _onBackgroundAnalysis(event: protocol.BackgroundDiagnosticStatusMessage) { + if (event.Status == BackgroundDiagnosticStatus.Finished && + event.NumberFilesRemaining === 0) { this._validateAllPipe.next(); } } diff --git a/src/observers/BackgroundWorkStatusBarObserver.ts b/src/observers/BackgroundWorkStatusBarObserver.ts index 46cddee14..84c2ed532 100644 --- a/src/observers/BackgroundWorkStatusBarObserver.ts +++ b/src/observers/BackgroundWorkStatusBarObserver.ts @@ -4,18 +4,19 @@ *--------------------------------------------------------------------------------------------*/ import { BaseStatusBarItemObserver } from './BaseStatusBarItemObserver'; -import { BaseEvent, OmnisharpProjectDiagnosticStatus } from '../omnisharp/loggingEvents'; +import { BaseEvent, OmnisharpBackgroundDiagnosticStatus } from '../omnisharp/loggingEvents'; import { EventType } from '../omnisharp/EventType'; -import { DiagnosticStatus } from '../omnisharp/protocol'; +import { BackgroundDiagnosticStatus } from '../omnisharp/protocol'; export class BackgroundWorkStatusBarObserver extends BaseStatusBarItemObserver { public post = (event: BaseEvent) => { - if (event.type === EventType.ProjectDiagnosticStatus) { - let asProjectEvent = event; + if (event.type === EventType.BackgroundDiagnosticStatus) { + let asProjectEvent = event; - if (asProjectEvent.message.Status === DiagnosticStatus.Processing) { - let projectFile = asProjectEvent.message.ProjectFilePath.replace(/^.*[\\\/]/, ''); - this.SetAndShowStatusBar(`$(sync~spin) Analyzing ${projectFile}`, 'o.showOutput', undefined, `Analyzing ${projectFile}`); + if (asProjectEvent.message.Status !== BackgroundDiagnosticStatus.Finished) { + let {NumberFilesRemaining, NumberFilesTotal} = asProjectEvent.message; + let message = `Analyzing ${NumberFilesTotal} files - Remaining ${NumberFilesRemaining} files`; + this.SetAndShowStatusBar(`$(sync~spin) ${message}`, 'o.showOutput', null, `${message}`); } else { this.ResetAndHideStatusBar(); diff --git a/src/omnisharp/EventType.ts b/src/omnisharp/EventType.ts index 4f8c2514f..4d7d64d07 100644 --- a/src/omnisharp/EventType.ts +++ b/src/omnisharp/EventType.ts @@ -79,11 +79,12 @@ export enum EventType { OmnisharpServerOnStart = 72, OmnisharpOnBeforeServerInstall = 73, ProjectConfigurationReceived = 74, - ProjectDiagnosticStatus = 75, + ProjectDiagnosticStatus = 75, // Obsolete, use BackgroundDiagnosticStatus DotNetTestRunInContextStart = 76, DotNetTestDebugInContextStart = 77, TelemetryErrorEvent = 78, OmnisharpServerRequestCancelled = 79, + BackgroundDiagnosticStatus = 80, } //Note that the EventType protocol is shared with Razor.VSCode and the numbers here should not be altered diff --git a/src/omnisharp/loggingEvents.ts b/src/omnisharp/loggingEvents.ts index b67b40ffb..f469d4766 100644 --- a/src/omnisharp/loggingEvents.ts +++ b/src/omnisharp/loggingEvents.ts @@ -98,9 +98,9 @@ export class OmnisharpServerOnError implements BaseEvent { constructor(public errorMessage: protocol.ErrorMessage) { } } -export class OmnisharpProjectDiagnosticStatus implements BaseEvent { - type = EventType.ProjectDiagnosticStatus; - constructor(public message: protocol.ProjectDiagnosticStatus) { } +export class OmnisharpBackgroundDiagnosticStatus implements BaseEvent { + type = EventType.BackgroundDiagnosticStatus; + constructor(public message: protocol.BackgroundDiagnosticStatusMessage) { } } export class OmnisharpServerMsBuildProjectDiagnostics implements BaseEvent { diff --git a/src/omnisharp/protocol.ts b/src/omnisharp/protocol.ts index 0e0c45720..87ba5092a 100644 --- a/src/omnisharp/protocol.ts +++ b/src/omnisharp/protocol.ts @@ -285,15 +285,17 @@ export interface ProjectInformationResponse { MsBuildProject: MSBuildProject; } -export enum DiagnosticStatus { - Processing = 0, - Ready = 1 +export enum BackgroundDiagnosticStatus { + Started = 0, + Progress = 1, + Finished = 2 } -export interface ProjectDiagnosticStatus { - Status: DiagnosticStatus; - ProjectFilePath: string; - Type: "background"; +export interface BackgroundDiagnosticStatusMessage { + Status: BackgroundDiagnosticStatus; + NumberProjects: number; + NumberFilesTotal: number; + NumberFilesRemaining: number; } export interface WorkspaceInformationResponse { diff --git a/src/omnisharp/server.ts b/src/omnisharp/server.ts index a0bdda575..bf984a099 100644 --- a/src/omnisharp/server.ts +++ b/src/omnisharp/server.ts @@ -69,7 +69,7 @@ module Events { export const ProjectAdded = 'ProjectAdded'; export const ProjectRemoved = 'ProjectRemoved'; - export const ProjectDiagnosticStatus = 'ProjectDiagnosticStatus'; + export const BackgroundDiagnosticStatus = 'BackgroundDiagnosticStatus'; export const MsBuildProjectDiagnostics = 'MsBuildProjectDiagnostics'; @@ -218,8 +218,8 @@ export class OmniSharpServer { return this._addListener(Events.ProjectRemoved, listener, thisArg); } - public onProjectDiagnosticStatus(listener: (e: protocol.ProjectDiagnosticStatus) => any, thisArg?: any) { - return this._addListener(Events.ProjectDiagnosticStatus, listener, thisArg); + public onBackgroundDiagnosticStatus(listener: (e: protocol.BackgroundDiagnosticStatusMessage) => any, thisArg?: any) { + return this._addListener(Events.BackgroundDiagnosticStatus, listener, thisArg); } public onMsBuildProjectDiagnostics(listener: (e: protocol.MSBuildProjectDiagnostics) => any, thisArg?: any) { @@ -319,8 +319,8 @@ export class OmniSharpServer { this.eventStream.post(new ObservableEvents.OmnisharpServerOnStart()); })); - disposables.add(this.onProjectDiagnosticStatus((message: protocol.ProjectDiagnosticStatus) => - this.eventStream.post(new ObservableEvents.OmnisharpProjectDiagnosticStatus(message)) + disposables.add(this.onBackgroundDiagnosticStatus((message: protocol.BackgroundDiagnosticStatusMessage) => + this.eventStream.post(new ObservableEvents.OmnisharpBackgroundDiagnosticStatus(message)) )); disposables.add(this.onProjectConfigurationReceived((message: protocol.ProjectConfigurationMessage) => { diff --git a/test/integrationTests/reAnalyze.integration.test.ts b/test/integrationTests/reAnalyze.integration.test.ts index a014c9723..324a689dc 100644 --- a/test/integrationTests/reAnalyze.integration.test.ts +++ b/test/integrationTests/reAnalyze.integration.test.ts @@ -12,8 +12,8 @@ import testAssetWorkspace from './testAssets/testAssetWorkspace'; import { poll, assertWithPoll } from './poll'; import { EventStream } from '../../src/EventStream'; import { EventType } from '../../src/omnisharp/EventType'; -import { BaseEvent, OmnisharpProjectDiagnosticStatus } from '../../src/omnisharp/loggingEvents'; -import { DiagnosticStatus } from '../../src/omnisharp/protocol'; +import { BaseEvent, OmnisharpBackgroundDiagnosticStatus } from '../../src/omnisharp/loggingEvents'; +import { BackgroundDiagnosticStatus } from '../../src/omnisharp/protocol'; const chai = require('chai'); chai.use(require('chai-arrays')); @@ -63,7 +63,7 @@ suite(`ReAnalyze: ${testAssetWorkspace.description}`, function () { }); test("When interface is manually renamed, then return correct analysis after re-analysis of project", async function () { - let diagnosticStatusEvents = listenEvents(eventStream, EventType.ProjectDiagnosticStatus); + let diagnosticStatusEvents = listenEvents(eventStream, EventType.BackgroundDiagnosticStatus); await vscode.commands.executeCommand("vscode.open", interfaceUri); @@ -73,7 +73,7 @@ suite(`ReAnalyze: ${testAssetWorkspace.description}`, function () { await vscode.commands.executeCommand('o.reanalyze.currentProject', interfaceImplUri); - await poll(() => diagnosticStatusEvents, 15 * 1000, 500, r => r.find(x => x.message.Status === DiagnosticStatus.Ready) !== undefined); + await poll(() => diagnosticStatusEvents, 15 * 1000, 500, r => r.find(x => x.message.Status === BackgroundDiagnosticStatus.Finished) !== undefined); await assertWithPoll( () => vscode.languages.getDiagnostics(interfaceImplUri), @@ -83,20 +83,20 @@ suite(`ReAnalyze: ${testAssetWorkspace.description}`, function () { }); test("When re-analyze of project is executed then eventually get notified about them.", async function () { - let diagnosticStatusEvents = listenEvents(eventStream, EventType.ProjectDiagnosticStatus); + let diagnosticStatusEvents = listenEvents(eventStream, EventType.BackgroundDiagnosticStatus); await vscode.commands.executeCommand('o.reanalyze.currentProject', interfaceImplUri); - await poll(() => diagnosticStatusEvents, 15 * 1000, 500, r => r.find(x => x.message.Status === DiagnosticStatus.Processing) != undefined); - await poll(() => diagnosticStatusEvents, 15 * 1000, 500, r => r.find(x => x.message.Status === DiagnosticStatus.Ready) != undefined); + await poll(() => diagnosticStatusEvents, 15 * 1000, 500, r => r.find(x => x.message.Status !== BackgroundDiagnosticStatus.Finished) != undefined); + await poll(() => diagnosticStatusEvents, 15 * 1000, 500, r => r.find(x => x.message.Status === BackgroundDiagnosticStatus.Finished) != undefined); }); test("When re-analyze of all projects is executed then eventually get notified about them.", async function () { - let diagnosticStatusEvents = listenEvents(eventStream, EventType.ProjectDiagnosticStatus); + let diagnosticStatusEvents = listenEvents(eventStream, EventType.BackgroundDiagnosticStatus); await vscode.commands.executeCommand('o.reanalyze.allProjects', interfaceImplUri); - await poll(() => diagnosticStatusEvents, 15 * 1000, 500, r => r.find(x => x.message.Status === DiagnosticStatus.Processing) != undefined); - await poll(() => diagnosticStatusEvents, 15 * 1000, 500, r => r.find(x => x.message.Status === DiagnosticStatus.Ready) != undefined); + await poll(() => diagnosticStatusEvents, 15 * 1000, 500, r => r.find(x => x.message.Status !== BackgroundDiagnosticStatus.Finished) != undefined); + await poll(() => diagnosticStatusEvents, 15 * 1000, 500, r => r.find(x => x.message.Status === BackgroundDiagnosticStatus.Finished) != undefined); }); }); diff --git a/test/integrationTests/testAssets/testAssets.ts b/test/integrationTests/testAssets/testAssets.ts index 9319886d5..4bf472742 100644 --- a/test/integrationTests/testAssets/testAssets.ts +++ b/test/integrationTests/testAssets/testAssets.ts @@ -75,7 +75,7 @@ export class TestAssetWorkspace { async waitForIdle(stream: EventStream, timeout: number = 25 * 1000): Promise { let event: BaseEvent = { type: 0 }; - const subscription = stream.subscribe((e: BaseEvent) => e.type !== EventType.ProjectDiagnosticStatus && (event = e)); + const subscription = stream.subscribe((e: BaseEvent) => e.type !== EventType.BackgroundDiagnosticStatus && (event = e)); await poll(() => event, timeout, 500, e => !e || (event = null)); diff --git a/test/unitTests/logging/BackgroundWorkStatusBarObserver.test.ts b/test/unitTests/logging/BackgroundWorkStatusBarObserver.test.ts index 24840441e..4e7ba9f5c 100644 --- a/test/unitTests/logging/BackgroundWorkStatusBarObserver.test.ts +++ b/test/unitTests/logging/BackgroundWorkStatusBarObserver.test.ts @@ -5,9 +5,9 @@ import { expect, should } from 'chai'; import { StatusBarItem } from '../../../src/vscodeAdapter'; -import { OmnisharpProjectDiagnosticStatus } from '../../../src/omnisharp/loggingEvents'; +import { OmnisharpBackgroundDiagnosticStatus } from '../../../src/omnisharp/loggingEvents'; import { BackgroundWorkStatusBarObserver } from '../../../src/observers/BackgroundWorkStatusBarObserver'; -import { DiagnosticStatus } from '../../../src/omnisharp/protocol'; +import { BackgroundDiagnosticStatus } from '../../../src/omnisharp/protocol'; suite('BackgroundWorkStatusBarObserver', () => { suiteSetup(() => should()); @@ -25,16 +25,16 @@ suite('BackgroundWorkStatusBarObserver', () => { hideCalled = false; }); - test('OmnisharpProjectDiagnosticStatus.Processing: Show processing message', () => { - let event = new OmnisharpProjectDiagnosticStatus({ Status: DiagnosticStatus.Processing, ProjectFilePath: "foo.csproj", Type: "background" }); + test('OmnisharpBackgroundDiagnosticStatus.Processing: Show processing message', () => { + let event = new OmnisharpBackgroundDiagnosticStatus({ Status: BackgroundDiagnosticStatus.Progress, NumberFilesRemaining: 0, NumberFilesTotal: 0, NumberProjects: 0 }); observer.post(event); expect(hideCalled).to.be.false; expect(showCalled).to.be.true; expect(statusBarItem.text).to.contain('Analyzing'); }); - test('OmnisharpProjectDiagnosticStatus.Ready: Hide processing message', () => { - let event = new OmnisharpProjectDiagnosticStatus({ Status: DiagnosticStatus.Ready, ProjectFilePath: "foo.csproj", Type: "background" }); + test('OmnisharpBackgroundDiagnosticStatus.Ready: Hide processing message', () => { + let event = new OmnisharpBackgroundDiagnosticStatus({ Status: BackgroundDiagnosticStatus.Finished, NumberFilesRemaining: 0, NumberFilesTotal: 0, NumberProjects: 0 }); observer.post(event); expect(hideCalled).to.be.true; expect(showCalled).to.be.false; From ee1c94b30af9c1759b815223de06226014005c76 Mon Sep 17 00:00:00 2001 From: Dryadxon <81884588+Dryadxon@users.noreply.github.com> Date: Fri, 23 Sep 2022 00:22:00 +0000 Subject: [PATCH 2/2] Update src/omnisharp/EventType.ts Make EventType.ProjectDiagnosticStatus unusable Co-authored-by: Joey Robichaud --- src/omnisharp/EventType.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/omnisharp/EventType.ts b/src/omnisharp/EventType.ts index 4d7d64d07..d398f91a5 100644 --- a/src/omnisharp/EventType.ts +++ b/src/omnisharp/EventType.ts @@ -79,7 +79,7 @@ export enum EventType { OmnisharpServerOnStart = 72, OmnisharpOnBeforeServerInstall = 73, ProjectConfigurationReceived = 74, - ProjectDiagnosticStatus = 75, // Obsolete, use BackgroundDiagnosticStatus + // ProjectDiagnosticStatus = 75, Obsolete, use BackgroundDiagnosticStatus DotNetTestRunInContextStart = 76, DotNetTestDebugInContextStart = 77, TelemetryErrorEvent = 78,