@vue/language-server 3.0.7 → 3.0.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-server",
3
- "version": "3.0.7",
3
+ "version": "3.0.8",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -17,9 +17,9 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@volar/language-server": "2.4.23",
20
- "@vue/language-core": "3.0.7",
21
- "@vue/language-service": "3.0.7",
22
- "@vue/typescript-plugin": "3.0.7",
20
+ "@vue/language-core": "3.0.8",
21
+ "@vue/language-service": "3.0.8",
22
+ "@vue/typescript-plugin": "3.0.8",
23
23
  "vscode-uri": "^3.0.8"
24
24
  },
25
25
  "peerDependencies": {
@@ -29,5 +29,5 @@
29
29
  "@typescript/server-harness": "latest",
30
30
  "@volar/test-utils": "2.4.23"
31
31
  },
32
- "gitHead": "6022b75534487f8a031dfc61a7879f900b64d414"
32
+ "gitHead": "f7bdeaa7bb476df1fc8ff46c504d75c1869b0be9"
33
33
  }
@@ -1,27 +0,0 @@
1
- import type * as ts from 'typescript';
2
- declare const enum TrackKind {
3
- AccessDotValue = 0,
4
- AccessAnyValue = 1,
5
- Call = 2
6
- }
7
- interface SignalNode {
8
- bindingInfo?: {
9
- isRef: boolean;
10
- name: ts.BindingName;
11
- trackKinds: TrackKind[];
12
- };
13
- trackInfo?: {
14
- depsHandler: ts.Node;
15
- needToUse: boolean;
16
- };
17
- sideEffectInfo?: {
18
- isEffect: boolean;
19
- handler: ts.Node;
20
- };
21
- }
22
- export declare function analyze(ts: typeof import('typescript'), languageService: ts.LanguageService, fileName: string, position: number): {
23
- sourceFile: ts.SourceFile;
24
- subscribers: SignalNode[];
25
- dependencies: ts.Node[];
26
- } | undefined;
27
- export {};
@@ -1,460 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.analyze = analyze;
4
- const language_core_1 = require("@vue/language-core");
5
- function analyze(ts, languageService, fileName, position) {
6
- const sourceFile = languageService.getProgram().getSourceFile(fileName);
7
- const { signals, dotValueAccesses, dotAnyAccesses, functionCalls } = collect(ts, sourceFile);
8
- let signal = findSignalByNamePosition(position);
9
- if (!signal) {
10
- signal = findEffectByEffectHandlerPosition(position);
11
- if (signal?.bindingInfo) {
12
- position = signal.bindingInfo.name.getStart(sourceFile);
13
- }
14
- }
15
- if (!signal) {
16
- return;
17
- }
18
- const subscribers = signal.bindingInfo
19
- ? findSubscribers(signal.bindingInfo.name, signal.bindingInfo.trackKinds)
20
- : [];
21
- const dependencies = signal
22
- ? findDependencies(signal)
23
- : [];
24
- if ((!signal.sideEffectInfo?.isEffect && !subscribers.length)
25
- || (!signal.bindingInfo?.isRef && !dependencies.length)) {
26
- return;
27
- }
28
- return {
29
- sourceFile,
30
- subscribers: [...new Set(subscribers)],
31
- dependencies: [...new Set(dependencies)],
32
- };
33
- function findDependencies(signal, visited = new Set()) {
34
- if (visited.has(signal)) {
35
- return [];
36
- }
37
- visited.add(signal);
38
- const nodes = [];
39
- let hasRef = signal.bindingInfo?.isRef ?? false;
40
- if (signal.trackInfo) {
41
- const { needToUse } = signal.trackInfo;
42
- visit(signal.trackInfo.depsHandler, needToUse);
43
- signal.trackInfo.depsHandler.forEachChild(child => visit(child, needToUse));
44
- }
45
- if (!hasRef) {
46
- return [];
47
- }
48
- return nodes;
49
- function visit(node, needToUse, parentIsPropertyAccess = false) {
50
- if (!needToUse) {
51
- if (!parentIsPropertyAccess && ts.isIdentifier(node)) {
52
- const definition = languageService.getDefinitionAtPosition(fileName, node.getStart(sourceFile));
53
- for (const info of definition ?? []) {
54
- if (info.fileName !== fileName) {
55
- continue;
56
- }
57
- const signal = findSignalByNamePosition(info.textSpan.start);
58
- if (!signal) {
59
- continue;
60
- }
61
- if (signal.bindingInfo) {
62
- nodes.push(signal.bindingInfo.name);
63
- hasRef ||= signal.bindingInfo.isRef;
64
- }
65
- if (signal.sideEffectInfo) {
66
- nodes.push(signal.sideEffectInfo.handler);
67
- }
68
- const deps = findDependencies(signal, visited);
69
- nodes.push(...deps);
70
- hasRef ||= deps.length > 0;
71
- }
72
- }
73
- }
74
- else if (ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node) || ts.isCallExpression(node)) {
75
- const definition = languageService.getDefinitionAtPosition(fileName, node.expression.getStart(sourceFile));
76
- for (const info of definition ?? []) {
77
- if (info.fileName !== fileName) {
78
- continue;
79
- }
80
- const signal = findSignalByNamePosition(info.textSpan.start);
81
- if (!signal) {
82
- continue;
83
- }
84
- const oldSize = nodes.length;
85
- if (signal.bindingInfo) {
86
- for (const trackKind of signal.bindingInfo.trackKinds) {
87
- if (ts.isPropertyAccessExpression(node)) {
88
- if (trackKind === 0 /* TrackKind.AccessDotValue */ && node.name.text === 'value') {
89
- nodes.push(signal.bindingInfo.name);
90
- hasRef ||= signal.bindingInfo.isRef;
91
- }
92
- if (trackKind === 1 /* TrackKind.AccessAnyValue */ && node.name.text !== '') {
93
- nodes.push(signal.bindingInfo.name);
94
- hasRef ||= signal.bindingInfo.isRef;
95
- }
96
- }
97
- else if (ts.isElementAccessExpression(node)) {
98
- if (trackKind === 1 /* TrackKind.AccessAnyValue */) {
99
- nodes.push(signal.bindingInfo.name);
100
- hasRef ||= signal.bindingInfo.isRef;
101
- }
102
- }
103
- else if (ts.isCallExpression(node)) {
104
- if (trackKind === 2 /* TrackKind.Call */) {
105
- nodes.push(signal.bindingInfo.name);
106
- hasRef ||= signal.bindingInfo.isRef;
107
- }
108
- }
109
- }
110
- }
111
- const signalDetected = nodes.length > oldSize;
112
- if (signalDetected) {
113
- if (signal.sideEffectInfo) {
114
- nodes.push(signal.sideEffectInfo.handler);
115
- }
116
- const deps = findDependencies(signal, visited);
117
- nodes.push(...deps);
118
- hasRef ||= deps.length > 0;
119
- }
120
- }
121
- }
122
- node.forEachChild(child => visit(child, needToUse, ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)));
123
- }
124
- }
125
- function findSubscribers(refName, trackKinds, visited = new Set()) {
126
- return (0, language_core_1.collectBindingRanges)(ts, refName, sourceFile)
127
- .map(range => findSubscribersWorker(range, trackKinds, visited))
128
- .flat();
129
- }
130
- function findSubscribersWorker(refName, trackKinds, visited = new Set()) {
131
- if (visited.has(refName.start)) {
132
- return [];
133
- }
134
- visited.add(refName.start);
135
- const references = languageService.findReferences(fileName, refName.start);
136
- if (!references) {
137
- return [];
138
- }
139
- const result = [];
140
- for (const reference of references) {
141
- for (const reference2 of reference.references) {
142
- if (reference2.fileName !== fileName) {
143
- continue;
144
- }
145
- const effect = findEffectByDepsHandlerPosition(reference2.textSpan.start);
146
- if (effect?.trackInfo) {
147
- if (effect.trackInfo.needToUse) {
148
- let match = false;
149
- for (const trackKind of trackKinds) {
150
- if (trackKind === 1 /* TrackKind.AccessAnyValue */) {
151
- match = dotAnyAccesses.has(reference2.textSpan.start + reference2.textSpan.length);
152
- }
153
- else if (trackKind === 0 /* TrackKind.AccessDotValue */) {
154
- match = dotValueAccesses.has(reference2.textSpan.start + reference2.textSpan.length);
155
- }
156
- else if (trackKind === 2 /* TrackKind.Call */) {
157
- match = functionCalls.has(reference2.textSpan.start + reference2.textSpan.length);
158
- }
159
- if (match) {
160
- break;
161
- }
162
- }
163
- if (!match) {
164
- continue;
165
- }
166
- }
167
- let hasEffect = effect.sideEffectInfo?.isEffect;
168
- if (effect.bindingInfo) {
169
- const subs = findSubscribers(effect.bindingInfo.name, effect.bindingInfo.trackKinds, visited);
170
- result.push(...subs);
171
- hasEffect ||= subs.length > 0;
172
- }
173
- if (hasEffect) {
174
- result.push(effect);
175
- }
176
- }
177
- }
178
- }
179
- return result;
180
- }
181
- function findSignalByNamePosition(position) {
182
- return signals.find(ref => ref.bindingInfo && ref.bindingInfo.name.getStart(sourceFile) <= position
183
- && ref.bindingInfo.name.getEnd() >= position);
184
- }
185
- function findEffectByEffectHandlerPosition(position) {
186
- return signals.filter(ref => ref.sideEffectInfo && ref.sideEffectInfo.handler.getStart(sourceFile) <= position
187
- && ref.sideEffectInfo.handler.getEnd() >= position).sort((a, b) => a.sideEffectInfo.handler.getWidth(sourceFile) - b.sideEffectInfo.handler.getWidth(sourceFile))[0];
188
- }
189
- function findEffectByDepsHandlerPosition(position) {
190
- return signals.filter(ref => ref.trackInfo && ref.trackInfo.depsHandler.getStart(sourceFile) <= position
191
- && ref.trackInfo.depsHandler.getEnd() >= position).sort((a, b) => a.trackInfo.depsHandler.getWidth(sourceFile) - b.trackInfo.depsHandler.getWidth(sourceFile))[0];
192
- }
193
- }
194
- function collect(ts, sourceFile) {
195
- const signals = [];
196
- const dotValueAccesses = new Set();
197
- const dotAnyAccesses = new Set();
198
- const functionCalls = new Set();
199
- sourceFile.forEachChild(function visit(node) {
200
- if (ts.isVariableDeclaration(node)) {
201
- if (node.initializer && ts.isCallExpression(node.initializer)) {
202
- const call = node.initializer;
203
- if (ts.isIdentifier(call.expression)) {
204
- const callName = call.expression.escapedText;
205
- if (callName === 'ref' || callName === 'shallowRef' || callName === 'toRef' || callName === 'useTemplateRef'
206
- || callName === 'defineModel') {
207
- signals.push({
208
- bindingInfo: {
209
- isRef: true,
210
- name: node.name,
211
- trackKinds: [0 /* TrackKind.AccessDotValue */],
212
- },
213
- });
214
- }
215
- else if (callName === 'reactive' || callName === 'shallowReactive' || callName === 'defineProps'
216
- || callName === 'withDefaults') {
217
- signals.push({
218
- bindingInfo: {
219
- isRef: true,
220
- name: node.name,
221
- trackKinds: [1 /* TrackKind.AccessAnyValue */],
222
- },
223
- });
224
- }
225
- // TODO: toRefs
226
- }
227
- }
228
- }
229
- else if (ts.isFunctionDeclaration(node)) {
230
- if (node.name && node.body) {
231
- signals.push({
232
- bindingInfo: {
233
- isRef: false,
234
- name: node.name,
235
- trackKinds: [2 /* TrackKind.Call */],
236
- },
237
- trackInfo: {
238
- depsHandler: node.body,
239
- needToUse: true,
240
- },
241
- sideEffectInfo: {
242
- isEffect: false,
243
- handler: node.body,
244
- },
245
- });
246
- }
247
- }
248
- else if (ts.isVariableStatement(node)) {
249
- for (const declaration of node.declarationList.declarations) {
250
- const name = declaration.name;
251
- const callback = declaration.initializer;
252
- if (callback && ts.isIdentifier(name) && (ts.isArrowFunction(callback) || ts.isFunctionExpression(callback))) {
253
- signals.push({
254
- bindingInfo: {
255
- isRef: false,
256
- name: name,
257
- trackKinds: [2 /* TrackKind.Call */],
258
- },
259
- trackInfo: {
260
- depsHandler: callback,
261
- needToUse: true,
262
- },
263
- sideEffectInfo: {
264
- isEffect: false,
265
- handler: callback,
266
- },
267
- });
268
- }
269
- }
270
- }
271
- else if (ts.isParameter(node)) {
272
- if (node.type && ts.isTypeReferenceNode(node.type)) {
273
- const typeName = node.type.typeName.getText(sourceFile);
274
- if (typeName.endsWith('Ref')) {
275
- signals.push({
276
- bindingInfo: {
277
- isRef: true,
278
- name: node.name,
279
- trackKinds: [0 /* TrackKind.AccessDotValue */],
280
- },
281
- });
282
- }
283
- }
284
- }
285
- else if (ts.isCallExpression(node) && ts.isIdentifier(node.expression)) {
286
- const call = node;
287
- const callName = node.expression.escapedText;
288
- if ((callName === 'effect' || callName === 'watchEffect') && call.arguments.length) {
289
- const callback = call.arguments[0];
290
- if (ts.isArrowFunction(callback) || ts.isFunctionExpression(callback)) {
291
- signals.push({
292
- trackInfo: {
293
- depsHandler: callback.body,
294
- needToUse: true,
295
- },
296
- sideEffectInfo: {
297
- isEffect: true,
298
- handler: callback.body,
299
- },
300
- });
301
- }
302
- }
303
- if (callName === 'watch' && call.arguments.length >= 2) {
304
- const depsCallback = call.arguments[0];
305
- const effectCallback = call.arguments[1];
306
- if (ts.isArrowFunction(effectCallback) || ts.isFunctionExpression(effectCallback)) {
307
- if (ts.isArrowFunction(depsCallback) || ts.isFunctionExpression(depsCallback)) {
308
- signals.push({
309
- trackInfo: {
310
- depsHandler: depsCallback.body,
311
- needToUse: true,
312
- },
313
- sideEffectInfo: {
314
- isEffect: true,
315
- handler: effectCallback.body,
316
- },
317
- });
318
- }
319
- else {
320
- signals.push({
321
- trackInfo: {
322
- depsHandler: depsCallback,
323
- needToUse: false,
324
- },
325
- sideEffectInfo: {
326
- isEffect: true,
327
- handler: effectCallback.body,
328
- },
329
- });
330
- }
331
- }
332
- }
333
- else if ((0, language_core_1.hyphenateAttr)(callName).startsWith('use-')) {
334
- signals.push({
335
- bindingInfo: ts.isVariableDeclaration(call.parent)
336
- ? {
337
- isRef: true,
338
- name: call.parent.name,
339
- trackKinds: [1 /* TrackKind.AccessAnyValue */, 2 /* TrackKind.Call */],
340
- }
341
- : undefined,
342
- trackInfo: {
343
- depsHandler: call,
344
- needToUse: false,
345
- },
346
- });
347
- }
348
- else if ((callName === 'computed' || (0, language_core_1.hyphenateAttr)(callName).endsWith('-computed')) && call.arguments.length) {
349
- const arg = call.arguments[0];
350
- if (ts.isArrowFunction(arg) || ts.isFunctionExpression(arg)) {
351
- signals.push({
352
- bindingInfo: ts.isVariableDeclaration(call.parent)
353
- ? {
354
- isRef: true,
355
- name: call.parent.name,
356
- trackKinds: [0 /* TrackKind.AccessDotValue */],
357
- }
358
- : undefined,
359
- trackInfo: {
360
- depsHandler: arg.body,
361
- needToUse: true,
362
- },
363
- sideEffectInfo: {
364
- isEffect: true,
365
- handler: arg.body,
366
- },
367
- });
368
- }
369
- else if (ts.isIdentifier(arg)) {
370
- signals.push({
371
- bindingInfo: ts.isVariableDeclaration(call.parent)
372
- ? {
373
- isRef: true,
374
- name: call.parent.name,
375
- trackKinds: [0 /* TrackKind.AccessDotValue */],
376
- }
377
- : undefined,
378
- trackInfo: {
379
- depsHandler: arg,
380
- needToUse: false,
381
- },
382
- });
383
- }
384
- else if (ts.isObjectLiteralExpression(arg)) {
385
- for (const prop of arg.properties) {
386
- if (prop.name?.getText(sourceFile) === 'get') {
387
- if (ts.isPropertyAssignment(prop)) {
388
- const callback = prop.initializer;
389
- if (ts.isArrowFunction(callback) || ts.isFunctionExpression(callback)) {
390
- signals.push({
391
- bindingInfo: ts.isVariableDeclaration(call.parent)
392
- ? {
393
- isRef: true,
394
- name: call.parent.name,
395
- trackKinds: [0 /* TrackKind.AccessDotValue */],
396
- }
397
- : undefined,
398
- trackInfo: {
399
- depsHandler: callback.body,
400
- needToUse: true,
401
- },
402
- sideEffectInfo: {
403
- isEffect: true,
404
- handler: callback.body,
405
- },
406
- });
407
- }
408
- }
409
- else if (ts.isMethodDeclaration(prop) && prop.body) {
410
- signals.push({
411
- bindingInfo: ts.isVariableDeclaration(call.parent)
412
- ? {
413
- isRef: true,
414
- name: call.parent.name,
415
- trackKinds: [0 /* TrackKind.AccessDotValue */],
416
- }
417
- : undefined,
418
- trackInfo: {
419
- depsHandler: prop.body,
420
- needToUse: true,
421
- },
422
- sideEffectInfo: {
423
- isEffect: true,
424
- handler: prop.body,
425
- },
426
- });
427
- }
428
- }
429
- }
430
- }
431
- }
432
- }
433
- node.forEachChild(visit);
434
- });
435
- sourceFile.forEachChild(function visit(node) {
436
- if (ts.isPropertyAccessExpression(node)) {
437
- if (node.name.text === 'value') {
438
- dotValueAccesses.add(node.expression.getEnd());
439
- dotAnyAccesses.add(node.expression.getEnd());
440
- }
441
- else if (node.name.text !== '') {
442
- dotAnyAccesses.add(node.expression.getEnd());
443
- }
444
- }
445
- else if (ts.isElementAccessExpression(node)) {
446
- dotAnyAccesses.add(node.expression.getEnd());
447
- }
448
- else if (ts.isCallExpression(node)) {
449
- functionCalls.add(node.expression.getEnd());
450
- }
451
- node.forEachChild(visit);
452
- });
453
- return {
454
- signals,
455
- dotValueAccesses,
456
- dotAnyAccesses,
457
- functionCalls,
458
- };
459
- }
460
- //# sourceMappingURL=reactivityAnalyze.js.map
@@ -1,5 +0,0 @@
1
- import type * as ts from 'typescript';
2
- export declare function getLanguageService(ts: typeof import('typescript'), snapshot: ts.IScriptSnapshot, languageId: string): {
3
- languageService: ts.LanguageService;
4
- fileName: string;
5
- };
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLanguageService = getLanguageService;
4
- let currentProjectVersion = -1;
5
- let currentFileName = '';
6
- let currentSnapshot;
7
- let languageService;
8
- const host = {
9
- getProjectVersion: () => currentProjectVersion.toString(),
10
- getScriptFileNames: () => [currentFileName],
11
- getScriptVersion: () => currentProjectVersion.toString(),
12
- getScriptSnapshot: fileName => fileName === currentFileName ? currentSnapshot : undefined,
13
- getCompilationSettings: () => ({
14
- allowJs: true,
15
- }),
16
- getCurrentDirectory: () => '',
17
- getDefaultLibFileName: () => '',
18
- readFile: () => undefined,
19
- fileExists: fileName => fileName === currentFileName,
20
- };
21
- // TODO: share with volar-service-typescript
22
- function getLanguageService(ts, snapshot, languageId) {
23
- if (currentSnapshot !== snapshot) {
24
- currentSnapshot = snapshot;
25
- currentFileName = '/tmp.' + (languageId === 'javascript'
26
- ? 'js'
27
- : languageId === 'typescriptreact'
28
- ? 'tsx'
29
- : languageId === 'javascriptreact'
30
- ? 'jsx'
31
- : 'ts');
32
- currentProjectVersion++;
33
- }
34
- languageService ??= ts.createLanguageService(host);
35
- return {
36
- languageService,
37
- fileName: currentFileName,
38
- };
39
- }
40
- //# sourceMappingURL=reactivityAnalyzeLS.js.map