diff --git a/lib/linter-ada.coffee b/lib/linter-ada.coffee index 5fa92ba..0939e95 100644 --- a/lib/linter-ada.coffee +++ b/lib/linter-ada.coffee @@ -1,3 +1,4 @@ +fs = require 'fs' path = require 'path' atom_linter = require 'atom-linter' @@ -6,16 +7,44 @@ module.exports = class LinterAda lint: (textEditor) -> editingFile = textEditor.getPath() cwd = path.dirname editingFile + efName = path.basename editingFile + regex = '(?.+):(?\\d+):(?\\d+):\\s(?.+)' styleregex = '\\(style\\).*' scs = atom.config.get('linter-ada.StyleCheckSwitch') scp = atom.config.get('linter-ada.StyleCheckParametersList') + + # Find out the projectpath base one current editingFile + [projectPath, relativePath] = atom.project.relativizePath(editingFile) + + gprregex = '.+\\.gpr' + if projectPath == null + gprfiles = [] + else + gprfiles = fs.readdirSync(projectPath).filter (x) -> x.match(gprregex) + + #Check if need to do style check if scs == true - parList = ["-f","-gnatef","-gnatc","-gnaty#{scp}",editingFile] + parList = ["-f","-F","-eS","-gnatef","-gnatc","-gnaty#{scp}"] + else + parList = ["-f","-F","-eS","-gnatef","-gnatc"] + + #Check if we have .gpr file in the project (atom's project idea) path + #if we have .gpr then use the first one + if gprfiles.length != 0 + firstGPR = gprfiles[0] + atom.notifications.addSuccess("LinterAda: Use #{firstGPR} for lint") + parList = ["-P",firstGPR].concat parList + parList = parList.concat efName + gnatMakeRunPath = projectPath else - parList = ["-f","-gnatef","-gnatc",editingFile] + atom.notifications.addInfo "LinterAda: No GPR found in Atom's \ + Project root will put obj file in current directory" + #Need to use the fullpath, so gnatmake wull givback a fullpath + parList = parList.concat editingFile + gnatMakeRunPath = cwd - atom_linter.exec("gnatmake", parList, {cwd: cwd, stream: 'both'}) + atom_linter.exec("gnatmake", parList, {cwd:gnatMakeRunPath, stream: 'both'}) .then (output) -> {stdout, stderr, exitCode} = output warnings = atom_linter.parse(stderr,regex).map((parsed) -> diff --git a/package.json b/package.json index 212b1ca..677f484 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "linter-ada", "main": "./lib/init", - "version": "0.1.0", + "version": "0.1.1", "description": "Linter for Ada use GNATMake", "repository": "https://github.com/soiamsoNG/linter-ada", "license": "MIT",