From 0436b13c2061bd512586be012a777854e87be66c Mon Sep 17 00:00:00 2001
From: SeeBasTStick <sebastian.stock@hhu.de>
Date: Wed, 20 May 2020 10:56:21 +0200
Subject: [PATCH] added wd and strict option refactored server

---
 README.md            |  4 ++-
 package.json         | 12 +++++++++
 server/src/server.ts | 61 +++++++++++++++++++++++++-------------------
 3 files changed, 50 insertions(+), 27 deletions(-)

diff --git a/README.md b/README.md
index 8c5aad8..4ad0ac4 100644
--- a/README.md
+++ b/README.md
@@ -27,7 +27,9 @@ This extension contributes the following settings:
 ## Future plans
 - Linter Support
 - Keyword support
-- Quickfix support
+- Quickfix support aká Code Completion
+- WD Support
+
 
 ## Release Notes
 
diff --git a/package.json b/package.json
index 3ac04d1..519db1b 100644
--- a/package.json
+++ b/package.json
@@ -53,6 +53,18 @@
 					"type": "string",
 					"default": "~/prob_prolog/probcli.sh",
 					"description": "Path to ProB executable"
+				},
+				"languageServer.wdChecks": {
+					"scope": "window",
+					"type": "boolean",
+					"default": "off",
+					"description": "Option for WD Checks"
+				},
+				"languageServer.strictChecks": {
+					"scope": "window",
+					"type": "boolean",
+					"default": "off",
+					"description": "Option for stricter Checks"
 				}
 			}
 		}
diff --git a/server/src/server.ts b/server/src/server.ts
index 6d316f6..c5306b0 100644
--- a/server/src/server.ts
+++ b/server/src/server.ts
@@ -1,8 +1,3 @@
-/* --------------------------------------------------------------------------------------------
- * Copyright (c) Microsoft Corporation. All rights reserved.
- * Licensed under the MIT License. See License.txt in the project root for license information.
- * ------------------------------------------------------------------------------------------ */
-
 import {
 	createConnection,
 	TextDocuments,
@@ -26,6 +21,7 @@ import * as fs from 'fs';
 import {ErrorMatcher} from './ErrorMatcher';
 import * as wordComplition from './wordCompletion'
 import * as path from 'path';
+import { settings } from 'cluster';
 
 
 
@@ -92,12 +88,19 @@ connection.onInitialized(() => {
 
 // The settings
 interface Settings {
-	maxNumberOfProblems: number;
-	probHome : string;
+	maxNumberOfProblems: number
+	strictChecks : boolean
+	wdChecks : boolean
+	probHome : string
 }
 
 
-const defaultSettings: Settings = { maxNumberOfProblems: 1000, probHome: "/home/sebastian/prob_prolog/probcli.sh" };
+const defaultSettings: Settings = { 
+	maxNumberOfProblems: 1000, 
+	probHome: "/home/sebastian/prob_prolog/probcli.sh",
+	strictChecks : false,
+	wdChecks : false };
+
 let globalSettings: Settings = defaultSettings;
 
 // Cache the settings of all open documents
@@ -144,33 +147,22 @@ documents.onDidSave(change => {
 
 
 async function validateTextDocument(textDocument: TextDocument): Promise<void> {
-	let settings = await getDocumentSettings(textDocument.uri);
-	
-	let pathy:path.ParsedPath = path.parse(URI.parse(textDocument.uri).path);
+	let documentPath:path.ParsedPath = path.parse(URI.parse(textDocument.uri).path);
 
-	let dic:string = pathy.dir
-
-	console.log(settings.probHome)
-	
-	let probCliHome:string = settings.probHome
+	let errorPath:string = documentPath.dir+'/_error.json'
 
-
-	let ndjson:string = 'NDJSON_ERROR_LOG_FILE '
-	let errorPath:string = dic+'/_error.json'
 	const {exec} = require('child_process');
-	let command:string = probCliHome + ' -p MAX_INITIALISATIONS 0 -version -p STRICT_CLASH_CHECKING TRUE -p TYPE_CHECK_DEFINITIONS TRUE '
-	
-	fs.writeFile(errorPath, "", () =>{}) //Insure a clean error dictonary
-	let command2:string = command +  URI.parse(textDocument.uri).path + " -p " + ndjson + errorPath;
 	
+	fs.writeFile(errorPath, "", () =>{}) //Insure a clean error file
+
+	let command:string = getCommand(URI.parse(textDocument.uri).path, errorPath) 
 	
 	let diagnostics : Array<Diagnostic> = new Array()
 	let diagnosticsPromise : Promise<Set<Diagnostic>>
 
-	
-	if(correctPath(probCliHome))
+	if(correctPath(globalSettings.probHome))
 	{
-		exec(command2, (err:string, stdout:string, stderr:string) => {
+		exec(command, (err:string, stdout:string, stderr:string) => {
 		let bla = new ErrorMatcher()
 	    diagnosticsPromise =  bla.matchError(textDocument, errorPath)
 
@@ -185,6 +177,22 @@ async function validateTextDocument(textDocument: TextDocument): Promise<void> {
 
 }
 
+function getCommand(documentPath : string, errorPath : string) : string{
+	let wdCmd = ""
+	let strict = ""
+
+	if(globalSettings.wdChecks){
+		wdCmd = " -wd-check -release_java_parser"
+	}
+
+	if(globalSettings.strictChecks){
+		strict = " -p STRICT_CLASH_CHECKING TRUE -p TYPE_CHECK_DEFINITIONS TRUE -lint"
+	}
+
+	return globalSettings.probHome + ' -p MAX_INITIALISATIONS 0 -version' + strict + wdCmd + documentPath +" -p " + "NDJSON_ERROR_LOG_FILE " + errorPath
+}
+
+
 function correctPath(path:string): boolean{
 	try{
 		fs.accessSync(path)
@@ -198,6 +206,7 @@ function correctPath(path:string): boolean{
 
 // This handler provides the initial list of the completion items.
 connection.onCompletion(
+	
 	(textDocumentPosition: TextDocumentPositionParams): CompletionItem[] => {
 		return wordComplition.selectCompletion(textDocumentPosition)
 	}
-- 
GitLab