Repository navigation
Native language server in Flow; Python LSP deleted (#693) - #1016
Merged
Merged
Conversation
godofecht
force-pushed
the
port/native-lsp
branch
2 times, most recently
from
September 29, 2026 08:43
0c51e16 to
8731b7c
Compare
godofecht
force-pushed
the
port/native-lsp
branch
2 times, most recently
from
September 29, 2026 09:40
6c1274e to
67653fb
Compare
…ness tools/lsp/main.flow speaks JSON-RPC over stdio and takes diagnostics from the flowc parser and Stage-A checker in process. ./flow lsp builds and runs it. tests/tools/lsp/run.sh drives it with recorded sessions; the *.python files are the Python server's answers to the same sessions.
Formatting takes fmt.flow's output only when it keeps every token and comment, and otherwise re-indents. The idiom check counts writes by token, so assignments inside brace-skipped blocks count.
src/flow/lsp_server.py, lsp_intel.py, lsp_syntax.py, lsp_dynamics.py and lsp_ordering.py are replaced by tools/lsp. The behavioral checks of scripts/test_lsp_server.py, tests/unit/test_lsp_*.py and the re-export index test now live in the transcript sessions under tests/tools/lsp. Python ratchet tightened.
tests/tools/run.sh now runs the language server sessions too, so the native-tools CI job (Python stubbed out) covers flow lsp.
With #999 on main, flowc expands dyn. blocks, so the server indexes dynamics files the way it compiles them.
tests/tools/lsp/fixtures/dsl.flow holds a dsys block, so the dynamics passthrough check asks for an ex_ mirror. The golden is written from the Python expander at 7527ab37.
tests/tools/lsp/fixtures holds inputs for the LSP transcripts, several of them broken on purpose to exercise diagnostics. The tier-2 sweep tried to compile them and failed. The transcripts in tests/tools/run.sh cover them.
godofecht
force-pushed
the
port/native-lsp
branch
from
September 29, 2026 10:22
67653fb to
bd5b632
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes the LSP part of #693.
What this does
Replaces the Python language server with one written in Flow,
tools/lsp/main.flow(about 6.5k lines acrosstools/lsp/*.flow)../flow lspbuilds it with the Stage-A compiler on first use (flow_native_tool, same asflow repl) and runs it../flow-lspis now a bash launcher for./flow lsp, and the VS Code extension startsflow lspby default.It speaks JSON-RPC 2.0 over stdio with Content-Length framing and keeps the Python server's JSON layout (key order,
", "/": "separators,\uXXXXescapes) so the two can be diffed byte for byte.Methods:
initialize,initialized,shutdown,exit,textDocument/didOpen,didChange(full sync, 200 ms debounce as before),didClose,publishDiagnostics,hover,completion,definition,documentSymbol,references,documentHighlight,prepareRename,rename,formatting,rangeFormatting,codeAction. The Python server had a code action handler for idiom fixes but never routed it; the native one does and advertises it.Diagnostics run in process:
compiler/src/parser.flow(after the Field DSL, dynamics DSL and flow block expansions, as flowc compiles);typecheck.flow), with the exports of every module the document reaches through imports seeded first, as the bundle checker does. The checker prints to stdout, so the server keeps the protocol on a dup of the original stdout, points fd 1 at stderr, and captures the checker's output through a scratch file;Imports resolve with the module resolver's rules (relative,
std., flow.toml[paths]and[dependencies]viaflow_packages/, legacy string paths) and followexport importforwards, so hover and definition onuse_hello_lib's imports reachhello_lib/src/lib.flow.Formatting uses
compiler/src/fmt.flowonly when its output keeps every token and comment of the source; otherwise it re-indents without touching tokens. fmt.flow drops comments and some declarations and writeslet x: voidfor an untypedlet, so a straight pass-through would delete code.Proof: transcript test
tests/tools/lsp/run.shreplays nine JSON-RPC sessions (tests/tools/lsp/sessions/*.lsp) against the server: lifecycle, diagnostics and code actions, references and rename across two files, hover, completion, definition, imports through re-export chains, formatting, and diagnostics plus document symbols over ten repository files (stdlib, examples including effects, enums, dynamics and a proof file, a tests/lang program, a compiler source file, a package consumer).Each case checks two things:
<case>.expected;diff <case>.python nativeequals<case>.accepted.diff, where<case>.pythonis what the Python server answered to the same session, recorded before deletion.Result: 205 messages, 150 identical to the Python server's, 55 different. Every difference is classified in
tests/tools/lsp/ACCEPTED.md:codeActionProvider, version) in eachinitialize;if;«»claim paths) lost that message and the next; the native server answers all of them;@attrlines) and imported symbols no longer listed indocumentSymbol;ptr<f64>) instead of Python's internal names (ptr<ptr_f64>,array_7_i32);dyn.files: Python analysed the expanded text but reported a parse error from the raw text;<expr>, dropped comments and dropped parentheses ((a + b) * 2becamea + b * 2).Hover and completion prose is the Python text with U+2014 written as a hyphen;
run.shnormalizes that one character before diffing.No
python invokedline in any server stderr, and the server was rebuilt from scratch under the stub.Deleted
src/flow/lsp_server.py,lsp_intel.py,lsp_syntax.py,lsp_dynamics.py,lsp_ordering.pyscripts/test_lsp_server.py,tests/integration/test_lsp_server.py,tests/unit/test_lsp_hover.py,test_lsp_idioms.py,test_lsp_intel.py, and the LSP class intest_module_reexport.py. Their behavioral checks are sessions intests/tools/lsp/.4,607 lines of Python removed.
./scripts/python_ratchet.sh --updaterun; baseline limit now 92,899.Branch notes
origin/fix/stage-a-batch-3is merged in (one duplicateAST_IDENT_SORT_MODleft by the merge removed), andorigin/main(selfhost: dynamics DSL and flow-block lowering on flowc, Python expanders retired (#681) #999) merged after. Bootstrap C regenerated last in its own commit: fixed point OK,bootstrap_from_c.sh --verify,self_host_full.shandroundtrip.shresults below.compiler/srcedits in this PR are comments only (thelsp_*.flowhelper headers no longer say the server is Python); none of those modules is in the bootstrap bundle.lib/stdlibwithfindthroughpopen(the hostlib helper the REPL already uses).Verification on the final tree: fixed point OK;
bootstrap_from_c.sh --verifyPASS;self_host_full.shALL PASS (three generations byte-identical);roundtrip.shALL PASS;FLOW_HOST=python ./flow run compiler/src/main.flowprintsflowc: PASS.CI
tests/tools/run.shnow callstests/tools/lsp/run.sh, so the existingnative-toolsjob (Python stubbed out) runs the LSP sessions with no workflow change. It needsjq, which ubuntu-latest has. If a separate job is preferred, it would be the same steps asnative-toolswith./tests/tools/lsp/run.shas the last command, triggered ontools/**,tests/tools/**,flow-driverandcompiler/**.Follow-ups
let, print imports and externs. The server then takes its output for more files.