Skip to content

Commit dd06d56

Browse files
lambdalisueclaude
andcommitted
fix(source): fix type error in git status source
Handle unknown error type properly by checking if it's an Error instance before accessing the name property. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> fix: resolve linting issues and remove unused imports - Remove unused 'relative' import from file_info.ts and git_status.ts - Implement custom formatBytes function instead of external dependency - Fix prefer-const violations in git_status.ts and command.ts - Prefix unused variable with underscore in loclist.ts 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> fix: resolve all type checking and linting issues - Fix type errors in refiners by properly handling async iterables - Fix type errors in grep/vimgrep sources by using type assertions - Remove unused imports and variables - Fix async function without await in smart_grep renderer - Ensure all code passes type checking and linting 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> fix: format code with deno fmt 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 8c025e7 commit dd06d56

File tree

9 files changed

+53
-26
lines changed

9 files changed

+53
-26
lines changed

builtin/refiner/buffer_info.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as fn from "@denops/std/function";
2+
import type { IdItem } from "@vim-fall/core/item";
23
import { defineRefiner, type Refiner } from "../../refiner.ts";
34

45
type Detail = {
@@ -84,7 +85,13 @@ export function bufferInfo(
8485
const minLines = options.minLines;
8586
const maxLines = options.maxLines;
8687

87-
return defineRefiner(async (denops, { items }) => {
88+
return defineRefiner(async function* (denops, { items }) {
89+
// Convert async iterable to array first
90+
const itemsArray: IdItem<Detail>[] = [];
91+
for await (const item of items) {
92+
itemsArray.push(item);
93+
}
94+
8895
// Get all buffer info at once for efficiency
8996
const allBufinfo = await fn.getbufinfo(denops);
9097
const bufInfoMap = new Map(
@@ -93,7 +100,7 @@ export function bufferInfo(
93100

94101
// Process items and filter
95102
const results = await Promise.all(
96-
items.map(async (item) => {
103+
itemsArray.map(async (item) => {
97104
const { bufnr } = item.detail;
98105
const bufinfo = bufInfoMap.get(bufnr);
99106

@@ -102,17 +109,17 @@ export function bufferInfo(
102109
}
103110

104111
// Check modification status
105-
if (modified !== undefined && bufinfo.changed !== (modified ? 1 : 0)) {
112+
if (modified !== undefined && !!bufinfo.changed !== modified) {
106113
return null;
107114
}
108115

109116
// Check listed status
110-
if (listed !== undefined && bufinfo.listed !== (listed ? 1 : 0)) {
117+
if (listed !== undefined && !!bufinfo.listed !== listed) {
111118
return null;
112119
}
113120

114121
// Check loaded status
115-
if (loaded !== undefined && bufinfo.loaded !== (loaded ? 1 : 0)) {
122+
if (loaded !== undefined && !!bufinfo.loaded !== loaded) {
116123
return null;
117124
}
118125

@@ -180,6 +187,9 @@ export function bufferInfo(
180187
);
181188

182189
// Return only non-null items
183-
return results.filter((item) => item !== null);
190+
const filtered = results.filter((item): item is IdItem<Detail> =>
191+
item !== null
192+
);
193+
yield* filtered;
184194
});
185195
}

builtin/refiner/file_info.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { IdItem } from "@vim-fall/core/item";
12
import { defineRefiner, type Refiner } from "../../refiner.ts";
23
import { extname } from "@std/path/extname";
34

@@ -85,15 +86,22 @@ export function fileInfo(
8586
const excludeHidden = options.excludeHidden ?? false;
8687
const excludePatterns = options.excludePatterns ?? [];
8788

88-
return defineRefiner(async (_denops, { items }) => {
89+
return defineRefiner(async function* (_denops, { items }) {
90+
// Convert async iterable to array first
91+
const itemsArray: IdItem<Detail>[] = [];
92+
for await (const item of items) {
93+
itemsArray.push(item);
94+
}
95+
8996
// Process items in parallel and filter
9097
const results = await Promise.all(
91-
items.map(async (item) => {
98+
itemsArray.map(async (item) => {
9299
const { path } = item.detail;
93100

94101
// Check if hidden file should be excluded
95102
if (
96-
excludeHidden && path.split("/").some((part) => part.startsWith("."))
103+
excludeHidden &&
104+
path.split("/").some((part: string) => part.startsWith("."))
97105
) {
98106
return null;
99107
}
@@ -173,6 +181,9 @@ export function fileInfo(
173181
);
174182

175183
// Return only non-null items
176-
return results.filter((item) => item !== null);
184+
const filtered = results.filter((item): item is IdItem<Detail> =>
185+
item !== null
186+
);
187+
yield* filtered;
177188
});
178189
}

builtin/renderer/file_info.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import { format } from "@std/fmt/bytes";
2-
import { relative } from "@std/path/relative";
3-
41
import { defineRenderer, type Renderer } from "../../renderer.ts";
52

63
type Detail = {
@@ -77,7 +74,7 @@ export function fileInfo(
7774
switch (field) {
7875
case "size": {
7976
const sizeStr = stat.isFile
80-
? format(stat.size, { minimumFractionDigits: 0 })
77+
? formatBytes(stat.size)
8178
: stat.isDirectory
8279
? "-"
8380
: "0B";
@@ -149,6 +146,19 @@ export function fileInfo(
149146
});
150147
}
151148

149+
/**
150+
* Formats bytes to a human-readable string.
151+
*/
152+
function formatBytes(bytes: number): string {
153+
if (bytes === 0) return "0B";
154+
155+
const units = ["B", "KB", "MB", "GB", "TB"];
156+
const k = 1024;
157+
const i = Math.floor(Math.log(bytes) / Math.log(k));
158+
159+
return `${(bytes / Math.pow(k, i)).toFixed(1)}${units[i]}`;
160+
}
161+
152162
/**
153163
* Formats a date to a relative time string.
154164
*/

builtin/renderer/smart_grep.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { defineRenderer, type Renderer } from "../../renderer.ts";
22
import { dirname } from "@std/path/dirname";
3-
import { basename } from "@std/path/basename";
43

54
type Detail = {
65
/**
@@ -82,7 +81,7 @@ export function smartGrep(
8281
const colorize = options.colorize ?? false;
8382
const alignColumns = options.alignColumns ?? true;
8483

85-
return defineRenderer(async (_denops, { items }) => {
84+
return defineRenderer((_denops, { items }) => {
8685
if (items.length === 0) {
8786
return;
8887
}
@@ -150,7 +149,6 @@ export function smartGrep(
150149

151150
// Format path
152151
const displayPath = useRelativePaths ? path : path;
153-
const filename = basename(displayPath);
154152
const pathPart = alignColumns
155153
? displayPath.padEnd(maxPathWidth)
156154
: displayPath;

builtin/source/command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export function command(
7272
const lines = commandOutput.trim().split("\n").filter((line) =>
7373
line.trim()
7474
);
75-
let items: Array<{
75+
const items: Array<{
7676
id: number;
7777
value: string;
7878
detail: Detail;

builtin/source/git_status.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as fn from "@denops/std/function";
22
import { join } from "@std/path/join";
3-
import { relative } from "@std/path/relative";
43

54
import { defineSource, type Source } from "../../source.ts";
65

@@ -125,7 +124,7 @@ export function gitStatus(
125124
const filename = line.substring(3);
126125

127126
// Determine status code and description
128-
let status = `${staged}${unstaged}`;
127+
const status = `${staged}${unstaged}`;
129128
let statusDescription = "";
130129
let isStaged = false;
131130
let isUnstaged = false;
@@ -197,7 +196,7 @@ export function gitStatus(
197196
yield* items;
198197
} catch (err) {
199198
// Handle errors gracefully
200-
if (err.name === "NotFound") {
199+
if (err instanceof Error && err.name === "NotFound") {
201200
// Git not installed - silently return empty
202201
return;
203202
}

builtin/source/grep.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export function grep(
100100
signal?.throwIfAborted();
101101

102102
// Get results from quickfix list
103-
const qflist = await fn.getqflist(denops) as Array<{
103+
const qflist = await fn.getqflist(denops) as unknown as Array<{
104104
bufnr: number;
105105
lnum: number;
106106
col: number;
@@ -146,7 +146,6 @@ export function grep(
146146
} else {
147147
// Execute grep directly and parse output
148148
const grepprg = await denops.eval("&grepprg") as string;
149-
const grepformat = await denops.eval("&grepformat") as string;
150149

151150
// This is a simplified implementation
152151
// In practice, we'd need to properly parse grepformat

builtin/source/loclist.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export function loclist(
8383
const winnr = await denops.call("win_id2win", winid) as number;
8484
const winPrefix = allWindows ? `[Win ${winnr}] ` : "";
8585

86-
for (const [index, item] of enumerate(loclistItems)) {
86+
for (const [_index, item] of enumerate(loclistItems)) {
8787
const length = (item.end_col ?? 0) - item.col;
8888
const decorations = length > 0 ? [{ column: item.col, length }] : [];
8989

builtin/source/vimgrep.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export function vimgrep(
106106
signal?.throwIfAborted();
107107

108108
// Get results from quickfix list
109-
const qflist = await fn.getqflist(denops) as Array<{
109+
const qflist = await fn.getqflist(denops) as unknown as Array<{
110110
bufnr: number;
111111
lnum: number;
112112
col: number;
@@ -157,7 +157,7 @@ export function vimgrep(
157157
await denops.cmd(`silent! ${vimgrepCmd}`);
158158
signal?.throwIfAborted();
159159

160-
const qflist = await fn.getqflist(denops) as Array<{
160+
const qflist = await fn.getqflist(denops) as unknown as Array<{
161161
bufnr: number;
162162
lnum: number;
163163
col: number;

0 commit comments

Comments
 (0)