-
-
Notifications
You must be signed in to change notification settings - Fork 364
/
vue-visualize-hidden-callback-param.ts
50 lines (43 loc) · 1.47 KB
/
vue-visualize-hidden-callback-param.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { LanguageServicePlugin } from '@volar/language-service';
import * as vscode from 'vscode-languageserver-protocol';
const plugin: LanguageServicePlugin = (context) => {
if (!context)
return {};
return {
async provideInlayHints(document, range) {
const enabled = await context.configurationHost?.getConfiguration<boolean>('volar.inlayHints.eventArgumentInInlineHandlers') ?? true;
if (!enabled)
return;
const result: vscode.InlayHint[] = [];
const [file] = context.documents.getVirtualFileByUri(document.uri);
if (file) {
const start = document.offsetAt(range.start);
const end = document.offsetAt(range.end);
for (const mapping of file.mappings) {
if (
mapping.generatedRange[0] >= start
&& mapping.generatedRange[1] <= end
&& (mapping.data as any).__hiddenParam
) {
result.push({
label: '$event =>',
paddingRight: true,
position: document.positionAt(mapping.generatedRange[0]),
kind: vscode.InlayHintKind.Parameter,
tooltip: {
kind: 'markdown',
value: [
'`$event` is a hidden parameter, you can use it in this callback.',
'To hide this hint, set `volar.inlayHints.eventArgumentInInlineHandlers` to `false` in IDE settings.',
'[More info](https://github.com/vuejs/language-tools/issues/2445#issuecomment-1444771420)',
].join('\n\n'),
},
});
}
}
}
return result;
},
};
};
export default () => plugin;