Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified completion/Erlang-Libs.dirinfo
Binary file not shown.
1,740 changes: 1 addition & 1,739 deletions completion/Erlang-Libs.sublime-completions.full

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions sublimerl_autocompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
# imports
import sublime, sublime_plugin
import os, threading
from sublimerl_core import SUBLIMERL, SublimErlProjectLoader
import SublimErl.sublimerl_core as GLOBALS
from .sublimerl_core import SublimErlProjectLoader


# test runner
Expand All @@ -46,8 +47,8 @@ def __init__(self, view):

def setup_panel(self):
self.panel = self.window.get_output_panel(self.panel_name)
self.panel.settings().set("syntax", os.path.join(SUBLIMERL.plugin_path, "theme", "SublimErlAutocompile.hidden-tmLanguage"))
self.panel.settings().set("color_scheme", os.path.join(SUBLIMERL.plugin_path, "theme", "SublimErlAutocompile.hidden-tmTheme"))
self.panel.settings().set("syntax", os.path.join(GLOBALS.SUBLIMERL.plugin_path, "theme", "SublimErlAutocompile.hidden-tmLanguage"))
self.panel.settings().set("color_scheme", os.path.join(GLOBALS.SUBLIMERL.plugin_path, "theme", "SublimErlAutocompile.hidden-tmTheme"))

def update_panel(self):
if len(self.panel_buffer):
Expand Down Expand Up @@ -78,7 +79,7 @@ class SublimErlAutocompilerListener(sublime_plugin.EventListener):
# CALLBACK ON VIEW SAVE
def on_post_save(self, view):
# check init successful
if SUBLIMERL.initialized == False: return
if GLOBALS.SUBLIMERL.initialized == False: return
# ensure context matches
caret = view.sel()[0].a
if not ('source.erlang' in view.scope_name(caret) and sublime.platform() != 'windows'): return
Expand Down
69 changes: 38 additions & 31 deletions sublimerl_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
# ==========================================================================================================

# imports
import sublime, sublime_plugin
import sublime, sublime_plugin, fnmatch
import os, threading, pickle, json, re
from sublimerl_core import SUBLIMERL, SublimErlProjectLoader
import SublimErl.sublimerl_core as GLOBALS
from .sublimerl_core import SublimErlProjectLoader

SUBLIMERL_COMPLETIONS = {
'erlang_libs': {
Expand All @@ -49,9 +50,9 @@ class SublimErlModuleNameCompletions():

def set_completions(self):
# if errors occurred
if SUBLIMERL.plugin_path == None: return
if GLOBALS.SUBLIMERL.plugin_path == None: return
# load json
completions_full_path = os.path.join(SUBLIMERL.plugin_path, 'completion', 'Erlang-Libs.sublime-completions.full')
completions_full_path = os.path.join(GLOBALS.SUBLIMERL.plugin_path, 'completion', 'Erlang-Libs.sublime-completions.full')
if os.path.exists(completions_full_path):
f = open(completions_full_path)
file_json = json.load(f)
Expand All @@ -61,14 +62,14 @@ def set_completions(self):
completions = []
for m in file_json['completions']:
valid = True
for regex in SUBLIMERL.completion_skip_erlang_libs:
for regex in GLOBALS.SUBLIMERL.completion_skip_erlang_libs:
if re.search(regex, m['trigger']):
valid = False
break
if valid == True: completions.append(m)
# generate completion file
file_json['completions'] = completions
f = open(os.path.join(SUBLIMERL.plugin_path, 'completion', 'Erlang-Libs.sublime-completions'), 'w')
f = open(os.path.join(GLOBALS.SUBLIMERL.plugin_path, 'completion', 'Erlang-Libs.sublime-completions'), 'w')
f.write(json.dumps(file_json))
f.close()

Expand All @@ -79,13 +80,16 @@ def run(self):
this.set_completions()
SublimErlThread().start()

SublimErlModuleNameCompletions().set_completions_threaded()

def plugin_loaded():
sublime.set_timeout(lambda: SublimErlModuleNameCompletions().set_completions_threaded(), 5000)



# completions
class SublimErlCompletions(SublimErlProjectLoader):

def get_available_completions(self):
def get_available_completions(self):
# load current erlang libs
if SUBLIMERL_COMPLETIONS['erlang_libs']['completions'] == {}: self.load_erlang_lib_completions()
# start rebuilding: only done once per sublimerl session
Expand All @@ -98,14 +102,14 @@ def get_completion_filename(self, code_type):
if code_type == 'erlang_libs': return 'Erlang-Libs'
elif code_type == 'current_project': return 'Current-Project'

def load_erlang_lib_completions(self):
def load_erlang_lib_completions(self):
self.load_completions('erlang_libs')

def load_current_project_completions(self):
self.load_completions('current_project')

def load_completions(self, code_type):
# check lock
# check lock
global SUBLIMERL_COMPLETIONS
if SUBLIMERL_COMPLETIONS[code_type]['load_in_progress'] == True: return
# set lock
Expand All @@ -116,10 +120,10 @@ class SublimErlThread(threading.Thread):
def run(self):
global SUBLIMERL_COMPLETIONS
# load completetions from file
disasm_filepath = os.path.join(SUBLIMERL.plugin_path, "completion", "%s.disasm" % this.get_completion_filename(code_type))
disasm_filepath = os.path.join(GLOBALS.SUBLIMERL.plugin_path, "completion", "%s.disasm" % this.get_completion_filename(code_type))
if os.path.exists(disasm_filepath):
# load file
f = open(disasm_filepath, 'r')
f = open(disasm_filepath, 'rb')
completions = pickle.load(f)
f.close()
# set
Expand All @@ -140,13 +144,14 @@ def generate_erlang_lib_completions(self):
# rebuild
this = self
class SublimErlThread(threading.Thread):
def run(self):
def run(self):
# get dirs
dest_file_base = os.path.join(SUBLIMERL.completions_path, "Erlang-Libs")
dest_file_base = os.path.join(GLOBALS.SUBLIMERL.completions_path, "Erlang-Libs")
# get erlang libs info
current_erlang_libs = [name for name in os.listdir(SUBLIMERL.erlang_libs_path) if os.path.isdir(os.path.join(SUBLIMERL.erlang_libs_path, name))]
current_erlang_libs = [name for name in os.listdir(GLOBALS.SUBLIMERL.erlang_libs_path) if os.path.isdir(os.path.join(GLOBALS.SUBLIMERL.erlang_libs_path, name))]
# read file of previous erlang libs
dirinfo_path = os.path.join(SUBLIMERL.completions_path, "Erlang-Libs.dirinfo")
dirinfo_path = os.path.join(GLOBALS.SUBLIMERL.completions_path, "Erlang-Libs.dirinfo")

if os.path.exists(dirinfo_path):
f = open(dirinfo_path, 'rb')
erlang_libs = pickle.load(f)
Expand All @@ -157,10 +162,11 @@ def run(self):
# different erlang libs -> regenerate
this.status("Regenerating Erlang lib completions...")
# set cwd
os.chdir(SUBLIMERL.support_path)
os.chdir(GLOBALS.SUBLIMERL.support_path)
# start gen
this.execute_os_command("python sublimerl_libparser.py %s %s" % (this.shellquote(SUBLIMERL.erlang_libs_path), this.shellquote(dest_file_base)))
this.execute_os_command("python sublimerl_libparser.py %s %s" % (this.shellquote(SublimErlTextCommand.erlang_libs_path), this.shellquote(dest_file_base)))
# rename file to .full
os.remove("%s.sublime-completions.full" % dest_file_base)
os.rename("%s.sublime-completions" % dest_file_base, "%s.sublime-completions.full" % dest_file_base)
# save dir information
f = open(dirinfo_path, 'wb')
Expand Down Expand Up @@ -188,9 +194,9 @@ def run(self):
global SUBLIMERL_COMPLETIONS
this.status("Regenerating Project completions...")
# get dir
dest_file_base = os.path.join(SUBLIMERL.completions_path, "Current-Project")
dest_file_base = os.path.join(GLOBALS.SUBLIMERL.completions_path, "Current-Project")
# set cwd
os.chdir(SUBLIMERL.support_path)
os.chdir(GLOBALS.SUBLIMERL.support_path)
# start gen
this.execute_os_command("python sublimerl_libparser.py %s %s" % (this.shellquote(this.project_root), this.shellquote(dest_file_base)))
# release lock
Expand All @@ -204,14 +210,15 @@ def run(self):

# listener
class SublimErlCompletionsListener(sublime_plugin.EventListener):

# CALLBACK ON VIEW SAVE
def on_post_save(self, view):
# check init successful
if SUBLIMERL.initialized == False: return

if GLOBALS.SUBLIMERL.initialized == False: return
# ensure context matches
caret = view.sel()[0].a
if not ('source.erlang' in view.scope_name(caret) and sublime.platform() != 'windows'): return
if not ('source.erlang' in view.scope_name(caret)): return
# init
completions = SublimErlCompletions(view)
# compile saved file & reload completions
Expand All @@ -222,12 +229,12 @@ def run(self):
SublimErlThread().start()

# CALLBACK ON VIEW LOADED
def on_load(self, view):
def on_load(self, view):
# check init successful
if SUBLIMERL.initialized == False: return
if GLOBALS.SUBLIMERL.initialized == False: return
# only trigger within erlang
caret = view.sel()[0].a
if not ('source.erlang' in view.scope_name(caret) and sublime.platform() != 'windows'): return
if not ('source.erlang' in view.scope_name(caret)): return
# init
completions = SublimErlCompletions(view)
# get completions
Expand All @@ -240,10 +247,9 @@ def run(self):
# CALLBACK ON QUERY COMPLETIONS
def on_query_completions(self, view, prefix, locations):
# check init successful
if SUBLIMERL.initialized == False: return
if GLOBALS.SUBLIMERL.initialized == False: return
# only trigger within erlang
if not view.match_selector(locations[0], "source.erlang"): return []

# only trigger if : was hit
pt = locations[0] - len(prefix) - 1
ch = view.substr(sublime.Region(pt, pt + 1))
Expand All @@ -254,11 +260,12 @@ def on_query_completions(self, view, prefix, locations):
if function_name.strip() == ':': return
# check for existance
global SUBLIMERL_COMPLETIONS
if SUBLIMERL_COMPLETIONS['erlang_libs']['completions'].has_key(function_name):
if function_name in SUBLIMERL_COMPLETIONS['erlang_libs']['completions']:
available_completions = SUBLIMERL_COMPLETIONS['erlang_libs']['completions'][function_name]
elif SUBLIMERL_COMPLETIONS['current_project']['completions'].has_key(function_name):
elif function_name in SUBLIMERL_COMPLETIONS['current_project']['completions']:
available_completions = SUBLIMERL_COMPLETIONS['current_project']['completions'][function_name]
else: return
else:
return

# return snippets
return (available_completions, sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS)
30 changes: 19 additions & 11 deletions sublimerl_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import sublime, sublime_plugin
import os, subprocess, re

SUBLIMERL = None

# plugin initialized (Sublime might need to be restarted if some env configs / preferences change)
class SublimErlGlobal():

Expand Down Expand Up @@ -111,7 +113,7 @@ def set_paths(self):

def log(message):
self.init_errors.append(message)
print "SublimErl Init Error: %s" % message
print("SublimErl Init Error:", message )

def test_path(path):
return path != None and os.path.exists(path)
Expand Down Expand Up @@ -174,16 +176,21 @@ def get_erlang_module_name(self, view):
return m.group(1)

def get_exe_path(self, name):
retcode, data = self.execute_os_command('which %s' % name)
data = data.strip()
command = 'which %s'
if sublime.platform() == 'windows':
command = 'where %s'
retcode, data = self.execute_os_command(command % name)
data = data.strip().decode('ascii')
data = data.split('\r\n')
data = data[0]
if retcode == 0 and len(data) > 0:
return data

def set_erlang_libs_path(self):
# run escript to get erlang lib path
os.chdir(self.support_path)
escript_command = "sublimerl_utility.erl lib_dir"
retcode, data = self.execute_os_command('%s %s' % (self.escript_path, escript_command))
retcode, data = self.execute_os_command('"%s" %s' % (self.escript_path, escript_command))
self.erlang_libs_path = data
return self.erlang_libs_path != ''

Expand All @@ -198,12 +205,13 @@ def execute_os_command(self, os_cmd):


def shellquote(self, s):
return "'" + s.replace("'", "'\\''") + "'"


# initialize
SUBLIMERL = SublimErlGlobal()
if s:
quote = "\"" if sublime.platform() == 'windows' else "'"
return quote + s.replace("'", "'\\''") + quote

def plugin_loaded():
global SUBLIMERL
SUBLIMERL = SublimErlGlobal()

# project loader
class SublimErlProjectLoader():
Expand Down Expand Up @@ -263,7 +271,7 @@ def set_app_name(self):
self.app_name = self.find_app_name(app_file_path)

def find_app_name(self, app_file_path):
f = open(app_file_path, 'rb')
f = open(app_file_path)
app_desc = f.read()
f.close()
m = re.search(r"{\s*application\s*,\s*('?[A-Za-z0-9_]+'?)\s*,\s*\[", app_desc)
Expand Down Expand Up @@ -325,7 +333,7 @@ def run(self, edit):
# check
if SUBLIMERL.initialized == False:
# self.log("SublimErl could not be initialized:\n\n%s\n" % '\n'.join(SUBLIMERL.init_errors))
print "SublimErl could not be initialized:\n\n%s\n" % '\n'.join(SUBLIMERL.init_errors)
print ("SublimErl could not be initialized:", '\n'.join(SUBLIMERL.init_errors))
return
else:
return self.run_command(edit)
Expand Down
2 changes: 1 addition & 1 deletion sublimerl_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

# imports
import sublime, sublime_plugin, os, tempfile
from sublimerl_core import SUBLIMERL, SublimErlTextCommand, SublimErlProjectLoader
from .sublimerl_core import SUBLIMERL, SublimErlTextCommand, SublimErlProjectLoader


# main autoformat
Expand Down
4 changes: 2 additions & 2 deletions sublimerl_function_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
# imports
import sublime
import os, time, threading, pickle
from sublimerl_core import SUBLIMERL, SublimErlTextCommand, SublimErlProjectLoader
from sublimerl_completion import SUBLIMERL_COMPLETIONS
from .sublimerl_core import SUBLIMERL, SublimErlTextCommand, SublimErlProjectLoader
from .sublimerl_completion import SUBLIMERL_COMPLETIONS


# main autoformat
Expand Down
2 changes: 1 addition & 1 deletion sublimerl_man.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# imports
import sublime
import os
from sublimerl_core import SUBLIMERL, SublimErlTextCommand, SublimErlGlobal
from .sublimerl_core import SUBLIMERL, SublimErlTextCommand, SublimErlGlobal


# show man
Expand Down
2 changes: 1 addition & 1 deletion sublimerl_tests_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# imports
import sublime
import os, subprocess, re, threading, webbrowser
from sublimerl_core import SUBLIMERL_VERSION, SUBLIMERL, SublimErlTextCommand, SublimErlProjectLoader
from .sublimerl_core import SUBLIMERL_VERSION, SUBLIMERL, SublimErlTextCommand, SublimErlProjectLoader


# test runner
Expand Down
6 changes: 3 additions & 3 deletions support/sublimerl_libparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def generate_completions(self, starting_dir, dest_file_base):
# get completions
module_completions, line_numbers = self.get_completions(module)
if len(module_completions) > 0:
# set disasm
# set disasmf
disasms[module_name] = sorted(module_completions, key=lambda k: k[0])
# set searches
for i in range(0, len(module_completions)):
Expand All @@ -82,7 +82,7 @@ def generate_completions(self, starting_dir, dest_file_base):
completions.append("{ \"trigger\": \"%s\", \"contents\": \"%s\" }" % (module_name, module_name))

# add BIF completions?
if disasms.has_key('erlang'):
if 'erlang' in disasms:
# we are generating erlang disasm
bif_completions = self.bif_completions()
for k in bif_completions.keys():
Expand All @@ -103,7 +103,7 @@ def generate_completions(self, starting_dir, dest_file_base):
pickle.dump(disasms, f_disasms)
f_disasms.close()
# write to files: completions
f_completions = open("%s.sublime-completions" % dest_file_base, 'wb')
f_completions = open("%s.sublime-completions" % dest_file_base, 'w')
if len(completions) > 0:
f_completions.write("{ \"scope\": \"source.erlang\", \"completions\": [\n" + ',\n'.join(completions) + "\n]}")
else:
Expand Down