Skip to main content

Extension Commands and Settings Reference

This reference document provides comprehensive information about all available commands, settings, keyboard shortcuts, and configuration options in the Infrahub VSCode extension.

Commands​

Available Commands​

The extension registers the following commands that can be executed via the Command Palette (Ctrl+Shift+P / Cmd+Shift+P):

Command IDTitleDescriptionContext
infrahub.editInfrahubYamlEdit fileOpens the selected YAML file at a specific locationTree view item
infrahub.editGqlQueryEdit GraphQL QueryOpens the GraphQL query file for editingQuery tree item
infrahub.executeGraphQLQueryExecute GraphQL QueryRuns a GraphQL query against selected server/branchQuery tree item
infrahub.newBranchNew BranchCreates a new branch on the selected serverServer tree item
infrahub.deleteBranchDelete BranchDeletes the selected branchBranch tree item

Command Execution​

From Command Palette​

  1. Press Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (macOS)
  2. Type "Infrahub" to filter commands
  3. Select the desired command

From Context Menus​

Right-click on tree view items to access contextual commands:

  • Server Items: New Branch
  • Branch Items: Delete Branch
  • Query Items: Execute Query, Edit Query
  • YAML Items: Edit File

Programmatic Execution​

Commands can be executed programmatically:

// Execute a command from another extension
vscode.commands.executeCommand('infrahub.executeGraphQLQuery', queryItem);

Extension Settings​

Configuration Properties​

All settings are prefixed with infrahub-vscode.:

SettingTypeDefaultDescription
serversarray[]List of Infrahub server configurations
schemaDirectorystring"schemas"Path to directory containing schema files

Server Configuration Schema​

Each server in the servers array follows this structure:

interface ServerConfig {
name: string; // Display name for the server
address: string; // Server URL (http/https)
api_token?: string; // Optional API token for authentication
}

Example Configuration​

{
"infrahub-vscode.servers": [
{
"name": "Local Development",
"address": "http://localhost:8000"
},
{
"name": "Production",
"address": "https://infrahub.example.com",
"api_token": "inf_1234567890abcdef"
}
],
"infrahub-vscode.schemaDirectory": "infrastructure/schemas"
}

Environment Variable Substitution​

Settings support environment variable substitution using ${env:VARIABLE_NAME}:

{
"infrahub-vscode.servers": [
{
"name": "Production",
"address": "${env:INFRAHUB_SERVER_URL}",
"api_token": "${env:INFRAHUB_API_TOKEN}"
}
]
}

Tree View Components​

Infrahub Servers Tree View​

View ID: InfrahubServerTreeView Location: Activity Bar → Infrahub Container

Tree Structure​

📁 Infrahub Servers
└─ 🖥️ [Server Name]
├─ 🌿 main (default)
├─ 🌿 feature-branch-1
└─ 🌿 feature-branch-2

Item Types​

Item TypeView Item IDAvailable Actions
ServerinfrahubServerNew Branch
Branch (default)infrahubBranch-defaultDelete Branch
Branch (regular)infrahubBranchDelete Branch

Infrahub YAML Tree View​

View ID: infrahubYamlTreeView Location: Activity Bar → Infrahub Container

Tree Structure​

📁 Infrahub YAML
└─ 📄 .infrahub.yml
├─ 📁 schemas
│ ├─ 📄 network.yml
│ └─ 📄 location.yml
├─ 📁 queries
│ ├─ 📊 get_devices
│ └─ 📊 topology_report
└─ 📁 checks
└─ 🔍 validate_hostnames

Item Types​

Item TypeView Item ID PatternAvailable Actions
YAML FilefileEdit File
Queryqueries/*Execute Query, Edit Query
Schemaschemas/*Edit File
Checkchecks/*Edit File

Status Bar​

Status Bar Item​

Alignment: Left Priority: 100

Status States​

StateDisplay TextBackground Color
ConnectedInfrahub: v[version] ([server])Default
No ServerInfrahub: No server setNo folder background
UnreachableInfrahub: Server unreachableError background

Update Interval​

  • Status updates every 10 seconds
  • Displays first configured server's status

Activation Events​

The extension activates when:

"activationEvents": [
"workspaceContains:.infrahub.yml",
"workspaceContains:.infrahub.yaml"
]

File Associations​

YAML Validation​

Files matching these patterns receive schema validation:

"yamlValidation": [
{
"fileMatch": [
"models/**/*.yml",
"models/**/*.yaml",
"schemas/**/*.yml",
"schemas/**/*.yaml"
],
"url": "https://schema.infrahub.app/infrahub/schema/latest.json"
}
]

Language Features​

Definition Provider​

Language: YAML Feature: Go-to-definition (F12 or Ctrl+Click)

Navigates to:

  • Schema definitions
  • Referenced nodes
  • Relationship targets

Document Symbol Provider​

Language: YAML Feature: Document outline

Provides symbols for:

  • Nodes
  • Attributes
  • Relationships
  • Queries
  • Checks

Context Menu Integration​

View Item Context Menus​

Commands appear in context menus based on when clauses:

"menus": {
"view/item/context": [
{
"command": "infrahub.newBranch",
"when": "view == InfrahubServerTreeView && viewItem == infrahubServer"
},
{
"command": "infrahub.deleteBranch",
"when": "view == InfrahubServerTreeView && viewItem =~ /^infrahubBranch/"
}
]
}

Extension Dependencies​

Required Extensions​

"extensionDependencies": [
"redhat.vscode-yaml" // YAML language support
]

The Red Hat YAML extension must be installed for schema validation to work.

API Token Management​

Token Format​

Infrahub API tokens typically follow this format:

inf_[32-character-alphanumeric-string]

Token Security Best Practices​

  1. Never commit tokens: Use environment variables
  2. Rotate regularly: Change tokens periodically
  3. Minimal permissions: Use read-only tokens when possible
  4. Separate environments: Different tokens per environment

Token Configuration Methods​

{
"infrahub-vscode.servers": [
{
"api_token": "inf_direct_token_not_secure"
}
]
}
{
"infrahub-vscode.servers": [
{
"api_token": "${env:INFRAHUB_TOKEN}"
}
]
}

Method 3: VSCode Secrets (Future)​

Planned support for VSCode's secret storage API.

Troubleshooting Reference​

Common Issues and Solutions​

IssuePossible CauseSolution
Extension not activatingNo .infrahub.yml fileCreate .infrahub.yml in workspace root
Server unreachableInvalid URL or network issueCheck server URL and network connection
Commands not appearingWrong contextEnsure correct tree view item is selected
Validation not workingMissing YAML extensionInstall Red Hat YAML extension
Token not workingIncorrect format or permissionsVerify token format and permissions

Debug Output​

Enable debug logging:

  1. Open VSCode Developer Tools: Help → Toggle Developer Tools
  2. Check Console tab for extension logs
  3. Look for messages starting with "Infrahub Extension"

Keyboard Shortcuts​

The extension doesn't define default keyboard shortcuts, but you can add custom ones:

Adding Custom Shortcuts​

  1. Open Keyboard Shortcuts: Ctrl+K Ctrl+S (Windows/Linux) or Cmd+K Cmd+S (macOS)
  2. Search for "Infrahub"
  3. Click the + icon to add a keybinding

Suggested Shortcuts​

{
"key": "ctrl+alt+q",
"command": "infrahub.executeGraphQLQuery",
"when": "view == infrahubYamlTreeView"
},
{
"key": "ctrl+alt+b",
"command": "infrahub.newBranch",
"when": "view == InfrahubServerTreeView"
}

Performance Settings​

Refresh Intervals​

ComponentIntervalConfigurable
Server Tree View10 secondsNo (hardcoded)
Status Bar10 secondsNo (hardcoded)

Resource Limits​

  • Maximum servers: No limit (performance may degrade with >10)
  • Query result size: Limited by VSCode webview memory
  • Tree view items: No hard limit

Version Compatibility​

VSCode Version​

  • Minimum: 1.99.0
  • Recommended: Latest stable version

Infrahub Server Version​

  • Minimum: 0.14.0 (basic functionality)
  • Recommended: 0.15.0+ (all features)

Node.js Runtime​

  • Target: ES2022
  • Module System: Node16

Extension Metadata​

Publisher Information​

"galleryBanner": {
"color": "#2183F7",
"theme": "dark"
}

Further Information​