A comprehensive VSCode extension that provides syntax highlighting and intelligent autocompletion for Viewi PHP/HTML components.
- PHP expressions in HTML: Highlights PHP code within
{}and{{}}braces - Viewi components: Special highlighting for component tags (PascalCase tags)
- PHP variables and functions: Proper syntax highlighting for PHP expressions in HTML templates
- Component tags: Autocomplete component names when typing
<in HTML files - Cross-project discovery: Automatically finds all Viewi components across the project
- Property completion: Autocomplete public properties from the corresponding PHP component class
- Method completion: Autocomplete public methods with parameter hints
- Trigger on
{: Automatically suggests expressions when typing opening braces - Context-aware: Only shows relevant completions based on the current component
- Automatically detects PHP/HTML component pairs (same base name, same location)
- Links HTML templates with their corresponding PHP component classes
Viewi components consist of two files:
ComponentName.php- Contains the PHP class with the component logicComponentName.html- Contains the HTML template
HomePage.php:
<?php
namespace Components\Views\Home;
use Viewi\Components\BaseComponent;
class HomePage extends BaseComponent
{
public string $title = 'Viewi - Reactive application for PHP';
public bool $isLoading = false;
function getName(): string
{
return 'HomePage';
}
function getTitle(): string
{
return $this->title;
}
}HomePage.html:
<div class="home-page">
<h1>$title</h1>
<p>Loading: {$isLoading ? 'Yes' : 'No'}</p>
<p>Component: {getName()}</p>
<p>Title: {{getTitle()}}</p>
</div><div>
<HomePage title="My new title" />
</div>The extension can be configured through VSCode settings:
{
"viewi.enableAutocompletion": true,
"viewi.componentSearchPaths": ["."]
}viewi.enableAutocompletion(boolean, default:true): Enable/disable autocompletion featuresviewi.componentSearchPaths(array, default:["."]): Directories to search for Viewi components
Viewi: Refresh Components: Manually refresh the component cache
The extension enhances the built-in HTML language support in VS Code to provide syntax highlighting and autocompletion for Viewi components and expressions.
Autocompletion is triggered by:
<- For component tag suggestions{- For PHP expression suggestions$- For variable suggestions anywhere in HTML files- CTRL + (SPACE)
- Component Tags: Type
<My→ suggestsMyButton, etc. - Variables anywhere: Type
$→ suggests$title,$isLoading, etc. - Variables in braces: Type
{$→ suggests$title,$isLoading, etc. - Methods in braces: Type
{get→ suggestsgetName(),getTitle(), etc. - Expression templates: Type
{→ suggests{$title},{{$title}},{getName()}, etc. - CTRL + (SPACE): All above
- Install the extension from the VSCode marketplace
- Open a project containing Viewi components
- The extension will automatically detect and index your components
npm install
npm run compilenpm install -g @vscode/vsce
node_modules/.bin/vsce package
-- OR
vsce package
vsce publish
-- OR
node_modules/.bin/vsce publish
-- OR
node_modules/.bin/vsce publish -p TOKEN
├── client/ # VSCode extension client
│ ├── src/
│ │ └── extension.ts # Main extension entry point
│ └── package.json
├── server/ # Language server
│ ├── src/
│ │ ├── server.ts # Language server implementation
│ │ └── viewi-parser.ts # Component parsing logic
│ └── package.json
├── syntaxes/ # Syntax highlighting rules
│ └── viewi-html.tmLanguage.json
└── package.json # Extension manifest
- VSCode 1.80.0 or higher
- Node.js for development
- Component discovery is currently limited to the configured search paths
- PHP parsing is regex-based and may not handle all edge cases
Contributions are welcome! Please feel free to submit issues and pull requests.
MIT License