diff --git a/README.md b/README.md index 8c5aad855d392ca755077d463a773fd69c5d097e..4ad0ac4a21a7eb334d3758dc8158c48f82fd27f6 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 3ac04d1a0007683c6701c166ecdbdded92c8f465..519db1b9bb5adff875b15a42183655c18e66dc00 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 6d316f6acb12149b6e36cb25dc8f3028dbb17792..c5306b05f1aa3ea583c6ccb533285d0721f2fe5b 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) }