33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6- import { AzureWizardPromptStep , type IActionContext , type IAzureQuickPickItem , type IAzureQuickPickOptions , type IWizardOptions } from '@microsoft/vscode-azext-utils' ;
6+ import { AzureWizardPromptStep , type IAzureQuickPickItem , type IWizardOptions } from '@microsoft/vscode-azext-utils' ;
77import * as escape from 'escape-string-regexp' ;
88import { type FuncVersion } from '../../FuncVersion' ;
9- import { JavaBuildTool , ProjectLanguage , TemplateFilter , templateFilterSetting } from '../../constants' ;
9+ import { JavaBuildTool , ProjectLanguage } from '../../constants' ;
1010import { ext } from '../../extensionVariables' ;
1111import { localize } from '../../localize' ;
1212import { type FunctionTemplateBase , type IFunctionTemplate } from '../../templates/IFunctionTemplate' ;
1313import { TemplateSchemaVersion } from '../../templates/TemplateProviderBase' ;
1414import { durableUtils } from '../../utils/durableUtils' ;
1515import { nonNullProp } from '../../utils/nonNull' ;
1616import { isNodeV4Plus , isPythonV2Plus , nodeV4Suffix } from '../../utils/programmingModelUtils' ;
17- import { getWorkspaceSetting , updateWorkspaceSetting } from '../../vsCodeConfig/settings' ;
17+ import { getWorkspaceSetting } from '../../vsCodeConfig/settings' ;
1818import { FunctionSubWizard } from './FunctionSubWizard' ;
1919import { type IFunctionWizardContext } from './IFunctionWizardContext' ;
2020import { JobsListStep } from './JobsListStep' ;
@@ -39,7 +39,7 @@ export class FunctionListStep extends AzureWizardPromptStep<IFunctionWizardConte
3939 const language : ProjectLanguage = nonNullProp ( context , 'language' ) ;
4040 const version : FuncVersion = nonNullProp ( context , 'version' ) ;
4141 const templateProvider = ext . templateProvider . get ( context ) ;
42- const templates : FunctionTemplateBase [ ] = await templateProvider . getFunctionTemplates ( context , context . projectPath , language , context . languageModel , version , TemplateFilter . All , context . projectTemplateKey ) ;
42+ const templates : FunctionTemplateBase [ ] = await templateProvider . getFunctionTemplates ( context , context . projectPath , language , context . languageModel , version , context . projectTemplateKey ) ;
4343 const foundTemplate : FunctionTemplateBase | undefined = templates . find ( ( t : FunctionTemplateBase ) => {
4444 if ( this . _options . templateId ) {
4545 const actualId : string = t . id . toLowerCase ( ) ;
@@ -83,10 +83,6 @@ export class FunctionListStep extends AzureWizardPromptStep<IFunctionWizardConte
8383 }
8484
8585 public async prompt ( context : IFunctionWizardContext ) : Promise < void > {
86- /* v2 schema doesn't have a template filter setting */
87- let templateFilter : TemplateFilter = context . templateSchemaVersion === TemplateSchemaVersion . v2 ? TemplateFilter . All :
88- getWorkspaceSetting < TemplateFilter > ( templateFilterSetting , context . projectPath ) || TemplateFilter . Verified ;
89-
9086 const templateProvider = ext . templateProvider . get ( context ) ;
9187 while ( ! context . functionTemplate ) {
9288 let placeHolder : string = this . _isProjectWizard ?
@@ -97,17 +93,13 @@ export class FunctionListStep extends AzureWizardPromptStep<IFunctionWizardConte
9793 placeHolder += localize ( 'templateSource' , ' (Template source: "{0}")' , templateProvider . templateSource )
9894 }
9995
100- const result : FunctionTemplateBase | TemplatePromptResult = ( await context . ui . showQuickPick ( this . getPicks ( context , templateFilter ) , { placeHolder } ) ) . data ;
96+ const result : FunctionTemplateBase | TemplatePromptResult =
97+ ( await context . ui . showQuickPick ( this . getPicks ( context ) ,
98+ { placeHolder, enableGrouping : true } ) ) . data ;
99+
101100 if ( result === 'skipForNow' ) {
102101 context . telemetry . properties . templateId = 'skipForNow' ;
103102 break ;
104- } else if ( result === 'changeFilter' ) {
105- templateFilter = await promptForTemplateFilter ( context ) ;
106- // can only update setting if it's open in a workspace
107- if ( ! this . _isProjectWizard || context . openBehavior === 'AlreadyOpen' ) {
108- await updateWorkspaceSetting ( templateFilterSetting , templateFilter , context . projectPath ) ;
109- }
110- context . telemetry . properties . changedFilter = 'true' ;
111103 } else if ( result === 'openAPI' ) {
112104 context . generateFromOpenAPI = true ;
113105 break ;
@@ -117,8 +109,6 @@ export class FunctionListStep extends AzureWizardPromptStep<IFunctionWizardConte
117109 } else {
118110 context . functionTemplate = result ;
119111 }
120-
121- context . telemetry . properties . templateFilter = templateFilter ;
122112 }
123113 }
124114
@@ -128,18 +118,18 @@ export class FunctionListStep extends AzureWizardPromptStep<IFunctionWizardConte
128118 context . language !== ProjectLanguage . SelfHostedMCPServer ;
129119 }
130120
131- private async getPicks ( context : IFunctionWizardContext , templateFilter : TemplateFilter ) : Promise < IAzureQuickPickItem < FunctionTemplateBase | TemplatePromptResult > [ ] > {
121+ private async getPicks ( context : IFunctionWizardContext ) : Promise < IAzureQuickPickItem < FunctionTemplateBase | TemplatePromptResult > [ ] > {
132122 const language : ProjectLanguage = nonNullProp ( context , 'language' ) ;
133123 const languageModel = context . languageModel ;
134124 const version : FuncVersion = nonNullProp ( context , 'version' ) ;
135125 const templateProvider = ext . templateProvider . get ( context ) ;
136126
137- const templates : FunctionTemplateBase [ ] = await templateProvider . getFunctionTemplates ( context , context . projectPath , language , context . languageModel , version , templateFilter , context . projectTemplateKey ) ;
127+ const templates : FunctionTemplateBase [ ] = await templateProvider . getFunctionTemplates ( context , context . projectPath , language , context . languageModel , version , context . projectTemplateKey ) ;
138128 context . telemetry . measurements . templateCount = templates . length ;
139129 const picks : IAzureQuickPickItem < FunctionTemplateBase | TemplatePromptResult > [ ] = templates
140130 . filter ( ( t ) => ! ( doesTemplateRequireExistingStorageSetup ( t . id , language ) && ! context . hasDurableStorage ) )
141- . sort ( ( a , b ) => sortTemplates ( a , b , templateFilter ) )
142- . map ( t => { return { label : t . name , data : t } ; } ) ;
131+ . sort ( ( a , b ) => sortTemplates ( a , b ) )
132+ . map ( t => { return { label : t . name , data : t , group : t . templateFilter } ; } ) ;
143133
144134 if ( this . _isProjectWizard ) {
145135 picks . unshift ( {
@@ -167,15 +157,6 @@ export class FunctionListStep extends AzureWizardPromptStep<IFunctionWizardConte
167157 suppressPersistence : true
168158 } ) ;
169159 }
170- if ( context . templateSchemaVersion !== TemplateSchemaVersion . v2 ) {
171- // don't offer template filter for v2 schema
172- picks . push ( {
173- label : localize ( 'selectFilter' , '$(gear) Change template filter' ) ,
174- description : localize ( 'currentFilter' , 'Current: {0}' , templateFilter ) ,
175- data : 'changeFilter' ,
176- suppressPersistence : true
177- } ) ;
178- }
179160
180161 if ( getWorkspaceSetting < boolean > ( 'showReloadTemplates' ) ) {
181162 picks . push ( {
@@ -195,18 +176,7 @@ interface IFunctionListStepOptions {
195176 functionSettings : { [ key : string ] : string | undefined } | undefined ;
196177}
197178
198- type TemplatePromptResult = 'changeFilter' | 'skipForNow' | 'openAPI' | 'reloadTemplates' ;
199-
200- async function promptForTemplateFilter ( context : IActionContext ) : Promise < TemplateFilter > {
201- const picks : IAzureQuickPickItem < TemplateFilter > [ ] = [
202- { label : TemplateFilter . Verified , description : localize ( 'verifiedDescription' , '(Subset of "Core" that has been verified in VS Code)' ) , data : TemplateFilter . Verified } ,
203- { label : TemplateFilter . Core , data : TemplateFilter . Core } ,
204- { label : TemplateFilter . All , data : TemplateFilter . All }
205- ] ;
206-
207- const options : IAzureQuickPickOptions = { suppressPersistence : true , placeHolder : localize ( 'selectFilter' , 'Select a template filter' ) } ;
208- return ( await context . ui . showQuickPick ( picks , options ) ) . data ;
209- }
179+ type TemplatePromptResult = 'skipForNow' | 'openAPI' | 'reloadTemplates' ;
210180
211181// Todo: https://github.com/microsoft/vscode-azurefunctions/issues/3529
212182// Identify and filter out Durable Function templates requiring a pre-existing storage setup
@@ -228,21 +198,17 @@ function doesTemplateRequireExistingStorageSetup(templateId: string, language?:
228198 * If templateFilter is verified, puts HttpTrigger/TimerTrigger at the top since they're the most popular
229199 * Otherwise sort alphabetically
230200 */
231- function sortTemplates ( a : FunctionTemplateBase , b : FunctionTemplateBase , templateFilter : TemplateFilter ) : number {
232- if ( templateFilter === TemplateFilter . Verified ) {
233- function getPriority ( id : string ) : number {
234- if ( / \b h t t p t r i g g e r \b / i. test ( id ) ) { // Plain http trigger
235- return 1 ;
236- } else if ( / \b h t t p t r i g g e r / i. test ( id ) ) { // Http trigger with any extra pizazz
237- return 2 ;
238- } else if ( / \b t i m e r t r i g g e r \b / i. test ( id ) ) {
239- return 3 ;
240- } else {
241- return 4 ;
242- }
201+ function sortTemplates ( a : FunctionTemplateBase , b : FunctionTemplateBase ) : number {
202+ function getPriority ( id : string ) : number {
203+ if ( / \b h t t p t r i g g e r \b / i. test ( id ) ) { // Plain http trigger
204+ return 1 ;
205+ } else if ( / \b h t t p t r i g g e r / i. test ( id ) ) { // Http trigger with any extra pizazz
206+ return 2 ;
207+ } else if ( / \b t i m e r t r i g g e r \b / i. test ( id ) ) {
208+ return 3 ;
209+ } else {
210+ return a . name . localeCompare ( b . name ) === - 1 ? 4 : 5 ;
243211 }
244- return getPriority ( a . id ) - getPriority ( b . id ) ;
245212 }
246-
247- return a . name . localeCompare ( b . name ) ;
213+ return getPriority ( a . id ) - getPriority ( b . id ) ;
248214}
0 commit comments