<commit_before>import sublime, sublime_plugin

ERBCOMPLETIONS_SETTING = "ERBAutocomplete.sublime-settings"

class ERBAutoCompleteAPI():
    def init(self):
        self.words = []
        self.words = sublime.load_settings(ERBCOMPLETIONS_SETTING)

ERBComplete = ERBAutoCompleteAPI()

if int(sublime.version()) < 3000:
    erbCompletion.init()
else:
    def plugin_loaded():
        global ERBComplete
        ERBComplete.init()

class ERBAutocompleteListener(sublime_plugin.EventListener):
    global ERBComplete
    def on_query_completions(self, view, prefix, locations):
        self.completions = []
        scope = ERBComplete.words.get('scope')
        
        if scope and view.match_selector(locations[0], scope):
            self.completions += ERBComplete.words.get('completions')
        if not self.completions:
            return []
            
        window = sublime.active_window()
        baseCompletions = [view.extract_completions(prefix)]
        baseCompletions = [(item,item) for sublist in baseCompletions for item in sublist] #flatten
        baseCompletions = list(set(baseCompletions))
        completions = list(self.completions)
        completions = [tuple(attr) for attr in self.completions]
        completions.extend(baseCompletions)
        return completions



<commit_msg>add const variable. add auto switch syntax to erb<commit_after>import sublime, sublime_plugin
import os
ERBCOMPLETIONS_SETTING = 'ERBAutocomplete.sublime-settings'
BASE_PATH = os.path.abspath(os.path.dirname(__file__))
PACKAGES_PATH = sublime.packages_path() or os.path.dirname(BASE_PATH)
ERB_GRAMMAR = 'Packages/%s/erb.tmLanguage' % os.path.basename(BASE_PATH).replace('.sublime-package', '')
class ERBAutoCompleteAPI():
    def init(self):
        self.words = []
        self.words = sublime.load_settings(ERBCOMPLETIONS_SETTING)

ERBComplete = ERBAutoCompleteAPI()

if int(sublime.version()) < 3000:
    erbCompletion.init()
else:
    def plugin_loaded():
        global ERBComplete
        ERBComplete.init()

class ERBAutocompleteListener(sublime_plugin.EventListener):
    global ERBComplete
    def on_query_completions(self, view, prefix, locations):
        self.completions = []
        scope = ERBComplete.words.get('scope')
        
        if scope and view.match_selector(locations[0], scope):
            self.completions += ERBComplete.words.get('completions')
        if not self.completions:
            return []
            
        window = sublime.active_window()
        baseCompletions = [view.extract_completions(prefix)]
        baseCompletions = [(item,item) for sublist in baseCompletions for item in sublist] #flatten
        baseCompletions = list(set(baseCompletions))
        completions = list(self.completions)
        completions = [tuple(attr) for attr in self.completions]
        completions.extend(baseCompletions)
        return completions

    def on_load(self, view):
        filename = view.file_name()
        if not filename:
            return
        
        name = os.path.basename(filename.lower())
        if name[-8:] == "html.erb" or name[-3:] == "erb":
            view.settings().set('syntax', ERB_GRAMMAR)
            print("Switched syntax to: ERB")
{'fraction_non_alphanumeric': 0.10220565392979186, 'fraction_numerical': 0.003727865796831314, 'mean_word_length': 3.1019108280254777, 'pattern_counts': {'":': 1, '<': 5, '<?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': '5137685', 'n_tokens_mistral': 1005, 'n_tokens_neox': 957, 'n_words': 192}