|
2 | 2 | """ |
3 | 3 | Commands and code to expose nimsuggest functionality to the user. |
4 | 4 | """ |
| 5 | +import os |
| 6 | +import tarfile |
5 | 7 | from pprint import pprint |
6 | | -from traceback import print_stack |
7 | | - |
8 | | -import sys |
| 8 | +from tempfile import mkdtemp |
| 9 | +from zipfile import ZipFile |
9 | 10 |
|
10 | 11 | import sublime |
11 | | -from nimlime_core.utils.error_handler import catch_errors |
12 | | -from nimlime_core.utils.misc import send_self, get_next_method, samefile |
13 | | -from nimlime_core.utils.mixins import (NimLimeOutputMixin, IdetoolMixin) |
14 | 12 | from sublime_plugin import ApplicationCommand |
15 | 13 |
|
| 14 | +import NimLime |
| 15 | +from nimlime_core import configuration |
| 16 | +from nimlime_core.utils.error_handler import catch_errors |
| 17 | +from nimlime_core.utils.misc import (send_self, get_next_method, samefile, |
| 18 | + run_process, busy_frames) |
| 19 | +from nimlime_core.utils.mixins import (NimLimeOutputMixin, IdetoolMixin, |
| 20 | + NimLimeMixin) |
| 21 | + |
16 | 22 |
|
17 | 23 | class NimIdeCommand(NimLimeOutputMixin, IdetoolMixin, ApplicationCommand): |
18 | 24 | requires_nimsuggest = True |
19 | 25 | requires_nim_syntax = True |
20 | 26 | st2_compatible = False |
21 | 27 |
|
22 | 28 |
|
| 29 | +class NimCompileInternalNimsuggest(NimLimeMixin, ApplicationCommand): |
| 30 | + """ |
| 31 | + Compile the version of Nimsuggest bundled with NimLime. |
| 32 | + """ |
| 33 | + requires_nim = True |
| 34 | + |
| 35 | + @send_self |
| 36 | + @catch_errors |
| 37 | + def run(self): |
| 38 | + this = yield |
| 39 | + window = sublime.active_window() |
| 40 | + view = window.active_view() |
| 41 | + |
| 42 | + frames = ["Compiling Internal Nimsuggest" + f for f in busy_frames] |
| 43 | + |
| 44 | + exe_path = yield window.show_input_panel( |
| 45 | + "Path to copy nimsuggest to? (Blank for temporary directory)", '', |
| 46 | + this.send, None, None |
| 47 | + ) |
| 48 | + if exe_path == '': |
| 49 | + exe_path = mkdtemp() |
| 50 | + |
| 51 | + if not (os.path.exists(exe_path) and os.path.isdir(exe_path)): |
| 52 | + sublime.status_message("Invalid path.") |
| 53 | + yield |
| 54 | + |
| 55 | + nimlime_dir = os.path.dirname(NimLime.__file__) |
| 56 | + nimsuggest_file = os.path.join( |
| 57 | + nimlime_dir, 'nimsuggest', 'nimsuggest.nim' |
| 58 | + ) |
| 59 | + if os.path.exists(nimsuggest_file): |
| 60 | + # Either we're using an actual file |
| 61 | + run_process( |
| 62 | + [configuration.nim_executable, 'c', nimsuggest_file] |
| 63 | + ) |
| 64 | + else: |
| 65 | + # Or we're using a zipped version |
| 66 | + package_file = ZipFile(os.path.join(nimlime_dir)) |
| 67 | + package_file.extract('nimsuggest.tar.gz', exe_path) |
| 68 | + tarfile.open( |
| 69 | + os.path.join(exe_path, 'nimsuggest.tar.gz') |
| 70 | + ).extractall(exe_path) |
| 71 | + |
| 72 | + |
23 | 73 | class NimGotoDefinition(NimIdeCommand): |
24 | 74 | """ |
25 | 75 | Goto definition of symbol at cursor. |
@@ -72,6 +122,7 @@ def run(self): |
72 | 122 |
|
73 | 123 | yield |
74 | 124 |
|
| 125 | + |
75 | 126 | class NimShowDefinition(NimIdeCommand): |
76 | 127 | """ |
77 | 128 | Show definition of symbol at cursor. |
@@ -175,7 +226,7 @@ def run(self): |
175 | 226 | if samefile(filename, view.file_name()): |
176 | 227 | index += 1 |
177 | 228 | else: |
178 | | - del(entries[index]) |
| 229 | + del (entries[index]) |
179 | 230 |
|
180 | 231 | index = yield window.show_quick_panel( |
181 | 232 | ['({5},{6}) {3}'.format(*entry2) for entry2 in entries], |
|
0 commit comments