Introducing a new way to review your PRs.

Read the announcement

oraios / serena

A powerful MCP toolkit for coding, providing semantic retrieval and editing capabilities - the IDE for your agent

View on GitHub

13 documents · Updated Nov 16, 2026

docs / serena-language-backends

Serena Language Backends

Overview

Serena exposes language intelligence through interchangeable language backends. The common backend contract lives outside this doc in src/…/language_backend.py, but the concrete orchestration covered here is split between the LSP backend in src/…/lsp_backend.py, the language-server process manager in src/…/ls_manager.py, the JetBrains plugin-backed backend in src/serena/jetbrains/, and the OLB JVM wrapper in src/…/olb_jvm_backend.py.

For the LSP backend, src/…/lsp_backend.py is the project-activation entry point. LSPLanguageBackend.init_active_project() calls agent.reset_language_server_manager(), so activating an LSP project creates or recreates the project's LanguageServerManager. Its facade is LspApi, and its editor is a LanguageServerCodeEditor backed by LanguageServerSymbolRetriever. LSPLanguageBackend.is_source_file() filters source files by each configured project.project_config.language_servers filename matcher, while create_file_proxy() always returns a local project file proxy because LSP paths are project-relative only.

src/…/ls_manager.py owns the lifetime of SolidLSP servers. LanguageServerFactory.create_language_server() builds a LanguageServerConfig from project workspace folders, ignored patterns, encoding, trust, tracing, and per-language settings, then passes Serena's user home and project data path through SolidLSPSettings. LanguageServerManager.from_languages() starts all requested servers in parallel threads, collects startup failures, and fails fast: if any server cannot start, all successfully started servers are stopped and a LanguageServerManagerInitialisationError is raised. Once running, get_language_server(relative_path) chooses a suitable server by asking each server whether the relative path is ignored or unsupported; single-server projects fall back to the default server. The manager also restarts dead servers lazily, can dynamically add/remove servers, saves caches immediately or no more often than _CACHE_SAVE_INTERVAL, and stops all servers on shutdown.

The same manager also protects warm LSP indexes from stale filesystem state. LanguageServerFileChangeNotifier records a baseline over project.gather_source_files() at construction and LanguageServerManager.sync_file_system_changes() later diffs mtimes to emit workspace/didChangeWatchedFiles notifications for created, changed, and deleted source files. For created files it additionally calls notify_files_created() and opens/closes relevant files because a plain create notification was not sufficient for every backend to update cross-file reference graphs.

LSP diagnostics support is isolated in src/…/lsp_diagnostics.py. DiagnosticsContext is currently disabled by default, but when enabled around edit tools it snapshots warning-or-higher diagnostics before an edit and formats only new diagnostics afterward. PublishedDiagnosticsSnapshot records each edited file's published diagnostics generation plus diagnostic identities for the pre-edit path. DiagnosticsDiff waits for published diagnostics after the captured generation, falls back to direct text-document diagnostics, suppresses diagnostics already present before the edit, and groups new diagnostics by relative path, severity, and owner symbol using LanguageServerSymbolRetriever.find_diagnostic_owner_symbol().

The JetBrains backend in src/…/jetbrains_backend.py does not start or stop analysis processes directly. JetBrainsLanguageBackend.init_active_project() first looks for an already-running Serena JetBrains plugin server for the active project. If none is found and agent.serena_config.jetbrains_launch_command is configured, it delegates to src/…/launch_coordinator.py, which serializes concurrent launches for the same command with a temp-file lock, runs the IDE launch command with the project root appended, and polls for the plugin server. Shutdown is intentionally a no-op because IDE lifecycle is user-controlled. JetBrains treats every file as potentially source, but marks encoded dependency paths as external when they start with JB_EXTERNAL_FILE_PREFIX from src/…/jetbrains_types.py; those external paths are read through JetBrainsFileProxy, which calls the plugin's /readFile endpoint.

The JetBrains plugin client in src/…/jetbrains_plugin_client.py is the HTTP transport layer. JetBrainsPluginClientManager scans SerenaPorts.JETBRAINS_PLUGIN_SERVER_BASE_PORT plus 20 ports in parallel and matches plugin instances by project root. Matching tolerates symlinks, WSL UNC prefixes, /mnt/c versus C:/, suffix prefixes, and case differences. JetBrainsPluginClient.from_project() reuses the last successful port before scanning. Each client obtains /status at construction, converts camelCase JSON keys to snake_case by default, renders HTML quick-info/documentation to plain text in symbol responses, distinguishes recoverable API errors from plugin-server failures using plugin version checks, and gates newer operations with _require_version_at_least().

JetBrains symbol/query behavior is surfaced through src/…/jetbrains_tools.py and the JetBrainsApi facade. JetBrainsLanguageBackend.get_lsp_tool_class_replacements() replaces the standard LSP symbolic tools for find symbol, overview, references, implementations, declaration, rename, and safe delete with JetBrains-backed tool classes. The tool classes are thin adapters: they sanitize user parameters, instantiate JetBrainsApi, and return the facade result representation. The facade then calls plugin endpoints such as /findSymbol, /findReferences, /getSymbolsOverview, /findDeclaration, /findImplementations, /moveSymbol, /safeDelete, /inlineSymbol, /renameSymbol, /runInspectionsOnFile, /listInspections, and debug REPL endpoints. The JetBrains API preserves Serena's name_path/relative_path symbol contract, adds compact grouping/rendering for large results, converts external-path searches into dependency searches, and enriches reference results with local context when the reference is not external.

src/…/olb_jvm_backend.py implements the Oraios JVM language backend as a drop-in specialization of JetBrainsLanguageBackend. It uses the same plugin-client protocol, tool replacements, code editor, and facade shape, but changes the backend key to olb-jvm, renames the REPL facade from jb to ide, and replaces “JetBrains” with “Oraios” in the facade description. Activation requires the olb CLI on PATH, launches olb start jvm through the same launch coordinator, and shutdown runs olb stop --lb jvm <project_root> with the project shutdown timeout.

Coupling

  • If the set of standard symbolic tools changes, update JetBrainsLanguageBackend.get_lsp_tool_class_replacements() in src/…/jetbrains_backend.py and the adapters in src/…/jetbrains_tools.py; prompts and tool exposure map standard tool names to backend replacements through this mapping, so an omitted replacement silently leaves an LSP-only implementation active in a JetBrains/OLB session.
  • If the JetBrains plugin changes DTO field names or endpoint JSON shape, update src/…/jetbrains_types.py and the pythonification/postprocessing logic in src/…/jetbrains_plugin_client.py; the API facade and tools expect snake_case keys such as relative_path, name_path, quick_info, and reference_line_no.
  • If new JetBrains plugin operations require a newer plugin, add or adjust _require_version_at_least() checks in src/…/jetbrains_plugin_client.py; otherwise old plugins may surface internal server errors instead of a clear “update the plugin” message.
  • If backend-specific external path encoding changes, keep JB_EXTERNAL_FILE_PREFIX in src/…/jetbrains_types.py, JetBrainsLanguageBackend.is_external_path()/JetBrainsFileProxy in src/…/jetbrains_backend.py, and dependency-search handling in the JetBrains API aligned; external dependency files are not local relative paths.
  • If source-file discovery or ignore rules change, verify LanguageServerFileChangeNotifier.poll_and_notify() in src/…/ls_manager.py; it deliberately reuses project.gather_source_files() so the files watched for LSP freshness match Serena's own source-file model.
  • If the OLB plugin protocol diverges from the JetBrains plugin protocol, OraiosJVMLanguageBackend in src/…/olb_jvm_backend.py can no longer inherit JetBrains behavior unchanged; its facade, tool replacement, and file-proxy assumptions all currently depend on JetBrains-compatible endpoints.

Risks

  • src/…/ls_manager.py starts multiple language servers concurrently and aborts the whole manager if one fails. This avoids partial symbolic behavior, but it means one misconfigured language in project.project_config.language_servers prevents all symbolic LSP tools for the project from becoming available.
  • src/…/launch_coordinator.py can return after a failed launch command or after the plugin-server wait timeout without raising. The next JetBrains-backed tool will then fail through JetBrainsPluginClient.from_project(), so activation can appear successful even though code-intelligence requests are not yet serviceable.
  • src/…/jetbrains_plugin_client.py relies on project-root matching heuristics across WSL, Windows, symlinks, prefixes, and case differences. If two open IDE projects have paths where one normalized path is a suffix of another, Serena could match the wrong plugin instance and run symbol/edit operations against the wrong project.