Repository navigation
Description
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 addtree-sitter-ctorequirements.txt. It owns.cand.h. - Add
backend/languages/cfamily.pywith the C/C++-shared tree-sitter helpers (declarator names, parameters, comment blocks,#includeresolution) so the C++ issue can reuse it. Use the shared bookkeeping from refactor(backend): share resolution bookkeeping across language plugins #31 (build_edgesetc.) rather than re-implementing it. - Extract Functions: only definitions (a function with a body). A prototype in a header never becomes a Function.
qualnameis the function name;moduleis the file path without its extension; the id is<file>::<name>, with#2,#3appended to same-named definitions in one file (e.g.#ifdefbranches). - 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.cfile 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. staticfunctions are visible only in their own file (astatic inlinein 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.pydoes: nothing is preprocessed or compiled; functions defined by macros are not Functions; calls hidden in macro bodies are invisible; every#ifdefbranch 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) tolanguages.ts, importprismjs/components/prism-cinFunctionNode.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
.cand.hfiles shows its Functions and Call edges; prototypes in headers do not appear as function cards. - A call from one
.cfile to a function defined in another, declared through an included header, draws a Wire. - Two same-named
staticfunctions in different files each wire only to their own file's callers. - A name with two non-static definitions and no
#includepath to either draws no Wire (no arbitrary pick). -
cb(x)wherecbis a function-pointer parameter draws no Wire, even when a function namedcbis 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/.hfile 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.analyzeronsample_project,sample_rust_projectandsample_typescript_projectgives identical function and edge counts before and after. -
npm run buildandnpm run lintpass infrontend/, andGET /api/healthstill returns OK.
Activity
feat: add C support via a language plugin (#35)