mirror of
				https://github.com/We-Dont-Byte/Mind_Reader.git
				synced 2025-02-04 10:38:42 +00:00 
			
		
		
		
	js -> ts migration
.js files ended up getting uploaded, beginnings of attempting to fix that mistake. Migrating changes made in .js file to .ts file
This commit is contained in:
		@@ -1,5 +1,7 @@
 | 
			
		||||
"use strict";
 | 
			
		||||
Object.defineProperty(exports, "__esModule", { value: true });
 | 
			
		||||
Object.defineProperty(exports, "__esModule", {
 | 
			
		||||
    value: true
 | 
			
		||||
});
 | 
			
		||||
exports.textCommands = void 0;
 | 
			
		||||
 | 
			
		||||
const vscode = require("vscode");
 | 
			
		||||
@@ -49,37 +51,34 @@ function getLineNumber() {
 | 
			
		||||
    if (editor) {
 | 
			
		||||
        let lineNum = fetchLineNumber(editor);
 | 
			
		||||
        vscode.window.showInformationMessage(`Line ${lineNum.toString()}`);
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
    } else {
 | 
			
		||||
        vscode.window.showErrorMessage('No document currently active');
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function getIndent() {
 | 
			
		||||
    let editor = vscode.window.activeTextEditor;
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    if (editor) {
 | 
			
		||||
        let lineNum = fetchLineNumber(editor);
 | 
			
		||||
        let textLine = fetchTextLine(editor);
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        if (textLine.isEmptyOrWhitespace) {
 | 
			
		||||
            vscode.window.showInformationMessage(`"Line ${lineNum.toString()} is Empty`);
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            vscode.window.showInformationMessage(`Line ${lineNum.toString()} is Empty`);
 | 
			
		||||
        } else {
 | 
			
		||||
            // Grab tab format from open document
 | 
			
		||||
            let tabFmt = {
 | 
			
		||||
                size: editor.options.tabSize,
 | 
			
		||||
                hard: !editor.options.insertSpaces
 | 
			
		||||
            };
 | 
			
		||||
            let i = pl.Lexer.getIndent(textLine.text, tabFmt);
 | 
			
		||||
            
 | 
			
		||||
            // Ternary operator to change the tense of 'indent' to 'indents' for the output if i is greater than 1
 | 
			
		||||
            (i > 1) ? 
 | 
			
		||||
                vscode.window.showInformationMessage(`Line ${lineNum.toString()}: ${i.toString()} indents`) : 
 | 
			
		||||
 | 
			
		||||
            /* Ternary operator to change the tense of 'indent' to 'indents' for the output if i is 0 or greater than 1 */
 | 
			
		||||
            (i !== 1) ?
 | 
			
		||||
            vscode.window.showInformationMessage(`Line ${lineNum.toString()}: ${i.toString()} indents`):
 | 
			
		||||
                vscode.window.showInformationMessage(`Line ${lineNum.toString()}: ${i.toString()} indent`);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
    } else {
 | 
			
		||||
        vscode.window.showErrorMessage('No document currently active');
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -106,11 +105,10 @@ function getLeadingSpaces() {
 | 
			
		||||
    if (editor) {
 | 
			
		||||
        const lineNum = fetchLineNumber(editor);
 | 
			
		||||
        const textLine = fetchTextLine(editor);
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        if (textLine.isEmptyOrWhitespace) {
 | 
			
		||||
            vscode.window.showInformationMessage(`Line ${lineNum.toString()} is empty`);
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
        } else {
 | 
			
		||||
            /*
 | 
			
		||||
             * set  true to use method 1: find the number of leading spaces through arithmetic
 | 
			
		||||
             * set false to use method 2: find the index position of the first non-whitespace character in a 0-index
 | 
			
		||||
@@ -121,21 +119,20 @@ function getLeadingSpaces() {
 | 
			
		||||
            const numSpaces = (calculateLeadingSpaces === true) ?
 | 
			
		||||
                pl.Lexer.getLeadingSpacesByArithmetic(textLine) :
 | 
			
		||||
                pl.Lexer.getLeadingSpacesByIndex(textLine);
 | 
			
		||||
            
 | 
			
		||||
            /* Ternary operator to change the tense of 'space' to 'spaces' for the output if numSpaces is greater than 1 */
 | 
			
		||||
            (numSpaces > 1) ? 
 | 
			
		||||
                vscode.window.showInformationMessage(`Line ${lineNum.toString()}: ${numSpaces.toString()} spaces`) : 
 | 
			
		||||
 | 
			
		||||
            /* Ternary operator to change the tense of 'space' to 'spaces' for the output if numSpaces is 0 or greater than 1 */
 | 
			
		||||
            (numSpaces !== 1) ?
 | 
			
		||||
            vscode.window.showInformationMessage(`Line ${lineNum.toString()}: ${numSpaces.toString()} spaces`):
 | 
			
		||||
                vscode.window.showInformationMessage(`Line ${lineNum.toString()}: ${numSpaces.toString()} space`);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
    } else {
 | 
			
		||||
        vscode.window.showErrorMessage('No document currently active');
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function runLineContext() {
 | 
			
		||||
    let editor = vscode.window.activeTextEditor;
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    if (editor) {
 | 
			
		||||
        // current text and line number
 | 
			
		||||
        let editorText = editor.document.getText();
 | 
			
		||||
@@ -144,15 +141,17 @@ function runLineContext() {
 | 
			
		||||
        let size = parseInt(editor.options.tabSize);
 | 
			
		||||
        let hard = !editor.options.insertSpaces;
 | 
			
		||||
        // initialize parser
 | 
			
		||||
        let parser = new pl.Parser(editorText, { size, hard });
 | 
			
		||||
        let parser = new pl.Parser(editorText, {
 | 
			
		||||
            size,
 | 
			
		||||
            hard
 | 
			
		||||
        });
 | 
			
		||||
        parser.parse();
 | 
			
		||||
        let context = parser.context(line);
 | 
			
		||||
        // build text
 | 
			
		||||
        let contentString = createContextString(context, line);
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        vscode.window.showInformationMessage(contentString);
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
    } else {
 | 
			
		||||
        vscode.window.showErrorMessage('No document currently active');
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -161,22 +160,22 @@ function createContextString(context, line) {
 | 
			
		||||
    if (context.length < 1) {
 | 
			
		||||
        throw new Error('Cannot create context string for empty context');
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    let contextString = 'Line ' + (line + 1); // 1 based
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    if (context[0].token && context[0].token.attr) {
 | 
			
		||||
        contextString += ': ' + context[0].token.type.toString() + ' ' + context[0].token.attr.toString();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    for (let i = 1; i < context.length; i++) {
 | 
			
		||||
        let node = context[i];
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        if (node.label === 'root') {
 | 
			
		||||
            // root
 | 
			
		||||
            contextString += ' in the Document Root';
 | 
			
		||||
            continue;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
 | 
			
		||||
        if (node.token.type !== pl.PylexSymbol.EMPTY &&
 | 
			
		||||
            node.token.type !== pl.PylexSymbol.INDENT) {
 | 
			
		||||
            contextString += ' inside ' + node.token.type.toString();
 | 
			
		||||
@@ -192,12 +191,12 @@ function createContextString(context, line) {
 | 
			
		||||
// the value of `#mindReader.reader.contextWindow`
 | 
			
		||||
function runCursorContext() {
 | 
			
		||||
    let editor = vscode.window.activeTextEditor;
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    if (!editor) {
 | 
			
		||||
        vscode.window.showErrorMessage('RunCursorContext: No Active Editor');
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    const cursorPos = editor.selection.active;
 | 
			
		||||
    const text = editor.document.lineAt(cursorPos).text;
 | 
			
		||||
    const windowSize = vscode.workspace.getConfiguration('mindReader').get('reader.contextWindow');
 | 
			
		||||
@@ -208,24 +207,27 @@ function runCursorContext() {
 | 
			
		||||
    let maxPos = text.length;
 | 
			
		||||
    // clamp cursor start/end to new range
 | 
			
		||||
    let col = cursorPos.character; // effective column of the cursor position
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    if (col < leadingWS) {
 | 
			
		||||
        // move effective start to first non-whitespace character in the line
 | 
			
		||||
        col = leadingWS;
 | 
			
		||||
    }
 | 
			
		||||
    else if (col > leadingWS + trimmedText.length - 1) {
 | 
			
		||||
    } else if (col > leadingWS + trimmedText.length - 1) {
 | 
			
		||||
        // move effective end to last non-whitespace character in the line
 | 
			
		||||
        col = leadingWS + trimmedText.length - 1;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    // generate list of space separate words with range data (start, end)
 | 
			
		||||
    // TODO: can find user position to be done in one pass
 | 
			
		||||
    let spaceWords = [];
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    while (pos < maxPos && trimmedText.length > 0) {
 | 
			
		||||
        let word = trimmedText.replace(/ .*/, '');
 | 
			
		||||
    
 | 
			
		||||
        spaceWords.push({ word, start: pos, end: pos + word.length });
 | 
			
		||||
 | 
			
		||||
        spaceWords.push({
 | 
			
		||||
            word,
 | 
			
		||||
            start: pos,
 | 
			
		||||
            end: pos + word.length
 | 
			
		||||
        });
 | 
			
		||||
        // remove processed word from trimmed text
 | 
			
		||||
        const oldText = trimmedText;
 | 
			
		||||
        trimmedText = trimmedText.replace(/[^ ]+/, '').trimStart();
 | 
			
		||||
@@ -233,8 +235,9 @@ function runCursorContext() {
 | 
			
		||||
        pos += oldText.length - trimmedText.length;
 | 
			
		||||
    }
 | 
			
		||||
    // find word the user is in
 | 
			
		||||
    let contextStart = -1, contextEnd = -1;
 | 
			
		||||
    
 | 
			
		||||
    let contextStart = -1,
 | 
			
		||||
        contextEnd = -1;
 | 
			
		||||
 | 
			
		||||
    for (let i = 0; i < spaceWords.length; i++) {
 | 
			
		||||
        if (col >= spaceWords[i].start && col <= spaceWords[i].end) {
 | 
			
		||||
            // found the word
 | 
			
		||||
@@ -242,7 +245,7 @@ function runCursorContext() {
 | 
			
		||||
            contextEnd = Math.min(spaceWords.length, i + windowSize + 1); // clamp end index
 | 
			
		||||
            // construct cursor context string
 | 
			
		||||
            let contextString = '';
 | 
			
		||||
            
 | 
			
		||||
 | 
			
		||||
            for (let i = contextStart; i < contextEnd; i++) {
 | 
			
		||||
                contextString += spaceWords[i].word + ' ';
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user