Skip to content
This repository
Browse code

Provide a "Goto Next Error" option

  • Loading branch information...
commit 971d32d57f88cf4702743e29e55128827952d069 1 parent d5890a2
Ben Selby authored August 11, 2012
4  Changelog.md
Source Rendered
... ...
@@ -1,6 +1,10 @@
1 1
 Sublime PHP CodeSniffer, Linter and Mess Detector Plugin Changelog
2 2
 ==================================================================
3 3
 
  4
+4.3
  5
+---
  6
+* 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
  7
+
4 8
 4.2
5 9
 ---
6 10
 * Ability to configure if you want the errors to be highlighted in the editor. Thanks to [Aleksandr Gornostal](https://github.com/gornostal)
1  Context.sublime-menu
@@ -6,6 +6,7 @@
6 6
         [
7 7
             { "command": "phpcs_sniff_this_file", "caption": "Sniff this file" },
8 8
             { "command": "phpcs_show_previous_errors", "caption": "Show previous errors" },
  9
+            { "command": "phpcs_goto_next_error", "caption": "Goto Next Error" },
9 10
             { "command": "phpcs_clear_sniffer_marks", "caption": "Clear sniffer marks" },
10 11
             { "command": "phpcs_fix_this_file", "caption": "Fix this file (PHP-CS-Fixer)" }
11 12
         ]
3  Default (OSX).sublime-keymap
... ...
@@ -1,4 +1,5 @@
1 1
 [
2 2
     { "keys": ["ctrl+super+s"], "command": "phpcs_show_previous_errors" },
3  
-    { "keys": ["shift+ctrl+super+s"], "command": "phpcs_sniff_this_file" }
  3
+    { "keys": ["shift+ctrl+super+s"], "command": "phpcs_sniff_this_file" },
  4
+    { "keys": ["ctrl+super+n"], "command": "phpcs_goto_next_error" }
4 5
 ]
4  Default.sublime-commands
@@ -12,6 +12,10 @@
12 12
         "command": "phpcs_show_previous_errors"
13 13
     },
14 14
     {
  15
+        "caption": "PHP Code Sniffer: Goto next error",
  16
+        "command": "phpcs_goto_next_error"
  17
+    },
  18
+    {
15 19
         "caption": "PHP Coding Standards Fixer: Fix this file",
16 20
         "command": "phpcs_fix_this_file"
17 21
     }
32  phpcs.py
@@ -355,6 +355,27 @@ def get_errors(self, line):
355 355
 
356 356
         return self.error_lines[line + 1]
357 357
 
  358
+    def get_next_error(self, line):
  359
+        current_line = line + 1
  360
+
  361
+        cache_error=None
  362
+        # todo: Need a way of getting the line count of the current file!
  363
+        cache_line=1000000
  364
+        for error in self.report:
  365
+            error_line = error.get_line()
  366
+
  367
+            if cache_error != None:
  368
+                cache_line = cache_error.get_line()
  369
+
  370
+            if int(error_line) > int(current_line) and int(error_line) < int(cache_line):
  371
+                cache_error = error
  372
+
  373
+        if cache_error != None:
  374
+            pt = cache_error.get_point()
  375
+            self.window.active_view().sel().clear()
  376
+            self.window.active_view().sel().add(sublime.Region(pt))
  377
+            self.window.active_view().show(pt)
  378
+
358 379
 
359 380
 class PhpcsTextBase(sublime_plugin.TextCommand):
360 381
     """Base class for Text commands in the plugin, mainly here to check php files"""
@@ -367,7 +388,7 @@ def description(self):
367 388
         if not PhpcsTextBase.should_execute(self.view):
368 389
             return "Invalid file format"
369 390
         else:
370  
-            return description
  391
+            return self.description
371 392
 
372 393
     @staticmethod
373 394
     def should_execute(view):
@@ -406,6 +427,15 @@ def is_enabled(self):
406 427
             and len(PhpcsCommand.instance(self.view, False).error_list)
407 428
 
408 429
 
  430
+class PhpcsGotoNextErrorCommand(PhpcsTextBase):
  431
+    """Go to the next error from the current position"""
  432
+    def run(self, args):
  433
+        line = self.view.rowcol(self.view.sel()[0].end())[0]
  434
+
  435
+        cmd = PhpcsCommand.instance(self.view)
  436
+        next_line = cmd.get_next_error(line)
  437
+
  438
+
409 439
 class PhpcsClearSnifferMarksCommand(PhpcsTextBase):
410 440
     """Command to clear the sniffer marks from the view"""
411 441
     description = 'Clear sniffer marks...'

0 notes on commit 971d32d

Please sign in to comment.
Something went wrong with that request. Please try again.