11#!/usr/bin/env node
22
33const { existsSync} = require ( `fs` ) ;
4- const { createRequire, createRequireFromPath } = require ( `module` ) ;
4+ const { createRequire} = require ( `module` ) ;
55const { resolve} = require ( `path` ) ;
66
77const relPnpApiPath = "../../../../.pnp.cjs" ;
88
99const absPnpApiPath = resolve ( __dirname , relPnpApiPath ) ;
10- const absRequire = ( createRequire || createRequireFromPath ) ( absPnpApiPath ) ;
10+ const absRequire = createRequire ( absPnpApiPath ) ;
1111
1212const moduleWrapper = tsserver => {
1313 if ( ! process . versions . pnp ) {
@@ -61,14 +61,18 @@ const moduleWrapper = tsserver => {
6161 //
6262 // Ref: https://github.com/microsoft/vscode/issues/105014#issuecomment-686760910
6363 //
64- // Update 2021-10-08: VSCode changed their format in 1.61.
64+ // 2021-10-08: VSCode changed the format in 1.61.
6565 // Before | ^zip:/c:/foo/bar.zip/package.json
6666 // After | ^/zip//c:/foo/bar.zip/package.json
6767 //
68- // Update 2022-04-06: VSCode changed the format in 1.66.
68+ // 2022-04-06: VSCode changed the format in 1.66.
6969 // Before | ^/zip//c:/foo/bar.zip/package.json
7070 // After | ^/zip/c:/foo/bar.zip/package.json
7171 //
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+ //
7276 case `vscode <1.61` : {
7377 str = `^zip:${ str } ` ;
7478 } break ;
@@ -77,10 +81,14 @@ const moduleWrapper = tsserver => {
7781 str = `^/zip/${ str } ` ;
7882 } break ;
7983
80- case `vscode` : {
84+ case `vscode <1.68 ` : {
8185 str = `^/zip${ str } ` ;
8286 } break ;
8387
88+ case `vscode` : {
89+ str = `^/zip/${ str } ` ;
90+ } break ;
91+
8492 // To make "go to definition" work,
8593 // We have to resolve the actual file system path from virtual path
8694 // and convert scheme to supported by [vim-rzip](https://github.com/lbrayner/vim-rzip)
@@ -101,6 +109,8 @@ const moduleWrapper = tsserver => {
101109 str = `zip:${ str } ` ;
102110 } break ;
103111 }
112+ } else {
113+ str = str . replace ( / ^ \/ ? / , process . platform === `win32` ? `` : `/` ) ;
104114 }
105115 }
106116
@@ -127,9 +137,7 @@ const moduleWrapper = tsserver => {
127137
128138 case `vscode` :
129139 default : {
130- return process . platform === `win32`
131- ? str . replace ( / ^ \^ ? ( z i p : | \/ z i p ) \/ + / , `` )
132- : str . replace ( / ^ \^ ? ( z i p : | \/ z i p ) \/ + / , `/` ) ;
140+ 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` ? `` : `/` )
133141 } break ;
134142 }
135143 }
@@ -169,10 +177,19 @@ const moduleWrapper = tsserver => {
169177 ) {
170178 hostInfo = parsedMessage . arguments . hostInfo ;
171179 if ( hostInfo === `vscode` && process . env . VSCODE_IPC_HOOK ) {
172- if ( / ( \/ | - ) 1 \. ( [ 1 - 5 ] [ 0 - 9 ] | 6 0 ) \. / . test ( process . env . VSCODE_IPC_HOOK ) ) {
173- hostInfo += ` <1.61` ;
174- } else if ( / ( \/ | - ) 1 \. ( 6 [ 1 - 5 ] ) \. / . test ( process . env . VSCODE_IPC_HOOK ) ) {
175- hostInfo += ` <1.66` ;
180+ const [ , major , minor ] = ( process . env . VSCODE_IPC_HOOK . match (
181+ // The RegExp from https://semver.org/ but without the caret at the start
182+ / ( 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 - ] + ) * ) ) ? $ /
183+ ) ?? [ ] ) . map ( Number )
184+
185+ if ( major === 1 ) {
186+ if ( minor < 61 ) {
187+ hostInfo += ` <1.61` ;
188+ } else if ( minor < 66 ) {
189+ hostInfo += ` <1.66` ;
190+ } else if ( minor < 68 ) {
191+ hostInfo += ` <1.68` ;
192+ }
176193 }
177194 }
178195 }
0 commit comments