diff --git a/Cargo.lock b/Cargo.lock index 5d6d3d4..2d9d8a6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -420,9 +420,9 @@ checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" [[package]] name = "form_urlencoded" -version = "1.2.2" +version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +checksum = "afa489199eaffb1211795df1c6236ce1ad0d41a6fa45250add73e3b02420f06e" dependencies = [ "percent-encoding", ] @@ -1768,9 +1768,9 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "url" -version = "2.5.8" +version = "2.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +checksum = "f00cd2407bb42c0ef17be88d4cf020f5cceffd121665bac9b8b9493a369b3b1a" dependencies = [ "form_urlencoded", "idna", diff --git a/docs/GOTCHAS.md b/docs/GOTCHAS.md index 2095c1d..325096f 100644 --- a/docs/GOTCHAS.md +++ b/docs/GOTCHAS.md @@ -571,6 +571,8 @@ See [OmniSharp notes](gotchas/dotnet.md#omnisharp). ## clangd +See [Anonymous namespace source-file comparison](gotchas/clangd-source-anonymous.md) for the header exclusion and verified source-file workaround. + - Objective-C name queries may fall back to `workspace/symbol` and return `.h` anchors that `--lang objc` cannot open: its filetype recognizes only `.m`. Keep the playground implementation protocol and file-scope type-definition data in `.m`; this fixture workaround does not add general header support. clangd 23.1.0 returned no type-definition matches for a file-scope `Order *` value; the fixture queries its `OrderItem` data instead. diff --git a/docs/gotchas/clangd-source-anonymous.md b/docs/gotchas/clangd-source-anonymous.md new file mode 100644 index 0000000..aecd1ea --- /dev/null +++ b/docs/gotchas/clangd-source-anonymous.md @@ -0,0 +1,70 @@ +# Anonymous namespace moved from header to source + +The user requested moving the anonymous namespace into a `.cpp`, committing the +change, and retrying the comparison. No clarification questions were asked. + +The original coverage fixture had `01_user.cpp` include `client.hpp`. That header +contained an anonymous namespace with `struct HttpClient {};` and +`inline void consume_hidden(HttpClient*) {}`. The entire namespace now lives in +[`01_user.cpp`](fixtures/clangd-source-anonymous/01_user.cpp); the include and header +are unnecessary. The named-namespace control remains in +[`00_normal.cpp`](fixtures/clangd-source-anonymous/00_normal.cpp). +These files preserve both class declarations and both reference expressions. + +## Comparison + +Real clangd 23.1.0, background indexing enabled, result/reference caps disabled. +Both translation units have generated absolute-path compilation database entries. +Each strategy ran twice in a separate server session and passed the same exact +two-anchor, two-reference oracle, recorded independently in +[`expected.json`](fixtures/clangd-source-anonymous/expected.json). + +| Strategy | Seconds, two runs | Document-symbol requests | Workspace-symbol requests | References | +| --- | --- | --- | --- | --- | +| Exhaustive, with readiness | 0.711 / 0.663 | 3 | 0 | 2 / 2 expected | +| Configured workspace discovery | 0.782 / 0.727 | 0 | 1 | 2 / 2 expected | + +Both strategies opened two documents and issued two reference requests. Exhaustive +discovery includes one readiness priming outline in addition to the two-file scan. +Workspace discovery waits for `backgroundIndexProgress` completion before search; +its optional header-outline patterns match no files in this source-only fixture. +All runs exited successfully, had no protocol errors, and left input files intact. +The [full measurement records](clangd-source-anonymous-results.jsonl) retain exact +positions, returned matches, timing and request counts. + +The unchanged comparison harness was `/tmp/clangd-validity/compare.py`, using +`run_case(label, workspace, 20, 10, truth_path=oracle, readiness=True)` for exhaustive +and `run_case(..., generic=True)` for configured workspace discovery. It used the +previously built `/tmp/clangd-validity/readiness-cli` and +`/tmp/clangd-generic-default/lsp-cli` experimental executables respectively. These +are experimental builds, not the production CLI in this checkout. Runtime inputs +were copied to `/tmp/clangd-generic-default/source-anonymous`; its compilation +database and URI-based oracle were generated there rather than committed with +checkout-specific paths. The committed oracle uses relative filenames and +one-based coordinates; raw LSP records use zero-based coordinates. + +## Tradeoffs and limits + +Moving the private declaration into a source file makes it discoverable through +clangd's workspace index and avoids header parsing for discovery. On this tiny +fixture it did not yield a speedup; startup/indexing overhead dominates. + +Keeping the original header layout preserves its previous translation-unit-local +entities, but clangd deliberately excludes its anonymous declarations from the +index. Scanning header outlines finds those declarations at additional parse cost, +without proving complete references across translation units. A shared named +namespace would be another design, changing entity identity and API exposure. + +This move is valid for this fixture's single consumer. It does not establish +workspace-search completeness for arbitrary code, remove the separate macro +counterexample, or enable a production fast-path policy. + +## Validation difficulties + +`make test` ran: 396 passed, one ignored, one failed. The existing unrelated +`sends_configured_ids_in_direct_and_windowed_document_opens` failure expects +`csharp` while the current catalog provides `cs`. No Rust/catalog changes are +included here. The first benchmark assertion expected only two exhaustive outline +requests; the trace showed the additional readiness priming request. The recorded +comparison correctly counts all three. Shell commands required execution outside +the failing `bwrap` sandbox.