@@ -39,20 +39,42 @@ connection.onInitialize(async params => {
39
39
tsdk . diagnosticMessages ,
40
40
async ( { env, uriConverter, projectHost, sys, configFileName } ) => {
41
41
const { asFileName, asUri } = uriConverter ;
42
+ const workspaceFolders = [ ...server . workspaceFolders . keys ( ) ] ;
42
43
uriConverter . asUri = ( fileName ) => {
43
44
if ( fileName === '/node_modules' ) {
44
45
return URI . parse ( 'vscode-typescript-web://cdn/' ) ;
45
46
}
46
47
if ( fileName . startsWith ( '/node_modules/' ) ) {
47
48
return URI . parse ( 'vscode-typescript-web://cdn/' + fileName . slice ( '/node_modules/' . length ) ) ;
48
49
}
50
+ if ( workspaceFolders . length === 1 && fileName . startsWith ( '/' ) ) {
51
+ const basePath = workspaceFolders [ 0 ] . path . endsWith ( '/' )
52
+ ? workspaceFolders [ 0 ] . path
53
+ : workspaceFolders [ 0 ] . path + '/' ;
54
+ return URI . from ( {
55
+ ...workspaceFolders [ 0 ] ,
56
+ path : basePath . slice ( 0 , - 1 ) + fileName ,
57
+ } ) ;
58
+ }
49
59
return asUri ( fileName ) ;
50
60
} ;
51
61
uriConverter . asFileName = ( uri ) => {
52
62
const cdnPath = getCdnPath ( uri ) ;
53
63
if ( cdnPath !== undefined ) {
54
64
return '/node_modules/' + cdnPath ;
55
65
}
66
+ if ( workspaceFolders . length === 1 ) {
67
+ const basePath = workspaceFolders [ 0 ] . path . endsWith ( '/' )
68
+ ? workspaceFolders [ 0 ] . path
69
+ : workspaceFolders [ 0 ] . path + '/' ;
70
+ if (
71
+ uri . scheme === workspaceFolders [ 0 ] . scheme
72
+ && uri . authority === workspaceFolders [ 0 ] . authority
73
+ && uri . path . startsWith ( basePath )
74
+ ) {
75
+ return uri . path . slice ( basePath . length - 1 ) ;
76
+ }
77
+ }
56
78
return asFileName ( uri ) ;
57
79
} ;
58
80
const { fs } = env ;
@@ -61,18 +83,27 @@ connection.onInitialize(async params => {
61
83
if ( getCdnPath ( uri ) !== undefined ) {
62
84
return ataSys . stat ( uri ) ;
63
85
}
86
+ if ( uri . path . endsWith ( '/node_modules' ) || uri . path . includes ( '/node_modules/' ) ) {
87
+ return ;
88
+ }
64
89
return fs ?. stat ( uri ) ;
65
90
} ,
66
91
readDirectory ( uri ) {
67
92
if ( getCdnPath ( uri ) !== undefined ) {
68
93
return ataSys . readDirectory ( uri ) ;
69
94
}
95
+ if ( uri . path . endsWith ( '/node_modules' ) || uri . path . includes ( '/node_modules/' ) ) {
96
+ return [ ] ;
97
+ }
70
98
return fs ?. readDirectory ( uri ) ?? [ ]
71
99
} ,
72
100
readFile ( uri ) {
73
101
if ( getCdnPath ( uri ) !== undefined ) {
74
102
return ataSys . readFile ( uri ) ;
75
103
}
104
+ if ( uri . path . endsWith ( '/node_modules' ) || uri . path . includes ( '/node_modules/' ) ) {
105
+ return ;
106
+ }
76
107
return fs ?. readFile ( uri ) ;
77
108
} ,
78
109
}
0 commit comments