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
-
8
6
export function convertServerOptionNameToClientConfigurationName ( section : string ) : string | null {
9
7
// Server name would be in format {languageName}|{grouping}.{name} or
10
- // {grouping}.{name} if this option can be applied to multiple languages.
8
+ // {grouping}.{name} if this option can be applied to multiple languages or
9
+ // just {name} if this option is not in a group.
11
10
const languageNameIndex = section . indexOf ( '|' ) ;
12
11
if ( languageNameIndex == - 1 || section . substring ( 0 , languageNameIndex ) == 'csharp' ) {
13
12
// 1. locate the last dot to find the {name} part.
14
13
const lastDotIndex = section . lastIndexOf ( '.' ) ;
15
- assert ( lastDotIndex !== - 1 , `There is no . in ${ section } .` ) ;
16
14
const optionName = section . substring ( lastDotIndex + 1 ) ;
17
15
18
16
// 2. Get {grouping} part.
@@ -25,7 +23,7 @@ export function convertServerOptionNameToClientConfigurationName(section: string
25
23
// Example:
26
24
// Grouping: implement_type
27
25
// Name: dotnet_insertion_behavior
28
- // Expect result is: dotnet.implmentType .insertionBehavior
26
+ // Expect result is: dotnet.implementType .insertionBehavior
29
27
const prefixes = [ 'dotnet' , 'csharp' ] ;
30
28
const optionNamePrefix = getPrefix ( optionName , prefixes ) ;
31
29
@@ -34,9 +32,11 @@ export function convertServerOptionNameToClientConfigurationName(section: string
34
32
// Finally, convert everything to camel case and put them together.
35
33
const camelCaseGroupName = convertToCamelCase ( optionGroupName , '_' ) ;
36
34
const camelCaseFeatureName = convertToCamelCase ( featureName , '_' ) ;
37
- return optionNamePrefix == ''
38
- ? camelCaseGroupName . concat ( '.' , camelCaseFeatureName )
39
- : convertToCamelCase ( optionNamePrefix , '_' ) . concat ( '.' , camelCaseGroupName , '.' , camelCaseFeatureName ) ;
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 ( '.' ) ;
40
40
}
41
41
42
42
return null ;
0 commit comments