@vue/language-service 2.1.10 → 2.2.0

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 (49) hide show
  1. package/data/language-blocks/cs.json +29 -930
  2. package/data/language-blocks/en.json +28 -929
  3. package/data/language-blocks/fr.json +28 -929
  4. package/data/language-blocks/it.json +28 -929
  5. package/data/language-blocks/ja.json +28 -929
  6. package/data/language-blocks/ko.json +28 -929
  7. package/data/language-blocks/pt.json +28 -929
  8. package/data/language-blocks/ru.json +28 -929
  9. package/data/language-blocks/zh-cn.json +30 -931
  10. package/data/language-blocks/zh-hk.json +28 -929
  11. package/data/locale.json +54 -0
  12. package/data/model-modifiers/cs.json +6 -165
  13. package/data/model-modifiers/en.json +6 -165
  14. package/data/model-modifiers/fr.json +6 -165
  15. package/data/model-modifiers/it.json +6 -165
  16. package/data/model-modifiers/ja.json +6 -165
  17. package/data/model-modifiers/ko.json +6 -165
  18. package/data/model-modifiers/pt.json +6 -165
  19. package/data/model-modifiers/ru.json +6 -165
  20. package/data/model-modifiers/zh-cn.json +6 -165
  21. package/data/model-modifiers/zh-hk.json +6 -165
  22. package/data/template/cs.json +59 -1429
  23. package/data/template/en.json +52 -1422
  24. package/data/template/fr.json +55 -1425
  25. package/data/template/it.json +44 -1422
  26. package/data/template/ja.json +53 -1423
  27. package/data/template/ko.json +44 -1422
  28. package/data/template/pt.json +44 -1422
  29. package/data/template/ru.json +52 -1422
  30. package/data/template/zh-cn.json +53 -1423
  31. package/data/template/zh-hk.json +44 -1422
  32. package/index.d.ts +2 -2
  33. package/index.js +2 -2
  34. package/lib/ideFeatures/nameCasing.js +14 -16
  35. package/lib/plugins/data.js +47 -20
  36. package/lib/plugins/vue-autoinsert-dotvalue.js +4 -3
  37. package/lib/plugins/vue-autoinsert-space.js +1 -1
  38. package/lib/plugins/vue-complete-define-assignment.js +11 -13
  39. package/lib/plugins/vue-directive-comments.js +10 -8
  40. package/lib/plugins/vue-document-drop.js +15 -12
  41. package/lib/plugins/vue-document-links.js +45 -39
  42. package/lib/plugins/vue-extract-file.js +19 -10
  43. package/lib/plugins/vue-inlayhints.d.ts +1 -1
  44. package/lib/plugins/vue-inlayhints.js +65 -56
  45. package/lib/plugins/vue-sfc.js +29 -27
  46. package/lib/plugins/vue-template.js +194 -162
  47. package/lib/plugins/vue-twoslash-queries.js +9 -4
  48. package/package.json +10 -9
  49. package/scripts/update-html-data.js +74 -70
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.create = create;
4
4
  exports.findDestructuredProps = findDestructuredProps;
5
5
  const language_core_1 = require("@vue/language-core");
6
+ const index_1 = require("@vue/language-core/lib/codegen/utils/index");
6
7
  const vscode_uri_1 = require("vscode-uri");
7
- const common_1 = require("@vue/language-core/lib/codegen/common");
8
8
  function create(ts) {
9
9
  return {
10
10
  name: 'vue-inlay-hints',
@@ -14,65 +14,74 @@ function create(ts) {
14
14
  create(context) {
15
15
  return {
16
16
  async provideInlayHints(document, range) {
17
- const settings = {};
18
- const result = [];
19
- const decoded = context.decodeEmbeddedDocumentUri(vscode_uri_1.URI.parse(document.uri));
17
+ const uri = vscode_uri_1.URI.parse(document.uri);
18
+ const decoded = context.decodeEmbeddedDocumentUri(uri);
20
19
  const sourceScript = decoded && context.language.scripts.get(decoded[0]);
21
20
  const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
22
- if (virtualCode instanceof language_core_1.VueVirtualCode) {
23
- const codegen = language_core_1.tsCodegen.get(virtualCode._sfc);
24
- const inlayHints = [
25
- ...codegen?.generatedTemplate.get()?.inlayHints ?? [],
26
- ...codegen?.generatedScript.get()?.inlayHints ?? [],
27
- ];
28
- const scriptSetupRanges = codegen?.scriptSetupRanges.get();
29
- if (scriptSetupRanges?.props.destructured && virtualCode._sfc.scriptSetup?.ast) {
30
- const setting = 'vue.inlayHints.destructuredProps';
31
- settings[setting] ??= await context.env.getConfiguration?.(setting) ?? false;
32
- if (settings[setting]) {
33
- for (const [prop, isShorthand] of findDestructuredProps(ts, virtualCode._sfc.scriptSetup.ast, scriptSetupRanges.props.destructured)) {
34
- const name = prop.text;
35
- const end = prop.getEnd();
36
- const pos = isShorthand ? end : end - name.length;
37
- const label = isShorthand ? `: props.${name}` : 'props.';
38
- inlayHints.push({
39
- blockName: 'scriptSetup',
40
- offset: pos,
41
- setting,
42
- label,
43
- });
44
- }
45
- }
46
- }
47
- const blocks = [
48
- virtualCode._sfc.template,
49
- virtualCode._sfc.script,
50
- virtualCode._sfc.scriptSetup,
51
- ];
52
- const start = document.offsetAt(range.start);
53
- const end = document.offsetAt(range.end);
54
- for (const hint of inlayHints) {
55
- const block = blocks.find(block => block?.name === hint.blockName);
56
- const hintOffset = (block?.startTagEnd ?? 0) + hint.offset;
57
- if (hintOffset >= start && hintOffset <= end) {
58
- settings[hint.setting] ??= await context.env.getConfiguration?.(hint.setting) ?? false;
59
- if (!settings[hint.setting]) {
60
- continue;
61
- }
62
- result.push({
63
- label: hint.label,
64
- paddingRight: hint.paddingRight,
65
- paddingLeft: hint.paddingLeft,
66
- position: document.positionAt(hintOffset),
67
- kind: 2,
68
- tooltip: hint.tooltip ? {
69
- kind: 'markdown',
70
- value: hint.tooltip,
71
- } : undefined,
21
+ if (!(virtualCode instanceof language_core_1.VueVirtualCode)) {
22
+ return;
23
+ }
24
+ const settings = {};
25
+ async function getSettingEnabled(key) {
26
+ return settings[key] ??= await context.env.getConfiguration?.(key) ?? false;
27
+ }
28
+ const result = [];
29
+ const codegen = language_core_1.tsCodegen.get(virtualCode._sfc);
30
+ const inlayHints = [
31
+ ...codegen?.generatedTemplate.get()?.inlayHints ?? [],
32
+ ...codegen?.generatedScript.get()?.inlayHints ?? [],
33
+ ];
34
+ const scriptSetupRanges = codegen?.scriptSetupRanges.get();
35
+ if (scriptSetupRanges?.defineProps?.destructured && virtualCode._sfc.scriptSetup?.ast) {
36
+ const setting = 'vue.inlayHints.destructuredProps';
37
+ const enabled = await getSettingEnabled(setting);
38
+ if (enabled) {
39
+ for (const [prop, isShorthand] of findDestructuredProps(ts, virtualCode._sfc.scriptSetup.ast, scriptSetupRanges.defineProps.destructured)) {
40
+ const name = prop.text;
41
+ const end = prop.getEnd();
42
+ const pos = isShorthand ? end : end - name.length;
43
+ const label = isShorthand ? `: props.${name}` : 'props.';
44
+ inlayHints.push({
45
+ blockName: 'scriptSetup',
46
+ offset: pos,
47
+ setting,
48
+ label,
72
49
  });
73
50
  }
74
51
  }
75
52
  }
53
+ const blocks = [
54
+ virtualCode._sfc.template,
55
+ virtualCode._sfc.script,
56
+ virtualCode._sfc.scriptSetup,
57
+ ];
58
+ const start = document.offsetAt(range.start);
59
+ const end = document.offsetAt(range.end);
60
+ for (const hint of inlayHints) {
61
+ const block = blocks.find(block => block?.name === hint.blockName);
62
+ if (!block) {
63
+ continue;
64
+ }
65
+ const hintOffset = block.startTagEnd + hint.offset;
66
+ if (hintOffset < start || hintOffset >= end) {
67
+ continue;
68
+ }
69
+ const enabled = await getSettingEnabled(hint.setting);
70
+ if (!enabled) {
71
+ continue;
72
+ }
73
+ result.push({
74
+ label: hint.label,
75
+ paddingRight: hint.paddingRight,
76
+ paddingLeft: hint.paddingLeft,
77
+ position: document.positionAt(hintOffset),
78
+ kind: 2,
79
+ tooltip: hint.tooltip ? {
80
+ kind: 'markdown',
81
+ value: hint.tooltip,
82
+ } : undefined,
83
+ });
84
+ }
76
85
  return result;
77
86
  },
78
87
  };
@@ -139,7 +148,7 @@ function findDestructuredProps(ts, ast, props) {
139
148
  && initializer
140
149
  && ts.isCallExpression(initializer)
141
150
  && initializer.expression.getText(ast) === 'defineProps';
142
- for (const [id] of (0, common_1.collectIdentifiers)(ts, name)) {
151
+ for (const [id] of (0, index_1.collectIdentifiers)(ts, name)) {
143
152
  if (isDefineProps) {
144
153
  excludedIds.add(id);
145
154
  }
@@ -154,7 +163,7 @@ function findDestructuredProps(ts, ast, props) {
154
163
  registerLocalBinding(name);
155
164
  }
156
165
  for (const p of parameters) {
157
- for (const [id] of (0, common_1.collectIdentifiers)(ts, p)) {
166
+ for (const [id] of (0, index_1.collectIdentifiers)(ts, p)) {
158
167
  registerLocalBinding(id);
159
168
  }
160
169
  }
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.create = create;
4
- const vue = require("@vue/language-core");
4
+ const language_core_1 = require("@vue/language-core");
5
5
  const volar_service_html_1 = require("volar-service-html");
6
6
  const html = require("vscode-html-languageservice");
7
- const data_1 = require("./data");
8
7
  const vscode_uri_1 = require("vscode-uri");
8
+ const data_1 = require("./data");
9
9
  let sfcDataProvider;
10
10
  function create() {
11
11
  const htmlPlugin = (0, volar_service_html_1.create)({
@@ -16,10 +16,10 @@ function create() {
16
16
  return [sfcDataProvider];
17
17
  },
18
18
  async getFormattingOptions(document, options, context) {
19
- return await worker(document, context, async (vueCode) => {
19
+ return await worker(document, context, async (root) => {
20
20
  const formatSettings = await context.env.getConfiguration?.('html.format') ?? {};
21
21
  const blockTypes = ['template', 'script', 'style'];
22
- for (const customBlock of vueCode._sfc.customBlocks) {
22
+ for (const customBlock of root._sfc.customBlocks) {
23
23
  blockTypes.push(customBlock.type);
24
24
  }
25
25
  return {
@@ -44,7 +44,7 @@ function create() {
44
44
  ...htmlPluginInstance,
45
45
  provideDocumentLinks: undefined,
46
46
  async resolveEmbeddedCodeFormattingOptions(sourceScript, virtualCode, options) {
47
- if (sourceScript.generated?.root instanceof vue.VueVirtualCode) {
47
+ if (sourceScript.generated?.root instanceof language_core_1.VueVirtualCode) {
48
48
  if (virtualCode.id === 'script_raw' || virtualCode.id === 'scriptsetup_raw') {
49
49
  if (await context.env.getConfiguration?.('vue.format.script.initialIndent') ?? false) {
50
50
  options.initialIndentLevel++;
@@ -64,52 +64,52 @@ function create() {
64
64
  return options;
65
65
  },
66
66
  provideDocumentSymbols(document) {
67
- return worker(document, context, vueSourceFile => {
67
+ return worker(document, context, root => {
68
68
  const result = [];
69
- const descriptor = vueSourceFile._sfc;
70
- if (descriptor.template) {
69
+ const sfc = root._sfc;
70
+ if (sfc.template) {
71
71
  result.push({
72
72
  name: 'template',
73
73
  kind: 2,
74
74
  range: {
75
- start: document.positionAt(descriptor.template.start),
76
- end: document.positionAt(descriptor.template.end),
75
+ start: document.positionAt(sfc.template.start),
76
+ end: document.positionAt(sfc.template.end),
77
77
  },
78
78
  selectionRange: {
79
- start: document.positionAt(descriptor.template.start),
80
- end: document.positionAt(descriptor.template.startTagEnd),
79
+ start: document.positionAt(sfc.template.start),
80
+ end: document.positionAt(sfc.template.startTagEnd),
81
81
  },
82
82
  });
83
83
  }
84
- if (descriptor.script) {
84
+ if (sfc.script) {
85
85
  result.push({
86
86
  name: 'script',
87
87
  kind: 2,
88
88
  range: {
89
- start: document.positionAt(descriptor.script.start),
90
- end: document.positionAt(descriptor.script.end),
89
+ start: document.positionAt(sfc.script.start),
90
+ end: document.positionAt(sfc.script.end),
91
91
  },
92
92
  selectionRange: {
93
- start: document.positionAt(descriptor.script.start),
94
- end: document.positionAt(descriptor.script.startTagEnd),
93
+ start: document.positionAt(sfc.script.start),
94
+ end: document.positionAt(sfc.script.startTagEnd),
95
95
  },
96
96
  });
97
97
  }
98
- if (descriptor.scriptSetup) {
98
+ if (sfc.scriptSetup) {
99
99
  result.push({
100
100
  name: 'script setup',
101
101
  kind: 2,
102
102
  range: {
103
- start: document.positionAt(descriptor.scriptSetup.start),
104
- end: document.positionAt(descriptor.scriptSetup.end),
103
+ start: document.positionAt(sfc.scriptSetup.start),
104
+ end: document.positionAt(sfc.scriptSetup.end),
105
105
  },
106
106
  selectionRange: {
107
- start: document.positionAt(descriptor.scriptSetup.start),
108
- end: document.positionAt(descriptor.scriptSetup.startTagEnd),
107
+ start: document.positionAt(sfc.scriptSetup.start),
108
+ end: document.positionAt(sfc.scriptSetup.startTagEnd),
109
109
  },
110
110
  });
111
111
  }
112
- for (const style of descriptor.styles) {
112
+ for (const style of sfc.styles) {
113
113
  let name = 'style';
114
114
  if (style.scoped) {
115
115
  name += ' scoped';
@@ -130,7 +130,7 @@ function create() {
130
130
  },
131
131
  });
132
132
  }
133
- for (const customBlock of descriptor.customBlocks) {
133
+ for (const customBlock of sfc.customBlocks) {
134
134
  result.push({
135
135
  name: `${customBlock.type}`,
136
136
  kind: 2,
@@ -217,10 +217,12 @@ function create() {
217
217
  if (document.languageId !== 'vue-root-tags') {
218
218
  return;
219
219
  }
220
- const decoded = context.decodeEmbeddedDocumentUri(vscode_uri_1.URI.parse(document.uri));
220
+ const uri = vscode_uri_1.URI.parse(document.uri);
221
+ const decoded = context.decodeEmbeddedDocumentUri(uri);
221
222
  const sourceScript = decoded && context.language.scripts.get(decoded[0]);
222
- if (sourceScript?.generated?.root instanceof vue.VueVirtualCode) {
223
- return callback(sourceScript.generated.root);
223
+ const root = sourceScript?.generated?.root;
224
+ if (root instanceof language_core_1.VueVirtualCode) {
225
+ return callback(root);
224
226
  }
225
227
  }
226
228
  }