====== Izrada Control VSIX ======
Upute za izradu VSIX Extension za WvdS Control.
===== Pregled =====
Svaki WvdS Control distribuira se kao samostalna VSIX Extension:
wvds-vscode-ui-{control}-0.1.0.vsix
├── package.json # Extension Manifest
├── dist/
│ └── extension_main.js # Kompilirani kod
├── images/
│ └── icon.png # Extension Icon
└── pas/
└── extension_main.pas # Pascal-izvorni kod
===== Struktura direktorija =====
sources/extensions/wvds.vscode.ui.controls/
├── {category}/
│ └── wvds.vscode.ui.{control}/
│ ├── package.json
│ ├── build.cfg
│ ├── pas/
│ │ └── extension_main.pas
│ └── dist/ # Build-Output
│ └── extension_main.js
===== Korak 1: Kreiranje direktorija =====
$ControlName = "mycontrol"
$Category = "editors"
$BasePath = "sources/extensions/wvds.vscode.ui.controls"
New-Item -ItemType Directory -Path "$BasePath/$Category/wvds.vscode.ui.$ControlName/pas" -Force
===== Korak 2: package.json =====
{
"name": "wvds-vscode-ui-mycontrol",
"displayName": "WvdS UI: MyControl",
"description": "MyControl component for WvdS UI Framework",
"version": "0.1.0",
"publisher": "ArmandoFilho",
"icon": "images/icon.png",
"engines": {
"vscode": "^1.85.0"
},
"categories": [
"Other"
],
"activationEvents": [
"onLanguage:pxaml"
],
"main": "./dist/extension_main.js",
"contributes": {
"snippets": [
{
"language": "pxaml",
"path": "./snippets/mycontrol.json"
}
]
},
"repository": {
"type": "git",
"url": "https://github.com/ArmandoFilho/WvdS.FPC"
},
"license": "MIT"
}
===== Korak 3: extension_main.pas =====
library extension_main;
{$mode objfpc}
{$modeswitch externalclass}
uses
JS, Web,
VSCode.Base, VSCode.Commands, VSCode.Window;
type
TExtension = class
public
class procedure Activate(AContext: TVSCodeExtensionContext);
class procedure Deactivate;
end;
class procedure TExtension.Activate(AContext: TVSCodeExtensionContext);
var
Disposable: TVSCodeDisposable;
begin
(* Registriraj snippet provider *)
Disposable := TVSCodeCommands.RegisterCommand(
'wvds.ui.mycontrol.insert',
@InsertSnippet
);
AContext.Subscriptions.Push(Disposable);
end;
class procedure TExtension.Deactivate;
begin
(* Cleanup *)
end;
procedure InsertSnippet;
begin
asm
const snippet = '';
vscode.window.activeTextEditor?.insertSnippet(
new vscode.SnippetString(snippet)
);
end;
end;
exports
Activate,
Deactivate;
begin
end.
===== Korak 4: build.cfg =====
-Mobjfpc
-Tnodejs
-O-
-Jc
-Jirtl.js
-Fu../../../common
-FUpas
-FEdist
-odist/extension_main.js
===== Korak 5: Kompiliranje =====
$ExtPath = "sources/extensions/wvds.vscode.ui.controls/editors/wvds.vscode.ui.mycontrol"
# Kompiliraj s pas2js
pas2js @"$ExtPath/build.cfg" "$ExtPath/pas/extension_main.pas"
===== Korak 6: Pakiranje VSIX =====
cd $ExtPath
# Kopiraj ikonu (ako ne postoji)
if (-not (Test-Path "images")) {
New-Item -ItemType Directory -Path "images" -Force
Copy-Item "%MEDIA%/wvds_fpc.png" "images/icon.png"
}
# Kreiraj VSIX
vsce package --no-dependencies
# Premjesti u dist
Move-Item "*.vsix" "%BINARIES%/dist/"
===== Snippet-definicija =====
Kreiraj ''snippets/mycontrol.json'':
{
"WvdS MyControl": {
"prefix": "wvds-mycontrol",
"body": [
""
],
"description": "Insert WvdS MyControl"
}
}
===== Potpuni primjer =====
==== Button Extension ====
library extension_main;
{$mode objfpc}
{$modeswitch externalclass}
uses
JS, Web,
VSCode.Base, VSCode.Commands, VSCode.Window,
VSCode.Languages, VSCode.CompletionItem;
const
CONTROL_NAME = 'Button';
CONTROL_CATEGORY = 'Basic Controls';
CONTROL_ICON = 'symbol-event';
type
TButtonExtension = class
public
class procedure Activate(AContext: TVSCodeExtensionContext);
class procedure Deactivate;
private
class procedure RegisterSnippet(AContext: TVSCodeExtensionContext);
class procedure RegisterCompletionProvider(AContext: TVSCodeExtensionContext);
end;
class procedure TButtonExtension.Activate(AContext: TVSCodeExtensionContext);
begin
RegisterSnippet(AContext);
RegisterCompletionProvider(AContext);
asm
console.log('WvdS UI: Button extension activated');
end;
end;
class procedure TButtonExtension.Deactivate;
begin
(* Cleanup *)
end;
class procedure TButtonExtension.RegisterSnippet(AContext: TVSCodeExtensionContext);
var
Cmd: TVSCodeDisposable;
begin
Cmd := TVSCodeCommands.RegisterCommand(
'wvds.ui.button.insert',
procedure
begin
asm
const editor = vscode.window.activeTextEditor;
if (editor) {
const snippet = new vscode.SnippetString(
''
);
editor.insertSnippet(snippet);
}
end;
end
);
AContext.Subscriptions.Push(Cmd);
end;
class procedure TButtonExtension.RegisterCompletionProvider(
AContext: TVSCodeExtensionContext);
begin
(* PXAML completion provider *)
asm
const provider = vscode.languages.registerCompletionItemProvider(
{ language: 'pxaml', scheme: 'file' },
{
provideCompletionItems(document, position) {
const item = new vscode.CompletionItem('Button', vscode.CompletionItemKind.Class);
item.insertText = new vscode.SnippetString(
''
);
item.documentation = 'WvdS Button control';
return [item];
}
},
'<'
);
AContext.subscriptions.push(provider);
end;
end;
procedure Activate(AContext: TJSObject);
begin
TButtonExtension.Activate(TVSCodeExtensionContext(AContext));
end;
procedure Deactivate;
begin
TButtonExtension.Deactivate;
end;
exports
Activate,
Deactivate;
begin
end.
===== Batch-generiranje =====
Za više kontrola, vidi [[.:control-generierung|Generiranje kontrola]].
===== Rješavanje problema =====
==== pas2js greške ====
| Greška | Rješenje |
^ ''class var'' nije podržan | Koristi Unit-Level Variable |
^ ''Int64'' nije podržan | Koristi ''Integer'' |
^ ''//'' u asm-bloku | Koristi ''/* */'' za JS-komentare |
==== VSIX greške ====
| Greška | Rješenje |
^ Missing publisher | Postavi ''publisher'' u package.json |
^ Icon not found | Kreiraj ''images/icon.png'' |
^ Invalid main | Provjeri putanju u ''main'' |
===== Vidi također =====
* [[.:control-generierung|Generiranje kontrola]]
* [[.:control-architektur|Arhitektura kontrola]]
* [[.:extension-entwicklung|Razvoj ekstenzija]]