Skip to content

Commit

Permalink
Add nimsuggest setup commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
Varriount committed Feb 9, 2016
1 parent 62d0ac5 commit 0c5bb9e
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 11 deletions.
4 changes: 4 additions & 0 deletions Support/Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,9 @@
{
"caption": "Nim: Get Suggestion",
"command": "nim_get_suggestions"
},
{
"caption": "Nim: Setup Nimsuggest.",
"command": "nim_compile_internal_nimsuggest"
}
]
65 changes: 58 additions & 7 deletions nimlime_core/commands/idecommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,74 @@
"""
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
requires_nim_syntax = True
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.
Expand Down Expand Up @@ -72,6 +122,7 @@ def run(self):

yield


class NimShowDefinition(NimIdeCommand):
"""
Show definition of symbol at cursor.
Expand Down Expand Up @@ -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],
Expand Down
12 changes: 9 additions & 3 deletions nimlime_core/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand All @@ -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():
Expand All @@ -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__)
3 changes: 2 additions & 1 deletion nimlime_core/utils/error_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import os
import sys
import tempfile
import traceback
from time import strftime

Expand Down Expand Up @@ -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
Expand Down
Binary file added nimsuggest.tar.gz
Binary file not shown.

0 comments on commit 0c5bb9e

Please sign in to comment.