From 4dd7c5861d591ae9d49a71d6f830d088883da7bd Mon Sep 17 00:00:00 2001 From: "Jip J. Dekker" Date: Wed, 29 Nov 2017 16:22:37 +1100 Subject: [PATCH] Fixes errors being shown in the wrong file --- CHANGELOG.md | 4 ++++ lib/linter-mzn.coffee | 17 ++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 609f5d3..530e9b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## [0.1.2] +### Fixes +- Errors made in included files will now be correctly located + ## [0.1.1] - 2017-11-17 ### Fixes - Small fixes to documentation and package definition diff --git a/lib/linter-mzn.coffee b/lib/linter-mzn.coffee index 352c18c..aadea0f 100644 --- a/lib/linter-mzn.coffee +++ b/lib/linter-mzn.coffee @@ -23,10 +23,11 @@ class LinterMZN atomLinter.exec(@compilerPath, args, options) .then (result) => {stdout, stderr, exit} = result + console.log stderr if exit is 0 [] else - @parse stderr, textEditor.getPath() + @parse stderr .catch (error) -> console.log error atom.notifications.addError "Failed to run #{command}", @@ -34,7 +35,7 @@ class LinterMZN dismissable: true [] - parse: (output, filePath) => + parse: (output) => messages = [] output = output.split('\n') warningLines = (i for line, i in output when /:([0-9]+):/.test(line) && ! /(did you forget to specify a data file\?)/.test(output[i+1])) @@ -42,14 +43,16 @@ class LinterMZN i = 0 while i < warningLines.length if i >= warningLines.length - 1 - messages.push @generateMessage output[warningLines[i]..], filePath + messages.push @generateMessage output[warningLines[i]..] else - messages.push @generateMessage output[warningLines[i]..warningLines[i+1]-1], filePath + messages.push @generateMessage output[warningLines[i]..warningLines[i+1]-1] i++ return messages - generateMessage: (output, filePath) -> + generateMessage: (output) -> + file = output[0].match(/^[^:]*/)[0] + console.log file match = output[0].match(/:([0-9]+):/) line = parseInt(match[1]) output = output[1..] @@ -63,9 +66,9 @@ class LinterMZN message = { severity: 'error', - excerpt: output.join('\n').replace(/MiniZinc: /, ""), + excerpt: output.join('\n').replace(/MiniZinc: /, "").replace(/Error: /, ""), location:{ - file: filePath, + file: file, position: [[line-1,startcol], [line-1,endcol]], } }