3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
+ import assert from 'node:assert' ;
7
+
6
8
export function convertServerOptionNameToClientConfigurationName ( section : string ) : string | null {
7
9
// 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.
10
11
const languageNameIndex = section . indexOf ( '|' ) ;
11
12
if ( languageNameIndex == - 1 || section . substring ( 0 , languageNameIndex ) == 'csharp' ) {
12
13
// 1. locate the last dot to find the {name} part.
13
14
const lastDotIndex = section . lastIndexOf ( '.' ) ;
15
+ assert ( lastDotIndex !== - 1 , `There is no . in ${ section } .` ) ;
14
16
const optionName = section . substring ( lastDotIndex + 1 ) ;
15
17
16
18
// 2. Get {grouping} part.
@@ -23,7 +25,7 @@ export function convertServerOptionNameToClientConfigurationName(section: string
23
25
// Example:
24
26
// Grouping: implement_type
25
27
// Name: dotnet_insertion_behavior
26
- // Expect result is: dotnet.implementType .insertionBehavior
28
+ // Expect result is: dotnet.implmentType .insertionBehavior
27
29
const prefixes = [ 'dotnet' , 'csharp' ] ;
28
30
const optionNamePrefix = getPrefix ( optionName , prefixes ) ;
29
31
@@ -32,11 +34,9 @@ export function convertServerOptionNameToClientConfigurationName(section: string
32
34
// Finally, convert everything to camel case and put them together.
33
35
const camelCaseGroupName = convertToCamelCase ( optionGroupName , '_' ) ;
34
36
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 ) ;
40
40
}
41
41
42
42
return null ;
0 commit comments