Skip to content

LSP Language Support

Mo Abualruz edited this page Dec 4, 2025 · 1 revision

LSP Language Support

Status: ✅ Complete

Last Updated: December 4, 2025


Overview

This guide describes the language support in RiceCoder's LSP server and how to add support for new languages.

Supported Languages

Rust

Status: ✅ Fully Supported

Features:

  • Symbol extraction (functions, types, structs, traits, modules)
  • Import tracking
  • Unused import detection
  • Missing documentation detection
  • Code actions for common fixes

Configuration: ~/.ricecoder/lsp/languages/rust.yaml

Example:

fn add(a: i32, b: i32) -> i32 {
    a + b
}

Diagnostics:

  • Missing documentation comment
  • Unused function (if not called)

TypeScript

Status: ✅ Fully Supported

Features:

  • Symbol extraction (functions, types, classes, interfaces, variables)
  • Import tracking
  • Unused import detection
  • Missing type annotations detection
  • Code actions for type hints

Configuration: ~/.ricecoder/lsp/languages/typescript.yaml

Example:

function greet(name: string): string {
    return `Hello, ${name}`;
}

Diagnostics:

  • Missing type annotations
  • Unused imports
  • Unused variables

Python

Status: ✅ Fully Supported

Features:

  • Symbol extraction (functions, classes, variables)
  • Import tracking
  • Unused import detection
  • Missing docstring detection
  • Code actions for docstrings

Configuration: ~/.ricecoder/lsp/languages/python.yaml

Example:

def add(a: int, b: int) -> int:
    return a + b

Diagnostics:

  • Missing docstring
  • Unused imports
  • Unused variables

Unsupported Languages

For unsupported languages, the LSP server provides:

  • Basic text analysis: No parsing, basic pattern matching
  • Generic diagnostics: Syntax errors only
  • Graceful degradation: No crashes, basic functionality

Adding Support for a New Language

Step 1: Create Configuration File

Create ~/.ricecoder/lsp/languages/{language}.yaml:

language: go
file_extensions:
  - go

parser_plugin: tree-sitter-go

diagnostic_rules:
  - name: unused_imports
    pattern: "^import"
    severity: warning
    message: "Unused import"
    fix_template: "Remove import"

  - name: missing_error_check
    pattern: "err :="
    severity: warning
    message: "Error not checked"

code_actions:
  - name: organize_imports
    title: "Organize imports"
    kind: source
    transformation: "Sort and group imports"

  - name: add_error_check
    title: "Add error check"
    kind: quickfix
    transformation: "Add if err != nil check"

Step 2: Verify Parser Plugin

Ensure the parser plugin is available:

# For tree-sitter parsers
cargo search tree-sitter-go

Step 3: Test Configuration

  1. Create a test file: test.go
  2. Start LSP server: ricecoder lsp start
  3. Open file in editor
  4. Verify diagnostics appear

Step 4: Customize Rules

Adjust diagnostic rules and code actions based on testing:

diagnostic_rules:
  - name: unused_imports
    pattern: "^import"
    severity: warning
    message: "Unused import"
    fix_template: "Remove import"
    code: "unused-import"

Language Configuration Reference

Rust Configuration

language: rust
file_extensions:
  - rs
  - rs.in

parser_plugin: tree-sitter-rust

diagnostic_rules:
  - name: unused_imports
    pattern: "use.*;"
    severity: warning
    message: "Unused import"

  - name: unused_variables
    pattern: "let\\s+\\w+\\s*="
    severity: warning
    message: "Unused variable"

  - name: missing_docs
    pattern: "^\\s*(pub\\s+)?(fn|struct|enum|trait)"
    severity: hint
    message: "Missing documentation"

code_actions:
  - name: add_doc_comment
    title: "Add documentation comment"
    kind: quickfix
    transformation: "Add /// comment above"

  - name: remove_unused_import
    title: "Remove unused import"
    kind: quickfix
    transformation: "Delete import line"

TypeScript Configuration

language: typescript
file_extensions:
  - ts
  - tsx
  - js
  - jsx

parser_plugin: tree-sitter-typescript

diagnostic_rules:
  - name: unused_imports
    pattern: "import.*from"
    severity: warning
    message: "Unused import"

  - name: missing_types
    pattern: "function\\s+\\w+\\s*\\("
    severity: hint
    message: "Missing type annotations"

code_actions:
  - name: add_type_annotations
    title: "Add type annotations"
    kind: quickfix
    transformation: "Add : Type to parameters"

  - name: organize_imports
    title: "Organize imports"
    kind: source
    transformation: "Sort and group imports"

Python Configuration

language: python
file_extensions:
  - py
  - pyi
  - pyw

parser_plugin: tree-sitter-python

diagnostic_rules:
  - name: unused_imports
    pattern: "^import|^from.*import"
    severity: warning
    message: "Unused import"

  - name: missing_docstring
    pattern: "^\\s*(def|class)\\s+\\w+"
    severity: hint
    message: "Missing docstring"

code_actions:
  - name: add_docstring
    title: "Add docstring"
    kind: quickfix
    transformation: "Add triple-quoted docstring"

  - name: add_type_hints
    title: "Add type hints"
    kind: quickfix
    transformation: "Add type annotations"

Parser Plugins

The LSP server uses tree-sitter parsers for code analysis. Available parsers:

  • tree-sitter-rust: Rust language
  • tree-sitter-typescript: TypeScript and JavaScript
  • tree-sitter-python: Python language
  • tree-sitter-go: Go language
  • tree-sitter-java: Java language
  • tree-sitter-cpp: C++ language
  • And many more...

Diagnostic Rules

Diagnostic rules use regex patterns to match code and generate diagnostics.

Pattern Examples

Pattern Matches
use.* Any use statement
let\s+\w+\s*= Variable declarations
^import Import statements
function\s+\w+ Function declarations
class\s+\w+ Class declarations

Severity Levels

Level Description
error Critical issue that prevents compilation
warning Issue that should be fixed
info Informational message

Code Actions

Code actions provide fixes and refactorings for diagnostics.

Action Kinds

Kind Description
quickfix Quick fix for a diagnostic
refactor Refactoring suggestion
source Source code organization

Troubleshooting

Language Not Recognized

Problem: Language configuration not loading

Solution:

  • Verify file is in ~/.ricecoder/lsp/languages/
  • Check file extension is .yaml or .yml
  • Verify YAML syntax is valid
  • Restart LSP server

Parser Plugin Not Found

Problem: "Parser plugin not found" error

Solution:

  • Verify parser plugin name is correct
  • Check parser is installed: cargo search tree-sitter-{language}
  • Update ricecoder to latest version

Diagnostics Not Appearing

Problem: Diagnostics not shown for language

Solution:

  • Verify file extension matches configuration
  • Check diagnostic rules are not empty
  • Verify pattern is valid regex
  • Check file contains matching patterns
  • Restart LSP server

See Also


Last updated: December 4, 2025

Clone this wiki locally