-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathserver.ts
More file actions
104 lines (85 loc) · 3.52 KB
/
server.ts
File metadata and controls
104 lines (85 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import {
Connection,
InitializeParams,
InitializeResult,
ServerCapabilities,
TextDocuments,
WorkspaceFolder,
} from "vscode-languageserver";
import { CleanWorkflowCommand } from "./commands/cleanWorkflow";
import { WorkflowLanguageService, TextDocument, WorkflowDocument } from "./languageTypes";
import { WorkflowDocuments } from "./models/workflowDocuments";
import { SymbolsProvider } from "./providers/symbolsProvider";
import { FormattingProvider } from "./providers/formattingProvider";
import { HoverProvider } from "./providers/hover/hoverProvider";
import { DebugHoverContentContributor } from "./providers/hover/debugHoverContentContributor";
export class GalaxyWorkflowLanguageServer {
public readonly languageService: WorkflowLanguageService;
public readonly documents = new TextDocuments(TextDocument);
public readonly workflowDocuments = new WorkflowDocuments();
protected workspaceFolders: WorkspaceFolder[] | null | undefined;
constructor(public readonly connection: Connection, languageService: WorkflowLanguageService) {
this.languageService = languageService;
// Track open, change and close text document events
this.trackDocumentChanges(connection);
this.connection.onInitialize((params) => this.initialize(params));
this.registerProviders();
this.registerCommands();
this.connection.onShutdown(() => this.cleanup());
}
public start(): void {
this.connection.listen();
}
private async initialize(params: InitializeParams): Promise<InitializeResult> {
this.workspaceFolders = params.workspaceFolders;
const capabilities: ServerCapabilities = {
documentFormattingProvider: true,
hoverProvider: true,
documentSymbolProvider: true,
};
return {
capabilities,
};
}
private registerProviders() {
FormattingProvider.register(this);
HoverProvider.register(this, [
// new DebugHoverContentContributor(), //TODO remove this contributor before release
]);
SymbolsProvider.register(this);
}
private registerCommands() {
CleanWorkflowCommand.register(this);
}
private trackDocumentChanges(connection: Connection) {
this.documents.listen(connection);
this.documents.onDidOpen((event) => this.onDocumentOpen(event.document));
this.documents.onDidChangeContent((event) => this.onDidChangeContent(event.document));
this.documents.onDidClose((event) => this.onDidClose(event.document));
}
private onDocumentOpen(textDocument: TextDocument) {
const workflowDocument = this.languageService.parseWorkflowDocument(textDocument);
this.workflowDocuments.addOrReplaceWorkflowDocument(workflowDocument);
this.validate(workflowDocument);
}
private onDidChangeContent(textDocument: TextDocument) {
const workflowDocument = this.languageService.parseWorkflowDocument(textDocument);
this.workflowDocuments.addOrReplaceWorkflowDocument(workflowDocument);
this.validate(workflowDocument);
}
private onDidClose(textDocument: TextDocument) {
this.workflowDocuments.removeWorkflowDocument(textDocument.uri);
this.clearValidation(textDocument);
}
private cleanup() {
this.workflowDocuments.dispose();
}
private validate(workflowDocument: WorkflowDocument) {
this.languageService.doValidation(workflowDocument).then((diagnostics) => {
this.connection.sendDiagnostics({ uri: workflowDocument.textDocument.uri, diagnostics });
});
}
private clearValidation(textDocument: TextDocument) {
this.connection.sendDiagnostics({ uri: textDocument.uri, diagnostics: [] });
}
}