@@ -40,6 +40,9 @@ export const generateTypescriptBaseWrapper: GenerateBaseWrapper = async (pnpApi:
40
40
const {isAbsolute} = require(\`path\`);
41
41
const pnpApi = require(\`pnpapi\`);
42
42
43
+ const isVirtual = str => str.match(/\\/(\\$\\$virtual|__virtual__)\\//);
44
+ const normalize = str => str.replace(/\\\\/g, \`/\`).replace(/^\\/?/, \`/\`);
45
+
43
46
const dependencyTreeRoots = new Set(pnpApi.getDependencyTreeRoots().map(locator => {
44
47
return \`\${locator.name}@\${locator.reference}\`;
45
48
}));
@@ -50,7 +53,7 @@ export const generateTypescriptBaseWrapper: GenerateBaseWrapper = async (pnpApi:
50
53
51
54
function toEditorPath(str) {
52
55
// 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 ))) {
54
57
// We also take the opportunity to turn virtual paths into physical ones;
55
58
// this makes is much easier to work with workspaces that list peer
56
59
// dependencies, since otherwise Ctrl+Click would bring us to the virtual
@@ -61,26 +64,41 @@ export const generateTypescriptBaseWrapper: GenerateBaseWrapper = async (pnpApi:
61
64
// with peer dep (otherwise jumping into react-dom would show resolution
62
65
// errors on react).
63
66
//
64
- const resolved = pnpApi.resolveVirtual(str);
67
+ const resolved = isVirtual(str) ? pnpApi.resolveVirtual(str) : str ;
65
68
if (resolved) {
66
69
const locator = pnpApi.findPackageLocator(resolved);
67
70
if (locator && dependencyTreeRoots.has(\`\${locator.name}@\${locator.reference}\`)) {
68
- str = resolved;
71
+ str = resolved;
69
72
}
70
73
}
71
74
72
- str = str.replace(/\\\\/g, \`/\`)
73
- str = str.replace(/^\\/?/, \`/\`);
75
+ str = normalize(str);
74
76
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
- //
82
77
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
+ }
84
102
}
85
103
}
86
104
@@ -113,7 +131,7 @@ export const generateTypescriptBaseWrapper: GenerateBaseWrapper = async (pnpApi:
113
131
114
132
const Session = tsserver.server.Session;
115
133
const {onMessage: originalOnMessage, send: originalSend} = Session.prototype;
116
- let isVSCode = false ;
134
+ let hostInfo = \`unknown\` ;
117
135
118
136
return Object.assign(Session.prototype, {
119
137
onMessage(/** @type {string} */ message) {
@@ -123,9 +141,9 @@ export const generateTypescriptBaseWrapper: GenerateBaseWrapper = async (pnpApi:
123
141
parsedMessage != null &&
124
142
typeof parsedMessage === \`object\` &&
125
143
parsedMessage.arguments &&
126
- parsedMessage.arguments.hostInfo === \`vscode \`
144
+ typeof parsedMessage.arguments.hostInfo === \`string \`
127
145
) {
128
- isVSCode = true ;
146
+ hostInfo = parsedMessage.arguments.hostInfo ;
129
147
}
130
148
131
149
return originalOnMessage.call(this, JSON.stringify(parsedMessage, (key, value) => {
0 commit comments