@vue/language-service 3.0.7-alpha.0 → 3.0.7

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.
Files changed (38) hide show
  1. package/index.d.ts +2 -1
  2. package/index.js +16 -16
  3. package/lib/nameCasing.d.ts +2 -2
  4. package/lib/plugins/css.js +4 -5
  5. package/lib/plugins/data.d.ts +4 -0
  6. package/lib/plugins/data.js +148 -0
  7. package/lib/plugins/typescript-semantic-tokens.js +3 -4
  8. package/lib/plugins/vue-autoinsert-dotvalue.d copy.d.ts +2 -0
  9. package/lib/plugins/vue-autoinsert-dotvalue.d copy.js +3 -0
  10. package/lib/plugins/vue-autoinsert-dotvalue.d.ts +1 -1
  11. package/lib/plugins/vue-autoinsert-dotvalue.js +6 -8
  12. package/lib/plugins/vue-compiler-dom-errors.js +3 -4
  13. package/lib/plugins/vue-complete-define-assignment.d.ts +2 -0
  14. package/lib/plugins/vue-complete-define-assignment.js +84 -0
  15. package/lib/plugins/vue-component-semantic-tokens.js +5 -6
  16. package/lib/plugins/vue-destructured-props-hints.d.ts +7 -0
  17. package/lib/plugins/vue-destructured-props-hints.js +220 -0
  18. package/lib/plugins/vue-diagnostic-global-types.d.ts +1 -0
  19. package/lib/plugins/vue-diagnostic-global-types.js +3 -0
  20. package/lib/plugins/vue-document-drop.js +14 -12
  21. package/lib/plugins/vue-document-highlights.js +5 -6
  22. package/lib/plugins/vue-document-links.d.ts +2 -0
  23. package/lib/plugins/vue-document-links.js +109 -0
  24. package/lib/plugins/vue-extract-file.js +11 -13
  25. package/lib/plugins/vue-global-types-error.js +5 -6
  26. package/lib/plugins/vue-inlayhints.js +4 -12
  27. package/lib/plugins/vue-missing-props-hints.js +11 -12
  28. package/lib/plugins/vue-scoped-class-links.js +6 -7
  29. package/lib/plugins/vue-sfc.js +10 -13
  30. package/lib/plugins/vue-suggest-define-assignment.js +4 -5
  31. package/lib/plugins/vue-template-ref-links.js +5 -6
  32. package/lib/plugins/vue-template.js +14 -9
  33. package/lib/plugins/vue-twoslash-queries.js +6 -7
  34. package/lib/types.d.ts +13 -0
  35. package/lib/types.js +34 -0
  36. package/lib/utils.d.ts +5 -5
  37. package/lib/utils.js +7 -31
  38. package/package.json +4 -4
@@ -12,14 +12,13 @@ function create() {
12
12
  create(context) {
13
13
  return {
14
14
  provideDocumentLinks(document) {
15
- const info = (0, utils_1.getEmbeddedInfo)(context, document, 'template');
16
- if (!info) {
15
+ const info = (0, utils_1.resolveEmbeddedCode)(context, document.uri);
16
+ if (info?.code.id !== 'template') {
17
17
  return;
18
18
  }
19
- const { sourceScript, root } = info;
20
- const { sfc } = root;
19
+ const { sfc } = info.root;
21
20
  const codegen = language_core_1.tsCodegen.get(sfc);
22
- const option = root.vueCompilerOptions.resolveStyleClassNames;
21
+ const option = info.root.vueCompilerOptions.resolveStyleClassNames;
23
22
  const scopedClasses = codegen?.getGeneratedTemplate()?.scopedClasses ?? [];
24
23
  const styleClasses = new Map();
25
24
  for (let i = 0; i < sfc.styles.length; i++) {
@@ -27,8 +26,8 @@ function create() {
27
26
  if (option !== true && !(option === 'scoped' && style.scoped)) {
28
27
  continue;
29
28
  }
30
- const styleDocumentUri = context.encodeEmbeddedDocumentUri(sourceScript.id, 'style_' + i);
31
- const styleVirtualCode = sourceScript.generated.embeddedCodes.get('style_' + i);
29
+ const styleDocumentUri = context.encodeEmbeddedDocumentUri(info.script.id, 'style_' + i);
30
+ const styleVirtualCode = info.script.generated.embeddedCodes.get('style_' + i);
32
31
  if (!styleVirtualCode) {
33
32
  continue;
34
33
  }
@@ -16,14 +16,13 @@ function create() {
16
16
  return [sfcDataProvider];
17
17
  },
18
18
  async getFormattingOptions(document, options, context) {
19
- const info = (0, utils_1.getEmbeddedInfo)(context, document, 'root_tags');
20
- if (!info) {
19
+ const info = (0, utils_1.resolveEmbeddedCode)(context, document.uri);
20
+ if (info?.code.id !== 'root_tags') {
21
21
  return {};
22
22
  }
23
- const { root } = info;
24
23
  const formatSettings = await context.env.getConfiguration?.('html.format') ?? {};
25
24
  const blockTypes = ['template', 'script', 'style'];
26
- for (const customBlock of root.sfc.customBlocks) {
25
+ for (const customBlock of info.root.sfc.customBlocks) {
27
26
  blockTypes.push(customBlock.type);
28
27
  }
29
28
  return {
@@ -76,12 +75,11 @@ function create() {
76
75
  return options;
77
76
  },
78
77
  async provideDiagnostics(document, token) {
79
- const info = (0, utils_1.getEmbeddedInfo)(context, document, 'root_tags');
80
- if (!info) {
78
+ const info = (0, utils_1.resolveEmbeddedCode)(context, document.uri);
79
+ if (info?.code.id !== 'root_tags') {
81
80
  return [];
82
81
  }
83
- const { root } = info;
84
- const { vueSfc, sfc } = root;
82
+ const { vueSfc, sfc } = info.root;
85
83
  if (!vueSfc) {
86
84
  return;
87
85
  }
@@ -113,13 +111,12 @@ function create() {
113
111
  ];
114
112
  },
115
113
  provideDocumentSymbols(document) {
116
- const info = (0, utils_1.getEmbeddedInfo)(context, document, 'root_tags');
117
- if (!info) {
114
+ const info = (0, utils_1.resolveEmbeddedCode)(context, document.uri);
115
+ if (info?.code.id !== 'root_tags') {
118
116
  return;
119
117
  }
120
- const { root } = info;
121
118
  const result = [];
122
- const { sfc } = root;
119
+ const { sfc } = info.root;
123
120
  if (sfc.template) {
124
121
  result.push({
125
122
  name: 'template',
@@ -185,7 +182,7 @@ function create() {
185
182
  }
186
183
  for (const customBlock of sfc.customBlocks) {
187
184
  result.push({
188
- name: `${customBlock.type}`,
185
+ name: customBlock.type,
189
186
  kind: 2,
190
187
  range: {
191
188
  start: document.positionAt(customBlock.start),
@@ -13,16 +13,15 @@ function create() {
13
13
  return {
14
14
  isAdditionalCompletion: true,
15
15
  async provideCompletionItems(document) {
16
- const info = (0, utils_1.getEmbeddedInfo)(context, document, id => id.startsWith('script_'));
17
- if (!info) {
16
+ const info = (0, utils_1.resolveEmbeddedCode)(context, document.uri);
17
+ if (!info?.code.id.startsWith('script_')) {
18
18
  return;
19
19
  }
20
- const { virtualCode, root } = info;
21
20
  const enabled = await context.env.getConfiguration?.('vue.suggest.defineAssignment') ?? true;
22
21
  if (!enabled) {
23
22
  return;
24
23
  }
25
- const { sfc } = root;
24
+ const { sfc } = info.root;
26
25
  const codegen = language_core_1.tsCodegen.get(sfc);
27
26
  const scriptSetup = sfc.scriptSetup;
28
27
  const scriptSetupRanges = codegen?.getScriptSetupRanges();
@@ -30,7 +29,7 @@ function create() {
30
29
  return;
31
30
  }
32
31
  const result = [];
33
- const mappings = [...context.language.maps.forEach(virtualCode)];
32
+ const mappings = [...context.language.maps.forEach(info.code)];
34
33
  addDefineCompletionItem(scriptSetupRanges.defineProps?.statement, scriptSetupRanges.withDefaults?.exp ?? scriptSetupRanges.defineProps?.exp, 'props');
35
34
  addDefineCompletionItem(scriptSetupRanges.defineEmits?.statement, scriptSetupRanges.defineEmits?.exp, 'emit');
36
35
  addDefineCompletionItem(scriptSetupRanges.defineSlots?.statement, scriptSetupRanges.defineSlots?.exp, 'slots');
@@ -12,21 +12,20 @@ function create() {
12
12
  create(context) {
13
13
  return {
14
14
  provideDocumentLinks(document) {
15
- const info = (0, utils_1.getEmbeddedInfo)(context, document, 'scriptsetup_raw');
16
- if (!info) {
15
+ const info = (0, utils_1.resolveEmbeddedCode)(context, document.uri);
16
+ if (info?.code.id !== 'scriptsetup_raw') {
17
17
  return;
18
18
  }
19
- const { sourceScript, root } = info;
20
- const { sfc } = root;
19
+ const { sfc } = info.root;
21
20
  const codegen = language_core_1.tsCodegen.get(sfc);
22
21
  if (!sfc.scriptSetup) {
23
22
  return;
24
23
  }
25
- const templateVirtualCode = sourceScript.generated.embeddedCodes.get('template');
24
+ const templateVirtualCode = info.script.generated.embeddedCodes.get('template');
26
25
  if (!templateVirtualCode) {
27
26
  return;
28
27
  }
29
- const templateDocumentUri = context.encodeEmbeddedDocumentUri(sourceScript.id, 'template');
28
+ const templateDocumentUri = context.encodeEmbeddedDocumentUri(info.script.id, 'template');
30
29
  const templateDocument = context.documents.get(templateDocumentUri, templateVirtualCode.languageId, templateVirtualCode.snapshot);
31
30
  const templateRefs = codegen?.getGeneratedTemplate()?.templateRefs;
32
31
  const useTemplateRefs = codegen?.getScriptSetupRanges()?.useTemplateRef ?? [];
@@ -128,12 +128,14 @@ function create(languageId, { getComponentNames, getElementAttrs, getComponentPr
128
128
  disposable?.dispose();
129
129
  },
130
130
  async provideCompletionItems(document, position, completionContext, token) {
131
- const info = (0, utils_1.getEmbeddedInfo)(context, document, 'template', languageId);
132
- if (!info) {
131
+ if (document.languageId !== languageId) {
133
132
  return;
134
133
  }
135
- const { sourceScript, root } = info;
136
- const { result: completionList, target, info: { components, propMap, }, } = await runWithVueData(sourceScript.id, root, () => baseServiceInstance.provideCompletionItems(document, position, completionContext, token));
134
+ const info = (0, utils_1.resolveEmbeddedCode)(context, document.uri);
135
+ if (info?.code.id !== 'template') {
136
+ return;
137
+ }
138
+ const { result: completionList, target, info: { components, propMap, }, } = await runWithVueData(info.script.id, info.root, () => baseServiceInstance.provideCompletionItems(document, position, completionContext, token));
137
139
  if (!completionList) {
138
140
  return;
139
141
  }
@@ -248,8 +250,11 @@ function create(languageId, { getComponentNames, getElementAttrs, getComponentPr
248
250
  }
249
251
  },
250
252
  provideHover(document, position, token) {
251
- const info = (0, utils_1.getEmbeddedInfo)(context, document, 'template', languageId);
252
- if (!info) {
253
+ if (document.languageId !== languageId) {
254
+ return;
255
+ }
256
+ const info = (0, utils_1.resolveEmbeddedCode)(context, document.uri);
257
+ if (info?.code.id !== 'template') {
253
258
  return;
254
259
  }
255
260
  if (context.decodeEmbeddedDocumentUri(vscode_uri_1.URI.parse(document.uri))) {
@@ -341,7 +346,7 @@ function create(languageId, { getComponentNames, getElementAttrs, getComponentPr
341
346
  if (casing.tag === nameCasing_1.TagNameCasing.Kebab) {
342
347
  names.add((0, language_core_1.hyphenateTag)(tag));
343
348
  }
344
- else if (casing.tag === nameCasing_1.TagNameCasing.Pascal) {
349
+ else {
345
350
  names.add(tag);
346
351
  }
347
352
  }
@@ -350,7 +355,7 @@ function create(languageId, { getComponentNames, getElementAttrs, getComponentPr
350
355
  if (casing.tag === nameCasing_1.TagNameCasing.Kebab) {
351
356
  names.add((0, language_core_1.hyphenateTag)(name));
352
357
  }
353
- else if (casing.tag === nameCasing_1.TagNameCasing.Pascal) {
358
+ else {
354
359
  names.add(name);
355
360
  }
356
361
  }
@@ -572,7 +577,7 @@ function create(languageId, { getComponentNames, getElementAttrs, getComponentPr
572
577
  for (const customDataPath of customData) {
573
578
  for (const workspaceFolder of context.env.workspaceFolders) {
574
579
  const uri = vscode_uri_1.Utils.resolvePath(workspaceFolder, customDataPath);
575
- const json = await context.env.fs?.readFile?.(uri);
580
+ const json = await context.env.fs?.readFile(uri);
576
581
  if (json) {
577
582
  try {
578
583
  const data = JSON.parse(json);
@@ -13,14 +13,14 @@ function create({ getQuickInfoAtPosition }) {
13
13
  create(context) {
14
14
  return {
15
15
  async provideInlayHints(document, range) {
16
- const info = (0, utils_1.getEmbeddedInfo)(context, document, id => id === 'template' || id.startsWith('script_'));
17
- if (!info) {
16
+ const info = (0, utils_1.resolveEmbeddedCode)(context, document.uri);
17
+ if (info?.code.id !== 'template' && !info?.code.id.startsWith('script_')) {
18
18
  return;
19
19
  }
20
- const { sourceScript, virtualCode, root } = info;
21
20
  const hoverOffsets = [];
22
21
  const inlayHints = [];
23
- const twoslashReg = virtualCode.id === 'template' ? twoslashTemplateReg : twoslashScriptReg;
22
+ const twoslashReg = info.code.id === 'template' ? twoslashTemplateReg : twoslashScriptReg;
23
+ const sourceDocument = context.documents.get(info.script.id, info.script.languageId, info.script.snapshot);
24
24
  for (const pointer of document.getText(range).matchAll(twoslashReg)) {
25
25
  const offset = pointer.index + pointer[0].indexOf('^?') + document.offsetAt(range.start);
26
26
  const position = document.positionAt(offset);
@@ -32,11 +32,10 @@ function create({ getQuickInfoAtPosition }) {
32
32
  }),
33
33
  ]);
34
34
  }
35
- const sourceDocument = context.documents.get(sourceScript.id, sourceScript.languageId, sourceScript.snapshot);
36
35
  for (const [pointerPosition, hoverOffset] of hoverOffsets) {
37
- const map = context.language.maps.get(virtualCode, sourceScript);
36
+ const map = context.language.maps.get(info.code, info.script);
38
37
  for (const [sourceOffset] of map.toSourceLocation(hoverOffset)) {
39
- const quickInfo = await getQuickInfoAtPosition(root.fileName, sourceDocument.positionAt(sourceOffset));
38
+ const quickInfo = await getQuickInfoAtPosition(info.root.fileName, sourceDocument.positionAt(sourceOffset));
40
39
  if (quickInfo) {
41
40
  inlayHints.push({
42
41
  position: { line: pointerPosition.line, character: pointerPosition.character + 2 },
package/lib/types.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ export declare enum TagNameCasing {
2
+ Kebab = 0,
3
+ Pascal = 1,
4
+ }
5
+ export declare enum AttrNameCasing {
6
+ Kebab = 0,
7
+ Camel = 1,
8
+ }
9
+ export declare const commands: {
10
+ parseSfc: string;
11
+ };
12
+ export * from '@volar/language-service/lib/types';
13
+ export * from '@vue/language-core/lib/types';
package/lib/types.js ADDED
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.commands = exports.AttrNameCasing = exports.TagNameCasing = void 0;
18
+ var TagNameCasing;
19
+ (function (TagNameCasing) {
20
+ TagNameCasing[TagNameCasing["Kebab"] = 0] = "Kebab";
21
+ TagNameCasing[TagNameCasing["Pascal"] = 1] = "Pascal";
22
+ })(TagNameCasing || (exports.TagNameCasing = TagNameCasing = {}));
23
+ var AttrNameCasing;
24
+ (function (AttrNameCasing) {
25
+ AttrNameCasing[AttrNameCasing["Kebab"] = 0] = "Kebab";
26
+ AttrNameCasing[AttrNameCasing["Camel"] = 1] = "Camel";
27
+ })(AttrNameCasing || (exports.AttrNameCasing = AttrNameCasing = {}));
28
+ exports.commands = {
29
+ parseSfc: 'vue.parseSfc',
30
+ };
31
+ // only export types of depend packages
32
+ __exportStar(require("@volar/language-service/lib/types"), exports);
33
+ __exportStar(require("@vue/language-core/lib/types"), exports);
34
+ //# sourceMappingURL=types.js.map
package/lib/utils.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { type LanguageServiceContext, type SourceScript, type TextDocument } from '@volar/language-service';
2
- import { VueVirtualCode } from '@vue/language-core';
1
+ import type { LanguageServiceContext, SourceScript } from '@volar/language-service';
2
+ import type { VueVirtualCode } from '@vue/language-core';
3
3
  import { URI } from 'vscode-uri';
4
- export declare function getEmbeddedInfo(context: LanguageServiceContext, document: TextDocument, embeddedCodeId?: string | ((id: string) => boolean), languageId?: string): {
5
- sourceScript: Required<SourceScript<URI>>;
6
- virtualCode: import("@volar/language-service").VirtualCode;
4
+ export declare function resolveEmbeddedCode(context: LanguageServiceContext, uriStr: string): {
5
+ script: Required<SourceScript<URI>>;
6
+ code: import("@volar/language-service").VirtualCode;
7
7
  root: VueVirtualCode;
8
8
  } | undefined;
package/lib/utils.js CHANGED
@@ -1,43 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getEmbeddedInfo = getEmbeddedInfo;
4
- const language_core_1 = require("@vue/language-core");
3
+ exports.resolveEmbeddedCode = resolveEmbeddedCode;
5
4
  const vscode_uri_1 = require("vscode-uri");
6
- function getEmbeddedInfo(context, document, embeddedCodeId, languageId) {
7
- const uri = vscode_uri_1.URI.parse(document.uri);
5
+ function resolveEmbeddedCode(context, uriStr) {
6
+ const uri = vscode_uri_1.URI.parse(uriStr);
8
7
  const decoded = context.decodeEmbeddedDocumentUri(uri);
9
8
  if (!decoded) {
10
9
  return;
11
10
  }
12
- if (embeddedCodeId) {
13
- if (typeof embeddedCodeId === 'string') {
14
- if (decoded[1] !== embeddedCodeId) {
15
- return;
16
- }
17
- }
18
- else if (!embeddedCodeId(decoded[1])) {
19
- return;
20
- }
21
- }
22
- if (languageId && document.languageId !== languageId) {
23
- return;
24
- }
25
11
  const sourceScript = context.language.scripts.get(decoded[0]);
26
- if (!sourceScript?.generated) {
27
- return;
28
- }
29
- const virtualCode = sourceScript.generated.embeddedCodes.get(decoded[1]);
30
- if (!virtualCode) {
31
- return;
32
- }
33
- const root = sourceScript.generated.root;
34
- if (!(root instanceof language_core_1.VueVirtualCode)) {
35
- return;
36
- }
12
+ const code = sourceScript.generated.embeddedCodes.get(decoded[1]);
37
13
  return {
38
- sourceScript: sourceScript,
39
- virtualCode,
40
- root,
14
+ script: sourceScript,
15
+ code,
16
+ root: sourceScript.generated.root,
41
17
  };
42
18
  }
43
19
  //# sourceMappingURL=utils.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-service",
3
- "version": "3.0.7-alpha.0",
3
+ "version": "3.0.7",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "data",
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@volar/language-service": "2.4.23",
21
- "@vue/language-core": "3.0.7-alpha.0",
21
+ "@vue/language-core": "3.0.7",
22
22
  "@vue/shared": "^3.5.0",
23
23
  "path-browserify": "^1.0.1",
24
24
  "volar-service-css": "0.0.65",
@@ -37,8 +37,8 @@
37
37
  "@volar/kit": "2.4.23",
38
38
  "@volar/typescript": "2.4.23",
39
39
  "@vue/compiler-dom": "^3.5.0",
40
- "@vue/typescript-plugin": "3.0.7-alpha.0",
40
+ "@vue/typescript-plugin": "3.0.7",
41
41
  "vscode-css-languageservice": "^6.3.1"
42
42
  },
43
- "gitHead": "a66f2330b5aa6f811f571159245c46af0c36c534"
43
+ "gitHead": "6022b75534487f8a031dfc61a7879f900b64d414"
44
44
  }