-
-
Notifications
You must be signed in to change notification settings - Fork 371
/
autoInsert.ts
43 lines (36 loc) · 1.22 KB
/
autoInsert.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
import type { DocumentServiceRuntimeContext } from '../types';
import { documentArgFeatureWorker } from '../utils/featureWorkers';
import type { TextDocument } from 'vscode-languageserver-textdocument';
import { EmbeddedLanguageServicePlugin } from '@volar/vue-language-service-types';
import * as vscode from 'vscode-languageserver-protocol';
export function register(context: DocumentServiceRuntimeContext) {
return (document: TextDocument, position: vscode.Position, options: Parameters<NonNullable<EmbeddedLanguageServicePlugin['doAutoInsert']>>[2]) => {
return documentArgFeatureWorker(
context,
document,
position,
sourceMap => true,
function* (position, sourceMap) {
for (const [mappedRange] of sourceMap.getMappedRanges(
position,
position,
data => !!data.capabilities.completion,
)) {
yield mappedRange.start;
}
},
(plugin, document, position) => plugin.doAutoInsert?.(document, position, options),
(data, sourceMap) => {
if (!sourceMap)
return data;
if (typeof data === 'string')
return data;
const range = sourceMap.getSourceRange(data.range.start, data.range.end)?.[0];
if (range) {
data.range = range;
return data;
}
},
);
}
}