Skip to content
Snippets Groups Projects
extension.ts 3.2 KiB
Newer Older
// tslint:disable
"use strict";

import { workspace, ExtensionContext } from 'vscode';
import * as vscode from 'vscode';
    LanguageClient,
    LanguageClientOptions,
    ServerOptions,
    Trace,
    TransportKind
} from 'vscode-languageclient/node';

let client: LanguageClient;
const paramHistory: Map<string, string> = new Map();

export function activate(context: ExtensionContext) {
    // The server is implemented in node
    let serverExe = "D:\\Desktop\\designproject\\modest-toolset\\Binaries\\Release\\win-x64\\Modest.LanguageServer.exe";
    // If the extension is launched in debug mode then the debug server options are used
    // Otherwise the run options are used
    let serverOptions: ServerOptions = {
        // run: { command: serverExe, args: ['-lsp', '-d'] },
        run: {
            command: serverExe,
            transport: TransportKind.pipe,
        },
        // debug: { command: serverExe, args: ['-lsp', '-d'] }
        debug: {
            command: serverExe,
            transport: TransportKind.pipe,
            runtime: "",
        },
    };
    // Options to control the language client
    let clientOptions: LanguageClientOptions = {
        // Register the server for plain text documents
        documentSelector: [
            {
                pattern: "**/*.modest",
            },
        ],
        progressOnInitialization: true,
        synchronize: {
            // Synchronize the setting section 'languageServerExample' to the server
            configurationSection: "languageServerExample",
            fileEvents: workspace.createFileSystemWatcher("**/*.modest"),
        },
    };
    // Simulate command
    let disposable = vscode.commands.registerCommand('extension.simulate', async () => {
        var fileName = vscode.window.activeTextEditor?.document.fileName;
        let parms = await vscode.window.showInputBox({
            prompt: "Enter run parameters",
            //TODO: refactor how we deal with nullability here (fileName should never be null anyway but w/e)
            value: fileName ? paramHistory.get(fileName) : undefined
        });

        if (parms === undefined) {
            return;
        }
        //TODO: refactor how we deal with nullability here (fileName should never be null anyway but w/e)
        if (fileName !== undefined) {
            paramHistory.set(fileName, parms);
        }
        let term = vscode.window.createTerminal("Modest simulation");
        term.sendText(`modest simulate ${fileName} ${parms}\n`);

        term.show(true);
    });

    context.subscriptions.push(disposable);








    // Create the language client and start the client.
    client = new LanguageClient(
        "ModestExtension",
        "Modest Extension",
        serverOptions,
        clientOptions);
    client.registerProposedFeatures();
    client.registerProposedFeatures();
    client.trace = Trace.Verbose;
    disposable = client.start();

    // Push the disposable to the context's subscriptions so that the
    // client can be deactivated on extension deactivation
    context.subscriptions.push(disposable);

export function deactivate(): Thenable<void> | undefined {
    if (!client) {
    }
    return client.stop();