Skip to content
Open
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
7 changes: 6 additions & 1 deletion extension/client/src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { commands, ExtensionContext, Uri, window } from "vscode";
import { commands, ExtensionContext, Uri, ViewColumn, window, workspace } from "vscode";
import { clearTableCache, getCache } from "./requests";
import { LanguageClient } from "vscode-languageclient/node";

export function registerCommands(context: ExtensionContext, client: LanguageClient) {
context.subscriptions.push(
commands.registerCommand(`vscode-rpgle.generateBinderSource`, async (content: string) => {
const document = await workspace.openTextDocument({ language: `bnd`, content: content });
await window.showTextDocument(document, ViewColumn.Beside);
}),

commands.registerCommand(`vscode-rpgle.server.reloadCache`, () => {
clearTableCache(client);
}),
Expand Down
28 changes: 28 additions & 0 deletions extension/server/src/providers/codeActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { documents, parser } from '.';
import Cache from '../../../../language/models/cache';
import { getLinterCodeActions } from './linter/codeActions';
import { createExtract, caseInsensitiveReplaceAll } from './language';
import Declaration from '../../../../language/models/declaration';

export default async function genericCodeActionsProvider(params: CodeActionParams): Promise<CodeAction[] | undefined> {
const uri = params.textDocument.uri;
Expand All @@ -27,6 +28,12 @@ export default async function genericCodeActionsProvider(params: CodeActionParam
actions.push(extractOption);
}

const exportedProcedures = docs.procedures.filter(proc => proc.keyword[`EXPORT`]);
if (exportedProcedures.length > 0) {
const generateOption = getGenerateBinderSourceAction(exportedProcedures);
actions.push(generateOption);
}

const linterActions = await getLinterCodeActions(docs, document, range);
if (linterActions) {
actions = actions.concat(linterActions);
Expand Down Expand Up @@ -245,4 +252,25 @@ export function getExtractProcedureAction(document: TextDocument, docs: Cache, r
return newAction;
}
}
}

export function getGenerateBinderSourceAction(exportedProcedures: Declaration[]): CodeAction {
const exportSymbols = exportedProcedures.map(proc => ` EXPORT SYMBOL('${proc.name.toUpperCase()}')`);

const binderSource = [
`STRPGMEXP PGMLVL(*CURRENT) SIGNATURE('V1')`,
...exportSymbols,
`ENDPGMEXP`
];

const newAction = CodeAction.create(`Generate binder source`, CodeActionKind.RefactorExtract);
newAction.command = {
title: 'Generate Binder Source',
command: 'vscode-rpgle.generateBinderSource',
arguments: [
binderSource.join('\n')
]
};

return newAction;
}