Skip to content

Commit

Permalink
feat: Demo of codelens for Jake
Browse files Browse the repository at this point in the history
  • Loading branch information
travisstebbins committed Jan 28, 2025
1 parent b50fc48 commit 71fe98a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
23 changes: 22 additions & 1 deletion packages/extension/src/LegendCodelensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ 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 { CLASSIFIER_PATH, TextLocation } from '@finos/legend-engine-ide-client-vscode-shared';

Check warning on line 30 in packages/extension/src/LegendCodelensProvider.ts

View workflow job for this annotation

GitHub Actions / Run Code Checks

Imports "TextLocation" are only used as type

export class LegendCodelensProvider implements CodeLensProvider {
private client: LegendLanguageClient;
Expand Down Expand Up @@ -55,6 +55,24 @@ export class LegendCodelensProvider implements CodeLensProvider {
);
}

private addDatabaseCodeLens(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: 'Edit/Execute in QueryBuilder',
command: LEGEND_GENERATE_MODELS,
arguments: [entityLocation],
},
),
);
}

public async provideCodeLenses(
document: TextDocument,
_token: CancellationToken,
Expand All @@ -74,6 +92,9 @@ export class LegendCodelensProvider implements CodeLensProvider {
) {
this.addQueryBuilderCodeLens(entity);
}
if (entity.classifierPath === CLASSIFIER_PATH.RELATION) {
this.addDatabaseCodeLens(entity.location);
}
});
return this.codeLenses;
}
Expand Down
20 changes: 20 additions & 0 deletions packages/extension/src/LegendLanguageClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,4 +548,24 @@ export class LegendLanguageClient extends LanguageClient {
executableArgs,
);
}

async generateModels(
entityDetails:
| TextLocation
| { documentUri: string; sectionIndex: number; entityId: string },
): Promise<LegendExecutionResult[]> {
return entityDetails instanceof TextLocation
? commands.executeCommand(
LEGEND_COMMAND,
entityDetails,
GET_QUERY_TYPEAHEAD_COMMAND_ID,
)
: commands.executeCommand(
LEGEND_COMMAND,
entityDetails.documentUri,
entityDetails.sectionIndex,
entityDetails.entityId,
GET_QUERY_TYPEAHEAD_COMMAND_ID,
);
}
}
10 changes: 10 additions & 0 deletions packages/extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import {
SERVICE_QUERY_EDITOR,
SHOW_RESULTS_COMMAND_ID,
TDSLegendExecutionResult,
TextLocation,
} from '@finos/legend-engine-ide-client-vscode-shared';
import { LegendWebViewProvider } from './utils/LegendWebViewProvider';
import {
Expand Down Expand Up @@ -501,6 +502,15 @@ export function registerCommands(context: ExtensionContext): void {
);
context.subscriptions.push(editInQueryBuilder);

const generateModels = commands.registerCommand(

Check warning on line 505 in packages/extension/src/extension.ts

View workflow job for this annotation

GitHub Actions / Run Code Checks

'generateModels' is assigned a value but never used
LEGEND_GENERATE_MODELS, // TODO: add as const
async (...args: unknown[]) => {
const path = args[0] as TextLocation;

Check warning on line 508 in packages/extension/src/extension.ts

View workflow job for this annotation

GitHub Actions / Run Code Checks

'path' is already declared in the upper scope on line 17 column 13
await client.generateModels(path);
}

)

Check warning on line 512 in packages/extension/src/extension.ts

View workflow job for this annotation

GitHub Actions / Run Code Checks

Missing semicolon

const oneEntityPerFileRefactor = commands.registerCommand(
ONE_ENTITY_PER_FILE_COMMAND_ID,
() => {
Expand Down

0 comments on commit 71fe98a

Please sign in to comment.