AL Studio has a public API that is available for other VSCode extension developers.
This API is provided even in the Free version and can be re-used by free/opensource extensions free of charge, without purchasing license.
Complete type definitions are available on GitHub: https://github.com/dynasist/ALStudio/blob/master/extension.d.ts
export interface IExternalAPIService {
isWorkspaceScanned: boolean;
onWorkspaceScanned: Function | undefined;
getObjects(): Array<CollectorItemExternal>;
getNextId(type: ALObjectType, projectNameOrFilePath: string): Promise<number>;
getSymbolUri(type: ALObjectType, name: string, standardFormat: boolean): Uri | null;
getALLanguageApiService(): IALLanguageApiService;
}
Indicates whether the initial workspace scanning is finished.
isWorkspaceScanned: boolean;
Event fired when the initial workspace scanning is finished. You can subscribe to this event by assigning a simple function to it.
Example:
alStudioAPI.onWorkspaceScanned = () => {
console.log('Workspace has been scanned!');
}
onWorkspaceScanned: Function | undefined;
Gets the complete set of objects collected from files and symbol packages. It containes Objects, EventPublishers and EventSubscribers as well.
This list is automatically maintained by AL Studio, calling getObjects() will always return the latest, updated set.
getObjects(): Array<CollectorItemExternal>;
Gets a simplified API reference for AL Language Extension itself.
getALLanguageApiService(): IALLanguageApiService;
Gets generated preview URI for symbol objects. This can be used to manually show source code preview window of specific symbols.
getSymbolUri(type: ALObjectType, name: string, standardFormat: boolean = false): Uri | null;
Gets the next available object ID for the given object type in the specified Application name or file path. projectNameOrFilePath
can be an:
app.json
, e.g. Base Application
In latter case, the proper app.json
will be implicitly search for.
getNextId(type: ALObjectType, projectNameOrFilePath: string): Promise<number>;
See below example how to get our API reference in your extension. This sample is placed in the extension loading process, e.g. activate
function in extension.ts
. However, you may get a reference later on demand as well.
// extension.ts
import { extensions } from 'vscode';
export async function activate(context: ExtensionContext) {
// you code...
let alStudioAPI = await getAlStudioAPI();
}
async function getAlStudioAPI() {
let alStudio: Extension<any> = extensions.getExtension('dynasist.al-studio')!;
if (alStudio) {
if (!alStudio.isActive) {
await alStudio.activate();
}
return alStudio.exports;
}
}