/
completion.ts
28 lines (24 loc) · 943 Bytes
/
completion.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
import { transformCompletionList } from '@volar/transforms';
import type * as html from 'vscode-html-languageservice';
import { MappingKind } from '../baseParse';
import type { PugDocument } from '../pugDocument';
export function register(htmlLs: html.LanguageService) {
return async (pugDoc: PugDocument, pos: html.Position, documentContext: html.DocumentContext | undefined, options?: html.CompletionConfiguration | undefined) => {
const htmlPos = pugDoc.map.toGeneratedPosition(pos, data => data !== MappingKind.EmptyTagCompletion);
if (!htmlPos)
return;
const htmlComplete = documentContext ? await htmlLs.doComplete2(
pugDoc.htmlTextDocument,
htmlPos,
pugDoc.htmlDocument,
documentContext,
options,
) : htmlLs.doComplete(
pugDoc.htmlTextDocument,
htmlPos,
pugDoc.htmlDocument,
options,
);
return transformCompletionList(htmlComplete, htmlRange => pugDoc.map.toSourceRange(htmlRange));
};
}