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

Fix #5171 #5372

Merged
merged 2 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 5 additions & 5 deletions src/features/diagnosticsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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();
}
}
Expand Down
15 changes: 8 additions & 7 deletions src/observers/BackgroundWorkStatusBarObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <OmnisharpProjectDiagnosticStatus>event;
if (event.type === EventType.BackgroundDiagnosticStatus) {
let asProjectEvent = <OmnisharpBackgroundDiagnosticStatus>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();
Expand Down
3 changes: 2 additions & 1 deletion src/omnisharp/EventType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/omnisharp/loggingEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 9 additions & 7 deletions src/omnisharp/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions src/omnisharp/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) => {
Expand Down
20 changes: 10 additions & 10 deletions test/integrationTests/reAnalyze.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -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<OmnisharpProjectDiagnosticStatus>(eventStream, EventType.ProjectDiagnosticStatus);
let diagnosticStatusEvents = listenEvents<OmnisharpBackgroundDiagnosticStatus>(eventStream, EventType.BackgroundDiagnosticStatus);

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

Expand All @@ -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),
Expand All @@ -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<OmnisharpProjectDiagnosticStatus>(eventStream, EventType.ProjectDiagnosticStatus);
let diagnosticStatusEvents = listenEvents<OmnisharpBackgroundDiagnosticStatus>(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<OmnisharpProjectDiagnosticStatus>(eventStream, EventType.ProjectDiagnosticStatus);
let diagnosticStatusEvents = listenEvents<OmnisharpBackgroundDiagnosticStatus>(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);
});
});
2 changes: 1 addition & 1 deletion test/integrationTests/testAssets/testAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class TestAssetWorkspace {
async waitForIdle(stream: EventStream, timeout: number = 25 * 1000): Promise<void> {
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));

Expand Down
12 changes: 6 additions & 6 deletions test/unitTests/logging/BackgroundWorkStatusBarObserver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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;
Expand Down