The valaq CLI application is a tool for querying and exploring VAPI (Vala API) files. It provides hierarchical navigation of symbols within VAPI files with support for both human-readable and JSON output formats.
┌─────────────────┐
│ CLI Interface │
└─────────┬───────┘
│
┌─────────▼───────┐
│ Symbol Navigator│
└─────────┬───────┘
│
┌─────────▼───────┐
│ VAPI Parser │
│ (libvala) │
└─────────┬───────┘
│
┌─────────▼───────┐
│ File System │
│ Interface │
└─────────────────┘
valaq/
├── src/
│ ├── main.vala # Application entry point
│ ├── cli/
│ │ ├── argument-parser.vala # Command-line argument parsing
│ │ └── command-handler.vala # Command processing logic
│ ├── core/
│ │ ├── vapi-parser.vala # VAPI file parsing using libvala
│ │ ├── symbol-navigator.vala # Symbol hierarchy navigation
│ │ └── symbol-model.vala # Data models for symbols
│ ├── output/
│ │ ├── formatter.vala # Output formatting interface
│ │ ├── text-formatter.vala # Human-readable output
│ │ └── json-formatter.vala # JSON output formatting
│ └── utils/
│ ├── file-utils.vala # File system operations
│ └── error-handling.vala # Error handling utilities
├── tests/
│ ├── test-vapi-parser.vala
│ ├── test-symbol-navigator.vala
│ └── test-output-formatters.vala
├── meson.build # Build configuration
└── README.md
ValaqApplicationmain(string[] args) - Application entry pointrun() - Main application loopArgumentParserparse(string[] args) - Parse command line argumentsget_vapi_path() - Get VAPI file path from argumentsget_symbol_path() - Get symbol navigation pathis_json_output() - Check if JSON output requestedVapiParserparse_file(string path) - Parse a VAPI fileget_root_symbols() - Get top-level symbolsget_symbol_details(Symbol symbol) - Get detailed symbol informationSymbolNavigatornavigate_to_path(string[] path) - Navigate to symbol pathget_child_symbols(Symbol parent) - Get child symbolsfind_symbol_by_name(string name) - Find symbol by nameTextFormatter / JsonFormatterformat_symbol_list(Symbol[] symbols) - Format symbol listformat_symbol_details(Symbol symbol) - Format symbol detailsSymbolClass, Interface, Struct, Enum, Delegate, Method, Property, Fieldgraph TD
A[CLI Arguments] --> B[ArgumentParser]
B --> C{No parameters?}
C -->|Yes| D[List VAPI files]
C -->|No| E{VAPI file only?}
E -->|Yes| F[List toplevel symbols]
E -->|No| G[Navigate to symbol path]
G --> H[Display symbol details]
D --> I[Output Formatter]
F --> I
H --> I
I --> J[Display Results]
graph TD
A[VAPI File] --> B[VapiParser]
B --> C[libvala CodeContext]
C --> D[Symbol Resolution]
D --> E[Build Symbol Tree]
E --> F[SymbolNavigator]
F --> G[Query/Navigation]
G --> H[Output Formatter]
Vala.CodeContext as the main parsing contextVala.SourceFile for VAPI file loadingVala.SymbolResolver for symbol resolutionVala.Namespace and other symbol types through the APICodeContext with appropriate reporteradd_source_file()Vala.Class → Class modelVala.Interface → Interface modelVala.Method → Method modelVala.Property → Property model{
"vapi_file": "path/to/file.vapi",
"query_path": ["symbol1", "symbol2"],
"result_type": "symbol_list|symbol_details|file_list",
"symbols": [...],
"metadata": {
"vala_version": "0.56",
"timestamp": "2023-..."
}
}
{
"name": "symbol_name",
"type": "class|interface|method|property|enum|delegate|field|constant",
"access": "public|private|protected|internal",
"return_type": "ReturnType",
"parameters": [
{
"name": "param_name",
"type": "ParamType",
"direction": "in|out|ref",
"default_value": "optional"
}
],
"properties": [...],
"methods": [...],
"fields": [...],
"base_types": ["BaseClass1", "Interface1"],
"source_location": {
"file": "file.vapi",
"line": 123
},
"documentation": "Symbol documentation comment"
}
{
"result_type": "file_list",
"vapi_directory": "/usr/share/vala-0.56/vapi",
"files": [
{
"name": "gtk+-3.0.vapi",
"path": "/usr/share/vala-0.56/vapi/gtk+-3.0.vapi",
"size": 123456,
"modified": "2023-..."
}
]
}
{
"error": {
"type": "file_not_found|parse_error|navigation_error",
"message": "Human readable error message",
"details": {
"file_path": "path/to/file.vapi",
"symbol_path": ["symbol1", "symbol2"],
"line_number": 123
}
}
}
valaq executableproject('valaq', 'vala', 'c',
version: '1.0.0',
license: 'GPLv3',
default_options: ['warning_level=2', 'werror=false'],
)
# Dependencies
glib_dep = dependency('glib-2.0', version: '>= 2.56')
gobject_dep = dependency('gobject-2.0', version: '>= 2.56')
json_glib_dep = dependency('json-glib-1.0', version: '>= 1.0')
libvala_dep = dependency('libvala-0.56', version: '>= 0.56.0')
# Source files
sources = files(
'src/main.vala',
'src/cli/argument-parser.vala',
'src/cli/command-handler.vala',
'src/core/vapi-parser.vala',
'src/core/symbol-navigator.vala',
'src/core/symbol-model.vala',
'src/output/formatter.vala',
'src/output/text-formatter.vala',
'src/output/json-formatter.vala',
'src/utils/file-utils.vala',
'src/utils/error-handling.vala',
)
# Vala compilation flags
vala_args = [
'--target-glib=2.56',
'--pkg', 'glib-2.0',
'--pkg', 'gobject-2.0',
'--pkg', 'json-glib-1.0',
'--pkg', 'libvala-0.56',
]
# Executable
executable('valaq',
sources,
dependencies: [glib_dep, gobject_dep, json_glib_dep, libvala_dep],
vala_args: vala_args,
install: true,
)
# Test configuration
test_dependencies = [glib_dep, gobject_dep, json_glib_dep, libvala_dep]
test_sources = files(
'tests/test-vapi-parser.vala',
'tests/test-symbol-navigator.vala',
'tests/test-output-formatters.vala',
)
foreach test_file : test_sources
test_name = test_file.split('/')[-1].split('.')[0]
test(test_name,
executable(test_name,
test_file,
dependencies: test_dependencies,
vala_args: vala_args,
)
endforeach
# Setup build directory
meson setup builddir
# Compile
meson compile -C builddir
# Run tests
meson test -C builddir
# Install
meson install -C builddir
Project Setup
Basic VAPI Parsing
CLI Framework
Symbol Navigation
Output Formatters
Performance Optimization
Testing and Validation
Documentation and Distribution
The valaq CLI application architecture provides a solid foundation for building a comprehensive VAPI file exploration tool. The key architectural decisions include:
libvala Integration: Leveraging the official Vala library ensures accurate and reliable VAPI parsing without reinventing the wheel.
Modular Design: Clear separation of concerns between CLI interface, parsing, navigation, and output formatting makes the codebase maintainable and extensible.
Hierarchical Navigation: The symbol navigator provides intuitive traversal of VAPI file structures, supporting both simple listing and deep exploration.
Flexible Output: Support for both human-readable and JSON output formats makes the tool suitable for interactive use and programmatic integration.
Performance Considerations: Caching and lazy loading strategies ensure good performance even with large VAPI files.
Extensibility: The plugin architecture and modular design allow for future enhancements without major refactoring.
This architecture plan provides a comprehensive roadmap for implementing the valaq CLI application, addressing all the specified requirements while maintaining flexibility for future enhancements.