import * as vscode from 'vscode' ; export function shouldProvideSchemaFor ( document ) { const overrideAnnotationText = findOverrideAnnotation ( document ) ; if ( overrideAnnotationText ) { const overrideAnnotation = parseOverrideAnnotation ( overrideAnnotationText ) ; if ( overrideAnnotation . exclude ) { return false ; } else if ( overrideAnnotation . include ) { return true ; } } return inferShouldProvideSchemaFor ( document ) ; } export function shouldSkip ( document ) { return ! shouldProvideSchemaFor ( document ) ; } interface OverrideAnnotation { readonly exclude ? : boolean ; readonly include ? : boolean ; } function inferShouldProvideSchemaFor ( _document ) { return true ; } function findOverrideAnnotation ( document ) { for ( const line of leadingComments ( document ) ) { const match = line . match ( /#\s*vscode-kubernetes-tools:\s*(.+)/ ) ; if ( match && match . length >= 2 ) { return match [ 1 ] ; } } return undefined ; } function parseOverrideAnnotation ( text ) { if ( text === 'exclude' ) { return { exclude : true } ; } else if ( text === 'include' ) { return { include : true } ; } else { return { } ; } } function * leadingComments ( document ) { for ( let i = 0 ; i < document . lineCount ; ++ i ) { const line = document . lineAt ( i ) ; if ( ! line ) { return ; } const lineText = line . text . trim ( ) ; if ( lineText . startsWith ( "#" ) ) { yield lineText ; } else if ( lineText . length === 0 ) { continue ; } else { return ; } } }