Select Git revision
ProBKernel.java
-
dgelessus authored
CommandUtils.splitArgs now takes an extra (optional) parameter to ask it to not split the entire argument string, but only up to the argument at the given offset in the string. The returned SplitResult contains information about which parameter the argument splitting stopped at. This is used in the new implementation of the inspection feature: when the kernel is asked to inspect at a certain position, the arguments are split up to that position, and the argument at that position is inspected. (The arguments are only split and not fully parsed, because inspection should be possible even if the command arguments are still incomplete or otherwise invalid.) This new implementation replaces the old separate implementation in CommandUtils.splitArgs.
dgelessus authoredCommandUtils.splitArgs now takes an extra (optional) parameter to ask it to not split the entire argument string, but only up to the argument at the given offset in the string. The returned SplitResult contains information about which parameter the argument splitting stopped at. This is used in the new implementation of the inspection feature: when the kernel is asked to inspect at a certain position, the arguments are split up to that position, and the argument at that position is inspected. (The arguments are only split and not fully parsed, because inspection should be possible even if the command arguments are still incomplete or otherwise invalid.) This new implementation replaces the old separate implementation in CommandUtils.splitArgs.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
extension.ts 2.90 KiB
import {
workspace,
ExtensionContext,
window,
TextEditor,
StatusBarAlignment,
OutputChannel,
} from 'vscode';
import {
LanguageClient,
LanguageClientOptions,
ServerOptions,
StreamInfo
} from 'vscode-languageclient';
import * as net from 'net';
import * as path from 'path'
import { spawn } from 'child_process';
let client: LanguageClient;
let debugChannle: OutputChannel = null;
export function activate(context: ExtensionContext) {
const serverHome = context.asAbsolutePath(path.join('node_modules', 'b-language-server', 'build', 'libs', 'b-language-server-all.jar'))
const javaHome: string = workspace.getConfiguration("common").get("javaHome")
let prc = spawn(javaHome, ['-jar', serverHome])
prc.stdout.on('data', function (data : Buffer) {
let portAsStringWithBrackets : String = data.toString()
let closingBracketPos : number = portAsStringWithBrackets.indexOf(">")
let portNumber : number = parseInt(portAsStringWithBrackets.substring(1, closingBracketPos))
let connectionInfo = {
port: portNumber,
}
let serverOptions: ServerOptions = () => {
let socket = net.connect(connectionInfo);
let result: StreamInfo = {
writer: socket,
reader: socket
};
return Promise.resolve(result);
}
if (debugChannle == null) {
debugChannle = window.createOutputChannel("ProB language server")
}
// Options to control the language client
let clientOptions: LanguageClientOptions = {
// Register the server for B files
documentSelector: [{ scheme: 'file', language: 'classicalb' }, { scheme: 'file', language: 'rmchAddOn' }],
synchronize: {
// Notify the server about file changes to '.clientrc files contained in the workspace
fileEvents: workspace.createFileSystemWatcher('**/.clientrc')
},
outputChannel: debugChannle,
}
// Create the language client and start the client.
client = new LanguageClient('languageServer', 'languageServer', serverOptions, clientOptions)
let item = window.createStatusBarItem(StatusBarAlignment.Right, Number.MIN_VALUE);
item.text = 'Starting ProB LSP...';
toggleItem(window.activeTextEditor, item);
let disposable = client.start();
context.subscriptions.push(disposable);
const debugMode: Boolean = workspace.getConfiguration("languageServer").get("debugMode")
if (!debugMode) {
debugChannle.hide()
} else {
debugChannle.show()
}
window.onDidOpenTerminal(() => {
showDebugMessages(debugChannle)
})
})
}
function showDebugMessages(debugChannle: OutputChannel) {
const debugMode: Boolean = workspace.getConfiguration("languageServer").get("debugMode")
if (debugMode) {
debugChannle.show()
}
}
export function deactivate(): Thenable<void> | undefined {
if (!client) {
return undefined;
}
return client.stop();
}
function toggleItem(editor: TextEditor, item) {
if (editor && editor.document &&
(editor.document.languageId === 'B')) {
item.show();
} else {
item.hide();
}
}