@vue/language-service 3.0.7-alpha.1 → 3.1.0-alpha.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 (40) 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/utils.d.ts +3 -0
  9. package/lib/plugins/utils.js +14 -0
  10. package/lib/plugins/vue-autoinsert-dotvalue.d copy.d.ts +2 -0
  11. package/lib/plugins/vue-autoinsert-dotvalue.d copy.js +3 -0
  12. package/lib/plugins/vue-autoinsert-dotvalue.d.ts +1 -1
  13. package/lib/plugins/vue-autoinsert-dotvalue.js +6 -8
  14. package/lib/plugins/vue-compiler-dom-errors.js +3 -4
  15. package/lib/plugins/vue-complete-define-assignment.d.ts +2 -0
  16. package/lib/plugins/vue-complete-define-assignment.js +84 -0
  17. package/lib/plugins/vue-component-semantic-tokens.js +5 -6
  18. package/lib/plugins/vue-destructured-props-hints.d.ts +7 -0
  19. package/lib/plugins/vue-destructured-props-hints.js +220 -0
  20. package/lib/plugins/vue-diagnostic-global-types.d.ts +1 -0
  21. package/lib/plugins/vue-diagnostic-global-types.js +3 -0
  22. package/lib/plugins/vue-document-drop.js +14 -12
  23. package/lib/plugins/vue-document-highlights.js +5 -6
  24. package/lib/plugins/vue-document-links.d.ts +2 -0
  25. package/lib/plugins/vue-document-links.js +109 -0
  26. package/lib/plugins/vue-extract-file.js +11 -13
  27. package/lib/plugins/vue-global-types-error.js +5 -6
  28. package/lib/plugins/vue-inlayhints.js +4 -12
  29. package/lib/plugins/vue-missing-props-hints.js +11 -12
  30. package/lib/plugins/vue-scoped-class-links.js +6 -7
  31. package/lib/plugins/vue-sfc.js +10 -13
  32. package/lib/plugins/vue-suggest-define-assignment.js +4 -5
  33. package/lib/plugins/vue-template-ref-links.js +5 -6
  34. package/lib/plugins/vue-template.js +14 -9
  35. package/lib/plugins/vue-twoslash-queries.js +6 -7
  36. package/lib/types.d.ts +13 -0
  37. package/lib/types.js +34 -0
  38. package/lib/utils.d.ts +5 -5
  39. package/lib/utils.js +7 -31
  40. package/package.json +4 -4
@@ -0,0 +1,220 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.create = create;
4
+ exports.findDestructuredProps = findDestructuredProps;
5
+ const language_core_1 = require("@vue/language-core");
6
+ const vscode_uri_1 = require("vscode-uri");
7
+ function create(ts) {
8
+ return {
9
+ name: 'vue-destructured-props-hints',
10
+ capabilities: {
11
+ inlayHintProvider: {},
12
+ },
13
+ create(context) {
14
+ return {
15
+ async provideInlayHints(document) {
16
+ const enabled = await context.env.getConfiguration?.('vue.inlayHints.destructuredProps') ?? false;
17
+ if (!enabled) {
18
+ return;
19
+ }
20
+ const uri = vscode_uri_1.URI.parse(document.uri);
21
+ const decoded = context.decodeEmbeddedDocumentUri(uri);
22
+ const sourceScript = decoded && context.language.scripts.get(decoded[0]);
23
+ const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
24
+ if (!sourceScript?.generated || virtualCode?.id !== 'main') {
25
+ return;
26
+ }
27
+ const root = sourceScript.generated.root;
28
+ if (!(root instanceof language_core_1.VueVirtualCode)) {
29
+ return;
30
+ }
31
+ const result = [];
32
+ const codegen = language_core_1.tsCodegen.get(root.sfc);
33
+ const scriptSetupRanges = codegen?.getScriptSetupRanges();
34
+ if (!scriptSetupRanges?.defineProps?.destructured || !root.sfc.scriptSetup?.ast) {
35
+ return;
36
+ }
37
+ for (const [prop, isShorthand] of findDestructuredProps(ts, root.sfc.scriptSetup.ast, scriptSetupRanges.defineProps.destructured.keys())) {
38
+ const name = prop.text;
39
+ const end = prop.getEnd();
40
+ const pos = isShorthand ? end : end - name.length;
41
+ const label = isShorthand ? `: props.${name}` : 'props.';
42
+ result.push({
43
+ label,
44
+ position: document.positionAt(root.sfc.scriptSetup.startTagEnd + pos),
45
+ kind: 2,
46
+ });
47
+ }
48
+ return result;
49
+ },
50
+ };
51
+ },
52
+ };
53
+ }
54
+ /**
55
+ * Refactored from https://github.com/vuejs/core/blob/main/packages/compiler-sfc/src/script/definePropsDestructure.ts
56
+ */
57
+ function findDestructuredProps(ts, ast, props) {
58
+ const rootScope = Object.create(null);
59
+ const scopeStack = [rootScope];
60
+ let currentScope = rootScope;
61
+ const excludedIds = new WeakSet();
62
+ const parentStack = [];
63
+ for (const prop of props) {
64
+ rootScope[prop] = true;
65
+ }
66
+ function pushScope() {
67
+ scopeStack.push(currentScope = Object.create(currentScope));
68
+ }
69
+ function popScope() {
70
+ scopeStack.pop();
71
+ currentScope = scopeStack[scopeStack.length - 1] || null;
72
+ }
73
+ function registerLocalBinding(id) {
74
+ excludedIds.add(id);
75
+ if (currentScope) {
76
+ currentScope[id.text] = false;
77
+ }
78
+ }
79
+ const references = [];
80
+ walkScope(ast, true);
81
+ walk(ast);
82
+ return references;
83
+ function walkScope(node, isRoot = false) {
84
+ ts.forEachChild(node, stmt => {
85
+ if (ts.isVariableStatement(stmt)) {
86
+ for (const decl of stmt.declarationList.declarations) {
87
+ walkVariableDeclaration(decl, isRoot);
88
+ }
89
+ }
90
+ else if (ts.isFunctionDeclaration(stmt)
91
+ || ts.isClassDeclaration(stmt)) {
92
+ const declare = ts.getModifiers(stmt)?.find(modifier => modifier.kind === ts.SyntaxKind.DeclareKeyword);
93
+ if (!stmt.name || declare) {
94
+ return;
95
+ }
96
+ registerLocalBinding(stmt.name);
97
+ }
98
+ else if ((ts.isForOfStatement(stmt) || ts.isForInStatement(stmt))
99
+ && ts.isVariableDeclarationList(stmt.initializer)) {
100
+ walkVariableDeclaration(stmt.initializer.declarations[0], isRoot);
101
+ }
102
+ else if (ts.isLabeledStatement(stmt)
103
+ && ts.isVariableDeclaration(stmt.statement)) {
104
+ walkVariableDeclaration(stmt.statement, isRoot);
105
+ }
106
+ });
107
+ }
108
+ function walkVariableDeclaration(decl, isRoot = false) {
109
+ const { initializer, name } = decl;
110
+ const isDefineProps = isRoot
111
+ && initializer
112
+ && ts.isCallExpression(initializer)
113
+ && initializer.expression.getText(ast) === 'defineProps';
114
+ for (const { id } of (0, language_core_1.collectIdentifiers)(ts, name)) {
115
+ if (isDefineProps) {
116
+ excludedIds.add(id);
117
+ }
118
+ else {
119
+ registerLocalBinding(id);
120
+ }
121
+ }
122
+ }
123
+ function walkFunctionDeclaration(node) {
124
+ const { name, parameters } = node;
125
+ if (name && ts.isIdentifier(name)) {
126
+ registerLocalBinding(name);
127
+ }
128
+ for (const p of parameters) {
129
+ for (const { id } of (0, language_core_1.collectIdentifiers)(ts, p)) {
130
+ registerLocalBinding(id);
131
+ }
132
+ }
133
+ }
134
+ function walk(parent) {
135
+ ts.forEachChild(parent, node => {
136
+ if (enter(node) ?? true) {
137
+ walk(node);
138
+ leave(node);
139
+ }
140
+ });
141
+ function enter(node) {
142
+ if (parent) {
143
+ parentStack.push(parent);
144
+ }
145
+ if (ts.isTypeLiteralNode(node)
146
+ || ts.isTypeReferenceNode(node)) {
147
+ return false;
148
+ }
149
+ if (ts.isFunctionLike(node)) {
150
+ pushScope();
151
+ walkFunctionDeclaration(node);
152
+ if ('body' in node) {
153
+ walkScope(node.body);
154
+ }
155
+ return;
156
+ }
157
+ if (ts.isCatchClause(node)) {
158
+ pushScope();
159
+ const { variableDeclaration: p } = node;
160
+ if (p && ts.isIdentifier(p.name)) {
161
+ registerLocalBinding(p.name);
162
+ }
163
+ walkScope(node.block);
164
+ return;
165
+ }
166
+ if (ts.isBlock(node)
167
+ && !ts.isFunctionLike(parent)
168
+ && !ts.isCatchClause(parent)) {
169
+ pushScope();
170
+ walkScope(node);
171
+ return;
172
+ }
173
+ if (ts.isIdentifier(node)
174
+ && isReferencedIdentifier(node, parent)
175
+ && !excludedIds.has(node)) {
176
+ const name = node.text;
177
+ if (currentScope[name]) {
178
+ const isShorthand = ts.isShorthandPropertyAssignment(parent);
179
+ references.push([node, isShorthand]);
180
+ }
181
+ }
182
+ }
183
+ function leave(node) {
184
+ if (parent) {
185
+ parentStack.pop();
186
+ }
187
+ if (ts.isFunctionLike(node)
188
+ || ts.isCatchClause(node)
189
+ || (ts.isBlock(node)
190
+ && !ts.isFunctionLike(parent)
191
+ && !ts.isCatchClause(parent))) {
192
+ popScope();
193
+ }
194
+ }
195
+ }
196
+ // TODO: more conditions
197
+ function isReferencedIdentifier(id, parent) {
198
+ if (!parent) {
199
+ return false;
200
+ }
201
+ if (id.text === 'arguments') {
202
+ return false;
203
+ }
204
+ if (ts.isExpressionWithTypeArguments(parent)
205
+ || ts.isInterfaceDeclaration(parent)
206
+ || ts.isTypeAliasDeclaration(parent)
207
+ || ts.isPropertySignature(parent)) {
208
+ return false;
209
+ }
210
+ if (ts.isPropertyAccessExpression(parent)
211
+ || ts.isPropertyAssignment(parent)
212
+ || ts.isPropertyDeclaration(parent)) {
213
+ if (parent.name === id) {
214
+ return false;
215
+ }
216
+ }
217
+ return true;
218
+ }
219
+ }
220
+ //# sourceMappingURL=vue-destructured-props-hints.js.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=vue-diagnostic-global-types.js.map
@@ -18,48 +18,50 @@ function create(ts, { getImportPathForFile }) {
18
18
  create(context) {
19
19
  return {
20
20
  async provideDocumentDropEdits(document, _position, dataTransfer) {
21
- const info = (0, utils_1.getEmbeddedInfo)(context, document, 'template', 'html');
22
- if (!info) {
21
+ if (document.languageId !== 'html') {
22
+ return;
23
+ }
24
+ const info = (0, utils_1.resolveEmbeddedCode)(context, document.uri);
25
+ if (info?.code.id !== 'template') {
23
26
  return;
24
27
  }
25
- const { sourceScript, root } = info;
26
28
  let importUri;
27
29
  for (const [mimeType, item] of dataTransfer) {
28
30
  if (mimeType === 'text/uri-list') {
29
31
  importUri = item.value;
30
32
  }
31
33
  }
32
- if (!importUri || !root.vueCompilerOptions.extensions.some(ext => importUri.endsWith(ext))) {
34
+ if (!importUri || !info.root.vueCompilerOptions.extensions.some(ext => importUri.endsWith(ext))) {
33
35
  return;
34
36
  }
35
- const { sfc } = root;
37
+ const { sfc } = info.root;
36
38
  const script = sfc.scriptSetup ?? sfc.script;
37
39
  if (!script) {
38
40
  return;
39
41
  }
40
- const casing = await (0, nameCasing_1.checkCasing)(context, sourceScript.id);
42
+ const casing = await (0, nameCasing_1.checkCasing)(context, info.script.id);
41
43
  const baseName = path_browserify_1.posix.basename(importUri);
42
44
  const newName = (0, shared_1.capitalize)((0, shared_1.camelize)(baseName.slice(0, baseName.lastIndexOf('.'))));
43
45
  const additionalEdit = {};
44
- const code = [...(0, language_core_1.forEachEmbeddedCode)(root)].find(code => code.id === (sfc.scriptSetup ? 'scriptsetup_raw' : 'script_raw'));
46
+ const code = [...(0, language_core_1.forEachEmbeddedCode)(info.root)].find(code => code.id === (sfc.scriptSetup ? 'scriptsetup_raw' : 'script_raw'));
45
47
  const lastImportNode = (0, vue_extract_file_1.getLastImportNode)(ts, script.ast);
46
48
  const incomingFileName = vscode_uri_1.URI.parse(importUri).fsPath.replace(/\\/g, '/');
47
49
  let importPath;
48
- const serviceScript = sourceScript.generated.languagePlugin.typescript?.getServiceScript(root);
50
+ const serviceScript = info.script.generated.languagePlugin.typescript?.getServiceScript(info.root);
49
51
  if (serviceScript) {
50
- const tsDocumentUri = context.encodeEmbeddedDocumentUri(sourceScript.id, serviceScript.code.id);
52
+ const tsDocumentUri = context.encodeEmbeddedDocumentUri(info.script.id, serviceScript.code.id);
51
53
  const tsDocument = context.documents.get(tsDocumentUri, serviceScript.code.languageId, serviceScript.code.snapshot);
52
54
  const preferences = await (0, getUserPreferences_1.getUserPreferences)(context, tsDocument);
53
- importPath = (await getImportPathForFile(root.fileName, incomingFileName, preferences) ?? {}).path;
55
+ importPath = await getImportPathForFile(info.root.fileName, incomingFileName, preferences);
54
56
  }
55
57
  if (!importPath) {
56
- importPath = path_browserify_1.posix.relative(path_browserify_1.posix.dirname(root.fileName), incomingFileName)
58
+ importPath = path_browserify_1.posix.relative(path_browserify_1.posix.dirname(info.root.fileName), incomingFileName)
57
59
  || importUri.slice(importUri.lastIndexOf('/') + 1);
58
60
  if (!importPath.startsWith('./') && !importPath.startsWith('../')) {
59
61
  importPath = './' + importPath;
60
62
  }
61
63
  }
62
- const embeddedDocumentUriStr = context.encodeEmbeddedDocumentUri(sourceScript.id, code.id).toString();
64
+ const embeddedDocumentUriStr = context.encodeEmbeddedDocumentUri(info.script.id, code.id).toString();
63
65
  additionalEdit.changes ??= {};
64
66
  additionalEdit.changes[embeddedDocumentUriStr] = [];
65
67
  additionalEdit.changes[embeddedDocumentUriStr].push({
@@ -12,12 +12,11 @@ function create({ getDocumentHighlights }) {
12
12
  create(context) {
13
13
  return {
14
14
  async provideDocumentHighlights(document, position) {
15
- const info = (0, utils_1.getEmbeddedInfo)(context, document, 'main');
16
- if (!info) {
15
+ const info = (0, utils_1.resolveEmbeddedCode)(context, document.uri);
16
+ if (info?.code.id !== 'main') {
17
17
  return;
18
18
  }
19
- const { root } = info;
20
- const { template } = root.sfc;
19
+ const { template } = info.root.sfc;
21
20
  const offset = document.offsetAt(position);
22
21
  if (template?.ast && offset >= template.startTagEnd && offset <= template.endTagStart) {
23
22
  const pos = offset - template.startTagEnd;
@@ -32,9 +31,9 @@ function create({ getDocumentHighlights }) {
32
31
  }
33
32
  }
34
33
  }
35
- const result = await getDocumentHighlights(root.fileName, offset);
34
+ const result = await getDocumentHighlights(info.root.fileName, offset);
36
35
  return result
37
- ?.filter(({ fileName }) => fileName === root.fileName)
36
+ ?.filter(({ fileName }) => fileName === info.root.fileName)
38
37
  .flatMap(({ highlightSpans }) => highlightSpans)
39
38
  .map(({ textSpan, kind }) => ({
40
39
  range: {
@@ -0,0 +1,2 @@
1
+ import type { LanguageServicePlugin } from '@volar/language-service';
2
+ export declare function create(): LanguageServicePlugin;
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.create = create;
4
+ const language_core_1 = require("@vue/language-core");
5
+ const vscode_uri_1 = require("vscode-uri");
6
+ function create() {
7
+ return {
8
+ name: 'vue-document-links',
9
+ capabilities: {
10
+ documentLinkProvider: {},
11
+ },
12
+ create(context) {
13
+ return {
14
+ provideDocumentLinks(document) {
15
+ const uri = vscode_uri_1.URI.parse(document.uri);
16
+ const decoded = context.decodeEmbeddedDocumentUri(uri);
17
+ const sourceScript = decoded && context.language.scripts.get(decoded[0]);
18
+ const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
19
+ if (!sourceScript?.generated || (virtualCode?.id !== 'template' && virtualCode?.id !== 'scriptsetup_raw')) {
20
+ return;
21
+ }
22
+ const root = sourceScript.generated.root;
23
+ if (!(root instanceof language_core_1.VueVirtualCode)) {
24
+ return;
25
+ }
26
+ const { sfc } = root;
27
+ const codegen = language_core_1.tsCodegen.get(sfc);
28
+ const result = [];
29
+ if (virtualCode.id === 'template') {
30
+ const scopedClasses = codegen?.getGeneratedTemplate()?.scopedClasses ?? [];
31
+ const styleClasses = new Map();
32
+ const option = root.vueCompilerOptions.resolveStyleClassNames;
33
+ for (let i = 0; i < sfc.styles.length; i++) {
34
+ const style = sfc.styles[i];
35
+ if (option === true || (option === 'scoped' && style.scoped)) {
36
+ for (const className of style.classNames) {
37
+ if (!styleClasses.has(className.text.slice(1))) {
38
+ styleClasses.set(className.text.slice(1), []);
39
+ }
40
+ styleClasses.get(className.text.slice(1)).push({
41
+ index: i,
42
+ style,
43
+ classOffset: className.offset,
44
+ });
45
+ }
46
+ }
47
+ }
48
+ for (const { className, offset } of scopedClasses) {
49
+ const styles = styleClasses.get(className);
50
+ if (styles) {
51
+ for (const style of styles) {
52
+ const styleDocumentUri = context.encodeEmbeddedDocumentUri(decoded[0], 'style_' + style.index);
53
+ const styleVirtualCode = sourceScript.generated.embeddedCodes.get('style_' + style.index);
54
+ if (!styleVirtualCode) {
55
+ continue;
56
+ }
57
+ const styleDocument = context.documents.get(styleDocumentUri, styleVirtualCode.languageId, styleVirtualCode.snapshot);
58
+ const start = styleDocument.positionAt(style.classOffset);
59
+ const end = styleDocument.positionAt(style.classOffset + className.length + 1);
60
+ result.push({
61
+ range: {
62
+ start: document.positionAt(offset),
63
+ end: document.positionAt(offset + className.length),
64
+ },
65
+ target: context.encodeEmbeddedDocumentUri(decoded[0], 'style_' + style.index)
66
+ + `#L${start.line + 1},${start.character + 1}-L${end.line + 1},${end.character + 1}`,
67
+ });
68
+ }
69
+ }
70
+ }
71
+ }
72
+ else if (virtualCode.id === 'scriptsetup_raw') {
73
+ if (!sfc.scriptSetup) {
74
+ return;
75
+ }
76
+ const templateVirtualCode = sourceScript.generated.embeddedCodes.get('template');
77
+ if (!templateVirtualCode) {
78
+ return;
79
+ }
80
+ const templateDocumentUri = context.encodeEmbeddedDocumentUri(decoded[0], 'template');
81
+ const templateDocument = context.documents.get(templateDocumentUri, templateVirtualCode.languageId, templateVirtualCode.snapshot);
82
+ const templateRefs = codegen?.getGeneratedTemplate()?.templateRefs;
83
+ const useTemplateRefs = codegen?.getScriptSetupRanges()?.useTemplateRef ?? [];
84
+ for (const { arg } of useTemplateRefs) {
85
+ if (!arg) {
86
+ continue;
87
+ }
88
+ const name = sfc.scriptSetup.content.slice(arg.start + 1, arg.end - 1);
89
+ for (const { offset } of templateRefs?.get(name) ?? []) {
90
+ const start = templateDocument.positionAt(offset);
91
+ const end = templateDocument.positionAt(offset + name.length);
92
+ result.push({
93
+ range: {
94
+ start: document.positionAt(arg.start + 1),
95
+ end: document.positionAt(arg.end - 1),
96
+ },
97
+ target: templateDocumentUri
98
+ + `#L${start.line + 1},${start.character + 1}-L${end.line + 1},${end.character + 1}`,
99
+ });
100
+ }
101
+ }
102
+ }
103
+ return result;
104
+ },
105
+ };
106
+ },
107
+ };
108
+ }
109
+ //# sourceMappingURL=vue-document-links.js.map
@@ -27,12 +27,11 @@ function create(ts, { collectExtractProps }) {
27
27
  if (startOffset === endOffset) {
28
28
  return;
29
29
  }
30
- const info = (0, utils_1.getEmbeddedInfo)(context, document, 'template');
31
- if (!info) {
30
+ const info = (0, utils_1.resolveEmbeddedCode)(context, document.uri);
31
+ if (info?.code.id !== 'template') {
32
32
  return;
33
33
  }
34
- const { root } = info;
35
- const { sfc } = root;
34
+ const { sfc } = info.root;
36
35
  const script = sfc.scriptSetup ?? sfc.script;
37
36
  if (!sfc.template || !script) {
38
37
  return;
@@ -56,12 +55,11 @@ function create(ts, { collectExtractProps }) {
56
55
  async resolveCodeAction(codeAction) {
57
56
  const { uri, range, newName } = codeAction.data;
58
57
  const [startOffset, endOffset] = range;
59
- const info = (0, utils_1.getEmbeddedInfo)(context, { uri }, 'template');
60
- if (!info) {
58
+ const info = (0, utils_1.resolveEmbeddedCode)(context, uri);
59
+ if (info?.code.id !== 'template') {
61
60
  return codeAction;
62
61
  }
63
- const { sourceScript, virtualCode, root } = info;
64
- const { sfc } = root;
62
+ const { sfc } = info.root;
65
63
  const script = sfc.scriptSetup ?? sfc.script;
66
64
  if (!sfc.template || !script) {
67
65
  return codeAction;
@@ -70,12 +68,12 @@ function create(ts, { collectExtractProps }) {
70
68
  if (!templateCodeRange) {
71
69
  return codeAction;
72
70
  }
73
- const toExtract = await collectExtractProps(root.fileName, templateCodeRange) ?? [];
71
+ const toExtract = await collectExtractProps(info.root.fileName, templateCodeRange) ?? [];
74
72
  const templateInitialIndent = await context.env.getConfiguration('vue.format.template.initialIndent') ?? true;
75
73
  const scriptInitialIndent = await context.env.getConfiguration('vue.format.script.initialIndent')
76
74
  ?? false;
77
- const document = context.documents.get(vscode_uri_1.URI.parse(uri), virtualCode.languageId, virtualCode.snapshot);
78
- const sfcDocument = context.documents.get(sourceScript.id, sourceScript.languageId, sourceScript.snapshot);
75
+ const document = context.documents.get(vscode_uri_1.URI.parse(uri), info.code.languageId, info.code.snapshot);
76
+ const sfcDocument = context.documents.get(info.script.id, info.script.languageId, info.script.snapshot);
79
77
  const newUri = sfcDocument.uri.slice(0, sfcDocument.uri.lastIndexOf('/') + 1) + `${newName}.vue`;
80
78
  const lastImportNode = getLastImportNode(ts, script.ast);
81
79
  let newFileTags = [];
@@ -136,7 +134,7 @@ function create(ts, { collectExtractProps }) {
136
134
  // editing vue sfc
137
135
  {
138
136
  textDocument: {
139
- uri: sourceScript.id.toString(),
137
+ uri: info.script.id.toString(),
140
138
  version: null,
141
139
  },
142
140
  edits: sfcEdits,
@@ -261,7 +259,7 @@ function createAddComponentToOptionEdit(ts, sfc, ast, componentName) {
261
259
  newText: unescape(printText.replace(unicodeReg, '%u')),
262
260
  };
263
261
  }
264
- else if (exportDefault.args && exportDefault.argsNode) {
262
+ else {
265
263
  const newNode = {
266
264
  ...exportDefault.argsNode,
267
265
  properties: [
@@ -14,16 +14,15 @@ function create() {
14
14
  create(context) {
15
15
  return {
16
16
  provideDiagnostics(document) {
17
- const info = (0, utils_1.getEmbeddedInfo)(context, document, 'root_tags');
18
- if (!info) {
17
+ const info = (0, utils_1.resolveEmbeddedCode)(context, document.uri);
18
+ if (info?.code.id !== 'root_tags') {
19
19
  return;
20
20
  }
21
- const { sourceScript, root } = info;
22
- if (sourceScript.id.scheme !== 'file') {
21
+ if (info.script.id.scheme !== 'file') {
23
22
  return;
24
23
  }
25
- const { vueCompilerOptions } = root;
26
- const globalTypesPath = vueCompilerOptions.globalTypesPath(root.fileName);
24
+ const { vueCompilerOptions } = info.root;
25
+ const globalTypesPath = vueCompilerOptions.globalTypesPath(info.root.fileName);
27
26
  if (globalTypesPath) {
28
27
  return;
29
28
  }
@@ -13,21 +13,20 @@ function create(ts) {
13
13
  create(context) {
14
14
  return {
15
15
  async provideInlayHints(document, range) {
16
- const info = (0, utils_1.getEmbeddedInfo)(context, document, 'main');
17
- if (!info) {
16
+ const info = (0, utils_1.resolveEmbeddedCode)(context, document.uri);
17
+ if (info?.code.id !== 'main') {
18
18
  return;
19
19
  }
20
- const { root } = info;
21
20
  const settings = {};
22
21
  async function getSettingEnabled(key) {
23
22
  return settings[key] ??= await context.env.getConfiguration?.(key) ?? false;
24
23
  }
25
24
  const result = [];
26
- const { sfc } = root;
25
+ const { sfc } = info.root;
27
26
  const codegen = language_core_1.tsCodegen.get(sfc);
28
27
  const inlayHints = [
29
28
  ...codegen?.getGeneratedTemplate()?.inlayHints ?? [],
30
- ...codegen?.getGeneratedScript()?.inlayHints ?? [],
29
+ ...codegen?.getGeneratedScript().inlayHints ?? [],
31
30
  ];
32
31
  const scriptSetupRanges = codegen?.getScriptSetupRanges();
33
32
  if (scriptSetupRanges?.defineProps?.destructured && sfc.scriptSetup?.ast) {
@@ -96,7 +95,6 @@ function findDestructuredProps(ts, ast, props) {
96
95
  const scopeStack = [rootScope];
97
96
  let currentScope = rootScope;
98
97
  const excludedIds = new WeakSet();
99
- const parentStack = [];
100
98
  for (const prop of props) {
101
99
  rootScope[prop] = true;
102
100
  }
@@ -176,9 +174,6 @@ function findDestructuredProps(ts, ast, props) {
176
174
  }
177
175
  });
178
176
  function enter(node) {
179
- if (parent) {
180
- parentStack.push(parent);
181
- }
182
177
  if (ts.isTypeLiteralNode(node)
183
178
  || ts.isTypeReferenceNode(node)) {
184
179
  return false;
@@ -218,9 +213,6 @@ function findDestructuredProps(ts, ast, props) {
218
213
  }
219
214
  }
220
215
  function leave(node) {
221
- if (parent) {
222
- parentStack.pop();
223
- }
224
216
  if (ts.isFunctionLike(node)
225
217
  || ts.isCatchClause(node)
226
218
  || (ts.isBlock(node)
@@ -15,11 +15,10 @@ function create({ getComponentNames, getElementNames, getComponentProps }) {
15
15
  let intrinsicElementNames;
16
16
  return {
17
17
  async provideInlayHints(document, range, cancellationToken) {
18
- const info = (0, utils_1.getEmbeddedInfo)(context, document, 'template');
19
- if (!info) {
18
+ const info = (0, utils_1.resolveEmbeddedCode)(context, document.uri);
19
+ if (info?.code.id !== 'template') {
20
20
  return;
21
21
  }
22
- const { sourceScript, root } = info;
23
22
  const enabled = await context.env.getConfiguration?.('vue.inlayHints.missingProps') ?? false;
24
23
  if (!enabled) {
25
24
  return;
@@ -29,10 +28,10 @@ function create({ getComponentNames, getElementNames, getComponentProps }) {
29
28
  return;
30
29
  }
31
30
  const result = [];
32
- const casing = await (0, nameCasing_1.checkCasing)(context, sourceScript.id);
33
- const components = await getComponentNames(root.fileName) ?? [];
34
- const componentProps = {};
35
- intrinsicElementNames ??= new Set(await getElementNames(root.fileName) ?? []);
31
+ const casing = await (0, nameCasing_1.checkCasing)(context, info.script.id);
32
+ const components = await getComponentNames(info.root.fileName) ?? [];
33
+ const componentProps = new Map();
34
+ intrinsicElementNames ??= new Set(await getElementNames(info.root.fileName) ?? []);
36
35
  let token;
37
36
  let current;
38
37
  while ((token = scanner.scan()) !== html.TokenType.EOS) {
@@ -51,16 +50,16 @@ function create({ getComponentNames, getElementNames, getComponentProps }) {
51
50
  if (tagOffset > document.offsetAt(range.end)) {
52
51
  break;
53
52
  }
54
- if (!componentProps[checkTag]) {
53
+ if (!componentProps.has(checkTag)) {
55
54
  if (cancellationToken.isCancellationRequested) {
56
55
  break;
57
56
  }
58
- componentProps[checkTag] = (await getComponentProps(root.fileName, checkTag) ?? [])
57
+ componentProps.set(checkTag, (await getComponentProps(info.root.fileName, checkTag) ?? [])
59
58
  .filter(prop => prop.required)
60
- .map(prop => prop.name);
59
+ .map(prop => prop.name));
61
60
  }
62
61
  current = {
63
- unburnedRequiredProps: [...componentProps[checkTag]],
62
+ unburnedRequiredProps: [...componentProps.get(checkTag)],
64
63
  labelOffset: scanner.getTokenOffset() + scanner.getTokenLength(),
65
64
  };
66
65
  }
@@ -86,7 +85,7 @@ function create({ getComponentNames, getElementNames, getComponentProps }) {
86
85
  attrText = attrText.slice('v-model:'.length);
87
86
  }
88
87
  else if (attrText === 'v-model') {
89
- attrText = root.vueCompilerOptions.target >= 3 ? 'modelValue' : 'value'; // TODO: support for experimentalModelPropName?
88
+ attrText = 'modelValue'; // TODO: support for experimentalModelPropName?
90
89
  }
91
90
  else if (attrText.startsWith('v-on:')) {
92
91
  attrText = 'on-' + (0, language_core_1.hyphenateAttr)(attrText.slice('v-on:'.length));