<commit_before>'use strict';
import {IPCMessageReader, IPCMessageWriter, createConnection, IConnection, TextDocument, TextDocumentSyncKind, TextDocuments, Diagnostic, DiagnosticSeverity, InitializeParams, InitializeResult} from 'vscode-languageserver';
import {CompletionItem, CompletionItemKind, TextDocumentPositionParams} from 'vscode-languageserver';
import {Ledger} from 'ledger-cli';
import * as url from 'url';

let accounts : string[] = [];

let connection: IConnection = createConnection(new IPCMessageReader(process), new IPCMessageWriter(process));

connection.onCompletion((textDocumentPosition: TextDocumentPositionParams): CompletionItem[] => {
    return accounts.map((account, index) => {
        return {
            label: account,
            kind: CompletionItemKind.Text,
            data: index
        }
    })
});

let documents: TextDocuments = new TextDocuments();
documents.onDidChangeContent((change) =>{
    connection.console.info("Content changed")
    connection.console.info(change.document.getText())
    //TODO: ditch ledger-cli so issues can be reported in real time
    let diagnostics: Diagnostic[] = [];
    /*
    diagnostics.push({
        severity: DiagnosticSeverity.Error,
        range: {
            start: { line: 0, character: 0 },
            end: { line: 10, character: 10 }
        },                
        message: err,
        source: 'ledger'
    });
    connection.sendDiagnostics({ uri: change.document.uri, diagnostics });
    */
})

documents.onDidOpen(params => {
    let ledger = new Ledger({ file: decodeURI(url.parse(params.document.uri).path) });
    ledger.accounts().on('data', account => accounts.push(account))
})

documents.onDidSave((change) => {
    let ledger = new Ledger({ file: decodeURI(url.parse(change.document.uri).path) });
    ledger.stats((err, stat) => {
        if(err){
            connection.window.showErrorMessage(err)  
        }
    });
});

documents.listen(connection);

connection.onInitialize((params): InitializeResult => {
	return {
		capabilities: {
            //TODO: evaluate if this should be done incrementally
            textDocumentSync: documents.syncKind,
            completionProvider: {
                resolveProvider: false
            }
        }
    }
});

connection.listen();<commit_msg>Removed code that wasn't doing anything useful. It was a stub for the two features described in #5 and #6<commit_after>'use strict';
import {IPCMessageReader, IPCMessageWriter, createConnection, IConnection, TextDocument, TextDocumentSyncKind, TextDocuments, Diagnostic, DiagnosticSeverity, InitializeParams, InitializeResult} from 'vscode-languageserver';
import {CompletionItem, CompletionItemKind, TextDocumentPositionParams} from 'vscode-languageserver';
import {Ledger} from 'ledger-cli';
import * as url from 'url';

let accounts : string[] = [];

let connection: IConnection = createConnection(new IPCMessageReader(process), new IPCMessageWriter(process));

connection.onCompletion((textDocumentPosition: TextDocumentPositionParams): CompletionItem[] => {
    return accounts.map((account, index) => {
        return {
            label: account,
            kind: CompletionItemKind.Text,
            data: index
        }
    })
});

let documents: TextDocuments = new TextDocuments();

documents.onDidOpen(params => {
    let ledger = new Ledger({ file: decodeURI(url.parse(params.document.uri).path) });
    ledger.accounts().on('data', account => accounts.push(account))
})

documents.onDidSave((change) => {
    let ledger = new Ledger({ file: decodeURI(url.parse(change.document.uri).path) });
    ledger.stats((err, stat) => {
        if(err){
            connection.window.showErrorMessage(err)  
        }
    });
});

documents.listen(connection);

connection.onInitialize((params): InitializeResult => {
	return {
		capabilities: {
            //TODO: evaluate if this should be done incrementally
            textDocumentSync: documents.syncKind,
            completionProvider: {
                resolveProvider: false
            }
        }
    }
});

connection.listen();
{'fraction_non_alphanumeric': 0.12173700902659185, 'fraction_numerical': 0.0019516955354964625, 'mean_word_length': 3.3991416309012874, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, 'https://': 0, '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': '1582731', 'n_tokens_mistral': 1135, 'n_tokens_neox': 1100, 'n_words': 256}