|
|
|
@ -18,6 +18,7 @@ const moduleWrapper = tsserver => {
|
|
|
|
|
const pnpApi = require(`pnpapi`);
|
|
|
|
|
|
|
|
|
|
const isVirtual = str => str.match(/\/(\$\$virtual|__virtual__)\//);
|
|
|
|
|
const isPortal = str => str.startsWith("portal:/");
|
|
|
|
|
const normalize = str => str.replace(/\\/g, `/`).replace(/^\/?/, `/`);
|
|
|
|
|
|
|
|
|
|
const dependencyTreeRoots = new Set(pnpApi.getDependencyTreeRoots().map(locator => {
|
|
|
|
@ -44,7 +45,7 @@ const moduleWrapper = tsserver => {
|
|
|
|
|
const resolved = isVirtual(str) ? pnpApi.resolveVirtual(str) : str;
|
|
|
|
|
if (resolved) {
|
|
|
|
|
const locator = pnpApi.findPackageLocator(resolved);
|
|
|
|
|
if (locator && dependencyTreeRoots.has(`${locator.name}@${locator.reference}`)) {
|
|
|
|
|
if (locator && (dependencyTreeRoots.has(`${locator.name}@${locator.reference}`) || isPortal(locator.reference))) {
|
|
|
|
|
str = resolved;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -60,18 +61,26 @@ const moduleWrapper = tsserver => {
|
|
|
|
|
//
|
|
|
|
|
// Ref: https://github.com/microsoft/vscode/issues/105014#issuecomment-686760910
|
|
|
|
|
//
|
|
|
|
|
// Update Oct 8 2021: VSCode changed their format in 1.61.
|
|
|
|
|
// Update 2021-10-08: VSCode changed their format in 1.61.
|
|
|
|
|
// Before | ^zip:/c:/foo/bar.zip/package.json
|
|
|
|
|
// After | ^/zip//c:/foo/bar.zip/package.json
|
|
|
|
|
//
|
|
|
|
|
// Update 2022-04-06: VSCode changed the format in 1.66.
|
|
|
|
|
// Before | ^/zip//c:/foo/bar.zip/package.json
|
|
|
|
|
// After | ^/zip/c:/foo/bar.zip/package.json
|
|
|
|
|
//
|
|
|
|
|
case `vscode <1.61`: {
|
|
|
|
|
str = `^zip:${str}`;
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
case `vscode`: {
|
|
|
|
|
case `vscode <1.66`: {
|
|
|
|
|
str = `^/zip/${str}`;
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
case `vscode`: {
|
|
|
|
|
str = `^/zip${str}`;
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
// To make "go to definition" work,
|
|
|
|
|
// We have to resolve the actual file system path from virtual path
|
|
|
|
|
// and convert scheme to supported by [vim-rzip](https://github.com/lbrayner/vim-rzip)
|
|
|
|
@ -85,7 +94,7 @@ const moduleWrapper = tsserver => {
|
|
|
|
|
// everything else is up to neovim
|
|
|
|
|
case `neovim`: {
|
|
|
|
|
str = normalize(resolved).replace(/\.zip\//, `.zip::`);
|
|
|
|
|
str = `zipfile:${str}`;
|
|
|
|
|
str = `zipfile://${str}`;
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
default: {
|
|
|
|
@ -100,8 +109,7 @@ const moduleWrapper = tsserver => {
|
|
|
|
|
|
|
|
|
|
function fromEditorPath(str) {
|
|
|
|
|
switch (hostInfo) {
|
|
|
|
|
case `coc-nvim`:
|
|
|
|
|
case `neovim`: {
|
|
|
|
|
case `coc-nvim`: {
|
|
|
|
|
str = str.replace(/\.zip::/, `.zip/`);
|
|
|
|
|
// The path for coc-nvim is in format of /<pwd>/zipfile:/<pwd>/.yarn/...
|
|
|
|
|
// So in order to convert it back, we use .* to match all the thing
|
|
|
|
@ -111,6 +119,12 @@ const moduleWrapper = tsserver => {
|
|
|
|
|
: str.replace(/^.*zipfile:/, ``);
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
case `neovim`: {
|
|
|
|
|
str = str.replace(/\.zip::/, `.zip/`);
|
|
|
|
|
// The path for neovim is in format of zipfile:///<pwd>/.yarn/...
|
|
|
|
|
return str.replace(/^zipfile:\/\//, ``);
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
|
|
case `vscode`:
|
|
|
|
|
default: {
|
|
|
|
|
return process.platform === `win32`
|
|
|
|
@ -143,8 +157,9 @@ const moduleWrapper = tsserver => {
|
|
|
|
|
let hostInfo = `unknown`;
|
|
|
|
|
|
|
|
|
|
Object.assign(Session.prototype, {
|
|
|
|
|
onMessage(/** @type {string} */ message) {
|
|
|
|
|
const parsedMessage = JSON.parse(message)
|
|
|
|
|
onMessage(/** @type {string | object} */ message) {
|
|
|
|
|
const isStringMessage = typeof message === 'string';
|
|
|
|
|
const parsedMessage = isStringMessage ? JSON.parse(message) : message;
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
parsedMessage != null &&
|
|
|
|
@ -153,14 +168,23 @@ const moduleWrapper = tsserver => {
|
|
|
|
|
typeof parsedMessage.arguments.hostInfo === `string`
|
|
|
|
|
) {
|
|
|
|
|
hostInfo = parsedMessage.arguments.hostInfo;
|
|
|
|
|
if (hostInfo === `vscode` && process.env.VSCODE_IPC_HOOK && process.env.VSCODE_IPC_HOOK.match(/Code\/1\.([1-5][0-9]|60)\./)) {
|
|
|
|
|
hostInfo += ` <1.61`;
|
|
|
|
|
if (hostInfo === `vscode` && process.env.VSCODE_IPC_HOOK) {
|
|
|
|
|
if (/(\/|-)1\.([1-5][0-9]|60)\./.test(process.env.VSCODE_IPC_HOOK)) {
|
|
|
|
|
hostInfo += ` <1.61`;
|
|
|
|
|
} else if (/(\/|-)1\.(6[1-5])\./.test(process.env.VSCODE_IPC_HOOK)) {
|
|
|
|
|
hostInfo += ` <1.66`;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return originalOnMessage.call(this, JSON.stringify(parsedMessage, (key, value) => {
|
|
|
|
|
return typeof value === `string` ? fromEditorPath(value) : value;
|
|
|
|
|
}));
|
|
|
|
|
const processedMessageJSON = JSON.stringify(parsedMessage, (key, value) => {
|
|
|
|
|
return typeof value === 'string' ? fromEditorPath(value) : value;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return originalOnMessage.call(
|
|
|
|
|
this,
|
|
|
|
|
isStringMessage ? processedMessageJSON : JSON.parse(processedMessageJSON)
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
send(/** @type {any} */ msg) {
|
|
|
|
|