mirror of
https://github.com/microsoft/vscode-extension-samples.git
synced 2026-04-27 16:55:44 +08:00
Repro all selected items not being there on enter
This commit is contained in:
@ -4,7 +4,6 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as path from 'path';
|
||||
import * as cp from 'child_process';
|
||||
import { Uri, window, Disposable } from 'vscode';
|
||||
import { QuickPickItem } from 'vscode';
|
||||
import { workspace } from 'vscode';
|
||||
@ -51,56 +50,19 @@ async function pickFile() {
|
||||
try {
|
||||
return await new Promise<Uri | undefined>((resolve) => {
|
||||
const input = window.createQuickPick<FileItem | MessageItem>();
|
||||
input.canSelectMany = true;
|
||||
const base = workspace.workspaceFolders?.[0].uri ?? Uri.file('/');
|
||||
input.items = [
|
||||
new MessageItem(base, 'Dummy item 1'),
|
||||
new MessageItem(base, 'Dummy item 2'),
|
||||
new MessageItem(base, 'Dummy item 3')
|
||||
];
|
||||
input.placeholder = 'Type to search for files';
|
||||
let rgs: cp.ChildProcess[] = [];
|
||||
disposables.push(
|
||||
input.onDidChangeValue(value => {
|
||||
rgs.forEach(rg => rg.kill());
|
||||
if (!value) {
|
||||
input.items = [];
|
||||
return;
|
||||
}
|
||||
input.busy = true;
|
||||
const cwds = workspace.workspaceFolders ? workspace.workspaceFolders.map(f => f.uri.fsPath) : [process.cwd()];
|
||||
const q = process.platform === 'win32' ? '"' : '\'';
|
||||
rgs = cwds.map(cwd => {
|
||||
const rg = cp.exec(`rg --files -g ${q}*${value}*${q}`, { cwd }, (err, stdout) => {
|
||||
const i = rgs.indexOf(rg);
|
||||
if (i !== -1) {
|
||||
if (rgs.length === cwds.length) {
|
||||
input.items = [];
|
||||
}
|
||||
if (!err) {
|
||||
input.items = input.items.concat(
|
||||
stdout
|
||||
.split('\n').slice(0, 50)
|
||||
.map(relative => new FileItem(Uri.file(cwd), Uri.file(path.join(cwd, relative))))
|
||||
);
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
if (err && !(err as any).killed && (err as any).code !== 1 && err.message) {
|
||||
input.items = input.items.concat([
|
||||
new MessageItem(Uri.file(cwd), err.message)
|
||||
]);
|
||||
}
|
||||
rgs.splice(i, 1);
|
||||
if (!rgs.length) {
|
||||
input.busy = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
return rg;
|
||||
});
|
||||
}),
|
||||
input.onDidChangeSelection(items => {
|
||||
const item = items[0];
|
||||
if (item instanceof FileItem) {
|
||||
resolve(item.uri);
|
||||
input.hide();
|
||||
}
|
||||
input.onDidAccept(_ => {
|
||||
window.showInformationMessage(`Accepted: ${input.selectedItems.length} items`);
|
||||
}),
|
||||
input.onDidHide(() => {
|
||||
rgs.forEach(rg => rg.kill());
|
||||
resolve(undefined);
|
||||
input.dispose();
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user