Skip to content

LSP Support

Codive includes a Language Server Protocol (LSP) implementation that integrates with any LSP-compatible editor. This brings AI-powered coding assistance directly into your editing experience.

The Codive LSP server provides:

  • Code Actions - AI-powered refactoring and code generation
  • Inline Completions - Context-aware code suggestions
  • Diagnostics - AI-assisted code review and error detection
  • Hover Information - Explanations for code under cursor
  • Code Lens - Quick actions embedded in your code

Start Codive in LSP mode:

Terminal window
codive lsp

The server communicates over stdio by default, which is the standard for LSP.

Terminal window
# Use TCP instead of stdio
codive lsp --tcp --port 9257
# Enable verbose logging
codive lsp --log-level debug
# Use specific configuration
codive lsp --config ~/.config/codive/lsp.toml

Codive provides AI-powered code actions through the standard LSP code action interface:

  • Explain Code - Get an explanation of the selected code
  • Refactor Selection - AI-assisted refactoring
  • Generate Tests - Create tests for selected function
  • Add Documentation - Generate docstrings/comments
  • Fix Issue - Apply AI-suggested fix

In most editors, you can trigger code actions with Ctrl+. or Cmd+..

Codive provides context-aware completions as you type:

fn calculate_total(items: &[Item]) -> f64 {
// Type here and Codive suggests the implementation
items.iter() // <- Codive completes based on context
}

Codive adds actionable hints above functions and classes:

// 📝 Add tests | 📚 Explain | ✨ Optimize
pub fn complex_algorithm(data: &[u8]) -> Result<Output, Error> {
// ...
}

Click these lenses to trigger the corresponding AI action.

Codive can analyze your code and provide AI-powered diagnostics:

fn process(data: Option<String>) -> String {
data.unwrap() // ⚠️ Codive: Potential panic - consider using unwrap_or_default()
}

Configure LSP behavior in codive.toml:

[lsp]
# Enable/disable features
code_actions = true
inline_completion = true
code_lens = true
diagnostics = true
# Completion settings
[lsp.completion]
# Trigger completion automatically
auto_trigger = true
# Delay before triggering (ms)
trigger_delay = 500
# Maximum suggestions
max_suggestions = 5
# Code lens settings
[lsp.code_lens]
# Actions to show
enabled_actions = ["explain", "test", "refactor"]
# Diagnostics settings
[lsp.diagnostics]
# Run on save only (vs. on change)
on_save_only = false
# Severity level
min_severity = "warning"

Codive extends the standard LSP with additional capabilities:

// Execute a Codive command
interface CodiveExecuteRequest {
command: string; // e.g., "explain", "refactor", "test"
arguments: {
uri: string;
range?: Range;
context?: string;
};
}
// Response
interface CodiveExecuteResponse {
success: boolean;
result?: string;
edits?: TextEdit[];
error?: string;
}
// Codive progress updates
interface CodiveProgressNotification {
id: string;
stage: "analyzing" | "generating" | "applying";
message: string;
percentage?: number;
}

Other Editors

Any LSP-compatible editor can use Codive.

For editors not explicitly documented, configure your LSP client to:

  1. Start codive lsp as the language server
  2. Associate it with your desired file types
  3. Enable the features you want to use

Example configuration (generic):

{
"languageserver": {
"codive": {
"command": "codive",
"args": ["lsp"],
"filetypes": ["rust", "typescript", "python", "go"],
"rootPatterns": [".git", "Cargo.toml", "package.json"]
}
}
}

Check that Codive is installed and accessible:

Terminal window
which codive
codive --version

Verify LSP is initialized:

Terminal window
# Check server logs
codive lsp --log-level debug 2>&1 | head -50

If responses are slow:

  1. Check your API key is valid
  2. Consider using a faster model
  3. Reduce context by configuring ignore_patterns
[lsp]
# Use a faster model for LSP
model = "claude-3-haiku-20240307"
[context]
# Reduce files included in context
max_files = 20

For TCP mode, ensure the port is available:

Terminal window
# Check if port is in use
lsof -i :9257
# Use a different port
codive lsp --tcp --port 9258