Skip to content

Commit

Permalink
fix(pug): compatible with volar 2.0.4 types
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Feb 13, 2024
1 parent 2d4bb1b commit cfe04fe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/pug/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function create(): ServicePlugin {

provideCompletionItems(document, position, _) {
return worker(document, (pugDocument) => {
return pugLs.doComplete(pugDocument, position, htmlService.provide['html/documentContext'](), /** TODO: CompletionConfiguration */);
return pugLs.doComplete(pugDocument, position, context, htmlService.provide['html/documentContext'](), /** TODO: CompletionConfiguration */);
});
},

Expand Down
17 changes: 14 additions & 3 deletions packages/pug/lib/services/completion.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import type * as html from 'vscode-html-languageservice';
import { TextDocument } from 'vscode-html-languageservice';
import type { PugDocument } from '../pugDocument';
import { transformCompletionList } from '@volar/language-service';
import { ServiceContext, transformCompletionList } from '@volar/language-service';

export function register(htmlLs: html.LanguageService) {

const docForEmptyLineCompletion = TextDocument.create('file:///foo.html', 'html', 0, '< />');
const htmlDocForEmptyLineCompletion = htmlLs.parseHTMLDocument(docForEmptyLineCompletion);
const posForEmptyLine = docForEmptyLineCompletion.positionAt(1);

return async (pugDoc: PugDocument, pos: html.Position, documentContext: html.DocumentContext | undefined, options?: html.CompletionConfiguration | undefined) => {
return async (
pugDoc: PugDocument,
pos: html.Position,
serviceContext: ServiceContext,
documentContext: html.DocumentContext | undefined,
options?: html.CompletionConfiguration | undefined
) => {

const offset = pugDoc.pugTextDocument.offsetAt(pos);

Expand Down Expand Up @@ -44,6 +50,11 @@ export function register(htmlLs: html.LanguageService) {
options,
);

return transformCompletionList(htmlComplete, htmlRange => pugDoc.map.getSourceRange(htmlRange), pugDoc.map.virtualFileDocument);
return transformCompletionList(
htmlComplete,
htmlRange => pugDoc.map.getSourceRange(htmlRange),
pugDoc.map.virtualFileDocument,
serviceContext,
);
};
}

0 comments on commit cfe04fe

Please sign in to comment.