@vue/typescript-plugin 2.0.3 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -0
- package/index.js +35 -10
- package/lib/client.d.ts +1 -3
- package/lib/client.js +34 -13
- package/lib/server.js +1 -1
- package/package.json +4 -4
package/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# typescript plugin
|
|
2
|
+
|
|
3
|
+
This is a plug-in for `tsserver` or `typescript-language-server`. It must be
|
|
4
|
+
installed in a file-system location accessible by the language server or in the
|
|
5
|
+
`node_modules` directory of projects being edited.
|
|
6
|
+
|
|
7
|
+
The LSP client must be configured to explicitly enable this plug-in. This is
|
|
8
|
+
done by passing `initializationOptions` with the appropriate [`plugins`]
|
|
9
|
+
configuration to the language server:
|
|
10
|
+
|
|
11
|
+
[`plugins`]: https://github.com/typescript-language-server/typescript-language-server/blob/b224b878652438bcdd639137a6b1d1a6630129e4/docs/configuration.md?plain=1#L27-L31
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
"initializationOptions": {
|
|
15
|
+
"plugins": [
|
|
16
|
+
{
|
|
17
|
+
"name": "@vue/typescript-plugin",
|
|
18
|
+
"location": "/usr/local/lib/node_modules/@vue/typescript-plugin",
|
|
19
|
+
"languages": ["javascript", "typescript", "vue"],
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The `languages` field must specify file-types for which the plug-in will be
|
|
26
|
+
enabled. If the plug-in package is installed in the local `node_modules`, the
|
|
27
|
+
`location` field may contain any arbitrary string, but MUST be present.
|
|
28
|
+
|
|
29
|
+
## Client-specific configuration
|
|
30
|
+
|
|
31
|
+
- For neovim, see the [details on configuring `tsserver`][nvim].
|
|
32
|
+
|
|
33
|
+
[nvim]: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#vue-support
|
package/index.js
CHANGED
|
@@ -22,13 +22,30 @@ function createLanguageServicePlugin() {
|
|
|
22
22
|
decoratedLanguageServices.add(info.languageService);
|
|
23
23
|
decoratedLanguageServiceHosts.add(info.languageServiceHost);
|
|
24
24
|
const vueOptions = vue.resolveVueCompilerOptions(getVueCompilerOptions());
|
|
25
|
-
const languagePlugin = vue.createVueLanguagePlugin(ts, id => id,
|
|
25
|
+
const languagePlugin = vue.createVueLanguagePlugin(ts, id => id, fileName => {
|
|
26
|
+
if (info.languageServiceHost.useCaseSensitiveFileNames?.() ?? false) {
|
|
27
|
+
return externalFiles.get(info.project)?.has(fileName) ?? false;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
const lowerFileName = fileName.toLowerCase();
|
|
31
|
+
for (const externalFile of externalFiles.get(info.project) ?? []) {
|
|
32
|
+
if (externalFile.toLowerCase() === lowerFileName) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}, info.languageServiceHost.getCompilationSettings(), vueOptions);
|
|
26
39
|
const extensions = languagePlugin.typescript?.extraFileExtensions.map(ext => '.' + ext.extension) ?? [];
|
|
27
40
|
const getScriptSnapshot = info.languageServiceHost.getScriptSnapshot.bind(info.languageServiceHost);
|
|
28
41
|
const files = (0, language_core_1.createFileRegistry)([languagePlugin], ts.sys.useCaseSensitiveFileNames, fileName => {
|
|
29
42
|
const snapshot = getScriptSnapshot(fileName);
|
|
30
43
|
if (snapshot) {
|
|
31
|
-
|
|
44
|
+
let languageId = (0, language_core_1.resolveCommonLanguageId)(fileName);
|
|
45
|
+
if (extensions.some(ext => fileName.endsWith(ext))) {
|
|
46
|
+
languageId = 'vue';
|
|
47
|
+
}
|
|
48
|
+
files.set(fileName, languageId, snapshot);
|
|
32
49
|
}
|
|
33
50
|
else {
|
|
34
51
|
files.delete(fileName);
|
|
@@ -168,25 +185,33 @@ function createLanguageServicePlugin() {
|
|
|
168
185
|
if (updateLevel >= (1)
|
|
169
186
|
|| !externalFiles.has(project)) {
|
|
170
187
|
const oldFiles = externalFiles.get(project);
|
|
171
|
-
const newFiles = (0, decorateLanguageServiceHost_1.searchExternalFiles)(ts, project, projectExternalFileExtensions.get(project));
|
|
188
|
+
const newFiles = new Set((0, decorateLanguageServiceHost_1.searchExternalFiles)(ts, project, projectExternalFileExtensions.get(project)));
|
|
189
|
+
console.log('volar-search vue files');
|
|
190
|
+
for (const file of newFiles) {
|
|
191
|
+
console.log(file);
|
|
192
|
+
}
|
|
172
193
|
externalFiles.set(project, newFiles);
|
|
173
|
-
if (oldFiles && !
|
|
194
|
+
if (oldFiles && !twoSetsEqual(oldFiles, newFiles)) {
|
|
195
|
+
for (const oldFile of oldFiles) {
|
|
196
|
+
if (!newFiles.has(oldFile)) {
|
|
197
|
+
utils_1.projects.get(project)?.files.delete(oldFile);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
174
200
|
project.refreshDiagnostics();
|
|
175
201
|
}
|
|
176
202
|
}
|
|
177
|
-
return externalFiles.get(project);
|
|
203
|
+
return [...externalFiles.get(project)];
|
|
178
204
|
},
|
|
179
205
|
};
|
|
180
206
|
return pluginModule;
|
|
181
207
|
};
|
|
182
208
|
}
|
|
183
|
-
function
|
|
184
|
-
if (a.
|
|
209
|
+
function twoSetsEqual(a, b) {
|
|
210
|
+
if (a.size !== b.size) {
|
|
185
211
|
return false;
|
|
186
212
|
}
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
if (!set.has(file)) {
|
|
213
|
+
for (const file of a) {
|
|
214
|
+
if (!b.has(file)) {
|
|
190
215
|
return false;
|
|
191
216
|
}
|
|
192
217
|
}
|
package/lib/client.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import type * as net from 'net';
|
|
3
1
|
import type * as ts from 'typescript';
|
|
4
2
|
import type { NamedPipeServer } from './utils';
|
|
5
3
|
export declare function collectExtractProps(...args: Parameters<typeof import('./requests/collectExtractProps.js')['collectExtractProps']>): Promise<{
|
|
@@ -14,4 +12,4 @@ export declare function getComponentEvents(...args: Parameters<typeof import('./
|
|
|
14
12
|
export declare function getTemplateContextProps(...args: Parameters<typeof import('./requests/componentInfos.js')['getTemplateContextProps']>): Promise<string[] | null | undefined>;
|
|
15
13
|
export declare function getComponentNames(...args: Parameters<typeof import('./requests/componentInfos.js')['getComponentNames']>): Promise<string[] | null | undefined>;
|
|
16
14
|
export declare function getElementAttrs(...args: Parameters<typeof import('./requests/componentInfos.js')['getElementAttrs']>): Promise<string[] | null | undefined>;
|
|
17
|
-
export declare function
|
|
15
|
+
export declare function searchNamedPipeServerForFile(fileName: string): Promise<NamedPipeServer | undefined>;
|
package/lib/client.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.searchNamedPipeServerForFile = exports.getElementAttrs = exports.getComponentNames = exports.getTemplateContextProps = exports.getComponentEvents = exports.getComponentProps = exports.getQuickInfoAtPosition = exports.getPropertiesAtLocation = exports.collectExtractProps = void 0;
|
|
4
4
|
const fs = require("fs");
|
|
5
5
|
const path = require("path");
|
|
6
6
|
const utils_1 = require("./utils");
|
|
@@ -62,17 +62,19 @@ function getElementAttrs(...args) {
|
|
|
62
62
|
}
|
|
63
63
|
exports.getElementAttrs = getElementAttrs;
|
|
64
64
|
async function sendRequest(request) {
|
|
65
|
-
const
|
|
66
|
-
if (!
|
|
65
|
+
const server = await searchNamedPipeServerForFile(request.args[0]);
|
|
66
|
+
if (!server) {
|
|
67
67
|
console.warn('[Vue Named Pipe Client] No server found for', request.args[0]);
|
|
68
68
|
return;
|
|
69
69
|
}
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
const client = await (0, utils_1.connect)(server.path);
|
|
71
|
+
if (!client) {
|
|
72
|
+
console.warn('[Vue Named Pipe Client] Failed to connect to', server.path);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
return await sendRequestWorker(request, client);
|
|
74
76
|
}
|
|
75
|
-
async function
|
|
77
|
+
async function searchNamedPipeServerForFile(fileName) {
|
|
76
78
|
if (!fs.existsSync(utils_1.pipeTable)) {
|
|
77
79
|
return;
|
|
78
80
|
}
|
|
@@ -87,7 +89,7 @@ async function connectForFile(fileName) {
|
|
|
87
89
|
if (client) {
|
|
88
90
|
const response = await sendRequestWorker({ type: 'containsFile', args: [fileName] }, client);
|
|
89
91
|
if (response) {
|
|
90
|
-
return
|
|
92
|
+
return server;
|
|
91
93
|
}
|
|
92
94
|
}
|
|
93
95
|
}
|
|
@@ -95,17 +97,36 @@ async function connectForFile(fileName) {
|
|
|
95
97
|
if (!path.relative(server.currentDirectory, fileName).startsWith('..')) {
|
|
96
98
|
const client = await (0, utils_1.connect)(server.path);
|
|
97
99
|
if (client) {
|
|
98
|
-
return
|
|
100
|
+
return server;
|
|
99
101
|
}
|
|
100
102
|
}
|
|
101
103
|
}
|
|
102
104
|
}
|
|
103
|
-
exports.
|
|
105
|
+
exports.searchNamedPipeServerForFile = searchNamedPipeServerForFile;
|
|
104
106
|
function sendRequestWorker(request, client) {
|
|
105
107
|
return new Promise(resolve => {
|
|
106
|
-
|
|
108
|
+
let dataChunks = [];
|
|
109
|
+
client.on('data', chunk => {
|
|
110
|
+
dataChunks.push(chunk);
|
|
111
|
+
});
|
|
112
|
+
client.on('end', () => {
|
|
113
|
+
if (!dataChunks.length) {
|
|
114
|
+
console.warn('[Vue Named Pipe Client] No response from server for request:', request.type);
|
|
115
|
+
resolve(undefined);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const data = Buffer.concat(dataChunks);
|
|
107
119
|
const text = data.toString();
|
|
108
|
-
|
|
120
|
+
let json = null;
|
|
121
|
+
try {
|
|
122
|
+
json = JSON.parse(text);
|
|
123
|
+
}
|
|
124
|
+
catch (e) {
|
|
125
|
+
console.error('[Vue Named Pipe Client] Failed to parse response:', text);
|
|
126
|
+
resolve(undefined);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
resolve(json);
|
|
109
130
|
});
|
|
110
131
|
client.write(JSON.stringify(request));
|
|
111
132
|
});
|
package/lib/server.js
CHANGED
|
@@ -60,8 +60,8 @@ function startNamedPipeServer(serverKind, currentDirectory) {
|
|
|
60
60
|
}
|
|
61
61
|
else {
|
|
62
62
|
console.warn('[Vue Named Pipe Server] Unknown request type:', request.type);
|
|
63
|
-
connection.write(JSON.stringify(null));
|
|
64
63
|
}
|
|
64
|
+
connection.end();
|
|
65
65
|
});
|
|
66
66
|
connection.on('error', err => console.error('[Vue Named Pipe Server]', err.message));
|
|
67
67
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/typescript-plugin",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
"directory": "packages/typescript-plugin"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@volar/typescript": "~2.1.
|
|
16
|
-
"@vue/language-core": "2.0.
|
|
15
|
+
"@volar/typescript": "~2.1.1",
|
|
16
|
+
"@vue/language-core": "2.0.5",
|
|
17
17
|
"@vue/shared": "^3.4.0"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@types/node": "latest"
|
|
21
21
|
},
|
|
22
|
-
"gitHead": "
|
|
22
|
+
"gitHead": "62b4fcb0d3f7153b5b2f5571af32f519117d8466"
|
|
23
23
|
}
|