Inhaltsverzeichnis

Core API

API Reference for the WvdS VSCode Core Extension.

Overview

The Core Extension provides central services that can be used by all other extensions.

uses
  WvdS.Core.Services,
  WvdS.Core.Toolchain,
  WvdS.Core.Logging;

Logging Service

LogInfo

procedure LogInfo(const AMessage: string);
procedure LogInfo(const AFormat: string; const AArgs: array of const);

Writes an info message to the Output Channel.

LogWarn

procedure LogWarn(const AMessage: string);
procedure LogWarn(const AFormat: string; const AArgs: array of const);

Writes a warning to the Output Channel.

LogError

procedure LogError(const AMessage: string);
procedure LogError(const AFormat: string; const AArgs: array of const);

Writes an error to the Output Channel.

LogDebug

{$IFDEF DEBUG}
procedure LogDebug(const AMessage: string);
procedure LogDebug(const AFormat: string; const AArgs: array of const);
{$ENDIF}

Writes a debug message. Only available when compiling with -dDEBUG.

Toolchain Service

GetToolPath

function GetToolPath(ATool: TWvdSToolType): string;

Returns the configured path for a tool.

TWvdSToolType Description
ttFPC Free Pascal Compiler
ttPas2js pas2js Transpiler
ttLazbuild Lazarus Build Tool
ttInnoSetup Inno Setup Compiler
ttMake GNU Make

Example:

var
  FpcPath: string;
begin
  FpcPath := GetToolPath(ttFPC);
  if FpcPath = '' then
    raise EWvdSToolNotFound.Create(rsToolNotFound);
end;

GetToolVersion

function GetToolVersion(ATool: TWvdSToolType): string;

Returns the version of an installed tool.

IsToolAvailable

function IsToolAvailable(ATool: TWvdSToolType): Boolean;

Checks if a tool is available.

AutoDetectTools

procedure AutoDetectTools;

Performs automatic detection of all tools.

Configuration

GetConfiguration

function GetConfiguration(const ASection: string): TJSObject;

Reads VS Code configuration.

Example:

var
  Config: TJSObject;
  LogLevel: string;
begin
  Config := GetConfiguration('wvds.core');
  LogLevel := String(Config['logLevel']);
end;

UpdateConfiguration

procedure UpdateConfiguration(
  const ASection: string;
  const AKey: string;
  AValue: JSValue;
  ATarget: TConfigurationTarget
);

Writes VS Code configuration.

TConfigurationTarget Description
ctGlobal User settings
ctWorkspace Workspace settings
ctWorkspaceFolder Folder settings

Event Bus

PublishEvent

procedure PublishEvent(const AEventName: string; AData: TJSObject);

Publishes an event for other extensions.

Example:

var
  Data: TJSObject;
begin
  Data := TJSObject.New;
  Data['projectPath'] := ProjectPath;
  Data['success'] := True;
  PublishEvent('wvds.build.completed', Data);
end;

SubscribeEvent

procedure SubscribeEvent(
  const AEventName: string;
  AHandler: TWvdSEventHandler
);

Subscribes to events.

Example:

procedure HandleBuildCompleted(AData: TJSObject);
begin
  if Boolean(AData['success']) then
    LogInfo('Build succeeded!')
  else
    LogError('Build failed!');
end;
 
// On activation:
SubscribeEvent('wvds.build.completed', @HandleBuildCompleted);

UI Services

ShowInfoMessage

procedure ShowInfoMessage(const AMessage: string);
function ShowInfoMessage(
  const AMessage: string;
  const AItems: array of string
): TJSPromise;  // Resolves to selected item

ShowWarningMessage

procedure ShowWarningMessage(const AMessage: string);

ShowErrorMessage

procedure ShowErrorMessage(const AMessage: string);

ShowQuickPick

function ShowQuickPick(
  const AItems: array of string;
  const APlaceholder: string
): TJSPromise;

Workspace Services

GetWorkspaceRoot

function GetWorkspaceRoot: string;

Returns the path to the workspace folder.

GetOpenDocument

function GetOpenDocument: string;

Returns the path to the currently open document.

See Also