Skip to content

Commit 0660961

Browse files
bors[bot]ehuss
andcommittedSep 20, 2018
345: On-save check: Show result in window status when done. r=ehuss a=ehuss Includes minor cleanup for tracking message levels. 347: Syntax: Support `vis` macro designator. r=ehuss a=ehuss Stabilized in 1.30. 348: Syntax: Fix tuple access so it doesn't show up as a float. r=ehuss a=ehuss I left the number portion scoped as an integer just as a personal preference, and to keep it symmetric with array access. 349: Syntax: Support irrefutable patterns in closure and function params. r=ehuss a=ehuss Co-authored-by: Eric Huss <[email protected]>
5 parents 8bfa2b3 + dd99693 + 566ab4d + 0ca5132 + 3a103b1 commit 0660961

12 files changed

+382
-92
lines changed
 

‎RustEnhanced.sublime-syntax

Lines changed: 87 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ variables:
1414
escaped_char: '\\([nrt0\"''\\]|x[0-7]\h|u\{(?:\h_*){1,6}\})'
1515
int_suffixes: '[iu](?:8|16|32|64|128|size)'
1616
float_suffixes: 'f(32|64)'
17+
dec_literal: '[0-9](?:[0-9_])*'
18+
float_exponent: '[eE][+-]?[0-9_]*[0-9][0-9_]*'
1719
contexts:
1820
main:
1921
- include: statements
@@ -309,6 +311,74 @@ contexts:
309311
- match: '(?=\S)'
310312
pop: true
311313

314+
pattern-param:
315+
- include: comments
316+
- match: '&'
317+
scope: keyword.operator.rust
318+
- match: \b(mut|ref)\b
319+
scope: storage.modifier.rust
320+
- match: '@'
321+
scope: keyword.operator.rust
322+
- match: '\b{{identifier}}\b(?!\s*(?:::|\{|\[|\())'
323+
scope: variable.parameter.rust
324+
325+
- match: '\{'
326+
# Struct pattern.
327+
scope: punctuation.section.block.begin.rust
328+
push:
329+
- meta_scope: meta.block.rust
330+
- match: '\}'
331+
scope: punctuation.section.block.end.rust
332+
pop: true
333+
- match: '(\d+)\s*(:)'
334+
# Tuple struct field specifier.
335+
captures:
336+
1: constant.numeric.integer.decimal.rust
337+
2: punctuation.separator.rust
338+
- match: '{{identifier}}\s*(:)'
339+
# Struct field specifier.
340+
captures:
341+
1: punctuation.separator.rust
342+
- match: '\.\.'
343+
scope: keyword.operator.rust
344+
- include: pattern-param
345+
346+
- match: '\('
347+
# Tuple or tuple struct pattern.
348+
scope: punctuation.section.group.begin.rust
349+
push:
350+
- meta_scope: meta.group.rust
351+
- match: '\)'
352+
scope: punctuation.section.group.end.rust
353+
pop: true
354+
- match: '\.\.'
355+
scope: keyword.operator.rust
356+
- include: pattern-param
357+
358+
- match: '\['
359+
# Slice pattern.
360+
scope: punctuation.section.brackets.begin.rust
361+
push:
362+
- meta_scope: meta.brackets.rust
363+
- match: '\]'
364+
scope: punctuation.section.brackets.end.rust
365+
pop: true
366+
- include: pattern-param
367+
368+
# Path for struct patterns.
369+
- match: '\bself\b|\bsuper\b'
370+
scope: keyword.other.rust
371+
- match: '\b{{identifier}}\b'
372+
- match: '::'
373+
374+
- match: ':(?!:)'
375+
# Type
376+
scope: punctuation.separator.rust
377+
push:
378+
- match: '(?=,|\)|\]|\}|\|)'
379+
pop: true
380+
- include: type-any-identifier
381+
312382
closure:
313383
- meta_content_scope: meta.function.closure.rust
314384
- match: '\|'
@@ -317,33 +387,16 @@ contexts:
317387

318388
closure-parameters:
319389
- meta_scope: meta.function.parameters.rust
390+
- match: '\|'
391+
scope: punctuation.definition.parameters.end.rust
392+
pop: true
393+
- include: pattern-param
320394
# If the user has just typed a |, exit the params
321395
# scope as soon as we hit something that it not a
322396
# valid part so the whole rest of the document isn't
323397
# highlighted using the params scope
324-
- include: comments
325-
- match: '(?=\()'
326-
push: group
327-
- match: '(?=[};)\]])'
328-
pop: true
329-
- match: '\|'
330-
scope: punctuation.definition.parameters.end.rust
398+
- match: '(?=[=};)\]])'
331399
pop: true
332-
- match: \bself\b
333-
scope: variable.parameter.rust
334-
- match: '({{identifier}})\s*(?:(:(?!:))|(?=\||,))'
335-
captures:
336-
1: variable.parameter.rust
337-
2: punctuation.separator.rust
338-
push:
339-
- match: (?=,|\|)
340-
pop: true
341-
- include: type-any-identifier
342-
- match: '&'
343-
scope: keyword.operator.rust
344-
- match: \b(mut|ref)\b
345-
scope: storage.modifier.rust
346-
- include: lifetime
347400

348401
closure-return:
349402
- meta_content_scope: meta.function.closure.rust
@@ -432,7 +485,7 @@ contexts:
432485
- include: raw-pointer
433486
- match: \b(mut|ref|const|unsafe)\b
434487
scope: storage.modifier.rust
435-
- match: \b(fn)\b(\()
488+
- match: \b(fn)\b\s*(\()
436489
captures:
437490
1: storage.type.function.rust
438491
2: meta.group.rust punctuation.definition.group.begin.rust
@@ -765,7 +818,7 @@ contexts:
765818
pop: true
766819
- include: macro-matchers
767820

768-
- match: '(\$\s*{{identifier}})\s*(:)\s*(ident|path|expr|ty|pat|stmt|block|item|meta|tt|lifetime)'
821+
- match: '(\$\s*{{identifier}})\s*(:)\s*(ident|path|expr|ty|pat|stmt|block|item|meta|tt|lifetime|vis)'
769822
captures:
770823
1: variable.parameter.rust
771824
2: punctuation.separator.rust
@@ -944,13 +997,7 @@ contexts:
944997
- include: comments
945998
- match: '(?=\))'
946999
pop: true
947-
- match: \bself\b
948-
scope: variable.parameter.rust
949-
- match: '({{identifier}})\s*(:(?!:))'
950-
captures:
951-
1: variable.parameter.rust
952-
2: punctuation.separator.rust
953-
- include: type-any-identifier
1000+
- include: pattern-param
9541001

9551002
fn-return:
9561003
- meta_scope: meta.function.rust
@@ -1197,22 +1244,18 @@ contexts:
11971244
scope: constant.other.placeholder.rust
11981245
11991246
numbers:
1200-
- match: '\b((?:\d[\d_]*)?\.)(\d[\d_]*(?:[eE][+-]?[\d_]+)?)({{float_suffixes}})?'
1201-
captures:
1202-
1: constant.numeric.float.rust
1203-
2: constant.numeric.float.rust
1204-
3: storage.type.numeric.rust
1205-
- match: '\b(\d[\d_]*\.)(?!\.)'
1206-
scope: constant.numeric.float.rust
1207-
- match: '\b(\d[\d_]*)({{float_suffixes}})\b'
1208-
captures:
1209-
1: constant.numeric.float.rust
1210-
2: storage.type.numeric.rust
1211-
- match: '\b(\d[\d_]*(?:\.[\d_]+)?[eE][-+]?[\d_]+)({{float_suffixes}})?\b'
1247+
- match: '\b({{dec_literal}}(?:\.{{dec_literal}})?(?:{{float_exponent}})?)({{float_suffixes}})'
12121248
captures:
12131249
1: constant.numeric.float.rust
12141250
2: storage.type.numeric.rust
1215-
- match: '\b(\d[\d_]*)({{int_suffixes}})?\b'
1251+
- match: '\b{{dec_literal}}\.{{dec_literal}}(?:{{float_exponent}})?'
1252+
scope: constant.numeric.float.rust
1253+
- match: '\b{{dec_literal}}{{float_exponent}}'
1254+
scope: constant.numeric.float.rust
1255+
- match: '\b{{dec_literal}}\.(?![A-Za-z._''])'
1256+
scope: constant.numeric.float.rust
1257+
1258+
- match: '\b({{dec_literal}})({{int_suffixes}})?\b'
12161259
captures:
12171260
1: constant.numeric.integer.decimal.rust
12181261
2: storage.type.numeric.rust

‎SyntaxCheckPlugin.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,31 @@ def run(self):
7878

7979
self.update_status()
8080
self.this_view_found = False
81+
CHECK_FAIL_MSG = 'Rust check failed, see console or debug log.'
8182
try:
8283
messages.clear_messages(self.window)
8384
try:
84-
self.get_rustc_messages()
85+
rc = self.get_rustc_messages()
8586
except rust_proc.ProcessTerminatedError:
87+
self.window.status_message('')
8688
return
87-
messages.messages_finished(self.window)
89+
except Exception as e:
90+
self.window.status_message(CHECK_FAIL_MSG)
91+
raise
8892
finally:
8993
self.done = True
90-
self.window.status_message('')
94+
messages.messages_finished(self.window)
95+
counts = messages.message_counts(self.window)
96+
if counts:
97+
msg = []
98+
for key, value in sorted(counts.items(), key=lambda x: x[0]):
99+
level = key.plural if value > 1 else key.name
100+
msg.append('%i %s' % (value, level))
101+
self.window.status_message('Rust check: %s' % (', '.join(msg,)))
102+
elif rc:
103+
self.window.status_message(CHECK_FAIL_MSG)
104+
else:
105+
self.window.status_message('Rust check: success')
91106

92107
def update_status(self, count=0):
93108
if self.done:
@@ -105,6 +120,9 @@ def get_rustc_messages(self):
105120
filename.
106121
107122
:raises rust_proc.ProcessTerminatedError: Check was canceled.
123+
:raises OSError: Failed to launch the child process.
124+
125+
:returns: Returns the process return code.
108126
"""
109127
method = util.get_setting('rust_syntax_checking_method', 'check')
110128
settings = cargo_settings.CargoSettings(self.window)
@@ -119,8 +137,7 @@ def get_rustc_messages(self):
119137
self.msg_rel_path = cmd['msg_rel_path']
120138
p = rust_proc.RustProc()
121139
p.run(self.window, cmd['command'], self.cwd, self, env=cmd['env'])
122-
p.wait()
123-
return
140+
return p.wait()
124141

125142
if method == 'no-trans':
126143
print('rust_syntax_checking_method == "no-trans" is no longer supported.')
@@ -129,10 +146,13 @@ def get_rustc_messages(self):
129146

130147
if method != 'check':
131148
print('Unknown setting for `rust_syntax_checking_method`: %r' % (method,))
132-
return
149+
return -1
133150

134151
td = target_detect.TargetDetector(self.window)
135152
targets = td.determine_targets(self.triggered_file_name)
153+
if not targets:
154+
return -1
155+
rc = 0
136156
for (target_src, target_args) in targets:
137157
cmd = settings.get_command(method, command_info, self.cwd, self.cwd,
138158
initial_settings={'target': ' '.join(target_args)},
@@ -149,9 +169,10 @@ def get_rustc_messages(self):
149169
p = rust_proc.RustProc()
150170
self.current_target_src = target_src
151171
p.run(self.window, cmd['command'], self.cwd, self, env=cmd['env'])
152-
p.wait()
172+
rc = p.wait()
153173
if self.this_view_found:
154-
break
174+
return rc
175+
return rc
155176

156177
#########################################################################
157178
# ProcListner methods

‎rust/levels.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import sublime
2+
from . import log
3+
4+
5+
class Level:
6+
7+
def __init__(self, order, name, plural):
8+
self.order = order
9+
self.name = name
10+
self.plural = plural
11+
12+
def __hash__(self):
13+
return hash(self.name)
14+
15+
def __eq__(self, other):
16+
if isinstance(other, Level):
17+
return self.name == other.name
18+
elif isinstance(other, str):
19+
return self.name == other
20+
else:
21+
return False
22+
23+
def __lt__(self, other):
24+
return self.order < other.order
25+
26+
def __le__(self, other):
27+
return self.order <= other.order
28+
29+
def __gt__(self, other):
30+
return self.order > other.order
31+
32+
def __ge__(self, other):
33+
return self.order >= other.order
34+
35+
def __repr__(self):
36+
return self.name
37+
38+
39+
LEVELS = {
40+
'error': Level(0, 'error', 'errors'),
41+
'warning': Level(1, 'warning', 'warnings'),
42+
'note': Level(2, 'note', 'notes'),
43+
'help': Level(3, 'help', 'help'),
44+
}
45+
46+
47+
def level_from_str(level):
48+
if level.startswith('error:'):
49+
# ICE
50+
level = 'error'
51+
try:
52+
return LEVELS[level]
53+
except KeyError:
54+
log.critical(sublime.active_window(),
55+
'RustEnhanced: Unknown message level %r encountered.',
56+
level)
57+
return LEVELS['error']

0 commit comments

Comments
 (0)