Skip to content

Commit 55bc054

Browse files
authored
Merge pull request #5372 from Dryadxon/replace-project-diagnostic-status
Fix #5171
2 parents 92d998f + ee1c94b commit 55bc054

File tree

9 files changed

+49
-45
lines changed

9 files changed

+49
-45
lines changed

src/features/diagnosticsProvider.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { TextDocument } from '../vscodeAdapter';
1616
import OptionProvider from '../observers/OptionProvider';
1717
import { Subject, Subscription } from 'rxjs';
1818
import { debounceTime } from 'rxjs/operators';
19-
import { DiagnosticStatus } from '../omnisharp/protocol';
19+
import { BackgroundDiagnosticStatus } from '../omnisharp/protocol';
2020
import { LanguageMiddlewareFeature } from '../omnisharp/LanguageMiddlewareFeature';
2121

2222
export class Advisor {
@@ -154,7 +154,7 @@ class DiagnosticsProvider extends AbstractSupport {
154154
this._disposable = new CompositeDisposable(this._diagnostics,
155155
this._server.onPackageRestore(() => this._validateAllPipe.next("onPackageRestore"), this),
156156
this._server.onProjectChange(() => this._validateAllPipe.next("onProjectChanged"), this),
157-
this._server.onProjectDiagnosticStatus(this._onProjectAnalysis, this),
157+
this._server.onBackgroundDiagnosticStatus(this._onBackgroundAnalysis, this),
158158
vscode.workspace.onDidOpenTextDocument(event => this._onDocumentOpenOrChange(event), this),
159159
vscode.workspace.onDidChangeTextDocument(event => this._onDocumentOpenOrChange(event.document), this),
160160
vscode.workspace.onDidCloseTextDocument(this._onDocumentClose, this),
@@ -210,9 +210,9 @@ class DiagnosticsProvider extends AbstractSupport {
210210
}
211211
}
212212

213-
private _onProjectAnalysis(event: protocol.ProjectDiagnosticStatus) {
214-
if (event.Status == DiagnosticStatus.Ready &&
215-
event.ProjectFilePath === "(100 %)") {
213+
private _onBackgroundAnalysis(event: protocol.BackgroundDiagnosticStatusMessage) {
214+
if (event.Status == BackgroundDiagnosticStatus.Finished &&
215+
event.NumberFilesRemaining === 0) {
216216
this._validateAllPipe.next();
217217
}
218218
}

src/observers/BackgroundWorkStatusBarObserver.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { BaseStatusBarItemObserver } from './BaseStatusBarItemObserver';
7-
import { BaseEvent, OmnisharpProjectDiagnosticStatus } from '../omnisharp/loggingEvents';
7+
import { BaseEvent, OmnisharpBackgroundDiagnosticStatus } from '../omnisharp/loggingEvents';
88
import { EventType } from '../omnisharp/EventType';
9-
import { DiagnosticStatus } from '../omnisharp/protocol';
9+
import { BackgroundDiagnosticStatus } from '../omnisharp/protocol';
1010

1111
export class BackgroundWorkStatusBarObserver extends BaseStatusBarItemObserver {
1212
public post = (event: BaseEvent) => {
13-
if (event.type === EventType.ProjectDiagnosticStatus) {
14-
let asProjectEvent = <OmnisharpProjectDiagnosticStatus>event;
13+
if (event.type === EventType.BackgroundDiagnosticStatus) {
14+
let asProjectEvent = <OmnisharpBackgroundDiagnosticStatus>event;
1515

16-
if (asProjectEvent.message.Status === DiagnosticStatus.Processing) {
17-
let projectFile = asProjectEvent.message.ProjectFilePath.replace(/^.*[\\\/]/, '');
18-
this.SetAndShowStatusBar(`$(sync~spin) Analyzing ${projectFile}`, 'o.showOutput', undefined, `Analyzing ${projectFile}`);
16+
if (asProjectEvent.message.Status !== BackgroundDiagnosticStatus.Finished) {
17+
let {NumberFilesRemaining, NumberFilesTotal} = asProjectEvent.message;
18+
let message = `Analyzing ${NumberFilesTotal} files - Remaining ${NumberFilesRemaining} files`;
19+
this.SetAndShowStatusBar(`$(sync~spin) ${message}`, 'o.showOutput', null, `${message}`);
1920
}
2021
else {
2122
this.ResetAndHideStatusBar();

src/omnisharp/EventType.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,12 @@ export enum EventType {
7979
OmnisharpServerOnStart = 72,
8080
OmnisharpOnBeforeServerInstall = 73,
8181
ProjectConfigurationReceived = 74,
82-
ProjectDiagnosticStatus = 75,
82+
// ProjectDiagnosticStatus = 75, Obsolete, use BackgroundDiagnosticStatus
8383
DotNetTestRunInContextStart = 76,
8484
DotNetTestDebugInContextStart = 77,
8585
TelemetryErrorEvent = 78,
8686
OmnisharpServerRequestCancelled = 79,
87+
BackgroundDiagnosticStatus = 80,
8788
}
8889

8990
//Note that the EventType protocol is shared with Razor.VSCode and the numbers here should not be altered

src/omnisharp/loggingEvents.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ export class OmnisharpServerOnError implements BaseEvent {
9898
constructor(public errorMessage: protocol.ErrorMessage) { }
9999
}
100100

101-
export class OmnisharpProjectDiagnosticStatus implements BaseEvent {
102-
type = EventType.ProjectDiagnosticStatus;
103-
constructor(public message: protocol.ProjectDiagnosticStatus) { }
101+
export class OmnisharpBackgroundDiagnosticStatus implements BaseEvent {
102+
type = EventType.BackgroundDiagnosticStatus;
103+
constructor(public message: protocol.BackgroundDiagnosticStatusMessage) { }
104104
}
105105

106106
export class OmnisharpServerMsBuildProjectDiagnostics implements BaseEvent {

src/omnisharp/protocol.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,17 @@ export interface ProjectInformationResponse {
285285
MsBuildProject: MSBuildProject;
286286
}
287287

288-
export enum DiagnosticStatus {
289-
Processing = 0,
290-
Ready = 1
288+
export enum BackgroundDiagnosticStatus {
289+
Started = 0,
290+
Progress = 1,
291+
Finished = 2
291292
}
292293

293-
export interface ProjectDiagnosticStatus {
294-
Status: DiagnosticStatus;
295-
ProjectFilePath: string;
296-
Type: "background";
294+
export interface BackgroundDiagnosticStatusMessage {
295+
Status: BackgroundDiagnosticStatus;
296+
NumberProjects: number;
297+
NumberFilesTotal: number;
298+
NumberFilesRemaining: number;
297299
}
298300

299301
export interface WorkspaceInformationResponse {

src/omnisharp/server.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ module Events {
6969
export const ProjectAdded = 'ProjectAdded';
7070
export const ProjectRemoved = 'ProjectRemoved';
7171

72-
export const ProjectDiagnosticStatus = 'ProjectDiagnosticStatus';
72+
export const BackgroundDiagnosticStatus = 'BackgroundDiagnosticStatus';
7373

7474
export const MsBuildProjectDiagnostics = 'MsBuildProjectDiagnostics';
7575

@@ -218,8 +218,8 @@ export class OmniSharpServer {
218218
return this._addListener(Events.ProjectRemoved, listener, thisArg);
219219
}
220220

221-
public onProjectDiagnosticStatus(listener: (e: protocol.ProjectDiagnosticStatus) => any, thisArg?: any) {
222-
return this._addListener(Events.ProjectDiagnosticStatus, listener, thisArg);
221+
public onBackgroundDiagnosticStatus(listener: (e: protocol.BackgroundDiagnosticStatusMessage) => any, thisArg?: any) {
222+
return this._addListener(Events.BackgroundDiagnosticStatus, listener, thisArg);
223223
}
224224

225225
public onMsBuildProjectDiagnostics(listener: (e: protocol.MSBuildProjectDiagnostics) => any, thisArg?: any) {
@@ -319,8 +319,8 @@ export class OmniSharpServer {
319319
this.eventStream.post(new ObservableEvents.OmnisharpServerOnStart());
320320
}));
321321

322-
disposables.add(this.onProjectDiagnosticStatus((message: protocol.ProjectDiagnosticStatus) =>
323-
this.eventStream.post(new ObservableEvents.OmnisharpProjectDiagnosticStatus(message))
322+
disposables.add(this.onBackgroundDiagnosticStatus((message: protocol.BackgroundDiagnosticStatusMessage) =>
323+
this.eventStream.post(new ObservableEvents.OmnisharpBackgroundDiagnosticStatus(message))
324324
));
325325

326326
disposables.add(this.onProjectConfigurationReceived((message: protocol.ProjectConfigurationMessage) => {

test/integrationTests/reAnalyze.integration.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import testAssetWorkspace from './testAssets/testAssetWorkspace';
1212
import { poll, assertWithPoll } from './poll';
1313
import { EventStream } from '../../src/EventStream';
1414
import { EventType } from '../../src/omnisharp/EventType';
15-
import { BaseEvent, OmnisharpProjectDiagnosticStatus } from '../../src/omnisharp/loggingEvents';
16-
import { DiagnosticStatus } from '../../src/omnisharp/protocol';
15+
import { BaseEvent, OmnisharpBackgroundDiagnosticStatus } from '../../src/omnisharp/loggingEvents';
16+
import { BackgroundDiagnosticStatus } from '../../src/omnisharp/protocol';
1717

1818
const chai = require('chai');
1919
chai.use(require('chai-arrays'));
@@ -63,7 +63,7 @@ suite(`ReAnalyze: ${testAssetWorkspace.description}`, function () {
6363
});
6464

6565
test("When interface is manually renamed, then return correct analysis after re-analysis of project", async function () {
66-
let diagnosticStatusEvents = listenEvents<OmnisharpProjectDiagnosticStatus>(eventStream, EventType.ProjectDiagnosticStatus);
66+
let diagnosticStatusEvents = listenEvents<OmnisharpBackgroundDiagnosticStatus>(eventStream, EventType.BackgroundDiagnosticStatus);
6767

6868
await vscode.commands.executeCommand("vscode.open", interfaceUri);
6969

@@ -73,7 +73,7 @@ suite(`ReAnalyze: ${testAssetWorkspace.description}`, function () {
7373

7474
await vscode.commands.executeCommand('o.reanalyze.currentProject', interfaceImplUri);
7575

76-
await poll(() => diagnosticStatusEvents, 15 * 1000, 500, r => r.find(x => x.message.Status === DiagnosticStatus.Ready) !== undefined);
76+
await poll(() => diagnosticStatusEvents, 15 * 1000, 500, r => r.find(x => x.message.Status === BackgroundDiagnosticStatus.Finished) !== undefined);
7777

7878
await assertWithPoll(
7979
() => vscode.languages.getDiagnostics(interfaceImplUri),
@@ -83,20 +83,20 @@ suite(`ReAnalyze: ${testAssetWorkspace.description}`, function () {
8383
});
8484

8585
test("When re-analyze of project is executed then eventually get notified about them.", async function () {
86-
let diagnosticStatusEvents = listenEvents<OmnisharpProjectDiagnosticStatus>(eventStream, EventType.ProjectDiagnosticStatus);
86+
let diagnosticStatusEvents = listenEvents<OmnisharpBackgroundDiagnosticStatus>(eventStream, EventType.BackgroundDiagnosticStatus);
8787

8888
await vscode.commands.executeCommand('o.reanalyze.currentProject', interfaceImplUri);
8989

90-
await poll(() => diagnosticStatusEvents, 15 * 1000, 500, r => r.find(x => x.message.Status === DiagnosticStatus.Processing) != undefined);
91-
await poll(() => diagnosticStatusEvents, 15 * 1000, 500, r => r.find(x => x.message.Status === DiagnosticStatus.Ready) != undefined);
90+
await poll(() => diagnosticStatusEvents, 15 * 1000, 500, r => r.find(x => x.message.Status !== BackgroundDiagnosticStatus.Finished) != undefined);
91+
await poll(() => diagnosticStatusEvents, 15 * 1000, 500, r => r.find(x => x.message.Status === BackgroundDiagnosticStatus.Finished) != undefined);
9292
});
9393

9494
test("When re-analyze of all projects is executed then eventually get notified about them.", async function () {
95-
let diagnosticStatusEvents = listenEvents<OmnisharpProjectDiagnosticStatus>(eventStream, EventType.ProjectDiagnosticStatus);
95+
let diagnosticStatusEvents = listenEvents<OmnisharpBackgroundDiagnosticStatus>(eventStream, EventType.BackgroundDiagnosticStatus);
9696

9797
await vscode.commands.executeCommand('o.reanalyze.allProjects', interfaceImplUri);
9898

99-
await poll(() => diagnosticStatusEvents, 15 * 1000, 500, r => r.find(x => x.message.Status === DiagnosticStatus.Processing) != undefined);
100-
await poll(() => diagnosticStatusEvents, 15 * 1000, 500, r => r.find(x => x.message.Status === DiagnosticStatus.Ready) != undefined);
99+
await poll(() => diagnosticStatusEvents, 15 * 1000, 500, r => r.find(x => x.message.Status !== BackgroundDiagnosticStatus.Finished) != undefined);
100+
await poll(() => diagnosticStatusEvents, 15 * 1000, 500, r => r.find(x => x.message.Status === BackgroundDiagnosticStatus.Finished) != undefined);
101101
});
102102
});

test/integrationTests/testAssets/testAssets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class TestAssetWorkspace {
7575
async waitForIdle(stream: EventStream, timeout: number = 25 * 1000): Promise<void> {
7676
let event: BaseEvent = { type: 0 };
7777

78-
const subscription = stream.subscribe((e: BaseEvent) => e.type !== EventType.ProjectDiagnosticStatus && (event = e));
78+
const subscription = stream.subscribe((e: BaseEvent) => e.type !== EventType.BackgroundDiagnosticStatus && (event = e));
7979

8080
await poll(() => event, timeout, 500, e => !e || (event = null));
8181

test/unitTests/logging/BackgroundWorkStatusBarObserver.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
import { expect, should } from 'chai';
77
import { StatusBarItem } from '../../../src/vscodeAdapter';
8-
import { OmnisharpProjectDiagnosticStatus } from '../../../src/omnisharp/loggingEvents';
8+
import { OmnisharpBackgroundDiagnosticStatus } from '../../../src/omnisharp/loggingEvents';
99
import { BackgroundWorkStatusBarObserver } from '../../../src/observers/BackgroundWorkStatusBarObserver';
10-
import { DiagnosticStatus } from '../../../src/omnisharp/protocol';
10+
import { BackgroundDiagnosticStatus } from '../../../src/omnisharp/protocol';
1111

1212
suite('BackgroundWorkStatusBarObserver', () => {
1313
suiteSetup(() => should());
@@ -25,16 +25,16 @@ suite('BackgroundWorkStatusBarObserver', () => {
2525
hideCalled = false;
2626
});
2727

28-
test('OmnisharpProjectDiagnosticStatus.Processing: Show processing message', () => {
29-
let event = new OmnisharpProjectDiagnosticStatus({ Status: DiagnosticStatus.Processing, ProjectFilePath: "foo.csproj", Type: "background" });
28+
test('OmnisharpBackgroundDiagnosticStatus.Processing: Show processing message', () => {
29+
let event = new OmnisharpBackgroundDiagnosticStatus({ Status: BackgroundDiagnosticStatus.Progress, NumberFilesRemaining: 0, NumberFilesTotal: 0, NumberProjects: 0 });
3030
observer.post(event);
3131
expect(hideCalled).to.be.false;
3232
expect(showCalled).to.be.true;
3333
expect(statusBarItem.text).to.contain('Analyzing');
3434
});
3535

36-
test('OmnisharpProjectDiagnosticStatus.Ready: Hide processing message', () => {
37-
let event = new OmnisharpProjectDiagnosticStatus({ Status: DiagnosticStatus.Ready, ProjectFilePath: "foo.csproj", Type: "background" });
36+
test('OmnisharpBackgroundDiagnosticStatus.Ready: Hide processing message', () => {
37+
let event = new OmnisharpBackgroundDiagnosticStatus({ Status: BackgroundDiagnosticStatus.Finished, NumberFilesRemaining: 0, NumberFilesTotal: 0, NumberProjects: 0 });
3838
observer.post(event);
3939
expect(hideCalled).to.be.true;
4040
expect(showCalled).to.be.false;

0 commit comments

Comments
 (0)