Language Server Protocol implementation for hx-requests Django library
Project description
hx-requests-lsp
Language Server Protocol implementation for the hx-requests Django library.
Features
- Autocomplete: Get suggestions for hx_request names in Django templates (prioritizes current app, works with or without quotes)
- Go-to-Definition: Jump from template usage to the Python class definition
- Find References: Find all template usages of an hx_request
- Diagnostics: Warnings for undefined hx_request names
- Hover Information: View details about an hx_request on hover
Installation
Install via pip:
pip install hx-requests-lsp
Verify installation:
hx-requests-lsp --help
Quick Start
VS Code Setup
The easiest way to use this LSP is through the VS Code extension, which bundles the server:
- Install the hx-requests-lsp VS Code extension from the Marketplace
- The extension includes a bundled copy of the server - no separate installation needed
- Open a Django project with hx-requests to start using LSP features
Alternatively, if you want to use your own installation of the server:
- Install this package:
pip install hx-requests-lsp - Install the VS Code extension
- The extension will automatically detect the server in your environment
Configuration
If the extension can't find the server automatically, add to your VS Code .vscode/settings.json:
{
"hxRequestsLsp.serverPath": "/path/to/venv/bin/hx-requests-lsp"
}
Usage
Once installed, the LSP provides these features in your editor:
| Feature | How to Use |
|---|---|
| Go to Definition | F12 or Ctrl+Click on an hx_request name in a template |
| Find References | Shift+F12 or right-click → "Find All References" |
| Hover Info | Hover over an hx_request name |
| Autocomplete | Type {% hx_get or {% hx_post in a template (quotes optional) |
| Diagnostics | Undefined hx_request names show warnings |
Supported Patterns
Python (definitions)
from hx_requests.hx_requests import BaseHxRequest, ModalHxRequest
class MyRequest(BaseHxRequest):
name = "my_request" # This name is indexed
GET_template = "partials/my.html"
Templates (usages)
{% load hx_tags %}
<!-- hx_post with name as first argument -->
<button {% hx_post 'my_request' object=item %}>Click</button>
<!-- hx_get -->
<div {% hx_get 'another_request' %}>Load</div>
<!-- hx_vals with hx_request_name keyword -->
<div {% hx_vals hx_request_name='my_request' title='Modal' %}>Open</div>
Requirements
- Python 3.11+
pygls>= 1.3.0 (Python Language Server library)lsprotocol>= 2023.0.0
Editor Support
VS Code
Use the official extension (recommended - includes bundled server)
Other Editors (Neovim, Emacs, etc.)
This LSP server works with any editor that supports the Language Server Protocol. Install via pip and configure your editor to use the hx-requests-lsp command.
Example for Neovim with nvim-lspconfig:
require'lspconfig'.hx_requests_lsp.setup{
cmd = {"hx-requests-lsp", "--stdio"},
filetypes = {"html", "htmldjango", "python"},
root_dir = require'lspconfig'.util.root_pattern("manage.py", ".git")
}
Development
Setup
# Clone the repository
git clone https://github.com/jordannpenn/hx-requests-lsp
cd hx-requests-lsp
# Install dependencies
pip install -e ".[dev]"
Running Tests
pytest
Testing the Server Manually
# Test that the server responds to LSP initialize
msg='{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"processId":null,"rootUri":"file:///app","capabilities":{}}}'
printf "Content-Length: ${#msg}\r\n\r\n${msg}" | hx-requests-lsp --stdio
Troubleshooting
Server not found
- Verify it's installed:
which hx-requests-lsp - Check the path matches your editor's
serverPathsetting - Make sure you're in the correct virtualenv
Extension shows "Activating" forever
- Check Developer Tools console:
Ctrl+Shift+P→ "Developer: Toggle Developer Tools" → Console tab - Look for errors mentioning "hx-requests"
No autocompletion or diagnostics
- Ensure your template files are properly recognized by your editor
- Restart your editor to reload the extension
- Check that hx_request classes have a
nameattribute
License
MIT License - see LICENSE file for details
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Project details
Release history Release notifications | RSS feed
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 hx_requests_lsp-1.1.1.tar.gz.
File metadata
- Download URL: hx_requests_lsp-1.1.1.tar.gz
- Upload date:
- Size: 16.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8c64cb344cca5942758c1f262057f1fa999c4634728ef869bf9181eef232039
|
|
| MD5 |
b20bf968794a0be7f954f51bda047233
|
|
| BLAKE2b-256 |
84daca5147ab2659da1b14c254482d2db50e8fddd313ad26c1b63c900ae02801
|
Provenance
The following attestation bundles were made for hx_requests_lsp-1.1.1.tar.gz:
Publisher:
workflow.yml on jordannpenn/hx-requests-lsp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hx_requests_lsp-1.1.1.tar.gz -
Subject digest:
e8c64cb344cca5942758c1f262057f1fa999c4634728ef869bf9181eef232039 - Sigstore transparency entry: 944390507
- Sigstore integration time:
-
Permalink:
jordannpenn/hx-requests-lsp@1a92234b8e034b2a4955a9e1aa933862484170f5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/jordannpenn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@1a92234b8e034b2a4955a9e1aa933862484170f5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file hx_requests_lsp-1.1.1-py3-none-any.whl.
File metadata
- Download URL: hx_requests_lsp-1.1.1-py3-none-any.whl
- Upload date:
- Size: 17.0 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 |
864e71768dc0c8096bb7fa1ec21321721ef796cfdbae6cf1fb787c9032dfae4f
|
|
| MD5 |
4d94e150597508e43a1c9221f26e51be
|
|
| BLAKE2b-256 |
e3f9f17e98abfdde249f9d794cce7e78a0be029d68798893897bc8b36624a3b2
|
Provenance
The following attestation bundles were made for hx_requests_lsp-1.1.1-py3-none-any.whl:
Publisher:
workflow.yml on jordannpenn/hx-requests-lsp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hx_requests_lsp-1.1.1-py3-none-any.whl -
Subject digest:
864e71768dc0c8096bb7fa1ec21321721ef796cfdbae6cf1fb787c9032dfae4f - Sigstore transparency entry: 944390563
- Sigstore integration time:
-
Permalink:
jordannpenn/hx-requests-lsp@1a92234b8e034b2a4955a9e1aa933862484170f5 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/jordannpenn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@1a92234b8e034b2a4955a9e1aa933862484170f5 -
Trigger Event:
push
-
Statement type: