From 50e2dde008820ef5ae8bd502d2646e00e5139bc4 Mon Sep 17 00:00:00 2001 From: Zuhaitz Méndez Fernández de Aránguiz Date: Tue, 20 Jan 2026 13:14:07 +0000 Subject: Using cJSON for the LSP --- README.md | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 2 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index c09161d..e9e383d 100644 --- a/README.md +++ b/README.md @@ -84,12 +84,16 @@ Join the discussion, share demos, ask questions, or report bugs in the official - [Volatile](#volatile) - [Named Constraints](#named-constraints) - [15. Build Directives](#15-build-directives) +- [Tooling](#tooling) + - [Language Server (LSP)](#language-server-lsp) + - [REPL](#repl) - [Compiler Support & Compatibility](#compiler-support--compatibility) - [Test Suite Status](#test-suite-status) - [Building with Zig](#building-with-zig) - [C++ Interop](#c-interop) - [CUDA Interop](#cuda-interop) - [Contributing](#contributing) +- [Attributions](#attributions) --- @@ -273,9 +277,10 @@ match shape { Rect(w, h) => print(f"Area: {w*h}"), Point => print("Point") } +``` #### Reference Binding -To inspect a value without taking ownership (moving it), use the `ref` keyword in the pattern. This is essential for types that implement Move Semantics (e.g. `Option`, `Result`, non-Copy structs). +To inspect a value without taking ownership (moving it), use the `ref` keyword in the pattern. This is essential for types that implement Move Semantics (like `Option`, `Result`, non-Copy structs). ```zc var opt = Some(NonCopyVal{...}); @@ -288,7 +293,6 @@ match opt { None => {} } ``` -``` #### Loops ```zc @@ -770,6 +774,72 @@ fn main() { ... } --- +## Tooling + +Zen C provides a built-in Language Server and REPL to enhance the development experience. + +### Language Server (LSP) + +The Zen C Language Server (LSP) supports standard LSP features for editor integration, providing: + +* **Go to Definition** +* **Find References** +* **Hover Information** +* **Completion** (Function/Struct names, Dot-completion for methods/fields) +* **Document Symbols** (Outline) +* **Signature Help** +* **Diagnostics** (Syntax/Semantic errors) + +To start the language server (typically configured in your editor's LSP settings): + +```bash +zc lsp +``` + +It communicates via standard I/O (JSON-RPC 2.0). + +### REPL + +The Read-Eval-Print Loop allows you to experiment with Zen C code interactively. + +```bash +zc repl +``` + +#### Features + +* **Interactive Coding**: Type expressions or statements for immediate evaluation. +* **Persistent History**: Commands are saved to `~/.zprep_history`. +* **Startup Script**: Auto-loads commands from `~/.zprep_init.zc`. + +#### Commands + +| Command | Description | +|:---|:---| +| `:help` | Show available commands. | +| `:reset` | Clear current session history (variables/functions). | +| `:vars` | Show active variables. | +| `:funcs` | Show user-defined functions. | +| `:structs` | Show user-defined structs. | +| `:imports` | Show active imports. | +| `:history` | Show session input history. | +| `:type ` | Show the type of an expression. | +| `:c ` | Show the generated C code for a statement. | +| `:time ` | Benchmark an expression (runs 1000 iterations). | +| `:edit [n]` | Edit command `n` (default: last) in `$EDITOR`. | +| `:save ` | Save the current session to a `.zc` file. | +| `:load ` | Load and execute a `.zc` file into the session. | +| `:watch ` | Watch an expression (re-evaluated after every entry). | +| `:unwatch ` | Remove a watch. | +| `:undo` | Remove the last command from the session. | +| `:delete ` | Remove command at index `n`. | +| `:clear` | Clear the screen. | +| `:quit` | Exit the REPL. | +| `! ` | Run a shell command (e.g. `!ls`). | + +--- + + ## Compiler Support & Compatibility Zen C is designed to work with most C11 compilers. Some features rely on GNU C extensions, but these often work in other compilers. Use the `--cc` flag to switch backends. @@ -966,3 +1036,12 @@ make test * **Parser**: `src/parser/` - Recursive descent parser. * **Codegen**: `src/codegen/` - Transpiler logic (Zen C -> GNU C/C11). * **Standard Library**: `std/` - Written in Zen C itself. + +--- + +## Attributions + +This project uses the following third-party libraries: + +* **cJSON** (MIT License): Used for JSON parsing and generation in the Language Server. + * Copyright (c) 2009-2017 Dave Gamble and cJSON contributors -- cgit v1.2.3