@@ -140,12 +140,17 @@ namespace ts.server {
140
140
return typeof cmdLineVerbosity === "undefined" ? nullLogger : new MainProcessLogger ( cmdLineVerbosity ) ;
141
141
}
142
142
143
+ interface WebServerHost extends ServerHost {
144
+ getWebPath : ( path : string ) => string | undefined ;
145
+ }
146
+
143
147
function createWebSystem ( args : string [ ] ) {
144
148
Debug . assert ( ts . sys === undefined ) ;
145
149
const returnEmptyString = ( ) => "" ;
146
150
// Later we could map ^memfs:/ to do something special if we want to enable more functionality like module resolution or something like that
147
151
const getWebPath = ( path : string ) => startsWith ( path , directorySeparator ) ? path . replace ( directorySeparator , executingDirectoryPath ) : undefined ;
148
- const sys : ServerHost = {
152
+ const sys : WebServerHost = {
153
+ getWebPath,
149
154
args,
150
155
newLine : "\r\n" , // This can be configured by clients
151
156
useCaseSensitiveFileNames : false , // Use false as the default on web since that is the safest option
@@ -233,10 +238,8 @@ namespace ts.server {
233
238
function startWebSession ( options : StartSessionOptions , logger : Logger , cancellationToken : ServerCancellationToken ) {
234
239
class WorkerSession extends Session < { } > {
235
240
constructor ( ) {
236
- const host = sys as ServerHost ;
237
-
238
241
super ( {
239
- host,
242
+ host : sys as WebServerHost ,
240
243
cancellationToken,
241
244
...options ,
242
245
typingsInstaller : nullTypingsInstaller ,
@@ -248,6 +251,9 @@ namespace ts.server {
248
251
}
249
252
250
253
public send ( msg : protocol . Message ) {
254
+ // Updates to file paths
255
+ this . updateWebPaths ( msg ) ;
256
+
251
257
if ( msg . type === "event" && ! this . canUseEvents ) {
252
258
if ( this . logger . hasLevel ( LogLevel . verbose ) ) {
253
259
this . logger . info ( `Session does not support events: ignored event: ${ JSON . stringify ( msg ) } ` ) ;
@@ -260,6 +266,30 @@ namespace ts.server {
260
266
postMessage ( msg ) ;
261
267
}
262
268
269
+ private updateWebPaths ( obj : any ) {
270
+ if ( isArray ( obj ) ) {
271
+ obj . forEach ( ele => this . updateWebPaths ( ele ) ) ;
272
+ }
273
+ else if ( typeof obj === "object" ) {
274
+ for ( const id in obj ) {
275
+ if ( hasProperty ( obj , id ) ) {
276
+ const value = obj [ id ] ;
277
+ if ( ( id === "file" || id === "fileName" || id === "renameFilename" ) && isString ( value ) ) {
278
+ const webpath = ( sys as WebServerHost ) . getWebPath ( value ) ;
279
+ if ( webpath ) obj [ id ] = webpath ;
280
+ }
281
+ else if ( ( id === "files" || id === "fileNames" ) && isArray ( value ) && value . every ( isString ) ) {
282
+ obj [ id ] = value . map ( ele => ( sys as WebServerHost ) . getWebPath ( ele ) || ele ) ;
283
+ }
284
+ else {
285
+ this . updateWebPaths ( value ) ;
286
+ }
287
+ }
288
+ }
289
+
290
+ }
291
+ }
292
+
263
293
protected parseMessage ( message : { } ) : protocol . Request {
264
294
return < protocol . Request > message ;
265
295
}
@@ -279,8 +309,6 @@ namespace ts.server {
279
309
this . onMessage ( message . data ) ;
280
310
} ) ;
281
311
}
282
-
283
- // TODO:: Update all responses to use webPath
284
312
}
285
313
286
314
const session = new WorkerSession ( ) ;
0 commit comments