Skip to main content

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
  • 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:

  1. Install the hx-requests-lsp VS Code extension from the Marketplace
  2. The extension includes a bundled copy of the server - no separate installation needed
  3. Open a Django project with hx-requests to start using LSP features

Alternatively, if you want to use your own installation of the server:

  1. Install this package: pip install hx-requests-lsp
  2. Install the VS Code extension
  3. 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
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

  1. Verify it's installed: which hx-requests-lsp
  2. Check the path matches your editor's serverPath setting
  3. Make sure you're in the correct virtualenv

Extension shows "Activating" forever

  1. Check Developer Tools console: Ctrl+Shift+P → "Developer: Toggle Developer Tools" → Console tab
  2. Look for errors mentioning "hx-requests"

No autocompletion or diagnostics

  1. Ensure your template files are properly recognized by your editor
  2. Restart your editor to reload the extension
  3. Check that hx_request classes have a name attribute

License

MIT License - see LICENSE file for details

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

hx_requests_lsp-0.1.1.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hx_requests_lsp-0.1.1-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file hx_requests_lsp-0.1.1.tar.gz.

File metadata

  • Download URL: hx_requests_lsp-0.1.1.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hx_requests_lsp-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b0cbd5e9a5b3d134100e2891466f658930b1efb3a39856c4cf4c3ad77cd7844d
MD5 b7068ce88a0e071c766cdac416b617bc
BLAKE2b-256 3077ab6f7f26ad75378ea70313c5f1407e17fe9dd84c6dc12163177b8cca16ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for hx_requests_lsp-0.1.1.tar.gz:

Publisher: publish.yml on jordannpenn/hx-requests-lsp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hx_requests_lsp-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for hx_requests_lsp-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 23964effbcfea156f1847abb74a0e9f9eb35a69b9dfabe5413861dca16c22fb0
MD5 a2c3a1f8cdc828a29df64db2678b68c5
BLAKE2b-256 a6e8ef1c7a655bdfd9ec7b61e2fda5c63b79d1a9dfa749cbf2f1486f3bdcb57c

See more details on using hashes here.

Provenance

The following attestation bundles were made for hx_requests_lsp-0.1.1-py3-none-any.whl:

Publisher: publish.yml on jordannpenn/hx-requests-lsp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page