M3.3: engine wiring for Phpactor and diagnostics
- One Phpactor per open project on its own session thread, started when the toolchain is ready; ordered document sync from buffer.edit and the pump; lspStatus, diagnosticsChanged, diagnostics.list, lsp.status, lsp.restart; app.quit stops the server synchronously. - Phpactor 2026.06.25.0 on Windows: keep-alive $/lutra/tick (its event loop only runs on stdin input), in-process diagnostics and a polling watcher through initializationOptions (amphp subprocesses fail), 500 ms shutdown timeout. - Editor lint extension (underlines, gutter dots, hover; tokens only) and a Problems tab in the bottom panel; problems.open Mod+Alt+P. - Tests: engine tests against the fake server (incl. sync proptest), an ignored real-Phpactor test, a TCP test, Vitest for lint and Problems. - Docs: architecture, gaps G6, parity (Inspections 4% est.), ui-parity, roadmap, ROADMAP. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
65c6966588
commit
13c76d3046
34 changed files with 3562 additions and 37 deletions
|
|
@ -24,6 +24,7 @@
|
|||
"@codemirror/lang-php": "^6.0.2",
|
||||
"@codemirror/lang-yaml": "^6.1.3",
|
||||
"@codemirror/language": "^6.13.1",
|
||||
"@codemirror/lint": "^6.9.7",
|
||||
"@codemirror/state": "^6.7.6",
|
||||
"@codemirror/view": "^6.43.14",
|
||||
"@lezer/highlight": "^1.2.5",
|
||||
|
|
|
|||
3
ui/pnpm-lock.yaml
generated
3
ui/pnpm-lock.yaml
generated
|
|
@ -32,6 +32,9 @@ importers:
|
|||
'@codemirror/language':
|
||||
specifier: ^6.13.1
|
||||
version: 6.13.1
|
||||
'@codemirror/lint':
|
||||
specifier: ^6.9.7
|
||||
version: 6.9.7
|
||||
'@codemirror/state':
|
||||
specifier: ^6.7.6
|
||||
version: 6.7.6
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ export const UI_COMMANDS: readonly UiCommandSpec[] = [
|
|||
{ id: "goto.symbolOpen", labelKey: "command.goto.symbolOpen", menuPath: "Go/Symbol…", defaultShortcut: "Mod+T" },
|
||||
{ id: "menu.open", labelKey: "command.menu.open", defaultShortcut: "Alt+M" },
|
||||
{ id: "palette.open", labelKey: "command.palette.open", menuPath: "View/Command Palette", defaultShortcut: "Mod+Shift+P" },
|
||||
{ id: "problems.open", labelKey: "command.problems.open", menuPath: "View/Problems", defaultShortcut: "Mod+Alt+P" },
|
||||
{ id: "settings.open", labelKey: "command.settings.open", menuPath: "View/Settings…", defaultShortcut: "Mod+," },
|
||||
{ id: "terminal.open", labelKey: "command.terminal.open", menuPath: "View/Terminal", defaultShortcut: "Mod+Shift+T" },
|
||||
{ id: "view.toggleProjectTree", labelKey: "command.view.toggleProjectTree", menuPath: "View/Project", defaultShortcut: "Mod+1" },
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import { EditorView } from "@codemirror/view";
|
|||
import type { Extension } from "@codemirror/state";
|
||||
import { basicSetup } from "codemirror";
|
||||
import { languageExtensions, type SYNTAX_CLASS, type SyntaxToken } from "./language";
|
||||
import { lintExtensions } from "./lint";
|
||||
|
||||
/**
|
||||
* Colours of the highlight classes (`language.ts`), one `--lt-syntax-*`
|
||||
|
|
@ -110,5 +111,5 @@ export const lutraEditorTheme: Extension = EditorView.theme({
|
|||
* omitted or unknown.
|
||||
*/
|
||||
export function editorExtensions(path = ""): Extension {
|
||||
return [basicSetup, lutraEditorTheme, languageExtensions(path)];
|
||||
return [basicSetup, lutraEditorTheme, languageExtensions(path), lintExtensions(path)];
|
||||
}
|
||||
|
|
|
|||
212
ui/src/components/editor/lint.ts
Normal file
212
ui/src/components/editor/lint.ts
Normal file
|
|
@ -0,0 +1,212 @@
|
|||
/**
|
||||
* Diagnostics in the editor (M3.3): wavy underlines, gutter markers and
|
||||
* the message on hover, from the language server's `diagnosticsChanged`
|
||||
* events, through CodeMirror's lint extension.
|
||||
*
|
||||
* The Problems store ({@link useProblemsStore}) owns the diagnostics and
|
||||
* hands every file's list to {@link publishDiagnostics}. This module keeps
|
||||
* them by path; each editor state built for a path carries a view plugin
|
||||
* that applies the file's list when the view shows the state and whenever
|
||||
* it changes. Editor states of tabs in the background are brought up to
|
||||
* date when they are shown again. Between two publications CodeMirror maps
|
||||
* the ranges through the user's edits.
|
||||
*
|
||||
* Positions are 0-based lines with UTF-16 columns, converted with
|
||||
* {@link positionOf} (CRLF-safe, clamped to the document). Colours come
|
||||
* from tokens: errors `--lt-error`, warnings `--lt-accent`, information and
|
||||
* hints `--lt-fg-muted`.
|
||||
*
|
||||
* @see useProblemsStore in `../problems/problems.ts`.
|
||||
*/
|
||||
import { lintGutter, setDiagnostics, type Diagnostic } from "@codemirror/lint";
|
||||
import type { Extension, Text } from "@codemirror/state";
|
||||
import { EditorView, ViewPlugin, type PluginValue } from "@codemirror/view";
|
||||
import { positionOf } from "./engineText";
|
||||
|
||||
/** Severity of a diagnostic, as the engine names it. */
|
||||
export type DiagnosticSeverity = "error" | "warning" | "info" | "hint";
|
||||
|
||||
/** A 0-based position; the column counts UTF-16 code units. */
|
||||
export interface DiagnosticPosition {
|
||||
/** Line. */
|
||||
line: number;
|
||||
/** Column. */
|
||||
column: number;
|
||||
}
|
||||
|
||||
/** One diagnostic of a file, as `diagnosticsChanged` carries it. */
|
||||
export interface DiagnosticItem {
|
||||
/** Where it applies; the end is exclusive. */
|
||||
range: { start: DiagnosticPosition; end: DiagnosticPosition };
|
||||
/** How severe it is. */
|
||||
severity: DiagnosticSeverity;
|
||||
/** The message. */
|
||||
message: string;
|
||||
/** Who reported it (`phpactor`, …). */
|
||||
source?: string;
|
||||
/** The diagnostic code. */
|
||||
code?: string;
|
||||
}
|
||||
|
||||
/** Diagnostics by project-relative path. */
|
||||
const byPath = new Map<string, readonly DiagnosticItem[]>();
|
||||
|
||||
/** Plugins listening for changes, by path. */
|
||||
const listeners = new Map<string, Set<() => void>>();
|
||||
|
||||
/**
|
||||
* Stores the diagnostics of a file and updates the editors showing it.
|
||||
*
|
||||
* @param path - project-relative path with `/`.
|
||||
* @param items - the file's diagnostics; empty clears them.
|
||||
*/
|
||||
export function publishDiagnostics(path: string, items: readonly DiagnosticItem[]): void {
|
||||
if (items.length === 0) {
|
||||
byPath.delete(path);
|
||||
} else {
|
||||
byPath.set(path, items);
|
||||
}
|
||||
for (const listener of listeners.get(path) ?? []) {
|
||||
listener();
|
||||
}
|
||||
}
|
||||
|
||||
/** Drops every file's diagnostics (project closed) and updates the editors. */
|
||||
export function clearDiagnostics(): void {
|
||||
const paths = [...byPath.keys()];
|
||||
byPath.clear();
|
||||
for (const path of paths) {
|
||||
for (const listener of listeners.get(path) ?? []) {
|
||||
listener();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The diagnostics stored for a file.
|
||||
*
|
||||
* @param path - project-relative path.
|
||||
*/
|
||||
export function diagnosticsOf(path: string): readonly DiagnosticItem[] {
|
||||
return byPath.get(path) ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a file's diagnostics into CodeMirror's, against `doc`.
|
||||
*
|
||||
* @param doc - the document they apply to.
|
||||
* @param items - the diagnostics.
|
||||
* @returns CodeMirror diagnostics, sorted by start as the lint state needs.
|
||||
*/
|
||||
export function toCodeMirror(doc: Text, items: readonly DiagnosticItem[]): Diagnostic[] {
|
||||
const out: Diagnostic[] = items.map((item) => {
|
||||
const from = positionOf(doc, item.range.start.line, item.range.start.column);
|
||||
const to = Math.max(from, positionOf(doc, item.range.end.line, item.range.end.column));
|
||||
const source = [item.source, item.code].filter((part) => part !== undefined && part !== "").join(" ");
|
||||
const diagnostic: Diagnostic = { from, to, severity: item.severity, message: item.message };
|
||||
if (source !== "") {
|
||||
diagnostic.source = source;
|
||||
}
|
||||
return diagnostic;
|
||||
});
|
||||
return out.sort((a, b) => a.from - b.from || a.to - b.to);
|
||||
}
|
||||
|
||||
/**
|
||||
* A view plugin that keeps the lint state of a path's editor in step with
|
||||
* {@link publishDiagnostics}. It applies the current list right after the
|
||||
* view shows the state (the dispatch waits a microtask: a plugin may not
|
||||
* dispatch while the view is updating) and on every change.
|
||||
*
|
||||
* @param path - project-relative path of the editor's file.
|
||||
*/
|
||||
function diagnosticsPlugin(path: string): Extension {
|
||||
return ViewPlugin.define((view): PluginValue => {
|
||||
let alive = true;
|
||||
const apply = (): void => {
|
||||
if (!alive) {
|
||||
return;
|
||||
}
|
||||
view.dispatch(setDiagnostics(view.state, toCodeMirror(view.state.doc, diagnosticsOf(path))));
|
||||
};
|
||||
let set = listeners.get(path);
|
||||
if (!set) {
|
||||
set = new Set();
|
||||
listeners.set(path, set);
|
||||
}
|
||||
set.add(apply);
|
||||
queueMicrotask(apply);
|
||||
return {
|
||||
destroy(): void {
|
||||
alive = false;
|
||||
const current = listeners.get(path);
|
||||
current?.delete(apply);
|
||||
if (current?.size === 0) {
|
||||
listeners.delete(path);
|
||||
}
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/** Wavy underline of one severity in a token colour. */
|
||||
function underline(colour: string): Record<string, string> {
|
||||
return {
|
||||
backgroundImage: "none",
|
||||
textDecoration: `underline wavy ${colour}`,
|
||||
textDecorationSkipInk: "none",
|
||||
textUnderlineOffset: "3px",
|
||||
};
|
||||
}
|
||||
|
||||
/** Gutter dot of one severity in a token colour. */
|
||||
function marker(colour: string): Record<string, string> {
|
||||
return {
|
||||
content: "none",
|
||||
width: "8px",
|
||||
height: "8px",
|
||||
margin: "0 auto",
|
||||
borderRadius: "50%",
|
||||
backgroundColor: colour,
|
||||
};
|
||||
}
|
||||
|
||||
/** Lint colours from tokens, replacing CodeMirror's built-in ones. */
|
||||
const lintTheme: Extension = EditorView.theme({
|
||||
".cm-lintRange-error": underline("var(--lt-error)"),
|
||||
".cm-lintRange-warning": underline("var(--lt-accent)"),
|
||||
".cm-lintRange-info, .cm-lintRange-hint": underline("var(--lt-fg-muted)"),
|
||||
".cm-lintRange-active": { backgroundColor: "var(--lt-editor-match-bg)" },
|
||||
".cm-lintPoint:after": { borderBottomColor: "var(--lt-error)" },
|
||||
".cm-lintPoint-warning:after": { borderBottomColor: "var(--lt-accent)" },
|
||||
".cm-lintPoint-info:after, .cm-lintPoint-hint:after": { borderBottomColor: "var(--lt-fg-muted)" },
|
||||
".cm-gutter-lint": { width: "14px" },
|
||||
".cm-gutter-lint .cm-gutterElement": { display: "flex", alignItems: "center", padding: "0" },
|
||||
".cm-lint-marker": { width: "8px", height: "8px" },
|
||||
".cm-lint-marker-error": marker("var(--lt-error)"),
|
||||
".cm-lint-marker-warning": marker("var(--lt-accent)"),
|
||||
".cm-lint-marker-info, .cm-lint-marker-hint": marker("var(--lt-fg-muted)"),
|
||||
".cm-diagnostic": { padding: "4px 8px", color: "var(--lt-fg)", whiteSpace: "pre-wrap" },
|
||||
".cm-diagnostic-error": { borderLeft: "3px solid var(--lt-error)" },
|
||||
".cm-diagnostic-warning": { borderLeft: "3px solid var(--lt-accent)" },
|
||||
".cm-diagnostic-info, .cm-diagnostic-hint": { borderLeft: "3px solid var(--lt-fg-muted)" },
|
||||
".cm-diagnosticSource": { color: "var(--lt-fg-muted)", opacity: "1" },
|
||||
".cm-tooltip-lint": { maxWidth: "640px" },
|
||||
".cm-panel.cm-panel-lint": { backgroundColor: "var(--lt-bg)", color: "var(--lt-fg)" },
|
||||
".cm-panel.cm-panel-lint ul [aria-selected]": { backgroundColor: "var(--lt-editor-selection-bg)" },
|
||||
});
|
||||
|
||||
/**
|
||||
* The lint extensions of an editor for `path`: the lint state with its
|
||||
* hover tooltips, the gutter column, the token theme and the plugin that
|
||||
* feeds them. Files without diagnostics get them too, so a first
|
||||
* publication shows at once.
|
||||
*
|
||||
* @param path - project-relative path of the file; empty for none.
|
||||
*/
|
||||
export function lintExtensions(path: string): Extension {
|
||||
if (path === "") {
|
||||
return [];
|
||||
}
|
||||
return [lintGutter(), lintTheme, diagnosticsPlugin(path)];
|
||||
}
|
||||
|
|
@ -15,14 +15,16 @@
|
|||
* `view.toggleStructure` (`Mod+2`): each shows its tool window, or hides
|
||||
* the left window when that tool window is already shown.
|
||||
*
|
||||
* The bottom panel ({@link BottomPanel}) holds the Find and Terminal tool
|
||||
* windows, as tabs in its header while both are shown. Find appears with
|
||||
* the UI command `find.open` (`Mod+Alt+F`), Terminal with `terminal.open`
|
||||
* (`Mod+Shift+T`, M3.6); both are supplied here so they work before the
|
||||
* panel exists, and each makes its tool window the active tab. The panel
|
||||
* collapses to its header; closing it hides the active tool window (the
|
||||
* other one, if shown, becomes active). The Find store keeps the results
|
||||
* and the Terminal store the running terminals while they are hidden.
|
||||
* The bottom panel ({@link BottomPanel}) holds the Find, Terminal and
|
||||
* Problems tool windows, as tabs in its header while more than one is
|
||||
* shown. Find appears with the UI command `find.open` (`Mod+Alt+F`),
|
||||
* Terminal with `terminal.open` (`Mod+Shift+T`, M3.6), Problems with
|
||||
* `problems.open` (`Mod+Alt+P`, M3.3); all are supplied here so they work
|
||||
* before the panel exists, and each makes its tool window the active tab.
|
||||
* The panel collapses to its header; closing it hides the active tool
|
||||
* window (another shown one becomes active). The Find store keeps the
|
||||
* results, the Terminal store the running terminals and the Problems store
|
||||
* the diagnostics while they are hidden.
|
||||
*
|
||||
* A slim header bar along the top (M3.9) holds the app menu
|
||||
* ({@link AppMenu}); its `header` slot can replace it.
|
||||
|
|
@ -35,6 +37,8 @@ import { useFindStore } from "../../stores/find";
|
|||
import { useTerminalStore } from "../../stores/terminal";
|
||||
import FindToolWindow from "../find/FindToolWindow.vue";
|
||||
import TerminalToolWindow from "../terminal/TerminalToolWindow.vue";
|
||||
import ProblemsToolWindow from "../problems/ProblemsToolWindow.vue";
|
||||
import { useProblemsStore } from "../problems/problems";
|
||||
import ProjectToolWindow from "../project/ProjectToolWindow.vue";
|
||||
import StatusBar from "../StatusBar.vue";
|
||||
import StructureToolWindow from "../structure/StructureToolWindow.vue";
|
||||
|
|
@ -79,9 +83,10 @@ function toggleLeft(tool: LeftTool): void {
|
|||
const commands = useCommandsStore();
|
||||
const find = useFindStore();
|
||||
const terminal = useTerminalStore();
|
||||
const problems = useProblemsStore();
|
||||
|
||||
/** Tool windows of the bottom panel. */
|
||||
type BottomTool = "find" | "terminal";
|
||||
type BottomTool = "find" | "terminal" | "problems";
|
||||
/** The bottom tool window last chosen. */
|
||||
const bottomTool = ref<BottomTool>("find");
|
||||
/** Bottom tool windows that are shown, in tab order. */
|
||||
|
|
@ -89,6 +94,7 @@ const bottomTools = computed(() => {
|
|||
const tools: { id: BottomTool; title: string }[] = [];
|
||||
if (find.visible) tools.push({ id: "find", title: t("find.toolWindow.title") });
|
||||
if (terminal.visible) tools.push({ id: "terminal", title: t("terminal.toolWindow.title") });
|
||||
if (problems.visible) tools.push({ id: "problems", title: t("problems.toolWindow.title") });
|
||||
return tools;
|
||||
});
|
||||
/** The active bottom tool window: the chosen one if shown, else the first. */
|
||||
|
|
@ -96,15 +102,15 @@ const bottomActive = computed<BottomTool | null>(() => {
|
|||
const tools = bottomTools.value;
|
||||
return tools.some((tool) => tool.id === bottomTool.value) ? bottomTool.value : (tools[0]?.id ?? null);
|
||||
});
|
||||
/** The store of the active bottom tool window. */
|
||||
const bottomStore = computed(() =>
|
||||
bottomActive.value === "terminal" ? terminal : bottomActive.value === "problems" ? problems : find,
|
||||
);
|
||||
/** Expansion of the panel, kept per tool window by its store. */
|
||||
const bottomOpen = computed({
|
||||
get: () => (bottomActive.value === "terminal" ? terminal.expanded : find.expanded),
|
||||
get: () => bottomStore.value.expanded,
|
||||
set: (open: boolean) => {
|
||||
if (bottomActive.value === "terminal") {
|
||||
terminal.expanded = open;
|
||||
} else {
|
||||
find.expanded = open;
|
||||
}
|
||||
bottomStore.value.expanded = open;
|
||||
},
|
||||
});
|
||||
|
||||
|
|
@ -114,18 +120,14 @@ const bottomOpen = computed({
|
|||
* @param id - the tool window id from the panel.
|
||||
*/
|
||||
function chooseBottom(id: string): void {
|
||||
if (id === "find" || id === "terminal") {
|
||||
if (id === "find" || id === "terminal" || id === "problems") {
|
||||
bottomTool.value = id;
|
||||
}
|
||||
}
|
||||
|
||||
/** Hides the active bottom tool window. */
|
||||
function closeBottom(): void {
|
||||
if (bottomActive.value === "terminal") {
|
||||
terminal.hide();
|
||||
} else {
|
||||
find.hide();
|
||||
}
|
||||
bottomStore.value.hide();
|
||||
}
|
||||
|
||||
/** Withdraws the command handlers; filled while mounted. */
|
||||
|
|
@ -134,6 +136,7 @@ let withdraw: (() => void)[] = [];
|
|||
onMounted(() => {
|
||||
find.start();
|
||||
terminal.start();
|
||||
problems.start();
|
||||
withdraw = [
|
||||
commands.provide("view.toggleProjectTree", {
|
||||
run: () => {
|
||||
|
|
@ -153,6 +156,12 @@ onMounted(() => {
|
|||
},
|
||||
enabled: () => commands.isEnabled("terminal.create"),
|
||||
}),
|
||||
commands.provide("problems.open", {
|
||||
run: () => {
|
||||
bottomTool.value = "problems";
|
||||
problems.open();
|
||||
},
|
||||
}),
|
||||
commands.provide("view.toggleStructure", {
|
||||
run: () => {
|
||||
toggleLeft("structure");
|
||||
|
|
@ -168,6 +177,7 @@ onBeforeUnmount(() => {
|
|||
withdraw = [];
|
||||
find.stop();
|
||||
terminal.stop();
|
||||
problems.stop();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
@ -239,6 +249,7 @@ onBeforeUnmount(() => {
|
|||
v-if="terminal.visible"
|
||||
v-show="bottomActive === 'terminal'"
|
||||
/>
|
||||
<ProblemsToolWindow v-show="bottomActive === 'problems'" />
|
||||
</BottomPanel>
|
||||
<StatusBar />
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ const ITEM_ORDER = [
|
|||
"view.toggleStructure",
|
||||
"find.open",
|
||||
"terminal.open",
|
||||
"problems.open",
|
||||
"settings.open",
|
||||
"goto.fileOpen",
|
||||
"goto.classOpen",
|
||||
|
|
|
|||
374
ui/src/components/problems/ProblemsToolWindow.vue
Normal file
374
ui/src/components/problems/ProblemsToolWindow.vue
Normal file
|
|
@ -0,0 +1,374 @@
|
|||
<script setup lang="ts">
|
||||
/**
|
||||
* The Problems tool window (M3.3), shown in the bottom panel: the
|
||||
* language server's diagnostics of the project, grouped by file.
|
||||
*
|
||||
* - **Header line:** the totals by severity, or the server's state while
|
||||
* it starts, restarts, failed or is not running.
|
||||
* - **List:** one group per file (name, directory, count), then its
|
||||
* diagnostics with a severity icon, the message, the source and code,
|
||||
* and the position. Up/Down, Page Up/Down, Home and End move the
|
||||
* selection; Enter or a click reveals the position through the command
|
||||
* `editor.reveal`.
|
||||
* - State lives in the Problems store (`problems.ts`), so it is kept while
|
||||
* the window is hidden. Icons are Lucide's; colours are tokens.
|
||||
*/
|
||||
import { CircleAlert, Info, Lightbulb, TriangleAlert } from "@lucide/vue";
|
||||
import { computed, nextTick, onMounted, ref, watch } from "vue";
|
||||
import { useCommandsStore } from "../../commands/store";
|
||||
import { t } from "../../i18n";
|
||||
import { baseName } from "../../stores/editor";
|
||||
import type { DiagnosticSeverity } from "../editor/lint";
|
||||
import { useProblemsStore, type ProblemRow } from "./problems";
|
||||
|
||||
const problems = useProblemsStore();
|
||||
const commands = useCommandsStore();
|
||||
|
||||
/** The list element. */
|
||||
const list = ref<HTMLElement | null>(null);
|
||||
|
||||
/** Rows moved by Page Up and Page Down. */
|
||||
const PAGE = 10;
|
||||
|
||||
/** Icons by severity. */
|
||||
const ICONS = { error: CircleAlert, warning: TriangleAlert, info: Info, hint: Lightbulb } as const;
|
||||
|
||||
/**
|
||||
* The accessible name of a severity.
|
||||
*
|
||||
* @param severity - the severity.
|
||||
*/
|
||||
function severityLabel(severity: DiagnosticSeverity): string {
|
||||
const labels: Record<DiagnosticSeverity, () => string> = {
|
||||
error: () => t("problems.severity.error"),
|
||||
warning: () => t("problems.severity.warning"),
|
||||
info: () => t("problems.severity.info"),
|
||||
hint: () => t("problems.severity.hint"),
|
||||
};
|
||||
return labels[severity]();
|
||||
}
|
||||
|
||||
/** The line above the list: the server's state, or the totals. */
|
||||
const status = computed(() => {
|
||||
const lsp = problems.lsp;
|
||||
const message = lsp?.message ?? "";
|
||||
if (lsp?.state === "starting") {
|
||||
return t("problems.lsp.starting");
|
||||
}
|
||||
if (lsp?.state === "restarting") {
|
||||
return t("problems.lsp.restarting", { message });
|
||||
}
|
||||
if (lsp?.state === "failed") {
|
||||
return t("problems.lsp.failed", { message });
|
||||
}
|
||||
if ((lsp === null || lsp.state === "stopped") && problems.rows.length === 0) {
|
||||
return t("problems.lsp.stopped");
|
||||
}
|
||||
if (problems.rows.length === 0) {
|
||||
return t("problems.empty");
|
||||
}
|
||||
const c = problems.counts;
|
||||
return t("problems.summary", {
|
||||
errors: String(c.error),
|
||||
warnings: String(c.warning),
|
||||
infos: String(c.info + c.hint),
|
||||
});
|
||||
});
|
||||
|
||||
/** A file with its rows and their indexes in the flat list. */
|
||||
interface ProblemGroup {
|
||||
/** Project-relative path. */
|
||||
path: string;
|
||||
/** The rows with their flat index. */
|
||||
rows: { row: ProblemRow; index: number }[];
|
||||
}
|
||||
|
||||
/** The rows grouped by file, in display order. */
|
||||
const groups = computed<ProblemGroup[]>(() => {
|
||||
const out: ProblemGroup[] = [];
|
||||
problems.rows.forEach((row, index) => {
|
||||
const last = out[out.length - 1];
|
||||
if (last?.path === row.path) {
|
||||
last.rows.push({ row, index });
|
||||
} else {
|
||||
out.push({ path: row.path, rows: [{ row, index }] });
|
||||
}
|
||||
});
|
||||
return out;
|
||||
});
|
||||
|
||||
/**
|
||||
* The DOM id of a row.
|
||||
*
|
||||
* @param index - the row's index in the flat list.
|
||||
*/
|
||||
function optionId(index: number): string {
|
||||
return `problem-row-${String(index)}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* The directory part of a path, empty at the root.
|
||||
*
|
||||
* @param path - project-relative path.
|
||||
*/
|
||||
function dirName(path: string): string {
|
||||
const slash = path.lastIndexOf("/");
|
||||
return slash < 0 ? "" : path.slice(0, slash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Source and code of a diagnostic, for the muted suffix.
|
||||
*
|
||||
* @param row - the row.
|
||||
*/
|
||||
function origin(row: ProblemRow): string {
|
||||
return [row.item.source, row.item.code].filter((part) => part !== undefined && part !== "").join(" ");
|
||||
}
|
||||
|
||||
/**
|
||||
* The position of a row, 1-based for people.
|
||||
*
|
||||
* @param row - the row.
|
||||
*/
|
||||
function position(row: ProblemRow): string {
|
||||
const start = row.item.range.start;
|
||||
return t("problems.position", { line: String(start.line + 1), column: String(start.column + 1) });
|
||||
}
|
||||
|
||||
/**
|
||||
* Reveals a diagnostic in the editor.
|
||||
*
|
||||
* @param row - the row.
|
||||
*/
|
||||
function openRow(row: ProblemRow): void {
|
||||
problems.select(row.key);
|
||||
const start = row.item.range.start;
|
||||
void commands.execute("editor.reveal", { path: row.path, line: start.line, column: start.column });
|
||||
}
|
||||
|
||||
/**
|
||||
* Keyboard navigation in the list.
|
||||
*
|
||||
* @param event - the key event.
|
||||
*/
|
||||
function onListKey(event: KeyboardEvent): void {
|
||||
const count = problems.rows.length;
|
||||
const moves: Record<string, number> = {
|
||||
ArrowDown: 1,
|
||||
ArrowUp: -1,
|
||||
PageDown: PAGE,
|
||||
PageUp: -PAGE,
|
||||
Home: -count,
|
||||
End: count,
|
||||
};
|
||||
const delta = moves[event.key];
|
||||
if (delta !== undefined) {
|
||||
event.preventDefault();
|
||||
problems.move(delta);
|
||||
} else if (event.key === "Enter") {
|
||||
const row = problems.rows[problems.selectedIndex];
|
||||
if (row) {
|
||||
event.preventDefault();
|
||||
openRow(row);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Takes the focus `problems.open` asked for, once. */
|
||||
async function takeFocus(): Promise<void> {
|
||||
if (!problems.focusPending) {
|
||||
return;
|
||||
}
|
||||
problems.focusPending = false;
|
||||
await nextTick();
|
||||
list.value?.focus();
|
||||
}
|
||||
|
||||
watch(() => problems.focusRequest, takeFocus);
|
||||
|
||||
onMounted(() => {
|
||||
void takeFocus();
|
||||
});
|
||||
|
||||
watch(
|
||||
() => problems.selectedIndex,
|
||||
async (index) => {
|
||||
await nextTick();
|
||||
const element = index < 0 ? null : document.getElementById(optionId(index));
|
||||
if (element && typeof element.scrollIntoView === "function") {
|
||||
element.scrollIntoView({ block: "nearest" });
|
||||
}
|
||||
},
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="problems"
|
||||
data-test="problems"
|
||||
>
|
||||
<div
|
||||
class="problems__status"
|
||||
role="status"
|
||||
data-test="problems-status"
|
||||
>
|
||||
{{ status }}
|
||||
</div>
|
||||
<div
|
||||
ref="list"
|
||||
class="problems__list"
|
||||
role="listbox"
|
||||
tabindex="0"
|
||||
:aria-label="t('problems.list.label')"
|
||||
:aria-activedescendant="problems.selectedIndex >= 0 ? optionId(problems.selectedIndex) : undefined"
|
||||
data-test="problems-list"
|
||||
@keydown="onListKey"
|
||||
>
|
||||
<div
|
||||
v-for="group in groups"
|
||||
:key="group.path"
|
||||
role="group"
|
||||
:aria-label="group.path"
|
||||
>
|
||||
<div
|
||||
class="problems__file"
|
||||
data-test="problems-file"
|
||||
>
|
||||
<span class="problems__file-name">{{ baseName(group.path) }}</span>
|
||||
<span class="problems__file-dir">{{ dirName(group.path) }}</span>
|
||||
<span
|
||||
class="problems__file-count"
|
||||
:title="t('problems.file.count', { count: String(group.rows.length) })"
|
||||
>{{ group.rows.length }}</span>
|
||||
</div>
|
||||
<div
|
||||
v-for="{ row, index } in group.rows"
|
||||
:id="optionId(index)"
|
||||
:key="row.key"
|
||||
role="option"
|
||||
class="problems__row"
|
||||
:class="{ 'problems__row--selected': problems.selectedKey === row.key }"
|
||||
:aria-selected="problems.selectedKey === row.key"
|
||||
:data-severity="row.item.severity"
|
||||
data-test="problems-row"
|
||||
@click="openRow(row)"
|
||||
>
|
||||
<component
|
||||
:is="ICONS[row.item.severity]"
|
||||
:size="14"
|
||||
class="problems__icon"
|
||||
:class="`problems__icon--${row.item.severity}`"
|
||||
role="img"
|
||||
:aria-label="severityLabel(row.item.severity)"
|
||||
/>
|
||||
<span class="problems__message">{{ row.item.message }}</span>
|
||||
<span
|
||||
v-if="origin(row) !== ''"
|
||||
class="problems__origin"
|
||||
>{{ origin(row) }}</span>
|
||||
<span class="problems__position">{{ position(row) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.problems {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.problems__status {
|
||||
padding: var(--lt-space-xs, 2px) var(--lt-space-m, 8px);
|
||||
color: var(--lt-fg-muted);
|
||||
}
|
||||
|
||||
.problems__list {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: auto;
|
||||
border-top: 1px solid var(--lt-border);
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.problems__list:focus-visible {
|
||||
box-shadow: inset 0 0 0 1px var(--lt-accent);
|
||||
}
|
||||
|
||||
.problems__file {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: var(--lt-space-m, 8px);
|
||||
padding: var(--lt-space-xs, 2px) var(--lt-space-m, 8px);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.problems__file-name {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.problems__file-dir {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
color: var(--lt-fg-muted);
|
||||
}
|
||||
|
||||
.problems__file-count {
|
||||
margin-left: auto;
|
||||
color: var(--lt-fg-muted);
|
||||
}
|
||||
|
||||
.problems__row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--lt-space-m, 8px);
|
||||
padding: 0 var(--lt-space-m, 8px) 0 var(--lt-space-l, 24px);
|
||||
white-space: nowrap;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.problems__row:hover {
|
||||
background: color-mix(in srgb, var(--lt-fg) 6%, transparent);
|
||||
}
|
||||
|
||||
.problems__row--selected,
|
||||
.problems__row--selected:hover {
|
||||
background: var(--lt-editor-selection-bg);
|
||||
}
|
||||
|
||||
.problems__icon {
|
||||
flex: none;
|
||||
}
|
||||
|
||||
.problems__icon--error {
|
||||
color: var(--lt-error);
|
||||
}
|
||||
|
||||
.problems__icon--warning {
|
||||
color: var(--lt-accent);
|
||||
}
|
||||
|
||||
.problems__icon--info,
|
||||
.problems__icon--hint {
|
||||
color: var(--lt-fg-muted);
|
||||
}
|
||||
|
||||
.problems__message {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.problems__origin,
|
||||
.problems__position {
|
||||
flex: none;
|
||||
color: var(--lt-fg-muted);
|
||||
}
|
||||
|
||||
.problems__row--selected .problems__origin,
|
||||
.problems__row--selected .problems__position {
|
||||
color: var(--lt-fg);
|
||||
}
|
||||
</style>
|
||||
341
ui/src/components/problems/problems.ts
Normal file
341
ui/src/components/problems/problems.ts
Normal file
|
|
@ -0,0 +1,341 @@
|
|||
/**
|
||||
* The Problems tool window's state (M3.3): the language server's
|
||||
* diagnostics of the project, grouped by file, and the server's state.
|
||||
*
|
||||
* - **Source:** `diagnosticsChanged {path, items}` replaces one file's
|
||||
* list (empty items remove the file); `diagnostics.list` loads every
|
||||
* file on start and when a project opens, and `lsp.status` the server's
|
||||
* state, which then follows `lspStatus`. A project close clears both.
|
||||
* - **Editor:** every change is handed to the editor's lint extension
|
||||
* ({@link publishDiagnostics}), which draws the underlines and gutter
|
||||
* markers.
|
||||
* - **Rows:** files sorted by path; inside a file errors first, then
|
||||
* warnings, information and hints, each by position. One flat row list
|
||||
* drives keyboard navigation; Enter or a click reveals the position
|
||||
* (`editor.reveal`).
|
||||
* - **Untrusted input:** event fields come from the engine and, through
|
||||
* it, from Phpactor; malformed items are dropped and the counts capped
|
||||
* ({@link MAX_ITEMS_PER_FILE}, {@link MAX_FILES}).
|
||||
*/
|
||||
import { defineStore } from "pinia";
|
||||
import { computed, ref, shallowRef } from "vue";
|
||||
import { onEngineEvent, run, type EngineEventPayload } from "../../ipc";
|
||||
import {
|
||||
clearDiagnostics,
|
||||
publishDiagnostics,
|
||||
type DiagnosticItem,
|
||||
type DiagnosticPosition,
|
||||
type DiagnosticSeverity,
|
||||
} from "../editor/lint";
|
||||
|
||||
/** Most diagnostics kept per file. */
|
||||
export const MAX_ITEMS_PER_FILE = 10_000;
|
||||
|
||||
/** Most files kept. */
|
||||
export const MAX_FILES = 10_000;
|
||||
|
||||
/** States of the language server, as `lspStatus` names them. */
|
||||
export const LSP_STATES = ["starting", "ready", "restarting", "failed", "stopped"] as const;
|
||||
|
||||
/** State of the language server. */
|
||||
export type LspState = (typeof LSP_STATES)[number];
|
||||
|
||||
/** The language server's state and why it is in it. */
|
||||
export interface LspStatus {
|
||||
/** The state. */
|
||||
state: LspState;
|
||||
/** Why it restarts or failed. */
|
||||
message: string | null;
|
||||
}
|
||||
|
||||
/** The diagnostics of one file. */
|
||||
export interface ProblemFile {
|
||||
/** Project-relative path with `/`. */
|
||||
path: string;
|
||||
/** Its diagnostics in display order. */
|
||||
items: DiagnosticItem[];
|
||||
}
|
||||
|
||||
/** A diagnostic in the flat display order. */
|
||||
export interface ProblemRow {
|
||||
/** Stable key: path and index. */
|
||||
key: string;
|
||||
/** Path of the file. */
|
||||
path: string;
|
||||
/** The diagnostic. */
|
||||
item: DiagnosticItem;
|
||||
}
|
||||
|
||||
/** Severities in display order. */
|
||||
const SEVERITY_ORDER: Record<DiagnosticSeverity, number> = { error: 0, warning: 1, info: 2, hint: 3 };
|
||||
|
||||
/**
|
||||
* Reads a position.
|
||||
*
|
||||
* @param raw - an untrusted `{line, column}`.
|
||||
*/
|
||||
function toPosition(raw: unknown): DiagnosticPosition | null {
|
||||
if (typeof raw !== "object" || raw === null) {
|
||||
return null;
|
||||
}
|
||||
const { line, column } = raw as Record<string, unknown>;
|
||||
const ok = (n: unknown): n is number => typeof n === "number" && Number.isInteger(n) && n >= 0;
|
||||
return ok(line) && ok(column) ? { line, column } : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads one diagnostic; null if malformed.
|
||||
*
|
||||
* @param raw - an untrusted item of `diagnosticsChanged`.
|
||||
*/
|
||||
export function toItem(raw: unknown): DiagnosticItem | null {
|
||||
if (typeof raw !== "object" || raw === null) {
|
||||
return null;
|
||||
}
|
||||
const i = raw as Record<string, unknown>;
|
||||
const range = typeof i.range === "object" && i.range !== null ? (i.range as Record<string, unknown>) : null;
|
||||
const start = toPosition(range?.start);
|
||||
const end = toPosition(range?.end);
|
||||
const severity = i.severity;
|
||||
if (
|
||||
!start ||
|
||||
!end ||
|
||||
typeof i.message !== "string" ||
|
||||
(severity !== "error" && severity !== "warning" && severity !== "info" && severity !== "hint")
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
const item: DiagnosticItem = { range: { start, end }, severity, message: i.message };
|
||||
if (typeof i.source === "string" && i.source !== "") {
|
||||
item.source = i.source;
|
||||
}
|
||||
if (typeof i.code === "string" && i.code !== "") {
|
||||
item.code = i.code;
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads and orders a file's diagnostics: errors first, then by position.
|
||||
*
|
||||
* @param raw - the untrusted `items` field.
|
||||
*/
|
||||
export function toItems(raw: unknown): DiagnosticItem[] {
|
||||
if (!Array.isArray(raw)) {
|
||||
return [];
|
||||
}
|
||||
const items: DiagnosticItem[] = [];
|
||||
for (const entry of raw as unknown[]) {
|
||||
if (items.length >= MAX_ITEMS_PER_FILE) {
|
||||
break;
|
||||
}
|
||||
const item = toItem(entry);
|
||||
if (item) {
|
||||
items.push(item);
|
||||
}
|
||||
}
|
||||
return items.sort(
|
||||
(a, b) =>
|
||||
SEVERITY_ORDER[a.severity] - SEVERITY_ORDER[b.severity] ||
|
||||
a.range.start.line - b.range.start.line ||
|
||||
a.range.start.column - b.range.start.column,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the payload of `lspStatus` or the result of `lsp.status`.
|
||||
*
|
||||
* @param raw - untrusted.
|
||||
* @returns the status, or null if the state is unknown.
|
||||
*/
|
||||
export function toStatus(raw: unknown): LspStatus | null {
|
||||
if (typeof raw !== "object" || raw === null) {
|
||||
return null;
|
||||
}
|
||||
const { state, message } = raw as Record<string, unknown>;
|
||||
const known = LSP_STATES.find((s) => s === state);
|
||||
if (!known) {
|
||||
return null;
|
||||
}
|
||||
return { state: known, message: typeof message === "string" ? message : null };
|
||||
}
|
||||
|
||||
/** The Problems store. */
|
||||
export const useProblemsStore = defineStore("problems", () => {
|
||||
/** Whether the tool window is shown in the bottom panel. */
|
||||
const visible = ref(false);
|
||||
/** Whether the panel is expanded while Problems is shown. */
|
||||
const expanded = ref(true);
|
||||
/** Files with diagnostics, sorted by path. */
|
||||
const files = shallowRef<ProblemFile[]>([]);
|
||||
/** The language server's state; null before the first report. */
|
||||
const lsp = ref<LspStatus | null>(null);
|
||||
/** Key of the selected row. */
|
||||
const selectedKey = ref<string | null>(null);
|
||||
/** Bumped when the window should take the keyboard focus. */
|
||||
const focusRequest = ref(0);
|
||||
/** Whether a focus request waits for the window (it may mount later). */
|
||||
const focusPending = ref(false);
|
||||
|
||||
/** Every diagnostic in display order. */
|
||||
const rows = computed<ProblemRow[]>(() =>
|
||||
files.value.flatMap((file) =>
|
||||
file.items.map((item, index) => ({ key: `${file.path}#${String(index)}`, path: file.path, item })),
|
||||
),
|
||||
);
|
||||
|
||||
/** Index of the selected row, -1 if none. */
|
||||
const selectedIndex = computed(() => rows.value.findIndex((row) => row.key === selectedKey.value));
|
||||
|
||||
/** Counts by severity over all files. */
|
||||
const counts = computed(() => {
|
||||
const out: Record<DiagnosticSeverity, number> = { error: 0, warning: 0, info: 0, hint: 0 };
|
||||
for (const file of files.value) {
|
||||
for (const item of file.items) {
|
||||
out[item.severity] += 1;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
});
|
||||
|
||||
/**
|
||||
* Replaces one file's diagnostics.
|
||||
*
|
||||
* @param path - project-relative path.
|
||||
* @param items - its diagnostics, already read; empty removes the file.
|
||||
*/
|
||||
function setFile(path: string, items: DiagnosticItem[]): void {
|
||||
const rest = files.value.filter((file) => file.path !== path);
|
||||
if (items.length > 0 && (rest.length < files.value.length || rest.length < MAX_FILES)) {
|
||||
rest.push({ path, items });
|
||||
rest.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
|
||||
}
|
||||
files.value = rest;
|
||||
publishDiagnostics(path, items);
|
||||
}
|
||||
|
||||
/** Drops every file's diagnostics. */
|
||||
function clear(): void {
|
||||
files.value = [];
|
||||
selectedKey.value = null;
|
||||
clearDiagnostics();
|
||||
}
|
||||
|
||||
/** Loads every file's diagnostics and the server's state from the engine. */
|
||||
async function load(): Promise<void> {
|
||||
const [list, status] = await Promise.all([run("diagnostics.list"), run("lsp.status")]);
|
||||
if (status.ok) {
|
||||
lsp.value = toStatus(status.value) ?? lsp.value;
|
||||
}
|
||||
if (!list.ok) {
|
||||
return;
|
||||
}
|
||||
const value = list.value;
|
||||
const raw = typeof value === "object" && value !== null && !Array.isArray(value) ? value.files : null;
|
||||
if (!Array.isArray(raw)) {
|
||||
return;
|
||||
}
|
||||
clear();
|
||||
for (const entry of raw) {
|
||||
if (typeof entry === "object" && entry !== null && !Array.isArray(entry) && typeof entry.path === "string") {
|
||||
setFile(entry.path, toItems(entry.items));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies one engine event.
|
||||
*
|
||||
* @param event - the event.
|
||||
*/
|
||||
function onEvent(event: EngineEventPayload): void {
|
||||
if (event.kind === "diagnosticsChanged") {
|
||||
if (typeof event.path === "string" && event.path !== "") {
|
||||
setFile(event.path, toItems(event.items));
|
||||
}
|
||||
} else if (event.kind === "lspStatus") {
|
||||
lsp.value = toStatus(event) ?? lsp.value;
|
||||
} else if (event.kind === "projectClosed") {
|
||||
clear();
|
||||
lsp.value = null;
|
||||
} else if (event.kind === "projectOpened") {
|
||||
void load();
|
||||
}
|
||||
}
|
||||
|
||||
/** Ends the event subscription; set while started. */
|
||||
let unsubscribe: (() => void) | null = null;
|
||||
|
||||
/** Subscribes to engine events and loads the current state. */
|
||||
function start(): void {
|
||||
if (unsubscribe) {
|
||||
return;
|
||||
}
|
||||
unsubscribe = onEngineEvent(onEvent);
|
||||
void load();
|
||||
}
|
||||
|
||||
/** Ends the subscription. */
|
||||
function stop(): void {
|
||||
unsubscribe?.();
|
||||
unsubscribe = null;
|
||||
}
|
||||
|
||||
/** Shows the tool window and asks it to take the focus: `problems.open`. */
|
||||
function open(): void {
|
||||
visible.value = true;
|
||||
expanded.value = true;
|
||||
focusPending.value = true;
|
||||
focusRequest.value += 1;
|
||||
}
|
||||
|
||||
/** Hides the tool window; the diagnostics stay. */
|
||||
function hide(): void {
|
||||
visible.value = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects a row.
|
||||
*
|
||||
* @param key - the row key, or null for none.
|
||||
*/
|
||||
function select(key: string | null): void {
|
||||
selectedKey.value = key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the selection by `delta` rows, clamped to the list.
|
||||
*
|
||||
* @param delta - rows to move; positive is down.
|
||||
*/
|
||||
function move(delta: number): void {
|
||||
const list = rows.value;
|
||||
if (list.length === 0) {
|
||||
return;
|
||||
}
|
||||
const from = selectedIndex.value < 0 ? (delta > 0 ? -1 : list.length) : selectedIndex.value;
|
||||
const index = Math.min(list.length - 1, Math.max(0, from + delta));
|
||||
selectedKey.value = list[index]?.key ?? null;
|
||||
}
|
||||
|
||||
return {
|
||||
visible,
|
||||
expanded,
|
||||
files,
|
||||
lsp,
|
||||
rows,
|
||||
counts,
|
||||
selectedKey,
|
||||
selectedIndex,
|
||||
focusRequest,
|
||||
focusPending,
|
||||
onEvent,
|
||||
load,
|
||||
start,
|
||||
stop,
|
||||
open,
|
||||
hide,
|
||||
select,
|
||||
move,
|
||||
};
|
||||
});
|
||||
|
|
@ -12,6 +12,7 @@
|
|||
"command.key.shift": "Shift",
|
||||
"command.menu.open": "Open Main Menu",
|
||||
"command.palette.open": "Command Palette",
|
||||
"command.problems.open": "Problems",
|
||||
"command.settings.open": "Settings…",
|
||||
"command.terminal.open": "Terminal",
|
||||
"command.unavailable": "{command} cannot run right now",
|
||||
|
|
@ -80,6 +81,7 @@
|
|||
"menu.label": "Main menu",
|
||||
"notification.close": "Close notification",
|
||||
"notification.command.failed": "{command} failed: {message}",
|
||||
"notification.lsp.failed": "The PHP language server stopped: {reason}. Run Restart PHP Language Server to try again.",
|
||||
"notification.project.notLocal": "The chosen folder is not on this computer: {reason}",
|
||||
"notification.project.openFailed": "Cannot open {path}: {reason}",
|
||||
"notification.project.unsavedChanges": "Cannot open {path} while {what} has unsaved changes. Save or close it first.",
|
||||
|
|
@ -101,6 +103,20 @@
|
|||
"palette.label": "Command palette",
|
||||
"palette.noMatches": "No matching commands",
|
||||
"palette.placeholder": "Type a command name",
|
||||
"problems.empty": "No problems found in open files",
|
||||
"problems.file.count": "{count} problems",
|
||||
"problems.list.label": "Problems of the project",
|
||||
"problems.lsp.failed": "Phpactor stopped: {message}",
|
||||
"problems.lsp.restarting": "Phpactor is restarting: {message}",
|
||||
"problems.lsp.starting": "Phpactor is starting…",
|
||||
"problems.lsp.stopped": "No PHP language server is running. It starts when PHP and Phpactor are available.",
|
||||
"problems.position": "line {line}, column {column}",
|
||||
"problems.severity.error": "Error",
|
||||
"problems.severity.hint": "Hint",
|
||||
"problems.severity.info": "Information",
|
||||
"problems.severity.warning": "Warning",
|
||||
"problems.summary": "{errors} errors, {warnings} warnings, {infos} other",
|
||||
"problems.toolWindow.title": "Problems",
|
||||
"project.empty.noFolder": "No folder is open.",
|
||||
"project.openFolder": "Open Folder…",
|
||||
"project.toolWindow.title": "Project",
|
||||
|
|
|
|||
|
|
@ -120,6 +120,20 @@ export type EngineEventPayload =
|
|||
terminalId: unknown;
|
||||
/** Exit code, null when Lutra closed it; unchecked. */
|
||||
code: unknown;
|
||||
}
|
||||
| {
|
||||
kind: "lspStatus";
|
||||
/** `starting`, `ready`, `restarting`, `failed` or `stopped`; unchecked. */
|
||||
state: unknown;
|
||||
/** Why it restarts or failed; unchecked. */
|
||||
message?: unknown;
|
||||
}
|
||||
| {
|
||||
kind: "diagnosticsChanged";
|
||||
/** Project-relative path of the file; unchecked, it comes from the engine. */
|
||||
path: unknown;
|
||||
/** `[{range, severity, message, source?, code?}]`, empty when cleared; unchecked. */
|
||||
items: unknown;
|
||||
};
|
||||
|
||||
/** Callback receiving engine events. */
|
||||
|
|
|
|||
173
ui/tests/editor/lint.test.ts
Normal file
173
ui/tests/editor/lint.test.ts
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
/**
|
||||
* Tests of the editor's diagnostics (M3.3, `lint.ts`): conversion to
|
||||
* CodeMirror positions (CRLF, clamping, order, source and code), the view
|
||||
* plugin applying a path's diagnostics when a view shows the state and on
|
||||
* every publication, clearing, and colours from tokens only.
|
||||
*/
|
||||
import { diagnosticCount, forEachDiagnostic, type Diagnostic } from "@codemirror/lint";
|
||||
import { EditorState, Text } from "@codemirror/state";
|
||||
import { EditorView } from "@codemirror/view";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import {
|
||||
clearDiagnostics,
|
||||
diagnosticsOf,
|
||||
lintExtensions,
|
||||
publishDiagnostics,
|
||||
toCodeMirror,
|
||||
type DiagnosticItem,
|
||||
} from "../../src/components/editor/lint";
|
||||
|
||||
/** Views created by a test, destroyed after it. */
|
||||
let views: EditorView[] = [];
|
||||
|
||||
/**
|
||||
* A diagnostic on one line.
|
||||
*
|
||||
* @param line - 0-based line.
|
||||
* @param from - start column.
|
||||
* @param to - end column.
|
||||
* @param extra - fields to override.
|
||||
*/
|
||||
function item(line: number, from: number, to: number, extra: Partial<DiagnosticItem> = {}): DiagnosticItem {
|
||||
return {
|
||||
range: { start: { line, column: from }, end: { line, column: to } },
|
||||
severity: "error",
|
||||
message: `problem at ${String(line)}:${String(from)}`,
|
||||
...extra,
|
||||
};
|
||||
}
|
||||
|
||||
/** Lets the plugin's microtask run. */
|
||||
async function settle(): Promise<void> {
|
||||
await Promise.resolve();
|
||||
await Promise.resolve();
|
||||
}
|
||||
|
||||
/**
|
||||
* A view showing `doc` as `path`.
|
||||
*
|
||||
* @param path - project-relative path.
|
||||
* @param doc - the text.
|
||||
*/
|
||||
function viewOf(path: string, doc: string): EditorView {
|
||||
const view = new EditorView({
|
||||
state: EditorState.create({ doc, extensions: lintExtensions(path) }),
|
||||
parent: document.body,
|
||||
});
|
||||
views.push(view);
|
||||
return view;
|
||||
}
|
||||
|
||||
/**
|
||||
* The diagnostics in a state.
|
||||
*
|
||||
* @param state - the editor state.
|
||||
*/
|
||||
function shown(state: EditorState): Diagnostic[] {
|
||||
const out: Diagnostic[] = [];
|
||||
forEachDiagnostic(state, (d, from, to) => out.push({ ...d, from, to }));
|
||||
return out;
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
for (const view of views) {
|
||||
view.destroy();
|
||||
}
|
||||
views = [];
|
||||
clearDiagnostics();
|
||||
});
|
||||
|
||||
describe("toCodeMirror", () => {
|
||||
it("converts lines and UTF-16 columns, CRLF-safe and clamped", () => {
|
||||
const doc = Text.of(["<?php", "echo 🦦 $x;", "end"]);
|
||||
const out = toCodeMirror(doc, [
|
||||
item(1, 8, 10, { severity: "warning", source: "phpactor", code: "W1" }),
|
||||
item(0, 0, 3),
|
||||
item(9, 0, 99, { severity: "hint" }),
|
||||
item(2, 2, 1, { severity: "info" }),
|
||||
]);
|
||||
expect(out.map((d) => [d.from, d.to, d.severity])).toEqual([
|
||||
[0, 3, "error"],
|
||||
[14, 16, "warning"],
|
||||
[18, 21, "hint"],
|
||||
[20, 20, "info"],
|
||||
]);
|
||||
expect(out[1]?.source).toBe("phpactor W1");
|
||||
expect(out[0]?.source).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("lintExtensions", () => {
|
||||
it("shows a file's diagnostics and follows every publication", async () => {
|
||||
publishDiagnostics("a.php", [item(1, 0, 4)]);
|
||||
const view = viewOf("a.php", "<?php\necho 1;\n");
|
||||
await settle();
|
||||
expect(shown(view.state).map((d) => [d.from, d.to, d.message])).toEqual([[6, 10, "problem at 1:0"]]);
|
||||
expect(view.dom.querySelector(".cm-lintRange-error")).not.toBeNull();
|
||||
expect(view.dom.querySelector(".cm-gutter-lint .cm-lint-marker-error")).not.toBeNull();
|
||||
|
||||
publishDiagnostics("a.php", [item(0, 0, 5, { severity: "warning" }), item(1, 5, 6)]);
|
||||
expect(diagnosticCount(view.state)).toBe(2);
|
||||
expect(view.dom.querySelector(".cm-lintRange-warning")).not.toBeNull();
|
||||
|
||||
publishDiagnostics("other.php", [item(0, 0, 1)]);
|
||||
expect(diagnosticCount(view.state)).toBe(2);
|
||||
|
||||
publishDiagnostics("a.php", []);
|
||||
expect(diagnosticCount(view.state)).toBe(0);
|
||||
expect(diagnosticsOf("a.php")).toEqual([]);
|
||||
});
|
||||
|
||||
it("brings a background state up to date when it is shown again", async () => {
|
||||
const view = viewOf("a.php", "<?php\n");
|
||||
await settle();
|
||||
const background = view.state;
|
||||
view.setState(EditorState.create({ doc: "x", extensions: lintExtensions("b.php") }));
|
||||
publishDiagnostics("a.php", [item(0, 0, 5)]);
|
||||
expect(diagnosticCount(view.state)).toBe(0);
|
||||
view.setState(background);
|
||||
await settle();
|
||||
expect(diagnosticCount(view.state)).toBe(1);
|
||||
});
|
||||
|
||||
it("maps diagnostics through edits until the next publication", async () => {
|
||||
publishDiagnostics("a.php", [item(0, 6, 10)]);
|
||||
const view = viewOf("a.php", "<?php echo;");
|
||||
await settle();
|
||||
view.dispatch({ changes: { from: 0, insert: "\n\n" } });
|
||||
expect(shown(view.state).map((d) => [d.from, d.to])).toEqual([[8, 12]]);
|
||||
});
|
||||
|
||||
it("clears every file on clearDiagnostics", async () => {
|
||||
publishDiagnostics("a.php", [item(0, 0, 1)]);
|
||||
const view = viewOf("a.php", "<?php");
|
||||
await settle();
|
||||
expect(diagnosticCount(view.state)).toBe(1);
|
||||
clearDiagnostics();
|
||||
expect(diagnosticCount(view.state)).toBe(0);
|
||||
});
|
||||
|
||||
it("stops listening when the view is destroyed", async () => {
|
||||
const view = viewOf("a.php", "<?php");
|
||||
await settle();
|
||||
view.destroy();
|
||||
views = [];
|
||||
expect(() => {
|
||||
publishDiagnostics("a.php", [item(0, 0, 1)]);
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
it("adds nothing without a path", () => {
|
||||
expect(lintExtensions("")).toEqual([]);
|
||||
});
|
||||
|
||||
it("takes its colours from tokens only", () => {
|
||||
const source = readFileSync(join(import.meta.dirname, "..", "..", "src", "components", "editor", "lint.ts"), "utf8");
|
||||
expect(source).not.toMatch(/#[0-9a-fA-F]{3,8}\b|rgba?\(|hsla?\(/);
|
||||
for (const colour of source.matchAll(/var\((--[a-z0-9-]+)\)/g)) {
|
||||
expect(colour[1]).toMatch(/^--lt-/);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
@ -48,6 +48,7 @@ const usedKeys = sourceFiles(SRC).flatMap((file) =>
|
|||
*/
|
||||
const RUNTIME_KEYS = new Set([
|
||||
"notification.command.failed",
|
||||
"notification.lsp.failed",
|
||||
"notification.project.notLocal",
|
||||
"notification.project.openFailed",
|
||||
"notification.project.unsavedChanges",
|
||||
|
|
@ -140,7 +141,7 @@ describe("en.json", () => {
|
|||
it("uses flat dotted keys of known areas with string values", () => {
|
||||
for (const [key, value] of Object.entries(en)) {
|
||||
expect(key).toMatch(
|
||||
/^(app|command|project|editor|common|palette|theme|recovery|notification|settings|find|goto|structure|menu|terminal)\.[A-Za-z0-9]+(\.[A-Za-z0-9]+)*$/,
|
||||
/^(app|command|project|editor|common|palette|theme|recovery|notification|settings|find|goto|structure|menu|terminal|problems)\.[A-Za-z0-9]+(\.[A-Za-z0-9]+)*$/,
|
||||
);
|
||||
expect(typeof value).toBe("string");
|
||||
expect(value.trim()).not.toBe("");
|
||||
|
|
|
|||
|
|
@ -267,6 +267,7 @@ describe("AppMenu", () => {
|
|||
"view.toggleStructure",
|
||||
"find.open",
|
||||
"terminal.open",
|
||||
"problems.open",
|
||||
"settings.open",
|
||||
"goto.fileOpen",
|
||||
"goto.classOpen",
|
||||
|
|
|
|||
|
|
@ -266,6 +266,7 @@ describe("CommandPalette", () => {
|
|||
"goto.symbolOpen",
|
||||
"project.openDialog",
|
||||
"menu.open",
|
||||
"problems.open",
|
||||
"app.quit",
|
||||
"editor.reveal",
|
||||
"settings.open",
|
||||
|
|
|
|||
300
ui/tests/problems/ProblemsToolWindow.test.ts
Normal file
300
ui/tests/problems/ProblemsToolWindow.test.ts
Normal file
|
|
@ -0,0 +1,300 @@
|
|||
/**
|
||||
* Tests of the Problems tool window (M3.3): the store (reading untrusted
|
||||
* items, ordering, `diagnostics.list` on start and project open,
|
||||
* `diagnosticsChanged` replacing and removing files, `lspStatus`, project
|
||||
* close, hand-over to the editor's lint), the window (status line,
|
||||
* grouping, click and Enter revealing through `editor.reveal`, keyboard
|
||||
* navigation), and `problems.open` with its shortcut and tabs next to
|
||||
* Find in the main layout. The engine is a fake behind the mocked Tauri
|
||||
* `invoke` and `listen`.
|
||||
*/
|
||||
import { flushPromises, mount, type VueWrapper } from "@vue/test-utils";
|
||||
import { createPinia, setActivePinia, type Pinia } from "pinia";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const invoke = vi.hoisted(() => vi.fn());
|
||||
const listen = vi.hoisted(() => vi.fn());
|
||||
vi.mock("@tauri-apps/api/core", () => ({ invoke }));
|
||||
vi.mock("@tauri-apps/api/event", () => ({ listen }));
|
||||
|
||||
import { useCommandsStore } from "../../src/commands/store";
|
||||
import { diagnosticsOf } from "../../src/components/editor/lint";
|
||||
import MainLayout from "../../src/components/layout/MainLayout.vue";
|
||||
import ProblemsToolWindow from "../../src/components/problems/ProblemsToolWindow.vue";
|
||||
import { toItems, toStatus, useProblemsStore } from "../../src/components/problems/problems";
|
||||
|
||||
/** Every `engine_execute` call, in order. */
|
||||
let calls: { command: string; params: Record<string, unknown> }[];
|
||||
/** Engine event callbacks of every subscription. */
|
||||
let listeners: ((event: { payload: unknown }) => void)[];
|
||||
/** What `diagnostics.list` answers. */
|
||||
let listed: unknown;
|
||||
/** What `lsp.status` answers. */
|
||||
let status: unknown;
|
||||
/** Pinia of the current test. */
|
||||
let pinia: Pinia;
|
||||
/** Mounted components, unmounted after each test. */
|
||||
let mounted: VueWrapper[];
|
||||
|
||||
/**
|
||||
* Sends an engine event to every subscription.
|
||||
*
|
||||
* @param payload - the event.
|
||||
*/
|
||||
async function emit(payload: unknown): Promise<void> {
|
||||
for (const listener of [...listeners]) {
|
||||
listener({ payload });
|
||||
}
|
||||
await flushPromises();
|
||||
}
|
||||
|
||||
/**
|
||||
* A diagnostic as the engine sends it.
|
||||
*
|
||||
* @param line - 0-based line.
|
||||
* @param severity - its severity.
|
||||
* @param message - its message.
|
||||
*/
|
||||
function diag(line: number, severity: string, message: string): Record<string, unknown> {
|
||||
return {
|
||||
range: { start: { line, column: 2 }, end: { line, column: 6 } },
|
||||
severity,
|
||||
message,
|
||||
source: "phpactor",
|
||||
};
|
||||
}
|
||||
|
||||
/** The params of every call of a command. */
|
||||
function paramsOf(command: string): Record<string, unknown>[] {
|
||||
return calls.filter((c) => c.command === command).map((c) => c.params);
|
||||
}
|
||||
|
||||
/** Mounts the window with a started store and an `editor.reveal` spy. */
|
||||
async function mountProblems(): Promise<{ wrapper: VueWrapper; reveals: unknown[] }> {
|
||||
const reveals: unknown[] = [];
|
||||
useCommandsStore(pinia).provide("editor.reveal", { run: (params) => void reveals.push(params) });
|
||||
useProblemsStore(pinia).start();
|
||||
const wrapper = mount(ProblemsToolWindow, { attachTo: document.body, global: { plugins: [pinia] } });
|
||||
mounted.push(wrapper);
|
||||
await flushPromises();
|
||||
return { wrapper, reveals };
|
||||
}
|
||||
|
||||
/**
|
||||
* The text of every row.
|
||||
*
|
||||
* @param wrapper - the window.
|
||||
*/
|
||||
function rowTexts(wrapper: VueWrapper): string[] {
|
||||
return wrapper.findAll("[data-test=problems-row]").map((row) => row.text());
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
pinia = createPinia();
|
||||
setActivePinia(pinia);
|
||||
calls = [];
|
||||
listeners = [];
|
||||
mounted = [];
|
||||
listed = { files: [] };
|
||||
status = { state: "stopped" };
|
||||
Element.prototype.scrollIntoView = () => undefined;
|
||||
invoke.mockReset();
|
||||
listen.mockReset();
|
||||
listen.mockImplementation((_name: string, callback: (event: { payload: unknown }) => void) => {
|
||||
listeners.push(callback);
|
||||
return Promise.resolve(() => {
|
||||
listeners = listeners.filter((l) => l !== callback);
|
||||
});
|
||||
});
|
||||
invoke.mockImplementation((cmd: string, args?: { command: string; params: Record<string, unknown> }) => {
|
||||
if (cmd === "engine_list_commands") {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
if (cmd !== "engine_execute" || !args) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
calls.push({ command: args.command, params: args.params });
|
||||
if (args.command === "diagnostics.list") {
|
||||
return Promise.resolve(listed);
|
||||
}
|
||||
if (args.command === "lsp.status") {
|
||||
return Promise.resolve(status);
|
||||
}
|
||||
return Promise.resolve(null);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
for (const wrapper of mounted) {
|
||||
wrapper.unmount();
|
||||
}
|
||||
useProblemsStore(pinia).stop();
|
||||
useProblemsStore(pinia).onEvent({ kind: "projectClosed" });
|
||||
useCommandsStore(pinia).stop();
|
||||
});
|
||||
|
||||
describe("problems store", () => {
|
||||
it("drops malformed items and orders errors first, then by position", () => {
|
||||
const items = toItems([
|
||||
diag(9, "warning", "w"),
|
||||
diag(5, "error", "e2"),
|
||||
diag(1, "error", "e1"),
|
||||
{ ...diag(0, "fatal", "bad severity") },
|
||||
{ range: { start: { line: -1, column: 0 }, end: { line: 0, column: 0 } }, severity: "error", message: "neg" },
|
||||
{ range: null, severity: "error", message: "no range" },
|
||||
{ ...diag(0, "info", "no message"), message: 4 },
|
||||
"junk",
|
||||
diag(3, "hint", "h"),
|
||||
]);
|
||||
expect(items.map((i) => i.message)).toEqual(["e1", "e2", "w", "h"]);
|
||||
expect(toItems("nope")).toEqual([]);
|
||||
expect(toStatus({ state: "failed", message: "crashed" })).toEqual({ state: "failed", message: "crashed" });
|
||||
expect(toStatus({ state: "exploded" })).toBeNull();
|
||||
});
|
||||
|
||||
it("loads on start, follows diagnosticsChanged and hands files to the editor", async () => {
|
||||
listed = { files: [{ path: "src/b.php", items: [diag(0, "error", "B")] }, { path: 3, items: [] }] };
|
||||
status = { state: "ready" };
|
||||
const problems = useProblemsStore();
|
||||
problems.start();
|
||||
await flushPromises();
|
||||
expect(paramsOf("diagnostics.list")).toEqual([{}]);
|
||||
expect(problems.lsp).toEqual({ state: "ready", message: null });
|
||||
expect(problems.files.map((f) => f.path)).toEqual(["src/b.php"]);
|
||||
expect(diagnosticsOf("src/b.php")).toHaveLength(1);
|
||||
|
||||
await emit({ kind: "diagnosticsChanged", path: "a.php", items: [diag(2, "warning", "A")] });
|
||||
expect(problems.files.map((f) => f.path)).toEqual(["a.php", "src/b.php"]);
|
||||
expect(problems.counts).toEqual({ error: 1, warning: 1, info: 0, hint: 0 });
|
||||
expect(diagnosticsOf("a.php").map((i) => i.message)).toEqual(["A"]);
|
||||
|
||||
await emit({ kind: "diagnosticsChanged", path: "src/b.php", items: [] });
|
||||
expect(problems.files.map((f) => f.path)).toEqual(["a.php"]);
|
||||
expect(diagnosticsOf("src/b.php")).toEqual([]);
|
||||
|
||||
await emit({ kind: "diagnosticsChanged", path: 7, items: [diag(0, "error", "x")] });
|
||||
expect(problems.files).toHaveLength(1);
|
||||
|
||||
await emit({ kind: "lspStatus", state: "restarting", message: "exit 7" });
|
||||
expect(problems.lsp).toEqual({ state: "restarting", message: "exit 7" });
|
||||
|
||||
await emit({ kind: "projectClosed" });
|
||||
expect(problems.files).toEqual([]);
|
||||
expect(problems.lsp).toBeNull();
|
||||
expect(diagnosticsOf("a.php")).toEqual([]);
|
||||
|
||||
listed = { files: [{ path: "c.php", items: [diag(0, "info", "C")] }] };
|
||||
await emit({ kind: "projectOpened", root: "/p", name: "p" });
|
||||
expect(problems.files.map((f) => f.path)).toEqual(["c.php"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("ProblemsToolWindow", () => {
|
||||
it("shows the server state while there is nothing to list", async () => {
|
||||
const { wrapper } = await mountProblems();
|
||||
const line = (): string => wrapper.get("[data-test=problems-status]").text();
|
||||
expect(line()).toContain("No PHP language server is running");
|
||||
await emit({ kind: "lspStatus", state: "starting" });
|
||||
expect(line()).toBe("Phpactor is starting…");
|
||||
await emit({ kind: "lspStatus", state: "ready" });
|
||||
expect(line()).toBe("No problems found in open files");
|
||||
await emit({ kind: "lspStatus", state: "failed", message: "php.exe vanished" });
|
||||
expect(line()).toBe("Phpactor stopped: php.exe vanished");
|
||||
});
|
||||
|
||||
it("groups by file with counts, severity icons, origin and position", async () => {
|
||||
status = { state: "ready" };
|
||||
const { wrapper } = await mountProblems();
|
||||
await emit({
|
||||
kind: "diagnosticsChanged",
|
||||
path: "src/Service.php",
|
||||
items: [diag(4, "warning", "Unused variable"), { ...diag(1, "error", "Undefined method"), code: "E12" }],
|
||||
});
|
||||
await emit({ kind: "diagnosticsChanged", path: "a.php", items: [diag(0, "hint", "Could be final")] });
|
||||
expect(wrapper.get("[data-test=problems-status]").text()).toBe("1 errors, 1 warnings, 1 other");
|
||||
const files = wrapper.findAll("[data-test=problems-file]").map((f) => f.text());
|
||||
expect(files[0]).toContain("a.php");
|
||||
expect(files[1]).toContain("Service.php");
|
||||
expect(files[1]).toContain("src");
|
||||
expect(files[1]).toContain("2");
|
||||
expect(rowTexts(wrapper)).toEqual([
|
||||
"Could be finalphpactorline 1, column 3",
|
||||
"Undefined methodphpactor E12line 2, column 3",
|
||||
"Unused variablephpactorline 5, column 3",
|
||||
]);
|
||||
const rows = wrapper.findAll("[data-test=problems-row]");
|
||||
expect(rows[1]?.attributes("data-severity")).toBe("error");
|
||||
expect(rows[1]?.find("[role=img]").attributes("aria-label")).toBe("Error");
|
||||
});
|
||||
|
||||
it("reveals a problem on click and with the keyboard", async () => {
|
||||
const { wrapper, reveals } = await mountProblems();
|
||||
await emit({ kind: "diagnosticsChanged", path: "a.php", items: [diag(0, "error", "one"), diag(3, "error", "two")] });
|
||||
await emit({ kind: "diagnosticsChanged", path: "b.php", items: [diag(7, "warning", "three")] });
|
||||
await wrapper.findAll("[data-test=problems-row]")[1]?.trigger("click");
|
||||
await flushPromises();
|
||||
expect(reveals).toEqual([{ path: "a.php", line: 3, column: 2 }]);
|
||||
const list = wrapper.get("[data-test=problems-list]");
|
||||
await list.trigger("keydown", { key: "ArrowDown" });
|
||||
expect(wrapper.find("[aria-selected=true]").text()).toContain("three");
|
||||
await list.trigger("keydown", { key: "Home" });
|
||||
expect(wrapper.find("[aria-selected=true]").text()).toContain("one");
|
||||
await list.trigger("keydown", { key: "End" });
|
||||
await list.trigger("keydown", { key: "Enter" });
|
||||
await flushPromises();
|
||||
expect(reveals.at(-1)).toEqual({ path: "b.php", line: 7, column: 2 });
|
||||
expect(list.attributes("aria-activedescendant")).toBe("problem-row-2");
|
||||
});
|
||||
});
|
||||
|
||||
describe("problems.open", () => {
|
||||
/** Mounts the main layout with the commands store started. */
|
||||
async function mountLayout(): Promise<VueWrapper> {
|
||||
const wrapper = mount(MainLayout, {
|
||||
attachTo: document.body,
|
||||
global: { plugins: [pinia], stubs: { ProjectToolWindow: true, StatusBar: true } },
|
||||
});
|
||||
mounted.push(wrapper);
|
||||
await useCommandsStore(pinia).start();
|
||||
await flushPromises();
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
it("is registered with its own shortcut and menu path", async () => {
|
||||
await mountLayout();
|
||||
const registered = paramsOf("ui.registerCommands")[0]?.commands as { id: string; defaultShortcut?: string; menuPath?: string }[];
|
||||
const command = registered.find((c) => c.id === "problems.open");
|
||||
expect(command?.defaultShortcut).toBe("Mod+Alt+P");
|
||||
expect(command?.menuPath).toBe("View/Problems");
|
||||
});
|
||||
|
||||
it("opens from the shortcut, shares the panel with Find as tabs and closes", async () => {
|
||||
const wrapper = await mountLayout();
|
||||
expect(wrapper.find("[data-test=bottom-panel]").exists()).toBe(false);
|
||||
window.dispatchEvent(new KeyboardEvent("keydown", { key: "p", code: "KeyP", ctrlKey: true, altKey: true, bubbles: true }));
|
||||
await flushPromises();
|
||||
expect(wrapper.find("[data-test=bottom-panel]").exists()).toBe(true);
|
||||
expect(wrapper.get("[data-test=problems]").isVisible()).toBe(true);
|
||||
expect(document.activeElement).toBe(wrapper.get("[data-test=problems-list]").element);
|
||||
expect(wrapper.find("[data-test=bottom-tab-problems]").exists()).toBe(false);
|
||||
|
||||
await emit({ kind: "uiCommand", id: "find.open", params: {} });
|
||||
expect(wrapper.get("[data-test=bottom-tab-problems]").attributes("aria-selected")).toBe("false");
|
||||
expect(wrapper.get("[data-test=bottom-tab-find]").attributes("aria-selected")).toBe("true");
|
||||
await wrapper.get("[data-test=bottom-tab-problems]").trigger("click");
|
||||
expect(wrapper.get("[data-test=problems]").isVisible()).toBe(true);
|
||||
expect(wrapper.get("[data-test=find]").isVisible()).toBe(false);
|
||||
|
||||
await wrapper.get("[data-test=bottom-panel-close]").trigger("click");
|
||||
expect(wrapper.find("[data-test=bottom-tab-problems]").exists()).toBe(false);
|
||||
expect(wrapper.get("[data-test=find]").isVisible()).toBe(true);
|
||||
await wrapper.get("[data-test=bottom-panel-close]").trigger("click");
|
||||
expect(wrapper.find("[data-test=bottom-panel]").exists()).toBe(false);
|
||||
});
|
||||
|
||||
it("opens from an agent's uiCommand", async () => {
|
||||
const wrapper = await mountLayout();
|
||||
await emit({ kind: "uiCommand", id: "problems.open", params: {} });
|
||||
expect(wrapper.find("[data-test=problems]").exists()).toBe(true);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue