@vue/language-service 2.1.8 → 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.
- package/data/language-blocks/cs.json +29 -930
- package/data/language-blocks/en.json +28 -929
- package/data/language-blocks/fr.json +28 -929
- package/data/language-blocks/it.json +28 -929
- package/data/language-blocks/ja.json +28 -929
- package/data/language-blocks/ko.json +28 -929
- package/data/language-blocks/pt.json +28 -929
- package/data/language-blocks/ru.json +28 -929
- package/data/language-blocks/zh-cn.json +30 -931
- package/data/language-blocks/zh-hk.json +28 -929
- package/data/locale.json +54 -0
- package/data/model-modifiers/cs.json +6 -165
- package/data/model-modifiers/en.json +6 -165
- package/data/model-modifiers/fr.json +6 -165
- package/data/model-modifiers/it.json +6 -165
- package/data/model-modifiers/ja.json +6 -165
- package/data/model-modifiers/ko.json +6 -165
- package/data/model-modifiers/pt.json +6 -165
- package/data/model-modifiers/ru.json +6 -165
- package/data/model-modifiers/zh-cn.json +6 -165
- package/data/model-modifiers/zh-hk.json +6 -165
- package/data/template/cs.json +59 -1429
- package/data/template/en.json +52 -1422
- package/data/template/fr.json +55 -1425
- package/data/template/it.json +44 -1422
- package/data/template/ja.json +53 -1423
- package/data/template/ko.json +44 -1422
- package/data/template/pt.json +44 -1422
- package/data/template/ru.json +52 -1422
- package/data/template/zh-cn.json +53 -1423
- package/data/template/zh-hk.json +44 -1422
- package/index.d.ts +2 -2
- package/index.js +3 -1
- package/lib/ideFeatures/nameCasing.js +14 -16
- package/lib/plugins/data.js +47 -20
- package/lib/plugins/vue-autoinsert-dotvalue.d.ts +1 -0
- package/lib/plugins/vue-autoinsert-dotvalue.js +5 -3
- package/lib/plugins/vue-autoinsert-space.js +1 -1
- package/lib/plugins/vue-complete-define-assignment.d.ts +2 -0
- package/lib/plugins/vue-complete-define-assignment.js +83 -0
- package/lib/plugins/vue-directive-comments.js +10 -8
- package/lib/plugins/vue-document-drop.js +15 -12
- package/lib/plugins/vue-document-links.js +45 -39
- package/lib/plugins/vue-extract-file.js +19 -10
- package/lib/plugins/vue-inlayhints.d.ts +1 -1
- package/lib/plugins/vue-inlayhints.js +65 -56
- package/lib/plugins/vue-sfc.js +29 -27
- package/lib/plugins/vue-template.js +194 -162
- package/lib/plugins/vue-twoslash-queries.js +9 -4
- package/package.json +9 -9
- package/scripts/update-html-data.js +74 -70
|
@@ -23,13 +23,18 @@ function create(ts, getTsPluginClient) {
|
|
|
23
23
|
if (startOffset === endOffset) {
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
|
-
const
|
|
26
|
+
const uri = vscode_uri_1.URI.parse(document.uri);
|
|
27
|
+
const decoded = context.decodeEmbeddedDocumentUri(uri);
|
|
27
28
|
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
28
29
|
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
29
|
-
if (!
|
|
30
|
+
if (!sourceScript?.generated || virtualCode?.id !== 'template') {
|
|
30
31
|
return;
|
|
31
32
|
}
|
|
32
|
-
const
|
|
33
|
+
const root = sourceScript.generated.root;
|
|
34
|
+
if (!(root instanceof language_core_1.VueVirtualCode)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const sfc = root._sfc;
|
|
33
38
|
const script = sfc.scriptSetup ?? sfc.script;
|
|
34
39
|
if (!sfc.template || !script) {
|
|
35
40
|
return;
|
|
@@ -57,12 +62,14 @@ function create(ts, getTsPluginClient) {
|
|
|
57
62
|
const decoded = context.decodeEmbeddedDocumentUri(parsedUri);
|
|
58
63
|
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
59
64
|
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
60
|
-
if (!
|
|
65
|
+
if (!sourceScript?.generated || virtualCode?.id !== 'template') {
|
|
61
66
|
return codeAction;
|
|
62
67
|
}
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
68
|
+
const root = sourceScript.generated.root;
|
|
69
|
+
if (!(root instanceof language_core_1.VueVirtualCode)) {
|
|
70
|
+
return codeAction;
|
|
71
|
+
}
|
|
72
|
+
const sfc = root._sfc;
|
|
66
73
|
const script = sfc.scriptSetup ?? sfc.script;
|
|
67
74
|
if (!sfc.template || !script) {
|
|
68
75
|
return codeAction;
|
|
@@ -71,16 +78,18 @@ function create(ts, getTsPluginClient) {
|
|
|
71
78
|
if (!templateCodeRange) {
|
|
72
79
|
return codeAction;
|
|
73
80
|
}
|
|
74
|
-
const toExtract = await tsPluginClient?.collectExtractProps(
|
|
81
|
+
const toExtract = await tsPluginClient?.collectExtractProps(root.fileName, templateCodeRange) ?? [];
|
|
75
82
|
if (!toExtract) {
|
|
76
83
|
return codeAction;
|
|
77
84
|
}
|
|
78
85
|
const templateInitialIndent = await context.env.getConfiguration('vue.format.template.initialIndent') ?? true;
|
|
79
86
|
const scriptInitialIndent = await context.env.getConfiguration('vue.format.script.initialIndent') ?? false;
|
|
80
|
-
const
|
|
87
|
+
const document = context.documents.get(parsedUri, virtualCode.languageId, virtualCode.snapshot);
|
|
88
|
+
const sfcDocument = context.documents.get(sourceScript.id, sourceScript.languageId, sourceScript.snapshot);
|
|
89
|
+
const newUri = sfcDocument.uri.slice(0, sfcDocument.uri.lastIndexOf('/') + 1) + `${newName}.vue`;
|
|
81
90
|
const lastImportNode = getLastImportNode(ts, script.ast);
|
|
82
91
|
let newFileTags = [];
|
|
83
|
-
newFileTags.push(constructTag('template', [], templateInitialIndent, sfc.template.content.
|
|
92
|
+
newFileTags.push(constructTag('template', [], templateInitialIndent, sfc.template.content.slice(templateCodeRange[0], templateCodeRange[1])));
|
|
84
93
|
if (toExtract.length) {
|
|
85
94
|
newFileTags.push(constructTag('script', ['setup', 'lang="ts"'], scriptInitialIndent, generateNewScriptContents()));
|
|
86
95
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { LanguageServicePlugin } from '../types';
|
|
2
1
|
import type * as ts from 'typescript';
|
|
2
|
+
import type { LanguageServicePlugin } from '../types';
|
|
3
3
|
export declare function create(ts: typeof import('typescript')): LanguageServicePlugin;
|
|
4
4
|
/**
|
|
5
5
|
* Refactored from https://github.com/vuejs/core/blob/main/packages/compiler-sfc/src/script/definePropsDestructure.ts
|
|
@@ -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
|
|
18
|
-
const
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
];
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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,
|
|
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,
|
|
166
|
+
for (const [id] of (0, index_1.collectIdentifiers)(ts, p)) {
|
|
158
167
|
registerLocalBinding(id);
|
|
159
168
|
}
|
|
160
169
|
}
|
package/lib/plugins/vue-sfc.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.create = create;
|
|
4
|
-
const
|
|
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 (
|
|
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
|
|
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
|
|
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,
|
|
67
|
+
return worker(document, context, root => {
|
|
68
68
|
const result = [];
|
|
69
|
-
const
|
|
70
|
-
if (
|
|
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(
|
|
76
|
-
end: document.positionAt(
|
|
75
|
+
start: document.positionAt(sfc.template.start),
|
|
76
|
+
end: document.positionAt(sfc.template.end),
|
|
77
77
|
},
|
|
78
78
|
selectionRange: {
|
|
79
|
-
start: document.positionAt(
|
|
80
|
-
end: document.positionAt(
|
|
79
|
+
start: document.positionAt(sfc.template.start),
|
|
80
|
+
end: document.positionAt(sfc.template.startTagEnd),
|
|
81
81
|
},
|
|
82
82
|
});
|
|
83
83
|
}
|
|
84
|
-
if (
|
|
84
|
+
if (sfc.script) {
|
|
85
85
|
result.push({
|
|
86
86
|
name: 'script',
|
|
87
87
|
kind: 2,
|
|
88
88
|
range: {
|
|
89
|
-
start: document.positionAt(
|
|
90
|
-
end: document.positionAt(
|
|
89
|
+
start: document.positionAt(sfc.script.start),
|
|
90
|
+
end: document.positionAt(sfc.script.end),
|
|
91
91
|
},
|
|
92
92
|
selectionRange: {
|
|
93
|
-
start: document.positionAt(
|
|
94
|
-
end: document.positionAt(
|
|
93
|
+
start: document.positionAt(sfc.script.start),
|
|
94
|
+
end: document.positionAt(sfc.script.startTagEnd),
|
|
95
95
|
},
|
|
96
96
|
});
|
|
97
97
|
}
|
|
98
|
-
if (
|
|
98
|
+
if (sfc.scriptSetup) {
|
|
99
99
|
result.push({
|
|
100
100
|
name: 'script setup',
|
|
101
101
|
kind: 2,
|
|
102
102
|
range: {
|
|
103
|
-
start: document.positionAt(
|
|
104
|
-
end: document.positionAt(
|
|
103
|
+
start: document.positionAt(sfc.scriptSetup.start),
|
|
104
|
+
end: document.positionAt(sfc.scriptSetup.end),
|
|
105
105
|
},
|
|
106
106
|
selectionRange: {
|
|
107
|
-
start: document.positionAt(
|
|
108
|
-
end: document.positionAt(
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
223
|
-
|
|
223
|
+
const root = sourceScript?.generated?.root;
|
|
224
|
+
if (root instanceof language_core_1.VueVirtualCode) {
|
|
225
|
+
return callback(root);
|
|
224
226
|
}
|
|
225
227
|
}
|
|
226
228
|
}
|