diff --git a/client/src/extension.ts b/client/src/extension.ts index ae78b89335c9aaa94d44719476137e6179a513a1..b67c3347365184776f584234a70c8f1cec787b56 100644 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -17,7 +17,6 @@ let client: LanguageClient; export function activate(context: ExtensionContext) { // The server is implemented in node - console.log("test") let serverModule = context.asAbsolutePath( path.join('server', 'out', 'server.js') ); @@ -54,11 +53,22 @@ export function activate(context: ExtensionContext) { clientOptions ); + client.onReady().then(() => { + client.onNotification("path_error_prob", (message:string) => { + console.log(message); + }); + client.onNotification("parse_error_prob", (message:string) => { + console.log(message); + }); + }); + //context.subscriptions.push(client.start()); + // Start the client. This will also launch the server client.start(); console.log("Client started") } + export function deactivate(): Thenable<void> | undefined { if (!client) { return undefined; diff --git a/package.json b/package.json index ca1c01c043707a27779384e1973ce612fa4a001b..17229c9714fc9c1f6fc3e554ba98e0879aa57e70 100644 --- a/package.json +++ b/package.json @@ -23,8 +23,7 @@ "proB" ], "activationEvents": [ - "onLanguage:B", - "onLanguage:eventB" + "onLanguage:plaintext" ], "main": "./client/out/extension", "contributes": { diff --git a/server/src/server.ts b/server/src/server.ts index 23cc5eb620655c1bd14d383a546a494413a19ea6..f73ef1d2474c1ccf563c736e25bb0c25635f3256 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -14,7 +14,9 @@ import { CompletionItemKind, TextDocumentPositionParams, TextDocumentSyncKind, - InitializeResult + InitializeResult, + NotificationType0, + PublishDiagnosticsNotification } from 'vscode-languageserver'; @@ -24,8 +26,9 @@ import { import { URI } from 'vscode-uri'; import * as fs from 'fs'; -import {ErrorMatcher} from './ErrorMatcher' -import * as path from 'path' +import {ErrorMatcher} from './ErrorMatcher'; +import * as path from 'path'; + // Create a connection for the server. The connection uses Node's IPC as a transport. // Also include all preview / proposed LSP features. @@ -39,6 +42,7 @@ let hasConfigurationCapability: boolean = false; let hasWorkspaceFolderCapability: boolean = false; let hasDiagnosticRelatedInformationCapability: boolean = false; + connection.onInitialize((params: InitializeParams) => { let capabilities = params.capabilities; @@ -87,27 +91,25 @@ connection.onInitialized(() => { } }); -// The example settings -interface ExampleSettings { +// The settings +interface Settings { maxNumberOfProblems: number; probHome : string; } -// The global settings, used when the `workspace/configuration` request is not supported by the client. -// Please note that this is not the case when using this server with the client provided in this example -// but could happen with other clients. -const defaultSettings: ExampleSettings = { maxNumberOfProblems: 1000, probHome: "/home/sebastian/prob_prolog/probcli.sh" }; -let globalSettings: ExampleSettings = defaultSettings; + +const defaultSettings: Settings = { maxNumberOfProblems: 1000, probHome: "/home/sebastian/prob_prolog/probcli.sh" }; +let globalSettings: Settings = defaultSettings; // Cache the settings of all open documents -let documentSettings: Map<string, Thenable<ExampleSettings>> = new Map(); +let documentSettings: Map<string, Thenable<Settings>> = new Map(); connection.onDidChangeConfiguration(change => { if (hasConfigurationCapability) { // Reset all cached document settings documentSettings.clear(); } else { - globalSettings = <ExampleSettings>( + globalSettings = <Settings>( (change.settings.languageServer || defaultSettings) ); } @@ -116,7 +118,7 @@ connection.onDidChangeConfiguration(change => { documents.all().forEach(validateTextDocument); }); -function getDocumentSettings(resource: string): Thenable<ExampleSettings> { +function getDocumentSettings(resource: string): Thenable<Settings> { if (!hasConfigurationCapability) { return Promise.resolve(globalSettings); } @@ -148,7 +150,6 @@ documents.onDidChangeContent(change => { }); async function validateTextDocument(textDocument: TextDocument): Promise<void> { - // In this simple example we get the settings for every validate run. let settings = await getDocumentSettings(textDocument.uri); let pathy:path.ParsedPath = path.parse(URI.parse(textDocument.uri).path); @@ -157,7 +158,8 @@ async function validateTextDocument(textDocument: TextDocument): Promise<void> { console.log(settings.probHome) - let probCliHome:string = settings.probHome//'/home/sebastian/prob_prolog/probcli.sh' + let probCliHome:string = settings.probHome + let ndjson:string = 'NDJSON_ERROR_LOG_FILE ' let errorPath:string = dic+'/_error.json' @@ -172,6 +174,7 @@ async function validateTextDocument(textDocument: TextDocument): Promise<void> { let diagnosticsPromise : Promise<Set<Diagnostic>> + console.log(command2) exec(command2, (err:string, stdout:string, stderr:string) => { let bla = new ErrorMatcher() diagnosticsPromise = bla.matchError(textDocument, errorPath) @@ -180,15 +183,25 @@ async function validateTextDocument(textDocument: TextDocument): Promise<void> { console.log("success") diagnostics = Array.from(result) connection.sendDiagnostics({ uri: textDocument.uri, diagnostics}); - + }, function(err){ + connection.sendNotification("parse_error_prob", "there are things wrong with the parse results " + err) connection.sendDiagnostics({ uri: textDocument.uri, diagnostics}) }) }); + } +function correctPath(path:string): boolean{ + fs.access(path, (err) => { + connection.sendNotification("path_error_prob", path + " seems to be the wrong path to ProB") + return false + }) + + return true +} connection.onDidChangeWatchedFiles(_change => { // Monitored files have change in VSCode @@ -199,17 +212,16 @@ connection.onDidChangeWatchedFiles(_change => { // This handler provides the initial list of the completion items. connection.onCompletion( + (textDocumentPosition: TextDocumentPositionParams): CompletionItem[] => { - // The pass parameter contains the position of the text document in - // which code complete got requested. For the example we ignore this - // info and always provide the same completion items. - // console.log("textpos" + textDocumentPosition); + return [ { label: 'MACHINE', kind: CompletionItemKind.Text, data: 1 }, + { label: 'VARIABLES', kind: CompletionItemKind.Text, @@ -224,7 +236,8 @@ connection.onCompletion( label: 'OPERATIONS', kind: CompletionItemKind.Text, data: 4 - } + }, + ]; } );