@@ -40,6 +40,9 @@ export const generateTypescriptBaseWrapper: GenerateBaseWrapper = async (pnpApi:
4040 const {isAbsolute} = require(\`path\`);
4141 const pnpApi = require(\`pnpapi\`);
4242
43+ const isVirtual = str => str.match(/\\/(\\$\\$virtual|__virtual__)\\//);
44+ const normalize = str => str.replace(/\\\\/g, \`/\`).replace(/^\\/?/, \`/\`);
45+
4346 const dependencyTreeRoots = new Set(pnpApi.getDependencyTreeRoots().map(locator => {
4447 return \`\${locator.name}@\${locator.reference}\`;
4548 }));
@@ -50,7 +53,7 @@ export const generateTypescriptBaseWrapper: GenerateBaseWrapper = async (pnpApi:
5053
5154 function toEditorPath(str) {
5255 // We add the \`zip:\` prefix to both \`.zip/\` paths and virtual paths
53- if (isAbsolute(str) && !str.match(/^\\^zip:/) && (str.match(/\\.zip\\//) || str.match(/\\/(\\$\\$virtual|__virtual__)\\// ))) {
56+ if (isAbsolute(str) && !str.match(/^\\^zip:/) && (str.match(/\\.zip\\//) || isVirtual(str ))) {
5457 // We also take the opportunity to turn virtual paths into physical ones;
5558 // this makes is much easier to work with workspaces that list peer
5659 // dependencies, since otherwise Ctrl+Click would bring us to the virtual
@@ -61,26 +64,41 @@ export const generateTypescriptBaseWrapper: GenerateBaseWrapper = async (pnpApi:
6164 // with peer dep (otherwise jumping into react-dom would show resolution
6265 // errors on react).
6366 //
64- const resolved = pnpApi.resolveVirtual(str);
67+ const resolved = isVirtual(str) ? pnpApi.resolveVirtual(str) : str ;
6568 if (resolved) {
6669 const locator = pnpApi.findPackageLocator(resolved);
6770 if (locator && dependencyTreeRoots.has(\`\${locator.name}@\${locator.reference}\`)) {
68- str = resolved;
71+ str = resolved;
6972 }
7073 }
7174
72- str = str.replace(/\\\\/g, \`/\`)
73- str = str.replace(/^\\/?/, \`/\`);
75+ str = normalize(str);
7476
75- // Absolute VSCode \`Uri.fsPath\`s need to start with a slash.
76- // VSCode only adds it automatically for supported schemes,
77- // so we have to do it manually for the \`zip\` scheme.
78- // The path needs to start with a caret otherwise VSCode doesn't handle the protocol
79- //
80- // Ref: https://github.com/microsoft/vscode/issues/105014#issuecomment-686760910
81- //
8277 if (str.match(/\\.zip\\//)) {
83- str = \`\${isVSCode ? \`^\` : \`\`}zip:\${str}\`;
78+ switch (hostInfo) {
79+ // Absolute VSCode \`Uri.fsPath\`s need to start with a slash.
80+ // VSCode only adds it automatically for supported schemes,
81+ // so we have to do it manually for the \`zip\` scheme.
82+ // The path needs to start with a caret otherwise VSCode doesn't handle the protocol
83+ //
84+ // Ref: https://github.com/microsoft/vscode/issues/105014#issuecomment-686760910
85+ //
86+ case \`vscode\`: {
87+ str = \`^zip:\${str}\`;
88+ } break;
89+
90+ // To make "go to definition" work,
91+ // We have to resolve the actual file system path from virtual path
92+ // and convert scheme to supported by [vim-rzip](https://github.com/lbrayner/vim-rzip)
93+ case \`coc-nvim\`: {
94+ str = normalize(resolved).replace(/\\.zip\\//, \`.zip::\`);
95+ str = resolve(\`zipfile:\${str}\`);
96+ } break;
97+
98+ default: {
99+ str = \`zip:\${str}\`;
100+ } break;
101+ }
84102 }
85103 }
86104
@@ -113,7 +131,7 @@ export const generateTypescriptBaseWrapper: GenerateBaseWrapper = async (pnpApi:
113131
114132 const Session = tsserver.server.Session;
115133 const {onMessage: originalOnMessage, send: originalSend} = Session.prototype;
116- let isVSCode = false ;
134+ let hostInfo = \`unknown\` ;
117135
118136 return Object.assign(Session.prototype, {
119137 onMessage(/** @type {string} */ message) {
@@ -123,9 +141,9 @@ export const generateTypescriptBaseWrapper: GenerateBaseWrapper = async (pnpApi:
123141 parsedMessage != null &&
124142 typeof parsedMessage === \`object\` &&
125143 parsedMessage.arguments &&
126- parsedMessage.arguments.hostInfo === \`vscode \`
144+ typeof parsedMessage.arguments.hostInfo === \`string \`
127145 ) {
128- isVSCode = true ;
146+ hostInfo = parsedMessage.arguments.hostInfo ;
129147 }
130148
131149 return originalOnMessage.call(this, JSON.stringify(parsedMessage, (key, value) => {
0 commit comments