How nextflow-io/language-server works
1. What this repo is
- This is a Java 17+ Language Server Protocol implementation for Nextflow.
- It runs as a stdio-based server jar and serves Nextflow script files and Nextflow config files.
2. Top-level runtime boundary
- The entrypoint is nextflow.lsp.NextflowLanguageServer.
- It sits between the editor/client and the internal language features, receiving LSP requests and publishing responses, diagnostics, and notifications over standard input/output.
3. Core dispatch layer
- nextflow.lsp.services.LanguageService is the main routing layer.
- It selects the appropriate subsystem for the file type: script services for .nf-style workflow scripts and config services for Nextflow config files.
- LanguageServerConfiguration and ErrorReportingMode control behavior from workspace configuration changes.
4. Two main analysis pipelines
- The repo has a clear split between:
- services/script/* for workflow scripts
- services/config/* for config files
- Each side has its own AST cache, visitors, completion/hover/definition/reference providers, formatting, semantic tokens, and symbol support.
5. Script subsystem
- ScriptService is the orchestrator for script files.
- It relies on ScriptAstCache, ScriptAstParentVisitor, and several specialized visitors/providers to answer editor features.
- This subsystem also handles workflow-specific concerns like process conversion, plugin include resolution, and workspace preview generation.
6. Config subsystem
- ConfigService plays the same role for configuration files.
- It uses ConfigAstCache, ConfigAstParentVisitor, and config-specific providers for completion, hover, links, formatting, and semantic highlighting.
- Config analysis also resolves includes via CachingResolveIncludeVisitor.
7. Parsing, compilation, and diagnostics
- nextflow.lsp.compiler.LanguageServerCompiler and LanguageServerErrorCollector form the diagnostics pipeline.
- Source files are parsed/compiled, errors are collected, and surfaced back to the client as diagnostics.
- This is the main path for “diagnostics” support in the language server.
8. State and caching
- nextflow.lsp.file.FileCache tracks workspace file contents/state.
- AST and domain-specific caches reduce repeated parsing and enable cross-request reuse.
- The design assumes many LSP requests are read-heavy and benefit from cached semantic models.
9. Language feature providers
- Standard LSP features are implemented as separate provider classes: completion, definition, references, rename, hover, formatting, symbols, links, code lens, call hierarchy, and semantic tokens.
- There is a shared abstraction layer in nextflow.lsp.services.*, with script/config specializations beneath it.
- This makes the architecture provider-oriented: each feature is implemented as a focused service over the cached AST/model.
10. Nextflow-specific semantic model
- nextflow.lsp.spec.* defines project-specific specs such as ScriptSpecFactory, ConfigSpecFactory, and plugin metadata caches.
- These classes encode knowledge of Nextflow syntax, plugins, and runtime conventions so the LSP can offer accurate completions and navigation.
- src/main/java/nextflow/script/* contains deeper language/type infrastructure, including type checking helpers and shim types that model Nextflow/Groovy semantics.
11. Workflow DAG preview path
- Script analysis includes a dedicated DAG preview subsystem under services/script/dag.
- DataflowVisitor builds graph data, Graph holds the intermediate representation, and MermaidRenderer turns it into a previewable diagram format.
- WorkspacePreviewProvider connects this analysis to the language server feature surface.
12. Utilities and support code
- Shared helpers in nextflow.lsp.util handle logging, JSON, positions/ranges, debouncing, and progress notifications.
- DebouncingExecutor suggests some requests are rate-limited or coalesced to avoid expensive repeated analysis while the user is typing.
13. Build and test structure
- The project uses Gradle with a wrapper, plus a Makefile for local build/test convenience.
- Tests are in Groovy under src/test/groovy, with coverage for caches, type checking, script/config features, DAG preview, and utility code.
- GitHub Actions workflows build the project and generate dependency updates.
14. Repository dependency boundary
- The README notes that this server is built alongside the Nextflow repository and the nf-lang module.
- Architecturally, that means this repo depends on Nextflow’s language/runtime semantics for correctness, while exposing them through an LSP-compatible server for editors.
Main entry points: ScriptService.java Script Service · LanguageService.java Language Service · ConfigService.java Config Service · NextflowLanguageServer.java Language Server
Components 19
Runtime
Server entrypoint and LSP boundary
- Language Server · Receives editor requests and publishes responses over stdio
src/main/java/nextflow/lsp/NextflowLanguageServer.java
Core
Dispatch, compilation, state, and shared LSP feature APIs
- Language Service · Dispatches requests to script or config subsystems
src/main/java/nextflow/lsp/services/LanguageService.java - Compiler · Parses and compiles sources, collecting errors for diagnostics
src/main/java/nextflow/lsp/compiler/LanguageServerCompiler.java - Error Collector · Turns compiler errors into LSP diagnostics
src/main/java/nextflow/lsp/compiler/LanguageServerErrorCollector.java - File Cache · Tracks file contents and workspace file state
src/main/java/nextflow/lsp/file/FileCache.java - LSP Providers · Common completion, hover, definition, reference, rename, symbols, links, formatting, and semantic token interfaces
src/main/java/nextflow/lsp/services - AST Utils · Common AST caching, parent lookup, and completion helpers
src/main/java/nextflow/lsp/ast - Server Config · Applies configuration changes and error reporting policy
src/main/java/nextflow/lsp/services/LanguageServerConfiguration.java - Utilities · Logging, JSON, positions, debouncing, and progress notifications
src/main/java/nextflow/lsp/util
Script
Workflow script analysis and editor features
- Script Service · Coordinates analysis and features for Nextflow workflow scripts
src/main/java/nextflow/lsp/services/script/ScriptService.java - Script Cache · Caches parsed workflow script ASTs
src/main/java/nextflow/lsp/services/script/ScriptAstCache.java - Script Features · Completion, hover, definition, references, rename, formatting, symbols, links, code lens, and semantic tokens for scripts
src/main/java/nextflow/lsp/services/script - DAG Preview · Builds and renders dataflow DAG previews for workflows
src/main/java/nextflow/lsp/services/script/dag
Config
Nextflow config analysis and editor features
- Config Service · Coordinates analysis and features for Nextflow config files
src/main/java/nextflow/lsp/services/config/ConfigService.java - Config Cache · Caches parsed config ASTs
src/main/java/nextflow/lsp/services/config/ConfigAstCache.java - Config Features · Completion, hover, links, formatting, and semantic tokens for config files
src/main/java/nextflow/lsp/services/config
Model
Nextflow-specific semantic and type infrastructure
- Specs · Project-specific script and config specs plus plugin metadata
src/main/java/nextflow/lsp/spec - Plugin Cache · Caches plugin specifications and references
src/main/java/nextflow/lsp/spec/PluginSpecCache.java - Script Types · Nextflow/Groovy type checking helpers and shim types
src/main/java/nextflow/script
Connections 26
- Language Server → Language Service: routes LSP · Entrypoint delegates editor requests to the service router
- Language Server → Compiler: diagnostics · Server surfaces compiler-driven diagnostics to the client
- Language Server → File Cache: workspace state · Server uses cached file contents and file state
- Language Service → Script Service: script files · Routes workflow scripts to the script subsystem
- Language Service → Config Service: config files · Routes config files to the config subsystem
- Language Service → Server Config: settings · Applies workspace configuration and error reporting mode
- Language Service → LSP Providers: feature API · Shares common LSP feature contracts across subsystems
- Language Service → AST Utils: AST helpers · Uses shared AST helpers and completion utilities
- Script Service → Script Cache: caches AST · Reuses parsed workflow ASTs
- Script Service → Script Features: serves features · Drives script completions, hovers, navigation, and formatting
- Script Service → DAG Preview: preview graph · Connects workflow analysis to DAG preview generation
- Script Service → Specs: script spec · Uses Nextflow script semantics for interpretation
- Script Service → Plugin Cache: plugins · Resolves plugin metadata for script analysis
- Script Service → Script Types: type model · Leverages Nextflow/Groovy typing infrastructure
- Config Service → Config Cache: caches AST · Reuses parsed config ASTs
- Config Service → Config Features: serves features · Drives config completions, hovers, links, formatting, and tokens
- Config Service → Specs: config spec · Uses config-specific Nextflow semantics
- Config Service → Plugin Cache: plugins · Uses plugin metadata during config analysis
- Config Service → Script Types: shared semantics · Relies on common language/type behavior where needed
- Compiler → Error Collector: collects errors · Compiler feeds collected errors into diagnostics handling
- Compiler → File Cache: reads sources · Compiler works from workspace file state
- DAG Preview → Utilities: rendering support · Uses utilities for progress, JSON, and coordination
- Script Features → AST Utils: AST queries · Feature providers depend on shared AST helpers
- Config Features → AST Utils: AST queries · Feature providers depend on shared AST helpers
- LSP Providers → Script Features: specialized by · Script subsystem implements shared LSP contracts
- LSP Providers → Config Features: specialized by · Config subsystem implements shared LSP contracts