Skip to content

Commit d53a554

Browse files
committed
Handle Elm compiler errors
The Elm compiler can run successfully and produce a list of compile errors, or the compiler can fail with an error itself. Elm Language Support now handles both correctly. Fixes #51
1 parent ac41cb0 commit d53a554

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

Syntaxes/Elm Compile Messages.sublime-syntax

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ contexts:
3131
(.+) # \4: tag
3232
[ ][-][ ] # separator
3333
(.+?): # \5: $file
34-
(\d+): # \6: $line
35-
(\d+) # \7: $column
34+
(\d+):? # \6: $line
35+
(\d+)? # \7: $column
3636
\n$ # End
3737
comment: '-- type: TAG - file:line:column\nMessage\n'
3838
captures:

elm_make.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def create_panel(self, working_dir):
8686
# Enable result navigation
8787
settings.set(
8888
'result_file_regex',
89-
r'^\-\- \w+: (?=.+ \- (.+?):(\d+):(\d+))(.+) \- .*$'
89+
r'^\-\- \w+: (?=.+ \- (.+?):(\d+)(?=:(\d+))?)(.+) \- .*$'
9090
)
9191
settings.set('result_base_dir', working_dir)
9292

@@ -160,7 +160,12 @@ def format_output(self, output):
160160
try:
161161
data = json.loads(output)
162162
log_string('make.logging.json', output)
163-
return self.format_errors(data['errors'])
163+
if data['type'] == 'compile-errors':
164+
return self.format_errors(data['errors'])
165+
elif data['type'] == 'error':
166+
return self.format_compiler_error(data)
167+
else:
168+
return 'Unrecognized compiler output:\n' + str(output) + '\n\nPlease report this bug in Elm Language Support.\n\n'
164169
except ValueError as e:
165170
log_string('make.logging.invalid_json', output)
166171
return ''
@@ -185,6 +190,18 @@ def format_problem(self, file, problem):
185190
vars.pop('self') # https://bugs.python.org/issue23671
186191
return error_format.substitute(**vars)
187192

193+
def format_compiler_error(self, error):
194+
error_format = string.Template('-- $type: $title - $file:1\n\n$message\n')
195+
196+
type = 'error'
197+
title = error['title']
198+
file = error['path']
199+
message = self.format_message(error['message'])
200+
201+
vars = locals()
202+
vars.pop('self') # https://bugs.python.org/issue23671
203+
return error_format.substitute(**vars)
204+
188205
def format_message(self, message):
189206
format = lambda msg: msg['string'] if 'string' in msg else msg
190207

0 commit comments

Comments
 (0)