@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
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
|
@@ -32,14 +32,15 @@ const syntactic_1 = require("volar-service-typescript/lib/plugins/syntactic");
|
|
|
32
32
|
const css_1 = require("./lib/plugins/css");
|
|
33
33
|
const vue_autoinsert_dotvalue_1 = require("./lib/plugins/vue-autoinsert-dotvalue");
|
|
34
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");
|
|
35
36
|
const vue_directive_comments_1 = require("./lib/plugins/vue-directive-comments");
|
|
36
37
|
const vue_document_drop_1 = require("./lib/plugins/vue-document-drop");
|
|
37
38
|
const vue_document_links_1 = require("./lib/plugins/vue-document-links");
|
|
38
39
|
const vue_extract_file_1 = require("./lib/plugins/vue-extract-file");
|
|
40
|
+
const vue_inlayhints_1 = require("./lib/plugins/vue-inlayhints");
|
|
39
41
|
const vue_sfc_1 = require("./lib/plugins/vue-sfc");
|
|
40
42
|
const vue_template_1 = require("./lib/plugins/vue-template");
|
|
41
43
|
const vue_twoslash_queries_1 = require("./lib/plugins/vue-twoslash-queries");
|
|
42
|
-
const vue_inlayhints_1 = require("./lib/plugins/vue-inlayhints");
|
|
43
44
|
const language_core_1 = require("@vue/language-core");
|
|
44
45
|
const common_1 = require("@vue/typescript-plugin/lib/common");
|
|
45
46
|
const collectExtractProps_1 = require("@vue/typescript-plugin/lib/requests/collectExtractProps");
|
|
@@ -179,6 +180,7 @@ function getCommonLanguageServicePlugins(ts, getTsPluginClient) {
|
|
|
179
180
|
(0, vue_twoslash_queries_1.create)(getTsPluginClient),
|
|
180
181
|
(0, vue_document_links_1.create)(),
|
|
181
182
|
(0, vue_document_drop_1.create)(ts, getTsPluginClient),
|
|
183
|
+
(0, vue_complete_define_assignment_1.create)(),
|
|
182
184
|
(0, vue_autoinsert_dotvalue_1.create)(ts, getTsPluginClient),
|
|
183
185
|
(0, vue_autoinsert_space_1.create)(),
|
|
184
186
|
(0, vue_inlayhints_1.create)(ts),
|
|
@@ -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
|
|
@@ -2,6 +2,7 @@ import type { LanguageServiceContext, LanguageServicePlugin } from '@volar/langu
|
|
|
2
2
|
import type * as ts from 'typescript';
|
|
3
3
|
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
4
4
|
export declare function create(ts: typeof import('typescript'), getTsPluginClient?: (context: LanguageServiceContext) => typeof import('@vue/typescript-plugin/lib/client') | undefined): LanguageServicePlugin;
|
|
5
|
+
export declare function isTsDocument(document: TextDocument): boolean;
|
|
5
6
|
export declare function isCharacterTyping(document: TextDocument, change: {
|
|
6
7
|
text: string;
|
|
7
8
|
rangeOffset: number;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.create = create;
|
|
4
|
+
exports.isTsDocument = isTsDocument;
|
|
4
5
|
exports.isCharacterTyping = isCharacterTyping;
|
|
5
6
|
exports.isBlacklistNode = isBlacklistNode;
|
|
6
7
|
const language_core_1 = require("@vue/language-core");
|
|
@@ -48,7 +49,8 @@ function create(ts, getTsPluginClient) {
|
|
|
48
49
|
if (!enabled) {
|
|
49
50
|
return;
|
|
50
51
|
}
|
|
51
|
-
const
|
|
52
|
+
const uri = vscode_uri_1.URI.parse(document.uri);
|
|
53
|
+
const decoded = context.decodeEmbeddedDocumentUri(uri);
|
|
52
54
|
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
53
55
|
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
54
56
|
if (!sourceScript) {
|
|
@@ -106,11 +108,11 @@ function isTsDocument(document) {
|
|
|
106
108
|
const charReg = /\w/;
|
|
107
109
|
function isCharacterTyping(document, change) {
|
|
108
110
|
const lastCharacter = change.text[change.text.length - 1];
|
|
109
|
-
const nextCharacter = document.getText().
|
|
111
|
+
const nextCharacter = document.getText().slice(change.rangeOffset + change.text.length, change.rangeOffset + change.text.length + 1);
|
|
110
112
|
if (lastCharacter === undefined) { // delete text
|
|
111
113
|
return false;
|
|
112
114
|
}
|
|
113
|
-
if (change.text.
|
|
115
|
+
if (change.text.includes('\n')) { // multi-line change
|
|
114
116
|
return false;
|
|
115
117
|
}
|
|
116
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
|
}
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
const vue_autoinsert_dotvalue_1 = require("./vue-autoinsert-dotvalue");
|
|
7
|
+
function create() {
|
|
8
|
+
return {
|
|
9
|
+
name: 'vue-complete-define-assignment',
|
|
10
|
+
capabilities: {
|
|
11
|
+
completionProvider: {},
|
|
12
|
+
},
|
|
13
|
+
create(context) {
|
|
14
|
+
return {
|
|
15
|
+
isAdditionalCompletion: true,
|
|
16
|
+
async provideCompletionItems(document) {
|
|
17
|
+
if (!(0, vue_autoinsert_dotvalue_1.isTsDocument)(document)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const enabled = await context.env.getConfiguration?.('vue.complete.defineAssignment') ?? true;
|
|
21
|
+
if (!enabled) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const uri = vscode_uri_1.URI.parse(document.uri);
|
|
25
|
+
const decoded = context.decodeEmbeddedDocumentUri(uri);
|
|
26
|
+
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
27
|
+
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
28
|
+
if (!sourceScript?.generated || !virtualCode) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const root = sourceScript.generated.root;
|
|
32
|
+
if (!(root instanceof language_core_1.VueVirtualCode)) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const codegen = language_core_1.tsCodegen.get(root._sfc);
|
|
36
|
+
const scriptSetup = root._sfc.scriptSetup;
|
|
37
|
+
const scriptSetupRanges = codegen?.scriptSetupRanges.get();
|
|
38
|
+
if (!scriptSetup || !scriptSetupRanges) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const result = [];
|
|
42
|
+
const mappings = [...context.language.maps.forEach(virtualCode)];
|
|
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');
|
|
46
|
+
return {
|
|
47
|
+
isIncomplete: false,
|
|
48
|
+
items: result
|
|
49
|
+
};
|
|
50
|
+
function addDefineCompletionItem(statement, exp, name) {
|
|
51
|
+
if (!exp || exp.start !== statement?.start) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
let offset;
|
|
55
|
+
for (const [, map] of mappings) {
|
|
56
|
+
for (const [generatedOffset] of map.toGeneratedLocation(scriptSetup.startTagEnd + exp.start)) {
|
|
57
|
+
offset = generatedOffset;
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (offset === undefined) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const pos = document.positionAt(offset);
|
|
65
|
+
result.push({
|
|
66
|
+
label: name,
|
|
67
|
+
kind: 6,
|
|
68
|
+
commitCharacters: ['.', ',', ';'],
|
|
69
|
+
additionalTextEdits: [{
|
|
70
|
+
newText: `const ${name} = `,
|
|
71
|
+
range: {
|
|
72
|
+
start: pos,
|
|
73
|
+
end: pos
|
|
74
|
+
}
|
|
75
|
+
}]
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=vue-complete-define-assignment.js.map
|
|
@@ -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
|
},
|