Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,135 changes: 1,135 additions & 0 deletions crates/fresh-editor/plugins/lib/controls.ts

Large diffs are not rendered by default.

82 changes: 49 additions & 33 deletions crates/fresh-editor/plugins/lib/finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export function defaultFuzzyFilter<T>(
items: T[],
query: string,
format: (item: T, index: number) => DisplayEntry,
maxResults: number = 100
maxResults: number = 100,
): T[] {
if (query === "" || query.trim() === "") {
return items.slice(0, maxResults);
Expand Down Expand Up @@ -296,7 +296,7 @@ export function parseGrepLine(line: string): {
*/
export function parseGrepOutput(
stdout: string,
maxResults: number = 100
maxResults: number = 100,
): Array<{ file: string; line: number; column: number; content: string }> {
const results: Array<{
file: string;
Expand Down Expand Up @@ -462,10 +462,12 @@ export class Finder<T> {
this.editor.startPromptWithInitial(
options.title,
this.config.id,
options.initialQuery
options.initialQuery,
);
} else {
this.editor.debug(`[Finder] calling startPrompt with title="${options.title}", id="${this.config.id}"`);
this.editor.debug(
`[Finder] calling startPrompt with title="${options.title}", id="${this.config.id}"`,
);
const result = this.editor.startPrompt(options.title, this.config.id);
this.editor.debug(`[Finder] startPrompt returned: ${result}`);
}
Expand Down Expand Up @@ -598,7 +600,10 @@ export class Finder<T> {

// Register event handlers
this.editor.on("prompt_changed", `${this.handlerPrefix}_changed`);
this.editor.on("prompt_selection_changed", `${this.handlerPrefix}_selection`);
this.editor.on(
"prompt_selection_changed",
`${this.handlerPrefix}_selection`,
);
this.editor.on("prompt_confirmed", `${this.handlerPrefix}_confirmed`);
this.editor.on("prompt_cancelled", `${this.handlerPrefix}_cancelled`);
}
Expand All @@ -624,7 +629,7 @@ export class Finder<T> {
this.allItems,
query,
this.config.format,
this.config.maxResults
this.config.maxResults,
);
}

Expand All @@ -649,7 +654,7 @@ export class Finder<T> {

private async runSearch(
query: string,
source: SearchSource<T>
source: SearchSource<T>,
): Promise<void> {
const debounceMs = source.debounceMs ?? 150;
const minQueryLength = source.minQueryLength ?? 2;
Expand Down Expand Up @@ -711,7 +716,7 @@ export class Finder<T> {
// Parse as grep output by default
const parsed = parseGrepOutput(
result.stdout,
this.config.maxResults
this.config.maxResults,
) as unknown as T[];
this.updatePromptResults(parsed);

Expand Down Expand Up @@ -772,7 +777,7 @@ export class Finder<T> {
description: entry.description,
value: `${i}`,
disabled: false,
})
}),
);

this.editor.setPromptSuggestions(suggestions);
Expand Down Expand Up @@ -810,10 +815,10 @@ export class Finder<T> {
this.editor.openFile(
entry.location.file,
entry.location.line,
entry.location.column
entry.location.column,
);
this.editor.setStatus(
`Opened ${entry.location.file}:${entry.location.line}`
`Opened ${entry.location.file}:${entry.location.line}`,
);
}
} else {
Expand Down Expand Up @@ -883,13 +888,18 @@ export class Finder<T> {

const contextLines = this.getContextLines();
const startLine = Math.max(0, entry.location.line - 1 - contextLines);
const endLine = Math.min(lines.length, entry.location.line + contextLines);
const endLine = Math.min(
lines.length,
entry.location.line + contextLines,
);

const entries: TextPropertyEntry[] = [];

// Header
entries.push({
text: ` ${entry.location.file}:${entry.location.line}:${entry.location.column ?? 1}\n`,
text: ` ${entry.location.file}:${entry.location.line}:${
entry.location.column ?? 1
}\n`,
properties: { type: "header" },
});
entries.push({
Expand Down Expand Up @@ -920,7 +930,7 @@ export class Finder<T> {
this.previewModeName,
"special",
[["q", "close_buffer"]],
true
true,
);

// Create preview split
Expand All @@ -945,7 +955,10 @@ export class Finder<T> {
}
} else {
// Update existing preview
this.editor.setVirtualBufferContent(this.previewState.bufferId, entries);
this.editor.setVirtualBufferContent(
this.previewState.bufferId,
entries,
);
}
} catch (e) {
this.editor.debug(`[Finder] Failed to update preview: ${e}`);
Expand Down Expand Up @@ -978,7 +991,7 @@ export class Finder<T> {
["Return", `${this.handlerPrefix}_panel_select`],
["Escape", `${this.handlerPrefix}_panel_close`],
],
true
true,
);

// Select handler
Expand Down Expand Up @@ -1014,7 +1027,7 @@ export class Finder<T> {
const itemIndex = self.panelState.lineToItemIndex.get(data.line);
if (itemIndex !== undefined && itemIndex < self.panelState.items.length) {
self.editor.setStatus(
`Item ${itemIndex + 1}/${self.panelState.items.length}`
`Item ${itemIndex + 1}/${self.panelState.items.length}`,
);
}
};
Expand Down Expand Up @@ -1064,7 +1077,9 @@ export class Finder<T> {

try {
const result = await this.editor.createVirtualBufferInSplit({
name: `*${this.config.id.charAt(0).toUpperCase() + this.config.id.slice(1)}*`,
name: `*${
this.config.id.charAt(0).toUpperCase() + this.config.id.slice(1)
}*`,
mode: this.modeName,
readOnly: true,
entries,
Expand All @@ -1082,7 +1097,9 @@ export class Finder<T> {
this.applyPanelHighlighting();

const count = this.panelState.items.length;
this.editor.setStatus(`${title}: ${count} item${count !== 1 ? "s" : ""}`);
this.editor.setStatus(
`${title}: ${count} item${count !== 1 ? "s" : ""}`,
);
} else {
this.editor.setStatus("Failed to open panel");
}
Expand Down Expand Up @@ -1180,16 +1197,15 @@ export class Finder<T> {
}

private buildItemEntry(entry: DisplayEntry): TextPropertyEntry {
const severityIcon =
entry.severity === "error"
? "[E]"
: entry.severity === "warning"
? "[W]"
: entry.severity === "info"
? "[I]"
: entry.severity === "hint"
? "[H]"
: "";
const severityIcon = entry.severity === "error"
? "[E]"
: entry.severity === "warning"
? "[W]"
: entry.severity === "info"
? "[I]"
: entry.severity === "hint"
? "[H]"
: "";

const prefix = severityIcon ? `${severityIcon} ` : " ";
const desc = entry.description ? ` ${entry.description}` : "";
Expand Down Expand Up @@ -1220,7 +1236,7 @@ export class Finder<T> {

private onPanelSelect(): void {
const itemIndex = this.panelState.lineToItemIndex.get(
this.panelState.cursorLine
this.panelState.cursorLine,
);
if (itemIndex === undefined) {
this.editor.setStatus("No item selected");
Expand All @@ -1240,10 +1256,10 @@ export class Finder<T> {
this.editor.openFile(
entry.location.file,
entry.location.line,
entry.location.column
entry.location.column,
);
this.editor.setStatus(
`Jumped to ${entry.location.file}:${entry.location.line}`
`Jumped to ${entry.location.file}:${entry.location.line}`,
);
}
}
Expand Down Expand Up @@ -1416,7 +1432,7 @@ export function getRelativePath(editor: EditorAPI, filePath: string): string {
* Create a simple live provider from a getter function
*/
export function createLiveProvider<T>(
getItems: () => T[]
getItems: () => T[],
): FinderProvider<T> & { notify: () => void } {
const listeners: Array<() => void> = [];

Expand Down
Loading
Loading