From 8ea77ec76722e4e97459c5c19d7d77da8492622f Mon Sep 17 00:00:00 2001 From: Radu Margarint Date: Mon, 17 Nov 2014 21:49:34 -0800 Subject: [PATCH 1/6] Allow for per-project eclipse source root paths and project names --- subclim_plugin.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/subclim_plugin.py b/subclim_plugin.py index 552b718..69a1e3c 100644 --- a/subclim_plugin.py +++ b/subclim_plugin.py @@ -201,14 +201,23 @@ def check_eclim(view=None): def get_context(view): s = view.settings() - project = s.get('subclim.project', None) - relative_path = s.get('subclim.project_relative_path', None) - if project is None: - project, relative_path = eclim.get_context(view.file_name()) - if project is not None: - s.set('subclim.project', project) + project = s.get('subclim.view.project', None) + relative_path = s.get('subclim.view.project_relative_path', None) + if project is None or relative_path is None: + p, relative_path = eclim.get_context(view.file_name()) + + if project is None: + project = s.get('subclim_eclipse_project_name', None) or p + + if relative_path is None: + root_path = s.get('subclim_eclipse_root_path', None) + if root_path: + relative_path = os.path.relpath(view.file_name(), root_path) + + if project is not None: + s.set('subclim.view.project', project) if relative_path is not None: - s.set('subclim.project_relative_path', relative_path) + s.set('subclim.view.project_relative_path', relative_path) return project, relative_path From d3d5c10003177d933cd3bdd229e575b96050632a Mon Sep 17 00:00:00 2001 From: Radu Margarint Date: Mon, 17 Nov 2014 21:58:30 -0800 Subject: [PATCH 2/6] After completing a method call allow tab to cycle through the parameters for easier insertion --- subclim_plugin.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/subclim_plugin.py b/subclim_plugin.py index 69a1e3c..0a9cf8b 100644 --- a/subclim_plugin.py +++ b/subclim_plugin.py @@ -493,10 +493,20 @@ def __init__(self, name, insert=None, type="None"): self.insert = insert else: self.insert = name + if ')' in self.name: # tokenize method params + self.insert = self.name.split(')', 1)[0] + ')' + op = self.insert.index('(') + 1 + cp = self.insert.index(')') + args = self.insert[op:cp].split(',') + toks = [] + for a in args: + toks.append("${%d:%s}" % (len(toks) + 1, a.strip())) + args = ", ".join(toks) + self.insert = self.insert[:op] + args + self.insert[cp:] self.type = "None" def __repr__(self): - return "CompletionProposal: %s %s" % (self.name, self.insert) + return "CompletionProposal: [%s] [%s]" % (self.name, self.insert) class ManualCompletionRequest(sublime_plugin.TextCommand): @@ -535,6 +545,7 @@ def on_query_completions(self, view, prefix, locations): pos = offset_of_location(view, locations[0]) proposals = self.to_proposals(c_func(project, fn, pos)) + proposals.sort(key=lambda x: x.display) return [(p.display, p.insert) for p in proposals] def queue_completions(self, view): From e3554e1128f6d09634ae51ce9a1e9a53b1647fa2 Mon Sep 17 00:00:00 2001 From: Radu Margarint Date: Mon, 17 Nov 2014 22:00:21 -0800 Subject: [PATCH 3/6] Misc fix and update the source when a view is activated, not just every time it's saved, as when the same buffer is opened in multiple views the save event is only sent for the first view. --- subclim_plugin.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/subclim_plugin.py b/subclim_plugin.py index 0a9cf8b..266e506 100644 --- a/subclim_plugin.py +++ b/subclim_plugin.py @@ -630,6 +630,8 @@ def __init__(self, *args, **kwargs): def validation_func(self, view): syntax = view.settings().get("syntax") + if not syntax: + return None if "Java.tmLanguage" in syntax: return eclim.update_java_src elif "Scala.tmLanguage" in syntax: @@ -637,6 +639,9 @@ def validation_func(self, view): else: return None + def on_activated(self, view): + self.on_post_save(view) + def on_load(self, view): validation_func = self.validation_func(view) if validation_func: From 68711c7f47195628b8e5839e7dcf612be4ae27de Mon Sep 17 00:00:00 2001 From: Radu Margarint Date: Mon, 17 Nov 2014 22:03:21 -0800 Subject: [PATCH 4/6] Make visualizing source status (error and warning regions, status message when caret is in regions) work when the same file is opened in multiple views. All views get the regions added instead of just the very first view, which may not be the view currently looked at. --- subclim_plugin.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/subclim_plugin.py b/subclim_plugin.py index 266e506..4ce4ed2 100644 --- a/subclim_plugin.py +++ b/subclim_plugin.py @@ -694,9 +694,16 @@ def on_validation_finished(): tasks.put(async_validate_task) def visualize(self, view): + views = [] + if view.window(): + views = [v for v in view.window().views() if v.buffer_id() is view.buffer_id()]; + for v in views or [view]: + self._view_visualize(v, view) + + def _view_visualize(self, view, first_view): view.erase_regions('subclim-errors') view.erase_regions('subclim-warnings') - lines = JavaValidation.line_messages[view.id()] + lines = JavaValidation.line_messages[first_view.id()] outlines = [view.line(view.text_point(lineno - 1, 0)) for lineno in lines.keys() @@ -711,16 +718,23 @@ def visualize(self, view): 'subclim-warnings', outlines, 'comment', 'dot', JavaValidation.drawType) def on_selection_modified(self, view): + views = [v for v in view.window().views() if v.buffer_id() is view.buffer_id()] if view.window() else None + for v in views or [view]: + if self._view_on_selection_modified(v, view): + return + view.erase_status('subclim') + + def _view_on_selection_modified(self, view, first_view): validation_func = self.validation_func(view) if validation_func: line_messages = JavaValidation.line_messages - vid = view.id() + vid = first_view.id() lineno = view.rowcol(view.sel()[0].end())[0] + 1 if vid in line_messages and lineno in line_messages[vid]: view.set_status( 'subclim', '; '.join([e['message'] for e in line_messages[vid][lineno]])) - else: - view.erase_status('subclim') + return True + return False class JavaImportClassUnderCursor(sublime_plugin.TextCommand): @@ -735,7 +749,8 @@ def run(self, edit, block=False): pos = self.view.sel()[0] word = self.view.word(pos) offset = offset_of_location(self.view, word.a) - self.view.run_command("save") + if self.view.is_dirty(): + self.view.run_command("save") class_names = [] message = [] From 34bb3cfbb56753efb503440a12608ee5b0f32f5c Mon Sep 17 00:00:00 2001 From: Radu Margarint Date: Mon, 17 Nov 2014 22:06:10 -0800 Subject: [PATCH 5/6] When running the AutoImport command, if there was only one possible option eclimd just modifies the source file w/o reporting back any options. In that case subclim treated it as an error. Suggest to the user that the import was succesful. When Sublime detects the file change it'll load up the changes. --- subclim_plugin.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/subclim_plugin.py b/subclim_plugin.py index 4ce4ed2..0f0fbf7 100644 --- a/subclim_plugin.py +++ b/subclim_plugin.py @@ -760,7 +760,10 @@ def async_find_imports_task(): if isinstance(import_result, list): class_names.extend(import_result) elif isinstance(import_result, dict): - message.append(import_result['message']) + if import_result['message']: + message.append(import_result['message']) + else: + mesage = '' elif isinstance(import_result, str): message.append(import_result) sublime.set_timeout(on_find_imports_finished, 0) @@ -772,7 +775,9 @@ def on_find_imports_finished(): elif len(class_names) > 1: self.possible_imports = class_names self.show_import_menu() - + elif not message: + sublime.message_dialog("Import likely succeeded with a single option.") + pass tasks.put(async_find_imports_task) def call_eclim(self, project, _file, offset): From e0a494498fd540ec603abb02426ba1d87e901b32 Mon Sep 17 00:00:00 2001 From: Radu Margarint Date: Mon, 17 Nov 2014 22:26:15 -0800 Subject: [PATCH 6/6] Make warning and error regions more visible --- subclim_plugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subclim_plugin.py b/subclim_plugin.py index 0f0fbf7..5dd8cdc 100644 --- a/subclim_plugin.py +++ b/subclim_plugin.py @@ -709,13 +709,13 @@ def _view_visualize(self, view, first_view): for lineno in lines.keys() if len(list(filter(lambda x: x['error'], lines[lineno]))) > 0] view.add_regions( - 'subclim-errors', outlines, 'keyword', 'dot', JavaValidation.drawType) + 'subclim-errors', outlines, 'invalid', 'dot') outlines = [view.line(view.text_point(lineno - 1, 0)) for lineno in lines.keys() if len(list(filter(lambda x: x['error'], lines[lineno]))) <= 0] view.add_regions( - 'subclim-warnings', outlines, 'comment', 'dot', JavaValidation.drawType) + 'subclim-warnings', outlines, 'comment', 'bookmark') def on_selection_modified(self, view): views = [v for v in view.window().views() if v.buffer_id() is view.buffer_id()] if view.window() else None