Inhaltsverzeichnis

Core API

Riferimento API per la WvdS VSCode Core Extension.

Panoramica

La Core Extension fornisce servizi centrali che possono essere utilizzati da tutte le altre Extension.

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

Servizio Logging

LogInfo

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

Scrive un messaggio informativo nell'Output Channel.

LogWarn

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

Scrive un avviso nell'Output Channel.

LogError

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

Scrive un errore nell'Output Channel.

LogDebug

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

Scrive un messaggio di debug. Disponibile solo con compilazione -dDEBUG.

Servizio Toolchain

GetToolPath

function GetToolPath(ATool: TWvdSToolType): string;

Restituisce il percorso configurato per uno strumento.

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

Esempio:

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

GetToolVersion

function GetToolVersion(ATool: TWvdSToolType): string;

Restituisce la versione di uno strumento installato.

IsToolAvailable

function IsToolAvailable(ATool: TWvdSToolType): Boolean;

Verifica se uno strumento e disponibile.

AutoDetectTools

procedure AutoDetectTools;

Esegue il rilevamento automatico di tutti gli strumenti.

Configurazione

GetConfiguration

function GetConfiguration(const ASection: string): TJSObject;

Legge la configurazione VS Code.

Esempio:

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
);

Scrive la configurazione VS Code.

TConfigurationTarget Descrizione
ctGlobal Impostazioni utente
ctWorkspace Impostazioni workspace
ctWorkspaceFolder Impostazioni cartella

Event-Bus

PublishEvent

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

Pubblica un evento per altre Extension.

Esempio:

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
);

Si sottoscrive agli eventi.

Esempio:

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

Servizi UI

ShowInfoMessage

procedure ShowInfoMessage(const AMessage: string);
function ShowInfoMessage(
  const AMessage: string;
  const AItems: array of string
): TJSPromise;  // Si risolve nell'item selezionato

ShowWarningMessage

procedure ShowWarningMessage(const AMessage: string);

ShowErrorMessage

procedure ShowErrorMessage(const AMessage: string);

ShowQuickPick

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

Servizi Workspace

GetWorkspaceRoot

function GetWorkspaceRoot: string;

Restituisce il percorso alla cartella workspace.

GetOpenDocument

function GetOpenDocument: string;

Restituisce il percorso al documento attualmente aperto.

Vedi anche