Skip to content

Commit 24cf60a

Browse files
author
Monte Goulding
committed
Added a linter for script parsing errors. Requires linter package installed and after pulling changes cd into repo and execute apm install to get atom-linter node module. Also requires a path to a standalone engine which defaults to 'livecode' assuming you have a symlink to a standalone engine somewhere in the current $PATH. Otherwise you can set the path under the language-livecode settings. TODO: GenerateSnippets stack should probably update scriptErrors.txt (hopefully from the livened repo somewhere) too to ensure it's updated.
1 parent e6c746f commit 24cf60a

4 files changed

Lines changed: 644 additions & 0 deletions

File tree

lib/main.coffee

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{CompositeDisposable} = require 'atom'
2+
3+
module.exports =
4+
config:
5+
executablePath:
6+
type: 'string'
7+
title: 'LiveCode Standalone Engine Path'
8+
default: 'livecode' # Let OS's $PATH handle the rest
9+
10+
activate: ->
11+
@subscriptions = new CompositeDisposable
12+
@subscriptions.add atom.config.observe 'language-livecode.executablePath',
13+
(executablePath) =>
14+
@executablePath = executablePath
15+
path = require 'path'
16+
@linterPath = path.join(__dirname, '..', 'tools', 'Linter.livecodescript')
17+
18+
deactivate: ->
19+
@subscriptions.dispose()
20+
21+
provideLinter: ->
22+
helpers = require('atom-linter')
23+
provider =
24+
grammarScopes: ['source.livecodescript']
25+
scope: 'file'
26+
lintOnFly: true
27+
lint: (textEditor) =>
28+
filePath = textEditor.getPath()
29+
command = @executablePath
30+
parameters = []
31+
parameters.push('-ui')
32+
stackfile = @linterPath
33+
parameters.push(stackfile)
34+
text = textEditor.getText()
35+
return helpers.exec(command, parameters, {stdin: text}).then (output) ->
36+
regex = /(\d+),(.*)/g
37+
messages = []
38+
while((match = regex.exec(output)) isnt null)
39+
messages.push
40+
type: "Error"
41+
filePath: filePath
42+
range: helpers.rangeFromLineNumber(textEditor, match[1]-1)
43+
text: match[2]
44+
return messages

package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,16 @@
66
"license": "GPLv3",
77
"engines": {
88
"atom": "*"
9+
},
10+
"main": "./lib/main",
11+
"dependencies": {
12+
"atom-linter": "^3.0.0"
13+
},
14+
"providedServices": {
15+
"linter": {
16+
"versions": {
17+
"1.0.0": "provideLinter"
18+
}
19+
}
920
}
1021
}

tools/Linter.livecodescript

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
script "Linter"
2+
3+
on startup
4+
try
5+
read from stdin until empty
6+
put it into theScript
7+
8+
local isScriptOnly = false
9+
if word 1 of theScript is "script" then
10+
put true into isScriptOnly
11+
end if
12+
13+
put the filename of me into theFilename
14+
set the itemDelimiter to slash
15+
put "scriptErrors.txt" into item -1 of theFilename
16+
put url ("file:"&theFilename) into theErrorsList
17+
18+
create script only stack "TestScript"
19+
20+
if isScriptOnly then
21+
delete line 1 of theScript
22+
end if
23+
24+
set the script of stack "TestScript" to theScript
25+
26+
put the result into theErrors
27+
set the itemDelimiter to comma
28+
29+
repeat for each line theError in theErrors
30+
if theError is not empty then
31+
if isScriptOnly then
32+
add 1 to item 2 of theError
33+
end if
34+
write item 2 of theError, line (item 1 of theError) of theErrorsList & linefeed to stdout
35+
end if
36+
end repeat
37+
38+
write linefeed to stdout
39+
catch e
40+
write e & linefeed & linefeed to stdout
41+
end try
42+
43+
quit
44+
end startup

0 commit comments

Comments
 (0)