Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ import { Parameter } from '../context/semantic/Entity';
import { parseIdentifiable } from '../protocol/LspParser';
import { Identifiable } from '../protocol/LspTypes';
import { ServerComponents } from '../server/ServerComponents';
import { LoggerFactory } from '../telemetry/LoggerFactory';
import { parseTemplateActionParams, parseGetParametersParams } from '../templates/TemplateParser';
import { parseStackActionParams, parseGetParametersParams } from '../stackActions/StackActionParser';
import {
GetParametersParams,
GetParametersResult,
TemplateActionParams,
TemplateActionResult,
TemplateStatusResult,
} from '../templates/TemplateRequestType';
StackActionParams,
StackActionResult,
StackActionStatusResult,
} from '../stackActions/StackActionRequestType';
import { LoggerFactory } from '../telemetry/LoggerFactory';
import { extractErrorMessage } from '../utils/Errors';
import { parseWithPrettyError } from '../utils/ZodErrorWrapper';

const log = LoggerFactory.getLogger('TemplateHandler');
const log = LoggerFactory.getLogger('StackActionHandler');

export function templateParametersHandler(
export function stackActionParametersHandler(
components: ServerComponents,
): ServerRequestHandler<GetParametersParams, GetParametersResult, never, void> {
return (rawParams, _token, _workDoneProgress, _resultProgress) => {
log.debug({ Handler: 'TemplateParameters', rawParams });
log.debug({ Handler: 'StackActionParameters', rawParams });

try {
const params = parseWithPrettyError(parseGetParametersParams, rawParams);
Expand All @@ -42,72 +42,72 @@ export function templateParametersHandler(
parameters: [],
};
} catch (error) {
handleTemplateError(error, 'Failed to get parameters');
handleStackActionError(error, 'Failed to get parameters');
}
};
}

export function templateValidationCreateHandler(
export function stackActionValidationCreateHandler(
components: ServerComponents,
): ServerRequestHandler<TemplateActionParams, TemplateActionResult, never, void> {
): ServerRequestHandler<StackActionParams, StackActionResult, never, void> {
return async (rawParams) => {
log.debug({ Handler: 'TemplateValidationCreate', rawParams });
log.debug({ Handler: 'StackActionValidationCreate', rawParams });

try {
const params = parseWithPrettyError(parseTemplateActionParams, rawParams);
const params = parseWithPrettyError(parseStackActionParams, rawParams);
return await components.validationWorkflowService.start(params);
} catch (error) {
handleTemplateError(error, 'Failed to start validation workflow');
handleStackActionError(error, 'Failed to start validation workflow');
}
};
}

export function templateDeploymentCreateHandler(
export function stackActionDeploymentCreateHandler(
components: ServerComponents,
): ServerRequestHandler<TemplateActionParams, TemplateActionResult, never, void> {
): ServerRequestHandler<StackActionParams, StackActionResult, never, void> {
return async (rawParams) => {
log.debug({ Handler: 'TemplateDeploymentCreate', rawParams });
log.debug({ Handler: 'StackActionDeploymentCreate', rawParams });

try {
const params = parseWithPrettyError(parseTemplateActionParams, rawParams);
const params = parseWithPrettyError(parseStackActionParams, rawParams);
return await components.deploymentWorkflowService.start(params);
} catch (error) {
handleTemplateError(error, 'Failed to start deployment workflow');
handleStackActionError(error, 'Failed to start deployment workflow');
}
};
}

export function templateValidationStatusHandler(
export function stackActionValidationStatusHandler(
components: ServerComponents,
): ServerRequestHandler<Identifiable, TemplateStatusResult, never, void> {
): ServerRequestHandler<Identifiable, StackActionStatusResult, never, void> {
return (rawParams) => {
log.debug({ Handler: 'TemplateValidationStatus', rawParams });
log.debug({ Handler: 'StackActionValidationStatus', rawParams });

try {
const params = parseWithPrettyError(parseIdentifiable, rawParams);
return components.validationWorkflowService.getStatus(params);
} catch (error) {
handleTemplateError(error, 'Failed to get validation status');
handleStackActionError(error, 'Failed to get validation status');
}
};
}

export function templateDeploymentStatusHandler(
export function stackActionDeploymentStatusHandler(
components: ServerComponents,
): ServerRequestHandler<Identifiable, TemplateStatusResult, never, void> {
): ServerRequestHandler<Identifiable, StackActionStatusResult, never, void> {
return (rawParams) => {
log.debug({ Handler: 'TemplateDeploymentStatus', rawParams });
log.debug({ Handler: 'StackActionDeploymentStatus', rawParams });

try {
const params = parseWithPrettyError(parseIdentifiable, rawParams);
return components.deploymentWorkflowService.getStatus(params);
} catch (error) {
handleTemplateError(error, 'Failed to get deployment status');
handleStackActionError(error, 'Failed to get deployment status');
}
};
}

function handleTemplateError(error: unknown, contextMessage: string): never {
function handleStackActionError(error: unknown, contextMessage: string): never {
if (error instanceof ResponseError) {
throw error;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ListStacksParams, ListStacksResult } from '../stacks/StackRequestType';
import { LoggerFactory } from '../telemetry/LoggerFactory';
import { extractErrorMessage } from '../utils/Errors';

const log = LoggerFactory.getLogger('StackHandler');
const log = LoggerFactory.getLogger('StackQueryHandler');

export function listStacksHandler(
components: ServerComponents,
Expand Down
20 changes: 10 additions & 10 deletions src/protocol/LspConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { LspDiagnostics } from './LspDiagnostics';
import { LspDocuments } from './LspDocuments';
import { LspHandlers } from './LspHandlers';
import { LspResourceHandlers } from './LspResourceHandlers';
import { LspStackHandlers } from './LspStackHandlers';
import { LspTemplateHandlers } from './LspTemplateHandlers';
import { LspStackActionHandlers } from './LspStackActionHandlers';
import { LspStackQueryHandlers } from './LspStackQueryHandlers';
import { LspWorkspace } from './LspWorkspace';

type LspConnectionHandlers = {
Expand All @@ -32,8 +32,8 @@ export type LspFeatures = {
communication: LspCommunication;
handlers: LspHandlers;
authHandlers: LspAuthHandlers;
templateHandlers: LspTemplateHandlers;
stackHandlers: LspStackHandlers;
stackActionHandlers: LspStackActionHandlers;
stackQueryHandlers: LspStackQueryHandlers;
resourceHandlers: LspResourceHandlers;
};

Expand All @@ -44,8 +44,8 @@ export class LspConnection {
private readonly communication: LspCommunication;
private readonly handlers: LspHandlers;
private readonly authHandlers: LspAuthHandlers;
private readonly templateHandlers: LspTemplateHandlers;
private readonly stackHandlers: LspStackHandlers;
private readonly stackActionHandlers: LspStackActionHandlers;
private readonly stackHandlers: LspStackQueryHandlers;
private readonly resourceHandlers: LspResourceHandlers;

private initializeParams?: InitializeParams;
Expand All @@ -67,8 +67,8 @@ export class LspConnection {
this.communication = new LspCommunication(this.connection);
this.handlers = new LspHandlers(this.connection);
this.authHandlers = new LspAuthHandlers(this.connection);
this.templateHandlers = new LspTemplateHandlers(this.connection);
this.stackHandlers = new LspStackHandlers(this.connection);
this.stackActionHandlers = new LspStackActionHandlers(this.connection);
this.stackHandlers = new LspStackQueryHandlers(this.connection);
this.resourceHandlers = new LspResourceHandlers(this.connection);

this.connection.onInitialize((params: InitializeParams): InitializeResult => {
Expand Down Expand Up @@ -102,8 +102,8 @@ export class LspConnection {
communication: this.communication,
handlers: this.handlers,
authHandlers: this.authHandlers,
templateHandlers: this.templateHandlers,
stackHandlers: this.stackHandlers,
stackActionHandlers: this.stackActionHandlers,
stackQueryHandlers: this.stackHandlers,
resourceHandlers: this.resourceHandlers,
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
import { Connection, ServerRequestHandler } from 'vscode-languageserver';
import {
TemplateActionParams,
TemplateActionResult,
TemplateValidationCreateRequest,
TemplateDeploymentCreateRequest,
TemplateDeploymentStatusRequest,
TemplateStatusResult,
TemplateValidationStatusRequest,
GetParametersParams,
GetParametersRequest,
} from '../stackActions/StackActionProtocol';
import {
StackActionParams,
StackActionResult,
StackActionStatusResult,
GetParametersParams,
GetParametersResult,
} from '../templates/TemplateRequestType';
} from '../stackActions/StackActionRequestType';
import { Identifiable } from './LspTypes';

export class LspTemplateHandlers {
export class LspStackActionHandlers {
constructor(private readonly connection: Connection) {}

onTemplateValidationCreate(handler: ServerRequestHandler<TemplateActionParams, TemplateActionResult, never, void>) {
onTemplateValidationCreate(handler: ServerRequestHandler<StackActionParams, StackActionResult, never, void>) {
this.connection.onRequest(TemplateValidationCreateRequest.method, handler);
}

onTemplateDeploymentCreate(handler: ServerRequestHandler<TemplateActionParams, TemplateActionResult, never, void>) {
onTemplateDeploymentCreate(handler: ServerRequestHandler<StackActionParams, StackActionResult, never, void>) {
this.connection.onRequest(TemplateDeploymentCreateRequest.method, handler);
}

onTemplateValidationStatus(handler: ServerRequestHandler<Identifiable, TemplateStatusResult, never, void>) {
onTemplateValidationStatus(handler: ServerRequestHandler<Identifiable, StackActionStatusResult, never, void>) {
this.connection.onRequest(TemplateValidationStatusRequest.method, handler);
}

onTemplateDeploymentStatus(handler: ServerRequestHandler<Identifiable, TemplateStatusResult, never, void>) {
onTemplateDeploymentStatus(handler: ServerRequestHandler<Identifiable, StackActionStatusResult, never, void>) {
this.connection.onRequest(TemplateDeploymentStatusRequest.method, handler);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Connection, ServerRequestHandler } from 'vscode-languageserver';
import { ListStacksParams, ListStacksResult, ListStacksRequest } from '../stacks/StackRequestType';

export class LspStackHandlers {
export class LspStackQueryHandlers {
constructor(private readonly connection: Connection) {}

onListStacks(handler: ServerRequestHandler<ListStacksParams, ListStacksResult, never, void>) {
Expand Down
34 changes: 21 additions & 13 deletions src/server/CfnServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import {
importResourceStateHandler,
refreshResourceListHandler,
} from '../handlers/ResourceHandler';
import { listStacksHandler } from '../handlers/StackHandler';
import {
templateValidationCreateHandler,
templateDeploymentCreateHandler,
templateValidationStatusHandler,
templateDeploymentStatusHandler,
templateParametersHandler,
} from '../handlers/TemplateHandler';
stackActionValidationCreateHandler,
stackActionDeploymentCreateHandler,
stackActionValidationStatusHandler,
stackActionDeploymentStatusHandler,
stackActionParametersHandler,
} from '../handlers/StackActionHandler';
import { listStacksHandler } from '../handlers/StackQueryHandler';
import { LspFeatures } from '../protocol/LspConnection';
import { ServerComponents } from './ServerComponents';

Expand Down Expand Up @@ -68,13 +68,21 @@ export class CfnServer {
this.features.authHandlers.onBearerCredentialsDelete(bearerCredentialsDeleteHandler(this.components));
this.features.authHandlers.onSsoTokenChanged(ssoTokenChangedHandler(this.components));

this.features.templateHandlers.onGetParameters(templateParametersHandler(this.components));
this.features.templateHandlers.onTemplateValidationCreate(templateValidationCreateHandler(this.components));
this.features.templateHandlers.onTemplateDeploymentCreate(templateDeploymentCreateHandler(this.components));
this.features.templateHandlers.onTemplateValidationStatus(templateValidationStatusHandler(this.components));
this.features.templateHandlers.onTemplateDeploymentStatus(templateDeploymentStatusHandler(this.components));
this.features.stackActionHandlers.onGetParameters(stackActionParametersHandler(this.components));
this.features.stackActionHandlers.onTemplateValidationCreate(
stackActionValidationCreateHandler(this.components),
);
this.features.stackActionHandlers.onTemplateDeploymentCreate(
stackActionDeploymentCreateHandler(this.components),
);
this.features.stackActionHandlers.onTemplateValidationStatus(
stackActionValidationStatusHandler(this.components),
);
this.features.stackActionHandlers.onTemplateDeploymentStatus(
stackActionDeploymentStatusHandler(this.components),
);

this.features.stackHandlers.onListStacks(listStacksHandler(this.components));
this.features.stackQueryHandlers.onListStacks(listStacksHandler(this.components));

this.features.resourceHandlers.onListResources(listResourcesHandler(this.components));
this.features.resourceHandlers.onRefreshResourceList(refreshResourceListHandler(this.components));
Expand Down
8 changes: 4 additions & 4 deletions src/server/ServerComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ import { DiagnosticCoordinator } from '../services/DiagnosticCoordinator';
import { GuardService } from '../services/guard/GuardService';
import { IacGeneratorService } from '../services/IacGeneratorService';
import { SettingsManager } from '../settings/SettingsManager';
import { DeploymentWorkflow } from '../stackActions/DeploymentWorkflow';
import { ValidationManager } from '../stackActions/ValidationManager';
import { ValidationWorkflow } from '../stackActions/ValidationWorkflow';
import { ClientMessage } from '../telemetry/ClientMessage';
import { StdOutLogger, LoggerFactory } from '../telemetry/LoggerFactory';
import { TelemetryService } from '../telemetry/TelemetryService';
import { DeploymentWorkflow } from '../templates/DeploymentWorkflow';
import { ValidationManager } from '../templates/ValidationManager';
import { ValidationWorkflow } from '../templates/ValidationWorkflow';

export interface Configurable {
configure(settingsManager: SettingsManager): void | Promise<void>;
Expand Down Expand Up @@ -110,7 +110,7 @@ export class ServerComponents {
private closeableComponents: Closeable[] = [];

constructor(
features: Omit<LspFeatures, 'handlers' | 'templateHandlers' | 'stackHandlers' | 'resourceHandlers'>,
features: Omit<LspFeatures, 'handlers' | 'stackActionHandlers' | 'stackQueryHandlers' | 'resourceHandlers'>,
overrides: Partial<ServerComponents> = {},
) {
this.diagnostics = features.diagnostics;
Expand Down
2 changes: 1 addition & 1 deletion src/services/CodeActionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import { NodeType } from '../context/syntaxtree/utils/NodeType';
import { DocumentManager } from '../document/DocumentManager';
import { ANALYZE_DIAGNOSTIC } from '../handlers/ExecutionHandler';
import { ServerComponents } from '../server/ServerComponents';
import { CFN_VALIDATION_SOURCE } from '../stackActions/ValidationWorkflow';
import { ClientMessage } from '../telemetry/ClientMessage';
import { LoggerFactory } from '../telemetry/LoggerFactory';
import { CFN_VALIDATION_SOURCE } from '../templates/ValidationWorkflow';
import { extractErrorMessage } from '../utils/Errors';
import { pointToPosition } from '../utils/TypeConverters';
import { DiagnosticCoordinator } from './DiagnosticCoordinator';
Expand Down
2 changes: 1 addition & 1 deletion src/services/DiagnosticCoordinator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Diagnostic, PublishDiagnosticsParams } from 'vscode-languageserver';
import { LspDiagnostics } from '../protocol/LspDiagnostics';
import { CFN_VALIDATION_SOURCE } from '../stackActions/ValidationWorkflow';
import { LoggerFactory } from '../telemetry/LoggerFactory';
import { CFN_VALIDATION_SOURCE } from '../templates/ValidationWorkflow';
import { extractErrorMessage } from '../utils/Errors';

type SourceToDiagnostics = Map<string, Diagnostic[]>;
Expand Down
Loading
Loading