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.

feat(vscode): show documentation drift in the Problems panel for markdown (#2648)

Raghav Chamadiyaf6886d08dd30
diff --git a/packages/vscode/README.md b/packages/vscode/README.md
index c0a93837f..0fae59619 100644
--- a/packages/vscode/README.md
+++ b/packages/vscode/README.md
@@ -107,6 +107,7 @@ The quickest way to tune Repowise is **Repowise: Open Settings**, a friendly pan
| `repowise.changeIntel.cochangeNudge` | `true` | The quiet "usually change together" status-bar hint |
| `repowise.changeIntel.cochangeMinScore` | `4` | How strong the history has to be before a related file is suggested |
| `repowise.diagnostics.enabled` | `false` | Also publish high-severity findings to the Problems panel |
+| `repowise.docDrift.diagnostics.enabled` | `true` | Flag lines in visible markdown files whose paths, links, anchors or commands no longer exist |
## Privacy
diff --git a/packages/vscode/package.json b/packages/vscode/package.json
index 9e0d83fa2..177131567 100644
--- a/packages/vscode/package.json
+++ b/packages/vscode/package.json
@@ -98,6 +98,18 @@
"default": ["defect", "maintainability", "performance"],
"description": "Health dimensions included in the Problems panel. Advisory findings never deduct from a score, so they are off by default; they stay visible in the gutter, in hovers and to the language-model tools either way."
},
+ "repowise.docDrift.diagnostics.enabled": {
+ "type": "boolean",
+ "default": true,
+ "description": "Show documentation-drift findings (paths, links, anchors and commands a markdown file names that the tree no longer has) for visible markdown files in the Problems panel. On by default: findings are sparse and each names the line to edit."
+ },
+ "repowise.docDrift.diagnostics.minConfidence": {
+ "type": "number",
+ "minimum": 0,
+ "maximum": 1,
+ "default": 0.7,
+ "description": "Lowest confidence a documentation-drift finding needs to appear in the Problems panel. Findings at 0.7 or above show as warnings, the rest as information."
+ },
"repowise.gutterHeat.enabled": {
"type": "boolean",
"default": true,
diff --git a/packages/vscode/src/core/fileSignals.ts b/packages/vscode/src/core/fileSignals.ts
index fa608524a..a37caa89c 100644
Binary files a/packages/vscode/src/core/fileSignals.ts and b/packages/vscode/src/core/fileSignals.ts differ
diff --git a/packages/vscode/src/core/webviewApi.ts b/packages/vscode/src/core/webviewApi.ts
index 145315f11..5f58a726d 100644
--- a/packages/vscode/src/core/webviewApi.ts
+++ b/packages/vscode/src/core/webviewApi.ts
@@ -60,6 +60,8 @@ const SETTING_DEFAULTS: SettingsValues = {
"diagnostics.enabled": true,
"diagnostics.minSeverity": "high",
"diagnostics.dimensions": ["defect", "maintainability", "performance"],
+ "docDrift.diagnostics.enabled": true,
+ "docDrift.diagnostics.minConfidence": 0.7,
"gutterHeat.enabled": true,
"fileDecorations.enabled": true,
"fileDecorations.maxScore": 4,
@@ -88,6 +90,8 @@ const SETTING_VALIDATORS: Record<SettingKey, (v: SettingValue) => SettingValue>
"diagnostics.enabled": expectBoolean,
"diagnostics.minSeverity": (v) => expectEnum(v, SEVERITIES),
"diagnostics.dimensions": (v) => expectStringSubset(v, DIMENSIONS),
+ "docDrift.diagnostics.enabled": expectBoolean,
+ "docDrift.diagnostics.minConfidence": (v) => expectNumberInRange(v, 0, 1),
"gutterHeat.enabled": expectBoolean,
"fileDecorations.enabled": expectBoolean,
"fileDecorations.maxScore": (v) => expectNumberInRange(v, 0, 10),
diff --git a/packages/vscode/src/extension.ts b/packages/vscode/src/extension.ts
index 650929dcb..33be5d774 100644
--- a/packages/vscode/src/extension.ts
+++ b/packages/vscode/src/extension.ts
@@ -12,6 +12,7 @@ import { registerOnboarding } from "./features/onboarding";
import { registerServerManager } from "./features/serverManager";
import { registerMcp } from "./features/mcp";
import { registerDiagnostics } from "./features/diagnostics";
+import { registerDocDriftDiagnostics } from "./features/docDriftDiagnostics";
import { registerGutterHeat } from "./features/gutterHeat";
import { registerHovers } from "./features/hovers";
import { registerFileDecorations } from "./features/fileDecorations";
@@ -85,6 +86,7 @@ export function activate(extCtx: vscode.ExtensionContext): void {
registerServerManager(ctx),
registerMcp(ctx),
registerDiagnostics(ctx),
+ registerDocDriftDiagnostics(ctx),
registerGutterHeat(ctx),
registerHovers(ctx),
registerFileDecorations(ctx),
diff --git a/packages/vscode/src/features/diagnostics.ts b/packages/vscode/src/features/diagnostics.ts
index f11bd6c70..9cdf20c04 100644
--- a/packages/vscode/src/features/diagnostics.ts
+++ b/packages/vscode/src/features/diagnostics.ts
@@ -1,8 +1,9 @@
import * as vscode from "vscode";
import { CONFIG_SECTION } from "../constants";
import type { RepowiseContext } from "../core/context";
-import { getFileFindings, repoRelativePath } from "../core/fileSignals";
+import { getFileFindings } from "../core/fileSignals";
import type { HealthDimension, HealthFinding, HealthSeverity } from "@repowise-dev/types/health";
+import { registerEditorDiagnostics } from "./editorDiagnostics";
/** Severity ordering, high number = more severe, for the minSeverity floor. */
const SEVERITY_RANK: Record<HealthSeverity, number> = {
@@ -42,123 +43,43 @@ function rangeFor(finding: HealthFinding): vscode.Range {
return new vscode.Range(start, 0, end, Number.MAX_SAFE_INTEGER);
}
+function toDiagnostic(_doc: vscode.TextDocument, f: HealthFinding): vscode.Diagnostic {
+ const diagnostic = new vscode.Diagnostic(
+ rangeFor(f),
+ f.reason,
+ toDiagnosticSeverity(f.severity),
+ );
+ diagnostic.source = "repowise";
+ diagnostic.code = f.biomarker_type;
+ return diagnostic;
+}
+
/**
* Publishes health findings for visible editors into the Problems panel. Only
* findings at or above the configured severity floor and within the configured
- * dimensions surface; the deeper set stays in the gutter. Work is confined to
- * visible editors, and a file is only republished when its finding set changes.
+ * dimensions surface; the deeper set stays in the gutter.
*/
export function registerDiagnostics(ctx: RepowiseContext): vscode.Disposable {
- const collection = vscode.languages.createDiagnosticCollection("repowise");
- const disposables: vscode.Disposable[] = [collection];
-
- /** Last published finding-set signature per document URI, for diff-only set. */
- const signatures = new Map<string, string>();
- /** Lazily created freshness subscription, so activate() does no watching. */
- let watcherSub: vscode.Disposable | null = null;
-
const cfg = () => vscode.workspace.getConfiguration(CONFIG_SECTION);
- const enabled = (): boolean => cfg().get<boolean>("diagnostics.enabled", true);
const minSeverity = (): HealthSeverity =>
cfg().get<HealthSeverity>("diagnostics.minSeverity", "high");
const dimensions = (): Set<string> =>
new Set(cfg().get<string[]>("diagnostics.dimensions", DEFAULT_DIMENSIONS));
- function clearAll(): void {
- collection.clear();
- signatures.clear();
- }
-
- /** Diff-only publish: skips the set when the file's finding set is unchanged. */
- function publish(doc: vscode.TextDocument, findings: HealthFinding[]): void {
- const floor = SEVERITY_RANK[minSeverity()];
- const dims = dimensions();
- const filtered = findings.filter(
- (f) =>
- SEVERITY_RANK[f.severity] >= floor && dims.has(f.dimension ?? "defect"),
- );
-
- const signature = filtered
- .map((f) => `${f.id}:${f.line_start}:${f.line_end}:${f.severity}`)
- .sort()
- .join("|");
- const uriKey = doc.uri.toString();
- if (signatures.get(uriKey) === signature) return;
- signatures.set(uriKey, signature);
-
- const diagnostics = filtered.map((f) => {
- const diagnostic = new vscode.Diagnostic(
- rangeFor(f),
- f.reason,
- toDiagnosticSeverity(f.severity),
+ return registerEditorDiagnostics<HealthFinding>(ctx, {
+ name: "repowise",
+ configPrefix: CONFIG_PREFIX,
+ enabled: () => cfg().get<boolean>("diagnostics.enabled", true),
+ load: async (c, rel) => {
+ const findings = await getFileFindings(c, rel);
+ // Filters are read after the fetch, so a config change mid-fetch applies.
+ const floor = SEVERITY_RANK[minSeverity()];
+ const dims = dimensions();
+ return findings.filter(
+ (f) => SEVERITY_RANK[f.severity] >= floor && dims.has(f.dimension ?? "defect"),
);
- diagnostic.source = "repowise";
- diagnostic.code = f.biomarker_type;
- return diagnostic;
- });
- collection.set(doc.uri, diagnostics);
- }
-
- async function refreshAll(): Promise<void> {
- if (!enabled() || ctx.getExtensionState() !== "ready" || !ctx.repoId) {
- clearAll();
- return;
- }
-
- const editors = vscode.window.visibleTextEditors;
- const visible = new Set<string>();
- for (const editor of editors) {
- const rel = repoRelativePath(ctx, editor.document.uri);
- if (!rel) continue;
- visible.add(editor.document.uri.toString());
- const findings = await getFileFindings(ctx, rel);
- // State or config may have changed across the await; re-check before set.
- if (!enabled() || ctx.getExtensionState() !== "ready") return;
- publish(editor.document, findings);
- }
-
- // Drop entries for documents that are no longer visible.
- for (const uriKey of [...signatures.keys()]) {
- if (!visible.has(uriKey)) {
- collection.delete(vscode.Uri.parse(uriKey));
- signatures.delete(uriKey);
- }
- }
- }
-
- /** Subscribe to index-change events for this repo, once, while ready. */
- function ensureWatcher(): void {
- if (watcherSub) return;
- const watcher = ctx.events();
- if (!watcher) return;
- watcherSub = watcher.onDidChange((kind) => {
- if (kind !== "indexChanged") return;
- // A finished index update re-stamps head_commit; re-resolve it so the
- // next fetch caches under the new tag, then recompute visible editors.
- void ctx.refreshRepo().then(() => refreshAll());
- });
- disposables.push(watcherSub);
- }
-
- disposables.push(
- ctx.onDidChangeExtensionState((state) => {
- if (state === "ready") {
- ensureWatcher();
- void refreshAll();
- } else {
- clearAll();
- }
- }),
- vscode.window.onDidChangeVisibleTextEditors(() => void refreshAll()),
- vscode.workspace.onDidChangeConfiguration((event) => {
- if (event.affectsConfiguration(CONFIG_PREFIX)) void refreshAll();
- }),
- );
-
- if (ctx.getExtensionState() === "ready") {
- ensureWatcher();
- void refreshAll();
- }
-
- return vscode.Disposable.from(...disposables);
+ },
+ signature: (f) => `${f.id}:${f.line_start}:${f.line_end}:${f.severity}`,
+ toDiagnostic,
+ });
}
diff --git a/packages/vscode/src/features/docDriftDiagnostics.ts b/packages/vscode/src/features/docDriftDiagnostics.ts
new file mode 100644
index 000000000..a90de7cf3
--- /dev/null
+++ b/packages/vscode/src/features/docDriftDiagnostics.ts
@@ -0,0 +1,62 @@
+import * as vscode from "vscode";
+import { CONFIG_SECTION } from "../constants";
+import type { RepowiseContext } from "../core/context";
+import { getDocDriftFindings } from "../core/fileSignals";
+import { DOC_DRIFT_CONFIDENCE, type DocDriftFinding } from "@repowise-dev/types/doc-drift";
+import { registerEditorDiagnostics } from "./editorDiagnostics";
+
+const CONFIG_PREFIX = `${CONFIG_SECTION}.docDrift`;
+const MARKDOWN_EXT = /\.(md|mdx|markdown)$/i;
+
+function isMarkdown(doc: vscode.TextDocument): boolean {
+ return doc.languageId === "markdown" || MARKDOWN_EXT.test(doc.uri.path);
+}
+
+/** The finding's line, narrowed to the reference as written (else the target). */
+function rangeFor(doc: vscode.TextDocument, f: DocDriftFinding): vscode.Range {
+ const line = Math.min(Math.max(0, f.line_number - 1), doc.lineCount - 1);
+ const text = doc.lineAt(line).text;
+ for (const needle of [f.raw, f.target]) {
+ const at = needle ? text.indexOf(needle) : -1;
+ if (at >= 0) return new vscode.Range(line, at, line, at + needle.length);
+ }
+ return new vscode.Range(line, 0, line, text.length);
+}
+
+function toDiagnostic(doc: vscode.TextDocument, f: DocDriftFinding): vscode.Diagnostic {
+ const message = f.suggestion ? `${f.reason} Likely now: ${f.suggestion}.` : f.reason;
+ const diagnostic = new vscode.Diagnostic(
+ rangeFor(doc, f),
+ message,
+ f.confidence >= DOC_DRIFT_CONFIDENCE.HIGH
+ ? vscode.DiagnosticSeverity.Warning
+ : vscode.DiagnosticSeverity.Information,
+ );
+ diagnostic.source = "repowise";
+ diagnostic.code = `doc-drift:${f.kind}`;
+ return diagnostic;
+}
+
+/**
+ * Publishes documentation-drift findings for visible markdown editors into the
+ * Problems panel, in a collection of its own so it toggles independently of the
+ * health diagnostics. Detection only: no code action edits the document.
+ */
+export function registerDocDriftDiagnostics(ctx: RepowiseContext): vscode.Disposable {
+ const cfg = () => vscode.workspace.getConfiguration(CONFIG_PREFIX);
+ return registerEditorDiagnostics<DocDriftFinding>(ctx, {
+ name: "repowise-doc-drift",
+ configPrefix: CONFIG_PREFIX,
+ enabled: () => cfg().get<boolean>("diagnostics.enabled", true),
+ accept: isMarkdown,
+ load: (c, rel) =>
+ getDocDriftFindings(
+ c,
+ rel,
+ cfg().get<number>("diagnostics.minConfidence", DOC_DRIFT_CONFIDENCE.HIGH),
+ ),
+ // Keyed on what the diagnostic renders from.
+ signature: (f) => `${f.id}:${f.line_number}:${f.confidence}:${f.suggestion ?? ""}`,
+ toDiagnostic,
+ });
+}
diff --git a/packages/vscode/src/features/editorDiagnostics.ts b/packages/vscode/src/features/editorDiagnostics.ts
new file mode 100644
index 000000000..88572dfd1
--- /dev/null
+++ b/packages/vscode/src/features/editorDiagnostics.ts
@@ -0,0 +1,122 @@
+import * as vscode from "vscode";
+import type { RepowiseContext } from "../core/context";
+import { repoRelativePath } from "../core/fileSignals";
+
+/** One Problems-panel feature, as a configuration of the shared lifecycle. */
+export interface EditorDiagnosticsSpec<T> {
+ /** Diagnostic collection name. */
+ name: string;
+ /** Config section whose changes trigger a refresh. */
+ configPrefix: string;
+ enabled(): boolean;
+ /** Which visible documents the feature covers; all when omitted. */
+ accept?(doc: vscode.TextDocument): boolean;
+ /** The items to publish for one repo-relative file, already filtered. */
+ load(ctx: RepowiseContext, rel: string): Promise<T[]>;
+ /** Per-item key; a file is republished only when its sorted set changes. */
+ signature(item: T): string;
+ toDiagnostic(doc: vscode.TextDocument, item: T): vscode.Diagnostic;
+}
+
+/**
+ * Publishes per-file items for visible editors into a diagnostic collection.
+ * Work is confined to visible editors, a file is only republished when its item
+ * set changes, and an index change re-resolves the head commit and refreshes.
+ */
+export function registerEditorDiagnostics<T>(
+ ctx: RepowiseContext,
+ spec: EditorDiagnosticsSpec<T>,
+): vscode.Disposable {
+ const collection = vscode.languages.createDiagnosticCollection(spec.name);
+ const disposables: vscode.Disposable[] = [collection];
+
+ /** Last published item-set signature per document URI, for diff-only set. */
+ const signatures = new Map<string, string>();
+ /** Lazily created freshness subscription, so activate() does no watching. */
+ let watcherSub: vscode.Disposable | null = null;
+ /** Bumped per refresh run; a run that sees a newer value stops publishing. */
+ let generation = 0;
+
+ const active = (): boolean =>
+ spec.enabled() && ctx.getExtensionState() === "ready" && !!ctx.repoId;
+
+ function clearAll(): void {
+ collection.clear();
+ signatures.clear();
+ }
+
+ function publish(doc: vscode.TextDocument, items: T[]): void {
+ const signature = items.map(spec.signature).sort().join("|");
+ const uriKey = doc.uri.toString();
+ if (signatures.get(uriKey) === signature) return;
+ signatures.set(uriKey, signature);
+ collection.set(doc.uri, items.map((item) => spec.toDiagnostic(doc, item)));
+ }
+
+ async function refreshAll(): Promise<void> {
+ const run = ++generation;
+ if (!active()) {
+ clearAll();
+ return;
+ }
+
+ const visible = new Set<string>();
+ for (const editor of vscode.window.visibleTextEditors) {
+ const doc = editor.document;
+ if (spec.accept && !spec.accept(doc)) continue;
+ const rel = repoRelativePath(ctx, doc.uri);
+ if (!rel) continue;
+ visible.add(doc.uri.toString());
+ const items = await spec.load(ctx, rel);
+ // A newer run owns the collection now (it may hold a newer index's
+ // findings), and state or config may have changed across the await.
+ if (run !== generation || !active()) return;
+ publish(doc, items);
+ }
+
+ // Drop entries for documents that are no longer visible.
+ for (const uriKey of [...signatures.keys()]) {
+ if (!visible.has(uriKey)) {
+ collection.delete(vscode.Uri.parse(uriKey));
+ signatures.delete(uriKey);
+ }
+ }
+ }
+
+ /** Subscribe to index-change events for this repo, once, while ready. */
+ function ensureWatcher(): void {
+ if (watcherSub) return;
+ const watcher = ctx.events();
+ if (!watcher) return;
+ watcherSub = watcher.onDidChange((kind) => {
+ if (kind !== "indexChanged") return;
+ // A finished index update re-stamps head_commit; re-resolve it so the
+ // next fetch caches under the new tag, then recompute visible editors.
+ void ctx.refreshRepo().then(() => refreshAll());
+ });
+ disposables.push(watcherSub);
+ }
+
+ disposables.push(
+ ctx.onDidChangeExtensionState((state) => {
+ if (state === "ready") {
+ ensureWatcher();
+ void refreshAll();
+ } else {
+ clearAll();
+ }
+ }),
+ vscode.window.onDidChangeVisibleTextEditors(() => void refreshAll()),
+ vscode.workspace.onDidChangeConfiguration((event) => {
+ if (event.affectsConfiguration(spec.configPrefix)) void refreshAll();
+ }),
+ );
+
+ if (ctx.getExtensionState() === "ready") {
+ ensureWatcher();
+ void refreshAll();
+ }
+
+ // Reads the array at dispose time, so the lazily pushed watcher is included.
+ return new vscode.Disposable(() => disposables.forEach((d) => d.dispose()));
+}
diff --git a/packages/vscode/src/shared/webviewMessages.ts b/packages/vscode/src/shared/webviewMessages.ts
index 95086ffcb..219dfd7af 100644
--- a/packages/vscode/src/shared/webviewMessages.ts
+++ b/packages/vscode/src/shared/webviewMessages.ts
@@ -83,6 +83,8 @@ export const SETTING_KEYS = [
"diagnostics.enabled",
"diagnostics.minSeverity",
"diagnostics.dimensions",
+ "docDrift.diagnostics.enabled",
+ "docDrift.diagnostics.minConfidence",
"gutterHeat.enabled",
"fileDecorations.enabled",
"fileDecorations.maxScore",
diff --git a/packages/vscode/webview/src/views/settings/App.test.tsx b/packages/vscode/webview/src/views/settings/App.test.tsx
index 781b706cb..6f863248f 100644
--- a/packages/vscode/webview/src/views/settings/App.test.tsx
+++ b/packages/vscode/webview/src/views/settings/App.test.tsx
@@ -13,6 +13,8 @@ const DEFAULTS: SettingsValues = {
"diagnostics.enabled": true,
"diagnostics.minSeverity": "high",
"diagnostics.dimensions": ["defect", "maintainability", "performance"],
+ "docDrift.diagnostics.enabled": true,
+ "docDrift.diagnostics.minConfidence": 0.7,
"gutterHeat.enabled": true,
"fileDecorations.enabled": true,
"fileDecorations.maxScore": 4,
diff --git a/packages/vscode/webview/src/views/settings/App.tsx b/packages/vscode/webview/src/views/settings/App.tsx
index 114234232..39049114b 100644
--- a/packages/vscode/webview/src/views/settings/App.tsx
+++ b/packages/vscode/webview/src/views/settings/App.tsx
@@ -87,6 +87,24 @@ const GROUPS: Group[] = [
{ value: "advisory", label: "Advisory" },
],
},
+ {
+ key: "docDrift.diagnostics.enabled",
+ label: "Documentation drift",
+ description:
+ "Flag paths, links, anchors, and commands in visible markdown files that the tree no longer has.",
+ kind: "toggle",
+ },
+ {
+ key: "docDrift.diagnostics.minConfidence",
+ label: "Drift confidence floor",
+ description:
+ "Lowest confidence a drift finding needs to appear (0 to 1). At 0.7 or above it shows as a warning.",
+ kind: "number",
+ needs: "docDrift.diagnostics.enabled",
+ min: 0,
+ max: 1,
+ step: 0.05,
+ },
{
key: "gutterHeat.enabled",
label: "Gutter heat",