MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / buildDeadCode

Function buildDeadCode

src/ui-server/api/deadcode.ts:139–220  ·  view source on GitHub ↗
(
  cg: CodeGraph,
  projectRoot: string,
  query: URLSearchParams
)

Source from the content-addressed store, hash-verified

137}
138
139export function buildDeadCode(
140 cg: CodeGraph,
141 projectRoot: string,
142 query: URLSearchParams
143): WireDeadCode {
144 const started = Date.now();
145 const options = parseDeadCodeQuery(query);
146
147 const report = buildDeadCodeReport(cg, {
148 kinds: options.kinds,
149 includeExported: options.includeExported,
150 includeTests: options.includeTests,
151 includeGenerated: options.includeGenerated,
152 limit: options.limit,
153 // The chokepoint, not `fs`: the viewer never opens a path the index does
154 // not name and `resolveProjectFile` has not cleared.
155 readSource: (filePath) =>
156 readIndexedFileText(cg, projectRoot, filePath, MAX_CORROBORATION_BYTES),
157 });
158
159 const generatedFiles = cg.generatedFilePredicate(
160 report.entries.map((entry) => entry.node.filePath)
161 );
162
163 // Groups follow the rows' order: the first time a file appears is where its
164 // group sits, so the largest finding is still at the top of the screen.
165 const rows: WireDeadCodeRow[] = [];
166 const groups: WireDeadCodeGroup[] = [];
167 const byFile = new Map<string, WireDeadCodeGroup>();
168
169 for (const entry of report.entries) {
170 const row: WireDeadCodeRow = {
171 ...toNodeRef(entry.node),
172 lines: entry.lines,
173 members: wireList(
174 entry.members.slice(0, MAX_DEAD_CODE_MEMBERS).map((member) => toNodeRef(member)),
175 entry.members.length
176 ),
177 };
178 rows.push(row);
179
180 let group = byFile.get(row.file);
181 if (!group) {
182 group = {
183 file: row.file,
184 // The path convention plus the indexed banner verdict, both, so a
185 // generated file dims here for the same reason it dims on the map.
186 generated: generatedFiles(entry.node.filePath),
187 test: row.test,
188 lines: 0,
189 rows: [],
190 };
191 byFile.set(row.file, group);
192 groups.push(group);
193 }
194 group.rows.push(row);
195 group.lines += row.lines;
196 }

Callers 2

handlerFunction · 0.90

Calls 10

buildDeadCodeReportFunction · 0.90
readIndexedFileTextFunction · 0.90
toNodeRefFunction · 0.90
wireListFunction · 0.90
parseDeadCodeQueryFunction · 0.85
mapMethod · 0.80
pushMethod · 0.80
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected