diff --git a/client/src/extension.ts b/client/src/extension.ts index 32890ee849e2941b7d5e1497de1bda9a681ca7cd..9caacc132b0def5517dcd54bc0d77d7fd0e47773 100644 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -39,7 +39,7 @@ export function activate(context: ExtensionContext) { // Options to control the language client let clientOptions: LanguageClientOptions = { // Register the server for B, EventB documents - documentSelector: [{ scheme: 'file', language: 'B' }, { scheme: 'file', language: 'EventB' }], + documentSelector: [{ scheme: 'file', language: 'plaintext' }], synchronize: { // Notify the server about file changes to '.clientrc files contained in the workspace fileEvents: workspace.createFileSystemWatcher('**/.clientrc') diff --git a/package-lock.json b/package-lock.json index 129d1026c845c30cda5f77afedc15ec49d0e7559..00d68cc6d384e2eb40257dc66531ff4451e1b013 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2267,6 +2267,11 @@ } } }, + "without": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/without/-/without-1.2.3.tgz", + "integrity": "sha1-xGXfzUWLuIvLNCy3j8otmA64TGg=" + }, "word-wrap": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", diff --git a/package.json b/package.json index 78af215c83039f1ab51ee357aa8dc488214d4a75..0d10243cd549fed2aa30dd8ea312f3cdde567ba1 100644 --- a/package.json +++ b/package.json @@ -24,8 +24,7 @@ "proB" ], "activationEvents": [ - "onLanguage:B", - "onLanguage:EventB" + "onLanguage:plaintext" ], "main": "./client/out/extension", "contributes": { @@ -67,26 +66,15 @@ "type": "boolean", "default": false, "description": "Option for stricter Checks" + }, + "languageServer.performanceInfo": { + "scope": "window", + "type": "boolean", + "default": false, + "description": "Option for preformance Info" } } - }, - "languages": [ - { - "id": "B", - "extensions": [ - ".mch", - ".ref", - ".imp", - ".def" - ] - }, - { - "id": "EventB", - "extensions": [ - ".sys" - ] - } - ] + } }, "scripts": { "vscode:prepublish": "npm run compile", @@ -115,6 +103,7 @@ "stream-to-array": "^2.3.0", "ts-xor": "^1.0.8", "vscode-api": "0.0.0", - "vscode-uri": "^2.1.1" + "vscode-uri": "^2.1.1", + "without": "^1.2.3" } } diff --git a/server/src/ErrorMatcher.ts b/server/src/ErrorMatcher.ts index bbb1889512e78ef2d95dd33cebed9bf693aa18b4..c977262461da7cb2e50b835d66308e0b44b1f532 100644 --- a/server/src/ErrorMatcher.ts +++ b/server/src/ErrorMatcher.ts @@ -2,89 +2,107 @@ import { Diagnostic, DiagnosticSeverity } from 'vscode-languageserver' import { TextDocument } from 'vscode-languageserver-textdocument' import * as fs from 'fs'; import * as readline from 'readline' -import {XOR} from 'ts-xor' -export class ErrorMatcher{ +export class ErrorMatcher { - async matchError(target:TextDocument, errorPath:string):Promise<Set<Diagnostic>>{ + async matchError(target: TextDocument, errorPath: string): Promise<Set<Diagnostic>> { var diagnostics: Set<Diagnostic> = new Set() - var stream = fs.createReadStream( errorPath) - + var stream = fs.createReadStream(errorPath) + const rl = readline.createInterface({ input: stream, crlfDelay: Infinity - }); - - - - for await (const line of rl) { - let obj : XOR<Error, Warning> = JSON.parse(line) - let diagnostic : Diagnostic - console.log(obj) - - let serveity : DiagnosticSeverity - let content : ErrorOrWarning - if(obj.error ){ - content = obj.error - serveity = DiagnosticSeverity.Error - } - else{ - if(obj.warning){ - content = obj.warning - serveity = DiagnosticSeverity.Warning - }else{ - throw new Error("Parsed Object is neither Warning nor Error - this is wrong") + }); + + + for await (const line of rl) { + + try { + let obj: XOR3<Error, Warning, Information> = JSON.parse(line) + + let diagnostic: Diagnostic + let serveity: DiagnosticSeverity + let content: JBody + + if (obj.error) { + content = obj.error + serveity = DiagnosticSeverity.Error + } + else { + if (obj.warning) { + content = obj.warning + serveity = DiagnosticSeverity.Warning + } else { + content = obj.information + serveity = DiagnosticSeverity.Information + } } - } - diagnostic = { - severity: serveity, - range: { - start: - { - character: content.start.col, - line: content.start.line - 1 - }, - end: { - character:content.end.col, - line :content.end.line -1 + diagnostic = { + severity: serveity, + range: { + start: + { + character: content.start.col, + line: content.start.line - 1 + }, + end: { + character: content.end.col, + line: content.end.line - 1 } }, message: content.message, source: 'prob_prolog' - }; - diagnostics.add(diagnostic) + }; + diagnostics.add(diagnostic) + } + catch (e) { + throw new Error("unexpected syntax while parsing _error.json") + } } return diagnostics + } } +export declare type XOR3<T, U, V> = (T | U | V) extends object ? ((Without<T, U> & U) & (Without<V, U> & U)) | + ((Without<V, T> & T) & (Without<U, T> & T)) | + ((Without<T, V> & V) & (Without<U, V> & V)) : T | U | V; + -export interface Error{ - error : ErrorOrWarning; - +export declare type Without<T, U> = { + [P in Exclude<keyof T, keyof U>]?: never; +}; + +export interface Information { + information: JBody } -export interface Warning{ - warning : ErrorOrWarning + +export interface Error { + error: JBody; + } -export interface ErrorOrWarning { +export interface Warning { + warning: JBody +} + +export interface JBody { message: string; type: string; file: string; start: StartOrEnd; end: StartOrEnd; - } +} - export interface StartOrEnd { +export interface StartOrEnd { line: number; col: number; - } - - \ No newline at end of file +} + diff --git a/server/src/server.ts b/server/src/server.ts index da95a955f402ea57a2be86e814ec5bc33ca3d909..94090063d14d980c506962f6088b25a89608935f 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -89,6 +89,7 @@ interface Settings { maxNumberOfProblems: number strictChecks : boolean wdChecks : boolean + performanceCheck : boolean probHome : string } @@ -97,7 +98,8 @@ const defaultSettings: Settings = { maxNumberOfProblems: 1000, probHome: "~/prob_prolog/probcli.sh", strictChecks : false, - wdChecks : false }; + wdChecks : false, + performanceCheck : false }; let globalSettings: Settings = defaultSettings; @@ -181,6 +183,7 @@ async function validateTextDocument(textDocument: TextDocument): Promise<void> { function getCommand(documentPath : string, errorPath : string, settings: Settings) : string{ let wdCmd = "" let strict = "" + let performanceCheck = "" if(settings.wdChecks == true){ wdCmd = " -wd-check -release_java_parser " } @@ -189,7 +192,11 @@ function getCommand(documentPath : string, errorPath : string, settings: Setting strict = " -p STRICT_CLASH_CHECKING TRUE -p TYPE_CHECK_DEFINITIONS TRUE -lint " } - return settings.probHome + ' -p MAX_INITIALISATIONS 0 -version ' + strict + wdCmd + documentPath +" -p " + "NDJSON_ERROR_LOG_FILE " + errorPath + if(settings.strictChecks == true){ + performanceCheck = " -p PERFORMANCE_INFO TRUE " + } + + return settings.probHome + ' -p MAX_INITIALISATIONS 0 -version ' + strict + wdCmd + performanceCheck + documentPath +" -p " + "NDJSON_ERROR_LOG_FILE " + errorPath }