import { AzureWizardPromptStep } from 'vscode-azureextensionui' ; import * as XRegExp from 'xregexp' ; import { localize } from "../../../localize" ; import { IDotnetFunctionWizardContext } from './IDotnetFunctionWizardContext' ; export class DotnetNamespaceStep extends AzureWizardPromptStep < IDotnetFunctionWizardContext > { public async prompt ( context ) { context . namespace = await context . ui . showInputBox ( { placeHolder : localize ( 'namespacePlaceHolder' , 'Namespace' ) , prompt : localize ( 'namespacePrompt' , 'Provide a namespace' ) , validateInput : validateCSharpNamespace , value : 'Company.Function' } ) ; } public shouldPrompt ( context ) { return ! context . namespace ; } } const formattingCharacter = '\\p{Cf}' ; const connectingCharacter = '\\p{Pc}' ; const decimalDigitCharacter = '\\p{Nd}' ; const combiningCharacter = '\\p{Mn}|\\p{Mc}' ; const letterCharacter = '\\p{Lu}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Lo}|\\p{Nl}' ; const identifierPartCharacter = `${ letterCharacter }|${ decimalDigitCharacter }|${ connectingCharacter }|${ combiningCharacter }|${ formattingCharacter }` ; const identifierStartCharacter = `(${ letterCharacter }|_)` ; const identifierOrKeyword = `${ identifierStartCharacter }(${ identifierPartCharacter })*` ; const identifierRegex = XRegExp ( `^${ identifierOrKeyword }$` ) ; const keywords = [ 'abstract' , 'as' , 'base' , 'bool' , 'break' , 'byte' , 'case' , 'catch' , 'char' , 'checked' , 'class' , 'const' , 'continue' , 'decimal' , 'default' , 'delegate' , 'do' , 'double' , 'else' , 'enum' , 'event' , 'explicit' , 'extern' , 'false' , 'finally' , 'fixed' , 'float' , 'for' , 'foreach' , 'goto' , 'if' , 'implicit' , 'in' , 'int' , 'interface' , 'internal' , 'is' , 'lock' , 'long' , 'namespace' , 'new' , 'null' , 'object' , 'operator' , 'out' , 'override' , 'params' , 'private' , 'protected' , 'public' , 'readonly' , 'ref' , 'return' , 'sbyte' , 'sealed' , 'short' , 'sizeof' , 'stackalloc' , 'static' , 'string' , 'struct' , 'switch' , 'this' , 'throw' , 'true' , 'try' , 'typeof' , 'uint' , 'ulong' , 'unchecked' , 'unsafe' , 'ushort' , 'using' , 'virtual' , 'void' , 'volatile' , 'while' ] ; export function validateCSharpNamespace ( value ) { if ( ! value ) { return localize ( 'cSharpEmptyTemplateNameError' , 'The template name cannot be empty.' ) ; } const identifiers = value . split ( '.' ) ; for ( const identifier of identifiers ) { if ( identifier === '' ) { return localize ( 'cSharpExtraPeriod' , 'Leading or trailing "." character is not allowed.' ) ; } else if ( ! identifierRegex . test ( identifier ) ) { return localize ( 'cSharpInvalidCharacters' , 'The identifier "{0}" contains invalid characters.' , identifier ) ; } else if ( keywords . find ( ( s ) => s === identifier . toLowerCase ( ) ) !== undefined ) { return localize ( 'cSharpKeywordWarning' , 'The identifier "{0}" is a reserved keyword.' , identifier ) ; } } return undefined ; }