33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6+ import assert from 'node:assert' ;
7+
68export function convertServerOptionNameToClientConfigurationName ( section : string ) : string | null {
79 // Server name would be in format {languageName}|{grouping}.{name} or
8- // {grouping}.{name} if this option can be applied to multiple languages or
9- // just {name} if this option is not in a group.
10+ // {grouping}.{name} if this option can be applied to multiple languages.
1011 const languageNameIndex = section . indexOf ( '|' ) ;
1112 if ( languageNameIndex == - 1 || section . substring ( 0 , languageNameIndex ) == 'csharp' ) {
1213 // 1. locate the last dot to find the {name} part.
1314 const lastDotIndex = section . lastIndexOf ( '.' ) ;
15+ assert ( lastDotIndex !== - 1 , `There is no . in ${ section } .` ) ;
1416 const optionName = section . substring ( lastDotIndex + 1 ) ;
1517
1618 // 2. Get {grouping} part.
@@ -23,7 +25,7 @@ export function convertServerOptionNameToClientConfigurationName(section: string
2325 // Example:
2426 // Grouping: implement_type
2527 // Name: dotnet_insertion_behavior
26- // Expect result is: dotnet.implementType .insertionBehavior
28+ // Expect result is: dotnet.implmentType .insertionBehavior
2729 const prefixes = [ 'dotnet' , 'csharp' ] ;
2830 const optionNamePrefix = getPrefix ( optionName , prefixes ) ;
2931
@@ -32,11 +34,9 @@ export function convertServerOptionNameToClientConfigurationName(section: string
3234 // Finally, convert everything to camel case and put them together.
3335 const camelCaseGroupName = convertToCamelCase ( optionGroupName , '_' ) ;
3436 const camelCaseFeatureName = convertToCamelCase ( featureName , '_' ) ;
35- const camelCasePrefixName = convertToCamelCase ( optionNamePrefix , '_' ) ;
36-
37- // Concatenate the three parts together, with dots as separators, but only if they are not empty.
38- const parts = [ camelCasePrefixName , camelCaseGroupName , camelCaseFeatureName ] . filter ( ( part ) => part !== '' ) ;
39- return parts . join ( '.' ) ;
37+ return optionNamePrefix == ''
38+ ? camelCaseGroupName . concat ( '.' , camelCaseFeatureName )
39+ : convertToCamelCase ( optionNamePrefix , '_' ) . concat ( '.' , camelCaseGroupName , '.' , camelCaseFeatureName ) ;
4040 }
4141
4242 return null ;
0 commit comments