import { CodeAction , CodeActionContext , Command , Range , Selection , Uri } from "vscode" ; import { templateKeys } from "../../../common" ; import { INamedDefinition } from '../../language/INamedDefinition' ; import { Issue } from '../../language/Issue' ; import * as Json from "../../language/json/JSON" ; import { ReferenceList } from "../../language/ReferenceList" ; import { CachedValue } from '../../util/CachedValue' ; import { expectTemplateDocument , expectTemplateDocumentOrUndefined } from '../../util/expectDocument' ; import { DeploymentDocument , ResolvableCodeLens } from "../DeploymentDocument" ; import { ParametersPositionContext } from "../positionContexts/ParametersPositionContext" ; import { isParametersSchema } from "../templates/schemas" ; import { IParameterValuesSource } from './IParameterValuesSource' ; import { IParameterValuesSourceProvider } from './IParameterValuesSourceProvider' ; import { ParameterValueDefinition } from "./ParameterValueDefinition" ; import { getMissingParameterErrors , getParameterValuesCodeActions } from "./ParameterValues" ; import { ParameterValuesSourceFromJsonObject } from "./ParameterValuesSourceFromJsonObject" ; /**
 * Represents a deployment parameter file
 */ export class DeploymentParametersDoc extends DeploymentDocument { private _parameterValueDefinitions : CachedValue < ParameterValueDefinition [ ] > = new CachedValue < ParameterValueDefinition [ ] > ( ) ; private _parametersProperty : CachedValue < Json . Property | undefined > = new CachedValue < Json . Property | undefined > ( ) ; private _parameterValuesSource : CachedValue < IParameterValuesSource > = new CachedValue < IParameterValuesSource > ( ) ; param _documentText param _documentUri constructor ( documentText , documentUri , public readonly documentVersion ) { super ( documentText , documentUri , documentVersion ) ; } public hasParametersSchema ( ) { return isParametersSchema ( this . schemaUri ) ; } public get topLevelParameterValuesSource ( ) : IParameterValuesSource { return this . _parameterValuesSource . getOrCacheValue ( ( ) => { return new ParameterValuesSourceFromJsonObject ( this , this . parametersProperty , this . topLevelValue ) ; } ) ; } public getParameterValue ( parameterName ) { const parameterNameLC = parameterName . toLowerCase ( ) ; for ( let param of this . parameterValueDefinitions ) { if ( param . nameValue . unquotedValue . toLowerCase ( ) === parameterNameLC ) { return param ; } } return undefined ; } public get parameterValueDefinitions ( ) : ParameterValueDefinition [ ] { return this . _parameterValueDefinitions . getOrCacheValue ( ( ) => { const parameterDefinitions = [ ] ; for ( const parameter of this . parametersObjectValue ?. properties || [ ] ) { parameterDefinitions . push ( new ParameterValueDefinition ( parameter ) ) ; } return parameterDefinitions ; } ) ; } public get parametersProperty ( ) : Json . Property | undefined { return this . _parametersProperty . getOrCacheValue ( ( ) => { return this . topLevelValue ?. getProperty ( templateKeys . parameters ) ; } ) ; } public get parametersObjectValue ( ) : Json . ObjectValue | undefined { return Json . asObjectValue ( this . parametersProperty ?. value ) ; } public getContextFromDocumentLineAndColumnIndexes ( documentLineIndex , documentColumnIndex , associatedTemplate ) { return ParametersPositionContext . fromDocumentLineAndColumnIndices ( this , documentLineIndex , documentColumnIndex , expectTemplateDocumentOrUndefined ( associatedTemplate ) ) ; } public getContextFromDocumentCharacterIndex ( documentCharacterIndex , associatedDocument ) { return ParametersPositionContext . fromDocumentCharacterIndex ( this , documentCharacterIndex , expectTemplateDocumentOrUndefined ( associatedDocument ) ) ; } public findReferencesToDefinition ( definition ) { const results = new ReferenceList ( definition . definitionKind ) ; if ( definition . nameValue ) { const paramValue = this . getParameterValue ( definition . nameValue . unquotedValue ) ; if ( paramValue ) { results . add ( { document : this , span : paramValue . nameValue . unquotedSpan } ) ; } } return results ; } public getCodeLenses ( _parameterValuesSourceProvider ) { return [ ] ; } public getCodeActions ( associatedDocument , range , context ) { const template = expectTemplateDocumentOrUndefined ( associatedDocument ) ; if ( template ) { return getParameterValuesCodeActions ( this . topLevelParameterValuesSource , template . topLevelScope . parameterDefinitionsSource , undefined , range , context ) ; } return [ ] ; } public getErrorsCore ( associatedDocument ) { if ( ! associatedDocument ) { return [ ] ; } const template = expectTemplateDocument ( associatedDocument ) ; return getMissingParameterErrors ( this . topLevelParameterValuesSource , template . topLevelScope . parameterDefinitionsSource ) ; } public getWarnings ( ) { return [ ] ; } }