Adds the linter from linter-mzn to the package
This commit is contained in:
parent
306bfa942e
commit
e2e9d97cfb
@ -1,3 +1,6 @@
|
|||||||
|
## 0.4.0
|
||||||
|
- Combines the linter and syntax highlighting package (formerly https://github.com/jjdekker/linter-mzn). I'll look into the possibility of disabling the linter extension at a later stadium.
|
||||||
|
|
||||||
## 0.3.2
|
## 0.3.2
|
||||||
- Removes some duplicate syntax
|
- Removes some duplicate syntax
|
||||||
- Fixes the highlighting of numerical constants
|
- Fixes the highlighting of numerical constants
|
||||||
|
39
lib/init.coffee
Normal file
39
lib/init.coffee
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
{CompositeDisposable} = require 'atom'
|
||||||
|
|
||||||
|
module.exports = AtomLanguageMZN =
|
||||||
|
config:
|
||||||
|
mzn2fznPath:
|
||||||
|
type: 'string'
|
||||||
|
default: 'mzn2fzn'
|
||||||
|
description: "Path to Minizinc's compiler `mzn2fzn`"
|
||||||
|
|
||||||
|
activate: (state) ->
|
||||||
|
console.log 'language-mzn: package loaded,
|
||||||
|
ready to get initialized by AtomLinter.'
|
||||||
|
|
||||||
|
if not atom.packages.getLoadedPackage 'linter'
|
||||||
|
atom.notifications.addError 'Linter package not found',
|
||||||
|
detail: '[language-mzn] `linter` package not found. \
|
||||||
|
Please install https://github.com/AtomLinter/Linter'
|
||||||
|
|
||||||
|
@subscriptions = new CompositeDisposable
|
||||||
|
|
||||||
|
@subscriptions.add atom.config.observe 'linter-mzn.mzn2fznPath', (mzn2fznPath) =>
|
||||||
|
@mzn2fznPath = mzn2fznPath
|
||||||
|
|
||||||
|
deactivate: ->
|
||||||
|
@subscriptions.dispose()
|
||||||
|
|
||||||
|
serialize: ->
|
||||||
|
AtomLanguageMZNViewState: @AtomLanguageMZNView.serialize()
|
||||||
|
|
||||||
|
provideLinter: ->
|
||||||
|
LinterMZN = require('./linter-mzn')
|
||||||
|
@provider = new LinterMZN()
|
||||||
|
return {
|
||||||
|
name: 'MiniZinc',
|
||||||
|
grammarScopes: ['source.mzn'],
|
||||||
|
scope: 'file', # or 'project'
|
||||||
|
lintOnFly: true,
|
||||||
|
lint: @provider.lint
|
||||||
|
}
|
67
lib/linter-mzn.coffee
Normal file
67
lib/linter-mzn.coffee
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
{BufferedProcess} = require 'atom'
|
||||||
|
|
||||||
|
class LinterMZN
|
||||||
|
lintProcess: null
|
||||||
|
|
||||||
|
config: (key) ->
|
||||||
|
atom.config.get "language-mzn.#{key}"
|
||||||
|
|
||||||
|
lint: (textEditor) =>
|
||||||
|
return new Promise (resolve, reject) =>
|
||||||
|
output = ''
|
||||||
|
command = @config 'mzn2fznPath'
|
||||||
|
args = ['--instance-check-only', textEditor.getPath()]
|
||||||
|
options = process.env
|
||||||
|
|
||||||
|
stdout = (data) ->
|
||||||
|
atom.notifications.addWarning data
|
||||||
|
stderr = (data) ->
|
||||||
|
output += data
|
||||||
|
exit = (code) =>
|
||||||
|
if code is 0
|
||||||
|
resolve []
|
||||||
|
else
|
||||||
|
messages = @parse output, textEditor.getPath()
|
||||||
|
resolve messages
|
||||||
|
|
||||||
|
@lintProcess = new BufferedProcess({command, args, options, stdout, stderr, exit})
|
||||||
|
@lintProcess.onWillThrowError ({error, handle}) ->
|
||||||
|
atom.notifications.addError "Failed to run #{command}",
|
||||||
|
detail: "#{error.message}"
|
||||||
|
dismissable: true
|
||||||
|
handle()
|
||||||
|
resolve []
|
||||||
|
|
||||||
|
parse: (output, filePath) =>
|
||||||
|
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]))
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
while i < warningLines.length
|
||||||
|
if i >= warningLines.length - 1
|
||||||
|
messages.push @generateMessage output[warningLines[i]..], filePath
|
||||||
|
else
|
||||||
|
messages.push @generateMessage output[warningLines[i]..warningLines[i+1]-1], filePath
|
||||||
|
i++
|
||||||
|
|
||||||
|
return messages
|
||||||
|
|
||||||
|
generateMessage: (output, filePath) ->
|
||||||
|
match = output[0].match(/:([0-9]+):/)
|
||||||
|
line = parseInt(match[1])
|
||||||
|
console.log line + '\n'
|
||||||
|
|
||||||
|
message = {
|
||||||
|
type: 'Error',
|
||||||
|
text: output[1..].join('\n').replace(/MiniZinc: /, ""),
|
||||||
|
range: [[line-1,0], [line-1,500]],
|
||||||
|
filePath: filePath,
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log message
|
||||||
|
|
||||||
|
return message
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = LinterMZN
|
18
package.json
18
package.json
@ -1,11 +1,25 @@
|
|||||||
{
|
{
|
||||||
"name": "language-mzn",
|
"name": "language-mzn",
|
||||||
|
"main": "./lib/init",
|
||||||
"version": "0.3.2",
|
"version": "0.3.2",
|
||||||
"description": "Adds syntax highlighting for the MiniZinc constraint modeling language",
|
"description": "A language package for the MiniZinc constraint modeling language",
|
||||||
"repository": "https://github.com/jjdekker/language-mzn",
|
"repository": "https://github.com/jjdekker/language-mzn",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
"atom": ">=1.0.0 <2.0.0"
|
"atom": ">=1.0.0 <2.0.0"
|
||||||
},
|
},
|
||||||
"dependencies": {}
|
"dependencies": {
|
||||||
|
"atom-linter": "^2.0.5",
|
||||||
|
"atom-package-deps": "^2.0.1"
|
||||||
|
},
|
||||||
|
"package-deps": [
|
||||||
|
"linter"
|
||||||
|
],
|
||||||
|
"providedServices": {
|
||||||
|
"linter": {
|
||||||
|
"versions": {
|
||||||
|
"1.0.0": "provideLinter"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user