@vue/typescript-plugin 2.0.4 → 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 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, info.languageServiceHost.getCompilationSettings(), vueOptions);
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
- files.set(fileName, (0, language_core_1.resolveCommonLanguageId)(fileName), snapshot);
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 && !arrayItemsEqual(oldFiles, newFiles)) {
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 arrayItemsEqual(a, b) {
184
- if (a.length !== b.length) {
209
+ function twoSetsEqual(a, b) {
210
+ if (a.size !== b.size) {
185
211
  return false;
186
212
  }
187
- const set = new Set(a);
188
- for (const file of b) {
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.js CHANGED
@@ -110,9 +110,23 @@ function sendRequestWorker(request, client) {
110
110
  dataChunks.push(chunk);
111
111
  });
112
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
+ }
113
118
  const data = Buffer.concat(dataChunks);
114
119
  const text = data.toString();
115
- resolve(JSON.parse(text));
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);
116
130
  });
117
131
  client.write(JSON.stringify(request));
118
132
  });
package/lib/server.js CHANGED
@@ -60,7 +60,6 @@ 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
  }
65
64
  connection.end();
66
65
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/typescript-plugin",
3
- "version": "2.0.4",
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.0",
16
- "@vue/language-core": "2.0.4",
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": "241300968fd3084c7c09139d05691a51a7800fdc"
22
+ "gitHead": "62b4fcb0d3f7153b5b2f5571af32f519117d8466"
23
23
  }