1- import { ASTNode , getLanguageService , LanguageService } from "vscode-json-languageservice" ;
1+ import {
2+ getLanguageService ,
3+ LanguageService ,
4+ LanguageServiceParams ,
5+ DocumentLanguageSettings ,
6+ Diagnostic ,
7+ JSONSchema ,
8+ LanguageSettings ,
9+ SchemaConfiguration ,
10+ } from "vscode-json-languageservice" ;
211import {
312 TextDocument ,
413 Range ,
514 FormattingOptions ,
615 TextEdit ,
716 WorkflowDocument ,
817 WorkflowLanguageService ,
18+ Position ,
19+ Hover ,
920} from "./languageTypes" ;
21+ import NativeWorkflowSchema from "../../workflow-languages/schemas/native.schema.json" ;
1022
1123/**
1224 * A wrapper around the JSON Language Service to support language features
1325 * for native Galaxy workflow files AKA '.ga' workflows.
1426 */
1527export class NativeWorkflowLanguageService implements WorkflowLanguageService {
1628 private _jsonLanguageService : LanguageService ;
29+ private _documentSettings : DocumentLanguageSettings = { schemaValidation : "error" } ;
1730
1831 constructor ( ) {
19- this . _jsonLanguageService = getLanguageService ( { } ) ;
32+ const params : LanguageServiceParams = { } ;
33+ const settings = this . getLanguageSettings ( ) ;
34+ this . _jsonLanguageService = getLanguageService ( params ) ;
35+ this . _jsonLanguageService . configure ( settings ) ;
36+ }
37+
38+ public get schema ( ) : JSONSchema {
39+ return NativeWorkflowSchema ;
2040 }
2141
2242 public parseWorkflowDocument ( document : TextDocument ) : WorkflowDocument {
@@ -27,8 +47,38 @@ export class NativeWorkflowLanguageService implements WorkflowLanguageService {
2747 public format ( document : TextDocument , range : Range , options : FormattingOptions ) : TextEdit [ ] {
2848 return this . _jsonLanguageService . format ( document , range , options ) ;
2949 }
30- }
3150
32- export function getRange ( document : TextDocument , node : ASTNode ) {
33- return Range . create ( document . positionAt ( node . offset ) , document . positionAt ( node . offset + node . length ) ) ;
51+ public async doValidation ( workflowDocument : WorkflowDocument ) : Promise < Diagnostic [ ] > {
52+ const schemaValidationResults = await this . _jsonLanguageService . doValidation (
53+ workflowDocument . textDocument ,
54+ workflowDocument . jsonDocument ,
55+ this . _documentSettings ,
56+ this . schema
57+ ) ;
58+ return schemaValidationResults ;
59+ }
60+
61+ public async doHover ( workflowDocument : WorkflowDocument , position : Position ) : Promise < Hover | null > {
62+ const hover = await this . _jsonLanguageService . doHover (
63+ workflowDocument . textDocument ,
64+ position ,
65+ workflowDocument . jsonDocument
66+ ) ;
67+ return hover ;
68+ }
69+
70+ private getLanguageSettings ( ) : LanguageSettings {
71+ const settings : LanguageSettings = {
72+ schemas : [ this . getWorkflowSchemaConfig ( ) ] ,
73+ } ;
74+ return settings ;
75+ }
76+
77+ private getWorkflowSchemaConfig ( ) : SchemaConfiguration {
78+ return {
79+ uri : this . schema . id ?? "" ,
80+ fileMatch : [ "**.ga" ] ,
81+ schema : this . schema ,
82+ } ;
83+ }
3484}
0 commit comments