def run(self, *args): view = self.window.active_view() row, col = view.rowcol(view.sel()[0].a) offset = view.text_point(row, col) path = file_or_buffer_name(view) source = view.substr(sublime.Region(0, view.size())) if view.substr(offset) in [u'(', u')']: offset = view.text_point(row, col - 1) proxy = proxy_for(view) if not proxy: return def_result = proxy.definition_location( source, root_folder_for(view), path, offset) if not def_result or def_result == [None, None]: return target_path, target_lineno = def_result current_rowcol = view.rowcol(view.sel()[0].end()) current_lineno = current_rowcol[0] + 1 current_colno = current_rowcol[1] + 1 if None not in (path, target_path, target_lineno): self.save_pos(file_or_buffer_name(view), current_lineno, current_colno) path = target_path + ":" + str(target_lineno) self.window.open_file(path, sublime.ENCODED_POSITION) elif target_lineno is not None: self.save_pos(file_or_buffer_name(view), current_lineno, current_colno) path = file_or_buffer_name(view) + ":" + str(target_lineno) self.window.open_file(path, sublime.ENCODED_POSITION) else: # fail silently (user selected whitespace, etc) pass
def check(view=None): """Perform a linter check on the view """ if view is None: view = get_current_active_view() if not get_setting('python_linting', view, True): return filename = file_or_buffer_name(view) proxy = proxy_for(view) if not proxy: return lint_settings = { 'pep8': get_setting('pep8', view, default_value=True), 'pep8_ignore': get_setting('pep8_ignore', view, default_value=[]), 'pep8_max_line_length': get_setting( 'pep8_max_line_length', view, default_value=None), 'pyflakes_ignore': get_setting( 'pyflakes_ignore', view, default_value=[]), } code = view.substr(sublime.Region(0, view.size())) encoding = view.encoding() if encoding.lower() == "undefined": encoding = "utf-8" errors = proxy.check_syntax(code, encoding, lint_settings, filename) try: if errors: errors = pickle.loads(errors.data) vid = view.id() lines = set() # leave this here for compatibility with original plugin error_underlines[vid] = [] error_messages[vid] = {} violation_underlines[vid] = [] violation_messages[vid] = {} warning_underlines[vid] = [] warning_messages[vid] = {} if errors: parse_errors(view, errors, lines, vid) erroneous_lines[vid] = ListWithPointer(sorted(set( list(error_messages[vid].keys()) + list(violation_messages[vid].keys()) + list(warning_messages[vid].keys())))) # the result can be a list of errors, or single syntax exception try: _update_lint_marks(view, lines) except Exception as e: print('SublimePythonIDE: Add lint marks failed\n{0}'.format(e)) update_statusbar(view) except Exception as error: print("SublimePythonIDE: No server response\n{0}".format(error))
def run(self, *args): view = self.window.active_view() row, col = view.rowcol(view.sel()[0].a) offset = view.text_point(row, col) path = file_or_buffer_name(view) source = view.substr(sublime.Region(0, view.size())) if view.substr(offset) in [u'(', u')']: offset = view.text_point(row, col - 1) proxy = proxy_for(view) if not proxy: return def_result = proxy.definition_location( source, root_folder_for(view), path, offset) if not def_result or def_result == [None, None]: return target_path, target_lineno = def_result current_lineno = view.rowcol(view.sel()[0].end())[0] + 1 if None not in (path, target_path, target_lineno): self.save_pos(file_or_buffer_name(view), current_lineno) path = target_path + ":" + str(target_lineno) self.window.open_file(path, sublime.ENCODED_POSITION) elif target_lineno is not None: self.save_pos(file_or_buffer_name(view), current_lineno) path = file_or_buffer_name(view) + ":" + str(target_lineno) self.window.open_file(path, sublime.ENCODED_POSITION) else: # fail silently (user selected whitespace, etc) pass
def input_callback(self, input_str): if input_str == self.default: return proxy = proxy_for(self.view) if not proxy: return self.view.run_command("save") self.refactor(proxy, input_str, *self.refactoring_context()) self.view.run_command('revert') # reload view
def run(self, edit): if self.view.is_dirty(): self.view.run_command("save") if self.view.file_name(): row, col = self.view.rowcol(self.view.sel()[0].a) path = file_or_buffer_name(self.view) all_view = sublime.Region(0, self.view.size()) source = self.view.substr(all_view) proxy = proxy_for(self.view) if not proxy: return organized_source = proxy.organize_imports(source, root_folder_for(self.view), path) self.view.replace(edit, all_view, organized_source) # end with a saved view to be compatible with the other refactorings self.view.run_command("save")
def on_query_completions(self, view, prefix, locations): path = file_or_buffer_name(view) source = view.substr(sublime.Region(0, view.size())) loc = view.rowcol(locations[0]) # t0 = time.time() proxy = proxy_for(view) if not proxy: return [] proposals = proxy.completions(source, root_folder_for(view), path, loc) # proposals = ( # proxy.profile_completions(source, root_folder_for(view), path, loc) # ) # print("+++", time.time() - t0) if proposals: completion_flags = (sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS) return (proposals, completion_flags) return proposals
def on_query_completions(self, view, prefix, locations): path = file_or_buffer_name(view) source = view.substr(sublime.Region(0, view.size())) loc = view.rowcol(locations[0]) # t0 = time.time() proxy = proxy_for(view) if not proxy: return [] proposals = proxy.completions(source, root_folder_for(view), path, loc) # proposals = ( # proxy.profile_completions(source, root_folder_for(view), path, loc) # ) # print("+++", time.time() - t0) if proposals: completion_flags = ( sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS ) return (proposals, completion_flags) return proposals
def run(self): view = self.window.active_view() row, col = view.rowcol(view.sel()[0].a) offset = view.text_point(row, col) path = file_or_buffer_name(view) source = view.substr(sublime.Region(0, view.size())) if view.substr(offset) in [u'(', u')']: offset = view.text_point(row, col - 1) proxy = proxy_for(view) if not proxy: return doc = proxy.documentation(source, root_folder_for(view), path, offset) if doc: open_pydoc_in_view = get_setting("open_pydoc_in_view") if open_pydoc_in_view: self.display_docs_in_view(doc) else: self.display_docs_in_panel(view, doc) else: word = view.substr(view.word(offset)) self.notify_no_documentation(view, word)
def on_post_save_async(self, view, *args): proxy = proxy_for(view) if not proxy: return path = file_or_buffer_name(view) proxy.report_changed(root_folder_for(view), path)
def check(view=None): """Perform a linter check on the view """ if view is None: view = get_current_active_view() if not get_setting('python_linting', view, True): return filename = file_or_buffer_name(view) proxy = proxy_for(view) if not proxy: return lint_settings = { 'pep8': get_setting('pep8', view, default_value=True), 'pep8_ignore': get_setting('pep8_ignore', view, default_value=[]), 'pep8_max_line_length': get_setting('pep8_max_line_length', view, default_value=None), 'pyflakes_ignore': get_setting('pyflakes_ignore', view, default_value=[]), } code = view.substr(sublime.Region(0, view.size())) encoding = view.encoding() if encoding.lower() == "undefined": encoding = "utf-8" errors = proxy.check_syntax(code, encoding, lint_settings, filename) try: if errors: errors = pickle.loads(errors.data) vid = view.id() lines = set() # leave this here for compatibility with original plugin error_underlines[vid] = [] error_messages[vid] = {} violation_underlines[vid] = [] violation_messages[vid] = {} warning_underlines[vid] = [] warning_messages[vid] = {} if errors: parse_errors(view, errors, lines, vid) erroneous_lines[vid] = ListWithPointer( sorted( set( list(error_messages[vid].keys()) + list(violation_messages[vid].keys()) + list(warning_messages[vid].keys())))) # the result can be a list of errors, or single syntax exception try: _update_lint_marks(view, lines) except Exception as e: print('SublimePythonIDE: Add lint marks failed\n{0}'.format(e)) update_statusbar(view) except Exception as error: print("SublimePythonIDE: No server response\n{0}".format(error))