2016
2017
private async promptForInput(groupName: string, property: string, propertySchema: IJSONSchema, required: boolean, existing: IStringDictionary<unknown> | undefined): Promise<string | number | boolean | undefined> {
2019
>
try {
2020
>
const validate = (value: string): string | undefined => {
2021
>
if (!value && required) {
2022
return localize('valueRequired', "Value is required");
2023
}
2025
>
};
2026
>
2027
>
const value = await new Promise<string | undefined>((resolve, reject) => {
2028
>
const inputBox = disposables.add(this._quickInputService.createInputBox());
2029
>
inputBox.title = `${groupName}: ${propertySchema.title ?? property}`;
2030
>
inputBox.placeholder = localize('enterValue', "Enter value for {0}", property);
2031
>
inputBox.password = !!propertySchema.secret;
2032
>
inputBox.ignoreFocusOut = true;
2033
>
if (existing?.[property]) {
2034
>
inputBox.value = String(existing?.[property]);
2035
>
} else if (propertySchema.default) {
2036
inputBox.value = String(propertySchema.default);
2037
}
2038
>
const promptText = this.getDescriptionPlaintext(propertySchema);
languageModels.ts
2039
>
if (promptText) {
2040
inputBox.prompt = promptText;
2041
}
2043
>
disposables.add(inputBox.onDidChangeValue(value => {
2044
>
const message = validate(value);
2045
>
if (message) {
2046
inputBox.validationMessage = message;
2047
inputBox.severity = Severity.Error;
2049
>
inputBox.validationMessage = undefined;
2050
>
inputBox.severity = Severity.Ignore;
2051
>
}
2052
>
}));
2053
>
2054
>
disposables.add(inputBox.onDidAccept(() => {
2055
>
const message = validate(inputBox.value);
2056
>
if (message) {
2057
inputBox.validationMessage = message;
2058
inputBox.severity = Severity.Error;
2059
return;
2060
}
2062
>
inputBox.hide();
2063
>
}));
2064
>
2065
>
disposables.add(inputBox.onDidHide((e) => {
2066
>
if (e.reason === QuickInputHideReason.Gesture) {
2067
reject(new CancellationError());
2069
>
resolve(undefined);
2070
>
}
2071
>
}));
2072
>
2073
>
inputBox.show();
2074
>
});
2075
>
2076
>
if (!value) {
2077
return undefined; // User cancelled
2078
}
2080
>
if (propertySchema.type === 'number' || propertySchema.type === 'integer') {
2081
return Number(value);
2083
return value === 'true';
2085
>
return value;
2086
>
}
2087
>
2088
>
} finally {
2089
>
disposables.dispose();
2090
>
}
2091
>
}
2092
2093
private encodeSecretKey(property: string): string {