Metadata-Version: 2.4
Name: hx-requests-lsp
Version: 1.2.2
Summary: Language Server Protocol implementation for hx-requests Django library
License: MIT
License-File: LICENSE
Keywords: lsp,language-server,django,htmx,hx-requests
Author: Jordan Penn
Requires-Python: >=3.11,<4.0
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Libraries
Requires-Dist: lsprotocol (>=2023.0.0)
Requires-Dist: pygls (>=1.3.0,<2.0.0)
Project-URL: Homepage, https://github.com/jordannpenn/hx-requests-lsp
Project-URL: Repository, https://github.com/jordannpenn/hx-requests-lsp
Description-Content-Type: text/markdown

# hx-requests-lsp

Language Server Protocol implementation for the [hx-requests](https://github.com/yaakovLowenstein/hx-requests) Django library.

[![VS Code Extension](https://img.shields.io/visual-studio-marketplace/v/jordanpenn.hx-requests-lsp?label=VS%20Code%20Extension)](https://marketplace.visualstudio.com/items?itemName=jordanpenn.hx-requests-lsp)
[![PyPI](https://img.shields.io/pypi/v/hx-requests-lsp)](https://pypi.org/project/hx-requests-lsp/)

## 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

### VS Code (Recommended)

Install the [hx-requests-lsp extension](https://marketplace.visualstudio.com/items?itemName=jordanpenn.hx-requests-lsp) from the VS Code Marketplace. The extension bundles the language server - no additional setup required.

### Other Editors

Install the language server via pip/pipx:

```bash
pip install hx-requests-lsp
# or
pipx install hx-requests-lsp
```

#### Neovim Configuration

> **Note**: `hx-requests-lsp` is not yet in nvim-lspconfig's built-in server list, so you need to define it as a custom server.

**Vanilla Neovim with nvim-lspconfig:**

```lua
-- Define the custom server first
vim.lsp.config('hx_requests_lsp', {
  cmd = { 'hx-requests-lsp', '--stdio' },
  filetypes = { 'html', 'htmldjango', 'python' },
  root_markers = { 'manage.py', '.git' },
})

-- Then enable it
vim.lsp.enable('hx_requests_lsp')
```

**LazyVim:**

Add this to your `lua/plugins/lspconfig.lua`:

```lua
return {
  "neovim/nvim-lspconfig",
  opts = function(_, opts)
    -- Define the custom server
    vim.lsp.config("hx_requests_lsp", {
      cmd = { "hx-requests-lsp", "--stdio" },
      filetypes = { "html", "htmldjango", "python" },
      root_markers = { "manage.py", ".git" },
    })

    -- Add to server list
    return vim.tbl_deep_extend("force", opts or {}, {
      servers = {
        hx_requests_lsp = {},
      },
    })
  end,
}
```

**NvChad / LunarVim / AstroNvim:**

Add the `vim.lsp.config()` definition to your configuration file before setting up lspconfig, then add `hx_requests_lsp = {}` to your servers list.

#### Other Editors

Configure your editor to use `hx-requests-lsp --stdio` as the language server command for `html`, `htmldjango`, and `python` filetypes in Django projects (detected by `manage.py` in the root directory).

## Usage

Once installed, the LSP provides these features in your editor:

| Feature | Description |
|---------|-------------|
| **Go to Definition** | Jump to hx_request class from template usage |
| **Find References** | Find all template usages of an hx_request |
| **Hover Info** | View details about an hx_request on hover |
| **Autocomplete** | Get suggestions when typing `{% hx_get ` or `{% hx_post ` |
| **Diagnostics** | Warnings for undefined hx_request names |

## Supported Patterns

### Python (definitions)

```python
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)

```html
{% 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+

## Troubleshooting

### Server not found

1. Verify it's installed: `which hx-requests-lsp`
2. Make sure you're in the correct virtualenv or used `pipx` for global install
3. For Neovim, check if the LSP is running with `:LspInfo`

### 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](LICENSE) file for details

## Contributing

Contributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup instructions.

