Skip to content

Commit

Permalink
feat: add processHtmlFile, processMdFile to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Sep 16, 2022
1 parent 38d6862 commit 7ae2f6b
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 35 deletions.
13 changes: 8 additions & 5 deletions extensions/vscode-vue-language-features/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@
}
},
"contributes": {
"configurationDefaults": {
"[markdown]": {
"editor.quickSuggestions": true
}
},
"views": {
"explorer": [
{
Expand Down Expand Up @@ -307,6 +302,14 @@
"default": "off",
"description": "Traces the communication between VS Code and the language server."
},
"volar.vueserver.petiteVue.processHtmlFile": {
"type": "boolean",
"default": false
},
"volar.vueserver.vitePress.processMdFile": {
"type": "boolean",
"default": false
},
"volar.vueserver.textDocumentSync": {
"type": "string",
"default": "incremental",
Expand Down
52 changes: 32 additions & 20 deletions extensions/vscode-vue-language-features/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as doctor from './features/doctor';
import * as fileReferences from './features/fileReferences';
import * as reloadProject from './features/reloadProject';
import * as serverSys from './features/serverSys';
import { ServerInitializationOptions } from '@volar/vue-language-server';
import { VueServerInitializationOptions } from '@volar/vue-language-server';

let apiClient: lsp.BaseLanguageClient | undefined;
let docClient: lsp.BaseLanguageClient | undefined;
Expand All @@ -28,7 +28,7 @@ type CreateLanguageClient = (
id: string,
name: string,
documentSelector: lsp.DocumentSelector,
initOptions: ServerInitializationOptions,
initOptions: VueServerInitializationOptions,
port: number,
) => Promise<lsp.BaseLanguageClient>;

Expand All @@ -47,7 +47,7 @@ export async function activate(context: vscode.ExtensionContext, createLc: Creat
}

const currentlangId = vscode.window.activeTextEditor.document.languageId;
if (currentlangId === 'vue' || currentlangId === 'markdown' || currentlangId === 'html') {
if (currentlangId === 'vue' || (currentlangId === 'markdown' && processMd()) || (currentlangId === 'html' && processHtml())) {
doActivate(context, createLc);
stopCheck.dispose();
}
Expand All @@ -67,18 +67,14 @@ async function doActivate(context: vscode.ExtensionContext, createLc: CreateLang
const takeOverMode = takeOverModeEnabled();
const languageFeaturesDocumentSelector: lsp.DocumentSelector = takeOverMode ?
[
{ /* scheme: 'file', */ language: 'vue' },
{ /* scheme: 'file', */ language: 'markdown' },
{ /* scheme: 'file', */ language: 'html' },
{ /* scheme: 'file', */ language: 'javascript' },
{ /* scheme: 'file', */ language: 'typescript' },
{ /* scheme: 'file', */ language: 'javascriptreact' },
{ /* scheme: 'file', */ language: 'typescriptreact' },
{ /* scheme: 'file', */ language: 'json' },
{ language: 'vue' },
{ language: 'javascript' },
{ language: 'typescript' },
{ language: 'javascriptreact' },
{ language: 'typescriptreact' },
{ language: 'json' },
] : [
{ /* scheme: 'file', */ language: 'vue' },
{ /* scheme: 'file', */ language: 'markdown' },
{ /* scheme: 'file', */ language: 'html' },
{ language: 'vue' },
];
const documentFeaturesDocumentSelector: lsp.DocumentSelector = takeOverMode ?
[
Expand All @@ -91,10 +87,16 @@ async function doActivate(context: vscode.ExtensionContext, createLc: CreateLang
{ language: 'vue' },
];

if (enabledDocumentFeaturesInHtml()) {
if (processHtml()) {
languageFeaturesDocumentSelector.push({ language: 'html' });
documentFeaturesDocumentSelector.push({ language: 'html' });
}

if (processMd()) {
languageFeaturesDocumentSelector.push({ language: 'markdown' });
documentFeaturesDocumentSelector.push({ language: 'markdown' });
}

const _useSecondServer = useSecondServer();
const _serverMaxOldSpaceSize = serverMaxOldSpaceSize();

Expand Down Expand Up @@ -210,10 +212,6 @@ export function takeOverModeEnabled() {
return false;
}

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

function useSecondServer() {
return !!vscode.workspace.getConfiguration('volar').get<boolean>('vueserver.useSecondServer');
}
Expand All @@ -222,13 +220,27 @@ function serverMaxOldSpaceSize() {
return vscode.workspace.getConfiguration('volar').get<number | null>('vueserver.maxOldSpaceSize');
}

function processHtml() {
return !!vscode.workspace.getConfiguration('volar').get<boolean>('vueserver.petiteVue.processHtmlFile');
}

function processMd() {
return !!vscode.workspace.getConfiguration('volar').get<boolean>('vueserver.vitePress.processMdFile');
}

function getInitializationOptions(
context: vscode.ExtensionContext,
mode: 'main-language-features' | 'second-language-features' | 'document-features',
useSecondServer: boolean,
) {
const textDocumentSync = vscode.workspace.getConfiguration('volar').get<'incremental' | 'full' | 'none'>('vueserver.textDocumentSync');
const initializationOptions: ServerInitializationOptions = {
const initializationOptions: VueServerInitializationOptions = {
petiteVue: {
processHtmlFile: processHtml(),
},
vitePress: {
processMdFile: processMd(),
},
textDocumentSync: textDocumentSync ? {
incremental: lsp.TextDocumentSyncKind.Incremental,
full: lsp.TextDocumentSyncKind.Full,
Expand Down
1 change: 1 addition & 0 deletions packages/vue-language-server/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from '@volar/language-server';
export * from './requests';
export * from './types';

12 changes: 2 additions & 10 deletions packages/vue-language-server/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
import * as embedded from '@volar/language-core';
import { LanguageServerPlugin, ServerInitializationOptions } from '@volar/language-server';
import { LanguageServerPlugin } from '@volar/language-server';
import * as shared from '@volar/shared';
import * as vue from '@volar/vue-language-service';
import * as nameCasing from '@volar/vue-language-service/out/ideFeatures/nameCasing';
import { DetectTagCasingRequest, GetConvertTagCasingEditsRequest } from './requests';

type VueServerInitializationOptions = ServerInitializationOptions & {
petiteVue?: {
processHtmlFile: boolean,
},
vitePress?: {
processMdFile: boolean,
},
};
import { VueServerInitializationOptions } from './types';

const plugin: LanguageServerPlugin<VueServerInitializationOptions, vue.LanguageServiceHost> = (initOptions) => {

Expand Down
10 changes: 10 additions & 0 deletions packages/vue-language-server/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ServerInitializationOptions } from "@volar/language-server";

export type VueServerInitializationOptions = ServerInitializationOptions & {
petiteVue?: {
processHtmlFile: boolean,
},
vitePress?: {
processMdFile: boolean,
},
};

0 comments on commit 7ae2f6b

Please sign in to comment.