'use strict' ; import { FileInfo , ParsingProblem , ParsingProblemSeverity , utils } from 'pddl-workspace' ; import { Diagnostic , DiagnosticSeverity , Range } from 'vscode' ; import { URI } from 'vscode-uri' ; import { toRange } from '../utils' ; export function createRangeFromLine ( errorLine , errorColumn = 0 ) { return new Range ( errorLine , errorColumn , errorLine , errorColumn + 100 ) ; } export function createDiagnostic ( errorLine , errorColumn , error , severity ) { return new Diagnostic ( createRangeFromLine ( errorLine , errorColumn ) , error , severity ) ; } function toDiagnosticSeverity ( severity ) { switch ( severity ) { case "error" : return DiagnosticSeverity . Error ; case "warning" : return DiagnosticSeverity . Warning ; case "info" : return DiagnosticSeverity . Information ; case "hint" : return DiagnosticSeverity . Hint ; default : throw new Error ( "Unexpected severity: " + severity ) ; } } export function createDiagnosticFromParsingProblem ( problem ) { return new Diagnostic ( toRange ( problem . range ) , problem . problem , toDiagnosticSeverity ( problem . severity ) ) ; } export function toDiagnosticsFromParsingProblems ( problems ) { return problems . map ( p => createDiagnosticFromParsingProblem ( p ) ) ; } export function toDiagnostics ( parsingErrors , allParsed ) { const diagnostics = new Map < string , Diagnostic [ ] > ( ) ; parsingErrors . forEach ( ( problems , uri ) => diagnostics . set ( uri , toDiagnosticsFromParsingProblems ( problems ) ) ) ; allParsed . filter ( file => ! diagnostics . has ( file . fileUri . toString ( ) ) ) . forEach ( validFile => diagnostics . set ( validFile . fileUri . toString ( ) , [ ] ) ) ; return diagnostics ; }