Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Enhances the API Description selection #4742

Merged
merged 3 commits into from
May 30, 2024
Merged
Changes from all commits
Commits
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
50 changes: 30 additions & 20 deletions vscode/microsoft-kiota/src/steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,47 @@ export async function searchSteps(searchCallBack: (searchQuery: string) => Thena
let step = 1;
let totalSteps = 2;
async function inputPathOrSearch(input: MultiStepInput, state: Partial<SearchState & OpenState>) {
const selectedOption = await input.showQuickPick({
title,
step: step++,
totalSteps: totalSteps,
placeholder: l10n.t('Search or paste a path to an API description'),
items: [{label: l10n.t('Search')}, {label: l10n.t('Browse path')}],
validate: validateIsNotEmpty,
shouldResume: shouldResume
});
if(selectedOption?.label === l10n.t('Search')) {
return (input: MultiStepInput) => inputSearch(input, state);
}
else if(selectedOption?.label === l10n.t('Browse path')) {
const fileUri = await input.showOpenDialog({
canSelectMany: false,
openLabel: 'Select',
canSelectFolders: false,
canSelectFiles: true
});

if (fileUri && fileUri[0]) {
state.descriptionPath = fileUri[0].fsPath;
}
}
}

async function inputSearch(input: MultiStepInput, state: Partial<SearchState & OpenState>) {
state.searchQuery = await input.showInputBox({
title,
step: step++,
totalSteps: totalSteps,
value: state.searchQuery ?? '',
prompt: l10n.t('Search or paste a path to an API description'),
prompt: l10n.t('Search a path to an API description'),
validate: validateIsNotEmpty,
shouldResume: shouldResume
});

state.searchResults = await searchCallBack(state.searchQuery);
if(state.searchResults && Object.keys(state.searchResults).length > 0) {
return (input: MultiStepInput) => pickSearchResult(input, state);
}
state.descriptionPath = state.searchQuery;
return (input: MultiStepInput) => inputPathOrUrl(input, state);
}

async function inputPathOrUrl(input: MultiStepInput, state: Partial<OpenState>) {
if (state.descriptionPath) {
return;
}
state.descriptionPath = await input.showInputBox({
title,
step: step++,
totalSteps: 1,
value: state.descriptionPath || '',
prompt: l10n.t('Search or paste a path to an API description'),
validate: validateIsNotEmpty,
shouldResume: shouldResume
});

}
async function pickSearchResult(input: MultiStepInput, state: Partial<SearchState & OpenState>) {
const items: QuickSearchPickItem[] = [];
Expand Down Expand Up @@ -270,7 +280,7 @@ export async function generateSteps(existingConfiguration: Partial<GenerateState
state.outputPath = state.outputPath === '' ? 'output' : state.outputPath;
break;
}
}
}

async function inputManifestName(input:MultiStepInput, state: Partial<GenerateState>) {
state.pluginName = await input.showInputBox({
Expand Down
Loading