import { YAMLSchemaService , CustomSchemaProvider , SchemaAdditions , SchemaDeletions , SchemaDeletionsAll , } from './services/yamlSchemaService' ; import { Position , CompletionList , Diagnostic , Hover , SymbolInformation , DocumentSymbol , TextEdit , DocumentLink , CodeLens , DefinitionLink , } from 'vscode-languageserver-types' ; import { JSONSchema } from './jsonSchema' ; import { YAMLDocumentSymbols } from './services/documentSymbols' ; import { YAMLHover } from './services/yamlHover' ; import { YAMLValidation } from './services/yamlValidation' ; import { YAMLFormatter } from './services/yamlFormatter' ; import { DocumentSymbolsContext } from 'vscode-json-languageservice' ; import { YamlLinks } from './services/yamlLinks' ; import { FoldingRange , ClientCapabilities , CodeActionParams , CodeAction , Connection , DocumentOnTypeFormattingParams , CodeLensParams , DefinitionParams , } from 'vscode-languageserver/node' ; import { TextDocument } from 'vscode-languageserver-textdocument' ; import { getFoldingRanges } from './services/yamlFolding' ; import { FoldingRangesContext } from './yamlTypes' ; import { YamlCodeActions } from './services/yamlCodeActions' ; import { commandExecutor } from '../languageserver/commandExecutor' ; import { doDocumentOnTypeFormatting } from './services/yamlOnTypeFormatting' ; import { YamlCodeLens } from './services/yamlCodeLens' ; import { registerCommands } from './services/yamlCommands' ; import { Telemetry } from '../languageserver/telemetry' ; import { YamlVersion } from './parser/yamlParser07' ; import { YamlCompletion } from './services/yamlCompletion' ; import { yamlDocumentsCache } from './parser/yaml-documents' ; import { SettingsState } from '../yamlSettings' ; import { JSONSchemaSelection } from '../languageserver/handlers/schemaSelectionHandlers' ; import { YamlDefinition } from './services/yamlDefinition' ; export enum SchemaPriority { SchemaStore = 1 , SchemaAssociation = 2 , Settings = 3 , Modeline = 4 } export interface SchemasSettings { priority ? : SchemaPriority ; fileMatch : string [ ] ; schema ? : unknown ; uri : string ; name ? : string ; description ? : string ; } export interface LanguageSettings { validate ? : boolean ; hover ? : boolean ; completion ? : boolean ; format ? : boolean ; isKubernetes ? : boolean ; schemas ? : SchemasSettings [ ] ; customTags ? : Array < string > ; /**
     * Default indentation size
     */ indentation ? : string ; /**
     * Globally set additionalProperties to false if additionalProperties is not set and if schema.type is object.
     * So if its true, no extra properties are allowed inside yaml.
     */ disableAdditionalProperties ? : boolean ; /**
     * Disable adding not required properties with default values into completion text.
     */ disableDefaultProperties ? : boolean ; /**
     * Default yaml lang version
     */ yamlVersion ? : YamlVersion ; } export interface WorkspaceContextService { resolveRelativePath ( relativePath , resource ) : string ; } /**
 * The schema request service is used to fetch schemas. The result should the schema file comment, or,
 * in case of an error, a displayable error string
 */ export interface SchemaRequestService { ( uri ) : Promise < string > ; } export interface SchemaConfiguration { /**
     * The URI of the schema, which is also the identifier of the schema.
     */ uri : string ; /**
     * A list of file names that are associated to the schema. The '*' wildcard can be used. For example '*.schema.json', 'package.json'
     */ fileMatch ? : string [ ] ; /**
     * The schema for the given URI.
     * If no schema is provided, the schema will be fetched with the schema request service (if available).
     */ schema ? : JSONSchema ; } export interface CustomFormatterOptions { singleQuote ? : boolean ; bracketSpacing ? : boolean ; proseWrap ? : string ; printWidth ? : number ; enable ? : boolean ; } export interface LanguageService { configure ( settings ) : void ; registerCustomSchemaProvider ( schemaProvider ) : void ; doComplete ( document , position , isKubernetes ) : Promise < CompletionList > ; doValidation ( document , isKubernetes ) : Promise < Diagnostic [ ] > ; doHover ( document , position ) : Promise < Hover | null > ; findDocumentSymbols ( document , context ) : SymbolInformation [ ] ; findDocumentSymbols2 ( document , context ) : DocumentSymbol [ ] ; findLinks ( document ) : Promise < DocumentLink [ ] > ; resetSchema ( uri ) : boolean ; doFormat ( document , options ) : TextEdit [ ] ; doDefinition ( document , params ) : DefinitionLink [ ] | undefined ; doDocumentOnTypeFormatting ( document , params ) : TextEdit [ ] | undefined ; addSchema ( schemaID , schema ) : void ; deleteSchema ( schemaID ) : void ; modifySchemaContent ( schemaAdditions ) : void ; deleteSchemaContent ( schemaDeletions ) : void ; deleteSchemasWhole ( schemaDeletions ) : void ; getFoldingRanges ( document , context ) : FoldingRange [ ] | null ; getCodeAction ( document , params ) : CodeAction [ ] | undefined ; getCodeLens ( document , params ) : Thenable < CodeLens [ ] | undefined > | CodeLens [ ] | undefined ; resolveCodeLens ( param ) : Thenable < CodeLens > | CodeLens ; } export function getLanguageService ( schemaRequestService , workspaceContext , connection , telemetry , yamlSettings , clientCapabilities ? ) { const schemaService = new YAMLSchemaService ( schemaRequestService , workspaceContext ) ; const completer = new YamlCompletion ( schemaService , clientCapabilities , yamlDocumentsCache , telemetry ) ; const hover = new YAMLHover ( schemaService , telemetry ) ; const yamlDocumentSymbols = new YAMLDocumentSymbols ( schemaService , telemetry ) ; const yamlValidation = new YAMLValidation ( schemaService ) ; const formatter = new YAMLFormatter ( ) ; const yamlCodeActions = new YamlCodeActions ( clientCapabilities ) ; const yamlCodeLens = new YamlCodeLens ( schemaService , telemetry ) ; const yamlLinks = new YamlLinks ( telemetry ) ; const yamlDefinition = new YamlDefinition ( telemetry ) ; new JSONSchemaSelection ( schemaService , yamlSettings , connection ) ; registerCommands ( commandExecutor , connection ) ; return { configure : ( settings ) => { schemaService . clearExternalSchemas ( ) ; if ( settings . schemas ) { schemaService . schemaPriorityMapping = new Map ( ) ; settings . schemas . forEach ( ( settings ) => { const currPriority = settings . priority ? settings . priority : 0 ; schemaService . addSchemaPriority ( settings . uri , currPriority ) ; schemaService . registerExternalSchema ( settings . uri , settings . fileMatch , settings . schema , settings . name , settings . description ) ; } ) ; } yamlValidation . configure ( settings ) ; hover . configure ( settings ) ; completer . configure ( settings ) ; formatter . configure ( settings ) ; yamlCodeActions . configure ( settings ) ; } , registerCustomSchemaProvider : ( schemaProvider ) => { schemaService . registerCustomSchemaProvider ( schemaProvider ) ; } , findLinks : yamlLinks . findLinks . bind ( yamlLinks ) , doComplete : completer . doComplete . bind ( completer ) , doValidation : yamlValidation . doValidation . bind ( yamlValidation ) , doHover : hover . doHover . bind ( hover ) , findDocumentSymbols : yamlDocumentSymbols . findDocumentSymbols . bind ( yamlDocumentSymbols ) , findDocumentSymbols2 : yamlDocumentSymbols . findHierarchicalDocumentSymbols . bind ( yamlDocumentSymbols ) , doDefinition : yamlDefinition . getDefinition . bind ( yamlDefinition ) , resetSchema : ( uri ) => { return schemaService . onResourceChange ( uri ) ; } , doFormat : formatter . format . bind ( formatter ) , doDocumentOnTypeFormatting , addSchema : ( schemaID , schema ) => { return schemaService . saveSchema ( schemaID , schema ) ; } , deleteSchema : ( schemaID ) => { return schemaService . deleteSchema ( schemaID ) ; } , modifySchemaContent : ( schemaAdditions ) => { return schemaService . addContent ( schemaAdditions ) ; } , deleteSchemaContent : ( schemaDeletions ) => { return schemaService . deleteContent ( schemaDeletions ) ; } , deleteSchemasWhole : ( schemaDeletions ) => { return schemaService . deleteSchemas ( schemaDeletions ) ; } , getFoldingRanges , getCodeAction : ( document , params ) => { return yamlCodeActions . getCodeAction ( document , params ) ; } , getCodeLens : ( document , params ) => { return yamlCodeLens . getCodeLens ( document , params ) ; } , resolveCodeLens : ( param ) => yamlCodeLens . resolveCodeLens ( param ) , } ; }