Skip to content

Commit

Permalink
feat(pug): allow documentContext undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Jan 3, 2023
1 parent 4820a7c commit c97ef7c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
12 changes: 4 additions & 8 deletions plugins/pug/src/index.ts
Expand Up @@ -25,10 +25,7 @@ const plugin: LanguageServicePlugin<{

on(document, position, _) {
return worker(document, (pugDocument) => {

const documentContext = context.env.documentContext ?? { resolveReference: () => undefined };

return pugLs.doComplete(pugDocument, position, documentContext, /** TODO: CompletionConfiguration */);
return pugLs.doComplete(pugDocument, position, context.env.documentContext, /** TODO: CompletionConfiguration */);
});
},
},
Expand Down Expand Up @@ -72,10 +69,9 @@ const plugin: LanguageServicePlugin<{

findDocumentLinks(document) {
return worker(document, (pugDocument) => {

const documentContext = context.env.documentContext ?? { resolveReference: () => undefined };

return pugLs.findDocumentLinks(pugDocument, documentContext);
if (context.env.documentContext) {
return pugLs.findDocumentLinks(pugDocument, context.env.documentContext);
}
});
},

Expand Down
Expand Up @@ -4,18 +4,23 @@ 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, options?: html.CompletionConfiguration | undefined) => {
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 = await htmlLs.doComplete2(
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));
Expand Down

0 comments on commit c97ef7c

Please sign in to comment.