<commit_before>'use strict';

import * as path from 'path';
import * as child_process from 'child_process';

import { workspace, Disposable, ExtensionContext, window } from 'vscode';
import { LanguageClient, LanguageClientOptions, SettingMonitor, ServerOptions, TransportKind } from 'vscode-languageclient';

export function activate(context: ExtensionContext) {
    console.log('Activating qore-vscode extension');

    // Command-line arguments
    let serverArgs = ['qls/qls.q'];
    let debugServerArgs = ['qls/qls.q'];

    // Language server options
    let serverOptions: ServerOptions;
    let DEV_MODE = false;
    if (DEV_MODE) {
        serverOptions = () => new Promise<child_process.ChildProcess>((resolve, reject) => {
            function spawnServer(...args: string[]): child_process.ChildProcess {
                let childProcess = child_process.spawn('qore', serverArgs);
                childProcess.stderr.on('data', data => { console.log(`stderr: ${data}`); });
                childProcess.stdout.on('data', data => { console.log(`stdout: ${data}`); });
                return childProcess; // Uses stdin/stdout for communication
            }

            resolve(spawnServer())
        });
    }
    else {
        serverOptions = {
            run: {command: 'qore', args: serverArgs/*, opts: serverOpts */},
            debug: {command: 'qore', args: debugServerArgs/*, opts: debugServerOpts */}
        }
    }

    // Options to control the language client
    let clientOptions: LanguageClientOptions = {
        // Docs regarding documentSelector:
        // https://code.visualstudio.com/Docs/extensionAPI/vscode-api#DocumentSelector
        // https://code.visualstudio.com/Docs/extensionAPI/vscode-api#DocumentFilter
        documentSelector: ['qore'],
        synchronize: {
            // Synchronize the setting section 'qore' to the server
            configurationSection: 'qore',
            // Notify the server about file changes to qore files contained in the workspace
            fileEvents: [
                workspace.createFileSystemWatcher('**/*.q'),
                workspace.createFileSystemWatcher('**/*.qm'),
                workspace.createFileSystemWatcher('**/*.qtest'),
                workspace.createFileSystemWatcher('**/*.ql'),
                workspace.createFileSystemWatcher('**/*.qc'),
                workspace.createFileSystemWatcher('**/*.qsd'),
                workspace.createFileSystemWatcher('**/*.qfd'),
                workspace.createFileSystemWatcher('**/*.qwf'),
                workspace.createFileSystemWatcher('**/*.qjob'),
                workspace.createFileSystemWatcher('**/*.qclass'),
                workspace.createFileSystemWatcher('**/*.qconst'),
                workspace.createFileSystemWatcher('**/*.qsm')
            ]
        }
    }

    // Create the language client and start the client.
    let lc = new LanguageClient('qls', 'Qore Language Server', serverOptions, clientOptions);
    let disposable = lc.start();
    console.log('Started qls');

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

// this method is called when your extension is deactivated
export function deactivate() {
}
<commit_msg>Added check for Qore and astparser module to the extension, so that QLS won't be run if they're not present.<commit_after>'use strict';

import * as path from 'path';
import * as vscode from 'vscode';
import * as child_process from 'child_process';

import { workspace, Disposable, ExtensionContext, window } from 'vscode';
import { LanguageClient, LanguageClientOptions, SettingMonitor, ServerOptions, TransportKind } from 'vscode-languageclient';

export function activate(context: ExtensionContext) {
    console.log('Activating qore-vscode extension');

    // Find out if Qore and the astparser module are present.
    let results = child_process.spawnSync("qore", ["-ne", "%requires astparser\nint x = 1; x++;"]);
    let qlsOk = false;
    /*if (results.status == 0)
        qlsOk = true;*/

    // Language server command-line arguments
    let extensionDir = vscode.extensions.getExtension("qoretechnologies.qore-vscode").extensionPath;
    let serverArgs = [extensionDir + '/qls/qls.q'];
    let debugServerArgs = [extensionDir + '/qls/qls.q'];

    // Language server options
    let serverOptions: ServerOptions;
    let DEV_MODE = false;
    if (DEV_MODE) {
        serverOptions = () => new Promise<child_process.ChildProcess>((resolve, reject) => {
            function spawnServer(...args: string[]): child_process.ChildProcess {
                let childProcess = child_process.spawn('qore', serverArgs);
                childProcess.stderr.on('data', data => { console.log(`stderr: ${data}`); });
                childProcess.stdout.on('data', data => { console.log(`stdout: ${data}`); });
                return childProcess; // Uses stdin/stdout for communication
            }

            resolve(spawnServer())
        });
    }
    else {
        serverOptions = {
            run: {command: 'qore', args: serverArgs/*, opts: serverOpts */},
            debug: {command: 'qore', args: debugServerArgs/*, opts: debugServerOpts */}
        }
    }

    // Options to control the language client
    let clientOptions: LanguageClientOptions = {
        // Docs regarding documentSelector:
        // https://code.visualstudio.com/Docs/extensionAPI/vscode-api#DocumentSelector
        // https://code.visualstudio.com/Docs/extensionAPI/vscode-api#DocumentFilter
        documentSelector: ['qore'],
        synchronize: {
            // Synchronize the setting section 'qore' to the server
            configurationSection: 'qore',
            // Notify the server about file changes to qore files contained in the workspace
            fileEvents: [
                workspace.createFileSystemWatcher('**/*.q'),
                workspace.createFileSystemWatcher('**/*.qm'),
                workspace.createFileSystemWatcher('**/*.qtest'),
                workspace.createFileSystemWatcher('**/*.ql'),
                workspace.createFileSystemWatcher('**/*.qc'),
                workspace.createFileSystemWatcher('**/*.qsd'),
                workspace.createFileSystemWatcher('**/*.qfd'),
                workspace.createFileSystemWatcher('**/*.qwf'),
                workspace.createFileSystemWatcher('**/*.qjob'),
                workspace.createFileSystemWatcher('**/*.qclass'),
                workspace.createFileSystemWatcher('**/*.qconst'),
                workspace.createFileSystemWatcher('**/*.qsm')
            ]
        }
    }

    let lc = new LanguageClient('qls', 'Qore Language Server', serverOptions, clientOptions);
    let disposable;

    // Create the language client and start the client.
    if (qlsOk) {
        disposable = lc.start();
        console.log('Started QLS');

        // Push the disposable to the context's subscriptions so that the
        // client can be deactivated on extension deactivation
        context.subscriptions.push(disposable);
    }
    else {
        console.log("Qore and/or astparser module are not present -> won't run QLS");
        vscode.window.showWarningMessage("Qore or Qore's astparser module are not present. Qore language server will not be started.");
    }
}

// this method is called when your extension is deactivated
export function deactivate() {
}

{'fraction_non_alphanumeric': 0.1254350736278447, 'fraction_numerical': 0.0002677376171352075, 'mean_word_length': 2.646168862859932, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 14, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6110414', 'n_tokens_mistral': 2036, 'n_tokens_neox': 1986, 'n_words': 489}