|  | 
| 1 |  | - | 
| 2 | 1 | import sublime, sublime_plugin, tempfile, os, subprocess, threading, signal, sys | 
| 3 | 2 | 
 | 
| 4 |  | -from SQLTools import const | 
| 5 |  | -from SQLTools.lib.connection import Connection | 
| 6 |  | -from SQLTools.lib.command import Command | 
| 7 |  | -from SQLTools.lib.general import Selection, Options, Log | 
|  | 3 | +from os.path import dirname | 
|  | 4 | +sys.path.append(dirname(__file__)) | 
|  | 5 | + | 
|  | 6 | +from lib import const | 
|  | 7 | +from lib.connection import Connection | 
|  | 8 | +from lib.command import Command | 
|  | 9 | +from lib.general import Selection, Options, Log | 
| 8 | 10 | 
 | 
| 9 | 11 | if sys.version_info >= (3, 0): | 
| 10 |  | -    from SQLTools import sqlparse3 as sqlparse | 
|  | 12 | +    import sqlparse3 as sqlparse | 
| 11 | 13 | else: | 
| 12 |  | -    from SQLTools import sqlparse2 as sqlparse | 
|  | 14 | +    import sqlparse2 as sqlparse | 
| 13 | 15 | 
 | 
| 14 |  | -connection          = None | 
| 15 |  | -history             = [''] | 
|  | 16 | +connection = None | 
|  | 17 | +history    = [''] | 
|  | 18 | +tableNames = [] | 
| 16 | 19 | 
 | 
| 17 | 20 | def sqlChangeConnection(index): | 
| 18 | 21 |     global connection | 
| 19 |  | -    names = Options.list() | 
| 20 |  | -    options = Options(names[index]) | 
|  | 22 | +    global tableNames | 
|  | 23 | +    names      = Options.list() | 
|  | 24 | +    options    = Options(names[index]) | 
| 21 | 25 |     connection = Connection(options) | 
|  | 26 | +    tableNames = connection.desc() | 
| 22 | 27 |     sublime.status_message('ST: Connection switched to %s' % names[index]) | 
| 23 | 28 | 
 | 
| 24 | 29 | def showTableRecords(index): | 
| 25 | 30 |     global connection | 
|  | 31 | +    global tableNames | 
| 26 | 32 |     if index > -1: | 
| 27 | 33 |         if connection != None: | 
| 28 | 34 |             tables = connection.desc() | 
| @@ -143,3 +149,31 @@ def run(self, edit): | 
| 143 | 149 |                 self.replace_region_with_formatted_sql(edit, region) | 
| 144 | 150 | 
 | 
| 145 | 151 | Log.debug("Package Loaded") | 
|  | 152 | + | 
|  | 153 | + | 
|  | 154 | +# class SqlCompletePlugin(sublime_plugin.EventListener): | 
|  | 155 | +#     def on_query_completions(self, view, prefix, locations): | 
|  | 156 | +#         return self.get_autocomplete_list(prefix) | 
|  | 157 | + | 
|  | 158 | +#     def get_autocomplete_list(self, word): | 
|  | 159 | +#         global tableNames | 
|  | 160 | +#         completions = list(set(tableNames)) | 
|  | 161 | +#         completions.sort() | 
|  | 162 | +#         # return the array | 
|  | 163 | +#         print (word) | 
|  | 164 | +#         autocomplete_list = [] | 
|  | 165 | +#         for w in tableNames: | 
|  | 166 | +#             try: | 
|  | 167 | +#                 if word.lower() in w.lower(): | 
|  | 168 | +#                     autocomplete_list.append((w, w)) | 
|  | 169 | +#             except UnicodeDecodeError: | 
|  | 170 | +#                 continue | 
|  | 171 | + | 
|  | 172 | +#         return autocomplete_list | 
|  | 173 | + | 
|  | 174 | +if sublime.load_settings(const.connectionsFilename).get("default", False): | 
|  | 175 | +    default = sublime.load_settings(const.connectionsFilename).get("default") | 
|  | 176 | +    Log.debug("Default database set to " + default) | 
|  | 177 | +    dbs = Options.list() | 
|  | 178 | +    index = dbs.index(default) | 
|  | 179 | +    sqlChangeConnection(index) | 
0 commit comments