Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 39 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,72 +1,82 @@
# Struct YAML Support for VS Code
# StructKit

A VS Code extension that provides enhanced support for struct YAML configuration files with schema validation and intelligent autocomplete.
Official StructKit extension for VS Code and Cursor with schema validation and intelligent autocomplete for `.struct.yaml` configuration files.

## Features

- **Schema Validation**: Automatic validation of `*.struct.yaml` files using the official struct schema
- **Custom Schema Generation**: Generate custom schemas based on your struct configurations
- **Intelligent Autocomplete**: Get suggestions and validation while editing struct files
- **Configurable Struct Path**: Set custom path to your struct command executable
- **Schema Validation**: Automatic validation of `*.struct.yaml` files using the official StructKit schema
- **Custom Schema Generation**: Generate custom schemas based on your StructKit configurations
- **Intelligent Autocomplete**: Get suggestions and validation while editing StructKit files
- **Configurable CLI Path**: Set custom path to your `structkit` command executable
- **Custom Structures Support**: Configure path to custom structures for enhanced validation

## Installation

### Prerequisites

Install the StructKit CLI:

```bash
pip install structkit
```

### Extension Installation

- **From Marketplace** (coming soon): Search for "StructKit" in VS Code/Cursor extensions
- **From VSIX**: Download the `.vsix` file and install via `code --install-extension structkit-*.vsix`

## Configuration

### Extension Settings

This extension contributes the following settings:

- `struct.commandPath`: Path to the struct command executable (default: `struct`)
- `struct.customStructuresPath`: Path to custom structures directory (default: empty)
- `structkit.commandPath`: Path to the structkit command executable (default: `structkit`)
- `structkit.customStructuresPath`: Path to custom structures directory (default: empty)

### Setting up the Extension

1. Install the extension
2. Configure the struct command path in VS Code settings:
2. Install StructKit CLI: `pip install structkit`
3. Configure the structkit command path in VS Code settings (optional):
- Open VS Code settings (Ctrl/Cmd + ,)
- Search for "struct"
- Set `struct.commandPath` to the path of your struct executable
- Optionally set `struct.customStructuresPath` to your custom structures directory
- Search for "structkit"
- Set `structkit.commandPath` to the path of your structkit executable
- Optionally set `structkit.customStructuresPath` to your custom structures directory

## Commands

- `Struct: Generate Custom Schema` - Generate a custom schema based on your struct configuration
- `Struct: Refresh Schema` - Refresh the schema validation
- `StructKit: Generate Custom Schema` - Generate a custom schema based on your StructKit configuration
- `StructKit: Refresh Schema` - Refresh the schema validation

## Usage

1. Create or open a file with the `.struct.yaml` extension
2. The extension will automatically apply schema validation
3. If you have custom structures configured, use the "Generate Custom Schema" command to create enhanced validation
4. Enjoy intelligent autocomplete and validation while editing your struct files
4. Enjoy intelligent autocomplete and validation while editing your StructKit files

## Requirements

- VS Code 1.74.0 or higher
- struct command-line tool (optional, for custom schema generation)

## Extension Settings

This extension contributes the following settings:

* `struct.commandPath`: Path to the struct command executable
* `struct.customStructuresPath`: Path to custom structures directory
- VS Code or Cursor 1.74.0 or higher
- StructKit CLI: `pip install structkit` (required for custom schema generation)

## Known Issues

- Custom schema generation requires the struct command to be available in your system
- Schema validation is currently limited to `*.struct.yaml` files
- Custom schema generation requires the `structkit` command to be available in your system
- Schema validation is currently optimized for `*.struct.yaml` files

## Release Notes

### 0.1.0

Initial release of Struct YAML Support extension:
Initial release of the official StructKit extension:

- Basic schema validation for `*.struct.yaml` files
- Schema validation for `*.struct.yaml` files using official StructKit schema
- Custom schema generation support
- Configurable struct command path
- Configurable structkit command path
- Custom structures path configuration
- Support for VS Code and Cursor

## Contributing

Expand Down
32 changes: 23 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vscode-struct",
"displayName": "Struct YAML Support",
"description": "VS Code extension for struct YAML configuration files with schema validation",
"displayName": "StructKit",
"description": "Official StructKit extension for VS Code and Cursor with schema validation and intelligent autocomplete",
"version": "0.1.0",
"publisher": "kennethbelitzky",
"engines": {
Expand All @@ -13,35 +13,49 @@
"Formatters"
],
"activationEvents": [
"onLanguage:yaml"
"onLanguage:yaml",
"workspaceContains:**/.struct.yaml",
"workspaceContains:**/*.struct.yaml"
],
"main": "./out/extension.js",
"contributes": {
"configuration": {
"title": "Struct",
"title": "StructKit",
"properties": {
"structkit.commandPath": {
"type": "string",
"default": "structkit",
"description": "Path to the structkit command executable"
},
"structkit.customStructuresPath": {
"type": "string",
"default": "",
"description": "Path to custom structures directory"
},
"struct.commandPath": {
"type": "string",
"default": "struct",
"description": "Path to the struct command executable"
"default": "structkit",
"description": "Deprecated: Use structkit.commandPath instead",
"deprecationMessage": "This setting is deprecated. Please use structkit.commandPath instead."
},
"struct.customStructuresPath": {
"type": "string",
"default": "",
"description": "Path to custom structures directory"
"description": "Deprecated: Use structkit.customStructuresPath instead",
"deprecationMessage": "This setting is deprecated. Please use structkit.customStructuresPath instead."
}
}
},
"commands": [
{
"command": "struct.generateSchema",
"title": "Generate Custom Schema",
"category": "Struct"
"category": "StructKit"
},
{
"command": "struct.refreshSchema",
"title": "Refresh Schema",
"category": "Struct"
"category": "StructKit"
}
]
},
Expand Down
22 changes: 22 additions & 0 deletions schemas/struct-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,28 @@
}
}
},
"sources": {
"type": "object",
"description": "File-local named structure sources. These override user-level sources at the top level and are inherited by nested structs.",
"patternProperties": {
".*": {
"oneOf": [
{ "type": "string" },
{
"type": "object",
"properties": {
"path": { "type": "string" },
"url": { "type": "string" }
},
"additionalProperties": false,
"minProperties": 1,
"maxProperties": 1
}
]
}
},
"additionalProperties": false
},
"pre_hooks": {
"type": "array",
"items": { "type": "string" },
Expand Down
50 changes: 33 additions & 17 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
function updateStatusBar(isAvailable: boolean) {
if (isAvailable) {
statusBarItem.text = 'Struct: $(check) Available';
statusBarItem.text = 'StructKit: $(check) Available';
statusBarItem.color = 'lightgreen';
} else {
statusBarItem.text = 'Struct: $(x) Not Available';
statusBarItem.text = 'StructKit: $(x) Not Available';
statusBarItem.color = 'red';
}
statusBarItem.show();
Expand All @@ -22,7 +22,7 @@ let statusBarItem: vscode.StatusBarItem;
let documentSelector: vscode.DocumentSelector = { pattern: '**/*.struct.yaml' };

export function activate(context: vscode.ExtensionContext) {
console.log('Struct YAML extension is now active!');
console.log('StructKit extension is now active!');

// Create status bar item
statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100);
Expand All @@ -31,7 +31,7 @@ export function activate(context: vscode.ExtensionContext) {

// Register configuration change listener
const configWatcher = vscode.workspace.onDidChangeConfiguration(event => {
if (event.affectsConfiguration('struct')) {
if (event.affectsConfiguration('structkit') || event.affectsConfiguration('struct')) {
updateSchemaForStructFiles();
}
});
Expand All @@ -55,10 +55,27 @@ export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(configWatcher, generateSchemaCommand, refreshSchemaCommand);
}

function getConfig(key: string, defaultValue: string): string {
// Try new structkit config first, fall back to old struct config
const newConfig = vscode.workspace.getConfiguration('structkit');
const oldConfig = vscode.workspace.getConfiguration('struct');

const newValue = newConfig.get<string>(key);
if (newValue !== undefined && newValue !== '') {
return newValue;
}

const oldValue = oldConfig.get<string>(key);
if (oldValue !== undefined && oldValue !== '') {
return oldValue;
}

return defaultValue;
}

async function updateSchemaForStructFiles() {
const config = vscode.workspace.getConfiguration('struct');
const structPath = config.get<string>('commandPath', 'struct');
const customStructuresPath = config.get<string>('customStructuresPath', '');
const structPath = getConfig('commandPath', 'structkit');
const customStructuresPath = getConfig('customStructuresPath', '');

try {
// Check if struct command is available
Expand All @@ -72,33 +89,32 @@ async function updateSchemaForStructFiles() {
await generateCustomSchema();
}
} catch (error: any) {
console.log(`[DEBUG] Command failed: ${structPath} list`);
console.log(`[DEBUG] Command failed: ${structPath} list`);
console.log(`[DEBUG] Error:`, error.message || error);
console.log('Struct command not found or not working, using default schema');
console.log('StructKit command not found or not working, using default schema');
updateStatusBar(false);
vscode.window.showWarningMessage(`Struct command not found. Please [install](https://github.com/httpdss/struct/blob/main/docs/installation.md) it to use all features of this extension.`, 'Install').then(selection => {
vscode.window.showWarningMessage('StructKit CLI not found. Install it with: pip install structkit', 'Install').then(selection => {
if (selection === 'Install') {
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse('https://github.com/httpdss/struct/blob/main/docs/installation.md'));
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse('https://github.com/httpdss/structkit'));
}
});
}
}

async function generateCustomSchema(): Promise<void> {
const config = vscode.workspace.getConfiguration('struct');
const structPath = config.get<string>('commandPath', 'struct');
const customStructuresPath = config.get<string>('customStructuresPath', '');
const structPath = getConfig('commandPath', 'structkit');
const customStructuresPath = getConfig('customStructuresPath', '');

// Check if struct command is available first
// Check if structkit command is available first
try {
await execAsync(`${structPath} list`);
} catch (error) {
vscode.window.showErrorMessage(
'Struct command not found. Please install it first to generate custom schemas.',
'StructKit CLI not found. Install it with: pip install structkit',
'Install'
).then(selection => {
if (selection === 'Install') {
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse('https://github.com/httpdss/struct/blob/main/docs/installation.md'));
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse('https://github.com/httpdss/structkit'));
}
});
return;
Expand Down
Loading