Skip to content

Commit 0c5bb9e

Browse files
committed
Add nimsuggest setup commands.
1 parent 62d0ac5 commit 0c5bb9e

File tree

5 files changed

+73
-11
lines changed

5 files changed

+73
-11
lines changed

Support/Default.sublime-commands

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,9 @@
6767
{
6868
"caption": "Nim: Get Suggestion",
6969
"command": "nim_get_suggestions"
70+
},
71+
{
72+
"caption": "Nim: Setup Nimsuggest.",
73+
"command": "nim_compile_internal_nimsuggest"
7074
}
7175
]

nimlime_core/commands/idecommands.py

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,74 @@
22
"""
33
Commands and code to expose nimsuggest functionality to the user.
44
"""
5+
import os
6+
import tarfile
57
from pprint import pprint
6-
from traceback import print_stack
7-
8-
import sys
8+
from tempfile import mkdtemp
9+
from zipfile import ZipFile
910

1011
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)
1412
from sublime_plugin import ApplicationCommand
1513

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+
1622

1723
class NimIdeCommand(NimLimeOutputMixin, IdetoolMixin, ApplicationCommand):
1824
requires_nimsuggest = True
1925
requires_nim_syntax = True
2026
st2_compatible = False
2127

2228

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+
2373
class NimGotoDefinition(NimIdeCommand):
2474
"""
2575
Goto definition of symbol at cursor.
@@ -72,6 +122,7 @@ def run(self):
72122

73123
yield
74124

125+
75126
class NimShowDefinition(NimIdeCommand):
76127
"""
77128
Show definition of symbol at cursor.
@@ -175,7 +226,7 @@ def run(self):
175226
if samefile(filename, view.file_name()):
176227
index += 1
177228
else:
178-
del(entries[index])
229+
del (entries[index])
179230

180231
index = yield window.show_quick_panel(
181232
['({5},{6}) {3}'.format(*entry2) for entry2 in entries],

nimlime_core/configuration.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@
2020
in NimLime's settings file to 'False'.
2121
""")
2222

23+
nimsuggest_not_found_msg = not_found_msg + format_msg("""\\n
24+
NOTE: The Nimsuggest must be the versions generated by the
25+
'setup nimsuggest' command.
26+
""")
2327

24-
def gen_exe_check(program_name, setting_key, default_exe):
28+
def gen_exe_check(program_name, setting_key, default_exe, message=None):
2529
"""
2630
Generates a function that checks if a program is on the path, based off
2731
of settings. May also notify the user if the check can't find the
@@ -54,7 +58,7 @@ def callback():
5458
sublime.set_timeout(callback, 500)
5559
return
5660
sublime.error_message(
57-
not_found_msg.format(program_name, setting_key)
61+
(message or not_found_msg).format(program_name, setting_key)
5862
)
5963
callback()
6064

@@ -74,7 +78,7 @@ def callback():
7478
_nimble_exe_check = gen_exe_check('Nimble', 'nimble.executable', 'nimble.exe')
7579
_nim_exe_check = gen_exe_check('Nim', 'nim.executable', 'nim.exe')
7680
_nimsuggest_exe_check = gen_exe_check('Nimsuggest', 'nimsuggest.executable',
77-
'nimsuggest.exe')
81+
'nimsuggest.exe', nimsuggest_not_found_msg)
7882

7983

8084
def _check_for_nimble_exe():
@@ -95,3 +99,5 @@ def _check_for_nimsuggest_exe():
9599
settings.run_on_load_and_change('nimble.executable', _check_for_nimble_exe)
96100
settings.run_on_load_and_change('nim.executable', _check_for_nim_exe)
97101
settings.run_on_load_and_change('nimsuggest.executable', _check_for_nimsuggest_exe)
102+
103+
is_zipped = not os.path.isfile(__file__)

nimlime_core/utils/error_handler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import os
2222
import sys
23+
import tempfile
2324
import traceback
2425
from time import strftime
2526

@@ -51,7 +52,7 @@
5152
'error_handler.enabled' setting in NimLime's settings file to 'False'.
5253
""")
5354

54-
default_logfile_path = os.path.join(root_dir)
55+
default_logfile_path = tempfile.gettempdir()
5556

5657
enabled = True
5758
logfile_path = default_logfile_path

nimsuggest.tar.gz

12.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)