Skip to content

Commit 776935d

Browse files
committed
fix: apply review feedback to all extensions
1 parent dd06d56 commit 776935d

File tree

16 files changed

+563
-482
lines changed

16 files changed

+563
-482
lines changed

builtin/curator/grep.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ async function getAbsolutePathOf(
107107
expr: string,
108108
signal?: AbortSignal,
109109
): Promise<string> {
110-
const path = await fn.expand(denops, expr) as string;
110+
const path = await fn.expand(denops, expr);
111111
signal?.throwIfAborted();
112112
const abspath = await fn.fnamemodify(denops, path, ":p");
113113
return abspath;

builtin/renderer/file_info.ts

Lines changed: 72 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -59,90 +59,88 @@ export function fileInfo(
5959
const colorize = options.colorize ?? false;
6060

6161
return defineRenderer(async (_denops, { items }) => {
62-
// Process items in parallel
63-
await Promise.all(
64-
items.map(async (item) => {
65-
const { path } = item.detail;
66-
const parts: string[] = [];
67-
68-
try {
69-
// Get file stats
70-
const stat = await Deno.stat(path);
71-
72-
// Add requested fields
73-
for (const field of fields) {
74-
switch (field) {
75-
case "size": {
76-
const sizeStr = stat.isFile
77-
? formatBytes(stat.size)
78-
: stat.isDirectory
79-
? "-"
80-
: "0B";
81-
parts.push(sizeStr.padStart(fieldWidths.size));
82-
break;
83-
}
62+
// Process items sequentially to avoid file system issues
63+
for (const item of items) {
64+
const { path } = item.detail;
65+
const parts: string[] = [];
66+
67+
try {
68+
// Get file stats
69+
const stat = await Deno.stat(path);
70+
71+
// Add requested fields
72+
for (const field of fields) {
73+
switch (field) {
74+
case "size": {
75+
const sizeStr = stat.isFile
76+
? formatBytes(stat.size)
77+
: stat.isDirectory
78+
? "-"
79+
: "0B";
80+
parts.push(sizeStr.padStart(fieldWidths.size));
81+
break;
82+
}
8483

85-
case "modified": {
86-
const mtime = stat.mtime;
87-
let timeStr: string;
88-
if (mtime && relativeTime) {
89-
timeStr = formatRelativeTime(mtime);
90-
} else if (mtime) {
91-
timeStr = formatDate(mtime);
92-
} else {
93-
timeStr = "-";
94-
}
95-
parts.push(timeStr.padEnd(fieldWidths.modified));
96-
break;
84+
case "modified": {
85+
const mtime = stat.mtime;
86+
let timeStr: string;
87+
if (mtime && relativeTime) {
88+
timeStr = formatRelativeTime(mtime);
89+
} else if (mtime) {
90+
timeStr = formatDate(mtime);
91+
} else {
92+
timeStr = "-";
9793
}
94+
parts.push(timeStr.padEnd(fieldWidths.modified));
95+
break;
96+
}
9897

99-
case "permissions": {
100-
const permsStr = formatPermissions(stat.mode);
101-
parts.push(permsStr.padEnd(fieldWidths.permissions));
102-
break;
103-
}
98+
case "permissions": {
99+
const permsStr = formatPermissions(stat.mode);
100+
parts.push(permsStr.padEnd(fieldWidths.permissions));
101+
break;
102+
}
104103

105-
case "type": {
106-
const typeStr = stat.isDirectory
107-
? "dir"
108-
: stat.isFile
109-
? "file"
110-
: stat.isSymlink
111-
? "link"
112-
: "other";
113-
parts.push(typeStr.padEnd(fieldWidths.type));
114-
break;
115-
}
104+
case "type": {
105+
const typeStr = stat.isDirectory
106+
? "dir"
107+
: stat.isFile
108+
? "file"
109+
: stat.isSymlink
110+
? "link"
111+
: "other";
112+
parts.push(typeStr.padEnd(fieldWidths.type));
113+
break;
116114
}
117115
}
116+
}
118117

119-
// Combine parts and append to label
120-
const info = parts.join(" ");
121-
if (colorize) {
122-
// Add color based on file type
123-
if (stat.isDirectory) {
124-
item.label = `${item.label} \x1b[34m${info}\x1b[0m`;
125-
} else if (stat.isSymlink) {
126-
item.label = `${item.label} \x1b[36m${info}\x1b[0m`;
127-
} else if ((stat.mode ?? 0) & 0o111) {
128-
// Executable
129-
item.label = `${item.label} \x1b[32m${info}\x1b[0m`;
130-
} else {
131-
item.label = `${item.label} \x1b[90m${info}\x1b[0m`;
132-
}
118+
// Combine parts and append to label
119+
const info = parts.join(" ");
120+
if (colorize) {
121+
// Add color based on file type
122+
if (stat.isDirectory) {
123+
item.label = `${item.label} \x1b[34m${info}\x1b[0m`;
124+
} else if (stat.isSymlink) {
125+
item.label = `${item.label} \x1b[36m${info}\x1b[0m`;
126+
} else if ((stat.mode ?? 0) & 0o111) {
127+
// Executable
128+
item.label = `${item.label} \x1b[32m${info}\x1b[0m`;
133129
} else {
134-
item.label = `${item.label} ${info}`;
130+
item.label = `${item.label} \x1b[90m${info}\x1b[0m`;
135131
}
136-
} catch {
137-
// If stat fails, add placeholder
138-
const placeholder = fields.map((field) => {
139-
const width = fieldWidths[field as keyof typeof fieldWidths] ?? 10;
140-
return "-".padEnd(width);
141-
}).join(" ");
142-
item.label = `${item.label} ${placeholder}`;
132+
} else {
133+
item.label = `${item.label} ${info}`;
143134
}
144-
}),
145-
);
135+
} catch {
136+
// If stat fails, add placeholder
137+
const placeholder = fields.map((field) => {
138+
const width = fieldWidths[field as keyof typeof fieldWidths] ?? 10;
139+
return "-".padEnd(width);
140+
}).join(" ");
141+
item.label = `${item.label} ${placeholder}`;
142+
}
143+
}
146144
});
147145
}
148146

builtin/source/autocmd.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as fn from "@denops/std/function";
2+
13
import { defineSource, type Source } from "../../source.ts";
24

35
type Detail = {
@@ -56,6 +58,23 @@ export type AutocmdOptions = {
5658
showFullCommand?: boolean;
5759
};
5860

61+
/**
62+
* Creates a Source that generates items from Vim autocmds.
63+
*
64+
* This Source retrieves all defined autocmds and generates items
65+
* for each one, showing their events, patterns, and commands.
66+
*
67+
* @param options - Options to customize autocmd listing.
68+
* @returns A Source that generates items representing autocmds.
69+
*/
70+
// Regular expressions for parsing autocmd output
71+
const PATTERNS = {
72+
GROUP_HEADER: /^--- Autocommands ---$/,
73+
NAMED_GROUP_HEADER: /^(\w+)\s+Autocommands for "(.+)"$/,
74+
EVENT_HEADER: /^(\w+)$/,
75+
AUTOCMD_LINE: /^\s*(\S+)\s+(.+)$/,
76+
} as const;
77+
5978
/**
6079
* Creates a Source that generates items from Vim autocmds.
6180
*
@@ -75,8 +94,8 @@ export function autocmd(
7594

7695
return defineSource(async function* (denops, _params, { signal }) {
7796
// Get autocmd output
78-
const autocmdCmd = filterGroup ? `:autocmd ${filterGroup}` : ":autocmd";
79-
const output = await denops.call("execute", autocmdCmd) as string;
97+
const autocmdCmd = filterGroup ? `autocmd ${filterGroup}` : "autocmd";
98+
const output = await fn.execute(denops, autocmdCmd);
8099
signal?.throwIfAborted();
81100

82101
// Parse autocmd output
@@ -96,31 +115,28 @@ export function autocmd(
96115
if (!trimmed) continue;
97116

98117
// Check for group header
99-
const groupMatch = trimmed.match(/^--- Autocommands ---$/);
100-
if (groupMatch) {
118+
if (PATTERNS.GROUP_HEADER.test(trimmed)) {
101119
currentGroup = "";
102120
continue;
103121
}
104122

105123
// Check for named group header
106-
const namedGroupMatch = trimmed.match(
107-
/^(\w+)\s+Autocommands for "(.+)"$/,
108-
);
124+
const namedGroupMatch = trimmed.match(PATTERNS.NAMED_GROUP_HEADER);
109125
if (namedGroupMatch) {
110126
currentGroup = namedGroupMatch[1];
111127
continue;
112128
}
113129

114130
// Check for event header
115-
const eventMatch = trimmed.match(/^(\w+)$/);
131+
const eventMatch = trimmed.match(PATTERNS.EVENT_HEADER);
116132
if (eventMatch && !trimmed.includes(" ")) {
117133
currentEvent = eventMatch[1];
118134
continue;
119135
}
120136

121137
// Parse autocmd line
122138
// Format: " pattern command"
123-
const cmdMatch = trimmed.match(/^\s*(\S+)\s+(.+)$/);
139+
const cmdMatch = trimmed.match(PATTERNS.AUTOCMD_LINE);
124140
if (cmdMatch && currentEvent) {
125141
const [, pattern, command] = cmdMatch;
126142

builtin/source/colorscheme.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ export type ColorschemeOptions = {
2020
* @default true
2121
*/
2222
markCurrent?: boolean;
23+
24+
/**
25+
* The indicator string for the current colorscheme.
26+
* @default "> "
27+
*/
28+
indicator?: string;
2329
};
2430

2531
/**
@@ -39,22 +45,23 @@ export function colorscheme(
3945
// Get list of all colorschemes
4046
const colorschemes = await fn.getcompletion(
4147
denops,
42-
"colors",
48+
"",
4349
"color",
4450
) as string[];
4551
signal?.throwIfAborted();
4652

4753
// Get current colorscheme if needed
4854
let currentColorscheme = "";
4955
if (markCurrent) {
50-
const colors = await denops.call("execute", "colorscheme") as string;
56+
const colors = await fn.execute(denops, "colorscheme") as string;
5157
// Extract colorscheme name from output (removes whitespace and newlines)
5258
currentColorscheme = colors.trim();
5359
}
5460

5561
const items = colorschemes.map((name, index) => {
5662
const isCurrent = markCurrent && name === currentColorscheme;
57-
const prefix = isCurrent ? "▸ " : " ";
63+
const indicator = options.indicator ?? "> ";
64+
const prefix = isCurrent ? indicator : " ".repeat(indicator.length);
5865
const suffix = isCurrent ? " (current)" : "";
5966

6067
return {

builtin/source/command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export function command(
6565

6666
return defineSource(async function* (denops, _params, { signal }) {
6767
// Get user commands
68-
const commandOutput = await denops.call("execute", "command") as string;
68+
const commandOutput = await fn.execute(denops, "command");
6969
signal?.throwIfAborted();
7070

7171
// Parse command output

0 commit comments

Comments
 (0)