Skip to content

Commit

Permalink
Restructure initalization (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
razzeee committed Aug 11, 2019
1 parent 0e36e15 commit 2a4fd76
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Expand Up @@ -34,7 +34,7 @@ connection.onInitialize(
},
);

connection.onInitialized(async () => {
connection.onInitialized(() => {
server.registerInitializedProviders();
});

Expand Down
57 changes: 25 additions & 32 deletions src/server.ts
Expand Up @@ -3,7 +3,6 @@ import glob from "glob";
import os from "os";
import {
Connection,
DidChangeConfigurationParams,
InitializeParams,
InitializeResult,
} from "vscode-languageserver";
Expand Down Expand Up @@ -49,6 +48,8 @@ export class Server implements ILanguageServer {
private imports: IImports;
private elmWorkspace: URI;
private settings: Settings;
private documentEvents: DocumentEvents;
private textDocumentEvents: TextDocumentEvents;

constructor(
private connection: Connection,
Expand All @@ -75,6 +76,12 @@ export class Server implements ILanguageServer {
this.settings = new Settings(this.connection);

this.settings.updateSettings(initializationOptions);

this.documentEvents = new DocumentEvents(
this.connection,
this.elmWorkspace,
);
this.textDocumentEvents = new TextDocumentEvents(this.documentEvents);
}

get capabilities(): InitializeResult {
Expand All @@ -84,26 +91,16 @@ export class Server implements ILanguageServer {
}

public async init() {
this.setupConfigListeners();

await this.initWorkspace();
}
public async registerInitializedProviders() {
const documentEvents = new DocumentEvents(
this.connection,
this.elmWorkspace,
);
const textDocumentEvents = new TextDocumentEvents(documentEvents);
const documentFormatingProvider = new DocumentFormattingProvider(
this.connection,
this.elmWorkspace,
textDocumentEvents,
this.textDocumentEvents,
this.settings,
);
const elmAnalyse = new ElmAnalyseDiagnostics(
this.connection,
this.elmWorkspace,
textDocumentEvents,
this.textDocumentEvents,
this.settings,
documentFormatingProvider,
);
Expand All @@ -112,33 +109,37 @@ export class Server implements ILanguageServer {
this.elmWorkspace,
this.settings,
);
// tslint:disable:no-unused-expression
new DiagnosticsProvider(
this.connection,
this.elmWorkspace,
this.settings,
this.textDocumentEvents,
elmAnalyse,
elmMake,
);
new CodeActionProvider(this.connection, elmAnalyse, elmMake);

await this.initWorkspace();
}
public async registerInitializedProviders() {
// tslint:disable:no-unused-expression
new ASTProvider(
this.connection,
this.forest,
documentEvents,
this.documentEvents,
this.imports,
this.parser,
);
new FoldingRangeProvider(this.connection, this.forest);
new CompletionProvider(this.connection, this.forest, this.imports);
new HoverProvider(this.connection, this.forest, this.imports);
new DiagnosticsProvider(
this.connection,
this.elmWorkspace,
this.settings,
textDocumentEvents,
elmAnalyse,
elmMake,
);
new DefinitionProvider(this.connection, this.forest, this.imports);
new ReferencesProvider(this.connection, this.forest, this.imports);
new DocumentSymbolProvider(this.connection, this.forest);
new WorkspaceSymbolProvider(this.connection, this.forest);
new CodeLensProvider(this.connection, this.forest, this.imports);
new RenameProvider(this.connection, this.forest, this.imports);
new CodeActionProvider(this.connection, elmAnalyse, elmMake);
Promise.resolve();
}

public async initWorkspace() {
Expand Down Expand Up @@ -263,14 +264,6 @@ export class Server implements ILanguageServer {
.map(path => ({ path, writable: element.writable }));
}

private setupConfigListeners() {
this.connection.onDidChangeConfiguration(
({ settings }: DidChangeConfigurationParams) => {
this.settings.updateSettings(settings.elmLS);
},
);
}

private packageOrPackagesFolder(elmVersion: string | undefined): string {
return elmVersion === "0.19.0" ? "package" : "packages";
}
Expand Down

0 comments on commit 2a4fd76

Please sign in to comment.