@@ -18,6 +18,7 @@ const moduleWrapper = tsserver => {
1818 const pnpApi = require ( `pnpapi` ) ;
1919
2020 const isVirtual = str => str . match ( / \/ ( \$ \$ v i r t u a l | _ _ v i r t u a l _ _ ) \/ / ) ;
21+ const isPortal = str => str . startsWith ( "portal:/" ) ;
2122 const normalize = str => str . replace ( / \\ / g, `/` ) . replace ( / ^ \/ ? / , `/` ) ;
2223
2324 const dependencyTreeRoots = new Set ( pnpApi . getDependencyTreeRoots ( ) . map ( locator => {
@@ -44,7 +45,7 @@ const moduleWrapper = tsserver => {
4445 const resolved = isVirtual ( str ) ? pnpApi . resolveVirtual ( str ) : str ;
4546 if ( resolved ) {
4647 const locator = pnpApi . findPackageLocator ( resolved ) ;
47- if ( locator && dependencyTreeRoots . has ( `${ locator . name } @${ locator . reference } ` ) ) {
48+ if ( locator && ( dependencyTreeRoots . has ( `${ locator . name } @${ locator . reference } ` ) || isPortal ( locator . reference ) ) ) {
4849 str = resolved ;
4950 }
5051 }
@@ -60,14 +61,30 @@ const moduleWrapper = tsserver => {
6061 //
6162 // Ref: https://github.com/microsoft/vscode/issues/105014#issuecomment-686760910
6263 //
63- // Update Oct 8 2021: VSCode changed their format in 1.61.
64+ // 2021-10-08 : VSCode changed the format in 1.61.
6465 // Before | ^zip:/c:/foo/bar.zip/package.json
6566 // After | ^/zip//c:/foo/bar.zip/package.json
6667 //
68+ // 2022-04-06: VSCode changed the format in 1.66.
69+ // Before | ^/zip//c:/foo/bar.zip/package.json
70+ // After | ^/zip/c:/foo/bar.zip/package.json
71+ //
72+ // 2022-05-06: VSCode changed the format in 1.68
73+ // Before | ^/zip/c:/foo/bar.zip/package.json
74+ // After | ^/zip//c:/foo/bar.zip/package.json
75+ //
6776 case `vscode <1.61` : {
6877 str = `^zip:${ str } ` ;
6978 } break ;
7079
80+ case `vscode <1.66` : {
81+ str = `^/zip/${ str } ` ;
82+ } break ;
83+
84+ case `vscode <1.68` : {
85+ str = `^/zip${ str } ` ;
86+ } break ;
87+
7188 case `vscode` : {
7289 str = `^/zip/${ str } ` ;
7390 } break ;
@@ -85,7 +102,7 @@ const moduleWrapper = tsserver => {
85102 // everything else is up to neovim
86103 case `neovim` : {
87104 str = normalize ( resolved ) . replace ( / \. z i p \/ / , `.zip::` ) ;
88- str = `zipfile:${ str } ` ;
105+ str = `zipfile:// ${ str } ` ;
89106 } break ;
90107
91108 default : {
@@ -100,8 +117,7 @@ const moduleWrapper = tsserver => {
100117
101118 function fromEditorPath ( str ) {
102119 switch ( hostInfo ) {
103- case `coc-nvim` :
104- case `neovim` : {
120+ case `coc-nvim` : {
105121 str = str . replace ( / \. z i p : : / , `.zip/` ) ;
106122 // The path for coc-nvim is in format of /<pwd>/zipfile:/<pwd>/.yarn/...
107123 // So in order to convert it back, we use .* to match all the thing
@@ -111,11 +127,15 @@ const moduleWrapper = tsserver => {
111127 : str . replace ( / ^ .* z i p f i l e : / , `` ) ;
112128 } break ;
113129
130+ case `neovim` : {
131+ str = str . replace ( / \. z i p : : / , `.zip/` ) ;
132+ // The path for neovim is in format of zipfile:///<pwd>/.yarn/...
133+ return str . replace ( / ^ z i p f i l e : \/ \/ / , `` ) ;
134+ } break ;
135+
114136 case `vscode` :
115137 default : {
116- return process . platform === `win32`
117- ? str . replace ( / ^ \^ ? ( z i p : | \/ z i p ) \/ + / , `` )
118- : str . replace ( / ^ \^ ? ( z i p : | \/ z i p ) \/ + / , `/` ) ;
138+ return str . replace ( / ^ \^ ? ( z i p : | \/ z i p ( \/ t s - n u l - a u t h o r i t y ) ? ) \/ + / , process . platform === `win32` ? `` : `/` )
119139 } break ;
120140 }
121141 }
@@ -143,8 +163,9 @@ const moduleWrapper = tsserver => {
143163 let hostInfo = `unknown` ;
144164
145165 Object . assign ( Session . prototype , {
146- onMessage ( /** @type {string } */ message ) {
147- const parsedMessage = JSON . parse ( message )
166+ onMessage ( /** @type {string | object } */ message ) {
167+ const isStringMessage = typeof message === 'string' ;
168+ const parsedMessage = isStringMessage ? JSON . parse ( message ) : message ;
148169
149170 if (
150171 parsedMessage != null &&
@@ -153,14 +174,32 @@ const moduleWrapper = tsserver => {
153174 typeof parsedMessage . arguments . hostInfo === `string`
154175 ) {
155176 hostInfo = parsedMessage . arguments . hostInfo ;
156- if ( hostInfo === `vscode` && process . env . VSCODE_IPC_HOOK && process . env . VSCODE_IPC_HOOK . match ( / C o d e \/ 1 \. ( [ 1 - 5 ] [ 0 - 9 ] | 6 0 ) \. / ) ) {
157- hostInfo += ` <1.61` ;
177+ if ( hostInfo === `vscode` && process . env . VSCODE_IPC_HOOK ) {
178+ const [ , major , minor ] = ( process . env . VSCODE_IPC_HOOK . match (
179+ // The RegExp from https://semver.org/ but without the caret at the start
180+ / ( 0 | [ 1 - 9 ] \d * ) \. ( 0 | [ 1 - 9 ] \d * ) \. ( 0 | [ 1 - 9 ] \d * ) (?: - ( (?: 0 | [ 1 - 9 ] \d * | \d * [ a - z A - Z - ] [ 0 - 9 a - z A - Z - ] * ) (?: \. (?: 0 | [ 1 - 9 ] \d * | \d * [ a - z A - Z - ] [ 0 - 9 a - z A - Z - ] * ) ) * ) ) ? (?: \+ ( [ 0 - 9 a - z A - Z - ] + (?: \. [ 0 - 9 a - z A - Z - ] + ) * ) ) ? $ /
181+ ) ?? [ ] ) . map ( Number )
182+
183+ if ( major === 1 ) {
184+ if ( minor < 61 ) {
185+ hostInfo += ` <1.61` ;
186+ } else if ( minor < 66 ) {
187+ hostInfo += ` <1.66` ;
188+ } else if ( minor < 68 ) {
189+ hostInfo += ` <1.68` ;
190+ }
191+ }
158192 }
159193 }
160194
161- return originalOnMessage . call ( this , JSON . stringify ( parsedMessage , ( key , value ) => {
162- return typeof value === `string` ? fromEditorPath ( value ) : value ;
163- } ) ) ;
195+ const processedMessageJSON = JSON . stringify ( parsedMessage , ( key , value ) => {
196+ return typeof value === 'string' ? fromEditorPath ( value ) : value ;
197+ } ) ;
198+
199+ return originalOnMessage . call (
200+ this ,
201+ isStringMessage ? processedMessageJSON : JSON . parse ( processedMessageJSON )
202+ ) ;
164203 } ,
165204
166205 send ( /** @type {any } */ msg ) {
0 commit comments