<commit_before>
        // node built in
var   path = require('path')
    , crypto = require('crypto')
        // lib code
    , query = require('./query')
    , debug = require('./debug')
    , file = require('./file')
    , state = require('../haxe-state')
    , signatures = require('../parsing/signatures')
    , escape = require('../utils/escape-html')
        // dep code
    , xml2js = require('xml2js')
    , fs = require('fs-extra')
    , filter = require('fuzzaldrin').filter


var REGEX_ENDS_WITH_DOT_IDENTIFIER = /\.([a-zA-Z_0-9]*)$/;


module.exports = {

    selector: '.source.haxe',
    disableForSelector: '.source.haxe .comment',
    inclusionPriority: 1,
    excludeLowerPriority: true,
    prefixes:['.','('],

    last_completion_index: null,
    last_key_path: null,
    last_has_partial_key: false,
    last_suggestions: null,
    last_suggestions_kind: null,

        // Set to true to use extended completion
        // on anonymous structures as argument
    use_extended_completion: false,

        // Set to true to save into an external file
        // and avoid touching the original file
    use_external_file: false,

    getSuggestions : function(opt) {

        if(!state.hxml_cwd) return [];
        if(!state.hxml_content && !state.hxml_file) return [];

        var _file = opt.editor.buffer.file.path;
        if(!_file) return [];

        return new Promise( function(resolve, reject) {

            var buffer_pos = opt.bufferPosition.toArray();
            var pretext = opt.editor.getTextInBufferRange( [ [0,0], buffer_pos] );
            var index = pretext.length;

            var position_info = this._position_info_from_text_and_index(pretext, index);

                // If a new index is provided, use it
            if (position_info != null) {
                index = position_info.index;

                //if (position_info.call != null) {
                //    console.log(position_info.call);
                //}
            }

                // Check if we should run haxe autocomplete again
            var key_path = null, has_partial_key = false;
            if (this.last_completion_index != null) {
                if (this.last_completion_index === index) {
                    var should_recompute_completion = true;

                        // Compare last key path/partial key with the current one
                    if (position_info.call != null) {
                        key_path = position_info.call.key_path;
                        has_partial_key = (position_info.call.partial_key != null);
                    }
                    if (((key_path != null && this.last_key_path != null && key_path.join(',') === this.last_key_path.join(','))
                    || (key_path == null && this.last_key_path == null)) && this.last_has_partial_key == has_partial_key) {
                            // Key path is the same as before
                        should_recompute_completion = false;
                    }

                    if (!should_recompute_completion) {
                            // No need to recompute haxe completion
                            // Just filter and resolve
                        var filtered = this._filter_suggestions(this.last_suggestions, this.last_suggestions_kind, opt, position_info);
                        return resolve(filtered);
                    }
                }
            }
            this.last_completion_index = index;
            this.last_key_path = key_path;
            this.last_has_partial_key = has_partial_key;

                // We need to perform a new haxe query
                // Save file first
            var fetch, save_info;
            if (this.use_external_file) {
                    // Completion using an external file
                save_info = file.save_tmp_file_for_completion_of_original_file(opt.editor.buffer.file.path, pretext);

                fetch = query.get({
                    file: save_info.file_path,
                    byte: index,
                    add_args: ['-cp', save_info.cp_path]
                });
            }
            else {
                    // `classic` way of saving the file
                save_info = this._save_for_completion(opt.editor, _file);

                fetch = query.get({
                    file: save_info.file,
                    byte: index,
                    add_args:[]
                });
            }

            fetch.then(function(data) {

                var parse = this._parse_suggestions(opt, data, position_info);

                    parse.then(function(result){
                        resolve(result);
                    }).catch(function(e) {
                        reject(e);
                    });

            }.bind(this)).catch(reject).then(function() {

                this._restore_post_completion(save_info);

            }.bind(this)); //then

        }.bind(this));  //promise

    }, //getSuggestions

    onDidInsertSuggestion: function(options) {
            // Get editor state
        var editor = options.editor;
        var position = options.triggerPosition;
        var buffer_pos = editor.getLastCursor().getBufferPosition().toArray();

        if (this.use_extended_completion && this.last_key_path != null) {
            editor.insertText(': ');
<commit_msg>completion; fix confirming type hint in structure. enable extended completion<commit_after>
        // node built in
var   path = require('path')
    , crypto = require('crypto')
        // lib code
    , query = require('./query')
    , debug = require('./debug')
    , file = require('./file')
    , state = require('../haxe-state')
    , signatures = require('../parsing/signatures')
    , escape = require('../utils/escape-html')
        // dep code
    , xml2js = require('xml2js')
    , fs = require('fs-extra')
    , filter = require('fuzzaldrin').filter


var REGEX_ENDS_WITH_DOT_IDENTIFIER = /\.([a-zA-Z_0-9]*)$/;


module.exports = {

    selector: '.source.haxe',
    disableForSelector: '.source.haxe .comment',
    inclusionPriority: 1,
    excludeLowerPriority: true,
    prefixes:['.','('],

    last_completion_index: null,
    last_key_path: null,
    last_has_partial_key: false,
    last_suggestions: null,
    last_suggestions_kind: null,

        // Set to true to use extended completion
        // on anonymous structures as argument
    use_extended_completion: true,

        // Set to true to save into an external file
        // and avoid touching the original file
    use_external_file: false,

    getSuggestions : function(opt) {

        if(!state.hxml_cwd) return [];
        if(!state.hxml_content && !state.hxml_file) return [];

        var _file = opt.editor.buffer.file.path;
        if(!_file) return [];

        return new Promise( function(resolve, reject) {

            var buffer_pos = opt.bufferPosition.toArray();
            var pretext = opt.editor.getTextInBufferRange( [ [0,0], buffer_pos] );
            var index = pretext.length;

            var position_info = this._position_info_from_text_and_index(pretext, index);

                // If a new index is provided, use it
            if (position_info != null) {
                index = position_info.index;

                //if (position_info.call != null) {
                //    console.log(position_info.call);
                //}
            }

                // Check if we should run haxe autocomplete again
            var key_path = null, has_partial_key = false;
            if (this.last_completion_index != null) {
                if (this.last_completion_index === index) {
                    var should_recompute_completion = true;

                        // Compare last key path/partial key with the current one
                    if (position_info.call != null) {
                        key_path = position_info.call.key_path;
                        has_partial_key = (position_info.call.partial_key != null);
                    }
                    if (((key_path != null && this.last_key_path != null && key_path.join(',') === this.last_key_path.join(','))
                    || (key_path == null && this.last_key_path == null)) && this.last_has_partial_key == has_partial_key) {
                            // Key path is the same as before
                        should_recompute_completion = false;
                    }

                    if (!should_recompute_completion) {
                            // No need to recompute haxe completion
                            // Just filter and resolve
                        var filtered = this._filter_suggestions(this.last_suggestions, this.last_suggestions_kind, opt, position_info);
                        return resolve(filtered);
                    }
                }
            }
            this.last_completion_index = index;
            this.last_key_path = key_path;
            this.last_has_partial_key = has_partial_key;

                // We need to perform a new haxe query
                // Save file first
            var fetch, save_info;
            if (this.use_external_file) {
                    // Completion using an external file
                save_info = file.save_tmp_file_for_completion_of_original_file(opt.editor.buffer.file.path, pretext);

                fetch = query.get({
                    file: save_info.file_path,
                    byte: index,
                    add_args: ['-cp', save_info.cp_path]
                });
            }
            else {
                    // `classic` way of saving the file
                save_info = this._save_for_completion(opt.editor, _file);

                fetch = query.get({
                    file: save_info.file,
                    byte: index,
                    add_args:[]
                });
            }

            fetch.then(function(data) {

                var parse = this._parse_suggestions(opt, data, position_info);

                    parse.then(function(result){
                        resolve(result);
                    }).catch(function(e) {
                        reject(e);
                    });

            }.bind(this)).catch(reject).then(function() {

                this._restore_post_completion(save_info);

            }.bind(this)); //then

        }.bind(this));  //promise

    }, //getSuggestions

    onDidInsertSuggestion: function(options) {
            // Get editor state
        var editor = options.editor;
        var position = options.triggerPosition;
        var buffer_pos = editor.getLastCursor().getBufferPosition().toArray();
        var suggestion = options.suggestion;

        if (this.use_extended_completion && (this.last_key_path != null || this.last_has_partial_key) && suggestion.className != 'haxe-autocomplete-suggestion-type-hint') {
            editor.insertText(': ');

{'fraction_non_alphanumeric': 0.10652794401988767, 'fraction_numerical': 0.0012890157444065925, 'mean_word_length': 1.6072971675468075, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '893290', 'n_tokens_mistral': 3029, 'n_tokens_neox': 2799, 'n_words': 631}