|
10 | 10 |
|
11 | 11 | """This module exports the Clang plugin class."""
|
12 | 12 |
|
13 |
| -from SublimeLinter.lint import Linter, util |
| 13 | +import re |
| 14 | +from SublimeLinter.lint import Linter |
14 | 15 |
|
15 | 16 |
|
16 |
| -class Clang(Linter): |
17 |
| - """Provides an interface to clang.""" |
| 17 | +OUTPUT_RE = re.compile( |
| 18 | + r'<stdin>:(?P<line>\d+):' |
| 19 | + r'((?P<col>\d*): )?' # column number, colon and space are only applicable for single line messages |
| 20 | + # several lines of anything followed by |
| 21 | + # either error/warning/note or newline (= irrelevant backtrace content) |
| 22 | + # (lazy quantifiers so we don’t skip what we seek) |
| 23 | + r'(.*?((?P<error>error)|(?P<warning>warning|note)|\r?\n))+?' |
| 24 | + r': (?P<message>.+)', # match the remaining content of the current line for output |
| 25 | + re.MULTILINE |
| 26 | +) |
18 | 27 |
|
19 |
| - regex = ( |
20 |
| - r'<stdin>:(?P<line>\d+):' |
21 |
| - r'((?P<col>\d*): )?' # column number, colon and space are only applicable for single line messages |
22 |
| - # several lines of anything followed by |
23 |
| - # either error/warning/note or newline (= irrelevant backtrace content) |
24 |
| - # (lazy quantifiers so we don’t skip what we seek) |
25 |
| - r'(.*?((?P<error>error)|(?P<warning>warning|note)|\r?\n))+?' |
26 |
| - r': (?P<message>.+)' # match the remaining content of the current line for output |
27 |
| - ) |
28 |
| - |
29 |
| - multiline = True |
30 | 28 |
|
| 29 | +class clangc(Linter): |
| 30 | + cmd = 'clang -fsyntax-only -fno-caret-diagnostics ${args} -' |
31 | 31 | defaults = {
|
32 |
| - 'selector': 'source.c, source.c++', |
| 32 | + 'selector': 'source.c', |
33 | 33 | '-Wall': True,
|
34 | 34 | '-I +': [],
|
35 |
| - '-x': None |
| 35 | + '-x': 'c' |
36 | 36 | }
|
37 |
| - |
| 37 | + regex = OUTPUT_RE |
| 38 | + multiline = True |
38 | 39 | on_stderr = None
|
39 | 40 |
|
40 |
| - def cmd(self): |
41 |
| - """Return the command line to execute.""" |
42 |
| - |
43 |
| - cmd = 'clang -fsyntax-only -fno-caret-diagnostics ${args} -' |
44 |
| - |
45 |
| - settings = self.get_view_settings() |
46 |
| - |
47 |
| - # If not set by the user apply magic |
48 |
| - if settings['x'] is None: |
49 |
| - syntax = util.get_syntax(self.view) |
50 |
| - if syntax in ['c', 'c improved']: |
51 |
| - settings['x'] = 'c' |
52 |
| - elif syntax in ['c++', 'c++11']: |
53 |
| - settings['x'] = 'c++' |
54 | 41 |
|
55 |
| - return cmd |
| 42 | +class clangcplus(Linter): |
| 43 | + cmd = 'clang -fsyntax-only -fno-caret-diagnostics ${args} -' |
| 44 | + defaults = { |
| 45 | + 'selector': 'source.c++', |
| 46 | + '-Wall': True, |
| 47 | + '-I +': [], |
| 48 | + '-x': 'c++' |
| 49 | + } |
| 50 | + regex = OUTPUT_RE |
| 51 | + multiline = True |
| 52 | + on_stderr = None |
0 commit comments