import { getLineMaxColumn , getLineMinColumn , ISyntaxDecorations , IWorkerContext , IWorkerModel , VAToken } from './common' ; import { VAStepLine } from './stepline' ; function groupDecoration ( lineNumber , style = undefined ) { return { range : { startLineNumber : lineNumber , startColumn : 1 , endLineNumber : lineNumber , endColumn : 1 } , options : { stickiness : 1 , glyphMarginClassName : "codicon-triangle-right" , inlineClassName : style , isWholeLine : style != undefined , } } ; } export function checkSyntax ( ctx , model , msg ) { const steps = { } ; const groups = [ ] ; const decorations = [ ] ; const problems = [ ] ; const lineCount = model . getLineCount ( ) ; let section = "" ; for ( let lineNumber = 1 ; lineNumber <= lineCount ; lineNumber ++ ) { const line = model . getLineContent ( lineNumber ) ; const token = model . getLineToken ( lineNumber ) ; switch ( token . token ) { case VAToken . Empty : case VAToken . Comment : case VAToken . Multiline : case VAToken . Parameter : case VAToken . Instruction : continue ; case VAToken . Section : section = ctx . matcher . getSection ( line ) ; continue ; case VAToken . Asterisk : decorations . push ( groupDecoration ( lineNumber ) ) ; continue ; } if ( section == "feature" || section == "variables" ) continue ; if ( ctx . matcher . metatags . test ( line ) ) { continue ; } const step = new VAStepLine ( ctx . matcher , line ) ; if ( step . keyword ) steps [ lineNumber ] = true ; const syntax = step . checkSyntax ( ctx , lineNumber , line ) ; if ( syntax . error ) problems . push ( { severity : 8 , message : ctx . messages . syntaxMsg , startLineNumber : lineNumber , endLineNumber : lineNumber , startColumn : getLineMinColumn ( line ) , endColumn : getLineMaxColumn ( line ) , } ) ; else if ( syntax . decoration ) { if ( syntax . decoration . options . inlineClassName ) { syntax . decoration . range = { startLineNumber : lineNumber , startColumn : getLineMinColumn ( line ) , endLineNumber : lineNumber , endColumn : getLineMaxColumn ( line ) , } ; } decorations . push ( syntax . decoration ) ; } else if ( token . folding ) { if ( ctx . matcher . stepkey . else . test ( line ) ) continue ; if ( ctx . matcher . stepkey . elseif . test ( line ) ) continue ; groups . push ( { lineNumber , folding : token . folding } ) ; } } groups . forEach ( e => { for ( let i = e . lineNumber + 1 ; i <= e . folding ; ++ i ) if ( steps [ i ] ) { decorations . push ( groupDecoration ( e . lineNumber , "vanessa-style-bold" ) ) ; break ; } } ) ; return { decorations , problems } ; }