Skip to content

Commit

Permalink
Merge pull request #4742 from microsoft/elinor/add-api-path-selection
Browse files Browse the repository at this point in the history
Feature: Enhances the API Description selection
  • Loading branch information
ElinorW authored May 30, 2024
2 parents c63339a + d86275b commit 2045df0
Showing 1 changed file with 30 additions and 20 deletions.
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

0 comments on commit 2045df0

Please sign in to comment.