Skip to content

Commit

Permalink
Fix too early and double capability registration
Browse files Browse the repository at this point in the history
- setupDynamicFormatters() was called too early. Can only be called
  after `initialized`.
- It should be enough to call it from "onDidChangeConfiguration" as
  that notification is guaranteed to be called by the client.
- Avoid double-registration by not calling it from "init".
  • Loading branch information
rchl authored and octref committed Nov 6, 2020
1 parent 155cf5b commit 23c8373
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions server/src/services/vls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import {
CompletionTriggerKind,
ExecuteCommandParams,
ApplyWorkspaceEditRequest,
FoldingRangeParams,
CancellationTokenSource
FoldingRangeParams
} from 'vscode-languageserver';
import {
ColorInformation,
Expand Down Expand Up @@ -84,7 +83,7 @@ export class VLS {

private documentFormatterRegistration: Disposable | undefined;

private config: VLSConfig;
private config: VLSFullConfig;

constructor(private lspConnection: Connection) {
this.documentService = new DocumentService(this.lspConnection);
Expand All @@ -95,7 +94,7 @@ export class VLS {
}

async init(params: InitializeParams) {
const config: VLSFullConfig = this.getFullConfig(params.initializationOptions?.config);
const config = this.getFullConfig(params.initializationOptions?.config);

const workspacePath = params.rootPath;
if (!workspacePath) {
Expand All @@ -107,7 +106,7 @@ export class VLS {

this.workspacePath = workspacePath;

await this.vueInfoService.init(this.languageModes);
this.vueInfoService.init(this.languageModes);
await this.dependencyService.init(workspacePath, config.vetur.useWorkspaceDependencies, config.typescript.tsdk);

await this.languageModes.init(
Expand All @@ -119,7 +118,7 @@ export class VLS {
params.initializationOptions?.globalSnippetDir
);

this.setupConfigure(config);
this.configure(config);
this.setupConfigListeners();
this.setupLSPHandlers();
this.setupCustomLSPHandlers();
Expand All @@ -138,14 +137,11 @@ export class VLS {
return config ? _.merge(getDefaultVLSConfig(), config) : getDefaultVLSConfig();
}

public setupConfigure(config: VLSFullConfig) {
this.configure(config);
this.setupDynamicFormatters(config);
}

private setupConfigListeners() {
this.lspConnection.onDidChangeConfiguration(async ({ settings }: DidChangeConfigurationParams) => {
await this.setupConfigure(this.getFullConfig(settings));
const config = this.getFullConfig(settings);
this.configure(config);
this.setupDynamicFormatters(config);
});

this.documentService.getAllDocuments().forEach(this.triggerValidation);
Expand Down

0 comments on commit 23c8373

Please sign in to comment.