Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ jobs:
- name: Wait for dampen-dev to be available
run: sleep 30

- name: Publish dampen-lsp
run: cargo publish -p dampen-lsp --token ${{ secrets.CARGO_TOKEN }}
continue-on-error: false

- name: Wait for dampen-lsp to be available
run: sleep 30

- name: Publish dampen-cli
run: cargo publish -p dampen-cli --token ${{ secrets.CARGO_TOKEN }}
continue-on-error: false
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"crates/dampen-iced",
"crates/dampen-dev",
"crates/dampen-cli",
"crates/dampen-lsp",
"crates/dampen-visual-tests",
"examples/hello-world",
"examples/counter",
Expand Down Expand Up @@ -53,7 +54,7 @@ uuid = { version = "1.0", features = ["v4"] }
directories = "5.0"

# Parser
roxmltree = "0.19"
roxmltree = "0.21"
nom = "7.1"
csscolorparser = "0.6"

Expand Down
59 changes: 59 additions & 0 deletions crates/dampen-lsp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[package]
name = "dampen-lsp"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
authors.workspace = true
license.workspace = true
repository.workspace = true
documentation.workspace = true
readme.workspace = true
keywords.workspace = true
categories.workspace = true
publish = true
description = "Language Server Protocol implementation for Dampen UI framework"

[[bin]]
name = "dampen-lsp"
path = "src/main.rs"

[lib]
name = "dampen_lsp"
path = "src/lib.rs"

[dependencies]
# Internal crates
dampen-core = { workspace = true }

# LSP framework
tower-lsp = "0.20"
lsp-types = "0.95"

# Async runtime
tokio = { version = "1.0", features = ["rt-multi-thread", "macros", "io-std"] }

# Serialization
serde = { workspace = true }
serde_json = { workspace = true }

# Logging/tracing
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

# URL handling
url = "2.0"

# LRU cache for documents
lru = "0.12"

# Lazy static initialization
once_cell = "1.0"

[dev-dependencies]
# Testing
tokio-test = "0.4"
insta = { workspace = true }
tempfile = { workspace = true }

[lints]
workspace = true
168 changes: 168 additions & 0 deletions crates/dampen-lsp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# Dampen LSP Server

Language Server Protocol (LSP) implementation for the Dampen UI framework.

## Overview

The Dampen LSP server provides real-time XML validation, intelligent autocompletion, and contextual hover documentation for `.dampen` files. It is built on the `tower-lsp` framework and communicates via JSON-RPC over stdio.

## Features

- **Real-time Validation**: Syntax and semantic errors appear as you type
- **Intelligent Autocompletion**: Context-aware suggestions for widgets, attributes, and values
- **Hover Documentation**: Documentation tooltips for widgets and attributes
- **Error Diagnostics**: Red underlines with detailed error messages and suggestions

## Installation

### From Source

```bash
cargo build --release -p dampen-lsp
```

The binary will be available at `target/release/dampen-lsp`.

### Prerequisites

- Rust 1.85+ (MSRV)
- dampen-core crate (included in workspace)

## Editor Configuration

### VS Code

Add to `.vscode/settings.json`:

```json
{
"dampen.lsp.enabled": true,
"dampen.lsp.path": "/path/to/dampen-lsp"
}
```

### Zed

Add to `~/.config/zed/settings.json`:

```json
{
"lsp": {
"dampen-lsp": {
"binary": {
"path": "/path/to/dampen-lsp"
}
}
}
}
```

### Neovim

Using nvim-lspconfig:

```lua
require('lspconfig').dampen.setup{
cmd = {"/path/to/dampen-lsp"},
filetypes = {"dampen"},
root_dir = require('lspconfig').util.root_pattern(".git", "Cargo.toml"),
}
```

## Usage

The LSP server is started automatically by your editor. Manual start:

```bash
dampen-lsp
```

The server reads JSON-RPC messages from stdin and writes responses to stdout.

## Development

### Running Tests

```bash
# All tests
cargo test -p dampen-lsp

# Specific test
cargo test -p dampen-lsp test_completion

# With output
cargo test -p dampen-lsp -- --nocapture
```

### Linting and Formatting

```bash
# Run clippy
cargo clippy -p dampen-lsp -- -D warnings

# Format code
cargo fmt -p dampen-lsp

# Check formatting
cargo fmt -p dampen-lsp -- --check
```

### Build Release

```bash
cargo build --release -p dampen-lsp
```

## Project Structure

```
crates/dampen-lsp/
├── src/
│ ├── main.rs # Entry point
│ ├── lib.rs # Library exports
│ ├── server.rs # LSP server orchestration (in main.rs)
│ ├── document.rs # Document cache management
│ ├── analyzer.rs # Semantic analysis
│ ├── capabilities.rs # LSP capabilities
│ ├── converters.rs # Type conversions
│ ├── schema_data.rs # Widget documentation
│ └── handlers/ # LSP method handlers
│ ├── mod.rs
│ ├── text_document.rs
│ ├── diagnostics.rs
│ ├── completion.rs
│ └── hover.rs
└── tests/
├── integration_tests.rs
└── fixtures/
```

## Architecture

The server uses an actor-style architecture:

- **LspServer**: Main orchestrator handling LSP lifecycle
- **DocumentCache**: LRU cache of open documents (50 max)
- **Analyzer**: Semantic analysis and position-based queries
- **Handlers**: LSP method implementations (textDocument/*)

## Performance

- Parse time: <50ms for 1000-line files
- Completion response: <100ms
- Hover response: <200ms
- Diagnostics publish: <500ms

## Logging

Enable structured logging:

```bash
RUST_LOG=info dampen-lsp # Info level
RUST_LOG=debug dampen-lsp # Debug level
RUST_LOG=trace dampen-lsp # Trace level (verbose)
```

## License

See the workspace LICENSE file.
Loading
Loading