Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

fix(ui): draw a file health cannot analyse grey, never as a score (#2963)

Raghav Chamadiya1f89d2da8a20
diff --git a/packages/types/src/health.ts b/packages/types/src/health.ts
index a1c0f8196..37fe28d62 100644
--- a/packages/types/src/health.ts
+++ b/packages/types/src/health.ts
@@ -232,9 +232,14 @@ export interface DefectAccuracy {
export interface HealthFileMetric {
file_path: string;
- score: number;
- max_ccn: number;
- max_nesting: number;
+ /**
+ * `null` when health has no dialect for the file's language: nothing
+ * measured it, so it has no score and no complexity figures. Render it as
+ * "not analysed", never as a number. Older servers always send a number.
+ */
+ score: number | null;
+ max_ccn: number | null;
+ max_nesting: number | null;
nloc: number;
has_test_file: boolean;
line_coverage_pct: number | null;
@@ -648,7 +653,12 @@ export interface BiomarkerBreakdownRow {
export interface HealthOverviewSummary {
file_count: number;
- average_health: number;
+ /** `null` when no file is scored: every file is in a language health has no
+ * dialect for. */
+ average_health: number | null;
+ /** Files left out of every figure here because health has no dialect for
+ * their language. Absent on an older server. */
+ unanalysed_file_count?: number;
hotspot_health?: number | null;
worst_performer_path: string | null;
worst_performer_score: number | null;
@@ -872,11 +882,12 @@ export interface FileBreakdownCategory {
export interface HealthFileBreakdownResponse {
file_path: string;
metric: HealthFileMetric | null;
+ /** `null` for a file with no score (no health dialect for its language). */
breakdown: {
score: number;
total_deduction: number;
categories: FileBreakdownCategory[];
- };
+ } | null;
findings: HealthFinding[];
suggestions: Record<string, string>;
/** Per-file score trajectory (silent when history is thin). */
@@ -1054,7 +1065,7 @@ export interface CoverageFileRow {
ingested_at: string | null;
ingested_commit_sha: string | null;
covered_lines?: number[];
- health_score?: number;
+ health_score?: number | null;
nloc?: number;
}
@@ -1121,7 +1132,7 @@ export type ReachedVia = "call-graph" | "import-graph";
export interface ReachedFileRow {
file_path: string;
reached: boolean;
- health_score?: number;
+ health_score?: number | null;
nloc?: number;
}
diff --git a/packages/ui/__tests__/health/health-file-drawer.test.tsx b/packages/ui/__tests__/health/health-file-drawer.test.tsx
index d53142251..2399e5420 100644
--- a/packages/ui/__tests__/health/health-file-drawer.test.tsx
+++ b/packages/ui/__tests__/health/health-file-drawer.test.tsx
@@ -664,3 +664,18 @@ describe("HealthFileDrawer leading cause", () => {
expect(document.querySelector('[title="Code health pillar"]')).toBeNull();
});
});
+
+describe("HealthFileDrawer: a file with no score", () => {
+ it("says it was not analysed instead of printing a score and a band", () => {
+ render(
+ <HealthFileDrawer
+ open
+ onClose={() => {}}
+ metric={metric({ file_path: "src/Big.php", score: null, max_ccn: null, max_nesting: null })}
+ findings={[]}
+ />,
+ );
+ expect(screen.getByText(/Not analysed\. No detector for this language\./)).toBeInTheDocument();
+ expect(screen.queryByText("out of 10")).toBeNull();
+ });
+});
diff --git a/packages/ui/__tests__/health/unanalysed-files.test.tsx b/packages/ui/__tests__/health/unanalysed-files.test.tsx
new file mode 100644
index 000000000..ef533becd
--- /dev/null
+++ b/packages/ui/__tests__/health/unanalysed-files.test.tsx
@@ -0,0 +1,141 @@
+/**
+ * A file in a language health has no dialect for arrives with `score: null`.
+ * It is drawn grey, like a file no performance detector covers, and is never
+ * printed as a score. A field with no scored file says why in one line.
+ */
+import { describe, it, expect, vi, beforeAll } from "vitest";
+import { render, screen } from "@testing-library/react";
+import type { HealthOverviewSummary } from "@repowise-dev/types/health";
+import {
+ CodeHealthMap,
+ HEALTH_UNSUPPORTED_LABEL,
+ HEALTH_UNSUPPORTED_NOTICE,
+ NEUTRAL_FILL,
+ OVERLAY_SPECS,
+ PERFORMANCE_STATE_LABEL,
+ noFileScored,
+ type CodeHealthMapFile,
+} from "../../src/health/code-health-map.js";
+import { MapFieldList, MapInspector } from "../../src/health/map/inspector.js";
+import { CodeHealthLede } from "../../src/health/code-health-lede.js";
+
+function f(path: string, score: number | null, nloc = 100): CodeHealthMapFile {
+ return {
+ file_path: path,
+ score,
+ nloc,
+ module: "src",
+ line_coverage_pct: null,
+ has_test_file: false,
+ maintainability_score: score,
+ };
+}
+
+beforeAll(() => {
+ class RO {
+ cb: ResizeObserverCallback;
+ constructor(cb: ResizeObserverCallback) {
+ this.cb = cb;
+ }
+ observe() {
+ this.cb(
+ [{ contentRect: { width: 800, height: 600 } } as ResizeObserverEntry],
+ this as unknown as ResizeObserver,
+ );
+ }
+ unobserve() {}
+ disconnect() {}
+ }
+ vi.stubGlobal("ResizeObserver", RO);
+});
+
+describe("an unscored file on the health lens", () => {
+ it("is grey, not the green a perfect score would draw", () => {
+ expect(OVERLAY_SPECS.health.fill(f("src/Big.php", null))).toBe(NEUTRAL_FILL);
+ expect(OVERLAY_SPECS.health.fill(f("src/ok.py", 10))).not.toBe(NEUTRAL_FILL);
+ });
+
+ it("is named in the key with the performance lens's own words", () => {
+ expect(HEALTH_UNSUPPORTED_LABEL).toBe(PERFORMANCE_STATE_LABEL.unsupported);
+ expect(OVERLAY_SPECS.health.legend.at(-1)).toEqual({
+ fill: NEUTRAL_FILL,
+ label: HEALTH_UNSUPPORTED_LABEL,
+ });
+ });
+
+ it("ranks last and prints no score in the list", () => {
+ const { container } = render(
+ <MapFieldList
+ files={[f("src/Big.php", null), f("src/bad.py", 3), f("src/ok.py", 9)]}
+ overlay="health"
+ onSelectFile={() => {}}
+ />,
+ );
+ const names = Array.from(container.querySelectorAll("li")).map((li) => li.textContent ?? "");
+ expect(names[0]).toContain("bad.py");
+ expect(names[2]).toContain("Big.php");
+ expect(names[2]).toContain("—");
+ });
+
+ it("is described, not scored, in the inspector", () => {
+ render(
+ <MapInspector
+ file={f("src/Big.php", null)}
+ overlay="health"
+ onOpen={() => {}}
+ onClose={() => {}}
+ />,
+ );
+ expect(screen.getByText(HEALTH_UNSUPPORTED_LABEL)).toBeTruthy();
+ expect(screen.queryByText("10.0")).toBeNull();
+ });
+});
+
+describe("a field with no scored file", () => {
+ it("is recognised only when every file is unscored", () => {
+ expect(noFileScored([f("a.php", null), f("b.php", null)])).toBe(true);
+ expect(noFileScored([f("a.php", null), f("b.py", 8)])).toBe(false);
+ expect(noFileScored([])).toBe(false);
+ });
+
+ it("says so in one line over the map", () => {
+ render(<CodeHealthMap files={[f("a.php", null), f("b.php", null, 40)]} />);
+ expect(screen.getByTestId("map-unanalysed").textContent).toBe(HEALTH_UNSUPPORTED_NOTICE);
+ });
+
+ it("says nothing when some file is scored", () => {
+ render(<CodeHealthMap files={[f("a.php", null), f("b.py", 7, 40)]} />);
+ expect(screen.queryByTestId("map-unanalysed")).toBeNull();
+ });
+});
+
+describe("the code health lede", () => {
+ const base = {
+ file_count: 0,
+ open_findings: 0,
+ worst_performer_path: null,
+ worst_performer_score: null,
+ };
+
+ it("leads with 'Not analysed' when no file is scored", () => {
+ render(
+ <CodeHealthLede
+ summary={{ ...base, average_health: null, unanalysed_file_count: 2992 } as HealthOverviewSummary}
+ />,
+ );
+ expect(screen.getByText("Not analysed")).toBeTruthy();
+ expect(screen.getByText(HEALTH_UNSUPPORTED_NOTICE)).toBeTruthy();
+ expect(screen.queryByText("out of 10")).toBeNull();
+ });
+
+ it("names the files it left out of a scored figure", () => {
+ const { container } = render(
+ <CodeHealthLede
+ summary={
+ { ...base, file_count: 253, average_health: 9.1, unanalysed_file_count: 1650 } as HealthOverviewSummary
+ }
+ />,
+ );
+ expect(container.textContent).toContain("1,650 more files are in a");
+ });
+});
diff --git a/packages/ui/src/health/ai-prompts/file-health-prompt.ts b/packages/ui/src/health/ai-prompts/file-health-prompt.ts
index fb3f7abea..2fa366314 100644
--- a/packages/ui/src/health/ai-prompts/file-health-prompt.ts
+++ b/packages/ui/src/health/ai-prompts/file-health-prompt.ts
@@ -22,7 +22,8 @@ import {
*/
export interface FileHealthPromptInput {
file_path: string;
- score: number;
+ /** `null` when health has no dialect for the file's language. */
+ score: number | null;
nloc?: number | null;
module?: string | null;
defect_score?: number | null;
@@ -164,7 +165,9 @@ function healthSnapshot(
trendDelta: number | null | undefined,
): string {
return bulletList([
- `Health score: **${file.score.toFixed(1)}/10** (lower is worse; 10.0 is clean)`,
+ file.score == null
+ ? "Health score: not analysed (no health support for this language yet)"
+ : `Health score: **${file.score.toFixed(1)}/10** (lower is worse; 10.0 is clean)`,
deductionLine(file.total_deduction, categoryCount),
trendLine(trendDelta),
file.nloc != null ? `Size: ${file.nloc} NLOC` : null,
diff --git a/packages/ui/src/health/code-health-controls.tsx b/packages/ui/src/health/code-health-controls.tsx
index 2d07be5fe..1a58e3253 100644
--- a/packages/ui/src/health/code-health-controls.tsx
+++ b/packages/ui/src/health/code-health-controls.tsx
@@ -4,6 +4,7 @@ import * as React from "react";
import { cn } from "../lib/cn";
import { scoreBadgeClass } from "./tokens";
import type { CodeHealthMapFile } from "./code-health-map";
+import { scoreText } from "./map/lens";
/** Labelled <select> used across the Triage queue filters. */
export function FilterSelect({
@@ -112,14 +113,18 @@ export function FileSpotlight({
return (
<div className="space-y-2 rounded-lg border border-[var(--color-border-default)] bg-[var(--color-bg-surface)] p-3">
<div className="flex items-center gap-2">
- <span
- className={cn(
- "inline-flex items-center justify-center rounded px-1.5 py-0.5 text-xs font-semibold",
- scoreBadgeClass(file.score),
- )}
- >
- {file.score.toFixed(1)}
- </span>
+ {file.score == null ? (
+ <span className="text-xs text-[var(--color-text-tertiary)]">{scoreText(file)}</span>
+ ) : (
+ <span
+ className={cn(
+ "inline-flex items-center justify-center rounded px-1.5 py-0.5 text-xs font-semibold",
+ scoreBadgeClass(file.score),
+ )}
+ >
+ {file.score.toFixed(1)}
+ </span>
+ )}
<span
className="truncate text-sm font-medium text-[var(--color-text-primary)]"
title={file.file_path}
diff --git a/packages/ui/src/health/code-health-lede.tsx b/packages/ui/src/health/code-health-lede.tsx
index 0a5babd93..b31218bf6 100644
--- a/packages/ui/src/health/code-health-lede.tsx
+++ b/packages/ui/src/health/code-health-lede.tsx
@@ -33,6 +33,7 @@ import { StatRibbon, type RibbonStat } from "../stats/stat-ribbon";
import { formatNumber } from "../lib/format";
import { healthBand, healthBandColor, scoreTextColor } from "./tokens";
import { HealthDistributionBar } from "./health-distribution-bar";
+import { HEALTH_UNSUPPORTED_NOTICE } from "./map/lens";
const HEALTH_HINT =
"Fitted against real bug history to predict where defects appear. Built from " +
@@ -98,6 +99,27 @@ export interface CodeHealthLedeProps {
}
/** "3 months" / "1 month", from a day count. */
+function UnanalysedLede({ action }: { action?: React.ReactNode }) {
+ return (
+ <PageLede label="Code health" value="Not analysed" action={action}>
+ <p>{HEALTH_UNSUPPORTED_NOTICE}</p>
+ </PageLede>
+ );
+}
+
+/** The files a scored figure left out because health has no dialect for them. */
+function UnanalysedNote({ count }: { count: number }) {
+ if (count <= 0) return null;
+ const one = count === 1;
+ return (
+ <>
+ {" "}
+ {formatNumber(count)} more {one ? "file is" : "files are"} in a language health does not
+ analyse yet, so {one ? "it is" : "they are"} left out of this figure.
+ </>
+ );
+}
+
function windowLabel(days: number): string {
const months = Math.max(1, Math.round(days / 30));
return months === 1 ? "month" : `${months} months`;
@@ -112,6 +134,9 @@ export function CodeHealthLede({
variant = "lead",
}: CodeHealthLedeProps) {
const health = summary.average_health;
+ // No file scored: every file is in a language health has no dialect for.
+ // There is no figure to lead with, so the lede says that instead of a 10.
+ if (health == null) return <UnanalysedLede action={action} />;
const maint = summary.maintainability_average;
const perf = summary.performance_average;
const perfFindings = summary.performance_findings ?? 0;
@@ -224,6 +249,7 @@ export function CodeHealthLede({
duplication, coverage
{codeShape ? "" : ", churn and ownership"}.
{healthChip ? <> That puts it in the {healthChip.label} band.</> : null}
+ <UnanalysedNote count={summary.unanalysed_file_count ?? 0} />
{perf != null && (
<>
{" "}
diff --git a/packages/ui/src/health/code-health-map.tsx b/packages/ui/src/health/code-health-map.tsx
index c54af2655..1b1bebc3b 100644
--- a/packages/ui/src/health/code-health-map.tsx
+++ b/packages/ui/src/health/code-health-map.tsx
@@ -21,7 +21,7 @@ import type {
} from "react";
import { useCommunityFamilies } from "../shared/use-theme-tokens";
-import { OVERLAY_ORDER, OVERLAY_SPECS } from "./map/lens";
+import { HEALTH_UNSUPPORTED_NOTICE, OVERLAY_ORDER, OVERLAY_SPECS, noFileScored } from "./map/lens";
import { packGalaxies, rand } from "./map/layout";
import { FileNodes } from "./map/node-layer";
import { HoverCard, NodeHighlight, SearchMatches } from "./map/overlay";
@@ -38,14 +38,18 @@ export type {
PerformanceActionability,
} from "./map/types";
export {
+ HEALTH_UNSUPPORTED_LABEL,
+ HEALTH_UNSUPPORTED_NOTICE,
NEUTRAL_FILL,
OVERLAY_ORDER,
OVERLAY_SPECS,
PERFORMANCE_STATE_LABEL,
burdenBand,
+ noFileScored,
performanceBurden,
performanceFill,
performanceSentence,
+ scoreText,
} from "./map/lens";
export type {
LegendRow,
@@ -622,6 +626,16 @@ export function CodeHealthMap({
{scope ? <MapScopeNote scope={scope} matches={matches.length} query={q} /> : null}
+ {noFileScored(files) ? (
+ <div
+ role="status"
+ data-testid="map-unanalysed"
+ className="pointer-events-none absolute bottom-3 left-3 max-w-[64%] rounded-md border border-[var(--color-border-default)] bg-[var(--color-bg-glass)] px-2.5 py-1.5 text-[11px] text-[var(--color-text-secondary)] shadow-sm backdrop-blur-sm sm:max-w-[44%]"
+ >
+ {HEALTH_UNSUPPORTED_NOTICE}
+ </div>
+ ) : null}
+
{hovered && pointer ? (
<HoverCard
file={hovered}
diff --git a/packages/ui/src/health/health-file-drawer.tsx b/packages/ui/src/health/health-file-drawer.tsx
index fc0b38f3f..68048614b 100644
--- a/packages/ui/src/health/health-file-drawer.tsx
+++ b/packages/ui/src/health/health-file-drawer.tsx
@@ -30,6 +30,7 @@ import { CollapsibleSection } from "../shared/collapsible-section";
import { formatRelativeTimeOrNull } from "../lib/format";
import { Sparkline } from "./sparkline";
import { ACTIONABILITY_LABEL } from "./performance/presentation";
+import { HEALTH_UNSUPPORTED_LABEL } from "./map/lens";
import {
SEVERITY_CHIP,
SEVERITY_LABEL,
@@ -71,7 +72,8 @@ export interface HealthDrawerFinding {
export interface HealthDrawerMetric {
file_path: string;
- score: number;
+ /** `null` when health has no dialect for the file's language. */
+ score: number | null;
/** Structural counters — null when the host has no metric row for the
* file, so the drawer can say "not measured" instead of a misleading 0. */
max_ccn: number | null;
@@ -461,25 +463,15 @@ export function HealthFileDrawer({
<p className="font-mono text-[10px] uppercase tracking-[0.12em] text-[var(--color-text-tertiary)]">
Code health
</p>
- <div className="flex flex-wrap items-baseline gap-x-2.5 gap-y-1">
- <span
- className="text-[40px] font-semibold leading-none tracking-tight tabular-nums"
- style={{ color: healthBandColor(bandForScore(metric.score)) }}
- >
- {formatScore(metric.score)}
- </span>
- <span className="text-xs text-[var(--color-text-tertiary)]">out of 10</span>
- </div>
- <span
- className="w-fit rounded-full border px-2.5 py-0.5 text-[11px] font-medium"
- style={{
- color: healthBandColor(bandForScore(metric.score)),
- borderColor: `color-mix(in srgb, ${healthBandColor(bandForScore(metric.score))} 40%, transparent)`,
- background: `color-mix(in srgb, ${healthBandColor(bandForScore(metric.score))} 9%, transparent)`,
- }}
- >
- {HEALTH_BAND_LABEL[bandForScore(metric.score)]}
- </span>
+ {metric.score == null ? (
+ // Nothing measured this file, so there is no number and no
+ // band: the words the map's grey node carries instead.
+ <p className="text-sm text-[var(--color-text-secondary)]">
+ Not analysed. {HEALTH_UNSUPPORTED_LABEL}.
+ </p>
+ ) : (
+ <ScoreLede score={metric.score} />
+ )}
{trend && trend.points.length >= 2 ? (
<div className="mt-1 flex items-center gap-2">
@@ -841,6 +833,33 @@ function MeasuredNum({ v }: { v: number | null }) {
* carry their band colour; counters are plain, because a nesting depth of 3 is
* not good or bad news on its own.
*/
+/** The score and its band, for a file that has one. */
+function ScoreLede({ score }: { score: number }) {
+ return (
+ <>
+ <div className="flex flex-wrap items-baseline gap-x-2.5 gap-y-1">
+ <span
+ className="text-[40px] font-semibold leading-none tracking-tight tabular-nums"
+ style={{ color: healthBandColor(bandForScore(score)) }}
+ >
+ {formatScore(score)}
+ </span>
+ <span className="text-xs text-[var(--color-text-tertiary)]">out of 10</span>
+ </div>
+ <span
+ className="w-fit rounded-full border px-2.5 py-0.5 text-[11px] font-medium"
+ style={{
+ color: healthBandColor(bandForScore(score)),
+ borderColor: `color-mix(in srgb, ${healthBandColor(bandForScore(score))} 40%, transparent)`,
+ background: `color-mix(in srgb, ${healthBandColor(bandForScore(score))} 9%, transparent)`,
+ }}
+ >
+ {HEALTH_BAND_LABEL[bandForScore(score)]}
+ </span>
+ </>
+ );
+}
+
function MetricGrid({ metric }: { metric: HealthDrawerMetric }) {
const cells: { label: string; value: React.ReactNode }[] = [
{
diff --git a/packages/ui/src/health/map/inspector.tsx b/packages/ui/src/health/map/inspector.tsx
index 83bad498b..1180b7eea 100644
--- a/packages/ui/src/health/map/inspector.tsx
+++ b/packages/ui/src/health/map/inspector.tsx
@@ -16,10 +16,13 @@ import { useMemo } from "react";
import { cn } from "../../lib/cn";
import { scoreBadgeClass } from "../tokens";
import {
+ HEALTH_UNSUPPORTED_LABEL,
+ NEUTRAL_FILL,
PERFORMANCE_STATE_LABEL,
performanceBurden,
performanceFill,
performanceSentence,
+ scoreText,
} from "./lens";
import type { CodeHealthMapFile, CodeHealthOverlay, MapScope } from "./types";
@@ -60,7 +63,12 @@ function rankFiles(
return a.file_path.localeCompare(b.file_path);
});
}
- return [...files].sort((a, b) => a.score - b.score || a.file_path.localeCompare(b.file_path));
+ // A file with no score sorts last: nothing measured it, so it is neither
+ // worst nor best.
+ const key = (f: CodeHealthMapFile) => f.score ?? Number.POSITIVE_INFINITY;
+ return [...files].sort(
+ (a, b) => key(a) - key(b) || a.file_path.localeCompare(b.file_path),
+ );
}
const LIST_HEADING: Record<string, string> = {
@@ -138,7 +146,7 @@ export function MapFieldList({
</span>
) : (
<span className="shrink-0 font-mono text-[10px] tabular-nums text-[var(--color-text-secondary)]">
- {f.score.toFixed(1)}
+ {f.score == null ? "—" : f.score.toFixed(1)}
</span>
)}
</span>
@@ -198,22 +206,7 @@ export function MapInspector({
The mark is the node as the canvas draws it, from the same
function, so the selection and the field it was picked out of can
never describe the file differently. */}
- {overlay === "performance" ? (
- <span
- aria-hidden
- className="inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-full"
- style={{ backgroundColor: performanceFill(file) }}
- />
- ) : (
- <span
- className={cn(
- "inline-flex shrink-0 items-center justify-center rounded px-1.5 py-0.5 text-xs font-semibold tabular-nums",
- scoreBadgeClass(file.score),
- )}
- >
- {file.score.toFixed(1)}
- </span>
- )}
+ <InspectorMark file={file} overlay={overlay} />
<span className="min-w-0 flex-1 truncate text-sm font-medium text-[var(--color-text-primary)]">
{name}
</span>
@@ -262,7 +255,9 @@ export function MapInspector({
{overlay === "performance" ? (
// Still available, but as one supporting figure among several rather
// than as the headline the lens is not about.
- <span className="tabular-nums">code health {file.score.toFixed(1)}</span>
+ <span className="tabular-nums">code health {scoreText(file)}</span>
+ ) : file.score == null ? (
+ <span>{HEALTH_UNSUPPORTED_LABEL}</span>
) : null}
<span className="tabular-nums">{file.nloc.toLocaleString()} NLOC</span>
{file.line_coverage_pct != null ? (
@@ -281,3 +276,35 @@ export function MapInspector({
</section>
);
}
+
+/** The lead mark: the node as the field draws it, or the score pill. */
+function InspectorMark({
+ file,
+ overlay,
+}: {
+ file: CodeHealthMapFile;
+ overlay: CodeHealthOverlay;
+}) {
+ // Under performance, or for a file with no score, the mark is the node as
+ // the field draws it: a score pill would claim a figure the lens is not
+ // about, or one nothing measured.
+ if (overlay === "performance" || file.score == null) {
+ return (
+ <span
+ aria-hidden
+ className="inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-full"
+ style={{ backgroundColor: overlay === "performance" ? performanceFill(file) : NEUTRAL_FILL }}
+ />
+ );
+ }
+ return (
+ <span
+ className={cn(
+ "inline-flex shrink-0 items-center justify-center rounded px-1.5 py-0.5 text-xs font-semibold tabular-nums",
+ scoreBadgeClass(file.score),
+ )}
+ >
+ {file.score.toFixed(1)}
+ </span>
+ );
+}
diff --git a/packages/ui/src/health/map/lens.ts b/packages/ui/src/health/map/lens.ts
index 3dfd3eaa4..5aa50e3e6 100644
--- a/packages/ui/src/health/map/lens.ts
+++ b/packages/ui/src/health/map/lens.ts
@@ -208,6 +208,27 @@ export const PERFORMANCE_STATE_LABEL: Record<PerformanceNodeState, string> = {
unknown: "Not analyzed here",
};
+/**
+ * What the health lenses say for a file with no score: the same words the
+ * performance lens uses for a file no detector covers, because it is the same
+ * situation one pillar over. Grey, never green.
+ */
+export const HEALTH_UNSUPPORTED_LABEL = PERFORMANCE_STATE_LABEL.unsupported;
+
+/** The one line a map shows when not one drawn file has a score. */
+export const HEALTH_UNSUPPORTED_NOTICE =
+ "Code health analysis does not support this language yet, so its files are shown grey.";
+
+/** True when the field has files and none of them carries a score. */
+export function noFileScored(files: CodeHealthMapFile[]): boolean {
+ return files.length > 0 && files.every((f) => f.score == null);
+}
+
+/** A file's score at one decimal, or the unsupported label. */
+export function scoreText(f: CodeHealthMapFile): string {
+ return f.score == null ? HEALTH_UNSUPPORTED_LABEL : f.score.toFixed(1);
+}
+
/** One sentence a hover card or inspector can print about a file. */
export function performanceSentence(f: CodeHealthMapFile): string {
const { state, count, unit } = performanceBurden(f);
@@ -221,9 +242,9 @@ export function performanceSentence(f: CodeHealthMapFile): string {
export const OVERLAY_SPECS: Record<CodeHealthOverlay, OverlaySpec> = {
health: {
label: "Code health",
- caption: "galaxy = module · size = lines of code",
- fill: (f) => healthNodeFill(f.score),
- legend: BAND_LEGEND,
+ caption: "galaxy = module · size = lines of code · grey = not analysed",
+ fill: (f) => scoreFill(f.score),
+ legend: [...BAND_LEGEND, { fill: NEUTRAL_FILL, label: HEALTH_UNSUPPORTED_LABEL }],
},
maintainability: {
label: "Maintainability",
diff --git a/packages/ui/src/health/map/overlay.tsx b/packages/ui/src/health/map/overlay.tsx
index 7e068e453..0f5a01561 100644
--- a/packages/ui/src/health/map/overlay.tsx
+++ b/packages/ui/src/health/map/overlay.tsx
@@ -10,7 +10,7 @@
* ring on the matches instead of touching the thousands that did not match.
*/
-import { performanceSentence } from "./lens";
+import { performanceSentence, scoreText } from "./lens";
import type { CodeHealthMapFile, CodeHealthOverlay, FileNode } from "./types";
/** Match rings drawn at once. Beyond this the field is the answer, not a mark. */
@@ -177,7 +177,8 @@ export function HoverCard({
</div>
) : null}
<div className="mt-0.5 text-[10px] leading-tight text-[var(--color-text-tertiary)] tabular-nums">
- score {file.score.toFixed(1)} · {file.nloc.toLocaleString()} NLOC
+ {file.score == null ? scoreText(file) : `score ${scoreText(file)}`} ·{" "}
+ {file.nloc.toLocaleString()} NLOC
{cov != null ? ` · ${Math.round(cov)}% cov` : ""}
{file.has_test_file ? "" : " · untested"}
</div>
diff --git a/packages/ui/src/health/map/types.ts b/packages/ui/src/health/map/types.ts
index 5ea83b77e..f156eaeb2 100644
--- a/packages/ui/src/health/map/types.ts
+++ b/packages/ui/src/health/map/types.ts
@@ -9,7 +9,9 @@ import type { PerformanceActionabilityState } from "@repowise-dev/types/health";
export interface CodeHealthMapFile {
file_path: string;
- score: number;
+ /** `null` when health has no dialect for the file's language: drawn grey,
+ * like a file no performance detector covers, never as a score. */
+ score: number | null;
nloc: number;
module: string | null;
line_coverage_pct: number | null;
diff --git a/packages/vscode/src/core/bulkHealth.ts b/packages/vscode/src/core/bulkHealth.ts
index c258dabd5..4f62da40a 100644
--- a/packages/vscode/src/core/bulkHealth.ts
+++ b/packages/vscode/src/core/bulkHealth.ts
@@ -33,7 +33,15 @@ const PAGE_LIMIT = 2000;
*/
const inFlight = new Map<string, Promise<Map<string, FileScores> | null>>();
-function toScores(metric: HealthFileMetric): FileScores {
+/**
+ * A file with no score (no health dialect for its language) gets no
+ * decoration, the same as a file the index has no row for.
+ */
+function hasScore(metric: HealthFileMetric): metric is HealthFileMetric & { score: number } {
+ return metric.score != null;
+}
+
+function toScores(metric: HealthFileMetric & { score: number }): FileScores {
return {
score: metric.score,
defectScore: metric.defect_score ?? null,
@@ -58,7 +66,7 @@ async function fetchAll(
let offset = 0;
for (;;) {
const page = await listHealthFiles(repoId, { limit: PAGE_LIMIT, offset });
- for (const metric of page.files) {
+ for (const metric of page.files.filter(hasScore)) {
map.set(metric.file_path, toScores(metric));
}
offset += page.files.length;
diff --git a/packages/vscode/webview/src/views/health/App.test.tsx b/packages/vscode/webview/src/views/health/App.test.tsx
index 7be56bf8c..fd7e6b7b5 100644
--- a/packages/vscode/webview/src/views/health/App.test.tsx
+++ b/packages/vscode/webview/src/views/health/App.test.tsx
@@ -194,7 +194,8 @@ describe("Health dashboard", () => {
);
const figure = await screen.findByText("7.6");
- const file = files.files.find((f) => f.file_path === "src/mid.py")!;
+ const found = files.files.find((f) => f.file_path === "src/mid.py")!;
+ const file = { ...found, score: found.score! };
// The contradiction this replaced: the panel called 7.6 green while the
// canvas beside it coloured the same node amber.
diff --git a/packages/web/src/components/health/health-file-drawer-host.tsx b/packages/web/src/components/health/health-file-drawer-host.tsx
index 06de30338..b72a92ed0 100644
--- a/packages/web/src/components/health/health-file-drawer-host.tsx
+++ b/packages/web/src/components/health/health-file-drawer-host.tsx
@@ -87,7 +87,7 @@ export function HealthFileDrawerHost({
loading={isLoading}
metric={data?.metric ?? null}
breakdown={
- data
+ data?.breakdown
? {
score: data.breakdown.score,
total_deduction: data.breakdown.total_deduction,