LSP server for Collagraph (.cgx) files with ruff integration
Project description
Collagraph LSP Server
A Language Server Protocol (LSP) implementation for Collagraph .cgx files with integrated ruff linting.
Collagraph is a Python port of Vue.js, supporting single-file components in .cgx files. This LSP server provides real-time linting and formatting for Python code within these files.
Features
- Linting with ruff: Uses ruff to lint the Python code within the script tag
- Formatting with ruff: Uses ruff to format the python code within the script tag and template expressions
Installation
Install from PyPi:
uv tool install collagraph-lsp
# or with pip
pip install uv
Install from source
# Clone the repository
git clone https://github.com/fork-tongue/collagraph-lsp.git
cd collagraph-lsp
# Install with uv
uv tool install .
Usage
Running the Server
The LSP server communicates over stdin/stdout. To start it:
# Using uv
uv run collagraph-lsp
# Or run directly
uv run python -m collagraph_lsp.server
Configuration
The server works with default Ruff settings. It should pick up on your configuration in your project root:
# pyproject.toml
[tool.ruff]
line-length = 120
select = ["E", "F", "W"]
ignore = ["E501"]
Editor Integration
Sublime Text
-
Install LSP package via Package Control
-
Manually configure LSP by adding to your settings:
{
"clients": {
"collagraph-lsp": {
"enabled": true,
"command": ["collagraph-lsp"],
"selector": "source.collagraph | text.html.collagraph",
"schemes": ["file"],
"languageId": "collagraph"
}
}
}
VS Code
Coming soon!
Zed
Coming soon!
Example CGX File
<widget>
<label :text="message"></label>
<button @clicked="on_click">Click Me</button>
</widget>
<script>
import collagraph as cg
# This line has an unused import
from PySide6.QtWidgets import QBoxLayout
class TestComponent(cg.Component):
def init(self):
self.message = "Hello from Collagraph LSP!"
def on_click(self):
print(self.message)
# This line has an error - undefined variable
undefined_variable = "test"
</script>
Development
Running Tests
# Install (development) dependencies
uv sync
# Run tests
uv run pytest
# Run tests with coverage
uv run pytest --cov=collagraph_lsp
# Lint and format
uv run ruff check --fix
uv run ruff format
How It Works
-
Parsing: When a
.cgxfile is opened or modified, the Collagraph parser extracts the<script>section with its exact line range -
Virtual File Creation: Creates a virtual Python file where:
- Script section lines are preserved as-is
- Non-script lines (template, style) are replaced with
#comments - This preserves line numbers for accurate error reporting
-
Template Compilation: Uses Collagraph's
construct_astto compile the template into arender()method:- The render method references all variables used in the template
- This allows Ruff to see that template variables are actually used
- For example, if
QBoxLayoutis imported and used in a template attribute, Ruff won't report it as unused
-
Virtual Subclass: Appends a virtual subclass with the render method to the file:
class VirtualDirectives(Directives): def render(self): # noqa # ... generated code that uses template variables ...
-
Linting: Runs Ruff on the complete virtual Python file (with
--ignore=RUF100to skip unused noqa warnings) -
Mapping: Diagnostics are correctly positioned since line numbers are preserved
-
Publishing: Sends diagnostics to the editor via LSP protocol
License
MIT License
Related Projects
- Collagraph - Python port of Vue.js
- Ruff - Fast Python linter
- pygls Library for LSP implementation
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file collagraph_lsp-0.1.0.tar.gz.
File metadata
- Download URL: collagraph_lsp-0.1.0.tar.gz
- Upload date:
- Size: 12.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3103fc808025cbd850e52bee031eda436d7b3ddfe7a02b2bc81929adec2063aa
|
|
| MD5 |
71f4899592d0c4406168225b2042452b
|
|
| BLAKE2b-256 |
dce92d0e92af6fbe2b91aa2238637592e801d47628536ecb72c371e9864f16ab
|
Provenance
The following attestation bundles were made for collagraph_lsp-0.1.0.tar.gz:
Publisher:
ci.yml on fork-tongue/collagraph-lsp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
collagraph_lsp-0.1.0.tar.gz -
Subject digest:
3103fc808025cbd850e52bee031eda436d7b3ddfe7a02b2bc81929adec2063aa - Sigstore transparency entry: 650679899
- Sigstore integration time:
-
Permalink:
fork-tongue/collagraph-lsp@36afe125c9d021bc41f7ef52bb78fe781c8e35d9 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/fork-tongue
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@36afe125c9d021bc41f7ef52bb78fe781c8e35d9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file collagraph_lsp-0.1.0-py3-none-any.whl.
File metadata
- Download URL: collagraph_lsp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be3b928d1e9afae9992011254c90fbc9a14dfde58804f79092ab8a737bc7f9db
|
|
| MD5 |
7601fea248656593636f8bf376ea06c1
|
|
| BLAKE2b-256 |
81a34adf738b9a32221f03f5c4d493ef2660baa11b94bb870b0012b06f81ccf8
|
Provenance
The following attestation bundles were made for collagraph_lsp-0.1.0-py3-none-any.whl:
Publisher:
ci.yml on fork-tongue/collagraph-lsp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
collagraph_lsp-0.1.0-py3-none-any.whl -
Subject digest:
be3b928d1e9afae9992011254c90fbc9a14dfde58804f79092ab8a737bc7f9db - Sigstore transparency entry: 650679910
- Sigstore integration time:
-
Permalink:
fork-tongue/collagraph-lsp@36afe125c9d021bc41f7ef52bb78fe781c8e35d9 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/fork-tongue
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@36afe125c9d021bc41f7ef52bb78fe781c8e35d9 -
Trigger Event:
push
-
Statement type: