Skip to content

Commit

Permalink
Provide a "Goto Next Error" option
Browse files Browse the repository at this point in the history
  • Loading branch information
benmatselby committed Aug 13, 2012
1 parent d5890a2 commit 971d32d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
@@ -1,6 +1,10 @@
Sublime PHP CodeSniffer, Linter and Mess Detector Plugin Changelog
==================================================================

4.3
---
* Ehancement for [GH-34](https://github.com/benmatselby/sublime-phpcs/issues/34) which provides a command to "Goto Next Error" which can also have a shortcut key assigned to it. Thanks to [Casey Becking](https://github.com/caseybecking) for raising the feature request

4.2
---
* Ability to configure if you want the errors to be highlighted in the editor. Thanks to [Aleksandr Gornostal](https://github.com/gornostal)
Expand Down
1 change: 1 addition & 0 deletions Context.sublime-menu
Expand Up @@ -6,6 +6,7 @@
[
{ "command": "phpcs_sniff_this_file", "caption": "Sniff this file" },
{ "command": "phpcs_show_previous_errors", "caption": "Show previous errors" },
{ "command": "phpcs_goto_next_error", "caption": "Goto Next Error" },
{ "command": "phpcs_clear_sniffer_marks", "caption": "Clear sniffer marks" },
{ "command": "phpcs_fix_this_file", "caption": "Fix this file (PHP-CS-Fixer)" }
]
Expand Down
3 changes: 2 additions & 1 deletion Default (OSX).sublime-keymap
@@ -1,4 +1,5 @@
[
{ "keys": ["ctrl+super+s"], "command": "phpcs_show_previous_errors" },
{ "keys": ["shift+ctrl+super+s"], "command": "phpcs_sniff_this_file" }
{ "keys": ["shift+ctrl+super+s"], "command": "phpcs_sniff_this_file" },
{ "keys": ["ctrl+super+n"], "command": "phpcs_goto_next_error" }
]
4 changes: 4 additions & 0 deletions Default.sublime-commands
Expand Up @@ -11,6 +11,10 @@
"caption": "PHP Code Sniffer: Show previous errors",
"command": "phpcs_show_previous_errors"
},
{
"caption": "PHP Code Sniffer: Goto next error",
"command": "phpcs_goto_next_error"
},
{
"caption": "PHP Coding Standards Fixer: Fix this file",
"command": "phpcs_fix_this_file"
Expand Down
32 changes: 31 additions & 1 deletion phpcs.py
Expand Up @@ -355,6 +355,27 @@ def get_errors(self, line):

return self.error_lines[line + 1]

def get_next_error(self, line):
current_line = line + 1

cache_error=None
# todo: Need a way of getting the line count of the current file!
cache_line=1000000
for error in self.report:
error_line = error.get_line()

if cache_error != None:
cache_line = cache_error.get_line()

if int(error_line) > int(current_line) and int(error_line) < int(cache_line):
cache_error = error

if cache_error != None:
pt = cache_error.get_point()
self.window.active_view().sel().clear()
self.window.active_view().sel().add(sublime.Region(pt))
self.window.active_view().show(pt)


class PhpcsTextBase(sublime_plugin.TextCommand):
"""Base class for Text commands in the plugin, mainly here to check php files"""
Expand All @@ -367,7 +388,7 @@ def description(self):
if not PhpcsTextBase.should_execute(self.view):
return "Invalid file format"
else:
return description
return self.description

@staticmethod
def should_execute(view):
Expand Down Expand Up @@ -406,6 +427,15 @@ def is_enabled(self):
and len(PhpcsCommand.instance(self.view, False).error_list)


class PhpcsGotoNextErrorCommand(PhpcsTextBase):
"""Go to the next error from the current position"""
def run(self, args):
line = self.view.rowcol(self.view.sel()[0].end())[0]

cmd = PhpcsCommand.instance(self.view)
next_line = cmd.get_next_error(line)


class PhpcsClearSnifferMarksCommand(PhpcsTextBase):
"""Command to clear the sniffer marks from the view"""
description = 'Clear sniffer marks...'
Expand Down

0 comments on commit 971d32d

Please sign in to comment.