Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure initalization #129

Merged
merged 2 commits into from Aug 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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