Skip to content

Commit

Permalink
fix: vue tag auto-complete not working
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Mar 20, 2022
1 parent 335ae83 commit cd182f6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 27 deletions.
18 changes: 10 additions & 8 deletions packages/vue-language-service/src/commonPlugins/html.ts
Expand Up @@ -4,9 +4,10 @@ import { TextDocument } from 'vscode-languageserver-textdocument';
import * as shared from '@volar/shared';

export default function (host: {
configurationHost: ConfigurationHost | undefined
configurationHost?: ConfigurationHost,
documentContext?: html.DocumentContext,
fileSystemProvider?: html.FileSystemProvider,
validLang?: string,
}): EmbeddedLanguageServicePlugin & {
htmlLs: html.LanguageService,
getHtmlDocument(document: TextDocument): html.HTMLDocument | undefined,
Expand Down Expand Up @@ -35,11 +36,12 @@ export default function (host: {

async doComplete(document, position, context) {
return worker(document, (htmlDocument) => {

if (!host.documentContext)
return;

return htmlLs.doComplete2(document, position, htmlDocument, host.documentContext, /** TODO: CompletionConfiguration */);
if (host.documentContext) {
return htmlLs.doComplete2(document, position, htmlDocument, host.documentContext, /** TODO: CompletionConfiguration */);
}
else {
return htmlLs.doComplete(document, position, htmlDocument, /** TODO: CompletionConfiguration */);
}
});
},

Expand Down Expand Up @@ -153,7 +155,7 @@ export default function (host: {
};

async function initCustomData() {
if (!inited) {
if (!inited && host.configurationHost) {
customData = await getCustomData();
htmlLs.setDataProviders(true, customData);
inited = true;
Expand Down Expand Up @@ -208,7 +210,7 @@ export default function (host: {

function getHtmlDocument(document: TextDocument) {

if (document.languageId !== 'html')
if (document.languageId !== (host.validLang ?? 'html'))
return;

const cache = htmlDocuments.get(document);
Expand Down
1 change: 0 additions & 1 deletion packages/vue-language-service/src/documentService.ts
Expand Up @@ -47,7 +47,6 @@ export function getDocumentService(

// language support plugins
const vuePlugin = useVuePlugin({
configurationHost,
getVueDocument,
scriptTsLs: undefined,
});
Expand Down
2 changes: 0 additions & 2 deletions packages/vue-language-service/src/languageService.ts
Expand Up @@ -119,10 +119,8 @@ export function createLanguageService(
const customPlugins = _customPlugins.map(plugin => defineLanguageServicePlugin(plugin));
const vuePlugin = defineLanguageServicePlugin(
useVuePlugin({
configurationHost,
getVueDocument: (document) => vueDocuments.get(document.uri),
scriptTsLs,
documentContext,
}),
);
const vueTemplateHtmlPlugin = _useVueTemplateLanguagePlugin(
Expand Down
20 changes: 4 additions & 16 deletions packages/vue-language-service/src/vuePlugins/vue.ts
Expand Up @@ -5,6 +5,7 @@ import useHtmlPlugin from '../commonPlugins/html';
import * as vscode from 'vscode-languageserver-protocol';
import type * as ts2 from '@volar/typescript-language-service';
import { VueDocument } from '../vueDocuments';
import { EmbeddedLanguageServicePlugin } from '@volar/vue-language-service-types';

const dataProvider = html.newHTMLDataProvider('vue', {
version: 1.1,
Expand Down Expand Up @@ -91,12 +92,12 @@ const dataProvider = html.newHTMLDataProvider('vue', {
]
});

export default function (host: Omit<Parameters<typeof useHtmlPlugin>[0], 'getHtmlLs'> & {
export default function (host: {
getVueDocument(document: TextDocument): VueDocument | undefined,
scriptTsLs: ts2.LanguageService | undefined,
}): ReturnType<typeof useHtmlPlugin> {
}): EmbeddedLanguageServicePlugin {

const htmlPlugin = useHtmlPlugin(host);
const htmlPlugin = useHtmlPlugin({ validLang: 'vue' });
htmlPlugin.htmlLs.setDataProviders(false, [dataProvider]);

return {
Expand Down Expand Up @@ -150,19 +151,6 @@ export default function (host: Omit<Parameters<typeof useHtmlPlugin>[0], 'getHtm
});
},

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

if (!host.documentContext)
return;

const sfcWithEmptyBlocks = getSfcCodeWithEmptyBlocks(vueDocument, document.getText());
const sfcWithEmptyBlocksDocument = TextDocument.create(document.uri, document.languageId, document.version, sfcWithEmptyBlocks);

return htmlPlugin.htmlLs.findDocumentLinks(sfcWithEmptyBlocksDocument, host.documentContext);
});
},

findDocumentSymbols(document) {
return worker(document, (vueDocument) => {

Expand Down

0 comments on commit cd182f6

Please sign in to comment.