Skip to content

Zack-911/forgelsp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

106 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ForgeLSP

Rust Tower LSP Tokio GitHub License

High-performance Language Server Protocol implementation for ForgeScript

wakatime


✨ Features

πŸ” Language Intelligence

  • Hover Documentation: Rich markdown tooltips with function signatures, descriptions, and examples
  • Auto-Completion: Context-aware suggestions triggered by $ or .
  • Signature Help: Real-time parameter hints with active parameter highlighting
  • Semantic Tokens: Syntax highlighting for functions, strings, numbers, and keywords
  • Diagnostics: Real-time error detection with helpful messages

⚑ Performance

  • Trie-based Lookup: O(k) function name matching for instant completions
  • Async I/O: Non-blocking operations using Tokio runtime
  • Smart Caching: Metadata caching with network fallback
  • Incremental Parsing: Efficient document re-parsing on changes

🌐 Flexible Configuration

  • GitHub Shorthand: Use github:owner/repo#branch syntax for metadata URLs
  • Multi-Source Support: Load function metadata from multiple URLs
  • Workspace Config: Configure per-project via forgeconfig.json

πŸ“ Project Structure

forgelsp/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main.rs          # Entry point, LSP service initialization
β”‚   β”œβ”€β”€ server.rs        # LanguageServer trait implementation
β”‚   β”œβ”€β”€ hover.rs         # Hover provider logic
β”‚   β”œβ”€β”€ parser.rs        # ForgeScript parser with diagnostics
β”‚   β”œβ”€β”€ metadata.rs      # Metadata fetching, caching, and Trie
β”‚   β”œβ”€β”€ diagnostics.rs   # Diagnostic publishing utilities
β”‚   β”œβ”€β”€ semantic.rs      # Semantic token extraction
β”‚   └── utils.rs         # Helper functions and config loading
β”œβ”€β”€ docs/                # Comprehensive module documentation
β”‚   β”œβ”€β”€ main.md          # Entry point documentation
β”‚   β”œβ”€β”€ server.md        # LSP server documentation
β”‚   β”œβ”€β”€ hover.md         # Hover feature documentation
β”‚   β”œβ”€β”€ parser.md        # Parser implementation details
β”‚   β”œβ”€β”€ metadata.md      # Metadata management guide
β”‚   β”œβ”€β”€ diagnostics.md   # Diagnostics system overview
β”‚   β”œβ”€β”€ semantic.md      # Semantic highlighting details
β”‚   └── utils.md         # Utility functions reference
β”œβ”€β”€ .github/
β”‚   └── workflows/       # CI/CD pipelines
β”œβ”€β”€ Cargo.toml           # Rust dependencies
└── Cargo.lock           # Dependency lockfile

πŸ“¦ Source Files

main.rs

Entry point for the LSP server. Initializes the metadata manager, loads configuration from forgeconfig.json, and starts the Tower LSP service over stdio.

server.rs

Implements the LanguageServer trait from Tower LSP:

  • initialize: Registers capabilities (hover, completion, signature help, semantic tokens)
  • did_open/did_change: Processes document changes and triggers diagnostics
  • hover: Delegates to hover handler
  • completion: Returns function suggestions based on cursor context
  • signature_help: Provides parameter hints for function calls
  • semantic_tokens_full: Returns semantic highlighting data

hover.rs

Handles hover requests by:

  1. Locating the token under the cursor
  2. Looking up function metadata in the Trie
  3. Generating markdown documentation with signatures, descriptions, and examples

parser.rs

Custom ForgeScript parser that:

  • Tokenizes $functionName[args] syntax
  • Supports nested function calls
  • Validates argument counts against metadata
  • Reports diagnostics for unknown functions and syntax errors

metadata.rs

Manages function metadata with three key components:

Component Purpose
Fetcher HTTP client with file-based caching
FunctionTrie Prefix-tree for O(k) function lookup
MetadataManager Coordinates fetching and indexing

diagnostics.rs

Converts parser diagnostics to LSP format and publishes them to the client.

semantic.rs

Extracts semantic tokens from code blocks using regex patterns:

  • Functions ($name)
  • Strings (single/double quoted)
  • Numbers (integers/floats)
  • Keywords (true, false)

utils.rs

Utility functions:

  • load_forge_config: Parses forgeconfig.json
  • resolve_github_shorthand: Expands github:owner/repo to raw URLs
  • spawn_log: Async logging helper

πŸ“š Documentation

Comprehensive documentation for each module is available in the docs/ directory:


πŸ”§ Dependencies

Crate Version Purpose
tower-lsp 0.20.0 LSP framework
tokio 1.x Async runtime
reqwest 0.12 HTTP client
serde 1.x Serialization
serde_json 1.x JSON parsing
nom 8.0.0 Parser combinators
regex 1.12.2 Pattern matching
smallvec 1.15.1 Stack-allocated vectors
anyhow 1.x Error handling
base64 0.22.1 URL-safe cache keys
futures 0.3.31 Async utilities
tracing-subscriber 0.3.22 Structured logging

πŸš€ Building

# Debug build
cargo build

# Release build (optimized)
cargo build --release

# Run directly
cargo run

Release Profile Optimizations

[profile.release]
opt-level = 3      # Maximum optimization
lto = "fat"        # Link-time optimization
codegen-units = 1  # Single codegen unit for better optimization
panic = "abort"    # Smaller binary size
strip = true       # Remove debug symbols

πŸ“Š LSP Capabilities

Capability Status Description
Text Document Sync βœ… Full Complete document sync on each change
Hover βœ… Function documentation on hover
Completion βœ… Triggered by $ and .
Signature Help βœ… Triggered by $, [, ;
Semantic Tokens βœ… Full Full document semantic highlighting
Diagnostics βœ… Real-time error reporting

πŸ”— Related Projects


Contributors

  • Striatp (@striatp): Helping me with the github build scripts to build the lsp for all devices

πŸ“„ License

GPL-3 License - See LICENSE for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages