-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlanguageService.ts
More file actions
84 lines (75 loc) · 2.42 KB
/
languageService.ts
File metadata and controls
84 lines (75 loc) · 2.42 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
import {
getLanguageService,
LanguageService,
LanguageServiceParams,
DocumentLanguageSettings,
Diagnostic,
JSONSchema,
LanguageSettings,
SchemaConfiguration,
} from "vscode-json-languageservice";
import {
TextDocument,
Range,
FormattingOptions,
TextEdit,
WorkflowDocument,
WorkflowLanguageService,
Position,
Hover,
} from "./languageTypes";
import NativeWorkflowSchema from "../../workflow-languages/schemas/native.schema.json";
/**
* A wrapper around the JSON Language Service to support language features
* for native Galaxy workflow files AKA '.ga' workflows.
*/
export class NativeWorkflowLanguageService implements WorkflowLanguageService {
private _jsonLanguageService: LanguageService;
private _documentSettings: DocumentLanguageSettings = { schemaValidation: "error" };
constructor() {
const params: LanguageServiceParams = {};
const settings = this.getLanguageSettings();
this._jsonLanguageService = getLanguageService(params);
this._jsonLanguageService.configure(settings);
}
public get schema(): JSONSchema {
return NativeWorkflowSchema;
}
public parseWorkflowDocument(document: TextDocument): WorkflowDocument {
const jsonDocument = this._jsonLanguageService.parseJSONDocument(document);
return new WorkflowDocument(document, jsonDocument);
}
public format(document: TextDocument, range: Range, options: FormattingOptions): TextEdit[] {
return this._jsonLanguageService.format(document, range, options);
}
public async doValidation(workflowDocument: WorkflowDocument): Promise<Diagnostic[]> {
const schemaValidationResults = await this._jsonLanguageService.doValidation(
workflowDocument.textDocument,
workflowDocument.jsonDocument,
this._documentSettings,
this.schema
);
return schemaValidationResults;
}
public async doHover(workflowDocument: WorkflowDocument, position: Position): Promise<Hover | null> {
const hover = await this._jsonLanguageService.doHover(
workflowDocument.textDocument,
position,
workflowDocument.jsonDocument
);
return hover;
}
private getLanguageSettings(): LanguageSettings {
const settings: LanguageSettings = {
schemas: [this.getWorkflowSchemaConfig()],
};
return settings;
}
private getWorkflowSchemaConfig(): SchemaConfiguration {
return {
uri: this.schema.id ?? "",
fileMatch: ["**.ga"],
schema: this.schema,
};
}
}