Skip to content

Commit

Permalink
Separate VS Code and LSP specific code lenses to maintain encapsulation
Browse files Browse the repository at this point in the history
  • Loading branch information
jake-kim1 committed Feb 5, 2025
1 parent 124449d commit 30f90ed
Show file tree
Hide file tree
Showing 12 changed files with 167 additions and 985 deletions.
28 changes: 0 additions & 28 deletions packages/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@
},
"contributes": {
"viewsContainers": {
"panel": [
{
"id": "resultsViewContainer",
"title": "Results",
"icon": ""
}
],
"activitybar": [
{
"id": "legend-activity-bar-menu",
Expand All @@ -49,30 +42,9 @@
"id": "legendConceptTree",
"name": "Concept Tree"
}
],
"resultsViewContainer": [
{
"id": "executionView",
"name": "Execution"
},
{
"type": "webview",
"id": "resultsView",
"name": "Results"
}
]
},
"viewsWelcome": [
{
"view": "executionView",
"contents": "No executions",
"when": "!showExecutionResults"
},
{
"view": "executionView",
"contents": "Execution in progress...",
"when": "isExecutionHappening"
},
{
"view": "legendConceptTree",
"contents": "[Load](command:legend.conceptTree.refresh) Legend concepts."
Expand Down
76 changes: 71 additions & 5 deletions packages/extension/src/LegendCodelensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ import {
} from './LegendLanguageClient';
import { TextDocumentIdentifier } from 'vscode-languageclient';
import { type LegendEntity } from './model/LegendEntity';
import { CLASSIFIER_PATH } from '@finos/legend-engine-ide-client-vscode-shared';
import {
ACTIVATE_FUNCTION_ID,
CLASSIFIER_PATH,
EXEC_FUNCTION_ID,
LEGEND_SHOW_DIAGRAM_CODELENS,
type TextLocation,
} from '@finos/legend-engine-ide-client-vscode-shared';

export class LegendCodelensProvider implements CodeLensProvider {
private client: LegendLanguageClient;
Expand All @@ -37,6 +43,60 @@ export class LegendCodelensProvider implements CodeLensProvider {
this.client = client;
}

private addActivateFunctionCodeLens(entityLocation: TextLocation): void {
this.codeLenses.push(
new CodeLens(
new Range(
entityLocation.textInterval.start.line,
entityLocation.textInterval.start.column,
entityLocation.textInterval.end.line,
entityLocation.textInterval.end.column,
),
{
title: 'Activate',
command: ACTIVATE_FUNCTION_ID,
arguments: [entityLocation],
},
),
);
}

private addExecuteFunctionCodeLens(entityLocation: TextLocation): void {
this.codeLenses.push(
new CodeLens(
new Range(
entityLocation.textInterval.start.line,
entityLocation.textInterval.start.column,
entityLocation.textInterval.end.line,
entityLocation.textInterval.end.column,
),
{
title: 'Execute',
command: EXEC_FUNCTION_ID,
arguments: [entityLocation],
},
),
);
}

private addViewEditDiagramCodeLens(entity: LegendEntity): void {
this.codeLenses.push(
new CodeLens(
new Range(
entity.location.textInterval.start.line,
entity.location.textInterval.start.column,
entity.location.textInterval.end.line,
entity.location.textInterval.end.column,
),
{
title: 'View/Edit Diagram',
command: LEGEND_SHOW_DIAGRAM_CODELENS,
arguments: [entity],
},
),
);
}

private addQueryBuilderCodeLens(entity: LegendEntity): void {
this.codeLenses.push(
new CodeLens(
Expand Down Expand Up @@ -68,12 +128,18 @@ export class LegendCodelensProvider implements CodeLensProvider {
_token,
);
entities.forEach((entity) => {
if (
entity.classifierPath === CLASSIFIER_PATH.SERVICE ||
entity.classifierPath === CLASSIFIER_PATH.FUNCTION
) {
if (entity.classifierPath === CLASSIFIER_PATH.SERVICE) {
this.addExecuteFunctionCodeLens(entity.location);
this.addQueryBuilderCodeLens(entity);
}
if (entity.classifierPath === CLASSIFIER_PATH.FUNCTION) {
this.addActivateFunctionCodeLens(entity.location);
this.addExecuteFunctionCodeLens(entity.location);
this.addQueryBuilderCodeLens(entity);
}
if (entity.classifierPath === CLASSIFIER_PATH.DIAGRAM) {
this.addViewEditDiagramCodeLens(entity);
}
});
return this.codeLenses;
}
Expand Down
42 changes: 42 additions & 0 deletions packages/extension/src/LegendLanguageClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {
EXECUTE_TESTS_REQUEST_ID,
GENERATE_EXECUTION_PLAN_COMMAND_ID,
GET_CLASSIFIER_PATH_MAP_REQUEST_ID,
GET_EXECUTE_FUNCTION_DESCRIPTION_ID,
GET_FUNCTION_ACTIVATOR_SNIPPETS_ID,
GET_LAMBDA_RETURN_TYPE_COMMAND_ID,
GET_QUERY_TYPEAHEAD_COMMAND_ID,
GET_SUBTYPE_INFO_REQUEST_ID,
Expand Down Expand Up @@ -548,4 +550,44 @@ export class LegendLanguageClient extends LanguageClient {
executableArgs,
);
}

async getExecuteFunctionDescription(
entityDetails:
| TextLocation
| { documentUri: string; sectionIndex: number; entityId: string },
): Promise<LegendExecutionResult[]> {
return entityDetails instanceof TextLocation
? commands.executeCommand(
LEGEND_COMMAND,
entityDetails,
GET_EXECUTE_FUNCTION_DESCRIPTION_ID,
)
: commands.executeCommand(
LEGEND_COMMAND,
entityDetails.documentUri,
entityDetails.sectionIndex,
entityDetails.entityId,
GET_EXECUTE_FUNCTION_DESCRIPTION_ID,
);
}

async getFunctionActivatorSnippets(
entityDetails:
| TextLocation
| { documentUri: string; sectionIndex: number; entityId: string },
): Promise<LegendExecutionResult[]> {
return entityDetails instanceof TextLocation
? commands.executeCommand(
LEGEND_COMMAND,
entityDetails,
GET_FUNCTION_ACTIVATOR_SNIPPETS_ID,
)
: commands.executeCommand(
LEGEND_COMMAND,
entityDetails.documentUri,
entityDetails.sectionIndex,
entityDetails.entityId,
GET_FUNCTION_ACTIVATOR_SNIPPETS_ID,
);
}
}

This file was deleted.

Loading

0 comments on commit 30f90ed

Please sign in to comment.