@@ -18,20 +18,55 @@ suite('ConfigService', () => {
18
18
await Promise . all ( keys . map ( key => conf . update ( key , undefined ) ) ) ;
19
19
} ) ;
20
20
21
- testSingleFolderMode ( 'resolves relative server path with workspace folder' , async ( ) => {
22
- const service = new ConfigService ( ) ;
23
- const nonDefinedServerPath = service . getUserServerBinPath ( ) ;
21
+ const getWorkspaceFolderPlatformSafe = ( ) => {
22
+ let workspace_path = WORKSPACE_FOLDER . uri . path ;
23
+ if ( process . platform === 'win32' ) {
24
+ workspace_path = workspace_path . replaceAll ( '/' , '\\' ) ;
25
+ if ( workspace_path . startsWith ( '\\' ) ) {
26
+ workspace_path = workspace_path . slice ( 1 ) ;
27
+ }
28
+ }
29
+ return workspace_path ;
30
+ } ;
24
31
25
- strictEqual ( nonDefinedServerPath , undefined ) ;
32
+ suite ( 'getUserServerBinPath' , ( ) => {
33
+ testSingleFolderMode ( 'resolves relative server path with workspace folder' , async ( ) => {
34
+ const service = new ConfigService ( ) ;
35
+ const nonDefinedServerPath = service . getUserServerBinPath ( ) ;
26
36
27
- await conf . update ( 'path.server' , '/absolute/oxc_language_server' ) ;
28
- const absoluteServerPath = service . getUserServerBinPath ( ) ;
37
+ strictEqual ( nonDefinedServerPath , undefined ) ;
29
38
30
- strictEqual ( absoluteServerPath , '/absolute/oxc_language_server' ) ;
39
+ await conf . update ( 'path.server' , '/absolute/oxc_language_server' ) ;
40
+ const absoluteServerPath = service . getUserServerBinPath ( ) ;
31
41
32
- await conf . update ( 'path.server' , './relative/oxc_language_server' ) ;
33
- const relativeServerPath = service . getUserServerBinPath ( ) ;
42
+ strictEqual ( absoluteServerPath , '/absolute/oxc_language_server' ) ;
34
43
35
- strictEqual ( relativeServerPath , WORKSPACE_FOLDER . uri . path + '/relative/oxc_language_server' ) ;
44
+ await conf . update ( 'path.server' , './relative/oxc_language_server' ) ;
45
+ const relativeServerPath = service . getUserServerBinPath ( ) ;
46
+
47
+ let workspace_path = getWorkspaceFolderPlatformSafe ( ) ;
48
+ strictEqual ( relativeServerPath , `${ workspace_path } /relative/oxc_language_server` ) ;
49
+ } ) ;
50
+
51
+ testSingleFolderMode ( 'returns undefined for unsafe server path' , async ( ) => {
52
+ const service = new ConfigService ( ) ;
53
+ await conf . update ( 'path.server' , '../unsafe/oxc_language_server' ) ;
54
+ const unsafeServerPath = service . getUserServerBinPath ( ) ;
55
+
56
+ strictEqual ( unsafeServerPath , undefined ) ;
57
+ } ) ;
58
+
59
+ testSingleFolderMode ( 'returns backslashes path on Windows' , async ( ) => {
60
+ if ( process . platform !== 'win32' ) {
61
+ return ;
62
+ }
63
+ const service = new ConfigService ( ) ;
64
+ await conf . update ( 'path.server' , './relative/oxc_language_server' ) ;
65
+ const relativeServerPath = service . getUserServerBinPath ( ) ;
66
+ let workspace_path = getWorkspaceFolderPlatformSafe ( ) ;
67
+
68
+ strictEqual ( workspace_path [ 1 ] , ':' , 'The test workspace folder must be an absolute path with a drive letter on Windows' ) ;
69
+ strictEqual ( relativeServerPath , `${ workspace_path } \\relative\\oxc_language_server` ) ;
70
+ } ) ;
36
71
} ) ;
37
72
} ) ;
0 commit comments