diff --git a/Support/Default.sublime-commands b/Support/Default.sublime-commands index 8f2f15c..bef7212 100644 --- a/Support/Default.sublime-commands +++ b/Support/Default.sublime-commands @@ -67,5 +67,9 @@ { "caption": "Nim: Get Suggestion", "command": "nim_get_suggestions" + }, + { + "caption": "Nim: Setup Nimsuggest.", + "command": "nim_compile_internal_nimsuggest" } ] \ No newline at end of file diff --git a/nimlime_core/commands/idecommands.py b/nimlime_core/commands/idecommands.py index 22bdfa3..f80ca98 100644 --- a/nimlime_core/commands/idecommands.py +++ b/nimlime_core/commands/idecommands.py @@ -2,17 +2,23 @@ """ Commands and code to expose nimsuggest functionality to the user. """ +import os +import tarfile from pprint import pprint -from traceback import print_stack - -import sys +from tempfile import mkdtemp +from zipfile import ZipFile import sublime -from nimlime_core.utils.error_handler import catch_errors -from nimlime_core.utils.misc import send_self, get_next_method, samefile -from nimlime_core.utils.mixins import (NimLimeOutputMixin, IdetoolMixin) from sublime_plugin import ApplicationCommand +import NimLime +from nimlime_core import configuration +from nimlime_core.utils.error_handler import catch_errors +from nimlime_core.utils.misc import (send_self, get_next_method, samefile, + run_process, busy_frames) +from nimlime_core.utils.mixins import (NimLimeOutputMixin, IdetoolMixin, + NimLimeMixin) + class NimIdeCommand(NimLimeOutputMixin, IdetoolMixin, ApplicationCommand): requires_nimsuggest = True @@ -20,6 +26,50 @@ class NimIdeCommand(NimLimeOutputMixin, IdetoolMixin, ApplicationCommand): st2_compatible = False +class NimCompileInternalNimsuggest(NimLimeMixin, ApplicationCommand): + """ + Compile the version of Nimsuggest bundled with NimLime. + """ + requires_nim = True + + @send_self + @catch_errors + def run(self): + this = yield + window = sublime.active_window() + view = window.active_view() + + frames = ["Compiling Internal Nimsuggest" + f for f in busy_frames] + + exe_path = yield window.show_input_panel( + "Path to copy nimsuggest to? (Blank for temporary directory)", '', + this.send, None, None + ) + if exe_path == '': + exe_path = mkdtemp() + + if not (os.path.exists(exe_path) and os.path.isdir(exe_path)): + sublime.status_message("Invalid path.") + yield + + nimlime_dir = os.path.dirname(NimLime.__file__) + nimsuggest_file = os.path.join( + nimlime_dir, 'nimsuggest', 'nimsuggest.nim' + ) + if os.path.exists(nimsuggest_file): + # Either we're using an actual file + run_process( + [configuration.nim_executable, 'c', nimsuggest_file] + ) + else: + # Or we're using a zipped version + package_file = ZipFile(os.path.join(nimlime_dir)) + package_file.extract('nimsuggest.tar.gz', exe_path) + tarfile.open( + os.path.join(exe_path, 'nimsuggest.tar.gz') + ).extractall(exe_path) + + class NimGotoDefinition(NimIdeCommand): """ Goto definition of symbol at cursor. @@ -72,6 +122,7 @@ def run(self): yield + class NimShowDefinition(NimIdeCommand): """ Show definition of symbol at cursor. @@ -175,7 +226,7 @@ def run(self): if samefile(filename, view.file_name()): index += 1 else: - del(entries[index]) + del (entries[index]) index = yield window.show_quick_panel( ['({5},{6}) {3}'.format(*entry2) for entry2 in entries], diff --git a/nimlime_core/configuration.py b/nimlime_core/configuration.py index 62d2314..39845fa 100644 --- a/nimlime_core/configuration.py +++ b/nimlime_core/configuration.py @@ -20,8 +20,12 @@ in NimLime's settings file to 'False'. """) +nimsuggest_not_found_msg = not_found_msg + format_msg("""\\n +NOTE: The Nimsuggest must be the versions generated by the +'setup nimsuggest' command. +""") -def gen_exe_check(program_name, setting_key, default_exe): +def gen_exe_check(program_name, setting_key, default_exe, message=None): """ Generates a function that checks if a program is on the path, based off of settings. May also notify the user if the check can't find the @@ -54,7 +58,7 @@ def callback(): sublime.set_timeout(callback, 500) return sublime.error_message( - not_found_msg.format(program_name, setting_key) + (message or not_found_msg).format(program_name, setting_key) ) callback() @@ -74,7 +78,7 @@ def callback(): _nimble_exe_check = gen_exe_check('Nimble', 'nimble.executable', 'nimble.exe') _nim_exe_check = gen_exe_check('Nim', 'nim.executable', 'nim.exe') _nimsuggest_exe_check = gen_exe_check('Nimsuggest', 'nimsuggest.executable', - 'nimsuggest.exe') + 'nimsuggest.exe', nimsuggest_not_found_msg) def _check_for_nimble_exe(): @@ -95,3 +99,5 @@ def _check_for_nimsuggest_exe(): settings.run_on_load_and_change('nimble.executable', _check_for_nimble_exe) settings.run_on_load_and_change('nim.executable', _check_for_nim_exe) settings.run_on_load_and_change('nimsuggest.executable', _check_for_nimsuggest_exe) + +is_zipped = not os.path.isfile(__file__) \ No newline at end of file diff --git a/nimlime_core/utils/error_handler.py b/nimlime_core/utils/error_handler.py index 16ff6db..5fd8259 100644 --- a/nimlime_core/utils/error_handler.py +++ b/nimlime_core/utils/error_handler.py @@ -20,6 +20,7 @@ import os import sys +import tempfile import traceback from time import strftime @@ -51,7 +52,7 @@ 'error_handler.enabled' setting in NimLime's settings file to 'False'. """) -default_logfile_path = os.path.join(root_dir) +default_logfile_path = tempfile.gettempdir() enabled = True logfile_path = default_logfile_path diff --git a/nimsuggest.tar.gz b/nimsuggest.tar.gz new file mode 100644 index 0000000..601ffd2 Binary files /dev/null and b/nimsuggest.tar.gz differ