<commit_before>function extractVariable(
    activeEditorUtils,
    astNodeUtils,
    editActions,
    locationUtils,
    messageLogger
) {


    /*
    * Things we need to do
    *
    * 1. Check that something is selected
    *   a. if selection, continue
    *   b. (done) if no selection, alert (display error) and quit
    * 2. Get the entire document as source lines
    * 3. Get extraction scope options
    * 4. Select extraction scope to use
    * 5. Get placement position
    * 6. Get variable declaration type (var, let, const)
    * 7. Get variable content (selection from source)
    * 8. Create variable code string
    * 9. Replace original selection with variable name
    * 10. Insert variable code string
    */

    function isEmptySelection(selectionCoordinates) {
        const selectionAstCoordinates = locationUtils
            .convertToAstLocation(selectionCoordinates);
        
        return locationUtils.isLocationAnEmptySelection(selectionAstCoordinates);
    }

    function extract() {
        const activeEditor = activeEditorUtils.create();
        const selectionEditorCoordinates = activeEditor.getSelectionCoords();

        if(isEmptySelection(selectionEditorCoordinates)) {
            messageLogger.info('Cannot extract an empty selection to a variable');
        }
    }

    return {
        extract
    };
}

module.exports = extractVariable;<commit_msg>More work done on extract variable -- scope selection works<commit_after>function extractVariable(
    activeEditorUtils,
    astNodeUtils,
    editActions,
    extractVariableOptionsBuilder,
    locationUtils,
    messageLogger,
    parser,
    userInput,
    variableExtractionLocationFinder,
    variableExtractionScopeFinder
) {

    /*
    * Things we need to do
    *
    * [X] 1. Check that something is selected
    *   a. if selection, continue
    *   b. (done) if no selection, alert (display error) and quit
    * [X] 2. Get the entire document as source lines
    * [X] 3. Get extraction scope options
    * [ ] 4. Select extraction scope to use
    * [ ] 5. Get placement position
    * [ ] 6. Get variable declaration type (var, let, const)
    * [ ] 7. Get variable content (selection from source)
    * [ ] 8. Create variable code string
    * [ ] 9. Replace original selection with variable name
    * [ ] 10. Insert variable code string
    */

    function isEmptySelection(selectionAstCoordinates) {
        return locationUtils.isLocationAnEmptySelection(selectionAstCoordinates);
    }

    function getSelectedScope({
        sourceLines,
        astLocationCoordinates
    }) {
        const parsedDocument = parser.parseSourceLines(sourceLines);

        const extractionScopePath = variableExtractionScopeFinder
            .findScopePath(astLocationCoordinates, parsedDocument);
        const extractionScopeNodes = [parsedDocument].concat(extractionScopePath);
        const extractionScopeOptions = extractVariableOptionsBuilder
            .getScopeOptions(extractionScopeNodes, sourceLines);

        extractionScopeOptions[0] = '0: Document';

        const quickPickOptions = userInput.getBaseQuickPickOptions('Extract variable to where?');

        return userInput
            .showQuickPick(extractionScopeOptions, quickPickOptions)
            .then(function (selectedValue) {
                const selectedIndex = selectedValue.split(':')[0];
                return extractionScopeNodes[selectedIndex];
            });
    }

    function getSourceDataIfValid() {
        return new Promise(function (resolve, reject) {
            const activeEditor = activeEditorUtils.create();
            const selectionCoordinates = activeEditor.getSelectionCoords();
            const astLocationCoordinates = locationUtils.convertToAstLocation(selectionCoordinates)
            const sourceLines = activeEditor.getSourceLines();

            if (isEmptySelection(astLocationCoordinates)) {
                reject(new Error('Cannot extract an empty selection to a variable'));
            } else {
                resolve({
                    astLocationCoordinates,
                    sourceLines
                });
            }
        });
    }

    function extract() {
        getSourceDataIfValid()
            .then(function ({ sourceLines, astLocationCoordinates }) {
                return getSelectedScope({ sourceLines, astLocationCoordinates });
            })
            .then(function (selectedScope) {
                console.log(selectedScope);
            })
            .catch(function (error) {
                messageLogger.info(error.message);
            });
    }

    return extract;
}

module.exports = extractVariable;
{'fraction_non_alphanumeric': 0.07675860594398118, 'fraction_numerical': 0.005345306820611503, 'mean_word_length': 2.512012012012012, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6743837', 'n_tokens_mistral': 1173, 'n_tokens_neox': 1104, 'n_words': 316}