|
1 | 1 | # cpp_ls |
2 | 2 |
|
3 | | -**Work in progress — under development.** There is no release, no stability promise, and the |
4 | | -internals move. Everything below is what runs today, not what is planned. |
| 3 | +A **C, C++ and CUDA language server written in Rust**, implemented by Deepseek: parser, |
| 4 | +preprocessor, semantic analysis and the LSP layer are all in this repository, with no clangd, no compiler daemon and |
| 5 | +no `compile_commands.json` required. |
5 | 6 |
|
6 | | -A C++ language server written in Rust. It reads a project the way a compiler does: macros are |
7 | | -expanded, conditional compilation is resolved for the branches actually in force, `#include`s are |
8 | | -inlined, and the resulting *rendering* is what gets parsed — because a C++ file does not mean what |
9 | | -its characters say until a preprocessor has run. |
10 | | - |
11 | | -## What works today |
| 7 | +It reads a project the way a compiler does — macros expanded, conditional compilation resolved for the branches in |
| 8 | +force, `#include`s inlined — and the text the preprocessor produces is what gets parsed. That is what lets completion, |
| 9 | +hover, diagnostics and the rest work in a file that has never been compiled, including a half-typed line. |
12 | 10 |
|
13 | 11 | ``` |
14 | | -cargo build --release --workspace --all-targets no errors, no warnings |
15 | | -cargo test --release --workspace green |
| 12 | +completion · hover · signature help · go to definition / type definition / implementation · references |
| 13 | +document highlight · rename · call hierarchy · document and workspace symbols · folding · selection range |
| 14 | +formatting · inlay hints · semantic tokens · code actions · diagnostics · #include links |
16 | 15 | ``` |
17 | 16 |
|
18 | | -- **Parsing and rendering** of a real project: zero syntax errors over the whole MSVC standard-library |
19 | | - closure (187 files). |
20 | | -- **Thirteen semantic checks**, each with a `DiagnosticCode` (carried to the client as the LSP |
21 | | - `code`), a severity and, where it applies, a tag: |
22 | | - |
23 | | - ``` |
24 | | - syntax-error include-not-found macro-redefined unused access-invisible |
25 | | - missing-return assignment-in-condition unnecessary-branch undefined-field |
26 | | - argument-count param-type-check assign-type-check return-type-mismatch |
27 | | - ``` |
28 | | - |
29 | | -- **Zero false positives on the standard library** — the measurement this layer is built to pass: |
| 17 | +## Building |
30 | 18 |
|
31 | | - ``` |
32 | | - cargo run --release -p cpp_code_analysis --example checks_probe -- target/std-cook target/std-cook/assign-case.cpp |
33 | | - assign-case.cpp:52 [assign-type-check] `x` is initialised with a value that does not convert to `std::string` |
34 | | - --- checks over 5 file(s) --- 1 assign-type-check |
35 | | - ``` |
36 | | - |
37 | | - Exactly one true positive, nothing else. Fixtures used by that measurement live in `target/std-cook/`. |
38 | | - |
39 | | -- **A finding is about the file being edited; the knowledge behind it is the project's.** A check |
40 | | - reports only on what this file writes, but it may read the index's facts about any other file — so |
41 | | - `std::string x = 123;` is judged from the parameter list of `std::string`'s constructors recorded in |
42 | | - the index, not by parsing `<string>` again. |
| 19 | +```bash |
| 20 | +cargo build --release -p cpp_ls # one binary, LSP over stdio by default |
| 21 | +target/release/cpp_ls --help # tcp, log level, config path, std library switches |
| 22 | +``` |
43 | 23 |
|
44 | | -- **The server side**: diagnostics, completion, signature help, go to definition, references, |
45 | | - semantic tokens, folding, inlay hints. |
| 24 | +The VS Code client is [CppCXY/VSCode-Cppls](https://github.com/CppCXY/VSCode-Cppls); any other LSP client can be |
| 25 | +pointed at the binary directly. |
46 | 26 |
|
47 | | -## Where it is going |
| 27 | +## Configuring a project |
48 | 28 |
|
49 | | -**Configuring a project** — `compile_commands.json` and `.cppls.toml`, including the multi-target form that a |
50 | | -real C++ project needs: [`docs/configuration.md`](docs/configuration.md). |
51 | | -See [`docs/status.md`](docs/status.md) — one document, describing the current state, the defects that |
52 | | -are known and measured, and the plan. (It replaces nineteen older documents that described the |
53 | | -process rather than the state of the code, and had drifted out of date.) |
| 29 | +A `.cppls.toml` in the workspace root, or a `compile_commands.json` for the exact compiler flags — both are described |
| 30 | +in [`docs/configuration.md`](docs/configuration.md). No configuration is needed for a project of plain sources. |
54 | 31 |
|
55 | | -## Trying it |
| 32 | +## Working on it |
56 | 33 |
|
57 | 34 | ```bash |
58 | | -cargo run --release --workspace --bin cpp_ls # the server, speaking LSP on stdio |
59 | | - |
60 | | -# the checks over a real project, one command |
61 | | -cargo run --release -p cpp_code_analysis --example checks_probe -- <include-dir> <root file> |
62 | | - |
63 | | -# one check, with the declaration facts each finding came from |
64 | | -cargo run --release -p cpp_code_analysis --example one_check -- <include-dir> <root file> unused |
| 35 | +cargo test --workspace --all-features # tests; the latency ones only measure in --release |
| 36 | +cargo clippy --workspace --all-targets --all-features -- -D warnings |
| 37 | +cargo fmt --all |
65 | 38 | ``` |
66 | 39 |
|
67 | | -## Layout |
68 | | - |
69 | | -``` |
70 | | -crates/cpp_parser lexer and grammar; a lossless tree plus a typed AST over it |
71 | | -crates/cpp_code_analysis preprocessing and rendering, the index, the semantic model, the checks |
72 | | -crates/cpp_ls the language server: LSP handlers and the session they run against |
73 | | -``` |
| 40 | +## License |
74 | 41 |
|
| 42 | +MIT. See [`LICENSE`](LICENSE). |
0 commit comments