Skip to content

Commit

Permalink
fix: disable document features in html if `vscode.html-language-featu…
Browse files Browse the repository at this point in the history
…res` active

close #1552, close #1530
  • Loading branch information
johnsoncodehk committed Jul 11, 2022
1 parent bd8e2e1 commit d4b32f7
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
11 changes: 8 additions & 3 deletions extensions/vscode-alpine-language-features/src/common.ts
Expand Up @@ -10,7 +10,7 @@ import * as fileReferences from '../../vscode-vue-language-features/out/features

let apiClient: lsp.BaseLanguageClient;
let docClient: lsp.BaseLanguageClient | undefined;
let htmlClient: lsp.BaseLanguageClient;
let htmlClient: lsp.BaseLanguageClient | undefined;

type CreateLanguageClient = (
id: string,
Expand Down Expand Up @@ -85,13 +85,13 @@ async function doActivate(context: vscode.ExtensionContext, createLc: CreateLang
getInitializationOptions(context, 'second-language-features', _useSecondServer),
6110,
) : undefined,
createLc(
enabledDocumentFeaturesInHtml() ? createLc(
'volar-alpine-document-features',
'Volar-Alpine - Document Features Server',
documentFeaturesDocumentSelector,
getInitializationOptions(context, 'document-features', _useSecondServer),
6111,
),
) : undefined,
]);

const clients = [apiClient, docClient, htmlClient].filter(shared.notEmpty);
Expand Down Expand Up @@ -160,6 +160,10 @@ export function takeOverModeEnabled() {
return vscode.workspace.getConfiguration('volar').get<boolean>('alpine.takeOverMode.enabled');
}

function enabledDocumentFeaturesInHtml() {
return !vscode.extensions.getExtension('vscode.html-language-features');
}

function useSecondServer() {
return !!vscode.workspace.getConfiguration('volar').get<boolean>('alpineserver.useSecondServer');
}
Expand Down Expand Up @@ -212,6 +216,7 @@ function getInitializationOptions(
} : {}),
} : undefined,
documentFeatures: mode === 'document-features' ? {
allowedLanguageIds: ['html'],
selectionRange: true,
foldingRange: true,
linkedEditingRange: true,
Expand Down
5 changes: 5 additions & 0 deletions extensions/vscode-vue-language-features/src/common.ts
Expand Up @@ -210,6 +210,10 @@ export function takeOverModeEnabled() {
return status;
}

function enabledDocumentFeaturesInHtml() {
return !vscode.extensions.getExtension('vscode.html-language-features');
}

function useSecondServer() {
return !!vscode.workspace.getConfiguration('volar').get<boolean>('vueserver.useSecondServer');
}
Expand Down Expand Up @@ -257,6 +261,7 @@ function getInitializationOptions(
} : {}),
} : undefined,
documentFeatures: mode === 'document-features' ? {
allowedLanguageIds: ['vue', enabledDocumentFeaturesInHtml() ? 'html' : undefined].filter(shared.notEmpty),
selectionRange: true,
foldingRange: true,
linkedEditingRange: true,
Expand Down
1 change: 1 addition & 0 deletions packages/shared/src/types.ts
Expand Up @@ -75,6 +75,7 @@ export interface ServerInitializationOptions {
* html language service will be create in server if this option is not null
*/
documentFeatures?: {
allowedLanguageIds?: string[];
selectionRange?: boolean;
foldingRange?: boolean;
linkedEditingRange?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/vue-language-server/src/common.ts
Expand Up @@ -74,7 +74,7 @@ export function createLanguageServer(
loadCustomPlugins(folders[0]),
);

(await import('./features/documentFeatures')).register(connection, documents, documentService);
(await import('./features/documentFeatures')).register(connection, documents, documentService, options.documentFeatures.allowedLanguageIds);
(await import('./registers/registerDocumentFeatures')).register(options.documentFeatures, result.capabilities);
}

Expand Down
Expand Up @@ -7,6 +7,7 @@ export function register(
connection: vscode.Connection,
documents: vscode.TextDocuments<TextDocument>,
vueDs: vue.DocumentService,
allowedLanguageIds: string[] = ['vue'],
) {
connection.onDocumentFormatting(handler => {
return worker(handler.textDocument.uri, document => {
Expand Down Expand Up @@ -61,7 +62,7 @@ export function register(

function worker<T>(uri: string, cb: (document: TextDocument) => T) {
const document = documents.get(uri);
if (document) {
if (document && allowedLanguageIds.includes(document.languageId)) {
return cb(document);
}
}
Expand Down
7 changes: 0 additions & 7 deletions packages/vue-language-service/src/documentService.ts
Expand Up @@ -116,13 +116,6 @@ export function getDocumentService(

function getVueDocument(document: TextDocument) {

if (
document.languageId !== 'vue'
&& document.languageId !== 'markdown'
&& document.languageId !== 'html'
)
return;

let vueDoc = vueDocuments.get(document);

if (vueDoc) {
Expand Down

0 comments on commit d4b32f7

Please sign in to comment.