Skip to content

Commit 05e8726

Browse files
committed
Index extensions and descriptions in plugin search
Build the search string from each plugin's description, config key, file extensions/names, and — for exec-style plugins — the extensions and commands under configItems. So "scss", "python", or "zig" now find the right plugin, not just its name or URL.
1 parent 130ac96 commit 05e8726

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

homeView.tsx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,28 @@ function renderPage(pluginsData: PluginsData) {
9595
);
9696
}
9797

98+
// builds the lowercased string the search filters against: name, url, version,
99+
// description, config key, and every file extension / file name / exec command
100+
// the plugin handles.
101+
function pluginSearchText(plugin: PluginData) {
102+
const parts: (string | undefined)[] = [
103+
plugin.name,
104+
plugin.url,
105+
plugin.version,
106+
plugin.description,
107+
plugin.configKey,
108+
...(plugin.fileExtensions ?? []),
109+
...(plugin.fileNames ?? []),
110+
];
111+
for (const item of plugin.configItems ?? []) {
112+
parts.push(...(item.match?.fileExtensions ?? []));
113+
for (const command of item.config?.commands ?? []) {
114+
parts.push(command.command, ...(command.exts ?? []));
115+
}
116+
}
117+
return parts.filter(Boolean).join(" ").toLowerCase();
118+
}
119+
98120
function renderCommands() {
99121
const commands: { cmd: string; desc: string }[] = [
100122
{ cmd: "dprint config update", desc: "Automatically updates the plugins in a config file." },
@@ -132,7 +154,7 @@ function renderPlugins(data: PluginsData) {
132154

133155
function renderPlugin(plugin: PluginData) {
134156
return (
135-
<div class="plugin-row" role="row" key={plugin.name} data-search={`${plugin.name} ${plugin.url}`.toLowerCase()}>
157+
<div class="plugin-row" role="row" key={plugin.name} data-search={pluginSearchText(plugin)}>
136158
<div class="col-name" role="cell">
137159
<span class="swatch"></span>
138160
<span class="name-text">{plugin.name}</span>

readInfoFile.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@ export interface PluginData {
1616
currentVersion: number;
1717
allVersions: number;
1818
};
19+
// descriptive fields carried over from info.json, used to index the search
20+
description?: string;
21+
configKey?: string;
22+
fileExtensions?: string[];
23+
fileNames?: string[];
24+
// present on plugins like exec where the real extensions/commands live in
25+
// per-match config rather than top-level fileExtensions
26+
configItems?: PluginConfigItem[];
27+
}
28+
29+
interface PluginConfigItem {
30+
match?: { fileExtensions?: string[] };
31+
config?: { commands?: { command?: string; exts?: string[] }[] };
1932
}
2033

2134
interface CacheEntry {

0 commit comments

Comments
 (0)