@vue/language-service 1.9.0-alpha.2 → 2.0.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/template/en.json +2 -2
- package/data/template/fr.json +1 -1
- package/data/template/ja.json +2 -2
- package/data/template/ko.json +13 -13
- package/data/template/pt.json +18 -18
- package/data/template/zh-cn.json +3 -3
- package/package.json +18 -18
- package/out/helpers.d.ts +0 -17
- package/out/helpers.js +0 -235
- package/out/ideFeatures/dragImport.d.ts +0 -9
- package/out/ideFeatures/dragImport.js +0 -50
- package/out/ideFeatures/nameCasing.d.ts +0 -16
- package/out/ideFeatures/nameCasing.js +0 -158
- package/out/index.d.ts +0 -8
- package/out/index.js +0 -26
- package/out/languageService.d.ts +0 -9
- package/out/languageService.js +0 -239
- package/out/plugins/data.d.ts +0 -5
- package/out/plugins/data.js +0 -91
- package/out/plugins/vue-autoinsert-dotvalue.d.ts +0 -7
- package/out/plugins/vue-autoinsert-dotvalue.js +0 -161
- package/out/plugins/vue-autoinsert-parentheses.d.ts +0 -3
- package/out/plugins/vue-autoinsert-parentheses.js +0 -61
- package/out/plugins/vue-autoinsert-space.d.ts +0 -3
- package/out/plugins/vue-autoinsert-space.js +0 -32
- package/out/plugins/vue-codelens-references.d.ts +0 -3
- package/out/plugins/vue-codelens-references.js +0 -54
- package/out/plugins/vue-directive-comments.d.ts +0 -3
- package/out/plugins/vue-directive-comments.js +0 -57
- package/out/plugins/vue-extract-file.d.ts +0 -9
- package/out/plugins/vue-extract-file.js +0 -293
- package/out/plugins/vue-template.d.ts +0 -12
- package/out/plugins/vue-template.js +0 -548
- package/out/plugins/vue-toggle-v-bind-codeaction.d.ts +0 -3
- package/out/plugins/vue-toggle-v-bind-codeaction.js +0 -126
- package/out/plugins/vue-twoslash-queries.d.ts +0 -3
- package/out/plugins/vue-twoslash-queries.js +0 -60
- package/out/plugins/vue-visualize-hidden-callback-param.d.ts +0 -3
- package/out/plugins/vue-visualize-hidden-callback-param.js +0 -43
- package/out/plugins/vue.d.ts +0 -8
- package/out/plugins/vue.js +0 -169
- package/out/types.d.ts +0 -11
- package/out/types.js +0 -31
package/out/languageService.js
DELETED
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveConfig = void 0;
|
|
4
|
-
const language_core_1 = require("@vue/language-core");
|
|
5
|
-
const shared_1 = require("@vue/shared");
|
|
6
|
-
const nameCasing_1 = require("./ideFeatures/nameCasing");
|
|
7
|
-
const types_1 = require("./types");
|
|
8
|
-
// volar services
|
|
9
|
-
const CssService = require("volar-service-css");
|
|
10
|
-
const EmmetService = require("volar-service-emmet");
|
|
11
|
-
const HtmlService = require("volar-service-html");
|
|
12
|
-
const JsonService = require("volar-service-json");
|
|
13
|
-
const PugService = require("volar-service-pug");
|
|
14
|
-
const PugFormatService = require("volar-service-pug-beautify");
|
|
15
|
-
const TsService = require("volar-service-typescript");
|
|
16
|
-
const TsTqService = require("volar-service-typescript-twoslash-queries");
|
|
17
|
-
// our services
|
|
18
|
-
const VueService = require("./plugins/vue");
|
|
19
|
-
const AutoDotValueService = require("./plugins/vue-autoinsert-dotvalue");
|
|
20
|
-
const AutoWrapParenthesesService = require("./plugins/vue-autoinsert-parentheses");
|
|
21
|
-
const AutoAddSpaceService = require("./plugins/vue-autoinsert-space");
|
|
22
|
-
const ReferencesCodeLensService = require("./plugins/vue-codelens-references");
|
|
23
|
-
const DirectiveCommentsService = require("./plugins/vue-directive-comments");
|
|
24
|
-
const ExtractComponentService = require("./plugins/vue-extract-file");
|
|
25
|
-
const VueTemplateLanguageService = require("./plugins/vue-template");
|
|
26
|
-
const ToggleVBindService = require("./plugins/vue-toggle-v-bind-codeaction");
|
|
27
|
-
const VueTqService = require("./plugins/vue-twoslash-queries");
|
|
28
|
-
const VisualizeHiddenCallbackParamService = require("./plugins/vue-visualize-hidden-callback-param");
|
|
29
|
-
function resolveConfig(ts, config, compilerOptions = {}, vueCompilerOptions = {}, codegenStack = false) {
|
|
30
|
-
const resolvedVueCompilerOptions = (0, language_core_1.resolveVueCompilerOptions)(vueCompilerOptions);
|
|
31
|
-
const vueLanguageModules = (0, language_core_1.createLanguages)(ts, compilerOptions, resolvedVueCompilerOptions, codegenStack);
|
|
32
|
-
config.languages = Object.assign({}, vueLanguageModules, config.languages);
|
|
33
|
-
config.services = resolvePlugins(config.services, resolvedVueCompilerOptions);
|
|
34
|
-
return config;
|
|
35
|
-
}
|
|
36
|
-
exports.resolveConfig = resolveConfig;
|
|
37
|
-
function resolvePlugins(services, vueCompilerOptions) {
|
|
38
|
-
const originalTsPlugin = services?.typescript ?? TsService.create();
|
|
39
|
-
services ??= {};
|
|
40
|
-
services.typescript = (ctx, modules) => {
|
|
41
|
-
const base = typeof originalTsPlugin === 'function' ? originalTsPlugin(ctx, modules) : originalTsPlugin;
|
|
42
|
-
if (!ctx || !modules?.typescript)
|
|
43
|
-
return base;
|
|
44
|
-
const ts = modules.typescript;
|
|
45
|
-
return {
|
|
46
|
-
...base,
|
|
47
|
-
async provideCompletionItems(document, position, context, item) {
|
|
48
|
-
const result = await base.provideCompletionItems?.(document, position, context, item);
|
|
49
|
-
if (result) {
|
|
50
|
-
// filter __VLS_
|
|
51
|
-
result.items = result.items.filter(item => item.label.indexOf('__VLS_') === -1
|
|
52
|
-
&& (!item.labelDetails?.description || item.labelDetails.description.indexOf('__VLS_') === -1));
|
|
53
|
-
// handle component auto-import patch
|
|
54
|
-
let casing;
|
|
55
|
-
for (const [_, map] of ctx.documents.getMapsByVirtualFileUri(document.uri)) {
|
|
56
|
-
const virtualFile = ctx.documents.getSourceByUri(map.sourceFileDocument.uri)?.root;
|
|
57
|
-
if (virtualFile instanceof language_core_1.VueFile) {
|
|
58
|
-
const isAutoImport = !!map.toSourcePosition(position, data => typeof data.completion === 'object' && !!data.completion.autoImportOnly);
|
|
59
|
-
if (isAutoImport) {
|
|
60
|
-
const source = ctx.documents.getVirtualFileByUri(document.uri)[1];
|
|
61
|
-
for (const item of result.items) {
|
|
62
|
-
item.data.__isComponentAutoImport = true;
|
|
63
|
-
}
|
|
64
|
-
// fix #2458
|
|
65
|
-
if (source) {
|
|
66
|
-
casing ??= await (0, nameCasing_1.getNameCasing)(ts, ctx, ctx.env.fileNameToUri(source.fileName), vueCompilerOptions);
|
|
67
|
-
if (casing.tag === types_1.TagNameCasing.Kebab) {
|
|
68
|
-
for (const item of result.items) {
|
|
69
|
-
item.filterText = (0, language_core_1.hyphenateTag)(item.filterText ?? item.label);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return result;
|
|
78
|
-
},
|
|
79
|
-
async resolveCompletionItem(item, token) {
|
|
80
|
-
item = await base.resolveCompletionItem?.(item, token) ?? item;
|
|
81
|
-
const itemData = item.data;
|
|
82
|
-
let newName;
|
|
83
|
-
if (itemData?.uri && item.additionalTextEdits) {
|
|
84
|
-
patchAdditionalTextEdits(itemData.uri, item.additionalTextEdits);
|
|
85
|
-
}
|
|
86
|
-
for (const ext of vueCompilerOptions.extensions) {
|
|
87
|
-
const suffix = (0, shared_1.capitalize)(ext.substring('.'.length)); // .vue -> Vue
|
|
88
|
-
if (itemData?.uri
|
|
89
|
-
&& item.textEdit?.newText.endsWith(suffix)
|
|
90
|
-
&& item.additionalTextEdits?.length === 1 && item.additionalTextEdits[0].newText.indexOf('import ' + item.textEdit.newText + ' from ') >= 0
|
|
91
|
-
&& (await ctx.env.getConfiguration?.('vue.complete.normalizeComponentImportName') ?? true)) {
|
|
92
|
-
newName = item.textEdit.newText.slice(0, -suffix.length);
|
|
93
|
-
newName = newName[0].toUpperCase() + newName.substring(1);
|
|
94
|
-
if (newName === 'Index') {
|
|
95
|
-
const tsItem = item.data.originalItem;
|
|
96
|
-
if (tsItem.source) {
|
|
97
|
-
const dirs = tsItem.source.split('/');
|
|
98
|
-
if (dirs.length >= 3) {
|
|
99
|
-
newName = dirs[dirs.length - 2];
|
|
100
|
-
newName = newName[0].toUpperCase() + newName.substring(1);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
item.additionalTextEdits[0].newText = item.additionalTextEdits[0].newText.replace('import ' + item.textEdit.newText + ' from ', 'import ' + newName + ' from ');
|
|
105
|
-
item.textEdit.newText = newName;
|
|
106
|
-
const source = ctx.documents.getVirtualFileByUri(itemData.uri)[1];
|
|
107
|
-
if (source) {
|
|
108
|
-
const casing = await (0, nameCasing_1.getNameCasing)(ts, ctx, ctx.env.fileNameToUri(source.fileName), vueCompilerOptions);
|
|
109
|
-
if (casing.tag === types_1.TagNameCasing.Kebab) {
|
|
110
|
-
item.textEdit.newText = (0, language_core_1.hyphenateTag)(item.textEdit.newText);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
else if (item.textEdit?.newText && new RegExp(`import \\w*${suffix}\\$1 from [\\S\\s]*`).test(item.textEdit.newText)) {
|
|
115
|
-
// https://github.com/vuejs/language-tools/issues/2286
|
|
116
|
-
item.textEdit.newText = item.textEdit.newText.replace(`${suffix}$1`, '$1');
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
const data = item.data;
|
|
120
|
-
if (item.data?.__isComponentAutoImport && data && item.additionalTextEdits?.length && item.textEdit && itemData?.uri) {
|
|
121
|
-
const fileName = ctx.env.uriToFileName(itemData.uri);
|
|
122
|
-
const langaugeService = ctx.inject('typescript/languageService');
|
|
123
|
-
const [virtualFile] = ctx.virtualFiles.getVirtualFile(fileName);
|
|
124
|
-
const ast = langaugeService.getProgram()?.getSourceFile(fileName);
|
|
125
|
-
const exportDefault = ast ? language_core_1.scriptRanges.parseScriptRanges(ts, ast, false, true).exportDefault : undefined;
|
|
126
|
-
if (virtualFile && ast && exportDefault) {
|
|
127
|
-
const componentName = newName ?? item.textEdit.newText;
|
|
128
|
-
const optionEdit = ExtractComponentService.createAddComponentToOptionEdit(ts, ast, componentName);
|
|
129
|
-
if (optionEdit) {
|
|
130
|
-
const textDoc = ctx.documents.getDocumentByFileName(virtualFile.snapshot, virtualFile.fileName);
|
|
131
|
-
item.additionalTextEdits.push({
|
|
132
|
-
range: {
|
|
133
|
-
start: textDoc.positionAt(optionEdit.range.start),
|
|
134
|
-
end: textDoc.positionAt(optionEdit.range.end),
|
|
135
|
-
},
|
|
136
|
-
newText: optionEdit.newText,
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
return item;
|
|
142
|
-
},
|
|
143
|
-
async provideCodeActions(document, range, context, token) {
|
|
144
|
-
const result = await base.provideCodeActions?.(document, range, context, token);
|
|
145
|
-
return result?.filter(codeAction => codeAction.title.indexOf('__VLS_') === -1);
|
|
146
|
-
},
|
|
147
|
-
async resolveCodeAction(item, token) {
|
|
148
|
-
const result = await base.resolveCodeAction?.(item, token) ?? item;
|
|
149
|
-
if (result?.edit?.changes) {
|
|
150
|
-
for (const uri in result.edit.changes) {
|
|
151
|
-
const edits = result.edit.changes[uri];
|
|
152
|
-
if (edits) {
|
|
153
|
-
patchAdditionalTextEdits(uri, edits);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
if (result?.edit?.documentChanges) {
|
|
158
|
-
for (const documentChange of result.edit.documentChanges) {
|
|
159
|
-
if ('textDocument' in documentChange) {
|
|
160
|
-
patchAdditionalTextEdits(documentChange.textDocument.uri, documentChange.edits);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
return result;
|
|
165
|
-
},
|
|
166
|
-
async provideSemanticDiagnostics(document, token) {
|
|
167
|
-
const result = await base.provideSemanticDiagnostics?.(document, token);
|
|
168
|
-
return result?.map(diagnostic => {
|
|
169
|
-
if (diagnostic.source === 'ts'
|
|
170
|
-
&& diagnostic.code === 2578 /* Unused '@ts-expect-error' directive. */
|
|
171
|
-
&& document.getText(diagnostic.range) === '// @ts-expect-error __VLS_TS_EXPECT_ERROR') {
|
|
172
|
-
diagnostic.source = 'vue';
|
|
173
|
-
diagnostic.code = 'ts-2578';
|
|
174
|
-
diagnostic.message = diagnostic.message.replace(/@ts-expect-error/g, '@vue-expect-error');
|
|
175
|
-
}
|
|
176
|
-
return diagnostic;
|
|
177
|
-
});
|
|
178
|
-
},
|
|
179
|
-
};
|
|
180
|
-
};
|
|
181
|
-
services.html ??= VueTemplateLanguageService.create({
|
|
182
|
-
baseService: HtmlService.create(),
|
|
183
|
-
getScanner: (htmlService, document) => {
|
|
184
|
-
return htmlService.provide['html/languageService']().createScanner(document.getText());
|
|
185
|
-
},
|
|
186
|
-
updateCustomData(htmlService, extraData) {
|
|
187
|
-
htmlService.provide['html/updateCustomData'](extraData);
|
|
188
|
-
},
|
|
189
|
-
isSupportedDocument: (document) => document.languageId === 'html',
|
|
190
|
-
vueCompilerOptions,
|
|
191
|
-
});
|
|
192
|
-
services.pug ??= VueTemplateLanguageService.create({
|
|
193
|
-
baseService: PugService.create(),
|
|
194
|
-
getScanner: (pugService, document) => {
|
|
195
|
-
const pugDocument = pugService.provide['pug/pugDocument'](document);
|
|
196
|
-
if (pugDocument) {
|
|
197
|
-
return pugService.provide['pug/languageService']().createScanner(pugDocument);
|
|
198
|
-
}
|
|
199
|
-
},
|
|
200
|
-
updateCustomData(pugService, extraData) {
|
|
201
|
-
pugService.provide['pug/updateCustomData'](extraData);
|
|
202
|
-
},
|
|
203
|
-
isSupportedDocument: (document) => document.languageId === 'jade',
|
|
204
|
-
vueCompilerOptions,
|
|
205
|
-
});
|
|
206
|
-
services.vue ??= VueService.create();
|
|
207
|
-
services.css ??= CssService.create();
|
|
208
|
-
services['pug-beautify'] ??= PugFormatService.create();
|
|
209
|
-
services.json ??= JsonService.create();
|
|
210
|
-
services['typescript/twoslash-queries'] ??= TsTqService.create();
|
|
211
|
-
services['vue/referencesCodeLens'] ??= ReferencesCodeLensService.create();
|
|
212
|
-
services['vue/autoInsertDotValue'] ??= AutoDotValueService.create();
|
|
213
|
-
services['vue/twoslash-queries'] ??= VueTqService.create();
|
|
214
|
-
services['vue/autoInsertParentheses'] ??= AutoWrapParenthesesService.create();
|
|
215
|
-
services['vue/autoInsertSpaces'] ??= AutoAddSpaceService.create();
|
|
216
|
-
services['vue/visualizeHiddenCallbackParam'] ??= VisualizeHiddenCallbackParamService.create();
|
|
217
|
-
services['vue/directiveComments'] ??= DirectiveCommentsService.create();
|
|
218
|
-
services['vue/extractComponent'] ??= ExtractComponentService.create();
|
|
219
|
-
services['vue/toggleVBind'] ??= ToggleVBindService.create();
|
|
220
|
-
services.emmet ??= EmmetService.create();
|
|
221
|
-
return services;
|
|
222
|
-
}
|
|
223
|
-
// fix https://github.com/vuejs/language-tools/issues/916
|
|
224
|
-
function patchAdditionalTextEdits(uri, edits) {
|
|
225
|
-
if (uri.endsWith('.vue.js')
|
|
226
|
-
|| uri.endsWith('.vue.ts')
|
|
227
|
-
|| uri.endsWith('.vue.jsx')
|
|
228
|
-
|| uri.endsWith('.vue.tsx')) {
|
|
229
|
-
for (const edit of edits) {
|
|
230
|
-
if (edit.range.start.line === 0
|
|
231
|
-
&& edit.range.start.character === 0
|
|
232
|
-
&& edit.range.end.line === 0
|
|
233
|
-
&& edit.range.end.character === 0) {
|
|
234
|
-
edit.newText = '\n' + edit.newText;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
//# sourceMappingURL=languageService.js.map
|
package/out/plugins/data.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import * as html from 'vscode-html-languageservice';
|
|
2
|
-
export declare function loadTemplateData(lang: string): html.HTMLDataV1;
|
|
3
|
-
export declare function loadLanguageBlocks(lang: string): html.HTMLDataV1;
|
|
4
|
-
export declare function loadModelModifiersData(lang: string): html.HTMLDataV1;
|
|
5
|
-
//# sourceMappingURL=data.d.ts.map
|
package/out/plugins/data.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadModelModifiersData = exports.loadLanguageBlocks = exports.loadTemplateData = void 0;
|
|
4
|
-
function loadTemplateData(lang) {
|
|
5
|
-
lang = lang.toLowerCase();
|
|
6
|
-
let data;
|
|
7
|
-
if (lang === 'ja') {
|
|
8
|
-
data = require('../../data/template/ja.json');
|
|
9
|
-
}
|
|
10
|
-
else if (lang === 'fr') {
|
|
11
|
-
data = require('../../data/template/fr.json');
|
|
12
|
-
}
|
|
13
|
-
else if (lang === 'ko') {
|
|
14
|
-
data = require('../../data/template/ko.json');
|
|
15
|
-
}
|
|
16
|
-
else if (lang === 'pt-br') {
|
|
17
|
-
data = require('../../data/template/pt.json');
|
|
18
|
-
}
|
|
19
|
-
else if (lang === 'zh-cn') {
|
|
20
|
-
data = require('../../data/template/zh-cn.json');
|
|
21
|
-
}
|
|
22
|
-
else if (lang === 'it') {
|
|
23
|
-
data = require('../../data/template/it.json');
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
data = require('../../data/template/en.json');
|
|
27
|
-
}
|
|
28
|
-
for (const attr of [...data.globalAttributes ?? []]) {
|
|
29
|
-
if (!attr.name.startsWith('v-')) {
|
|
30
|
-
data.globalAttributes?.push({ ...attr, name: `:${attr.name}` });
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
const vOn = data.globalAttributes?.find(d => d.name === 'v-on');
|
|
34
|
-
const vSlot = data.globalAttributes?.find(d => d.name === 'v-slot');
|
|
35
|
-
const vBind = data.globalAttributes?.find(d => d.name === 'v-bind');
|
|
36
|
-
if (vOn)
|
|
37
|
-
data.globalAttributes?.push({ ...vOn, name: '@' });
|
|
38
|
-
if (vSlot)
|
|
39
|
-
data.globalAttributes?.push({ ...vSlot, name: '#' });
|
|
40
|
-
if (vBind)
|
|
41
|
-
data.globalAttributes?.push({ ...vBind, name: ':' });
|
|
42
|
-
return data;
|
|
43
|
-
}
|
|
44
|
-
exports.loadTemplateData = loadTemplateData;
|
|
45
|
-
function loadLanguageBlocks(lang) {
|
|
46
|
-
lang = lang.toLowerCase();
|
|
47
|
-
if (lang === 'ja') {
|
|
48
|
-
return require('../../data/language-blocks/ja.json');
|
|
49
|
-
}
|
|
50
|
-
else if (lang === 'fr') {
|
|
51
|
-
return require('../../data/language-blocks/fr.json');
|
|
52
|
-
}
|
|
53
|
-
else if (lang === 'ko') {
|
|
54
|
-
return require('../../data/language-blocks/ko.json');
|
|
55
|
-
}
|
|
56
|
-
else if (lang === 'pt-br') {
|
|
57
|
-
return require('../../data/language-blocks/pt.json');
|
|
58
|
-
}
|
|
59
|
-
else if (lang === 'zh-cn') {
|
|
60
|
-
return require('../../data/language-blocks/zh-cn.json');
|
|
61
|
-
}
|
|
62
|
-
else if (lang === 'it') {
|
|
63
|
-
return require('../../data/language-blocks/it.json');
|
|
64
|
-
}
|
|
65
|
-
return require('../../data/language-blocks/en.json');
|
|
66
|
-
}
|
|
67
|
-
exports.loadLanguageBlocks = loadLanguageBlocks;
|
|
68
|
-
function loadModelModifiersData(lang) {
|
|
69
|
-
lang = lang.toLowerCase();
|
|
70
|
-
if (lang === 'ja') {
|
|
71
|
-
return require('../../data/model-modifiers/ja.json');
|
|
72
|
-
}
|
|
73
|
-
else if (lang === 'fr') {
|
|
74
|
-
return require('../../data/model-modifiers/fr.json');
|
|
75
|
-
}
|
|
76
|
-
else if (lang === 'ko') {
|
|
77
|
-
return require('../../data/model-modifiers/ko.json');
|
|
78
|
-
}
|
|
79
|
-
else if (lang === 'pt-br') {
|
|
80
|
-
return require('../../data/model-modifiers/pt.json');
|
|
81
|
-
}
|
|
82
|
-
else if (lang === 'zh-cn') {
|
|
83
|
-
return require('../../data/model-modifiers/zh-cn.json');
|
|
84
|
-
}
|
|
85
|
-
else if (lang === 'it') {
|
|
86
|
-
return require('../../data/model-modifiers/it.json');
|
|
87
|
-
}
|
|
88
|
-
return require('../../data/model-modifiers/en.json');
|
|
89
|
-
}
|
|
90
|
-
exports.loadModelModifiersData = loadModelModifiersData;
|
|
91
|
-
//# sourceMappingURL=data.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { AutoInsertionContext, Service } from '@volar/language-service';
|
|
2
|
-
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
3
|
-
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
4
|
-
export declare const create: () => Service;
|
|
5
|
-
export declare function isCharacterTyping(document: TextDocument, options: AutoInsertionContext): boolean;
|
|
6
|
-
export declare function isBlacklistNode(ts: typeof import('typescript/lib/tsserverlibrary'), node: ts.Node, pos: number, allowAccessDotValue: boolean): boolean;
|
|
7
|
-
//# sourceMappingURL=vue-autoinsert-dotvalue.d.ts.map
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isBlacklistNode = exports.isCharacterTyping = exports.create = void 0;
|
|
4
|
-
const language_core_1 = require("@vue/language-core");
|
|
5
|
-
const plugin = (context, modules) => {
|
|
6
|
-
if (!modules?.typescript)
|
|
7
|
-
return {};
|
|
8
|
-
const ts = modules.typescript;
|
|
9
|
-
return {
|
|
10
|
-
async provideAutoInsertionEdit(document, position, insertContext) {
|
|
11
|
-
if (!isTsDocument(document))
|
|
12
|
-
return;
|
|
13
|
-
if (!isCharacterTyping(document, insertContext))
|
|
14
|
-
return;
|
|
15
|
-
const enabled = await context.env.getConfiguration?.('vue.autoInsert.dotValue') ?? true;
|
|
16
|
-
if (!enabled)
|
|
17
|
-
return;
|
|
18
|
-
const program = context.inject('typescript/languageService').getProgram();
|
|
19
|
-
if (!program)
|
|
20
|
-
return;
|
|
21
|
-
const sourceFile = program.getSourceFile(context.env.uriToFileName(document.uri));
|
|
22
|
-
if (!sourceFile)
|
|
23
|
-
return;
|
|
24
|
-
if (isBlacklistNode(ts, sourceFile, document.offsetAt(position), false))
|
|
25
|
-
return;
|
|
26
|
-
const node = findPositionIdentifier(sourceFile, sourceFile, document.offsetAt(position));
|
|
27
|
-
if (!node)
|
|
28
|
-
return;
|
|
29
|
-
const token = context.inject('typescript/languageServiceHost').getCancellationToken?.();
|
|
30
|
-
if (token) {
|
|
31
|
-
context.inject('typescript/languageService').getQuickInfoAtPosition(context.env.uriToFileName(document.uri), node.end);
|
|
32
|
-
if (token?.isCancellationRequested()) {
|
|
33
|
-
return; // check cancel here because type checker do not use cancel token
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
const checker = program.getTypeChecker();
|
|
37
|
-
const type = checker.getTypeAtLocation(node);
|
|
38
|
-
const props = type.getProperties();
|
|
39
|
-
if (props.some(prop => prop.name === 'value')) {
|
|
40
|
-
return '${1:.value}';
|
|
41
|
-
}
|
|
42
|
-
function findPositionIdentifier(sourceFile, node, offset) {
|
|
43
|
-
let result;
|
|
44
|
-
node.forEachChild(child => {
|
|
45
|
-
if (!result) {
|
|
46
|
-
if (child.end === offset && ts.isIdentifier(child)) {
|
|
47
|
-
result = child;
|
|
48
|
-
}
|
|
49
|
-
else if (child.end >= offset && child.getStart(sourceFile) < offset) {
|
|
50
|
-
result = findPositionIdentifier(sourceFile, child, offset);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
return result;
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
const create = () => plugin;
|
|
60
|
-
exports.create = create;
|
|
61
|
-
function isTsDocument(document) {
|
|
62
|
-
return document.languageId === 'javascript' ||
|
|
63
|
-
document.languageId === 'typescript' ||
|
|
64
|
-
document.languageId === 'javascriptreact' ||
|
|
65
|
-
document.languageId === 'typescriptreact';
|
|
66
|
-
}
|
|
67
|
-
const charReg = /\w/;
|
|
68
|
-
function isCharacterTyping(document, options) {
|
|
69
|
-
const lastCharacter = options.lastChange.text[options.lastChange.text.length - 1];
|
|
70
|
-
const rangeStart = options.lastChange.range.start;
|
|
71
|
-
const position = {
|
|
72
|
-
line: rangeStart.line,
|
|
73
|
-
character: rangeStart.character + options.lastChange.text.length,
|
|
74
|
-
};
|
|
75
|
-
const nextCharacter = document.getText({
|
|
76
|
-
start: position,
|
|
77
|
-
end: { line: position.line, character: position.character + 1 },
|
|
78
|
-
});
|
|
79
|
-
if (lastCharacter === undefined) { // delete text
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
if (options.lastChange.text.indexOf('\n') >= 0) { // multi-line change
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
return charReg.test(lastCharacter) && !charReg.test(nextCharacter);
|
|
86
|
-
}
|
|
87
|
-
exports.isCharacterTyping = isCharacterTyping;
|
|
88
|
-
function isBlacklistNode(ts, node, pos, allowAccessDotValue) {
|
|
89
|
-
if (ts.isVariableDeclaration(node) && pos >= node.name.getFullStart() && pos <= node.name.getEnd()) {
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
else if (ts.isFunctionDeclaration(node) && node.name && pos >= node.name.getFullStart() && pos <= node.name.getEnd()) {
|
|
93
|
-
return true;
|
|
94
|
-
}
|
|
95
|
-
else if (ts.isParameter(node) && pos >= node.name.getFullStart() && pos <= node.name.getEnd()) {
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
else if (ts.isPropertyAssignment(node) && pos >= node.name.getFullStart() && pos <= node.name.getEnd()) {
|
|
99
|
-
return true;
|
|
100
|
-
}
|
|
101
|
-
else if (ts.isShorthandPropertyAssignment(node)) {
|
|
102
|
-
return true;
|
|
103
|
-
}
|
|
104
|
-
else if (ts.isImportDeclaration(node)) {
|
|
105
|
-
return true;
|
|
106
|
-
}
|
|
107
|
-
else if (ts.isLiteralTypeNode(node)) {
|
|
108
|
-
return true;
|
|
109
|
-
}
|
|
110
|
-
else if (ts.isTypeReferenceNode(node)) {
|
|
111
|
-
return true;
|
|
112
|
-
}
|
|
113
|
-
else if (!allowAccessDotValue && ts.isPropertyAccessExpression(node) && node.expression.end === pos && node.name.text === 'value') {
|
|
114
|
-
return true;
|
|
115
|
-
}
|
|
116
|
-
else if (ts.isCallExpression(node)
|
|
117
|
-
&& ts.isIdentifier(node.expression)
|
|
118
|
-
&& isWatchOrUseFunction(node.expression.text)
|
|
119
|
-
&& isTopLevelArgOrArrayTopLevelItemItem(node)) {
|
|
120
|
-
return true;
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
let _isBlacklistNode = false;
|
|
124
|
-
node.forEachChild(node => {
|
|
125
|
-
if (_isBlacklistNode)
|
|
126
|
-
return;
|
|
127
|
-
if (pos >= node.getFullStart() && pos <= node.getEnd()) {
|
|
128
|
-
if (isBlacklistNode(ts, node, pos, allowAccessDotValue)) {
|
|
129
|
-
_isBlacklistNode = true;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
return _isBlacklistNode;
|
|
134
|
-
}
|
|
135
|
-
function isWatchOrUseFunction(fnName) {
|
|
136
|
-
return fnName === 'watch'
|
|
137
|
-
|| fnName === 'unref'
|
|
138
|
-
|| fnName === 'triggerRef'
|
|
139
|
-
|| fnName === 'isRef'
|
|
140
|
-
|| (0, language_core_1.hyphenateAttr)(fnName).startsWith('use-');
|
|
141
|
-
}
|
|
142
|
-
function isTopLevelArgOrArrayTopLevelItemItem(node) {
|
|
143
|
-
for (const arg of node.arguments) {
|
|
144
|
-
if (pos >= arg.getFullStart() && pos <= arg.getEnd()) {
|
|
145
|
-
if (ts.isIdentifier(arg)) {
|
|
146
|
-
return true;
|
|
147
|
-
}
|
|
148
|
-
if (ts.isArrayLiteralExpression(arg)) {
|
|
149
|
-
for (const el of arg.elements) {
|
|
150
|
-
if (pos >= el.getFullStart() && pos <= el.getEnd()) {
|
|
151
|
-
return ts.isIdentifier(el);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return false;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
exports.isBlacklistNode = isBlacklistNode;
|
|
161
|
-
//# sourceMappingURL=vue-autoinsert-dotvalue.js.map
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.create = void 0;
|
|
4
|
-
const vue_autoinsert_dotvalue_1 = require("./vue-autoinsert-dotvalue");
|
|
5
|
-
const plugin = (context, modules) => {
|
|
6
|
-
if (!context) {
|
|
7
|
-
return {};
|
|
8
|
-
}
|
|
9
|
-
if (!modules?.typescript) {
|
|
10
|
-
return {};
|
|
11
|
-
}
|
|
12
|
-
const ts = modules.typescript;
|
|
13
|
-
return {
|
|
14
|
-
async provideAutoInsertionEdit(document, position, options_2) {
|
|
15
|
-
const enabled = await context.env.getConfiguration?.('vue.autoInsert.parentheses') ?? false;
|
|
16
|
-
if (!enabled)
|
|
17
|
-
return;
|
|
18
|
-
if (!(0, vue_autoinsert_dotvalue_1.isCharacterTyping)(document, options_2))
|
|
19
|
-
return;
|
|
20
|
-
const [virtualFile] = context.documents.getVirtualFileByUri(document.uri);
|
|
21
|
-
if (!virtualFile?.fileName.endsWith('.template_format.ts'))
|
|
22
|
-
return;
|
|
23
|
-
const offset = document.offsetAt(position);
|
|
24
|
-
for (const mappedRange of virtualFile.mappings) {
|
|
25
|
-
if (mappedRange.generatedRange[1] === offset) {
|
|
26
|
-
const text = document.getText().substring(mappedRange.generatedRange[0], mappedRange.generatedRange[1]);
|
|
27
|
-
const ast = ts.createSourceFile(virtualFile.fileName, text, ts.ScriptTarget.Latest);
|
|
28
|
-
if (ast.statements.length === 1) {
|
|
29
|
-
const statement = ast.statements[0];
|
|
30
|
-
if (ts.isExpressionStatement(statement)
|
|
31
|
-
&& ((ts.isAsExpression(statement.expression)
|
|
32
|
-
&& ts.isTypeReferenceNode(statement.expression.type)
|
|
33
|
-
&& ts.isIdentifier(statement.expression.type.typeName)
|
|
34
|
-
&& statement.expression.type.typeName.text)
|
|
35
|
-
|| (ts.isBinaryExpression(statement.expression)
|
|
36
|
-
&& statement.expression.right.getText(ast)
|
|
37
|
-
&& statement.expression.operatorToken.kind === ts.SyntaxKind.InstanceOfKeyword)
|
|
38
|
-
|| (ts.isTypeOfExpression(statement.expression)
|
|
39
|
-
&& statement.expression.expression.getText(ast)))) {
|
|
40
|
-
// https://code.visualstudio.com/docs/editor/userdefinedsnippets#_grammar
|
|
41
|
-
const escapedText = text
|
|
42
|
-
.replaceAll('\\', '\\\\')
|
|
43
|
-
.replaceAll('$', '\\$')
|
|
44
|
-
.replaceAll('}', '\\}');
|
|
45
|
-
return {
|
|
46
|
-
range: {
|
|
47
|
-
start: document.positionAt(mappedRange.generatedRange[0]),
|
|
48
|
-
end: document.positionAt(mappedRange.generatedRange[1]),
|
|
49
|
-
},
|
|
50
|
-
newText: '(' + escapedText + '$0' + ')',
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
const create = () => plugin;
|
|
60
|
-
exports.create = create;
|
|
61
|
-
//# sourceMappingURL=vue-autoinsert-parentheses.js.map
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.create = void 0;
|
|
4
|
-
const plugin = (context) => {
|
|
5
|
-
if (!context)
|
|
6
|
-
return {};
|
|
7
|
-
return {
|
|
8
|
-
async provideAutoInsertionEdit(document, _, { lastChange }) {
|
|
9
|
-
if (document.languageId === 'html' || document.languageId === 'jade') {
|
|
10
|
-
const enabled = await context.env.getConfiguration?.('vue.autoInsert.bracketSpacing') ?? true;
|
|
11
|
-
if (!enabled)
|
|
12
|
-
return;
|
|
13
|
-
if (lastChange.text === '{}'
|
|
14
|
-
&& document.getText({
|
|
15
|
-
start: { line: lastChange.range.start.line, character: lastChange.range.start.character - 1 },
|
|
16
|
-
end: { line: lastChange.range.start.line, character: lastChange.range.start.character + 3 }
|
|
17
|
-
}) === '{{}}') {
|
|
18
|
-
return {
|
|
19
|
-
newText: ` $0 `,
|
|
20
|
-
range: {
|
|
21
|
-
start: { line: lastChange.range.start.line, character: lastChange.range.start.character + 1 },
|
|
22
|
-
end: { line: lastChange.range.start.line, character: lastChange.range.start.character + 1 }
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
const create = () => plugin;
|
|
31
|
-
exports.create = create;
|
|
32
|
-
//# sourceMappingURL=vue-autoinsert-space.js.map
|