@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.
- 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 +2 -2
- package/lib/ideFeatures/nameCasing.js +14 -16
- package/lib/plugins/data.js +47 -20
- package/lib/plugins/vue-autoinsert-dotvalue.js +4 -3
- package/lib/plugins/vue-autoinsert-space.js +1 -1
- package/lib/plugins/vue-complete-define-assignment.js +11 -13
- 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 +10 -9
- package/scripts/update-html-data.js +74 -70
package/index.d.ts
CHANGED
|
@@ -13,5 +13,5 @@ declare module '@volar/language-service' {
|
|
|
13
13
|
}
|
|
14
14
|
export declare function getFullLanguageServicePlugins(ts: typeof import('typescript'), { disableAutoImportCache }?: {
|
|
15
15
|
disableAutoImportCache?: boolean;
|
|
16
|
-
}): LanguageServicePlugin[];
|
|
17
|
-
export declare function getHybridModeLanguageServicePlugins(ts: typeof import('typescript'), getTsPluginClient: typeof import("@vue/typescript-plugin/lib/client")): LanguageServicePlugin[];
|
|
16
|
+
}): LanguageServicePlugin<any>[];
|
|
17
|
+
export declare function getHybridModeLanguageServicePlugins(ts: typeof import('typescript'), getTsPluginClient: typeof import("@vue/typescript-plugin/lib/client")): LanguageServicePlugin<any>[];
|
package/index.js
CHANGED
|
@@ -30,17 +30,17 @@ const volar_service_typescript_twoslash_queries_1 = require("volar-service-types
|
|
|
30
30
|
const docCommentTemplate_1 = require("volar-service-typescript/lib/plugins/docCommentTemplate");
|
|
31
31
|
const syntactic_1 = require("volar-service-typescript/lib/plugins/syntactic");
|
|
32
32
|
const css_1 = require("./lib/plugins/css");
|
|
33
|
-
const vue_complete_define_assignment_1 = require("./lib/plugins/vue-complete-define-assignment");
|
|
34
33
|
const vue_autoinsert_dotvalue_1 = require("./lib/plugins/vue-autoinsert-dotvalue");
|
|
35
34
|
const vue_autoinsert_space_1 = require("./lib/plugins/vue-autoinsert-space");
|
|
35
|
+
const vue_complete_define_assignment_1 = require("./lib/plugins/vue-complete-define-assignment");
|
|
36
36
|
const vue_directive_comments_1 = require("./lib/plugins/vue-directive-comments");
|
|
37
37
|
const vue_document_drop_1 = require("./lib/plugins/vue-document-drop");
|
|
38
38
|
const vue_document_links_1 = require("./lib/plugins/vue-document-links");
|
|
39
39
|
const vue_extract_file_1 = require("./lib/plugins/vue-extract-file");
|
|
40
|
+
const vue_inlayhints_1 = require("./lib/plugins/vue-inlayhints");
|
|
40
41
|
const vue_sfc_1 = require("./lib/plugins/vue-sfc");
|
|
41
42
|
const vue_template_1 = require("./lib/plugins/vue-template");
|
|
42
43
|
const vue_twoslash_queries_1 = require("./lib/plugins/vue-twoslash-queries");
|
|
43
|
-
const vue_inlayhints_1 = require("./lib/plugins/vue-inlayhints");
|
|
44
44
|
const language_core_1 = require("@vue/language-core");
|
|
45
45
|
const common_1 = require("@vue/typescript-plugin/lib/common");
|
|
46
46
|
const collectExtractProps_1 = require("@vue/typescript-plugin/lib/requests/collectExtractProps");
|
|
@@ -13,19 +13,18 @@ async function convertTagName(context, uri, casing, tsPluginClient) {
|
|
|
13
13
|
if (!sourceFile) {
|
|
14
14
|
return;
|
|
15
15
|
}
|
|
16
|
-
const
|
|
17
|
-
if (!(
|
|
16
|
+
const root = sourceFile?.generated?.root;
|
|
17
|
+
if (!(root instanceof language_core_1.VueVirtualCode)) {
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
20
|
-
const
|
|
21
|
-
if (!
|
|
20
|
+
const { template } = root._sfc;
|
|
21
|
+
if (!template) {
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
|
-
const template = desc.template;
|
|
25
24
|
const document = context.documents.get(sourceFile.id, sourceFile.languageId, sourceFile.snapshot);
|
|
26
25
|
const edits = [];
|
|
27
|
-
const components = await tsPluginClient?.getComponentNames(
|
|
28
|
-
const tags = getTemplateTagsAndAttrs(
|
|
26
|
+
const components = await tsPluginClient?.getComponentNames(root.fileName) ?? [];
|
|
27
|
+
const tags = getTemplateTagsAndAttrs(root);
|
|
29
28
|
for (const [tagName, { offsets }] of tags) {
|
|
30
29
|
const componentName = components.find(component => component === tagName || (0, language_core_1.hyphenateTag)(component) === tagName);
|
|
31
30
|
if (componentName) {
|
|
@@ -49,23 +48,22 @@ async function convertAttrName(context, uri, casing, tsPluginClient) {
|
|
|
49
48
|
if (!sourceFile) {
|
|
50
49
|
return;
|
|
51
50
|
}
|
|
52
|
-
const
|
|
53
|
-
if (!(
|
|
51
|
+
const root = sourceFile?.generated?.root;
|
|
52
|
+
if (!(root instanceof language_core_1.VueVirtualCode)) {
|
|
54
53
|
return;
|
|
55
54
|
}
|
|
56
|
-
const
|
|
57
|
-
if (!
|
|
55
|
+
const { template } = root._sfc;
|
|
56
|
+
if (!template) {
|
|
58
57
|
return;
|
|
59
58
|
}
|
|
60
|
-
const template = desc.template;
|
|
61
59
|
const document = context.documents.get(uri, sourceFile.languageId, sourceFile.snapshot);
|
|
62
60
|
const edits = [];
|
|
63
|
-
const components = await tsPluginClient?.getComponentNames(
|
|
64
|
-
const tags = getTemplateTagsAndAttrs(
|
|
61
|
+
const components = await tsPluginClient?.getComponentNames(root.fileName) ?? [];
|
|
62
|
+
const tags = getTemplateTagsAndAttrs(root);
|
|
65
63
|
for (const [tagName, { attrs }] of tags) {
|
|
66
64
|
const componentName = components.find(component => component === tagName || (0, language_core_1.hyphenateTag)(component) === tagName);
|
|
67
65
|
if (componentName) {
|
|
68
|
-
const props = (await tsPluginClient?.getComponentProps(
|
|
66
|
+
const props = (await tsPluginClient?.getComponentProps(root.fileName, componentName) ?? []).map(prop => prop.name);
|
|
69
67
|
for (const [attrName, { offsets }] of attrs) {
|
|
70
68
|
const propName = props.find(prop => prop === attrName || (0, language_core_1.hyphenateAttr)(prop) === attrName);
|
|
71
69
|
if (propName) {
|
|
@@ -124,7 +122,7 @@ async function detect(context, uri) {
|
|
|
124
122
|
}
|
|
125
123
|
for (const [tagName] of attrs) {
|
|
126
124
|
// attr-name
|
|
127
|
-
if (tagName.
|
|
125
|
+
if (tagName.includes('-')) {
|
|
128
126
|
result.push(types_1.AttrNameCasing.Kebab);
|
|
129
127
|
break;
|
|
130
128
|
}
|
package/lib/plugins/data.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.loadTemplateData = loadTemplateData;
|
|
4
4
|
exports.loadLanguageBlocks = loadLanguageBlocks;
|
|
5
5
|
exports.loadModelModifiersData = loadModelModifiersData;
|
|
6
|
+
let locale;
|
|
6
7
|
function loadTemplateData(lang) {
|
|
7
8
|
lang = lang.toLowerCase();
|
|
8
9
|
let data;
|
|
@@ -36,6 +37,7 @@ function loadTemplateData(lang) {
|
|
|
36
37
|
else {
|
|
37
38
|
data = require('../../data/template/en.json');
|
|
38
39
|
}
|
|
40
|
+
resolveReferences(data);
|
|
39
41
|
for (const attr of [...data.globalAttributes ?? []]) {
|
|
40
42
|
if (!attr.name.startsWith('v-')) {
|
|
41
43
|
data.globalAttributes?.push({ ...attr, name: `:${attr.name}` }, { ...attr, name: `v-bind:${attr.name}` });
|
|
@@ -57,64 +59,89 @@ function loadTemplateData(lang) {
|
|
|
57
59
|
}
|
|
58
60
|
function loadLanguageBlocks(lang) {
|
|
59
61
|
lang = lang.toLowerCase();
|
|
62
|
+
let data;
|
|
60
63
|
if (lang === 'ja') {
|
|
61
|
-
|
|
64
|
+
data = require('../../data/language-blocks/ja.json');
|
|
62
65
|
}
|
|
63
66
|
else if (lang === 'fr') {
|
|
64
|
-
|
|
67
|
+
data = require('../../data/language-blocks/fr.json');
|
|
65
68
|
}
|
|
66
69
|
else if (lang === 'ko') {
|
|
67
|
-
|
|
70
|
+
data = require('../../data/language-blocks/ko.json');
|
|
68
71
|
}
|
|
69
72
|
else if (lang === 'pt-br') {
|
|
70
|
-
|
|
73
|
+
data = require('../../data/language-blocks/pt.json');
|
|
71
74
|
}
|
|
72
75
|
else if (lang === 'zh-cn') {
|
|
73
|
-
|
|
76
|
+
data = require('../../data/language-blocks/zh-cn.json');
|
|
74
77
|
}
|
|
75
78
|
else if (lang === 'zh-tw') {
|
|
76
|
-
|
|
79
|
+
data = require('../../data/language-blocks/zh-hk.json');
|
|
77
80
|
}
|
|
78
81
|
else if (lang === 'it') {
|
|
79
|
-
|
|
82
|
+
data = require('../../data/language-blocks/it.json');
|
|
80
83
|
}
|
|
81
84
|
else if (lang === 'cs') {
|
|
82
|
-
|
|
85
|
+
data = require('../../data/language-blocks/cs.json');
|
|
83
86
|
}
|
|
84
87
|
else if (lang === 'ru') {
|
|
85
|
-
|
|
88
|
+
data = require('../../data/language-blocks/ru.json');
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
data = require('../../data/language-blocks/en.json');
|
|
86
92
|
}
|
|
87
|
-
|
|
93
|
+
resolveReferences(data);
|
|
94
|
+
return data;
|
|
88
95
|
}
|
|
89
96
|
function loadModelModifiersData(lang) {
|
|
90
97
|
lang = lang.toLowerCase();
|
|
98
|
+
let data;
|
|
91
99
|
if (lang === 'ja') {
|
|
92
|
-
|
|
100
|
+
data = require('../../data/model-modifiers/ja.json');
|
|
93
101
|
}
|
|
94
102
|
else if (lang === 'fr') {
|
|
95
|
-
|
|
103
|
+
data = require('../../data/model-modifiers/fr.json');
|
|
96
104
|
}
|
|
97
105
|
else if (lang === 'ko') {
|
|
98
|
-
|
|
106
|
+
data = require('../../data/model-modifiers/ko.json');
|
|
99
107
|
}
|
|
100
108
|
else if (lang === 'pt-br') {
|
|
101
|
-
|
|
109
|
+
data = require('../../data/model-modifiers/pt.json');
|
|
102
110
|
}
|
|
103
111
|
else if (lang === 'zh-cn') {
|
|
104
|
-
|
|
112
|
+
data = require('../../data/model-modifiers/zh-cn.json');
|
|
105
113
|
}
|
|
106
114
|
else if (lang === 'zh-tw') {
|
|
107
|
-
|
|
115
|
+
data = require('../../data/model-modifiers/zh-hk.json');
|
|
108
116
|
}
|
|
109
117
|
else if (lang === 'it') {
|
|
110
|
-
|
|
118
|
+
data = require('../../data/model-modifiers/it.json');
|
|
111
119
|
}
|
|
112
120
|
else if (lang === 'cs') {
|
|
113
|
-
|
|
121
|
+
data = require('../../data/model-modifiers/cs.json');
|
|
114
122
|
}
|
|
115
123
|
else if (lang === 'ru') {
|
|
116
|
-
|
|
124
|
+
data = require('../../data/model-modifiers/ru.json');
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
data = require('../../data/model-modifiers/en.json');
|
|
128
|
+
}
|
|
129
|
+
resolveReferences(data);
|
|
130
|
+
return data;
|
|
131
|
+
}
|
|
132
|
+
function resolveReferences(data) {
|
|
133
|
+
locale ??= require('../../data/locale.json');
|
|
134
|
+
for (const item of [
|
|
135
|
+
...data.globalAttributes ?? [],
|
|
136
|
+
...data.tags?.flatMap(tag => [tag, ...tag.attributes]) ?? [],
|
|
137
|
+
]) {
|
|
138
|
+
if (typeof item.references === 'string') {
|
|
139
|
+
const relativeUrl = item.references;
|
|
140
|
+
item.references = locale.map(({ name, url }) => ({
|
|
141
|
+
name,
|
|
142
|
+
url: url + relativeUrl
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
117
145
|
}
|
|
118
|
-
return require('../../data/model-modifiers/en.json');
|
|
119
146
|
}
|
|
120
147
|
//# sourceMappingURL=data.js.map
|
|
@@ -49,7 +49,8 @@ function create(ts, getTsPluginClient) {
|
|
|
49
49
|
if (!enabled) {
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
|
-
const
|
|
52
|
+
const uri = vscode_uri_1.URI.parse(document.uri);
|
|
53
|
+
const decoded = context.decodeEmbeddedDocumentUri(uri);
|
|
53
54
|
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
54
55
|
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
55
56
|
if (!sourceScript) {
|
|
@@ -107,11 +108,11 @@ function isTsDocument(document) {
|
|
|
107
108
|
const charReg = /\w/;
|
|
108
109
|
function isCharacterTyping(document, change) {
|
|
109
110
|
const lastCharacter = change.text[change.text.length - 1];
|
|
110
|
-
const nextCharacter = document.getText().
|
|
111
|
+
const nextCharacter = document.getText().slice(change.rangeOffset + change.text.length, change.rangeOffset + change.text.length + 1);
|
|
111
112
|
if (lastCharacter === undefined) { // delete text
|
|
112
113
|
return false;
|
|
113
114
|
}
|
|
114
|
-
if (change.text.
|
|
115
|
+
if (change.text.includes('\n')) { // multi-line change
|
|
115
116
|
return false;
|
|
116
117
|
}
|
|
117
118
|
return charReg.test(lastCharacter) && !charReg.test(nextCharacter);
|
|
@@ -19,7 +19,7 @@ function create() {
|
|
|
19
19
|
return;
|
|
20
20
|
}
|
|
21
21
|
if (change.text === '{}'
|
|
22
|
-
&& document.getText().
|
|
22
|
+
&& document.getText().slice(change.rangeOffset - 1, change.rangeOffset + 3) === '{{}}'
|
|
23
23
|
&& document.offsetAt(selection) === change.rangeOffset + 1) {
|
|
24
24
|
return ` $0 `;
|
|
25
25
|
}
|
|
@@ -21,14 +21,14 @@ function create() {
|
|
|
21
21
|
if (!enabled) {
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
|
-
const
|
|
25
|
-
const decoded = context.decodeEmbeddedDocumentUri(
|
|
24
|
+
const uri = vscode_uri_1.URI.parse(document.uri);
|
|
25
|
+
const decoded = context.decodeEmbeddedDocumentUri(uri);
|
|
26
26
|
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
27
27
|
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
28
|
-
if (!sourceScript || !virtualCode) {
|
|
28
|
+
if (!sourceScript?.generated || !virtualCode) {
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
|
-
const root = sourceScript
|
|
31
|
+
const root = sourceScript.generated.root;
|
|
32
32
|
if (!(root instanceof language_core_1.VueVirtualCode)) {
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
@@ -38,24 +38,22 @@ function create() {
|
|
|
38
38
|
if (!scriptSetup || !scriptSetupRanges) {
|
|
39
39
|
return;
|
|
40
40
|
}
|
|
41
|
+
const result = [];
|
|
41
42
|
const mappings = [...context.language.maps.forEach(virtualCode)];
|
|
42
|
-
addDefineCompletionItem(scriptSetupRanges.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}, 'props');
|
|
46
|
-
addDefineCompletionItem(scriptSetupRanges.emits.define, 'emit');
|
|
47
|
-
addDefineCompletionItem(scriptSetupRanges.slots.define, 'slots');
|
|
43
|
+
addDefineCompletionItem(scriptSetupRanges.defineProps?.statement, scriptSetupRanges.withDefaults?.exp ?? scriptSetupRanges.defineProps?.exp, 'props');
|
|
44
|
+
addDefineCompletionItem(scriptSetupRanges.defineEmits?.statement, scriptSetupRanges.defineEmits?.exp, 'emit');
|
|
45
|
+
addDefineCompletionItem(scriptSetupRanges.defineSlots?.statement, scriptSetupRanges.defineSlots?.exp, 'slots');
|
|
48
46
|
return {
|
|
49
47
|
isIncomplete: false,
|
|
50
48
|
items: result
|
|
51
49
|
};
|
|
52
|
-
function addDefineCompletionItem(
|
|
53
|
-
if (!
|
|
50
|
+
function addDefineCompletionItem(statement, exp, name) {
|
|
51
|
+
if (!exp || exp.start !== statement?.start) {
|
|
54
52
|
return;
|
|
55
53
|
}
|
|
56
54
|
let offset;
|
|
57
55
|
for (const [, map] of mappings) {
|
|
58
|
-
for (const [generatedOffset] of map.toGeneratedLocation(scriptSetup.startTagEnd +
|
|
56
|
+
for (const [generatedOffset] of map.toGeneratedLocation(scriptSetup.startTagEnd + exp.start)) {
|
|
59
57
|
offset = generatedOffset;
|
|
60
58
|
break;
|
|
61
59
|
}
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.create = create;
|
|
4
4
|
const cmds = [
|
|
5
|
-
'vue-ignore',
|
|
6
|
-
'vue-skip',
|
|
7
|
-
'vue-expect-error',
|
|
5
|
+
['vue-ignore'],
|
|
6
|
+
['vue-skip'],
|
|
7
|
+
['vue-expect-error'],
|
|
8
|
+
['vue-generic', 'vue-generic {$1}'],
|
|
8
9
|
];
|
|
9
10
|
const directiveCommentReg = /<!--\s*@/;
|
|
10
11
|
function create() {
|
|
@@ -27,19 +28,19 @@ function create() {
|
|
|
27
28
|
return;
|
|
28
29
|
}
|
|
29
30
|
const startIndex = cmdStart.index + cmdStart[0].length;
|
|
30
|
-
const remainText = line.
|
|
31
|
+
const remainText = line.slice(startIndex);
|
|
31
32
|
const result = [];
|
|
32
|
-
for (const
|
|
33
|
+
for (const [label, text = label] of cmds) {
|
|
33
34
|
let match = true;
|
|
34
35
|
for (let i = 0; i < remainText.length; i++) {
|
|
35
|
-
if (remainText[i] !==
|
|
36
|
+
if (remainText[i] !== label[i]) {
|
|
36
37
|
match = false;
|
|
37
38
|
break;
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
if (match) {
|
|
41
42
|
result.push({
|
|
42
|
-
label: '@' +
|
|
43
|
+
label: '@' + label,
|
|
43
44
|
textEdit: {
|
|
44
45
|
range: {
|
|
45
46
|
start: {
|
|
@@ -48,8 +49,9 @@ function create() {
|
|
|
48
49
|
},
|
|
49
50
|
end: position,
|
|
50
51
|
},
|
|
51
|
-
newText: '@' +
|
|
52
|
+
newText: '@' + text,
|
|
52
53
|
},
|
|
54
|
+
insertTextFormat: 2
|
|
53
55
|
});
|
|
54
56
|
}
|
|
55
57
|
}
|
|
@@ -26,11 +26,14 @@ function create(ts, getTsPluginClient) {
|
|
|
26
26
|
if (document.languageId !== 'html') {
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
|
-
const
|
|
29
|
+
const uri = vscode_uri_1.URI.parse(document.uri);
|
|
30
|
+
const decoded = context.decodeEmbeddedDocumentUri(uri);
|
|
30
31
|
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
if (!sourceScript?.generated) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const root = sourceScript.generated.root;
|
|
36
|
+
if (!(root instanceof language_core_1.VueVirtualCode)) {
|
|
34
37
|
return;
|
|
35
38
|
}
|
|
36
39
|
let importUri;
|
|
@@ -42,33 +45,33 @@ function create(ts, getTsPluginClient) {
|
|
|
42
45
|
if (!importUri || !vueCompilerOptions.extensions.some(ext => importUri.endsWith(ext))) {
|
|
43
46
|
return;
|
|
44
47
|
}
|
|
45
|
-
let baseName = importUri.
|
|
46
|
-
baseName = baseName.
|
|
48
|
+
let baseName = importUri.slice(importUri.lastIndexOf('/') + 1);
|
|
49
|
+
baseName = baseName.slice(0, baseName.lastIndexOf('.'));
|
|
47
50
|
const newName = (0, shared_1.capitalize)((0, shared_1.camelize)(baseName));
|
|
48
|
-
const
|
|
51
|
+
const sfc = root._sfc;
|
|
49
52
|
const script = sfc.scriptSetup ?? sfc.script;
|
|
50
53
|
if (!script) {
|
|
51
54
|
return;
|
|
52
55
|
}
|
|
53
56
|
const additionalEdit = {};
|
|
54
|
-
const code = [...(0, language_core_1.forEachEmbeddedCode)(
|
|
57
|
+
const code = [...(0, language_core_1.forEachEmbeddedCode)(root)].find(code => code.id === (sfc.scriptSetup ? 'scriptsetup_raw' : 'script_raw'));
|
|
55
58
|
const lastImportNode = (0, vue_extract_file_1.getLastImportNode)(ts, script.ast);
|
|
56
59
|
const incomingFileName = context.project.typescript?.uriConverter.asFileName(vscode_uri_1.URI.parse(importUri))
|
|
57
60
|
?? vscode_uri_1.URI.parse(importUri).fsPath.replace(/\\/g, '/');
|
|
58
61
|
let importPath;
|
|
59
|
-
const serviceScript = sourceScript.generated?.languagePlugin.typescript?.getServiceScript(
|
|
62
|
+
const serviceScript = sourceScript.generated?.languagePlugin.typescript?.getServiceScript(root);
|
|
60
63
|
if (tsPluginClient && serviceScript) {
|
|
61
64
|
const tsDocumentUri = context.encodeEmbeddedDocumentUri(sourceScript.id, serviceScript.code.id);
|
|
62
65
|
const tsDocument = context.documents.get(tsDocumentUri, serviceScript.code.languageId, serviceScript.code.snapshot);
|
|
63
66
|
const preferences = await (0, getUserPreferences_1.getUserPreferences)(context, tsDocument);
|
|
64
|
-
const importPathRequest = await tsPluginClient.getImportPathForFile(
|
|
67
|
+
const importPathRequest = await tsPluginClient.getImportPathForFile(root.fileName, incomingFileName, preferences);
|
|
65
68
|
if (importPathRequest) {
|
|
66
69
|
importPath = importPathRequest;
|
|
67
70
|
}
|
|
68
71
|
}
|
|
69
72
|
if (!importPath) {
|
|
70
|
-
importPath = path_browserify_1.posix.relative(path_browserify_1.posix.dirname(
|
|
71
|
-
|| importUri.
|
|
73
|
+
importPath = path_browserify_1.posix.relative(path_browserify_1.posix.dirname(root.fileName), incomingFileName)
|
|
74
|
+
|| importUri.slice(importUri.lastIndexOf('/') + 1);
|
|
72
75
|
if (!importPath.startsWith('./') && !importPath.startsWith('../')) {
|
|
73
76
|
importPath = './' + importPath;
|
|
74
77
|
}
|
|
@@ -12,54 +12,60 @@ function create() {
|
|
|
12
12
|
create(context) {
|
|
13
13
|
return {
|
|
14
14
|
provideDocumentLinks(document) {
|
|
15
|
-
const
|
|
15
|
+
const uri = vscode_uri_1.URI.parse(document.uri);
|
|
16
|
+
const decoded = context.decodeEmbeddedDocumentUri(uri);
|
|
16
17
|
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
17
18
|
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
18
|
-
if (sourceScript?.generated
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
19
|
+
if (!sourceScript?.generated || virtualCode?.id !== 'template') {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const root = sourceScript.generated.root;
|
|
23
|
+
if (!(root instanceof language_core_1.VueVirtualCode)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const result = [];
|
|
27
|
+
const codegen = language_core_1.tsCodegen.get(root._sfc);
|
|
28
|
+
const scopedClasses = codegen?.generatedTemplate.get()?.scopedClasses ?? [];
|
|
29
|
+
const styleClasses = new Map();
|
|
30
|
+
const option = root.vueCompilerOptions.experimentalResolveStyleCssClasses;
|
|
31
|
+
for (let i = 0; i < root._sfc.styles.length; i++) {
|
|
32
|
+
const style = root._sfc.styles[i];
|
|
33
|
+
if (option === 'always' || (option === 'scoped' && style.scoped)) {
|
|
34
|
+
for (const className of style.classNames) {
|
|
35
|
+
if (!styleClasses.has(className.text.slice(1))) {
|
|
36
|
+
styleClasses.set(className.text.slice(1), []);
|
|
36
37
|
}
|
|
38
|
+
styleClasses.get(className.text.slice(1)).push({
|
|
39
|
+
index: i,
|
|
40
|
+
style,
|
|
41
|
+
classOffset: className.offset,
|
|
42
|
+
});
|
|
37
43
|
}
|
|
38
44
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const styleDocument = context.documents.get(styleDocumentUri, styleVirtualCode.languageId, styleVirtualCode.snapshot);
|
|
49
|
-
const start = styleDocument.positionAt(style.classOffset);
|
|
50
|
-
const end = styleDocument.positionAt(style.classOffset + className.length + 1);
|
|
51
|
-
result.push({
|
|
52
|
-
range: {
|
|
53
|
-
start: document.positionAt(offset),
|
|
54
|
-
end: document.positionAt(offset + className.length),
|
|
55
|
-
},
|
|
56
|
-
target: context.encodeEmbeddedDocumentUri(decoded[0], 'style_' + style.index) + `#L${start.line + 1},${start.character + 1}-L${end.line + 1},${end.character + 1}`,
|
|
57
|
-
});
|
|
45
|
+
}
|
|
46
|
+
for (const { className, offset } of scopedClasses) {
|
|
47
|
+
const styles = styleClasses.get(className);
|
|
48
|
+
if (styles) {
|
|
49
|
+
for (const style of styles) {
|
|
50
|
+
const styleDocumentUri = context.encodeEmbeddedDocumentUri(decoded[0], 'style_' + style.index);
|
|
51
|
+
const styleVirtualCode = sourceScript.generated.embeddedCodes.get('style_' + style.index);
|
|
52
|
+
if (!styleVirtualCode) {
|
|
53
|
+
continue;
|
|
58
54
|
}
|
|
55
|
+
const styleDocument = context.documents.get(styleDocumentUri, styleVirtualCode.languageId, styleVirtualCode.snapshot);
|
|
56
|
+
const start = styleDocument.positionAt(style.classOffset);
|
|
57
|
+
const end = styleDocument.positionAt(style.classOffset + className.length + 1);
|
|
58
|
+
result.push({
|
|
59
|
+
range: {
|
|
60
|
+
start: document.positionAt(offset),
|
|
61
|
+
end: document.positionAt(offset + className.length),
|
|
62
|
+
},
|
|
63
|
+
target: context.encodeEmbeddedDocumentUri(decoded[0], 'style_' + style.index) + `#L${start.line + 1},${start.character + 1}-L${end.line + 1},${end.character + 1}`,
|
|
64
|
+
});
|
|
59
65
|
}
|
|
60
66
|
}
|
|
61
|
-
return result;
|
|
62
67
|
}
|
|
68
|
+
return result;
|
|
63
69
|
},
|
|
64
70
|
};
|
|
65
71
|
},
|
|
@@ -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
|