Skip to content

LSP & Editor Support

OpenPine includes a full Language Server Protocol (LSP) implementation and a VS Code extension.

Features

The LSP supports 20+ capabilities:

FeatureDescription
DiagnosticsReal-time error and warning reporting
CompletionsContext-aware code completions
Signature HelpFunction parameter hints
HoverType information and documentation on hover
Go to DefinitionJump to function/type/variable definitions
Go to Type DefinitionJump to the type of a symbol
Find ReferencesFind all usages of a symbol
Document HighlightsHighlight all occurrences of a symbol
Document SymbolsOutline of functions, types, variables
Workspace SymbolsSearch symbols across files
RenameRename a symbol across the project
Document ColorsColor preview for color literals
FormattingAuto-format Pine Script code
On-Type FormattingFormat as you type
Semantic TokensRich syntax highlighting
Inlay HintsInline type and parameter hints
Code LensInline actions above functions
Folding RangesCode folding for blocks
Call HierarchyIncoming/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 --force

Features

  • Syntax highlighting via TextMate grammar
  • All LSP features listed above
  • Pine Script file association (.pine files)

Running the LSP Server

Stdio Mode (default)

bash
cargo run -p openpine-lsp

TCP Mode

bash
cargo run -p openpine-lsp -- --tcp --port 9257

Using 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{}

Released under the MIT License.