@@ -274,6 +274,7 @@ export function createTypeScriptProject(
274274export function createUriConverter ( rootFolders : URI [ ] ) {
275275 const encodeds = new Map < string , URI > ( ) ;
276276 const isFileScheme = rootFolders . every ( folder => folder . scheme === 'file' ) ;
277+ const fragmentPrefix = '/' + encodeURIComponent ( '#' ) ;
277278
278279 return {
279280 asFileName,
@@ -291,7 +292,8 @@ export function createUriConverter(rootFolders: URI[]) {
291292 }
292293 const encoded = encodeURIComponent ( `${ parsed . scheme } ://${ parsed . authority } ` ) ;
293294 encodeds . set ( encoded , parsed ) ;
294- return `/${ encoded } ${ parsed . path } ` ;
295+ const fragment = parsed . fragment ? fragmentPrefix + encodeURIComponent ( parsed . fragment ) : '' ;
296+ return `/${ encoded } ${ parsed . path } ${ fragment } ` ;
295297 }
296298
297299 function asUri ( fileName : string ) {
@@ -308,7 +310,7 @@ export function createUriConverter(rootFolders: URI[]) {
308310 return URI . from ( {
309311 scheme : uri . scheme ,
310312 authority : uri . authority ,
311- path : fileName . substring ( prefix . length ) ,
313+ ... getComponents ( fileName , prefix . length ) ,
312314 } ) ;
313315 }
314316 }
@@ -317,7 +319,7 @@ export function createUriConverter(rootFolders: URI[]) {
317319 return URI . from ( {
318320 scheme : uri . scheme ,
319321 authority : uri . authority ,
320- path : fileName . substring ( prefix . length ) ,
322+ ... getComponents ( fileName , prefix . length ) ,
321323 } ) ;
322324 }
323325 }
@@ -329,6 +331,22 @@ export function createUriConverter(rootFolders: URI[]) {
329331 }
330332 return URI . file ( fileName ) ;
331333 }
334+
335+ function getComponents ( fileName : string , prefixLength : number ) {
336+ // Fragment is present when the fileName contains the fragment prefix and is not followed by a slash.
337+ const fragmentPosition = fileName . lastIndexOf ( fragmentPrefix ) ;
338+ if ( fragmentPosition >= prefixLength ) {
339+ if ( fileName . indexOf ( '/' , fragmentPosition + fragmentPrefix . length ) < 0 ) {
340+ return {
341+ path : fileName . substring ( prefixLength , fragmentPosition ) ,
342+ fragment : decodeURIComponent ( fileName . substring ( fragmentPosition + fragmentPrefix . length ) ) ,
343+ } ;
344+ }
345+ }
346+ return {
347+ path : fileName . substring ( prefixLength ) ,
348+ } ;
349+ }
332350}
333351
334352export function sortTSConfigs ( file : string , a : string , b : string ) {
0 commit comments