LSP & Editor Support
OpenPine includes a full Language Server Protocol (LSP) implementation and a VS Code extension.
Features
The LSP supports 20+ capabilities:
| Feature | Description |
|---|---|
| Diagnostics | Real-time error and warning reporting |
| Completions | Context-aware code completions |
| Signature Help | Function parameter hints |
| Hover | Type information and documentation on hover |
| Go to Definition | Jump to function/type/variable definitions |
| Go to Type Definition | Jump to the type of a symbol |
| Find References | Find all usages of a symbol |
| Document Highlights | Highlight all occurrences of a symbol |
| Document Symbols | Outline of functions, types, variables |
| Workspace Symbols | Search symbols across files |
| Rename | Rename a symbol across the project |
| Document Colors | Color preview for color literals |
| Formatting | Auto-format Pine Script code |
| On-Type Formatting | Format as you type |
| Semantic Tokens | Rich syntax highlighting |
| Inlay Hints | Inline type and parameter hints |
| Code Lens | Inline actions above functions |
| Folding Ranges | Code folding for blocks |
| Call Hierarchy | Incoming/outgoing call trees |
VS Code Extension
Installation
The VS Code extension is located at crates/lsp/editors/vscode/.
Build and install:
bash
cd crates/lsp/editors/vscode
npm install
npm run build
npm run package
code --install-extension openpine-0.1.0.vsix --forceFeatures
- Syntax highlighting via TextMate grammar
- All LSP features listed above
- Pine Script file association (
.pinefiles)
Running the LSP Server
Stdio Mode (default)
bash
cargo run -p openpine-lspTCP Mode
bash
cargo run -p openpine-lsp -- --tcp --port 9257Using the Analyzer API
For programmatic use, the Analyzer struct provides direct access to LSP features:
rust
use openpine_lsp::Analyzer;
let analyzer = Analyzer::new(loader);
let result = analyzer.analyze("script.pine", source);
// Get diagnostics
let diagnostics = result.diagnostics();
// Get completions at a position
let completions = result.completions_at(position);
// Go to definition
let definition = result.definition_at(position);
// Find all references
let references = result.references_at(position, include_declaration);
// Get document symbols
let symbols = result.document_symbols();
// Get document colors
let colors = result.document_colors();Neovim Setup
For Neovim with nvim-lspconfig:
lua
local lspconfig = require('lspconfig')
local configs = require('lspconfig.configs')
configs.openpine = {
default_config = {
cmd = { 'path/to/openpine-lsp' },
filetypes = { 'pine' },
root_dir = lspconfig.util.find_git_ancestor,
},
}
lspconfig.openpine.setup{}