@linxiraos/pi-tui 1.4.11 → 1.4.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -233
- package/README.md +4 -1
- package/THIRD-PARTY-NOTICES.txt +4 -5
- package/dist/types/apps/shell-visualizer.d.ts +24 -0
- package/dist/types/autocomplete.d.ts +20 -0
- package/dist/types/chat/cache-invalidation-marker.d.ts +15 -7
- package/dist/types/chat/chat-transcript-builder.d.ts +5 -3
- package/dist/types/chat/display-preferences.d.ts +2 -0
- package/dist/types/chat/extension-types.d.ts +72 -1
- package/dist/types/chat/image-loading.d.ts +2 -2
- package/dist/types/chat/messages.d.ts +2 -3
- package/dist/types/chat/read-tool-group.d.ts +15 -2
- package/dist/types/chat/skill-message.d.ts +1 -0
- package/dist/types/chat/spotlight.d.ts +203 -0
- package/dist/types/chat/tool-execution.d.ts +26 -5
- package/dist/types/chat/transcript-actions.d.ts +11 -0
- package/dist/types/chat/transcript-browser.d.ts +9 -0
- package/dist/types/chat/transcript-presentation.d.ts +164 -0
- package/dist/types/chat/ttsr-notification.d.ts +2 -0
- package/dist/types/chrome/message-frame.d.ts +2 -0
- package/dist/types/chrome/transcript-container.d.ts +27 -6
- package/dist/types/components/loader.d.ts +0 -2
- package/dist/types/components/markdown.d.ts +11 -1
- package/dist/types/components/settings-list.d.ts +12 -2
- package/dist/types/frame-rate.d.ts +18 -0
- package/dist/types/hotkeys-markdown.d.ts +2 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/keybinding-matchers.d.ts +4 -1
- package/dist/types/kitty-graphics.d.ts +1 -1
- package/dist/types/motion-effects.d.ts +10 -0
- package/dist/types/native/encode.d.ts +2 -0
- package/dist/types/native/measure.d.ts +10 -0
- package/dist/types/native/overlay.d.ts +1 -1
- package/dist/types/native/quiet.d.ts +5 -0
- package/dist/types/native/reconcile.d.ts +6 -1
- package/dist/types/native/spans.d.ts +6 -0
- package/dist/types/native/state.d.ts +4 -0
- package/dist/types/overlays/agent-hub.d.ts +6 -0
- package/dist/types/overlays/link-browser.d.ts +55 -0
- package/dist/types/overlays/running-subagent-badge.d.ts +1 -4
- package/dist/types/overlays/spotlight-sheet.d.ts +36 -0
- package/dist/types/prompt/composer-attachments.d.ts +5 -2
- package/dist/types/prompt/composer-cache.d.ts +7 -2
- package/dist/types/prompt/composer.d.ts +6 -11
- package/dist/types/prompt/custom-editor.d.ts +8 -2
- package/dist/types/prompt/gradient-highlight.d.ts +2 -2
- package/dist/types/prompt/magic-keywords.d.ts +2 -0
- package/dist/types/prompt/model-mention-autocomplete.d.ts +9 -7
- package/dist/types/prompt/model-mention-syntax.d.ts +6 -0
- package/dist/types/prompt/prompt-action-autocomplete.d.ts +2 -1
- package/dist/types/prompt/welcome.d.ts +19 -0
- package/dist/types/render/extension-links.d.ts +0 -6
- package/dist/types/render/index.d.ts +1 -0
- package/dist/types/render/link-hints.d.ts +78 -0
- package/dist/types/render/render-utils.d.ts +0 -2
- package/dist/types/setup/scenes/types.d.ts +8 -0
- package/dist/types/setup/scenes/updates.d.ts +6 -0
- package/dist/types/setup/wizard.d.ts +7 -2
- package/dist/types/spinner-clock.d.ts +34 -0
- package/dist/types/status-line/component.d.ts +8 -4
- package/dist/types/status-line/host.d.ts +62 -0
- package/dist/types/status-line/index.d.ts +1 -0
- package/dist/types/status-line/prompt-cache.d.ts +14 -0
- package/dist/types/status-line/schema.d.ts +1 -1
- package/dist/types/status-line/startup.d.ts +6 -0
- package/dist/types/status-line/types.d.ts +8 -21
- package/dist/types/theme/schema.d.ts +28 -1
- package/dist/types/theme/symbols.d.ts +1 -1
- package/dist/types/theme/theme-class.d.ts +12 -2
- package/dist/types/theme/theme.d.ts +1 -1
- package/dist/types/theme/tui-adapters.d.ts +7 -0
- package/dist/types/thinking.d.ts +12 -0
- package/dist/types/tools/ask.d.ts +1 -1
- package/dist/types/tools/bash.d.ts +21 -0
- package/dist/types/tools/find.d.ts +9 -1
- package/dist/types/tools/grep.d.ts +2 -1
- package/dist/types/tools/grouped-file-output.d.ts +17 -0
- package/dist/types/tools/job-widget.d.ts +2 -2
- package/dist/types/tools/lsp.d.ts +4 -2
- package/dist/types/tools/native-view.d.ts +4 -0
- package/dist/types/tools/renderer.d.ts +9 -1
- package/dist/types/tools/shell-trace.d.ts +10 -0
- package/dist/types/tools/shell-viz-render.d.ts +6 -0
- package/dist/types/tools/shell-viz.d.ts +16 -0
- package/dist/types/tools/wait.d.ts +2 -2
- package/dist/types/tools/web-search-types.d.ts +1 -0
- package/dist/types/tools/write.d.ts +2 -0
- package/dist/types/tui.d.ts +15 -1
- package/package.json +15 -11
- package/src/apps/shell-visualizer.d.ts +24 -0
- package/src/apps/shell-visualizer.ts +167 -0
- package/src/autocomplete.d.ts +20 -0
- package/src/autocomplete.ts +14 -0
- package/src/chat/assistant-message.ts +11 -6
- package/src/chat/cache-invalidation-marker.d.ts +15 -7
- package/src/chat/cache-invalidation-marker.ts +18 -9
- package/src/chat/chat-transcript-builder.d.ts +5 -3
- package/src/chat/chat-transcript-builder.ts +16 -12
- package/src/chat/display-preferences.d.ts +2 -0
- package/src/chat/display-preferences.ts +3 -0
- package/src/chat/extension-types.d.ts +72 -1
- package/src/chat/extension-types.ts +74 -1
- package/src/chat/image-loading.d.ts +2 -2
- package/src/chat/image-loading.ts +2 -2
- package/src/chat/messages.d.ts +2 -3
- package/src/chat/messages.ts +3 -8
- package/src/chat/read-tool-group.d.ts +15 -2
- package/src/chat/read-tool-group.ts +201 -41
- package/src/chat/skill-message.d.ts +1 -0
- package/src/chat/skill-message.ts +4 -0
- package/src/chat/spotlight.d.ts +203 -0
- package/src/chat/spotlight.ts +460 -0
- package/src/chat/tool-execution.d.ts +26 -5
- package/src/chat/tool-execution.ts +360 -38
- package/src/chat/transcript-actions.d.ts +11 -0
- package/src/chat/transcript-actions.ts +13 -1
- package/src/chat/transcript-browser.d.ts +9 -0
- package/src/chat/transcript-browser.ts +18 -0
- package/src/chat/transcript-presentation.d.ts +164 -0
- package/src/chat/transcript-presentation.ts +642 -0
- package/src/chat/ttsr-notification.d.ts +25 -0
- package/src/chat/ttsr-notification.ts +5 -0
- package/src/chrome/message-frame.d.ts +2 -0
- package/src/chrome/message-frame.ts +7 -0
- package/src/chrome/message-notice.d.ts +58 -0
- package/src/chrome/transcript-container.d.ts +27 -6
- package/src/chrome/transcript-container.ts +317 -66
- package/src/components/editor.ts +25 -1
- package/src/components/loader.d.ts +0 -2
- package/src/components/loader.ts +30 -18
- package/src/components/markdown.d.ts +11 -1
- package/src/components/markdown.ts +41 -16
- package/src/components/settings-list.d.ts +12 -2
- package/src/components/settings-list.ts +29 -13
- package/src/frame-rate.d.ts +18 -0
- package/src/frame-rate.ts +36 -0
- package/src/hotkeys-markdown.ts +9 -2
- package/src/index.d.ts +3 -0
- package/src/index.ts +3 -0
- package/src/keybinding-matchers.d.ts +4 -1
- package/src/keybinding-matchers.ts +13 -12
- package/src/kitty-graphics.d.ts +1 -1
- package/src/kitty-graphics.ts +3 -2
- package/src/motion-effects.d.ts +10 -0
- package/src/motion-effects.ts +27 -0
- package/src/native/backend.ts +66 -7
- package/src/native/encode.d.ts +2 -0
- package/src/native/encode.ts +2 -0
- package/src/native/measure.d.ts +10 -0
- package/src/native/measure.ts +185 -0
- package/src/native/overlay.d.ts +1 -1
- package/src/native/overlay.ts +1 -1
- package/src/native/quiet.d.ts +5 -0
- package/src/native/quiet.ts +105 -0
- package/src/native/reconcile.d.ts +6 -1
- package/src/native/reconcile.ts +16 -10
- package/src/native/spans.d.ts +6 -0
- package/src/native/spans.ts +40 -0
- package/src/native/state.d.ts +4 -0
- package/src/native/state.ts +18 -0
- package/src/overlays/agent-hub.ts +15 -2
- package/src/overlays/ask-dialog.ts +1 -0
- package/src/overlays/btw-history-panel.ts +73 -6
- package/src/overlays/link-browser.ts +295 -0
- package/src/overlays/running-subagent-badge.ts +2 -9
- package/src/overlays/settings-defs.ts +1 -1
- package/src/overlays/settings-selector.ts +17 -3
- package/src/overlays/spotlight-sheet.ts +478 -0
- package/src/overlays/usage-dashboard.ts +6 -5
- package/src/prompt/composer-attachments.d.ts +5 -2
- package/src/prompt/composer-attachments.ts +6 -6
- package/src/prompt/composer-cache.ts +17 -16
- package/src/prompt/composer.ts +30 -123
- package/src/prompt/custom-editor.ts +17 -13
- package/src/prompt/gradient-highlight.d.ts +2 -2
- package/src/prompt/gradient-highlight.ts +5 -4
- package/src/prompt/magic-keywords.d.ts +2 -0
- package/src/prompt/magic-keywords.ts +4 -1
- package/src/prompt/model-mention-autocomplete.ts +73 -20
- package/src/prompt/model-mention-syntax.d.ts +6 -0
- package/src/prompt/model-mention-syntax.ts +9 -0
- package/src/prompt/prompt-action-autocomplete.ts +49 -33
- package/src/prompt/tips.txt +1 -0
- package/src/prompt/welcome.ts +104 -2
- package/src/render/extension-links.d.ts +0 -6
- package/src/render/extension-links.ts +0 -20
- package/src/render/index.d.ts +1 -0
- package/src/render/index.ts +1 -0
- package/src/render/link-hints.d.ts +78 -0
- package/src/render/link-hints.ts +299 -0
- package/src/render/render-utils.d.ts +0 -2
- package/src/render/render-utils.ts +0 -5
- package/src/setup/scenes/glyph.ts +1 -1
- package/src/setup/scenes/types.ts +8 -0
- package/src/setup/scenes/updates.ts +116 -0
- package/src/setup/wizard.ts +19 -8
- package/src/spinner-clock.d.ts +34 -0
- package/src/spinner-clock.ts +79 -0
- package/src/status-line/component.ts +145 -53
- package/src/status-line/host.ts +51 -0
- package/src/status-line/index.ts +1 -0
- package/src/status-line/presets.ts +3 -1
- package/src/status-line/prompt-cache.ts +154 -0
- package/src/status-line/schema.ts +1 -1
- package/src/status-line/segments.ts +33 -22
- package/src/status-line/startup.ts +22 -4
- package/src/status-line/types.ts +8 -22
- package/src/stdin-buffer.ts +89 -46
- package/src/terminal-capabilities.ts +3 -3
- package/src/terminal.ts +1 -8
- package/src/theme/loader.ts +3 -2
- package/src/theme/schema.d.ts +28 -1
- package/src/theme/schema.ts +30 -1
- package/src/theme/symbols.d.ts +1 -1
- package/src/theme/symbols.ts +15 -3
- package/src/theme/theme-class.d.ts +12 -2
- package/src/theme/theme-class.ts +23 -0
- package/src/theme/theme-schema.json +1 -1
- package/src/theme/theme.d.ts +1 -1
- package/src/theme/theme.ts +3 -7
- package/src/theme/tui-adapters.d.ts +7 -0
- package/src/theme/tui-adapters.ts +33 -1
- package/src/thinking.d.ts +12 -0
- package/src/thinking.ts +31 -0
- package/src/tools/ask.d.ts +1 -1
- package/src/tools/ask.ts +99 -38
- package/src/tools/ast-edit.ts +51 -32
- package/src/tools/ast-grep.ts +31 -19
- package/src/tools/bash.d.ts +21 -0
- package/src/tools/bash.ts +166 -24
- package/src/tools/find.d.ts +9 -1
- package/src/tools/find.ts +23 -2
- package/src/tools/grep.d.ts +2 -1
- package/src/tools/grep.ts +52 -36
- package/src/tools/grouped-file-output.d.ts +17 -0
- package/src/tools/grouped-file-output.ts +20 -2
- package/src/tools/job-widget.d.ts +2 -2
- package/src/tools/job-widget.ts +2 -2
- package/src/tools/lsp.d.ts +4 -2
- package/src/tools/lsp.ts +537 -642
- package/src/tools/native-view.d.ts +4 -0
- package/src/tools/native-view.ts +8 -2
- package/src/tools/renderer.d.ts +9 -1
- package/src/tools/renderer.ts +9 -1
- package/src/tools/shell-trace.d.ts +10 -0
- package/src/tools/shell-trace.ts +80 -0
- package/src/tools/shell-viz-render.d.ts +6 -0
- package/src/tools/shell-viz-render.ts +156 -0
- package/src/tools/shell-viz.d.ts +16 -0
- package/src/tools/shell-viz.ts +181 -0
- package/src/tools/streaming-output.ts +18 -8
- package/src/tools/wait.d.ts +2 -2
- package/src/tools/wait.ts +39 -34
- package/src/tools/web-search-types.d.ts +1 -0
- package/src/tools/web-search-types.ts +1 -0
- package/src/tools/write.d.ts +2 -0
- package/src/tools/write.ts +2 -0
- package/src/tui.d.ts +15 -1
- package/src/tui.ts +63 -6
- package/src/windows-input-mode.ts +7 -1
- package/dist/types/chat/collab-prompt-message.d.ts +0 -14
- package/dist/types/chrome/collab-qrcode.d.ts +0 -35
- package/src/chat/collab-prompt-message.d.ts +0 -14
- package/src/chat/collab-prompt-message.ts +0 -46
- package/src/chrome/collab-qrcode.ts +0 -99
package/src/tools/lsp.ts
CHANGED
|
@@ -12,13 +12,12 @@ import type { NativeToolHead, NativeToolView, RenderResultOptions, ToolRenderer,
|
|
|
12
12
|
import type { Component } from "../tui";
|
|
13
13
|
import { Text } from "../components/text";
|
|
14
14
|
import { getLanguageFromPath } from "../lang-from-path";
|
|
15
|
-
import { highlightCode as highlightThemeCode, isHighlightLanguage, type Theme } from "../theme/theme";
|
|
15
|
+
import { highlightCode as highlightThemeCode, isHighlightLanguage, type Theme, type ThemeColor } from "../theme/theme";
|
|
16
16
|
import {
|
|
17
17
|
formatCodeFrameLine,
|
|
18
18
|
formatCount,
|
|
19
19
|
formatExpandHint,
|
|
20
20
|
formatMoreItems,
|
|
21
|
-
formatStatusIcon,
|
|
22
21
|
formatStyledPath,
|
|
23
22
|
PREVIEW_LIMITS,
|
|
24
23
|
type ParsedDiagnostic,
|
|
@@ -29,15 +28,15 @@ import {
|
|
|
29
28
|
TRUNCATE_LENGTHS,
|
|
30
29
|
truncateToWidth,
|
|
31
30
|
} from "../render/render-utils";
|
|
32
|
-
import { renderStatusLine } from "../render";
|
|
33
|
-
import {
|
|
31
|
+
import { renderStatusLine, renderTreeList } from "../render";
|
|
32
|
+
import type { StatusLineOptions } from "../render/status-line";
|
|
33
|
+
import { plainToolCard } from "../render/tool-card";
|
|
34
34
|
import { wrapGuidedLine, wrapPrefixedLine } from "../render/hanging-wrap";
|
|
35
|
-
import { visibleWidth } from "../utils";
|
|
36
35
|
import { ansi, code, col, compact, keyed, md, node, row, span, text } from "../native/describe";
|
|
37
36
|
import type { NativeNode } from "../native/node";
|
|
38
37
|
import { OwnerMemo } from "../native/memo";
|
|
39
38
|
import { plainText } from "../native/spans";
|
|
40
|
-
import { numberedCode, walkGroupedOutput } from "./grouped-file-output";
|
|
39
|
+
import { type NumberedLine, numberedCode, renderCodeFrameRun, walkGroupedOutput } from "./grouped-file-output";
|
|
41
40
|
import { diagnosticGlyph, displayPath, fileHref, fileRow, inlineErrorView } from "./native-view";
|
|
42
41
|
import { activeThemeSymbol } from "../theme/active-symbols";
|
|
43
42
|
|
|
@@ -104,63 +103,49 @@ export enum FileFormatResult {
|
|
|
104
103
|
// Call Rendering
|
|
105
104
|
// =============================================================================
|
|
106
105
|
|
|
107
|
-
/**
|
|
108
|
-
* Render the LSP tool call in the TUI.
|
|
109
|
-
* Shows: "lsp <operation> <file/filecount>"
|
|
110
|
-
*/
|
|
111
106
|
function sanitizeInlineText(value: string): string {
|
|
112
107
|
return replaceTabs(value).replaceAll(/\r?\n/g, " ");
|
|
113
108
|
}
|
|
114
109
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
110
|
+
/**
|
|
111
|
+
* The request half of the LSP status line: `action target` as the description
|
|
112
|
+
* (`references src/a.ts:42 (validateToken)`) and the call facts as meta.
|
|
113
|
+
* `fallbackAction` names the action when the request is unknown.
|
|
114
|
+
*/
|
|
115
|
+
function lspRequestStatus(
|
|
116
|
+
args: Partial<LspParams> | undefined,
|
|
117
|
+
fallbackAction = "request",
|
|
118
|
+
): { description: string; meta: string[] } {
|
|
119
|
+
const actionLabel = (args?.action ?? fallbackAction).replace(/_/g, " ");
|
|
120
|
+
const queryPreview = args?.query ? truncateToWidth(args.query, TRUNCATE_LENGTHS.SHORT) : undefined;
|
|
121
|
+
const symbolPreview = args?.symbol
|
|
119
122
|
? truncateToWidth(sanitizeInlineText(args.symbol), TRUNCATE_LENGTHS.SHORT)
|
|
120
123
|
: undefined;
|
|
121
124
|
|
|
122
125
|
let target: string | undefined;
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if (args.file) {
|
|
126
|
+
if (args?.file) {
|
|
126
127
|
target = shortenPath(args.file);
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (hasFileTarget && args.line !== undefined) {
|
|
131
|
-
target += `:${args.line}`;
|
|
132
|
-
if (symbolPreview) {
|
|
133
|
-
target += ` (${symbolPreview})`;
|
|
128
|
+
if (args.line !== undefined) {
|
|
129
|
+
target += `:${args.line}`;
|
|
130
|
+
if (symbolPreview) target += ` (${symbolPreview})`;
|
|
134
131
|
}
|
|
135
|
-
} else if (
|
|
132
|
+
} else if (args?.line !== undefined) {
|
|
136
133
|
target = `line ${args.line}`;
|
|
137
|
-
if (symbolPreview) {
|
|
138
|
-
target += ` (${symbolPreview})`;
|
|
139
|
-
}
|
|
134
|
+
if (symbolPreview) target += ` (${symbolPreview})`;
|
|
140
135
|
}
|
|
141
136
|
|
|
142
137
|
const meta: string[] = [];
|
|
143
138
|
if (queryPreview && target) meta.push(`query:${queryPreview}`);
|
|
144
|
-
if (args
|
|
145
|
-
if (args
|
|
146
|
-
|
|
147
|
-
const descriptionParts = [actionLabel];
|
|
148
|
-
if (target) {
|
|
149
|
-
descriptionParts.push(target);
|
|
150
|
-
} else if (queryPreview) {
|
|
151
|
-
descriptionParts.push(queryPreview);
|
|
152
|
-
}
|
|
139
|
+
if (args?.new_name) meta.push(`new:${args.new_name}`);
|
|
140
|
+
if (args?.apply !== undefined) meta.push(`apply:${args.apply ? "true" : "false"}`);
|
|
153
141
|
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
title: "LSP",
|
|
158
|
-
description: descriptionParts.join(" "),
|
|
159
|
-
meta,
|
|
160
|
-
},
|
|
161
|
-
theme,
|
|
162
|
-
);
|
|
142
|
+
const subject = target ?? queryPreview;
|
|
143
|
+
return { description: subject ? `${actionLabel} ${subject}` : actionLabel, meta };
|
|
144
|
+
}
|
|
163
145
|
|
|
146
|
+
/** Render the LSP tool call: `LSP: <action> <file:line (symbol)>`. */
|
|
147
|
+
export function renderCall(args: LspParams, _options: RenderResultOptions, theme: Theme): Text {
|
|
148
|
+
const text = renderStatusLine({ icon: "pending", title: "LSP", ...lspRequestStatus(args) }, theme);
|
|
164
149
|
return new Text(text, 0, 0);
|
|
165
150
|
}
|
|
166
151
|
|
|
@@ -170,6 +155,16 @@ export function renderCall(args: LspParams, _options: RenderResultOptions, theme
|
|
|
170
155
|
|
|
171
156
|
/** A diagnostics status line for a file no server reported on in time: unverified, never "No issues". */
|
|
172
157
|
const UNREPORTED_LINE_RE = /\bno diagnostics report yet\b/;
|
|
158
|
+
/** Files shown while a references result is collapsed. */
|
|
159
|
+
const COLLAPSED_REFERENCE_FILES = 3;
|
|
160
|
+
/** Locations shown per file while a references result is collapsed. */
|
|
161
|
+
const COLLAPSED_REFERENCE_LOCATIONS = 2;
|
|
162
|
+
/** Diagnostics shown while collapsed. */
|
|
163
|
+
const COLLAPSED_DIAGNOSTICS = 3;
|
|
164
|
+
/** Top-level symbols shown while collapsed. */
|
|
165
|
+
const COLLAPSED_SYMBOLS = 3;
|
|
166
|
+
/** Output lines shown while a generic response is collapsed. */
|
|
167
|
+
const COLLAPSED_GENERIC_LINES = 4;
|
|
173
168
|
|
|
174
169
|
/**
|
|
175
170
|
* Whether a line is one of the LSP tool's per-file status rows (`<glyph> <path>: …`).
|
|
@@ -191,9 +186,50 @@ function hasStatusRow(action: string | undefined, lines: readonly string[], glyp
|
|
|
191
186
|
return lines.some(line => isStatusRow(line, glyph));
|
|
192
187
|
}
|
|
193
188
|
|
|
189
|
+
/** Body rows for one expansion state; `hidden` says the rows hold something back. */
|
|
190
|
+
interface LspBodyRows {
|
|
191
|
+
rows: string[];
|
|
192
|
+
hidden: boolean;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** A parsed LSP response: the header outcome and counts, and the body rows per expansion state. */
|
|
196
|
+
interface LspResultView {
|
|
197
|
+
/** The action the response answers (`references`, `type definition`); names the header when the request is unknown. */
|
|
198
|
+
action: string;
|
|
199
|
+
/** The header's status; `success` shows the LSP icon. */
|
|
200
|
+
icon: "success" | "warning" | "error";
|
|
201
|
+
/** Counts appended to the header after the request facts. */
|
|
202
|
+
meta: string[];
|
|
203
|
+
/** Rows wrap while collapsed too (hover code) instead of clipping to one row each. */
|
|
204
|
+
wrapCollapsed?: boolean;
|
|
205
|
+
rows(expanded: boolean): LspBodyRows;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** A view's body laid out for one width, and whether the header advertises Ctrl+O. */
|
|
209
|
+
interface LspBodyLayout {
|
|
210
|
+
width: number;
|
|
211
|
+
hinted: boolean;
|
|
212
|
+
rows: string[];
|
|
213
|
+
}
|
|
214
|
+
|
|
194
215
|
/**
|
|
195
|
-
*
|
|
196
|
-
*
|
|
216
|
+
* Expanded rows hang under their tree connector or guide rails so Ctrl+O reveals
|
|
217
|
+
* full text; collapsed rows clip to one row each, and a collapsed view that hides
|
|
218
|
+
* rows or clips one gets the expand hint.
|
|
219
|
+
*/
|
|
220
|
+
function layoutBody(view: LspResultView, expanded: boolean, width: number, theme: Theme): LspBodyLayout {
|
|
221
|
+
const { rows, hidden } = view.rows(expanded);
|
|
222
|
+
if (expanded || view.wrapCollapsed) {
|
|
223
|
+
return { width, hinted: !expanded && hidden, rows: rows.flatMap(row => wrapGuidedLine(row, width, theme)) };
|
|
224
|
+
}
|
|
225
|
+
const clipped = rows.map(row => truncateToWidth(row, width));
|
|
226
|
+
return { width, hinted: hidden || clipped.some((row, index) => row !== rows[index]), rows: clipped };
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Render an LSP result flush: one status line carrying the request and the
|
|
231
|
+
* result counts, over the result rows. Detects locations, hover, diagnostics,
|
|
232
|
+
* references and symbols; anything else is listed line by line.
|
|
197
233
|
*/
|
|
198
234
|
export function renderResult(
|
|
199
235
|
result: { content: Array<{ type: string; text?: string }>; details?: LspToolDetails; isError?: boolean },
|
|
@@ -201,212 +237,155 @@ export function renderResult(
|
|
|
201
237
|
theme: Theme,
|
|
202
238
|
args?: LspParams,
|
|
203
239
|
): Component {
|
|
240
|
+
const request = args ?? result.details?.request;
|
|
204
241
|
const content = result.content?.[0];
|
|
205
|
-
|
|
206
|
-
const icon = formatStatusIcon("warning", theme, options.spinnerFrame);
|
|
207
|
-
const header = `${icon} LSP`;
|
|
208
|
-
return new Text([header, theme.fg("dim", "No result")].join("\n"), 0, 0);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
const text = content.text;
|
|
212
|
-
const lines = text.split("\n");
|
|
213
|
-
|
|
214
|
-
// Static type detection (result content doesn't change between renders). Locations are
|
|
215
|
-
// anchored at the response's first line, so they win over checks a source snippet could trip.
|
|
216
|
-
const locations = parseLspLocations(lines);
|
|
217
|
-
const codeBlockMatch = locations ? null : text.match(/```(\w*)\n([\s\S]*?)```/);
|
|
218
|
-
const errorMatch = text.match(/(\d+)\s+error\(s\)/);
|
|
219
|
-
const warningMatch = text.match(/(\d+)\s+warning\(s\)/);
|
|
220
|
-
const refMatch = text.match(/(\d+)\s+reference\(s\)/);
|
|
221
|
-
const symbolsMatch = text.match(/Symbols in (.+):/);
|
|
222
|
-
const unreportedCount = lines.filter(line => UNREPORTED_LINE_RE.test(line)).length;
|
|
242
|
+
const text = content?.type === "text" ? (content.text ?? "") : "";
|
|
223
243
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
244
|
+
if (result.isError) {
|
|
245
|
+
const { description, meta } = lspRequestStatus(request, result.details?.action);
|
|
246
|
+
const header = renderStatusLine({ icon: "error", title: "LSP", description, meta }, theme);
|
|
247
|
+
const messageLines = (text.trim() || "LSP request failed").split("\n").filter(line => line.trim().length > 0);
|
|
248
|
+
// The message hangs under the title, like a Grep or AST Grep error's, and wraps in full.
|
|
249
|
+
return plainToolCard(theme, ({ contentWidth }) => ({
|
|
250
|
+
header,
|
|
251
|
+
phase: "error",
|
|
252
|
+
body: messageLines.flatMap(line =>
|
|
253
|
+
wrapPrefixedLine(" ", " ", theme.fg("error", replaceTabs(line)), contentWidth),
|
|
254
|
+
),
|
|
255
|
+
applyBg: false,
|
|
256
|
+
}));
|
|
234
257
|
}
|
|
235
|
-
if (
|
|
236
|
-
|
|
258
|
+
if (!text) {
|
|
259
|
+
const { description, meta } = lspRequestStatus(request, result.details?.action);
|
|
260
|
+
const header = renderStatusLine(
|
|
261
|
+
{ icon: "warning", title: "LSP", description, meta: [...meta, "No result"] },
|
|
262
|
+
theme,
|
|
263
|
+
);
|
|
264
|
+
return plainToolCard(theme, () => ({ header, phase: "warning", applyBg: false }));
|
|
237
265
|
}
|
|
238
|
-
if (request?.query) requestLines.push(theme.fg("dim", `query: ${request.query}`));
|
|
239
|
-
if (request?.new_name) requestLines.push(theme.fg("dim", `new name: ${request.new_name}`));
|
|
240
|
-
if (request?.apply !== undefined) requestLines.push(theme.fg("dim", `apply: ${request.apply ? "true" : "false"}`));
|
|
241
|
-
|
|
242
|
-
// The body depends only on the (immutable) text, theme and `expanded`; parse
|
|
243
|
-
// and render it once per expanded state instead of on every spinner frame.
|
|
244
|
-
const bodies: Array<LspResultBody | undefined> = [undefined, undefined];
|
|
245
|
-
const renderBody = (expanded: boolean): LspResultBody => {
|
|
246
|
-
if (locations) {
|
|
247
|
-
return {
|
|
248
|
-
label: "Locations",
|
|
249
|
-
state: locations.count > 0 ? "success" : "warning",
|
|
250
|
-
bodyLines: renderLocations(locations, expanded, theme),
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
if (codeBlockMatch) {
|
|
254
|
-
return {
|
|
255
|
-
label: "Hover",
|
|
256
|
-
state: "success",
|
|
257
|
-
bodyLines: renderHover(codeBlockMatch, text, lines, expanded, theme),
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
if (errorMatch || warningMatch || hasStatusError || unreportedCount > 0) {
|
|
261
|
-
const errorCount = errorMatch ? Number.parseInt(errorMatch[1], 10) : 0;
|
|
262
|
-
const warnCount = warningMatch ? Number.parseInt(warningMatch[1], 10) : 0;
|
|
263
|
-
return {
|
|
264
|
-
label: "Diagnostics",
|
|
265
|
-
state: errorCount > 0 ? "error" : warnCount > 0 || unreportedCount > 0 ? "warning" : "success",
|
|
266
|
-
bodyLines: renderDiagnostics(errorMatch, warningMatch, lines, expanded, theme),
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
if (refMatch) {
|
|
270
|
-
return {
|
|
271
|
-
label: "References",
|
|
272
|
-
state: "success",
|
|
273
|
-
bodyLines: renderReferences(refMatch, lines, expanded, theme),
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
if (symbolsMatch) {
|
|
277
|
-
return { label: "Symbols", state: "success", bodyLines: renderSymbols(symbolsMatch, lines, expanded, theme) };
|
|
278
|
-
}
|
|
279
|
-
if (result.details?.action === "diagnostics" && text === "OK") {
|
|
280
|
-
return {
|
|
281
|
-
label: "Diagnostics",
|
|
282
|
-
state: "success",
|
|
283
|
-
bodyLines: [`${theme.styledSymbol("tool.lsp", "accent")} ${theme.fg("dim", "OK")}`],
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
return { label: "Response", state: "success", bodyLines: renderGeneric(text, lines, action, expanded, theme) };
|
|
287
|
-
};
|
|
288
266
|
|
|
289
|
-
|
|
267
|
+
const view = parseLspResult(text, request, result.details?.action, theme);
|
|
268
|
+
const { description, meta } = lspRequestStatus(request, result.details?.action ?? view.action);
|
|
269
|
+
const headerMeta = [...meta, ...view.meta];
|
|
270
|
+
// The body depends only on the (immutable) text, theme, width and `expanded`;
|
|
271
|
+
// lay it out once per expanded state instead of on every spinner frame.
|
|
272
|
+
const layouts: Array<LspBodyLayout | undefined> = [undefined, undefined];
|
|
273
|
+
return plainToolCard(theme, ({ contentWidth }) => {
|
|
290
274
|
// Read mutable state at render time
|
|
291
275
|
const { expanded, isPartial, spinnerFrame } = options;
|
|
292
276
|
const slot = expanded ? 1 : 0;
|
|
293
|
-
let
|
|
294
|
-
if (!
|
|
295
|
-
|
|
296
|
-
|
|
277
|
+
let layout = layouts[slot];
|
|
278
|
+
if (!layout || layout.width !== contentWidth) {
|
|
279
|
+
layout = layoutBody(view, expanded, contentWidth, theme);
|
|
280
|
+
layouts[slot] = layout;
|
|
297
281
|
}
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
: formatStatusIcon(isPartial ? "running" : "error", theme, spinnerFrame);
|
|
305
|
-
const header = `${icon} LSP ${actionLabel}`;
|
|
306
|
-
|
|
307
|
-
// Hover code hangs under its rail; expanded rows hang under their tree
|
|
308
|
-
// connector or guide rails so Ctrl+O reveals full text instead of clipping.
|
|
309
|
-
// Collapsed source lines stop at the card's edge, one row each under their rail.
|
|
310
|
-
const rail = ` ${theme.fg("mdCodeBlockBorder", theme.boxRound.vertical)} `;
|
|
311
|
-
const contentLines = codeBlockMatch
|
|
312
|
-
? bodyLines.flatMap(line =>
|
|
313
|
-
line.startsWith(rail) ? wrapPrefixedLine(rail, rail, line.slice(rail.length), contentWidth) : [line],
|
|
314
|
-
)
|
|
315
|
-
: expanded
|
|
316
|
-
? bodyLines.flatMap(line => wrapGuidedLine(line, contentWidth, theme))
|
|
317
|
-
: locations
|
|
318
|
-
? clipCollapsedLocations(bodyLines, contentWidth, locations, theme)
|
|
319
|
-
: bodyLines;
|
|
282
|
+
const icon: Pick<StatusLineOptions, "icon" | "iconOverride" | "spinnerFrame"> = isPartial
|
|
283
|
+
? { icon: "running", spinnerFrame }
|
|
284
|
+
: view.icon === "success"
|
|
285
|
+
? { iconOverride: theme.styledSymbol("tool.lsp", "accent") }
|
|
286
|
+
: { icon: view.icon };
|
|
287
|
+
const header = renderStatusLine({ ...icon, title: "LSP", description, meta: headerMeta }, theme);
|
|
320
288
|
return {
|
|
321
|
-
header,
|
|
322
|
-
phase: isPartial ? "partial" :
|
|
323
|
-
|
|
324
|
-
...(requestLines.length > 0 ? [{ content: requestLines }] : []),
|
|
325
|
-
{ label: theme.fg("toolTitle", "Response"), content: contentLines },
|
|
326
|
-
],
|
|
289
|
+
header: layout.hinted ? `${header}${formatExpandHint(theme)}` : header,
|
|
290
|
+
phase: isPartial ? "partial" : view.icon,
|
|
291
|
+
body: layout.rows.length > 0 ? layout.rows : undefined,
|
|
327
292
|
applyBg: false,
|
|
328
293
|
};
|
|
329
294
|
});
|
|
330
295
|
}
|
|
331
296
|
|
|
297
|
+
/** Detect the response kind and build its view. */
|
|
298
|
+
function parseLspResult(
|
|
299
|
+
text: string,
|
|
300
|
+
request: Partial<LspParams> | undefined,
|
|
301
|
+
detailsAction: string | undefined,
|
|
302
|
+
theme: Theme,
|
|
303
|
+
): LspResultView {
|
|
304
|
+
const lines = text.split("\n");
|
|
305
|
+
const action = request?.action ?? detailsAction;
|
|
306
|
+
// Locations and references are anchored at the response's first line, so they win over
|
|
307
|
+
// hover and diagnostics checks that their source context could trip.
|
|
308
|
+
const locations = parseLspLocations(lines);
|
|
309
|
+
if (locations?.noun === "reference") return referencesView(locations, theme);
|
|
310
|
+
if (locations) return locationsView(locations, theme);
|
|
311
|
+
|
|
312
|
+
// A diagnostics request answers with diagnostics whatever its rows hold: `OK`, a partial
|
|
313
|
+
// server failure, a summary. Without a known action, the rows themselves decide.
|
|
314
|
+
if (action === "diagnostics") return diagnosticsView(lines, theme);
|
|
315
|
+
|
|
316
|
+
const codeBlockMatch = text.match(/```(\w*)\n([\s\S]*?)```/);
|
|
317
|
+
if (codeBlockMatch) return hoverView(codeBlockMatch, text, theme);
|
|
318
|
+
|
|
319
|
+
const summarized = /\d+\s+(?:error|warning)\(s\)/.test(text);
|
|
320
|
+
const unreported = lines.some(line => UNREPORTED_LINE_RE.test(line));
|
|
321
|
+
if (summarized || hasStatusRow(action, lines, theme.status.error) || unreported) {
|
|
322
|
+
return diagnosticsView(lines, theme);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const symbolsMatch = text.match(/Symbols in (.+):/);
|
|
326
|
+
if (symbolsMatch) return symbolsView(symbolsMatch[1], request?.file === undefined, lines, theme);
|
|
327
|
+
|
|
328
|
+
return genericView(text, lines, action, theme);
|
|
329
|
+
}
|
|
330
|
+
|
|
332
331
|
// =============================================================================
|
|
333
332
|
// Hover Rendering
|
|
334
333
|
// =============================================================================
|
|
335
334
|
|
|
336
|
-
/**
|
|
337
|
-
|
|
338
|
-
*/
|
|
339
|
-
function renderHover(
|
|
340
|
-
codeBlockMatch: RegExpMatchArray,
|
|
341
|
-
fullText: string,
|
|
342
|
-
_lines: string[],
|
|
343
|
-
expanded: boolean,
|
|
344
|
-
theme: Theme,
|
|
345
|
-
): string[] {
|
|
335
|
+
/** Hover: the highlighted signature between any documentation around it; collapsed, its first line. */
|
|
336
|
+
function hoverView(codeBlockMatch: RegExpMatchArray, fullText: string, theme: Theme): LspResultView {
|
|
346
337
|
const lang = codeBlockMatch[1] || "";
|
|
347
|
-
const code = codeBlockMatch[2].trim();
|
|
348
338
|
const codeStart = codeBlockMatch.index ?? 0;
|
|
349
|
-
const beforeCode = fullText.slice(0, codeStart).
|
|
350
|
-
const afterCode = fullText.slice(
|
|
351
|
-
|
|
352
|
-
const
|
|
353
|
-
const
|
|
354
|
-
const
|
|
355
|
-
|
|
356
|
-
if (expanded) {
|
|
357
|
-
const h = theme.boxRound.horizontal;
|
|
358
|
-
const v = theme.boxRound.vertical;
|
|
359
|
-
const top = `${theme.boxRound.topLeft}${h.repeat(3)}`;
|
|
360
|
-
const bottom = `${theme.boxRound.bottomLeft}${h.repeat(3)}`;
|
|
361
|
-
let output = `${icon}${langLabel}`;
|
|
362
|
-
if (beforeCode) {
|
|
363
|
-
for (const line of beforeCode.split("\n")) {
|
|
364
|
-
output += `\n ${theme.fg("muted", line)}`;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
output += `\n ${theme.fg("mdCodeBlockBorder", top)}`;
|
|
368
|
-
for (const line of codeLines) {
|
|
369
|
-
output += `\n ${theme.fg("mdCodeBlockBorder", v)} ${line}`;
|
|
370
|
-
}
|
|
371
|
-
output += `\n ${theme.fg("mdCodeBlockBorder", bottom)}`;
|
|
372
|
-
if (afterCode) {
|
|
373
|
-
output += `\n ${theme.fg("muted", afterCode)}`;
|
|
374
|
-
}
|
|
375
|
-
return output.split("\n");
|
|
376
|
-
}
|
|
339
|
+
const beforeCode = fullText.slice(0, codeStart).trim();
|
|
340
|
+
const afterCode = fullText.slice(codeStart + codeBlockMatch[0].length).trim();
|
|
341
|
+
const codeLines = highlightThemeCode(codeBlockMatch[2].trim(), lang, theme);
|
|
342
|
+
const docLines = (doc: string) => (doc ? doc.split("\n").map(line => theme.fg("muted", replaceTabs(line))) : []);
|
|
343
|
+
const full = [...docLines(beforeCode), ...codeLines, ...docLines(afterCode)];
|
|
344
|
+
const first = codeLines[0] ?? full[0] ?? "";
|
|
345
|
+
const hiddenLines = full.length - 1;
|
|
377
346
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
347
|
+
return {
|
|
348
|
+
action: "hover",
|
|
349
|
+
icon: "success",
|
|
350
|
+
meta: [],
|
|
351
|
+
wrapCollapsed: true,
|
|
352
|
+
rows(expanded) {
|
|
353
|
+
if (expanded || hiddenLines <= 0) return { rows: full, hidden: false };
|
|
354
|
+
return { rows: [first, theme.fg("muted", formatMoreItems(hiddenLines, "line"))], hidden: true };
|
|
355
|
+
},
|
|
356
|
+
};
|
|
357
|
+
}
|
|
382
358
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
output += `\n ${theme.fg("dim", theme.tree.branch)} ${theme.fg("muted", preview)}`;
|
|
387
|
-
}
|
|
388
|
-
const h = theme.boxRound.horizontal;
|
|
389
|
-
const v = theme.boxRound.vertical;
|
|
390
|
-
const bottom = `${theme.boxRound.bottomLeft}${h.repeat(3)}`;
|
|
391
|
-
output += `\n ${theme.fg("mdCodeBlockBorder", v)} ${firstCodeLine}`;
|
|
359
|
+
// =============================================================================
|
|
360
|
+
// Diagnostics Rendering
|
|
361
|
+
// =============================================================================
|
|
392
362
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
363
|
+
/** A status or unparsed line of a diagnostics response, shown verbatim in `color`. */
|
|
364
|
+
interface RawDiagnostic {
|
|
365
|
+
raw: string;
|
|
366
|
+
color: ThemeColor;
|
|
367
|
+
}
|
|
396
368
|
|
|
397
|
-
|
|
398
|
-
const docPreview = truncateToWidth(afterCode, TRUNCATE_LENGTHS.TITLE);
|
|
399
|
-
output += `\n ${theme.fg("dim", theme.tree.last)} ${theme.fg("muted", docPreview)}`;
|
|
400
|
-
} else {
|
|
401
|
-
output += `\n ${theme.fg("mdCodeBlockBorder", bottom)}`;
|
|
402
|
-
}
|
|
369
|
+
type DiagnosticItem = ParsedDiagnostic | RawDiagnostic;
|
|
403
370
|
|
|
404
|
-
|
|
371
|
+
function formatDiagnosticMessage(diagnostic: ParsedDiagnostic): string {
|
|
372
|
+
const source = diagnostic.source ? `[${diagnostic.source}] ` : "";
|
|
373
|
+
const code = diagnostic.code ? ` (${diagnostic.code})` : "";
|
|
374
|
+
return `${source}${diagnostic.message}${code}`;
|
|
405
375
|
}
|
|
406
376
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
377
|
+
function severityToColor(severity: ParsedDiagnostic["severity"]): "error" | "warning" | "accent" | "dim" {
|
|
378
|
+
switch (severity) {
|
|
379
|
+
case "error":
|
|
380
|
+
return "error";
|
|
381
|
+
case "warning":
|
|
382
|
+
return "warning";
|
|
383
|
+
case "info":
|
|
384
|
+
return "accent";
|
|
385
|
+
default:
|
|
386
|
+
return "dim";
|
|
387
|
+
}
|
|
388
|
+
}
|
|
410
389
|
|
|
411
390
|
/** A diagnostic's location: the muted file-type icon, the styled path and the muted `:line:col`. */
|
|
412
391
|
function formatDiagnosticLocation(file: string, line: number, col: number, theme: Theme): string {
|
|
@@ -421,182 +400,76 @@ function formatSeverityTag(severity: ParsedDiagnostic["severity"], theme: Theme)
|
|
|
421
400
|
}
|
|
422
401
|
|
|
423
402
|
/**
|
|
424
|
-
*
|
|
403
|
+
* Diagnostics: the counts in the header, then one branch per row. Server failures
|
|
404
|
+
* and unverified files lead, since a reader must not miss them among diagnostics
|
|
405
|
+
* (`file:line:col [severity] message`); partial-failure warnings and unparsed
|
|
406
|
+
* lines follow. Expanded, a diagnostic's message moves to its own row beneath
|
|
407
|
+
* the location.
|
|
425
408
|
*/
|
|
426
|
-
function
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
): string[] {
|
|
433
|
-
const errorCount = errorMatch ? Number.parseInt(errorMatch[1], 10) : 0;
|
|
434
|
-
const warnCount = warningMatch ? Number.parseInt(warningMatch[1], 10) : 0;
|
|
435
|
-
const unreportedLines = lines.filter(line => UNREPORTED_LINE_RE.test(line));
|
|
436
|
-
|
|
437
|
-
const icon =
|
|
438
|
-
errorCount > 0
|
|
439
|
-
? theme.styledSymbol("status.error", "error")
|
|
440
|
-
: warnCount > 0 || unreportedLines.length > 0
|
|
441
|
-
? theme.styledSymbol("status.warning", "warning")
|
|
442
|
-
: theme.styledSymbol("tool.lsp", "accent");
|
|
409
|
+
function diagnosticsView(lines: string[], theme: Theme): LspResultView {
|
|
410
|
+
const parsed = parseLspDiagnostics(lines);
|
|
411
|
+
// Counted from the rows, not the tool's summary lines: a multi-file response carries one
|
|
412
|
+
// summary per file, and the native view counts the same rows.
|
|
413
|
+
const counts: Record<ParsedDiagnostic["severity"], number> = { error: 0, warning: 0, info: 0, hint: 0 };
|
|
414
|
+
for (const diagnostic of parsed.diagnostics) counts[diagnostic.severity]++;
|
|
443
415
|
|
|
444
416
|
const meta: string[] = [];
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
if (unreportedLines.length > 0) meta.push(formatCount("unverified file", unreportedLines.length));
|
|
448
|
-
if (meta.length === 0) meta.push("No issues");
|
|
449
|
-
|
|
450
|
-
const diagLines = lines.filter(l => isStatusRow(l, theme.status.error) || /:\d+:\d+/.test(l));
|
|
451
|
-
const parsedDiagnostics = diagLines
|
|
452
|
-
.map(line => parseDiagnosticMessage(line.trim()))
|
|
453
|
-
.filter((diag): diag is ParsedDiagnostic => diag !== null);
|
|
454
|
-
const fallbackDiagnostics: RawDiagnostic[] = diagLines.map(line => ({
|
|
455
|
-
raw: sanitizeDiagnosticDisplayText(line.trim()),
|
|
456
|
-
}));
|
|
457
|
-
// Unverified files lead: they are the rows a reader must not miss among diagnostics.
|
|
458
|
-
const items: DiagnosticItem[] = [
|
|
459
|
-
...unreportedLines.map(line => ({ raw: sanitizeDiagnosticDisplayText(line.trim()) })),
|
|
460
|
-
...(parsedDiagnostics.length > 0 ? parsedDiagnostics : fallbackDiagnostics),
|
|
461
|
-
];
|
|
462
|
-
|
|
463
|
-
if (expanded) {
|
|
464
|
-
let output = `${icon} ${theme.fg("dim", meta.join(theme.sep.dot))}`;
|
|
465
|
-
for (let i = 0; i < items.length; i++) {
|
|
466
|
-
const item = items[i];
|
|
467
|
-
const isLast = i === items.length - 1;
|
|
468
|
-
const branch = isLast ? theme.tree.last : theme.tree.branch;
|
|
469
|
-
const detailPrefix = isLast ? " " : `${theme.tree.vertical} `;
|
|
470
|
-
if ("raw" in item) {
|
|
471
|
-
output += `\n ${theme.fg("dim", branch)} ${theme.fg("muted", item.raw)}`;
|
|
472
|
-
continue;
|
|
473
|
-
}
|
|
474
|
-
const location = formatDiagnosticLocation(item.filePath, item.line, item.col, theme);
|
|
475
|
-
output += `\n ${theme.fg("dim", branch)} ${location} ${formatSeverityTag(item.severity, theme)}`;
|
|
476
|
-
const message = formatDiagnosticMessage(item);
|
|
477
|
-
if (message) {
|
|
478
|
-
output += `\n ${theme.fg("dim", detailPrefix)}${theme.fg("muted", message)}`;
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
return output.split("\n");
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
// Collapsed view
|
|
485
|
-
const previewItems = items.slice(0, 3);
|
|
486
|
-
const remaining = items.length - previewItems.length;
|
|
487
|
-
const clipped = previewItems.some(
|
|
488
|
-
item => !("raw" in item) && visibleWidth(formatDiagnosticMessage(item)) > TRUNCATE_LENGTHS.CONTENT,
|
|
489
|
-
);
|
|
490
|
-
const expandHint = formatExpandHint(theme, expanded, remaining > 0 || clipped);
|
|
491
|
-
let output = `${icon} ${theme.fg("dim", meta.join(theme.sep.dot))}${expandHint}`;
|
|
492
|
-
for (let i = 0; i < previewItems.length; i++) {
|
|
493
|
-
const item = previewItems[i];
|
|
494
|
-
const isLast = i === previewItems.length - 1 && remaining <= 0;
|
|
495
|
-
const branch = isLast ? theme.tree.last : theme.tree.branch;
|
|
496
|
-
if ("raw" in item) {
|
|
497
|
-
output += `\n ${theme.fg("dim", branch)} ${theme.fg("muted", item.raw)}`;
|
|
498
|
-
continue;
|
|
499
|
-
}
|
|
500
|
-
const location = formatDiagnosticLocation(item.filePath, item.line, item.col, theme);
|
|
501
|
-
const diagnosticMessage = formatDiagnosticMessage(item);
|
|
502
|
-
const message = diagnosticMessage
|
|
503
|
-
? ` ${theme.fg("muted", truncateToWidth(diagnosticMessage, TRUNCATE_LENGTHS.CONTENT))}`
|
|
504
|
-
: "";
|
|
505
|
-
output += `\n ${theme.fg("dim", branch)} ${location} ${formatSeverityTag(item.severity, theme)}${message}`;
|
|
506
|
-
}
|
|
507
|
-
if (remaining > 0) {
|
|
508
|
-
output += `\n ${theme.fg("dim", theme.tree.last)} ${theme.fg("muted", `… ${remaining} more`)}`;
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
return output.split("\n");
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
// =============================================================================
|
|
515
|
-
// References Rendering
|
|
516
|
-
// =============================================================================
|
|
517
|
-
|
|
518
|
-
/**
|
|
519
|
-
* Render references grouped by file.
|
|
520
|
-
*/
|
|
521
|
-
function renderReferences(refMatch: RegExpMatchArray, lines: string[], expanded: boolean, theme: Theme): string[] {
|
|
522
|
-
const refCount = Number.parseInt(refMatch[1], 10);
|
|
523
|
-
const icon =
|
|
524
|
-
refCount > 0 ? theme.styledSymbol("tool.lsp", "accent") : theme.styledSymbol("status.warning", "warning");
|
|
525
|
-
|
|
526
|
-
const locLines = lines.filter(l => /^\s*\S+:\d+:\d+/.test(l));
|
|
527
|
-
|
|
528
|
-
// Group by file
|
|
529
|
-
const byFile = new Map<string, Array<[string, string]>>();
|
|
530
|
-
for (const loc of locLines) {
|
|
531
|
-
const match = loc.trim().match(/^(.+):(\d+):(\d+)$/);
|
|
532
|
-
if (match) {
|
|
533
|
-
const [, file, line, col] = match;
|
|
534
|
-
if (!byFile.has(file)) byFile.set(file, []);
|
|
535
|
-
byFile.get(file)!.push([line, col]);
|
|
536
|
-
}
|
|
417
|
+
for (const severity of ["error", "warning", "info", "hint"] as const) {
|
|
418
|
+
if (counts[severity] > 0) meta.push(formatCount(severity, counts[severity]));
|
|
537
419
|
}
|
|
420
|
+
if (parsed.failures.length > 0) meta.push(formatCount("server failure", parsed.failures.length));
|
|
421
|
+
if (parsed.unreported.length > 0) meta.push(formatCount("unverified file", parsed.unreported.length));
|
|
538
422
|
|
|
539
|
-
const
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
const locs = byFile.get(file)!;
|
|
550
|
-
const isLastFile = fi === filesToShow.length - 1 && files.length <= maxFiles;
|
|
551
|
-
const fileBranch = isLastFile ? theme.tree.last : theme.tree.branch;
|
|
552
|
-
const fileCont = isLastFile ? " " : `${theme.tree.vertical} `;
|
|
553
|
-
|
|
554
|
-
const fileMeta = `${locs.length} reference${locs.length !== 1 ? "s" : ""}`;
|
|
555
|
-
output += `\n ${theme.fg("dim", fileBranch)} ${formatStyledPath(file, theme)} ${theme.fg("dim", fileMeta)}`;
|
|
556
|
-
|
|
557
|
-
if (maxLocsPerFile > 0) {
|
|
558
|
-
const locsToShow = locs.slice(0, maxLocsPerFile);
|
|
559
|
-
for (let li = 0; li < locsToShow.length; li++) {
|
|
560
|
-
const [line, col] = locsToShow[li];
|
|
561
|
-
const isLastLoc = li === locsToShow.length - 1 && locs.length <= maxLocsPerFile;
|
|
562
|
-
const locBranch = isLastLoc ? theme.tree.last : theme.tree.branch;
|
|
563
|
-
const locCont = isLastLoc ? " " : `${theme.tree.vertical} `;
|
|
564
|
-
output += `\n ${theme.fg("dim", fileCont)}${theme.fg("dim", locBranch)} ${theme.fg(
|
|
565
|
-
"muted",
|
|
566
|
-
`line ${line}, col ${col}`,
|
|
567
|
-
)}`;
|
|
568
|
-
if (expanded) {
|
|
569
|
-
const at = `${theme.fg("muted", "at ")}${formatStyledPath(file, theme)}${theme.fg("muted", `:${line}:${col}`)}`;
|
|
570
|
-
output += `\n ${theme.fg("dim", fileCont)}${theme.fg("dim", locCont)}${at}`;
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
if (locs.length > maxLocsPerFile) {
|
|
574
|
-
output += `\n ${theme.fg("dim", fileCont)}${theme.fg("dim", theme.tree.last)} ${theme.fg(
|
|
575
|
-
"muted",
|
|
576
|
-
`… ${locs.length - maxLocsPerFile} more`,
|
|
577
|
-
)}`;
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
if (files.length > maxFiles) {
|
|
583
|
-
output += `\n ${theme.fg("dim", theme.tree.last)} ${theme.fg(
|
|
584
|
-
"muted",
|
|
585
|
-
formatMoreItems(files.length - maxFiles, "file"),
|
|
586
|
-
)}`;
|
|
587
|
-
}
|
|
423
|
+
const raw = (color: ThemeColor) => (line: string) => ({ raw: sanitizeDiagnosticDisplayText(line), color });
|
|
424
|
+
const items: DiagnosticItem[] = [
|
|
425
|
+
...parsed.failures.map(raw("error")),
|
|
426
|
+
...parsed.unreported.map(raw("warning")),
|
|
427
|
+
...parsed.diagnostics,
|
|
428
|
+
...parsed.warnings.map(raw("warning")),
|
|
429
|
+
...parsed.other.map(raw("muted")),
|
|
430
|
+
];
|
|
431
|
+
// Only a response with nothing to count and nothing to show claims a clean file.
|
|
432
|
+
if (meta.length === 0 && items.length === 0) meta.push("No issues");
|
|
588
433
|
|
|
589
|
-
|
|
434
|
+
return {
|
|
435
|
+
action: "diagnostics",
|
|
436
|
+
// Errors and failed servers are an error state; warnings, unverified files and partial
|
|
437
|
+
// server failures a warning one, like the native view's tone.
|
|
438
|
+
icon:
|
|
439
|
+
counts.error > 0 || parsed.failures.length > 0
|
|
440
|
+
? "error"
|
|
441
|
+
: counts.warning > 0 || parsed.unreported.length > 0 || parsed.warnings.length > 0
|
|
442
|
+
? "warning"
|
|
443
|
+
: "success",
|
|
444
|
+
meta,
|
|
445
|
+
rows(expanded) {
|
|
446
|
+
const rows = renderTreeList(
|
|
447
|
+
{
|
|
448
|
+
items,
|
|
449
|
+
expanded,
|
|
450
|
+
maxCollapsed: COLLAPSED_DIAGNOSTICS,
|
|
451
|
+
itemType: "diagnostic",
|
|
452
|
+
renderItem: item => {
|
|
453
|
+
if ("raw" in item) return theme.fg(item.color, item.raw);
|
|
454
|
+
const location = formatDiagnosticLocation(item.filePath, item.line, item.col, theme);
|
|
455
|
+
const head = `${location} ${formatSeverityTag(item.severity, theme)}`;
|
|
456
|
+
const message = formatDiagnosticMessage(item);
|
|
457
|
+
if (!message) return head;
|
|
458
|
+
return expanded ? [head, theme.fg("muted", message)] : `${head} ${theme.fg("muted", message)}`;
|
|
459
|
+
},
|
|
460
|
+
},
|
|
461
|
+
theme,
|
|
462
|
+
);
|
|
463
|
+
return { rows, hidden: !expanded && items.length > COLLAPSED_DIAGNOSTICS };
|
|
464
|
+
},
|
|
590
465
|
};
|
|
591
|
-
|
|
592
|
-
return (expanded ? renderGrouped(files.length, Number.POSITIVE_INFINITY) : renderGrouped(3, 1)).split("\n");
|
|
593
466
|
}
|
|
594
467
|
|
|
595
468
|
// =============================================================================
|
|
596
|
-
// Locations
|
|
469
|
+
// Locations
|
|
597
470
|
// =============================================================================
|
|
598
471
|
|
|
599
|
-
/** One location of a definition-style response, with its numbered source context. */
|
|
472
|
+
/** One location of a definition-style or references response, with its numbered source context. */
|
|
600
473
|
interface LspLocation {
|
|
601
474
|
file: string;
|
|
602
475
|
line: number;
|
|
@@ -605,15 +478,6 @@ interface LspLocation {
|
|
|
605
478
|
context: { n: number; text: string; mark: boolean }[];
|
|
606
479
|
}
|
|
607
480
|
|
|
608
|
-
/** A definition, type definition or implementation response. */
|
|
609
|
-
interface LspLocations {
|
|
610
|
-
/** `definition`, `type definition` or `implementation`. */
|
|
611
|
-
noun: string;
|
|
612
|
-
count: number;
|
|
613
|
-
locations: LspLocation[];
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
const LOCATIONS_HEADER_RE = /^Found (\d+) (definition|type definition|implementation)\(s\):$/;
|
|
617
481
|
/**
|
|
618
482
|
* ` file:line:col`, the path from column 2 on (it may itself start with whitespace). Context rows are
|
|
619
483
|
* ` N: source`; a row matching both is context of the current location.
|
|
@@ -621,16 +485,10 @@ const LOCATIONS_HEADER_RE = /^Found (\d+) (definition|type definition|implementa
|
|
|
621
485
|
const LOCATION_RE = /^ {2}(.+):(\d+):(\d+)$/;
|
|
622
486
|
const LOCATION_CONTEXT_RE = /^ {4}(\d+): ?(.*)$/;
|
|
623
487
|
|
|
624
|
-
/**
|
|
625
|
-
|
|
626
|
-
* implementations): ` file:line:col` rows, each followed by its
|
|
627
|
-
* ` N: source` context lines.
|
|
628
|
-
*/
|
|
629
|
-
function parseLspLocations(lines: readonly string[]): LspLocations | undefined {
|
|
630
|
-
const header = LOCATIONS_HEADER_RE.exec(lines[0] ?? "");
|
|
631
|
-
if (!header) return undefined;
|
|
488
|
+
/** The ` file:line:col` rows of a locations or references response, each with the ` N: source` lines after it. */
|
|
489
|
+
function parseLocationRows(lines: readonly string[]): LspLocation[] {
|
|
632
490
|
const locations: LspLocation[] = [];
|
|
633
|
-
for (const line of lines
|
|
491
|
+
for (const line of lines) {
|
|
634
492
|
const current = locations.at(-1);
|
|
635
493
|
const context = current ? LOCATION_CONTEXT_RE.exec(line) : null;
|
|
636
494
|
if (current && context) {
|
|
@@ -644,79 +502,190 @@ function parseLspLocations(lines: readonly string[]): LspLocations | undefined {
|
|
|
644
502
|
locations.push({ file, line: Number(lineNumber), col: Number(column), context: [] });
|
|
645
503
|
}
|
|
646
504
|
}
|
|
647
|
-
return
|
|
505
|
+
return locations;
|
|
648
506
|
}
|
|
649
507
|
|
|
508
|
+
/** A definition, type definition, implementation or references response. */
|
|
509
|
+
interface LspLocations {
|
|
510
|
+
/** `definition`, `type definition`, `implementation` or `reference`. */
|
|
511
|
+
noun: string;
|
|
512
|
+
count: number;
|
|
513
|
+
locations: LspLocation[];
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
const LOCATIONS_HEADER_RE = /^Found (\d+) (definition|type definition|implementation|reference)\(s\):$/;
|
|
517
|
+
|
|
650
518
|
/**
|
|
651
|
-
*
|
|
652
|
-
* `file:line:col`
|
|
653
|
-
*
|
|
519
|
+
* Parse a `Found N definition(s):` response (also type definitions,
|
|
520
|
+
* implementations and references): ` file:line:col` rows, each followed by
|
|
521
|
+
* its ` N: source` context lines.
|
|
654
522
|
*/
|
|
655
|
-
function
|
|
656
|
-
const
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
const rows = [
|
|
661
|
-
`${icon} ${theme.fg("dim", formatCount(noun, count))}${formatExpandHint(theme, expanded, hidden > 0)}`,
|
|
662
|
-
];
|
|
523
|
+
function parseLspLocations(lines: readonly string[]): LspLocations | undefined {
|
|
524
|
+
const header = LOCATIONS_HEADER_RE.exec(lines[0] ?? "");
|
|
525
|
+
if (!header) return undefined;
|
|
526
|
+
return { noun: header[2], count: Number(header[1]), locations: parseLocationRows(lines.slice(1)) };
|
|
527
|
+
}
|
|
663
528
|
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
rows.push(` ${theme.fg("dim", branch)} ${file}${position}`);
|
|
671
|
-
|
|
672
|
-
const numberWidth = location.context.reduce((width, line) => Math.max(width, String(line.n).length), 0);
|
|
673
|
-
for (const line of location.context) {
|
|
674
|
-
const frame = formatCodeFrameLine(line.mark ? "*" : "", line.n, replaceTabs(line.text), numberWidth);
|
|
675
|
-
rows.push(` ${theme.fg("dim", rail)}${theme.fg("toolOutput", frame)}`);
|
|
676
|
-
}
|
|
677
|
-
});
|
|
529
|
+
/** One source line in its file's language, or in `fallback` when the highlighter doesn't know the language. */
|
|
530
|
+
function highlightSourceLine(source: string, lang: string | undefined, fallback: ThemeColor, theme: Theme): string {
|
|
531
|
+
const plain = replaceTabs(source);
|
|
532
|
+
if (!isHighlightLanguage(lang)) return theme.fg(fallback, plain);
|
|
533
|
+
return highlightThemeCode(plain, lang, theme)[0] ?? plain;
|
|
534
|
+
}
|
|
678
535
|
|
|
679
|
-
|
|
680
|
-
|
|
536
|
+
// =============================================================================
|
|
537
|
+
// References Rendering
|
|
538
|
+
// =============================================================================
|
|
539
|
+
|
|
540
|
+
/** Reference locations grouped by file, in first-seen order. */
|
|
541
|
+
function groupReferencesByFile(references: readonly LspLocation[]): Map<string, LspLocation[]> {
|
|
542
|
+
const byFile = new Map<string, LspLocation[]>();
|
|
543
|
+
for (const location of references) {
|
|
544
|
+
const locations = byFile.get(location.file);
|
|
545
|
+
if (locations) locations.push(location);
|
|
546
|
+
else byFile.set(location.file, [location]);
|
|
681
547
|
}
|
|
682
|
-
return
|
|
548
|
+
return byFile;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
function formatPosition(location: LspLocation): string {
|
|
552
|
+
return `${location.line}:${location.col}`;
|
|
683
553
|
}
|
|
684
554
|
|
|
685
555
|
/**
|
|
686
|
-
*
|
|
687
|
-
*
|
|
556
|
+
* One reference: its `line:col` right-aligned to `positionWidth` and a rule, then its
|
|
557
|
+
* source line in the file's language. References past the tool's context limit arrive
|
|
558
|
+
* without source and show the position alone.
|
|
688
559
|
*/
|
|
689
|
-
function
|
|
690
|
-
const
|
|
691
|
-
const
|
|
692
|
-
if (!
|
|
693
|
-
|
|
560
|
+
function referenceRow(location: LspLocation, positionWidth: number, lang: string | undefined, theme: Theme): string {
|
|
561
|
+
const position = formatPosition(location).padStart(positionWidth);
|
|
562
|
+
const source = location.context.find(line => line.mark)?.text.trim();
|
|
563
|
+
if (!source) return theme.fg("muted", position);
|
|
564
|
+
return `${theme.fg("muted", `${position}│`)} ${highlightSourceLine(source, lang, "toolOutput", theme)}`;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* References: the counts in the header, then one branch per file (`file (N)`) over its
|
|
569
|
+
* locations, each previewing its source line. All positions share one width, so the
|
|
570
|
+
* rules line up across files and stay put when the view expands.
|
|
571
|
+
*/
|
|
572
|
+
function referencesView(parsed: LspLocations, theme: Theme): LspResultView {
|
|
573
|
+
const refCount = parsed.count;
|
|
574
|
+
const byFile = groupReferencesByFile(parsed.locations);
|
|
575
|
+
const files = Array.from(byFile.keys());
|
|
576
|
+
const meta = [formatCount("reference", refCount)];
|
|
577
|
+
if (files.length > 0) meta.push(formatCount("file", files.length));
|
|
578
|
+
const collapsedHides =
|
|
579
|
+
files.length > COLLAPSED_REFERENCE_FILES ||
|
|
580
|
+
files.slice(0, COLLAPSED_REFERENCE_FILES).some(file => byFile.get(file)!.length > COLLAPSED_REFERENCE_LOCATIONS);
|
|
581
|
+
let positionWidth = 0;
|
|
582
|
+
for (const locations of byFile.values()) {
|
|
583
|
+
for (const location of locations) positionWidth = Math.max(positionWidth, formatPosition(location).length);
|
|
694
584
|
}
|
|
695
|
-
|
|
585
|
+
|
|
586
|
+
return {
|
|
587
|
+
action: "references",
|
|
588
|
+
icon: refCount > 0 ? "success" : "warning",
|
|
589
|
+
meta,
|
|
590
|
+
rows(expanded) {
|
|
591
|
+
const rows = renderTreeList(
|
|
592
|
+
{
|
|
593
|
+
items: files,
|
|
594
|
+
expanded,
|
|
595
|
+
maxCollapsed: COLLAPSED_REFERENCE_FILES,
|
|
596
|
+
itemType: "file",
|
|
597
|
+
renderItem: file => {
|
|
598
|
+
const locations = byFile.get(file)!;
|
|
599
|
+
const lang = getLanguageFromPath(file);
|
|
600
|
+
const header = `${formatStyledPath(replaceTabs(shortenPath(file)), theme)} ${theme.fg("dim", `(${locations.length})`)}`;
|
|
601
|
+
const locationRows = renderTreeList(
|
|
602
|
+
{
|
|
603
|
+
items: locations,
|
|
604
|
+
expanded,
|
|
605
|
+
maxCollapsed: COLLAPSED_REFERENCE_LOCATIONS,
|
|
606
|
+
itemType: "location",
|
|
607
|
+
renderItem: location => referenceRow(location, positionWidth, lang, theme),
|
|
608
|
+
},
|
|
609
|
+
theme,
|
|
610
|
+
);
|
|
611
|
+
return [header, ...locationRows];
|
|
612
|
+
},
|
|
613
|
+
},
|
|
614
|
+
theme,
|
|
615
|
+
);
|
|
616
|
+
return { rows, hidden: !expanded && collapsedHides };
|
|
617
|
+
},
|
|
618
|
+
};
|
|
696
619
|
}
|
|
697
620
|
|
|
698
621
|
// =============================================================================
|
|
699
|
-
//
|
|
622
|
+
// Locations Rendering
|
|
700
623
|
// =============================================================================
|
|
701
624
|
|
|
702
625
|
/**
|
|
703
|
-
*
|
|
626
|
+
* Definitions, type definitions and implementations: the count in the header,
|
|
627
|
+
* then one branch per `file:line:col` over its source context, the location's
|
|
628
|
+
* line marked like a grep match.
|
|
704
629
|
*/
|
|
705
|
-
function
|
|
706
|
-
const
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
630
|
+
function locationsView(parsed: LspLocations, theme: Theme): LspResultView {
|
|
631
|
+
const { noun, count, locations } = parsed;
|
|
632
|
+
return {
|
|
633
|
+
action: noun,
|
|
634
|
+
icon: count > 0 ? "success" : "warning",
|
|
635
|
+
meta: [formatCount(noun, count)],
|
|
636
|
+
rows(expanded) {
|
|
637
|
+
const rows = renderTreeList(
|
|
638
|
+
{
|
|
639
|
+
items: locations,
|
|
640
|
+
expanded,
|
|
641
|
+
maxCollapsed: PREVIEW_LIMITS.LOCATIONS_COLLAPSED,
|
|
642
|
+
itemType: noun,
|
|
643
|
+
renderItem: location => {
|
|
644
|
+
const position = theme.fg("muted", `:${location.line}:${location.col}`);
|
|
645
|
+
const file = formatStyledPath(replaceTabs(shortenPath(location.file)), theme);
|
|
646
|
+
const numberWidth = location.context.reduce(
|
|
647
|
+
(width, line) => Math.max(width, String(line.n).length),
|
|
648
|
+
0,
|
|
649
|
+
);
|
|
650
|
+
const frame = renderCodeFrameRun(
|
|
651
|
+
location.context.map(line => ({
|
|
652
|
+
gutter: formatCodeFrameLine(line.mark ? "*" : "", line.n, "", numberWidth),
|
|
653
|
+
source: line.text,
|
|
654
|
+
})),
|
|
655
|
+
getLanguageFromPath(location.file),
|
|
656
|
+
"toolOutput",
|
|
657
|
+
theme,
|
|
658
|
+
);
|
|
659
|
+
return [`${file}${position}`, ...frame];
|
|
660
|
+
},
|
|
661
|
+
},
|
|
662
|
+
theme,
|
|
663
|
+
);
|
|
664
|
+
return { rows, hidden: !expanded && locations.length > PREVIEW_LIMITS.LOCATIONS_COLLAPSED };
|
|
665
|
+
},
|
|
666
|
+
};
|
|
667
|
+
}
|
|
715
668
|
|
|
716
|
-
|
|
717
|
-
|
|
669
|
+
// =============================================================================
|
|
670
|
+
// Symbols Rendering
|
|
671
|
+
// =============================================================================
|
|
718
672
|
|
|
719
|
-
|
|
673
|
+
interface SymbolInfo {
|
|
674
|
+
name: string;
|
|
675
|
+
line: string;
|
|
676
|
+
indent: number;
|
|
677
|
+
icon: string;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
/**
|
|
681
|
+
* Document symbols: the count in the header (and the file, when the request
|
|
682
|
+
* does not name it), then a tree of symbols. Collapsed, the first top-level
|
|
683
|
+
* symbols; expanded, every symbol with its line beneath it.
|
|
684
|
+
*/
|
|
685
|
+
function symbolsView(fileName: string, showFile: boolean, lines: string[], theme: Theme): LspResultView {
|
|
686
|
+
const symbols: SymbolInfo[] = [];
|
|
687
|
+
for (const line of lines) {
|
|
688
|
+
if (!line.includes("@") || !line.includes("line")) continue;
|
|
720
689
|
const indent = line.match(/^(\s*)/)?.[1].length ?? 0;
|
|
721
690
|
const symMatch = line.trim().match(/^(\S+)\s+(.+?)\s*@\s*line\s*(\d+)/);
|
|
722
691
|
if (symMatch) {
|
|
@@ -736,165 +705,88 @@ function renderSymbols(symbolsMatch: RegExpMatchArray, lines: string[], expanded
|
|
|
736
705
|
isLast[i] = next < 0 || symbols[next].indent !== myIndent;
|
|
737
706
|
pending.push(i);
|
|
738
707
|
}
|
|
739
|
-
const
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
prefix += ancestorIdx !== undefined && isLast[ancestorIdx] ? " " : `${theme.tree.vertical} `;
|
|
748
|
-
}
|
|
749
|
-
prefixes.push(prefix);
|
|
750
|
-
lastAtIndent.set(myIndent, i);
|
|
708
|
+
const prefixes: string[] = [];
|
|
709
|
+
const lastAtIndent = new Map<number, number>();
|
|
710
|
+
for (let i = 0; i < symbols.length; i++) {
|
|
711
|
+
const myIndent = symbols[i].indent;
|
|
712
|
+
let prefix = "";
|
|
713
|
+
for (let level = 2; level <= myIndent; level += 2) {
|
|
714
|
+
const ancestorIdx = lastAtIndent.get(level - 2);
|
|
715
|
+
prefix += ancestorIdx !== undefined && isLast[ancestorIdx] ? " " : `${theme.tree.vertical} `;
|
|
751
716
|
}
|
|
752
|
-
|
|
753
|
-
|
|
717
|
+
prefixes.push(theme.fg("dim", prefix));
|
|
718
|
+
lastAtIndent.set(myIndent, i);
|
|
719
|
+
}
|
|
754
720
|
|
|
755
|
-
const
|
|
721
|
+
const topLevel = symbols.filter(s => s.indent === 0);
|
|
756
722
|
// The glyph keeps the accent; the name and signature read as code in the file's language.
|
|
757
723
|
const lang = getLanguageFromPath(fileName);
|
|
758
|
-
const
|
|
759
|
-
|
|
760
|
-
if (!isHighlightLanguage(lang)) return theme.fg("accent", plain);
|
|
761
|
-
return highlightThemeCode(plain, lang, theme)[0] ?? plain;
|
|
762
|
-
};
|
|
724
|
+
const symbolLabel = (sym: SymbolInfo) =>
|
|
725
|
+
`${theme.fg("accent", sym.icon)} ${highlightSourceLine(sym.name, lang, "accent", theme)}`;
|
|
763
726
|
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
}
|
|
797
|
-
|
|
798
|
-
return output.split("\n");
|
|
727
|
+
const meta = [formatCount("symbol", symbols.length)];
|
|
728
|
+
if (showFile) meta.push(`in ${fileName}`);
|
|
729
|
+
return {
|
|
730
|
+
action: "symbols",
|
|
731
|
+
icon: symbols.length > 0 ? "success" : "warning",
|
|
732
|
+
meta,
|
|
733
|
+
rows(expanded) {
|
|
734
|
+
if (expanded) {
|
|
735
|
+
const rows: string[] = [];
|
|
736
|
+
for (let i = 0; i < symbols.length; i++) {
|
|
737
|
+
const sym = symbols[i];
|
|
738
|
+
const branch = isLast[i] ? theme.tree.last : theme.tree.branch;
|
|
739
|
+
const detail = isLast[i] ? " " : `${theme.tree.vertical} `;
|
|
740
|
+
rows.push(`${prefixes[i]}${theme.fg("dim", branch)} ${symbolLabel(sym)}`);
|
|
741
|
+
rows.push(`${prefixes[i]}${theme.fg("dim", detail)}${theme.fg("muted", `line ${sym.line}`)}`);
|
|
742
|
+
}
|
|
743
|
+
return { rows, hidden: false };
|
|
744
|
+
}
|
|
745
|
+
// The marker counts every hidden symbol, nested ones included, so it adds up to the header's count.
|
|
746
|
+
const shown = topLevel.slice(0, COLLAPSED_SYMBOLS);
|
|
747
|
+
const hidden = symbols.length - shown.length;
|
|
748
|
+
const rows = renderTreeList(
|
|
749
|
+
{
|
|
750
|
+
items: shown,
|
|
751
|
+
trailingSummary: hidden > 0 ? formatMoreItems(hidden, "symbol") : "",
|
|
752
|
+
renderItem: sym => `${symbolLabel(sym)} ${theme.fg("muted", `line ${sym.line}`)}`,
|
|
753
|
+
},
|
|
754
|
+
theme,
|
|
755
|
+
);
|
|
756
|
+
return { rows, hidden: hidden > 0 };
|
|
757
|
+
},
|
|
758
|
+
};
|
|
799
759
|
}
|
|
800
760
|
|
|
801
761
|
// =============================================================================
|
|
802
762
|
// Generic Rendering
|
|
803
763
|
// =============================================================================
|
|
804
764
|
|
|
805
|
-
/**
|
|
806
|
-
|
|
807
|
-
*/
|
|
808
|
-
function renderGeneric(
|
|
809
|
-
text: string,
|
|
810
|
-
lines: string[],
|
|
811
|
-
action: string | undefined,
|
|
812
|
-
expanded: boolean,
|
|
813
|
-
theme: Theme,
|
|
814
|
-
): string[] {
|
|
765
|
+
/** Any other response (rename, code actions, status…): one branch per output line, capped while collapsed. */
|
|
766
|
+
function genericView(text: string, lines: string[], action: string | undefined, theme: Theme): LspResultView {
|
|
815
767
|
const hasError = text.includes("Error:") || hasStatusRow(action, lines, theme.status.error);
|
|
816
768
|
const hasSuccess = hasStatusRow(action, lines, theme.status.success) || text.includes("Applied");
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
expanded,
|
|
839
|
-
lines.length > 1 || visibleWidth(firstLine) > TRUNCATE_LENGTHS.TITLE,
|
|
840
|
-
);
|
|
841
|
-
let output = `${icon} ${theme.fg("dim", truncateToWidth(firstLine, TRUNCATE_LENGTHS.TITLE))}${expandHint}`;
|
|
842
|
-
|
|
843
|
-
if (lines.length > 1) {
|
|
844
|
-
const previewLines = lines.slice(1, 4);
|
|
845
|
-
for (let i = 0; i < previewLines.length; i++) {
|
|
846
|
-
const isLast = i === previewLines.length - 1 && lines.length <= 4;
|
|
847
|
-
const branch = isLast ? theme.tree.last : theme.tree.branch;
|
|
848
|
-
output += `\n ${theme.fg("dim", branch)} ${theme.fg(
|
|
849
|
-
"dim",
|
|
850
|
-
truncateToWidth(previewLines[i].trim(), TRUNCATE_LENGTHS.CONTENT),
|
|
851
|
-
)}`;
|
|
852
|
-
}
|
|
853
|
-
if (lines.length > 4) {
|
|
854
|
-
output += `\n ${theme.fg("dim", theme.tree.last)} ${theme.fg(
|
|
855
|
-
"muted",
|
|
856
|
-
formatMoreItems(lines.length - 4, "line"),
|
|
857
|
-
)}`;
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
return output.split("\n");
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
// =============================================================================
|
|
865
|
-
// Parsing Helpers
|
|
866
|
-
// =============================================================================
|
|
867
|
-
|
|
868
|
-
interface RawDiagnostic {
|
|
869
|
-
raw: string;
|
|
870
|
-
}
|
|
871
|
-
|
|
872
|
-
/** A rendered LSP result body for one `expanded` state. */
|
|
873
|
-
interface LspResultBody {
|
|
874
|
-
label: string;
|
|
875
|
-
state: "success" | "warning" | "error";
|
|
876
|
-
bodyLines: string[];
|
|
877
|
-
}
|
|
878
|
-
|
|
879
|
-
type DiagnosticItem = ParsedDiagnostic | RawDiagnostic;
|
|
880
|
-
|
|
881
|
-
function formatDiagnosticMessage(diagnostic: ParsedDiagnostic): string {
|
|
882
|
-
const source = diagnostic.source ? `[${diagnostic.source}] ` : "";
|
|
883
|
-
const code = diagnostic.code ? ` (${diagnostic.code})` : "";
|
|
884
|
-
return `${source}${diagnostic.message}${code}`;
|
|
885
|
-
}
|
|
886
|
-
|
|
887
|
-
function severityToColor(severity: ParsedDiagnostic["severity"]): "error" | "warning" | "accent" | "dim" {
|
|
888
|
-
switch (severity) {
|
|
889
|
-
case "error":
|
|
890
|
-
return "error";
|
|
891
|
-
case "warning":
|
|
892
|
-
return "warning";
|
|
893
|
-
case "info":
|
|
894
|
-
return "accent";
|
|
895
|
-
default:
|
|
896
|
-
return "dim";
|
|
897
|
-
}
|
|
769
|
+
const outputLines = lines.map(line => theme.fg("toolOutput", replaceTabs(line)));
|
|
770
|
+
return {
|
|
771
|
+
action: "request",
|
|
772
|
+
// The call completed; an error reported inside its output, or an empty
|
|
773
|
+
// answer ("No definition found"), needs attention.
|
|
774
|
+
icon: (hasError && !hasSuccess) || /^no\b.*\bfound\b/i.test(text.trim()) ? "warning" : "success",
|
|
775
|
+
meta: [],
|
|
776
|
+
rows(expanded) {
|
|
777
|
+
const rows = renderTreeList(
|
|
778
|
+
{
|
|
779
|
+
items: outputLines,
|
|
780
|
+
expanded,
|
|
781
|
+
maxCollapsed: COLLAPSED_GENERIC_LINES,
|
|
782
|
+
itemType: "line",
|
|
783
|
+
renderItem: line => line,
|
|
784
|
+
},
|
|
785
|
+
theme,
|
|
786
|
+
);
|
|
787
|
+
return { rows, hidden: !expanded && outputLines.length > COLLAPSED_GENERIC_LINES };
|
|
788
|
+
},
|
|
789
|
+
};
|
|
898
790
|
}
|
|
899
791
|
|
|
900
792
|
// =============================================================================
|
|
@@ -1055,9 +947,10 @@ function statusRow(message: string, tone: "error" | "warning", key: string): Nat
|
|
|
1055
947
|
}
|
|
1056
948
|
|
|
1057
949
|
/**
|
|
1058
|
-
* Diagnostics view: a card when there are diagnostics,
|
|
1059
|
-
* (rows of severity icon · `file:line:col` · source · message),
|
|
1060
|
-
*
|
|
950
|
+
* Diagnostics view: a card when there are diagnostics, failed or partly failed servers,
|
|
951
|
+
* or unverified files (rows of severity icon · `file:line:col` · source · message), inline otherwise.
|
|
952
|
+
* Only a response with nothing to show reads `No issues`; a failed server or a missing
|
|
953
|
+
* report is a row, never "No issues".
|
|
1061
954
|
*/
|
|
1062
955
|
function describeLspDiagnostics(request: Partial<LspParams> | undefined, fallbackAction: string, lines: string[]) {
|
|
1063
956
|
const parsed = parseLspDiagnostics(lines);
|
|
@@ -1076,9 +969,11 @@ function describeLspDiagnostics(request: Partial<LspParams> | undefined, fallbac
|
|
|
1076
969
|
];
|
|
1077
970
|
if (parsed.other.length > 0) rows.push(keyed(code(parsed.other.join("\n"), { wrap: true }), "other"));
|
|
1078
971
|
const hasErrors = parsed.failures.length > 0 || parsed.diagnostics.some(d => d.severity === "error");
|
|
1079
|
-
const meta = compact<TspText>([counts, failed, unverified,
|
|
972
|
+
const meta = compact<TspText>([counts, failed, unverified, rows.length === 0 && "No issues"]);
|
|
1080
973
|
const head = lspNativeHead(request, fallbackAction, meta);
|
|
1081
|
-
|
|
974
|
+
const flagged =
|
|
975
|
+
parsed.diagnostics.length + parsed.failures.length + parsed.unreported.length + parsed.warnings.length;
|
|
976
|
+
if (flagged === 0) {
|
|
1082
977
|
return { tool: head, inline: true, body: rows.length > 0 ? rows : undefined } satisfies NativeToolView;
|
|
1083
978
|
}
|
|
1084
979
|
return {
|
|
@@ -1089,30 +984,32 @@ function describeLspDiagnostics(request: Partial<LspParams> | undefined, fallbac
|
|
|
1089
984
|
} satisfies NativeToolView;
|
|
1090
985
|
}
|
|
1091
986
|
|
|
1092
|
-
/**
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
const [, file, line, col] = match;
|
|
1099
|
-
let locs = byFile.get(file);
|
|
1100
|
-
if (!locs) {
|
|
1101
|
-
locs = [];
|
|
1102
|
-
byFile.set(file, locs);
|
|
1103
|
-
}
|
|
1104
|
-
locs.push(`${line}:${col}`);
|
|
1105
|
-
}
|
|
987
|
+
/**
|
|
988
|
+
* References grouped by file (§7.3): a file row with the count, then each referencing
|
|
989
|
+
* line as numbered source, which Tern highlights by the file's path. References past
|
|
990
|
+
* the tool's context limit come without source and list as `line:col` positions.
|
|
991
|
+
*/
|
|
992
|
+
function describeLspReferences(references: readonly LspLocation[]): NativeNode[] {
|
|
1106
993
|
const nodes: NativeNode[] = [];
|
|
1107
|
-
for (const [file,
|
|
994
|
+
for (const [file, locations] of groupReferencesByFile(references)) {
|
|
1108
995
|
const name = plainText(file);
|
|
996
|
+
const sourceLines: NumberedLine[] = [];
|
|
997
|
+
const positions: string[] = [];
|
|
998
|
+
for (const location of locations) {
|
|
999
|
+
const line = location.context.find(context => context.mark);
|
|
1000
|
+
if (!line) positions.push(formatPosition(location));
|
|
1001
|
+
// Two references on one line share its source row.
|
|
1002
|
+
else if (sourceLines.at(-1)?.n !== line.n) sourceLines.push({ ...line, text: plainText(line.text) });
|
|
1003
|
+
}
|
|
1004
|
+
const chip = { text: String(locations.length), title: formatCount("reference", locations.length) };
|
|
1109
1005
|
nodes.push(
|
|
1110
1006
|
keyed(
|
|
1111
1007
|
col(
|
|
1112
|
-
[
|
|
1113
|
-
fileRow(name, { chip
|
|
1114
|
-
|
|
1115
|
-
|
|
1008
|
+
compact([
|
|
1009
|
+
fileRow(name, { chip }),
|
|
1010
|
+
numberedCode(sourceLines, { path: name }),
|
|
1011
|
+
positions.length > 0 && text([span(positions.join(" "), "mono muted")], { wrap: "word" }),
|
|
1012
|
+
]),
|
|
1116
1013
|
{ gap: "xs" },
|
|
1117
1014
|
),
|
|
1118
1015
|
name,
|
|
@@ -1184,10 +1081,19 @@ function describeLspResult(result: ToolRenderResult<LspToolDetails>, args: LspPa
|
|
|
1184
1081
|
|
|
1185
1082
|
const lines = text.split("\n");
|
|
1186
1083
|
const locations = parseLspLocations(lines);
|
|
1084
|
+
if (locations?.noun === "reference") {
|
|
1085
|
+
const body = describeLspReferences(locations.locations);
|
|
1086
|
+
return {
|
|
1087
|
+
tool: lspNativeHead(request, fallbackAction, [formatCount("reference", locations.count)]),
|
|
1088
|
+
tone: locations.count > 0 ? undefined : "warning",
|
|
1089
|
+
inline: true,
|
|
1090
|
+
body: body.length > 0 ? body : undefined,
|
|
1091
|
+
preview: { lines: 8 },
|
|
1092
|
+
};
|
|
1093
|
+
}
|
|
1187
1094
|
if (locations) return describeLspLocations(request, fallbackAction, locations);
|
|
1188
1095
|
|
|
1189
1096
|
const statusError = activeThemeSymbol("status.error");
|
|
1190
|
-
const refMatch = text.match(/(\d+)\s+reference\(s\)/);
|
|
1191
1097
|
const symbolsMatch = text.match(/Symbols in (.+):/);
|
|
1192
1098
|
|
|
1193
1099
|
if (/```(\w*)\n([\s\S]*?)```/.test(text)) {
|
|
@@ -1200,17 +1106,6 @@ function describeLspResult(result: ToolRenderResult<LspToolDetails>, args: LspPa
|
|
|
1200
1106
|
) {
|
|
1201
1107
|
return describeLspDiagnostics(request, fallbackAction, lines);
|
|
1202
1108
|
}
|
|
1203
|
-
if (refMatch) {
|
|
1204
|
-
const refCount = Number.parseInt(refMatch[1], 10);
|
|
1205
|
-
const body = describeLspReferences(lines);
|
|
1206
|
-
return {
|
|
1207
|
-
tool: lspNativeHead(request, fallbackAction, [formatCount("reference", refCount)]),
|
|
1208
|
-
tone: refCount > 0 ? undefined : "warning",
|
|
1209
|
-
inline: true,
|
|
1210
|
-
body: body.length > 0 ? body : undefined,
|
|
1211
|
-
preview: { lines: 8 },
|
|
1212
|
-
};
|
|
1213
|
-
}
|
|
1214
1109
|
if (symbolsMatch) {
|
|
1215
1110
|
const body = describeLspSymbols(lines);
|
|
1216
1111
|
return {
|