Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
75b036b
Add CLAUDE.md to provide guidance for Claude Code
lambdalisue Jul 5, 2025
6bdfbe0
feat(source): add window source for listing Vim windows
lambdalisue Jul 6, 2025
ad2d410
feat(source): add tabpage source for listing Vim tab pages
lambdalisue Jul 6, 2025
9004a59
feat(source): add loclist source for listing location list items
lambdalisue Jul 6, 2025
d337686
feat(source): add colorscheme source for listing available colorschemes
lambdalisue Jul 6, 2025
d8a627c
feat(source): add highlight source for listing highlight groups
lambdalisue Jul 6, 2025
33e58cd
feat(source): add jumplist source for listing jump locations
lambdalisue Jul 6, 2025
fd1a7c8
feat(source): add register source for listing Vim registers
lambdalisue Jul 6, 2025
5006534
feat(source): add mark source for listing Vim marks
lambdalisue Jul 6, 2025
1c0e825
feat(source): add command source for listing user-defined commands
lambdalisue Jul 6, 2025
9c39f46
feat(source): add mapping source for listing key mappings
lambdalisue Jul 6, 2025
e8f21f1
feat(source): add git status source for listing modified files
lambdalisue Jul 6, 2025
881a059
feat(source): add grep source for vim's :grep command results
lambdalisue Jul 6, 2025
c3bf51b
feat(source): add vimgrep source for vim's :vimgrep command results
lambdalisue Jul 6, 2025
89e0265
feat(source): add autocmd source for vim autocmds
lambdalisue Jul 6, 2025
c74961d
feat(previewer): add shell command previewer
lambdalisue Jul 6, 2025
bfba569
feat(renderer): add file info renderer for displaying file metadata
lambdalisue Jul 6, 2025
8090011
feat(renderer): add buffer info renderer for displaying buffer metadata
lambdalisue Jul 6, 2025
0f0a8f2
feat(renderer): add smart grep renderer for formatting grep-like results
lambdalisue Jul 6, 2025
e9a3319
feat(refiner): add file info refiner for filtering by file properties
lambdalisue Jul 6, 2025
c166b92
feat(refiner): add buffer info refiner for filtering by buffer proper…
lambdalisue Jul 6, 2025
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
178 changes: 178 additions & 0 deletions builtin/source/command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
import * as fn from "@denops/std/function";

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

type Detail = {
/**
* Command name
*/
name: string;

/**
* Command definition/replacement text
*/
definition: string;

/**
* Command attributes (bang, range, etc.)
*/
attributes: string;

/**
* Whether the command is buffer-local
*/
bufferLocal: boolean;

/**
* Number of arguments the command accepts
*/
nargs: string;

/**
* Completion type
*/
complete?: string;
};

export type CommandOptions = {
/**
* Whether to include buffer-local commands.
* @default true
*/
includeBufferLocal?: boolean;

/**
* Whether to include builtin commands.
* @default false
*/
includeBuiltin?: boolean;
};

/**
* Creates a Source that generates items from user-defined Vim commands.
*
* This Source retrieves all user-defined commands and generates items
* for each one, showing their definition and attributes.
*
* @param options - Options to customize command listing.
* @returns A Source that generates items representing commands.
*/
export function command(
options: Readonly<CommandOptions> = {},
): Source<Detail> {
const includeBufferLocal = options.includeBufferLocal ?? true;
const includeBuiltin = options.includeBuiltin ?? false;

return defineSource(async function* (denops, _params, { signal }) {
// Get user commands
const commandOutput = await fn.execute(denops, "command");
signal?.throwIfAborted();

// Parse command output
const lines = commandOutput.trim().split("\n").filter((line) =>
line.trim()
);
const items: Array<{
id: number;
value: string;
detail: Detail;
}> = [];

let id = 0;
for (const line of lines) {
// Skip header line
if (line.includes("Name") && line.includes("Args")) {
continue;
}

// Parse command line
// Format: " Name Args Address Complete Definition"
const match = line.match(
/^\s*(\S+)\s+(\S+)\s+(\S+)\s+(\S*)\s+(.*)$/,
);
if (!match) {
continue;
}

const [, name, nargs, address, complete, definition] = match;

// Check if it's a buffer-local command
const bufferLocal = name.startsWith("b:");

// Skip buffer-local commands if not included
if (bufferLocal && !includeBufferLocal) {
continue;
}

// Skip builtin commands if not included (they start with uppercase)
if (!includeBuiltin && /^[A-Z]/.test(name) && !name.includes(":")) {
continue;
}

// Build attributes string
const attributes: string[] = [];
if (nargs !== "0") {
attributes.push(`nargs=${nargs}`);
}
if (address !== ".") {
attributes.push(`addr=${address}`);
}
if (complete) {
attributes.push(`complete=${complete}`);
}

// Format display value
const attrStr = attributes.length > 0
? ` (${attributes.join(", ")})`
: "";
const localStr = bufferLocal ? " [buffer]" : "";
const truncatedDef = definition.length > 50
? definition.substring(0, 47) + "..."
: definition;

items.push({
id: id++,
value: `:${name}${localStr}${attrStr} → ${truncatedDef}`,
detail: {
name,
definition,
attributes: attrStr,
bufferLocal,
nargs,
complete: complete || undefined,
},
});
Comment on lines +133 to +144
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just yield.

}

// Get completion list if needed
if (includeBuiltin) {
const builtinCommands = await fn.getcompletion(
denops,
"",
"command",
) as string[];

for (const cmd of builtinCommands) {
// Skip if already in the list
if (items.some((item) => item.detail.name === cmd)) {
continue;
}

items.push({
id: id++,
value: `:${cmd} [builtin]`,
detail: {
name: cmd,
definition: "(builtin command)",
attributes: "",
bufferLocal: false,
nargs: "?",
complete: undefined,
},
});
Comment on lines +161 to +172
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just yield.

}
}

yield* items;
});
}
1 change: 1 addition & 0 deletions builtin/source/mod.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// This file is generated by gen-mod.ts
export * from "./buffer.ts";
export * from "./colorscheme.ts";
export * from "./command.ts";
export * from "./file.ts";
export * from "./helptag.ts";
export * from "./highlight.ts";
Expand Down