Skip to content

Add C support via a language plugin #33

Closed

Description

@MCR-3

Context

Function Viewer reads Python, Rust and TypeScript/JavaScript; C codebases can't be visualized at all. This adds a C Language plugin (.c, .h). It is the first of two issues; C++ follows in its own issue and reuses the shared helpers introduced here.

C and C++ are separate plugins, so their Languages get separate badges, icons and highlighting. The cost is that the dispatcher hands each plugin only its own extensions, so Call edges between C and C++ files are not drawn (TypeScript and JavaScript avoid this by sharing one plugin).

Call resolution is deliberately name-based. Measured on zlib, curl and redis, 96.6-99.2% of call sites are plain named calls; function-pointer calls are roughly 1-4%, so leaving them unlinked costs little.

To-dos

Backend

  • Add backend/languages/c.py (tree-sitter based), register it, and add tree-sitter-c to requirements.txt. It owns .c and .h.
  • Add backend/languages/cfamily.py with the C/C++-shared tree-sitter helpers (declarator names, parameters, comment blocks, #include resolution) so the C++ issue can reuse it. Use the shared bookkeeping from refactor(backend): share resolution bookkeeping across language plugins #31 (build_edges etc.) rather than re-implementing it.
  • Extract Functions: only definitions (a function with a body). A prototype in a header never becomes a Function. qualname is the function name; module is the file path without its extension; the id is <file>::<name>, with #2, #3 appended to same-named definitions in one file (e.g. #ifdef branches).
  • Use the contiguous own-line comment block directly above a function (//, ///, /* */, /** */, markers stripped) as the docstring and exclude it from the code body. If the definition has none, fall back to the comment above its prototype in an included header.
  • Resolve calls foo() in this order: (1) a definition in the same file, static or not; (2) a definition in a file reached through quoted #include "..." (transitively), or in the .c file implementing one of those headers (matched by file stem; non-static only); (3) the single non-static definition of that name anywhere in the picked root. Several candidates at any step means no edge. <system.h> includes are ignored.
  • static functions are visible only in their own file (a static inline in a header is visible to the files including it).
  • Treat a call whose name is a parameter or local variable as an indirect call and do not link it, even if a function of the same name exists.
  • Document the limits in the plugin docstring and README, as rust.py does: nothing is preprocessed or compiled; functions defined by macros are not Functions; calls hidden in macro bodies are invisible; every #ifdef branch is parsed; function-pointer calls (cb(x), s->handler(x), tbl[i](x)) are not linked; files tree-sitter cannot fully parse are flagged but keep whatever functions it recovered.

Frontend

  • Add c (C) to languages.ts, import prismjs/components/prism-c in FunctionNode.tsx, update any UI text that lists the supported languages, and check badge contrast in both themes.

Docs and fixtures

  • Add sample_c_project/ (headers with prototypes, a static helper, doc comments) and a row in the README's supported-languages table.

Out of scope

C++ (separate issue); running the preprocessor, compile_commands.json, -I paths or <system.h> includes; linking function-pointer or callback calls; macro-defined functions as Functions; Call edges between C and C++ files; Objective-C. Until the C++ issue lands, .h is always C.

Acceptance criteria

  • Loading a folder of .c and .h files shows its Functions and Call edges; prototypes in headers do not appear as function cards.
  • A call from one .c file to a function defined in another, declared through an included header, draws a Wire.
  • Two same-named static functions in different files each wire only to their own file's callers.
  • A name with two non-static definitions and no #include path to either draws no Wire (no arbitrary pick).
  • cb(x) where cb is a function-pointer parameter draws no Wire, even when a function named cb is loaded.
  • A doc comment above a function (or above its header prototype, when the definition has none) appears as the docstring and not in the code body.
  • Each .c / .h file shows the C badge and icon, and cards use C syntax highlighting.
  • On a macro-heavy tree (e.g. zlib) the analyzer completes, still finds the functions it can parse, and flags the files it could not fully parse.
  • Python, Rust and TypeScript are unchanged: python -m backend.analyzer on sample_project, sample_rust_project and sample_typescript_project gives identical function and edge counts before and after.
  • npm run build and npm run lint pass in frontend/, and GET /api/health still returns OK.

Activity

  1. added a commit that references this issue on Oct 11, 2026
    44f9b21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready-for-agentFully specified, ready for an AFK agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions