@vue/language-service 3.0.0 → 3.0.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/index.d.ts +1 -2
- package/index.js +24 -28
- package/lib/plugins/typescript-semantic-tokens.d.ts +2 -0
- package/lib/plugins/typescript-semantic-tokens.js +68 -0
- package/lib/plugins/vue-component-semantic-tokens.d.ts +2 -0
- package/lib/plugins/vue-component-semantic-tokens.js +92 -0
- package/lib/plugins/vue-diagnostic-global-types.d.ts +1 -0
- package/lib/plugins/vue-diagnostic-global-types.js +3 -0
- package/lib/plugins/vue-global-types-error.d.ts +2 -0
- package/lib/plugins/vue-global-types-error.js +37 -0
- package/lib/plugins/vue-suggest-define-assignment.d.ts +2 -0
- package/lib/plugins/vue-suggest-define-assignment.js +84 -0
- package/lib/plugins/vue-twoslash-queries.js +7 -3
- package/package.json +14 -15
package/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export * from '@volar/language-service';
|
|
2
2
|
export * from '@volar/language-service/lib/utils/featureWorkers';
|
|
3
|
-
import type { LanguageServicePlugin } from '@volar/language-service';
|
|
4
3
|
import type { VueCompilerOptions } from '@vue/language-core';
|
|
5
4
|
import type * as ts from 'typescript';
|
|
6
5
|
declare module '@volar/language-service' {
|
|
@@ -12,4 +11,4 @@ declare module '@volar/language-service' {
|
|
|
12
11
|
}
|
|
13
12
|
export declare function createVueLanguageServicePlugins(ts: typeof import('typescript'), tsPluginClient: (import('@vue/typescript-plugin/lib/requests').Requests & {
|
|
14
13
|
getDocumentHighlights: (fileName: string, position: number) => Promise<ts.DocumentHighlights[] | null>;
|
|
15
|
-
}) | undefined): LanguageServicePlugin<any>[];
|
|
14
|
+
}) | undefined): import("@volar/language-service").LanguageServicePlugin<any>[];
|
package/index.js
CHANGED
|
@@ -22,59 +22,51 @@ __exportStar(require("@volar/language-service/lib/utils/featureWorkers"), export
|
|
|
22
22
|
const volar_service_emmet_1 = require("volar-service-emmet");
|
|
23
23
|
const volar_service_json_1 = require("volar-service-json");
|
|
24
24
|
const volar_service_pug_beautify_1 = require("volar-service-pug-beautify");
|
|
25
|
-
const volar_service_typescript_twoslash_queries_1 = require("volar-service-typescript-twoslash-queries");
|
|
26
25
|
const docCommentTemplate_1 = require("volar-service-typescript/lib/plugins/docCommentTemplate");
|
|
27
26
|
const syntactic_1 = require("volar-service-typescript/lib/plugins/syntactic");
|
|
28
27
|
const css_1 = require("./lib/plugins/css");
|
|
28
|
+
const typescript_semantic_tokens_1 = require("./lib/plugins/typescript-semantic-tokens");
|
|
29
29
|
const vue_autoinsert_dotvalue_1 = require("./lib/plugins/vue-autoinsert-dotvalue");
|
|
30
30
|
const vue_autoinsert_space_1 = require("./lib/plugins/vue-autoinsert-space");
|
|
31
31
|
const vue_compiler_dom_errors_1 = require("./lib/plugins/vue-compiler-dom-errors");
|
|
32
|
-
const
|
|
32
|
+
const vue_component_semantic_tokens_1 = require("./lib/plugins/vue-component-semantic-tokens");
|
|
33
33
|
const vue_directive_comments_1 = require("./lib/plugins/vue-directive-comments");
|
|
34
34
|
const vue_document_drop_1 = require("./lib/plugins/vue-document-drop");
|
|
35
35
|
const vue_document_highlights_1 = require("./lib/plugins/vue-document-highlights");
|
|
36
36
|
const vue_document_links_1 = require("./lib/plugins/vue-document-links");
|
|
37
37
|
const vue_extract_file_1 = require("./lib/plugins/vue-extract-file");
|
|
38
|
+
const vue_global_types_error_1 = require("./lib/plugins/vue-global-types-error");
|
|
38
39
|
const vue_inlayhints_1 = require("./lib/plugins/vue-inlayhints");
|
|
39
40
|
const vue_missing_props_hints_1 = require("./lib/plugins/vue-missing-props-hints");
|
|
40
41
|
const vue_sfc_1 = require("./lib/plugins/vue-sfc");
|
|
42
|
+
const vue_suggest_define_assignment_1 = require("./lib/plugins/vue-suggest-define-assignment");
|
|
41
43
|
const vue_template_1 = require("./lib/plugins/vue-template");
|
|
42
44
|
const vue_twoslash_queries_1 = require("./lib/plugins/vue-twoslash-queries");
|
|
43
45
|
function createVueLanguageServicePlugins(ts, tsPluginClient) {
|
|
46
|
+
const getTsPluginClient = () => tsPluginClient;
|
|
44
47
|
const plugins = [
|
|
45
|
-
(0, syntactic_1.create)(ts),
|
|
46
|
-
(0, docCommentTemplate_1.create)(ts),
|
|
47
|
-
...getCommonLanguageServicePlugins(ts, () => tsPluginClient),
|
|
48
|
-
];
|
|
49
|
-
if (tsPluginClient) {
|
|
50
|
-
plugins.push((0, vue_document_highlights_1.create)(tsPluginClient.getDocumentHighlights));
|
|
51
|
-
}
|
|
52
|
-
for (const plugin of plugins) {
|
|
53
|
-
// avoid affecting TS plugin
|
|
54
|
-
delete plugin.capabilities.semanticTokensProvider;
|
|
55
|
-
}
|
|
56
|
-
return plugins;
|
|
57
|
-
}
|
|
58
|
-
function getCommonLanguageServicePlugins(ts, getTsPluginClient) {
|
|
59
|
-
return [
|
|
60
|
-
(0, volar_service_typescript_twoslash_queries_1.create)(ts),
|
|
61
48
|
(0, css_1.create)(),
|
|
62
|
-
(0, volar_service_pug_beautify_1.create)(),
|
|
63
49
|
(0, volar_service_json_1.create)(),
|
|
64
|
-
(0,
|
|
65
|
-
(0,
|
|
66
|
-
(0,
|
|
50
|
+
(0, volar_service_pug_beautify_1.create)(),
|
|
51
|
+
(0, docCommentTemplate_1.create)(ts),
|
|
52
|
+
(0, typescript_semantic_tokens_1.create)(getTsPluginClient),
|
|
53
|
+
(0, syntactic_1.create)(ts),
|
|
54
|
+
(0, vue_autoinsert_space_1.create)(),
|
|
55
|
+
(0, vue_autoinsert_dotvalue_1.create)(ts, getTsPluginClient),
|
|
67
56
|
(0, vue_compiler_dom_errors_1.create)(),
|
|
68
|
-
(0,
|
|
69
|
-
(0, vue_twoslash_queries_1.create)(getTsPluginClient),
|
|
57
|
+
(0, vue_component_semantic_tokens_1.create)(getTsPluginClient),
|
|
70
58
|
(0, vue_document_drop_1.create)(ts, getTsPluginClient),
|
|
71
59
|
(0, vue_document_links_1.create)(),
|
|
72
|
-
(0, vue_complete_define_assignment_1.create)(),
|
|
73
|
-
(0, vue_autoinsert_dotvalue_1.create)(ts, getTsPluginClient),
|
|
74
|
-
(0, vue_autoinsert_space_1.create)(),
|
|
75
|
-
(0, vue_inlayhints_1.create)(ts),
|
|
76
60
|
(0, vue_directive_comments_1.create)(),
|
|
77
61
|
(0, vue_extract_file_1.create)(ts, getTsPluginClient),
|
|
62
|
+
(0, vue_global_types_error_1.create)(),
|
|
63
|
+
(0, vue_inlayhints_1.create)(ts),
|
|
64
|
+
(0, vue_missing_props_hints_1.create)(getTsPluginClient),
|
|
65
|
+
(0, vue_sfc_1.create)(),
|
|
66
|
+
(0, vue_suggest_define_assignment_1.create)(),
|
|
67
|
+
(0, vue_template_1.create)('html', getTsPluginClient),
|
|
68
|
+
(0, vue_template_1.create)('pug', getTsPluginClient),
|
|
69
|
+
(0, vue_twoslash_queries_1.create)(getTsPluginClient),
|
|
78
70
|
(0, volar_service_emmet_1.create)({
|
|
79
71
|
mappedLanguages: {
|
|
80
72
|
'vue-root-tags': 'html',
|
|
@@ -82,5 +74,9 @@ function getCommonLanguageServicePlugins(ts, getTsPluginClient) {
|
|
|
82
74
|
},
|
|
83
75
|
}),
|
|
84
76
|
];
|
|
77
|
+
if (tsPluginClient) {
|
|
78
|
+
plugins.push((0, vue_document_highlights_1.create)(tsPluginClient.getDocumentHighlights));
|
|
79
|
+
}
|
|
80
|
+
return plugins;
|
|
85
81
|
}
|
|
86
82
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,68 @@
|
|
|
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 semanticTokens_1 = require("volar-service-typescript/lib/semanticFeatures/semanticTokens");
|
|
6
|
+
const vscode_uri_1 = require("vscode-uri");
|
|
7
|
+
function create(getTsPluginClient) {
|
|
8
|
+
return {
|
|
9
|
+
name: 'typescript-highlights',
|
|
10
|
+
capabilities: {
|
|
11
|
+
semanticTokensProvider: {
|
|
12
|
+
legend: {
|
|
13
|
+
tokenTypes: [
|
|
14
|
+
'namespace',
|
|
15
|
+
'class',
|
|
16
|
+
'enum',
|
|
17
|
+
'interface',
|
|
18
|
+
'typeParameter',
|
|
19
|
+
'type',
|
|
20
|
+
'parameter',
|
|
21
|
+
'variable',
|
|
22
|
+
'property',
|
|
23
|
+
'enumMember',
|
|
24
|
+
'function',
|
|
25
|
+
'method',
|
|
26
|
+
],
|
|
27
|
+
tokenModifiers: [
|
|
28
|
+
'declaration',
|
|
29
|
+
'readonly',
|
|
30
|
+
'static',
|
|
31
|
+
'async',
|
|
32
|
+
'defaultLibrary',
|
|
33
|
+
'local',
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
create(context) {
|
|
39
|
+
const tsPluginClient = getTsPluginClient?.(context);
|
|
40
|
+
return {
|
|
41
|
+
async provideDocumentSemanticTokens(document, range, legend) {
|
|
42
|
+
const uri = vscode_uri_1.URI.parse(document.uri);
|
|
43
|
+
const decoded = context.decodeEmbeddedDocumentUri(uri);
|
|
44
|
+
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
45
|
+
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
46
|
+
if (!sourceScript?.generated || virtualCode?.id !== 'main') {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const root = sourceScript.generated.root;
|
|
50
|
+
if (!(root instanceof language_core_1.VueVirtualCode)) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const start = document.offsetAt(range.start);
|
|
54
|
+
const end = document.offsetAt(range.end);
|
|
55
|
+
const span = {
|
|
56
|
+
start: start,
|
|
57
|
+
length: end - start,
|
|
58
|
+
};
|
|
59
|
+
const classifications = await tsPluginClient?.getEncodedSemanticClassifications(root.fileName, span);
|
|
60
|
+
if (classifications) {
|
|
61
|
+
return (0, semanticTokens_1.convertClassificationsToSemanticTokens)(document, span, legend, classifications);
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=typescript-semantic-tokens.js.map
|
|
@@ -0,0 +1,92 @@
|
|
|
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
|
+
function create(getTsPluginClient) {
|
|
7
|
+
return {
|
|
8
|
+
name: 'vue-component-highlights',
|
|
9
|
+
capabilities: {
|
|
10
|
+
semanticTokensProvider: {
|
|
11
|
+
legend: {
|
|
12
|
+
tokenTypes: ['component'],
|
|
13
|
+
tokenModifiers: [],
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
create(context) {
|
|
18
|
+
const tsPluginClient = getTsPluginClient?.(context);
|
|
19
|
+
return {
|
|
20
|
+
async provideDocumentSemanticTokens(document, range, legend) {
|
|
21
|
+
const uri = vscode_uri_1.URI.parse(document.uri);
|
|
22
|
+
const decoded = context.decodeEmbeddedDocumentUri(uri);
|
|
23
|
+
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
24
|
+
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
25
|
+
if (!sourceScript?.generated || virtualCode?.id !== 'template') {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const root = sourceScript.generated.root;
|
|
29
|
+
if (!(root instanceof language_core_1.VueVirtualCode)) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const { template } = root.sfc;
|
|
33
|
+
if (!template) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const result = [];
|
|
37
|
+
const tokenTypes = legend.tokenTypes.indexOf('component');
|
|
38
|
+
const componentSpans = await getComponentSpans(root.fileName, template, {
|
|
39
|
+
start: document.offsetAt(range.start),
|
|
40
|
+
length: document.offsetAt(range.end) - document.offsetAt(range.start),
|
|
41
|
+
});
|
|
42
|
+
for (const span of componentSpans) {
|
|
43
|
+
const position = document.positionAt(span.start);
|
|
44
|
+
result.push([
|
|
45
|
+
position.line,
|
|
46
|
+
position.character,
|
|
47
|
+
span.length,
|
|
48
|
+
tokenTypes,
|
|
49
|
+
0,
|
|
50
|
+
]);
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
async function getComponentSpans(fileName, template, spanTemplateRange) {
|
|
56
|
+
const result = [];
|
|
57
|
+
const validComponentNames = await tsPluginClient?.getComponentNames(fileName) ?? [];
|
|
58
|
+
const elements = new Set(await tsPluginClient?.getElementNames(fileName) ?? []);
|
|
59
|
+
const components = new Set([
|
|
60
|
+
...validComponentNames,
|
|
61
|
+
...validComponentNames.map(language_core_1.hyphenateTag),
|
|
62
|
+
]);
|
|
63
|
+
if (template.ast) {
|
|
64
|
+
for (const node of (0, language_core_1.forEachElementNode)(template.ast)) {
|
|
65
|
+
if (node.loc.end.offset <= spanTemplateRange.start
|
|
66
|
+
|| node.loc.start.offset >= (spanTemplateRange.start + spanTemplateRange.length)) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (components.has(node.tag) && !elements.has(node.tag)) {
|
|
70
|
+
let start = node.loc.start.offset;
|
|
71
|
+
if (template.lang === 'html') {
|
|
72
|
+
start += '<'.length;
|
|
73
|
+
}
|
|
74
|
+
result.push({
|
|
75
|
+
start,
|
|
76
|
+
length: node.tag.length,
|
|
77
|
+
});
|
|
78
|
+
if (template.lang === 'html' && !node.isSelfClosing) {
|
|
79
|
+
result.push({
|
|
80
|
+
start: node.loc.start.offset + node.loc.source.lastIndexOf(node.tag),
|
|
81
|
+
length: node.tag.length,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=vue-component-semantic-tokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.create = create;
|
|
4
|
+
function create() {
|
|
5
|
+
return {
|
|
6
|
+
name: 'vue-compiler-dom-errors',
|
|
7
|
+
capabilities: {
|
|
8
|
+
diagnosticProvider: {
|
|
9
|
+
interFileDependencies: false,
|
|
10
|
+
workspaceDiagnostics: false,
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
create(context) {
|
|
14
|
+
return {
|
|
15
|
+
provideDiagnostics(document) {
|
|
16
|
+
if (document.languageId !== 'vue-root-tags') {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const vueCompilerOptions = context.project.vue?.compilerOptions;
|
|
20
|
+
if (vueCompilerOptions && vueCompilerOptions.globalTypesPath === undefined) {
|
|
21
|
+
return [{
|
|
22
|
+
range: {
|
|
23
|
+
start: document.positionAt(0),
|
|
24
|
+
end: document.positionAt(0),
|
|
25
|
+
},
|
|
26
|
+
severity: 1,
|
|
27
|
+
code: 404,
|
|
28
|
+
source: 'vue',
|
|
29
|
+
message: `Write global types file failed. Please ensure that "node_modules" exists and "${vueCompilerOptions.lib}" is a direct dependency, or set "vueCompilerOptions.globalTypesPath" in "tsconfig.json" manually.`,
|
|
30
|
+
}];
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=vue-global-types-error.js.map
|
|
@@ -0,0 +1,84 @@
|
|
|
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 utils_1 = require("./utils");
|
|
7
|
+
function create() {
|
|
8
|
+
return {
|
|
9
|
+
name: 'vue-suggest-define-assignment',
|
|
10
|
+
capabilities: {
|
|
11
|
+
completionProvider: {},
|
|
12
|
+
},
|
|
13
|
+
create(context) {
|
|
14
|
+
return {
|
|
15
|
+
isAdditionalCompletion: true,
|
|
16
|
+
async provideCompletionItems(document) {
|
|
17
|
+
if (!(0, utils_1.isTsDocument)(document)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const enabled = await context.env.getConfiguration?.('vue.suggest.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 { sfc } = root;
|
|
36
|
+
const codegen = language_core_1.tsCodegen.get(sfc);
|
|
37
|
+
const scriptSetup = sfc.scriptSetup;
|
|
38
|
+
const scriptSetupRanges = codegen?.getScriptSetupRanges();
|
|
39
|
+
if (!scriptSetup || !scriptSetupRanges) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const result = [];
|
|
43
|
+
const mappings = [...context.language.maps.forEach(virtualCode)];
|
|
44
|
+
addDefineCompletionItem(scriptSetupRanges.defineProps?.statement, scriptSetupRanges.withDefaults?.exp ?? scriptSetupRanges.defineProps?.exp, 'props');
|
|
45
|
+
addDefineCompletionItem(scriptSetupRanges.defineEmits?.statement, scriptSetupRanges.defineEmits?.exp, 'emit');
|
|
46
|
+
addDefineCompletionItem(scriptSetupRanges.defineSlots?.statement, scriptSetupRanges.defineSlots?.exp, 'slots');
|
|
47
|
+
return {
|
|
48
|
+
isIncomplete: false,
|
|
49
|
+
items: result,
|
|
50
|
+
};
|
|
51
|
+
function addDefineCompletionItem(statement, exp, name) {
|
|
52
|
+
if (!exp || exp.start !== statement?.start) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
let offset;
|
|
56
|
+
for (const [, map] of mappings) {
|
|
57
|
+
for (const [generatedOffset] of map.toGeneratedLocation(scriptSetup.startTagEnd + exp.start)) {
|
|
58
|
+
offset = generatedOffset;
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (offset === undefined) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const pos = document.positionAt(offset);
|
|
66
|
+
result.push({
|
|
67
|
+
label: name,
|
|
68
|
+
kind: 6,
|
|
69
|
+
commitCharacters: ['.', ',', ';'],
|
|
70
|
+
additionalTextEdits: [{
|
|
71
|
+
newText: `const ${name} = `,
|
|
72
|
+
range: {
|
|
73
|
+
start: pos,
|
|
74
|
+
end: pos,
|
|
75
|
+
},
|
|
76
|
+
}],
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=vue-suggest-define-assignment.js.map
|
|
@@ -3,7 +3,8 @@ 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 twoslashTemplateReg = /<!--\s*\^\?\s*-->/g;
|
|
7
|
+
const twoslashScriptReg = /(?<=^|\n)\s*\/\/\s*\^\?/g;
|
|
7
8
|
function create(getTsPluginClient) {
|
|
8
9
|
return {
|
|
9
10
|
name: 'vue-twoslash-queries',
|
|
@@ -18,7 +19,8 @@ function create(getTsPluginClient) {
|
|
|
18
19
|
const decoded = context.decodeEmbeddedDocumentUri(uri);
|
|
19
20
|
const sourceScript = decoded && context.language.scripts.get(decoded[0]);
|
|
20
21
|
const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]);
|
|
21
|
-
if (!sourceScript?.generated
|
|
22
|
+
if (!sourceScript?.generated
|
|
23
|
+
|| (virtualCode?.id !== 'template' && !virtualCode?.id.startsWith('script_'))) {
|
|
22
24
|
return;
|
|
23
25
|
}
|
|
24
26
|
const root = sourceScript.generated.root;
|
|
@@ -27,6 +29,7 @@ function create(getTsPluginClient) {
|
|
|
27
29
|
}
|
|
28
30
|
const hoverOffsets = [];
|
|
29
31
|
const inlayHints = [];
|
|
32
|
+
const twoslashReg = virtualCode.id === 'template' ? twoslashTemplateReg : twoslashScriptReg;
|
|
30
33
|
for (const pointer of document.getText(range).matchAll(twoslashReg)) {
|
|
31
34
|
const offset = pointer.index + pointer[0].indexOf('^?') + document.offsetAt(range.start);
|
|
32
35
|
const position = document.positionAt(offset);
|
|
@@ -38,10 +41,11 @@ function create(getTsPluginClient) {
|
|
|
38
41
|
}),
|
|
39
42
|
]);
|
|
40
43
|
}
|
|
44
|
+
const sourceDocument = context.documents.get(decoded[0], sourceScript.languageId, sourceScript.snapshot);
|
|
41
45
|
for (const [pointerPosition, hoverOffset] of hoverOffsets) {
|
|
42
46
|
const map = context.language.maps.get(virtualCode, sourceScript);
|
|
43
47
|
for (const [sourceOffset] of map.toSourceLocation(hoverOffset)) {
|
|
44
|
-
const quickInfo = await tsPluginClient?.getQuickInfoAtPosition(root.fileName,
|
|
48
|
+
const quickInfo = await tsPluginClient?.getQuickInfoAtPosition(root.fileName, sourceDocument.positionAt(sourceOffset));
|
|
45
49
|
if (quickInfo) {
|
|
46
50
|
inlayHints.push({
|
|
47
51
|
position: { line: pointerPosition.line, character: pointerPosition.character + 2 },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/language-service",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"data",
|
|
@@ -17,29 +17,28 @@
|
|
|
17
17
|
"update-html-data": "node ./scripts/update-html-data.js"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@volar/language-service": "2.4.
|
|
21
|
-
"@vue/language-core": "3.0.
|
|
20
|
+
"@volar/language-service": "2.4.19",
|
|
21
|
+
"@vue/language-core": "3.0.2",
|
|
22
22
|
"@vue/shared": "^3.5.0",
|
|
23
23
|
"path-browserify": "^1.0.1",
|
|
24
|
-
"volar-service-css": "0.0.
|
|
25
|
-
"volar-service-emmet": "0.0.
|
|
26
|
-
"volar-service-html": "0.0.
|
|
27
|
-
"volar-service-json": "0.0.
|
|
28
|
-
"volar-service-pug": "0.0.
|
|
29
|
-
"volar-service-pug-beautify": "0.0.
|
|
30
|
-
"volar-service-typescript": "0.0.
|
|
31
|
-
"volar-service-typescript-twoslash-queries": "0.0.64",
|
|
24
|
+
"volar-service-css": "0.0.65",
|
|
25
|
+
"volar-service-emmet": "0.0.65",
|
|
26
|
+
"volar-service-html": "0.0.65",
|
|
27
|
+
"volar-service-json": "0.0.65",
|
|
28
|
+
"volar-service-pug": "0.0.65",
|
|
29
|
+
"volar-service-pug-beautify": "0.0.65",
|
|
30
|
+
"volar-service-typescript": "0.0.65",
|
|
32
31
|
"vscode-html-languageservice": "^5.2.0",
|
|
33
32
|
"vscode-uri": "^3.0.8"
|
|
34
33
|
},
|
|
35
34
|
"devDependencies": {
|
|
36
35
|
"@types/node": "^22.10.4",
|
|
37
36
|
"@types/path-browserify": "^1.0.1",
|
|
38
|
-
"@volar/kit": "2.4.
|
|
39
|
-
"@volar/typescript": "2.4.
|
|
37
|
+
"@volar/kit": "2.4.19",
|
|
38
|
+
"@volar/typescript": "2.4.19",
|
|
40
39
|
"@vue/compiler-dom": "^3.5.0",
|
|
41
|
-
"@vue/typescript-plugin": "3.0.
|
|
40
|
+
"@vue/typescript-plugin": "3.0.2",
|
|
42
41
|
"vscode-css-languageservice": "^6.3.1"
|
|
43
42
|
},
|
|
44
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "7343119e9ca4f6a54f63b57f448f15df4b592a9a"
|
|
45
44
|
}
|