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