@vue/language-service 2.1.10 → 2.2.2
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 +49 -1427
- 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 +14 -10
- package/lib/ideFeatures/nameCasing.js +15 -17
- package/lib/plugins/data.js +47 -20
- package/lib/plugins/utils.d.ts +3 -0
- package/lib/plugins/utils.js +14 -0
- package/lib/plugins/vue-autoinsert-dotvalue.d.ts +0 -9
- package/lib/plugins/vue-autoinsert-dotvalue.js +37 -53
- package/lib/plugins/vue-autoinsert-space.js +1 -1
- package/lib/plugins/vue-complete-define-assignment.js +14 -16
- package/lib/plugins/vue-directive-comments.js +10 -8
- package/lib/plugins/vue-document-drop.js +16 -13
- package/lib/plugins/vue-document-links.js +45 -39
- package/lib/plugins/vue-extract-file.d.ts +2 -1
- package/lib/plugins/vue-extract-file.js +29 -15
- package/lib/plugins/vue-inlayhints.d.ts +2 -2
- package/lib/plugins/vue-inlayhints.js +65 -56
- package/lib/plugins/vue-sfc.js +29 -27
- package/lib/plugins/vue-template.js +223 -201
- package/lib/plugins/vue-twoslash-queries.js +9 -4
- package/package.json +12 -11
- 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,21 +30,25 @@ 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");
|
|
47
|
-
const
|
|
47
|
+
const getComponentDirectives_1 = require("@vue/typescript-plugin/lib/requests/getComponentDirectives");
|
|
48
|
+
const getComponentEvents_1 = require("@vue/typescript-plugin/lib/requests/getComponentEvents");
|
|
49
|
+
const getComponentNames_1 = require("@vue/typescript-plugin/lib/requests/getComponentNames");
|
|
50
|
+
const getComponentProps_1 = require("@vue/typescript-plugin/lib/requests/getComponentProps");
|
|
51
|
+
const getElementAttrs_1 = require("@vue/typescript-plugin/lib/requests/getElementAttrs");
|
|
48
52
|
const getImportPathForFile_1 = require("@vue/typescript-plugin/lib/requests/getImportPathForFile");
|
|
49
53
|
const getPropertiesAtLocation_1 = require("@vue/typescript-plugin/lib/requests/getPropertiesAtLocation");
|
|
50
54
|
const vscode_uri_1 = require("vscode-uri");
|
|
@@ -106,19 +110,19 @@ function getFullLanguageServicePlugins(ts, { disableAutoImportCache } = {}) {
|
|
|
106
110
|
return await getImportPathForFile_1.getImportPathForFile.apply(requestContext, args);
|
|
107
111
|
},
|
|
108
112
|
async getComponentEvents(...args) {
|
|
109
|
-
return await
|
|
113
|
+
return await getComponentEvents_1.getComponentEvents.apply(requestContext, args);
|
|
114
|
+
},
|
|
115
|
+
async getComponentDirectives(...args) {
|
|
116
|
+
return await getComponentDirectives_1.getComponentDirectives.apply(requestContext, args);
|
|
110
117
|
},
|
|
111
118
|
async getComponentNames(...args) {
|
|
112
|
-
return await
|
|
119
|
+
return await getComponentNames_1.getComponentNames.apply(requestContext, args);
|
|
113
120
|
},
|
|
114
121
|
async getComponentProps(...args) {
|
|
115
|
-
return await
|
|
122
|
+
return await getComponentProps_1.getComponentProps.apply(requestContext, args);
|
|
116
123
|
},
|
|
117
124
|
async getElementAttrs(...args) {
|
|
118
|
-
return await
|
|
119
|
-
},
|
|
120
|
-
async getTemplateContextProps(...args) {
|
|
121
|
-
return await componentInfos_1.getTemplateContextProps.apply(requestContext, args);
|
|
125
|
+
return await getElementAttrs_1.getElementAttrs.apply(requestContext, args);
|
|
122
126
|
},
|
|
123
127
|
async getQuickInfoAtPosition(fileName, position) {
|
|
124
128
|
const languageService = context.getLanguageService();
|
|
@@ -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
|
}
|
|
@@ -199,6 +197,6 @@ function getTemplateTagsAndAttrs(sourceFile) {
|
|
|
199
197
|
});
|
|
200
198
|
map.set(sourceFile, getter);
|
|
201
199
|
}
|
|
202
|
-
return map.get(sourceFile)
|
|
200
|
+
return map.get(sourceFile)() ?? new Map();
|
|
203
201
|
}
|
|
204
202
|
//# sourceMappingURL=nameCasing.js.map
|
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
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sleep = sleep;
|
|
4
|
+
exports.isTsDocument = isTsDocument;
|
|
5
|
+
function sleep(ms) {
|
|
6
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
7
|
+
}
|
|
8
|
+
function isTsDocument(document) {
|
|
9
|
+
return document.languageId === 'javascript' ||
|
|
10
|
+
document.languageId === 'typescript' ||
|
|
11
|
+
document.languageId === 'javascriptreact' ||
|
|
12
|
+
document.languageId === 'typescriptreact';
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -1,11 +1,2 @@
|
|
|
1
1
|
import type { LanguageServiceContext, LanguageServicePlugin } from '@volar/language-service';
|
|
2
|
-
import type * as ts from 'typescript';
|
|
3
|
-
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
4
2
|
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;
|
|
6
|
-
export declare function isCharacterTyping(document: TextDocument, change: {
|
|
7
|
-
text: string;
|
|
8
|
-
rangeOffset: number;
|
|
9
|
-
rangeLength: number;
|
|
10
|
-
}): boolean;
|
|
11
|
-
export declare function isBlacklistNode(ts: typeof import('typescript'), node: ts.Node, pos: number, allowAccessDotValue: boolean): boolean;
|
|
@@ -1,20 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.create = create;
|
|
4
|
-
exports.isTsDocument = isTsDocument;
|
|
5
|
-
exports.isCharacterTyping = isCharacterTyping;
|
|
6
|
-
exports.isBlacklistNode = isBlacklistNode;
|
|
7
4
|
const language_core_1 = require("@vue/language-core");
|
|
8
5
|
const vscode_uri_1 = require("vscode-uri");
|
|
9
|
-
const
|
|
10
|
-
function getAst(ts, fileName, snapshot, scriptKind) {
|
|
11
|
-
let ast = asts.get(snapshot);
|
|
12
|
-
if (!ast) {
|
|
13
|
-
ast = ts.createSourceFile(fileName, snapshot.getText(0, snapshot.getLength()), ts.ScriptTarget.Latest, undefined, scriptKind);
|
|
14
|
-
asts.set(snapshot, ast);
|
|
15
|
-
}
|
|
16
|
-
return ast;
|
|
17
|
-
}
|
|
6
|
+
const utils_1 = require("./utils");
|
|
18
7
|
function create(ts, getTsPluginClient) {
|
|
19
8
|
return {
|
|
20
9
|
name: 'vue-autoinsert-dotvalue',
|
|
@@ -33,7 +22,7 @@ function create(ts, getTsPluginClient) {
|
|
|
33
22
|
if (document.offsetAt(selection) !== change.rangeOffset + change.text.length) {
|
|
34
23
|
return;
|
|
35
24
|
}
|
|
36
|
-
if (!isTsDocument(document)) {
|
|
25
|
+
if (!(0, utils_1.isTsDocument)(document)) {
|
|
37
26
|
return;
|
|
38
27
|
}
|
|
39
28
|
if (!isCharacterTyping(document, change)) {
|
|
@@ -41,7 +30,7 @@ function create(ts, getTsPluginClient) {
|
|
|
41
30
|
}
|
|
42
31
|
const req = ++currentReq;
|
|
43
32
|
// Wait for tsserver to sync
|
|
44
|
-
await sleep(250);
|
|
33
|
+
await (0, utils_1.sleep)(250);
|
|
45
34
|
if (req !== currentReq) {
|
|
46
35
|
return;
|
|
47
36
|
}
|
|
@@ -49,44 +38,48 @@ function create(ts, getTsPluginClient) {
|
|
|
49
38
|
if (!enabled) {
|
|
50
39
|
return;
|
|
51
40
|
}
|
|
52
|
-
const
|
|
41
|
+
const uri = vscode_uri_1.URI.parse(document.uri);
|
|
42
|
+
const decoded = context.decodeEmbeddedDocumentUri(uri);
|
|
53
43
|
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
54
44
|
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
55
|
-
if (!sourceScript) {
|
|
45
|
+
if (!sourceScript?.generated || !virtualCode) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const root = sourceScript.generated.root;
|
|
49
|
+
if (!(root instanceof language_core_1.VueVirtualCode)) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const blocks = [
|
|
53
|
+
root._sfc.script,
|
|
54
|
+
root._sfc.scriptSetup,
|
|
55
|
+
].filter(block => !!block);
|
|
56
|
+
if (!blocks.length) {
|
|
56
57
|
return;
|
|
57
58
|
}
|
|
58
|
-
let ast;
|
|
59
59
|
let sourceCodeOffset = document.offsetAt(selection);
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
ast = getAst(ts, fileName, virtualCode.snapshot, serviceScript.scriptKind);
|
|
68
|
-
let mapped = false;
|
|
69
|
-
for (const [_sourceScript, map] of context.language.maps.forEach(virtualCode)) {
|
|
70
|
-
for (const [sourceOffset] of map.toSourceLocation(document.offsetAt(selection))) {
|
|
71
|
-
sourceCodeOffset = sourceOffset;
|
|
72
|
-
mapped = true;
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
if (mapped) {
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
60
|
+
let mapped = false;
|
|
61
|
+
for (const [, map] of context.language.maps.forEach(virtualCode)) {
|
|
62
|
+
for (const [sourceOffset] of map.toSourceLocation(sourceCodeOffset)) {
|
|
63
|
+
sourceCodeOffset = sourceOffset;
|
|
64
|
+
mapped = true;
|
|
65
|
+
break;
|
|
78
66
|
}
|
|
79
|
-
if (
|
|
80
|
-
|
|
67
|
+
if (mapped) {
|
|
68
|
+
break;
|
|
81
69
|
}
|
|
82
70
|
}
|
|
83
|
-
|
|
84
|
-
ast = getAst(ts, fileName, sourceScript.snapshot);
|
|
85
|
-
}
|
|
86
|
-
if (isBlacklistNode(ts, ast, document.offsetAt(selection), false)) {
|
|
71
|
+
if (!mapped) {
|
|
87
72
|
return;
|
|
88
73
|
}
|
|
89
|
-
const
|
|
74
|
+
for (const { ast, startTagEnd, endTagStart } of blocks) {
|
|
75
|
+
if (sourceCodeOffset < startTagEnd || sourceCodeOffset > endTagStart) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (isBlacklistNode(ts, ast, sourceCodeOffset - startTagEnd, false)) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const props = await tsPluginClient?.getPropertiesAtLocation(root.fileName, sourceCodeOffset) ?? [];
|
|
90
83
|
if (props.some(prop => prop === 'value')) {
|
|
91
84
|
return '${1:.value}';
|
|
92
85
|
}
|
|
@@ -95,23 +88,14 @@ function create(ts, getTsPluginClient) {
|
|
|
95
88
|
},
|
|
96
89
|
};
|
|
97
90
|
}
|
|
98
|
-
function sleep(ms) {
|
|
99
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
100
|
-
}
|
|
101
|
-
function isTsDocument(document) {
|
|
102
|
-
return document.languageId === 'javascript' ||
|
|
103
|
-
document.languageId === 'typescript' ||
|
|
104
|
-
document.languageId === 'javascriptreact' ||
|
|
105
|
-
document.languageId === 'typescriptreact';
|
|
106
|
-
}
|
|
107
91
|
const charReg = /\w/;
|
|
108
92
|
function isCharacterTyping(document, change) {
|
|
109
93
|
const lastCharacter = change.text[change.text.length - 1];
|
|
110
|
-
const nextCharacter = document.getText().
|
|
94
|
+
const nextCharacter = document.getText().slice(change.rangeOffset + change.text.length, change.rangeOffset + change.text.length + 1);
|
|
111
95
|
if (lastCharacter === undefined) { // delete text
|
|
112
96
|
return false;
|
|
113
97
|
}
|
|
114
|
-
if (change.text.
|
|
98
|
+
if (change.text.includes('\n')) { // multi-line change
|
|
115
99
|
return false;
|
|
116
100
|
}
|
|
117
101
|
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
|
}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.create = create;
|
|
4
4
|
const language_core_1 = require("@vue/language-core");
|
|
5
5
|
const vscode_uri_1 = require("vscode-uri");
|
|
6
|
-
const
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
7
|
function create() {
|
|
8
8
|
return {
|
|
9
9
|
name: 'vue-complete-define-assignment',
|
|
@@ -14,48 +14,46 @@ function create() {
|
|
|
14
14
|
return {
|
|
15
15
|
isAdditionalCompletion: true,
|
|
16
16
|
async provideCompletionItems(document) {
|
|
17
|
-
if (!(0,
|
|
17
|
+
if (!(0, utils_1.isTsDocument)(document)) {
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
20
20
|
const enabled = await context.env.getConfiguration?.('vue.complete.defineAssignment') ?? true;
|
|
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
|
}
|
|
35
35
|
const codegen = language_core_1.tsCodegen.get(root._sfc);
|
|
36
36
|
const scriptSetup = root._sfc.scriptSetup;
|
|
37
|
-
const scriptSetupRanges = codegen?.
|
|
37
|
+
const scriptSetupRanges = codegen?.getScriptSetupRanges();
|
|
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
|
}
|
|
@@ -88,7 +91,7 @@ function create(ts, getTsPluginClient) {
|
|
|
88
91
|
+ (lastImportNode ? '' : '\n'),
|
|
89
92
|
});
|
|
90
93
|
if (sfc.script) {
|
|
91
|
-
const edit = (0, vue_extract_file_1.createAddComponentToOptionEdit)(ts, sfc.script.ast, newName);
|
|
94
|
+
const edit = (0, vue_extract_file_1.createAddComponentToOptionEdit)(ts, sfc, sfc.script.ast, newName);
|
|
92
95
|
if (edit) {
|
|
93
96
|
additionalEdit.changes[embeddedDocumentUriStr].push({
|
|
94
97
|
range: {
|