LSP / Editor Support
Language Server Protocol support and editor configuration for poly-bench
Language Server Protocol support and editor configuration for poly-bench
poly-bench includes a full Language Server Protocol (LSP) implementation that provides rich editor support for .bench files. This includes real-time diagnostics, completions, hover documentation, formatting, and semantic highlighting.
| Feature | Description |
|---|---|
| Diagnostics | Real-time error and warning reporting as you type |
| Formatting | Format documents on save or on demand |
| Completions | Intelligent completions for keywords, stdlib, and user symbols |
| Hover | Documentation and type information on hover |
| Semantic highlighting | Syntax highlighting tokens for accurate coloring |
| Embedded languages | Delegates to gopls, tsserver, and rust-analyzer for code blocks |
The LSP server runs over stdio. Start it with:
$poly-bench lspThis is typically invoked by your editor's extension, not run manually.
The poly-bench extension is available from the VS Code marketplace or can be installed from a .vsix file.
$# From marketplace (when available)$code --install-extension poly-bench.poly-bench
$# From local .vsix file$code --install-extension poly-bench-0.0.22.vsixIf you're not using the extension, configure the LSP manually in settings.json:
1{2"poly-bench.serverPath": "poly-bench",3"poly-bench.serverArgs": ["lsp"],4"[bench]": {5 "editor.formatOnSave": true,6 "editor.defaultFormatter": "poly-bench.poly-bench"7}8}Associate .bench files with the poly-bench language:
1{2"files.associations": {3 "*.bench": "bench"4}5}.bench files when installed. Manual configuration is only needed if you're setting up the LSP client yourself.1-- Add poly-bench to lspconfig2local lspconfig = require('lspconfig')3local configs = require('lspconfig.configs')4
5-- Define the poly-bench language server6if not configs.polybench then7configs.polybench = {8 default_config = {9 cmd = { 'poly-bench', 'lsp' },10 filetypes = { 'bench' },11 root_dir = lspconfig.util.root_pattern('polybench.toml', '.git'),12 settings = {},13 },14}15end16
17-- Set up the server18lspconfig.polybench.setup({19on_attach = function(client, bufnr)20 -- Your on_attach configuration21end,22capabilities = require('cmp_nvim_lsp').default_capabilities(),23})Add file type detection for .bench files:
1vim.filetype.add({2extension = {3 bench = 'bench',4},5})For basic syntax highlighting before Tree-sitter support:
1" Keywords2syn keyword benchKeyword suite setup bench fixture before after each use3syn keyword benchKeyword import init helpers4syn keyword benchLang go ts rust5syn keyword benchOption description warmup compare baseline mode6syn keyword benchOption targetTime minIterations maxIterations count7syn keyword benchOption memory concurrency outlierDetection cvThreshold8syn keyword benchOption timeout sink iterations9
10" Standard library11syn keyword benchStdlib std anvil charting constants12
13" Booleans14syn keyword benchBoolean true false15
16" Strings17syn region benchString start=/"/ end=/"/ skip=/\"/18
19" Numbers20syn match benchNumber '<d+>'21syn match benchDuration '<d+(ms|s|m)>'22
23" Comments24syn match benchComment '//.*$'25
26" Hex values27syn match benchHex '<0x[0-9a-fA-F]+>'28syn match benchHex '"[0-9a-fA-F]+"'29
30" Highlighting31hi def link benchKeyword Keyword32hi def link benchLang Type33hi def link benchOption Identifier34hi def link benchStdlib Constant35hi def link benchBoolean Boolean36hi def link benchString String37hi def link benchNumber Number38hi def link benchDuration Number39hi def link benchComment Comment40hi def link benchHex StringAdd to your languages.toml:
1[[language]]2name = "bench"3scope = "source.bench"4injection-regex = "bench"5file-types = ["bench"]6roots = ["polybench.toml"]7comment-token = "//"8indent = { tab-width = 4, unit = " " }9language-servers = ["polybench"]10
11[language-server.polybench]12command = "poly-bench"13args = ["lsp"]Add to your settings.json:
1{2"languages": {3 "Bench": {4 "language_servers": ["polybench"]5 }6},7"lsp": {8 "polybench": {9 "binary": {10 "path": "poly-bench",11 "arguments": ["lsp"]12 }13 }14}15}The LSP reports errors and warnings in real-time:
| Severity | Examples |
|---|---|
| Error | Syntax errors, undefined fixtures, missing required fields |
| Warning | Unused fixtures, deprecated syntax |
| Hint | Style suggestions |
1error: undefined fixture 'data' at line 152--> keccak.bench:15:93 |415 | go: keccak256(data)5 | ^^^^^^^^^^^^^^6 |7 = help: define a fixture named 'data' before using it8
9error: missing 'go' implementation in benchmark 'hash'10--> keccak.bench:20:511 |1220 | bench hash {13 | ^^^^^^^^^^14 |15 = help: add 'go: <expression>' to the benchmark blockThe LSP provides context-aware completions:
| Context | Completions |
|---|---|
| Top-level | suite, use |
| Suite body | setup, bench, fixture, before, after, each, config options |
| Setup block | import, init, helpers |
| After block | Standard library directives (charting.drawTable, etc.) |
| Bench block | Language names (go:, ts:, rust:), fixture names |
charting. in an after block to see available chart directives with documentation.Hover over keywords and symbols to see documentation:
1targetTime2─────────────────────────────────3Target execution time for auto-calibration mode.4When mode is set to "auto", poly-bench adjusts5the iteration count to reach this target time.6
7Type: duration (e.g., 3000ms, 5s)8Default: 3000msThe formatter enforces consistent style:
1suite test{2warmup:1003compare:true4
5setup go{6helpers{7func add(a,b int)int{return a+b}8}}9
10bench addition{11go:add(1,2)12}}The LSP provides semantic tokens for accurate highlighting:
| Token Type | Examples |
|---|---|
keyword | suite, setup, bench, fixture |
type | go, ts, rust |
variable | Fixture names, benchmark names |
function | Helper function names |
string | String literals, hex values |
number | Numeric literals, durations |
comment | Comments |
namespace | Standard library modules |
The LSP delegates to language-specific servers for code inside helpers and init blocks:
| Language | Delegate Server |
|---|---|
| Go | gopls |
| TypeScript | tsserver |
| Rust | rust-analyzer |
This provides:
poly-bench --version.bench extension.bench filesFormat Document)Enable verbose logging for debugging:
$# Set Rust log level$RUST_LOG=debug poly-bench lsp
$# Or trace level for maximum detail$RUST_LOG=trace poly-bench lsp