====== Extension-Arhitektura ======
Detaljan opis interne arhitekture WvdS VSCode Extensiona.
===== Životni ciklus =====
┌─────────────────────────────────────────────────────────────┐
│ EXTENSION LIFECYCLE │
├─────────────────────────────────────────────────────────────┤
│ │
│ 1. VS Code Start │
│ ↓ │
│ 2. Activation Event se aktivira │
│ (onCommand, onLanguage, onStartupFinished, ...) │
│ ↓ │
│ 3. extension_main.js se učitava │
│ ↓ │
│ 4. Activate() se poziva │
│ → Inicijalizacija servisa │
│ → Registracija naredbi │
│ → Postavljanje Event Handlera │
│ ↓ │
│ 5. Extension je aktivan │
│ → Interakcija s korisnikom │
│ → Izvršavanje naredbi │
│ ↓ │
│ 6. VS Code Shutdown / Extension deaktiviran │
│ ↓ │
│ 7. Deactivate() se poziva │
│ → Cleanup │
│ → Oslobađanje resursa │
│ │
└─────────────────────────────────────────────────────────────┘
===== Entry Point =====
Svaki Extension ima točno jedan Entry Point: ''extension_main.pas''
unit extension_main;
{$mode objfpc}{$H+}
interface
uses
JS, VSCode.API, VSCode.ExtensionExports;
procedure Activate(AContext: TExtensionContext);
procedure Deactivate;
implementation
procedure Activate(AContext: TExtensionContext);
begin
// Inicijalizacija ovdje
end;
procedure Deactivate;
begin
// Cleanup ovdje
end;
initialization
ExportActivateDeactivate(@Activate, @Deactivate);
end.
===== Activation Events =====
^ Event ^ Opis ^ Primjer ^
| onStartupFinished | Nakon pokretanja VS Code | Core Extension |
| onCommand:* | Pri pozivu naredbe | wvds.build.run |
| onLanguage:* | Pri otvaranju datoteke | pascal, pxaml |
| onView:* | Pri otvaranju Viewa | wvds.toolbox |
| workspaceContains:** | Kada datoteka postoji | *.lpr, *.pas |
| onCustomEditor:* | Pri Custom Editoru | wvds.designer |
===== Registracija naredbi =====
procedure RegisterCommands(AContext: TExtensionContext);
begin
// Jednostavna naredba
RegisterCommand('wvds.feature.action', @HandleAction);
// Naredba s argumentima
RegisterCommand('wvds.feature.open', @HandleOpen);
// Asinkrona naredba
RegisterAsyncCommand('wvds.feature.process', @HandleProcessAsync);
end;
procedure HandleAction(Args: TJSValueDynArray);
begin
ShowInfoMessage('Akcija izvršena');
end;
function HandleProcessAsync(Args: TJSValueDynArray): TJSPromise;
begin
Result := TJSPromise.New(
procedure(Resolve, Reject: TJSPromiseResolver)
begin
// Async posao...
Resolve(nil);
end
);
end;
===== Service-Pattern =====
// Feature.Service.pas
unit Feature.Service;
interface
type
TWvdSFeatureService = class
private
FInitialized: Boolean;
public
procedure Initialize;
procedure Shutdown;
function DoWork(const AInput: string): string;
end;
var
FeatureService: TWvdSFeatureService;
implementation
procedure TWvdSFeatureService.Initialize;
begin
if FInitialized then Exit;
// Inicijalizacija servisa
FInitialized := True;
end;
procedure TWvdSFeatureService.Shutdown;
begin
if not FInitialized then Exit;
// Čišćenje
FInitialized := False;
end;
initialization
FeatureService := TWvdSFeatureService.Create;
finalization
FeatureService.Free;
end.
===== Disposables =====
VS Code koristi Disposables za upravljanje resursima:
procedure Activate(AContext: TExtensionContext);
var
Disposable: TDisposable;
begin
// Registracija naredbe i dobivanje Disposablea
Disposable := RegisterCommand('wvds.test', @Handler);
// Dodavanje u Context za automatski cleanup
AContext.Subscriptions.Push(Disposable);
end;
===== WebView-Integracija =====
procedure ShowWebViewPanel;
var
Panel: TWebviewPanel;
begin
Panel := CreateWebviewPanel(
'wvds.feature.panel', // viewType
'Feature Panel', // title
ViewColumn.One, // showOptions
WebviewOptions // options
);
// Postavljanje HTML-a
Panel.Webview.Html := GetPanelHtml;
// Postavljanje Messaginga
Panel.Webview.OnDidReceiveMessage(@HandleWebviewMessage);
// Slanje poruka
Panel.Webview.PostMessage(TJSObject.New);
end;
===== Event-Handling =====
procedure SetupEventHandlers;
begin
// Promjena konfiguracije
OnDidChangeConfiguration(@HandleConfigChange);
// Dokument-Eventi
OnDidOpenTextDocument(@HandleDocumentOpen);
OnDidSaveTextDocument(@HandleDocumentSave);
OnDidCloseTextDocument(@HandleDocumentClose);
// Workspace-Eventi
OnDidChangeWorkspaceFolders(@HandleWorkspaceChange);
end;
===== Vidi također =====
* [[.:architektur|Pregled arhitekture]]
* [[.:extension-entwicklung|Razvoj Extensiona]]
* [[.:vscode-wrapper|VSCode Wrapper API]]