Skip to content
Snippets Groups Projects
Select Git revision
  • f5c0871eea793f77806eafaf0b9b8e0951269db4
  • develop default
  • release protected
  • v0.x
  • v2.2.0
  • v2.1.0
6 results

ErrorMatcher.ts

Blame
  • user avatar
    SeeBasTStick authored
    e6178cc9
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    ErrorMatcher.ts 1.15 KiB
    import { Diagnostic, DiagnosticSeverity } from 'vscode-languageserver'
    import { TextDocument } from 'vscode-languageserver-textdocument'
    import * as fs from 'fs';
    import * as readline from 'readline'
    
    
    export class ErrorMatcher{
    
    
    	async matchError(target:TextDocument, errorPath:string):Promise<Set<Diagnostic>>{
    		var diagnostics: Set<Diagnostic> = new Set()
    
    		var stream = fs.createReadStream( errorPath)
    		
    		const rl = readline.createInterface({
    			input: stream,
    			crlfDelay: Infinity
    		  });
    		
    		  for await (const line of rl) {
    			let obj:Error = JSON.parse(line)
    			
    			var diagnostic:Diagnostic = {
    				severity: DiagnosticSeverity.Error,
    				range: {
    					start: 
    					{
    						character: obj.error.start.col,
    						line:obj.error.start.line - 1
    					},
    					end: {
    						character:obj.error.end.col,
    						line :obj.error.end.line -1 
    					}
    
    				},
    				message: obj.error.message,
    				source: 'prob_prolog'
    			};
    			diagnostics.add(diagnostic)	  
    		}
    		return diagnostics
    	}
    }
    
    interface Error{
    	error : { 
    		message : string
    		type : string	
    		file : string
    		start : {
    			line :  number
    			col : number
    		}
    		end : {
    			line :  number
    			col : number
    		}
    	};	
    }