Skip to content

Commit

Permalink
Ensure all diagnostic checks accept resource args (#4036)
Browse files Browse the repository at this point in the history
For #3502 
First part of #3502
  • Loading branch information
DonJayamanne authored Jan 18, 2019
1 parent a39c939 commit 4e9f738
Show file tree
Hide file tree
Showing 26 changed files with 304 additions and 168 deletions.
2 changes: 1 addition & 1 deletion src/client/activation/activationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class ExtensionActivationService implements IExtensionActivationService,

let jedi = this.useJedi();
if (!jedi) {
const diagnostic = await this.lsNotSupportedDiagnosticService.diagnose();
const diagnostic = await this.lsNotSupportedDiagnosticService.diagnose(undefined);
this.lsNotSupportedDiagnosticService.handle(diagnostic).ignoreErrors();
if (diagnostic.length){
sendTelemetryEvent(EventName.PYTHON_LANGUAGE_SERVER_PLATFORM_NOT_SUPPORTED);
Expand Down
36 changes: 22 additions & 14 deletions src/client/application/diagnostics/applicationDiagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,41 @@
import { inject, injectable, named } from 'inversify';
import { DiagnosticSeverity } from 'vscode';
import { STANDARD_OUTPUT_CHANNEL } from '../../common/constants';
import { ILogger, IOutputChannel } from '../../common/types';
import { ILogger, IOutputChannel, Resource } from '../../common/types';
import { IServiceContainer } from '../../ioc/types';
import { IApplicationDiagnostics } from '../types';
import { InvalidMacPythonInterpreterServiceId } from './checks/macPythonInterpreter';
import { IDiagnostic, IDiagnosticsService, ISourceMapSupportService } from './types';

@injectable()
export class ApplicationDiagnostics implements IApplicationDiagnostics {
constructor(@inject(IServiceContainer) private readonly serviceContainer: IServiceContainer,
@inject(IOutputChannel) @named(STANDARD_OUTPUT_CHANNEL) private readonly outputChannel: IOutputChannel) { }
constructor(
@inject(IServiceContainer) private readonly serviceContainer: IServiceContainer,
@inject(IOutputChannel) @named(STANDARD_OUTPUT_CHANNEL) private readonly outputChannel: IOutputChannel
) {}
public register() {
this.serviceContainer.get<ISourceMapSupportService>(ISourceMapSupportService).register();
}
public async performPreStartupHealthCheck(): Promise<void> {
public async performPreStartupHealthCheck(resource: Resource): Promise<void> {
const diagnosticsServices = this.serviceContainer.getAll<IDiagnosticsService>(IDiagnosticsService);
await Promise.all(diagnosticsServices.map(async diagnosticsService => {
const diagnostics = await diagnosticsService.diagnose();
this.log(diagnostics);
if (diagnostics.length > 0) {
await diagnosticsService.handle(diagnostics);
}
}));
await Promise.all(
diagnosticsServices.map(async diagnosticsService => {
const diagnostics = await diagnosticsService.diagnose(resource);
this.log(diagnostics);
if (diagnostics.length > 0) {
await diagnosticsService.handle(diagnostics);
}
})
);

// Validate the Mac interperter in the background.
const maccInterpreterService = this.serviceContainer.get<IDiagnosticsService>(IDiagnosticsService, InvalidMacPythonInterpreterServiceId);
maccInterpreterService.diagnose()
.then(diagnostics => maccInterpreterService.handle(diagnostics))
const macInterpreterService = this.serviceContainer.get<IDiagnosticsService>(
IDiagnosticsService,
InvalidMacPythonInterpreterServiceId
);
macInterpreterService
.diagnose(undefined)
.then(diagnostics => macInterpreterService.handle(diagnostics))
.ignoreErrors();
}
private log(diagnostics: IDiagnostic[]): void {
Expand Down
6 changes: 4 additions & 2 deletions src/client/application/diagnostics/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { injectable, unmanaged } from 'inversify';
import { DiagnosticSeverity } from 'vscode';
import { Resource } from '../../common/types';
import { IServiceContainer } from '../../ioc/types';
import { sendTelemetryEvent } from '../../telemetry';
import { EventName } from '../../telemetry/constants';
Expand All @@ -14,7 +15,8 @@ import { DiagnosticScope, IDiagnostic, IDiagnosticFilterService, IDiagnosticsSer
@injectable()
export abstract class BaseDiagnostic implements IDiagnostic {
constructor(public readonly code: DiagnosticCodes, public readonly message: string,
public readonly severity: DiagnosticSeverity, public readonly scope: DiagnosticScope) { }
public readonly severity: DiagnosticSeverity, public readonly scope: DiagnosticScope,
public readonly resource: Resource) { }
}

@injectable()
Expand All @@ -24,7 +26,7 @@ export abstract class BaseDiagnosticsService implements IDiagnosticsService {
@unmanaged() protected serviceContainer: IServiceContainer) {
this.filterService = serviceContainer.get<IDiagnosticFilterService>(IDiagnosticFilterService);
}
public abstract diagnose(): Promise<IDiagnostic[]>;
public abstract diagnose(resource: Resource): Promise<IDiagnostic[]>;
public abstract handle(diagnostics: IDiagnostic[]): Promise<void>;
public async canHandle(diagnostic: IDiagnostic): Promise<boolean> {
sendTelemetryEvent(EventName.DIAGNOSTICS_MESSAGE, undefined, { code: diagnostic.code });
Expand Down
10 changes: 5 additions & 5 deletions src/client/application/diagnostics/checks/envPathVariable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { DiagnosticSeverity } from 'vscode';
import { IApplicationEnvironment } from '../../../common/application/types';
import '../../../common/extensions';
import { IPlatformService } from '../../../common/platform/types';
import { ICurrentProcess, IPathUtils } from '../../../common/types';
import { ICurrentProcess, IPathUtils, Resource } from '../../../common/types';
import { IServiceContainer } from '../../../ioc/types';
import { BaseDiagnostic, BaseDiagnosticsService } from '../base';
import { IDiagnosticsCommandFactory } from '../commands/types';
Expand All @@ -20,9 +20,9 @@ const InvalidEnvPathVariableMessage = 'The environment variable \'{0}\' seems to
' The existence of such a character is known to have caused the {1} extension to not load. If the extension fails to load please modify your paths to remove this \'"\' character.';

export class InvalidEnvironmentPathVariableDiagnostic extends BaseDiagnostic {
constructor(message: string) {
constructor(message: string, resource: Resource) {
super(DiagnosticCodes.InvalidEnvironmentPathVariableDiagnostic,
message, DiagnosticSeverity.Warning, DiagnosticScope.Global);
message, DiagnosticSeverity.Warning, DiagnosticScope.Global, resource);
}
}

Expand All @@ -37,13 +37,13 @@ export class EnvironmentPathVariableDiagnosticsService extends BaseDiagnosticsSe
this.platform = this.serviceContainer.get<IPlatformService>(IPlatformService);
this.messageService = serviceContainer.get<IDiagnosticHandlerService<MessageCommandPrompt>>(IDiagnosticHandlerService, DiagnosticCommandPromptHandlerServiceId);
}
public async diagnose(): Promise<IDiagnostic[]> {
public async diagnose(resource: Resource): Promise<IDiagnostic[]> {
if (this.platform.isWindows &&
this.doesPathVariableHaveInvalidEntries()) {
const env = this.serviceContainer.get<IApplicationEnvironment>(IApplicationEnvironment);
const message = InvalidEnvPathVariableMessage
.format(this.platform.pathVariableName, env.extensionName);
return [new InvalidEnvironmentPathVariableDiagnostic(message)];
return [new InvalidEnvironmentPathVariableDiagnostic(message, resource)];
} else {
return [];
}
Expand Down
10 changes: 6 additions & 4 deletions src/client/application/diagnostics/checks/invalidDebuggerType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { DiagnosticSeverity, WorkspaceFolder } from 'vscode';
import { ICommandManager, IWorkspaceService } from '../../../common/application/types';
import '../../../common/extensions';
import { IFileSystem } from '../../../common/platform/types';
import { Resource } from '../../../common/types';
import { IServiceContainer } from '../../../ioc/types';
import { BaseDiagnostic, BaseDiagnosticsService } from '../base';
import { IDiagnosticsCommandFactory } from '../commands/types';
Expand All @@ -21,9 +22,10 @@ const InvalidDebuggerTypeMessage = 'Your launch.json file needs to be updated to
'not work. Would you like to automatically update your launch.json file now?';

export class InvalidDebuggerTypeDiagnostic extends BaseDiagnostic {
constructor(message: string) {
constructor(message: string, resource: Resource) {
super(DiagnosticCodes.InvalidDebuggerTypeDiagnostic,
message, DiagnosticSeverity.Error, DiagnosticScope.WorkspaceFolder);
message, DiagnosticSeverity.Error, DiagnosticScope.WorkspaceFolder,
resource);
}
}

Expand All @@ -42,9 +44,9 @@ export class InvalidDebuggerTypeDiagnosticsService extends BaseDiagnosticsServic
this.fs = this.serviceContainer.get<IFileSystem>(IFileSystem);
cmdManager.registerCommand(CommandName, this.fixLaunchJson, this);
}
public async diagnose(): Promise<IDiagnostic[]> {
public async diagnose(resource: Resource): Promise<IDiagnostic[]> {
if (await this.isExperimentalDebuggerUsed()) {
return [new InvalidDebuggerTypeDiagnostic(InvalidDebuggerTypeMessage)];
return [new InvalidDebuggerTypeDiagnostic(InvalidDebuggerTypeMessage, resource)];
} else {
return [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { openFile } from '../../../../test/common';
import { IWorkspaceService } from '../../../common/application/types';
import '../../../common/extensions';
import { traceError } from '../../../common/logger';
import { IConfigurationService } from '../../../common/types';
import { IConfigurationService, Resource } from '../../../common/types';
import { Diagnostics } from '../../../common/utils/localize';
import { SystemVariables } from '../../../common/variables/systemVariables';
import { IInterpreterHelper } from '../../../interpreter/contracts';
Expand All @@ -22,16 +22,18 @@ import { DiagnosticCommandPromptHandlerServiceId, MessageCommandPrompt } from '.
import { DiagnosticScope, IDiagnostic, IDiagnosticCommand, IDiagnosticHandlerService, IInvalidPythonPathInDebuggerService } from '../types';

export class InvalidPythonPathInDebuggerSettingsDiagnostic extends BaseDiagnostic {
constructor() {
constructor(resource: Resource) {
super(DiagnosticCodes.InvalidPythonPathInDebuggerSettingsDiagnostic,
Diagnostics.invalidPythonPathInDebuggerSettings(), DiagnosticSeverity.Error, DiagnosticScope.WorkspaceFolder);
Diagnostics.invalidPythonPathInDebuggerSettings(), DiagnosticSeverity.Error, DiagnosticScope.WorkspaceFolder,
resource);
}
}

export class InvalidPythonPathInDebuggerLaunchDiagnostic extends BaseDiagnostic {
constructor() {
constructor(resource: Resource) {
super(DiagnosticCodes.InvalidPythonPathInDebuggerLaunchDiagnostic,
Diagnostics.invalidPythonPathInDebuggerLaunch(), DiagnosticSeverity.Error, DiagnosticScope.WorkspaceFolder);
Diagnostics.invalidPythonPathInDebuggerLaunch(), DiagnosticSeverity.Error, DiagnosticScope.WorkspaceFolder,
resource);
}
}

Expand All @@ -47,7 +49,7 @@ export class InvalidPythonPathInDebuggerService extends BaseDiagnosticsService i
@inject(IDiagnosticHandlerService) @named(DiagnosticCommandPromptHandlerServiceId) protected readonly messageService: IDiagnosticHandlerService<MessageCommandPrompt>) {
super([DiagnosticCodes.InvalidPythonPathInDebuggerSettingsDiagnostic, DiagnosticCodes.InvalidPythonPathInDebuggerLaunchDiagnostic], serviceContainer);
}
public async diagnose(): Promise<IDiagnostic[]> {
public async diagnose(_resource: Resource): Promise<IDiagnostic[]> {
return [];
}
public async handle(diagnostics: IDiagnostic[]): Promise<void> {
Expand All @@ -73,11 +75,11 @@ export class InvalidPythonPathInDebuggerService extends BaseDiagnosticsService i
}
traceError(`Invalid Python Path '${pythonPath}'`);
if (pathInLaunchJson) {
this.handle([new InvalidPythonPathInDebuggerLaunchDiagnostic()])
this.handle([new InvalidPythonPathInDebuggerLaunchDiagnostic(resource)])
.catch(ex => traceError('Failed to handle invalid python path in launch.json debugger', ex))
.ignoreErrors();
} else {
this.handle([new InvalidPythonPathInDebuggerSettingsDiagnostic()])
this.handle([new InvalidPythonPathInDebuggerSettingsDiagnostic(resource)])
.catch(ex => traceError('Failed to handle invalid python path in settings.json debugger', ex))
.ignoreErrors();
}
Expand Down
9 changes: 5 additions & 4 deletions src/client/application/diagnostics/checks/lsNotSupported.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { inject, named } from 'inversify';
import { DiagnosticSeverity } from 'vscode';
import { ILanguageServerCompatibilityService } from '../../../activation/types';
import { Resource } from '../../../common/types';
import { Diagnostics } from '../../../common/utils/localize';
import { IServiceContainer } from '../../../ioc/types';
import { BaseDiagnostic, BaseDiagnosticsService } from '../base';
Expand All @@ -15,9 +16,9 @@ import { DiagnosticCommandPromptHandlerServiceId, MessageCommandPrompt } from '.
import { DiagnosticScope, IDiagnostic, IDiagnosticHandlerService } from '../types';

export class LSNotSupportedDiagnostic extends BaseDiagnostic {
constructor(message: string) {
constructor(message: string, resource: Resource) {
super(DiagnosticCodes.LSNotSupportedDiagnostic,
message, DiagnosticSeverity.Warning, DiagnosticScope.Global);
message, DiagnosticSeverity.Warning, DiagnosticScope.Global, resource);
}
}

Expand All @@ -29,11 +30,11 @@ export class LSNotSupportedDiagnosticService extends BaseDiagnosticsService {
@inject(IDiagnosticHandlerService) @named(DiagnosticCommandPromptHandlerServiceId) protected readonly messageService: IDiagnosticHandlerService<MessageCommandPrompt>) {
super([DiagnosticCodes.LSNotSupportedDiagnostic], serviceContainer);
}
public async diagnose(): Promise<IDiagnostic[]>{
public async diagnose(resource: Resource): Promise<IDiagnostic[]>{
if (await this.lsCompatibility.isSupported()) {
return [];
} else{
return [new LSNotSupportedDiagnostic(Diagnostics.lsNotSupported())];
return [new LSNotSupportedDiagnostic(Diagnostics.lsNotSupported(), resource)];
}
}
public async handle(diagnostics: IDiagnostic[]): Promise<void>{
Expand Down
Loading

0 comments on commit 4e9f738

Please sign in to comment.