|
12 | 12 | """This module exports the Ruby plugin class.""" |
13 | 13 |
|
14 | 14 | from SublimeLinter.lint import RubyLinter |
| 15 | +import re |
15 | 16 |
|
16 | 17 |
|
17 | 18 | class Ruby(RubyLinter): |
@@ -39,4 +40,35 @@ def split_match(self, match): |
39 | 40 | if match.group('file') != '-': |
40 | 41 | match = None |
41 | 42 |
|
42 | | - return super().split_match(match) |
| 43 | + match, line, col, error, warning, message, _ = super().split_match(match) |
| 44 | + near = self.search_token(message) |
| 45 | + |
| 46 | + return match, line, col, error, warning, message, near |
| 47 | + |
| 48 | + def search_token(self, message): |
| 49 | + """Search text token to be highlighted.""" |
| 50 | + |
| 51 | + # First search for variable name enclosed in quotes |
| 52 | + m = re.search("(?<=`).*(?=')", message) |
| 53 | + |
| 54 | + # Then search for variable name following a dash |
| 55 | + if m is None: |
| 56 | + m = re.search('(?<= - )\S+', message) |
| 57 | + |
| 58 | + # Then search for mismatched indentation |
| 59 | + if m is None: |
| 60 | + m = re.search("(?<=mismatched indentations at ')end", message) |
| 61 | + |
| 62 | + # Then search for equal operator in conditional |
| 63 | + if m is None: |
| 64 | + m = re.search('(?<=found )=(?= in conditional)', message) |
| 65 | + |
| 66 | + # Then search for use of operator in void context |
| 67 | + if m is None: |
| 68 | + m = re.search('\S+(?= in void context)', message) |
| 69 | + |
| 70 | + # Then search for END in method |
| 71 | + if m is None: |
| 72 | + m = re.search('END(?= in method)', message) |
| 73 | + |
| 74 | + return m.group(0) if m else None |
0 commit comments