@vue/language-service 3.0.2 → 3.0.4

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 (37) hide show
  1. package/index.d.ts +1 -12
  2. package/index.js +14 -15
  3. package/lib/plugins/css.js +9 -17
  4. package/lib/plugins/typescript-semantic-tokens.d.ts +2 -2
  5. package/lib/plugins/typescript-semantic-tokens.js +6 -14
  6. package/lib/plugins/utils.d.ts +8 -2
  7. package/lib/plugins/utils.js +39 -6
  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 +2 -2
  11. package/lib/plugins/vue-autoinsert-dotvalue.js +15 -32
  12. package/lib/plugins/vue-compiler-dom-errors.js +17 -35
  13. package/lib/plugins/vue-component-semantic-tokens.d.ts +2 -2
  14. package/lib/plugins/vue-component-semantic-tokens.js +35 -49
  15. package/lib/plugins/vue-destructured-props-hints.d.ts +7 -0
  16. package/lib/plugins/vue-destructured-props-hints.js +220 -0
  17. package/lib/plugins/vue-document-drop.d.ts +2 -2
  18. package/lib/plugins/vue-document-drop.js +12 -26
  19. package/lib/plugins/vue-document-highlights.d.ts +1 -2
  20. package/lib/plugins/vue-document-highlights.js +6 -13
  21. package/lib/plugins/vue-extract-file.d.ts +2 -2
  22. package/lib/plugins/vue-extract-file.js +10 -25
  23. package/lib/plugins/vue-global-types-error.js +28 -14
  24. package/lib/plugins/vue-inlayhints.js +14 -15
  25. package/lib/plugins/vue-missing-props-hints.d.ts +2 -2
  26. package/lib/plugins/vue-missing-props-hints.js +7 -23
  27. package/lib/plugins/vue-scoped-class-links.d.ts +2 -0
  28. package/lib/plugins/vue-scoped-class-links.js +62 -0
  29. package/lib/plugins/vue-sfc.js +140 -143
  30. package/lib/plugins/vue-suggest-define-assignment.js +3 -13
  31. package/lib/plugins/vue-template-ref-links.d.ts +2 -0
  32. package/lib/plugins/vue-template-ref-links.js +57 -0
  33. package/lib/plugins/vue-template.d.ts +2 -2
  34. package/lib/plugins/vue-template.js +320 -353
  35. package/lib/plugins/vue-twoslash-queries.d.ts +2 -2
  36. package/lib/plugins/vue-twoslash-queries.js +6 -15
  37. package/package.json +7 -7
@@ -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
@@ -1,2 +1,2 @@
1
- import type { LanguageServiceContext, LanguageServicePlugin } from '@volar/language-service';
2
- export declare function create(ts: typeof import('typescript'), getTsPluginClient?: (context: LanguageServiceContext) => import('@vue/typescript-plugin/lib/requests').Requests | undefined): LanguageServicePlugin;
1
+ import type { LanguageServicePlugin } from '@volar/language-service';
2
+ export declare function create(ts: typeof import('typescript'), tsPluginClient: import('@vue/typescript-plugin/lib/requests').Requests | undefined): LanguageServicePlugin;
@@ -8,41 +8,28 @@ const getUserPreferences_1 = require("volar-service-typescript/lib/configs/getUs
8
8
  const vscode_uri_1 = require("vscode-uri");
9
9
  const nameCasing_1 = require("../nameCasing");
10
10
  const vue_extract_file_1 = require("../plugins/vue-extract-file");
11
- function create(ts, getTsPluginClient) {
11
+ const utils_1 = require("./utils");
12
+ function create(ts, tsPluginClient) {
12
13
  return {
13
14
  name: 'vue-document-drop',
14
15
  capabilities: {
15
16
  documentDropEditsProvider: true,
16
17
  },
17
18
  create(context) {
18
- if (!context.project.vue) {
19
- return {};
20
- }
21
- let casing = nameCasing_1.TagNameCasing.Pascal; // TODO
22
- const tsPluginClient = getTsPluginClient?.(context);
23
- const vueCompilerOptions = context.project.vue.compilerOptions;
24
19
  return {
25
20
  async provideDocumentDropEdits(document, _position, dataTransfer) {
26
- if (document.languageId !== 'html') {
27
- return;
28
- }
29
- const uri = vscode_uri_1.URI.parse(document.uri);
30
- const decoded = context.decodeEmbeddedDocumentUri(uri);
31
- const sourceScript = decoded && context.language.scripts.get(decoded[0]);
32
- if (!sourceScript?.generated) {
33
- return;
34
- }
35
- const root = sourceScript.generated.root;
36
- if (!(root instanceof language_core_1.VueVirtualCode)) {
21
+ const info = (0, utils_1.getEmbeddedInfo)(context, document, 'template', 'html');
22
+ if (!info) {
37
23
  return;
38
24
  }
25
+ const { sourceScript, root } = info;
39
26
  let importUri;
40
27
  for (const [mimeType, item] of dataTransfer) {
41
28
  if (mimeType === 'text/uri-list') {
42
29
  importUri = item.value;
43
30
  }
44
31
  }
45
- if (!importUri || !vueCompilerOptions.extensions.some(ext => importUri.endsWith(ext))) {
32
+ if (!importUri || !root.vueCompilerOptions.extensions.some(ext => importUri.endsWith(ext))) {
46
33
  return;
47
34
  }
48
35
  const { sfc } = root;
@@ -50,16 +37,15 @@ function create(ts, getTsPluginClient) {
50
37
  if (!script) {
51
38
  return;
52
39
  }
53
- let baseName = importUri.slice(importUri.lastIndexOf('/') + 1);
54
- baseName = baseName.slice(0, baseName.lastIndexOf('.'));
55
- const newName = (0, shared_1.capitalize)((0, shared_1.camelize)(baseName));
40
+ const casing = await (0, nameCasing_1.checkCasing)(context, sourceScript.id);
41
+ const baseName = path_browserify_1.posix.basename(importUri);
42
+ const newName = (0, shared_1.capitalize)((0, shared_1.camelize)(baseName.slice(0, baseName.lastIndexOf('.'))));
56
43
  const additionalEdit = {};
57
44
  const code = [...(0, language_core_1.forEachEmbeddedCode)(root)].find(code => code.id === (sfc.scriptSetup ? 'scriptsetup_raw' : 'script_raw'));
58
45
  const lastImportNode = (0, vue_extract_file_1.getLastImportNode)(ts, script.ast);
59
- const incomingFileName = context.project.typescript?.uriConverter.asFileName(vscode_uri_1.URI.parse(importUri))
60
- ?? vscode_uri_1.URI.parse(importUri).fsPath.replace(/\\/g, '/');
46
+ const incomingFileName = vscode_uri_1.URI.parse(importUri).fsPath.replace(/\\/g, '/');
61
47
  let importPath;
62
- const serviceScript = sourceScript.generated?.languagePlugin.typescript?.getServiceScript(root);
48
+ const serviceScript = sourceScript.generated.languagePlugin.typescript?.getServiceScript(root);
63
49
  if (tsPluginClient && serviceScript) {
64
50
  const tsDocumentUri = context.encodeEmbeddedDocumentUri(sourceScript.id, serviceScript.code.id);
65
51
  const tsDocument = context.documents.get(tsDocumentUri, serviceScript.code.languageId, serviceScript.code.snapshot);
@@ -105,7 +91,7 @@ function create(ts, getTsPluginClient) {
105
91
  }
106
92
  }
107
93
  return {
108
- insertText: `<${casing === nameCasing_1.TagNameCasing.Kebab ? (0, shared_1.hyphenate)(newName) : newName}$0 />`,
94
+ insertText: `<${casing.tag === nameCasing_1.TagNameCasing.Kebab ? (0, shared_1.hyphenate)(newName) : newName}$0 />`,
109
95
  insertTextFormat: 2,
110
96
  additionalEdit,
111
97
  };
@@ -1,3 +1,2 @@
1
1
  import type { LanguageServicePlugin } from '@volar/language-service';
2
- import type * as ts from 'typescript';
3
- export declare function create(getDocumentHighlights: (fileName: string, position: number) => Promise<ts.DocumentHighlights[] | null>): LanguageServicePlugin;
2
+ export declare function create(tsPluginClient: import('@vue/typescript-plugin/lib/requests').Requests | undefined): LanguageServicePlugin;
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.create = create;
4
- const language_core_1 = require("@vue/language-core");
5
- const vscode_uri_1 = require("vscode-uri");
6
- function create(getDocumentHighlights) {
4
+ const utils_1 = require("./utils");
5
+ function create(tsPluginClient) {
7
6
  return {
8
7
  name: 'vue-document-highlights',
9
8
  capabilities: {
@@ -12,18 +11,12 @@ function create(getDocumentHighlights) {
12
11
  create(context) {
13
12
  return {
14
13
  async provideDocumentHighlights(document, position) {
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 !== 'main') {
14
+ const info = (0, utils_1.getEmbeddedInfo)(context, document, 'main');
15
+ if (!info) {
20
16
  return;
21
17
  }
22
- const root = sourceScript.generated.root;
23
- if (!(root instanceof language_core_1.VueVirtualCode)) {
24
- return;
25
- }
26
- const result = await getDocumentHighlights(root.fileName, document.offsetAt(position));
18
+ const { root } = info;
19
+ const result = await tsPluginClient?.getDocumentHighlights(root.fileName, document.offsetAt(position));
27
20
  return result
28
21
  ?.filter(({ fileName }) => fileName === root.fileName)
29
22
  .flatMap(({ highlightSpans }) => highlightSpans)
@@ -1,7 +1,7 @@
1
- import type { LanguageServiceContext, LanguageServicePlugin } from '@volar/language-service';
1
+ import type { LanguageServicePlugin } from '@volar/language-service';
2
2
  import { type Sfc } from '@vue/language-core';
3
3
  import type * as ts from 'typescript';
4
- export declare function create(ts: typeof import('typescript'), getTsPluginClient?: (context: LanguageServiceContext) => import('@vue/typescript-plugin/lib/requests').Requests | undefined): LanguageServicePlugin;
4
+ export declare function create(ts: typeof import('typescript'), tsPluginClient: import('@vue/typescript-plugin/lib/requests').Requests | undefined): LanguageServicePlugin;
5
5
  export declare function getLastImportNode(ts: typeof import('typescript'), sourceFile: ts.SourceFile): ts.Node | undefined;
6
6
  export declare function createAddComponentToOptionEdit(ts: typeof import('typescript'), sfc: Sfc, ast: ts.SourceFile, componentName: string): {
7
7
  range: import("@vue/language-core").TextRange;
@@ -5,8 +5,9 @@ exports.getLastImportNode = getLastImportNode;
5
5
  exports.createAddComponentToOptionEdit = createAddComponentToOptionEdit;
6
6
  const language_core_1 = require("@vue/language-core");
7
7
  const vscode_uri_1 = require("vscode-uri");
8
+ const utils_1 = require("./utils");
8
9
  const unicodeReg = /\\u/g;
9
- function create(ts, getTsPluginClient) {
10
+ function create(ts, tsPluginClient) {
10
11
  return {
11
12
  name: 'vue-extract-file',
12
13
  capabilities: {
@@ -16,7 +17,6 @@ function create(ts, getTsPluginClient) {
16
17
  },
17
18
  },
18
19
  create(context) {
19
- const tsPluginClient = getTsPluginClient?.(context);
20
20
  return {
21
21
  provideCodeActions(document, range, ctx) {
22
22
  if (ctx.only && !ctx.only.includes('refactor')) {
@@ -27,17 +27,11 @@ function create(ts, getTsPluginClient) {
27
27
  if (startOffset === endOffset) {
28
28
  return;
29
29
  }
30
- const uri = vscode_uri_1.URI.parse(document.uri);
31
- const decoded = context.decodeEmbeddedDocumentUri(uri);
32
- const sourceScript = decoded && context.language.scripts.get(decoded[0]);
33
- const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
34
- if (!sourceScript?.generated || virtualCode?.id !== 'template') {
35
- return;
36
- }
37
- const root = sourceScript.generated.root;
38
- if (!(root instanceof language_core_1.VueVirtualCode)) {
30
+ const info = (0, utils_1.getEmbeddedInfo)(context, document, 'template');
31
+ if (!info) {
39
32
  return;
40
33
  }
34
+ const { root } = info;
41
35
  const { sfc } = root;
42
36
  const script = sfc.scriptSetup ?? sfc.script;
43
37
  if (!sfc.template || !script) {
@@ -62,17 +56,11 @@ function create(ts, getTsPluginClient) {
62
56
  async resolveCodeAction(codeAction) {
63
57
  const { uri, range, newName } = codeAction.data;
64
58
  const [startOffset, endOffset] = range;
65
- const parsedUri = vscode_uri_1.URI.parse(uri);
66
- const decoded = context.decodeEmbeddedDocumentUri(parsedUri);
67
- const sourceScript = decoded && context.language.scripts.get(decoded[0]);
68
- const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
69
- if (!sourceScript?.generated || virtualCode?.id !== 'template') {
70
- return codeAction;
71
- }
72
- const root = sourceScript.generated.root;
73
- if (!(root instanceof language_core_1.VueVirtualCode)) {
59
+ const info = (0, utils_1.getEmbeddedInfo)(context, { uri }, 'template');
60
+ if (!info) {
74
61
  return codeAction;
75
62
  }
63
+ const { sourceScript, virtualCode, root } = info;
76
64
  const { sfc } = root;
77
65
  const script = sfc.scriptSetup ?? sfc.script;
78
66
  if (!sfc.template || !script) {
@@ -83,13 +71,10 @@ function create(ts, getTsPluginClient) {
83
71
  return codeAction;
84
72
  }
85
73
  const toExtract = await tsPluginClient?.collectExtractProps(root.fileName, templateCodeRange) ?? [];
86
- if (!toExtract) {
87
- return codeAction;
88
- }
89
74
  const templateInitialIndent = await context.env.getConfiguration('vue.format.template.initialIndent') ?? true;
90
75
  const scriptInitialIndent = await context.env.getConfiguration('vue.format.script.initialIndent')
91
76
  ?? false;
92
- const document = context.documents.get(parsedUri, virtualCode.languageId, virtualCode.snapshot);
77
+ const document = context.documents.get(vscode_uri_1.URI.parse(uri), virtualCode.languageId, virtualCode.snapshot);
93
78
  const sfcDocument = context.documents.get(sourceScript.id, sourceScript.languageId, sourceScript.snapshot);
94
79
  const newUri = sfcDocument.uri.slice(0, sfcDocument.uri.lastIndexOf('/') + 1) + `${newName}.vue`;
95
80
  const lastImportNode = getLastImportNode(ts, script.ast);
@@ -184,7 +169,7 @@ function create(ts, getTsPluginClient) {
184
169
  const props = toExtract.filter(p => !p.model);
185
170
  const models = toExtract.filter(p => p.model);
186
171
  if (props.length) {
187
- lines.push(`defineProps<{ \n\t${props.map(p => `${p.name}: ${p.type};`).join('\n\t')}\n}>()`);
172
+ lines.push(`defineProps<{\n\t${props.map(p => `${p.name}: ${p.type};`).join('\n\t')}\n}>()`);
188
173
  }
189
174
  for (const model of models) {
190
175
  lines.push(`const ${model.name} = defineModel<${model.type}>('${model.name}', { required: true })`);
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.create = create;
4
+ const utils_1 = require("./utils");
4
5
  function create() {
5
6
  return {
6
- name: 'vue-compiler-dom-errors',
7
+ name: 'vue-global-types-error',
7
8
  capabilities: {
8
9
  diagnosticProvider: {
9
10
  interFileDependencies: false,
@@ -13,22 +14,35 @@ function create() {
13
14
  create(context) {
14
15
  return {
15
16
  provideDiagnostics(document) {
16
- if (document.languageId !== 'vue-root-tags') {
17
+ const info = (0, utils_1.getEmbeddedInfo)(context, document, 'root_tags');
18
+ if (!info) {
17
19
  return;
18
20
  }
19
- const vueCompilerOptions = context.project.vue?.compilerOptions;
20
- if (vueCompilerOptions && vueCompilerOptions.globalTypesPath === undefined) {
21
- return [{
22
- range: {
23
- start: document.positionAt(0),
24
- end: document.positionAt(0),
25
- },
26
- severity: 1,
27
- code: 404,
28
- source: 'vue',
29
- message: `Write global types file failed. Please ensure that "node_modules" exists and "${vueCompilerOptions.lib}" is a direct dependency, or set "vueCompilerOptions.globalTypesPath" in "tsconfig.json" manually.`,
30
- }];
21
+ const { root } = info;
22
+ const { vueCompilerOptions } = root;
23
+ const globalTypesPath = vueCompilerOptions.globalTypesPath(root.fileName);
24
+ if (globalTypesPath) {
25
+ return;
31
26
  }
27
+ return [{
28
+ range: {
29
+ start: document.positionAt(0),
30
+ end: document.positionAt(0),
31
+ },
32
+ severity: 2,
33
+ code: 404,
34
+ source: 'vue',
35
+ message: `
36
+ Failed to write the global types file. Make sure that:
37
+
38
+ 1. "node_modules" directory exists.
39
+ 2. "${vueCompilerOptions.lib}" is installed as a direct dependency.
40
+
41
+ Alternatively, you can manually set "vueCompilerOptions.globalTypesPath" in your "tsconfig.json".
42
+
43
+ If all dependencies are installed, try running the "vue.action.restartServer" command to restart Vue and TS servers.
44
+ `.trim(),
45
+ }];
32
46
  },
33
47
  };
34
48
  },
@@ -3,39 +3,38 @@ 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 vscode_uri_1 = require("vscode-uri");
6
+ const utils_1 = require("./utils");
7
7
  function create(ts) {
8
8
  return {
9
- name: 'vue-inlay-hints',
9
+ name: 'vue-inlayhints',
10
10
  capabilities: {
11
11
  inlayHintProvider: {},
12
12
  },
13
13
  create(context) {
14
14
  return {
15
15
  async provideInlayHints(document, range) {
16
- const uri = vscode_uri_1.URI.parse(document.uri);
17
- const decoded = context.decodeEmbeddedDocumentUri(uri);
18
- const sourceScript = decoded && context.language.scripts.get(decoded[0]);
19
- const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
20
- if (!(virtualCode instanceof language_core_1.VueVirtualCode)) {
16
+ const info = (0, utils_1.getEmbeddedInfo)(context, document, 'main');
17
+ if (!info) {
21
18
  return;
22
19
  }
20
+ const { root } = info;
23
21
  const settings = {};
24
22
  async function getSettingEnabled(key) {
25
23
  return settings[key] ??= await context.env.getConfiguration?.(key) ?? false;
26
24
  }
27
25
  const result = [];
28
- const codegen = language_core_1.tsCodegen.get(virtualCode.sfc);
26
+ const { sfc } = root;
27
+ const codegen = language_core_1.tsCodegen.get(sfc);
29
28
  const inlayHints = [
30
29
  ...codegen?.getGeneratedTemplate()?.inlayHints ?? [],
31
30
  ...codegen?.getGeneratedScript()?.inlayHints ?? [],
32
31
  ];
33
32
  const scriptSetupRanges = codegen?.getScriptSetupRanges();
34
- if (scriptSetupRanges?.defineProps?.destructured && virtualCode.sfc.scriptSetup?.ast) {
33
+ if (scriptSetupRanges?.defineProps?.destructured && sfc.scriptSetup?.ast) {
35
34
  const setting = 'vue.inlayHints.destructuredProps';
36
35
  const enabled = await getSettingEnabled(setting);
37
36
  if (enabled) {
38
- for (const [prop, isShorthand] of findDestructuredProps(ts, virtualCode.sfc.scriptSetup.ast, scriptSetupRanges.defineProps.destructured.keys())) {
37
+ for (const [prop, isShorthand] of findDestructuredProps(ts, sfc.scriptSetup.ast, scriptSetupRanges.defineProps.destructured.keys())) {
39
38
  const name = prop.text;
40
39
  const end = prop.getEnd();
41
40
  const pos = isShorthand ? end : end - name.length;
@@ -50,9 +49,9 @@ function create(ts) {
50
49
  }
51
50
  }
52
51
  const blocks = [
53
- virtualCode.sfc.template,
54
- virtualCode.sfc.script,
55
- virtualCode.sfc.scriptSetup,
52
+ sfc.template,
53
+ sfc.script,
54
+ sfc.scriptSetup,
56
55
  ];
57
56
  const start = document.offsetAt(range.start);
58
57
  const end = document.offsetAt(range.end);
@@ -149,7 +148,7 @@ function findDestructuredProps(ts, ast, props) {
149
148
  && initializer
150
149
  && ts.isCallExpression(initializer)
151
150
  && initializer.expression.getText(ast) === 'defineProps';
152
- for (const { id } of (0, language_core_1.collectIdentifiers)(ts, name)) {
151
+ for (const { id } of (0, language_core_1.collectBindingIdentifiers)(ts, name)) {
153
152
  if (isDefineProps) {
154
153
  excludedIds.add(id);
155
154
  }
@@ -164,7 +163,7 @@ function findDestructuredProps(ts, ast, props) {
164
163
  registerLocalBinding(name);
165
164
  }
166
165
  for (const p of parameters) {
167
- for (const { id } of (0, language_core_1.collectIdentifiers)(ts, p)) {
166
+ for (const { id } of (0, language_core_1.collectBindingIdentifiers)(ts, p)) {
168
167
  registerLocalBinding(id);
169
168
  }
170
169
  }
@@ -1,2 +1,2 @@
1
- import type { LanguageServiceContext, LanguageServicePlugin } from '@volar/language-service';
2
- export declare function create(getTsPluginClient?: (context: LanguageServiceContext) => import('@vue/typescript-plugin/lib/requests').Requests | undefined): LanguageServicePlugin;
1
+ import type { LanguageServicePlugin } from '@volar/language-service';
2
+ export declare function create(tsPluginClient: import('@vue/typescript-plugin/lib/requests').Requests | undefined): LanguageServicePlugin;