Skip to content

Commit fb7410d

Browse files
author
Monte Goulding
committed
Added support for explicit variables mode, descriptions for the settings, documented explicit variables mode and that the server engine must be 7.1+ because the linter uses commandArguments. Also some changes to main.coffee to kill errors from the coffee linter.
1 parent bd57d38 commit fb7410d

File tree

3 files changed

+50
-22
lines changed

3 files changed

+50
-22
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ script compilation errors on the fly.
4848
Dependencies:
4949

5050
* The [linter package](https://atom.io/packages/linter) needs to be installed
51-
* LiveCode Server engine for the platform it is being run on must be accessible
51+
* LiveCode 7.1+ Server engine for the platform it is being run on must be accessible
5252

5353
The default setting assumes you have installed the LiveCode Server engine somewhere
5454
on the current `$PATH` with the name `livecode-server`. However, you can enter any
@@ -58,6 +58,9 @@ For LiveCode Server the linter will only check for errors within the scope of
5858
the file being edited. If for example a variable re-declarition error is caused
5959
by the inclusion of another file that error won't be detected.
6060

61+
The linter supports an optional explicit variables mode which can be turned on
62+
via the package settings.
63+
6164
## Authors
6265

6366
* Ralf Bitter

lib/main.coffee

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,22 @@ module.exports =
66
type: 'string'
77
title: 'LiveCode Server Engine Path'
88
default: 'livecode-server' # Let OS's $PATH handle the rest
9+
description: 'Where is your livecode server installed? ' +
10+
'Default assumes it\'s on $PATH'
11+
explicitVars:
12+
type: 'boolean'
13+
title: 'Explicit Variables'
14+
default: 'false'
15+
description: 'Get errors on undeclared variables'
916

1017
activate: ->
1118
@subscriptions = new CompositeDisposable
1219
@subscriptions.add atom.config.observe 'language-livecode.executablePath',
1320
(executablePath) =>
1421
@executablePath = executablePath
22+
@subscriptions.add atom.config.observe 'language-livecode.explicitVars',
23+
(explicitVars) =>
24+
@explicitVars = explicitVars
1525
path = require 'path'
1626
@linterPath = path.join(__dirname, '..', 'tools', 'Linter.lc')
1727

@@ -25,21 +35,27 @@ module.exports =
2535
scope: 'file'
2636
lintOnFly: true
2737
lint: (textEditor) =>
28-
filePath = textEditor.getPath()
29-
command = @executablePath
30-
parameters = []
31-
stackfile = @linterPath
32-
parameters.push(stackfile)
33-
scope = '-scope=' + textEditor.getRootScopeDescriptor()
34-
parameters.push(scope)
35-
text = textEditor.getText()
36-
return helpers.exec(command, parameters, {stdin: text}).then (output) ->
37-
regex = /(\d+),(\d+),(.*)/g
38-
messages = []
39-
while((match = regex.exec(output)) isnt null)
40-
messages.push
41-
type: "Error"
42-
filePath: filePath
43-
range: [[match[1]-1, match[2]-0],[match[1]-1, textEditor.getBuffer().lineLengthForRow(match[1]-1)]]
44-
text: match[3]
45-
return messages
38+
filePath = textEditor.getPath()
39+
command = @executablePath
40+
parameters = []
41+
stackfile = @linterPath
42+
parameters.push(stackfile)
43+
scope = '-scope=' + textEditor.getRootScopeDescriptor()
44+
parameters.push(scope)
45+
explicitVariables = '-explicitVariables=' + @explicitVars
46+
parameters.push(explicitVariables)
47+
text = textEditor.getText()
48+
return helpers.exec(command, parameters, {stdin: text}).then (output) ->
49+
regex = /(\d+),(\d+),(.*)/g
50+
messages = []
51+
while((match = regex.exec(output)) isnt null)
52+
line = match[1]-1
53+
messages.push
54+
type: "Error"
55+
filePath: filePath
56+
range: [
57+
[line, match[2]-0],
58+
[line, textEditor.getBuffer().lineLengthForRow(line)]
59+
]
60+
text: match[3]
61+
return messages

tools/Linter.lc

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@ local sLastLine
66
Lint
77

88
command Lint
9-
local tScope
9+
local tScope, theArgument
1010
repeat for each element theArgument in the commandArguments
1111
if theArgument begins with "-scope" then
1212
split theArgument with "="
1313
put theArgument[2] into tScope
14+
else if theArgument begins with "-explicitVariables" then
15+
split theArgument with "="
16+
set the explicitVariables to theArgument[2]
1417
end if
1518
end repeat
1619

1720
read from stdin until empty
21+
local tScript
1822
put it into tScript
1923

2024
put the scriptParsingErrors into sErrorsList
@@ -36,10 +40,13 @@ command Lint
3640

3741
set the script of stack "TestScript" to tScript
3842

43+
local theErrors
3944
put the result into theErrors
4045
split theErrors with return
46+
local tIndex
4147
repeat with tIndex = 1 to the number of elements in theErrors
4248
if theErrors[tIndex] is not empty then
49+
local tMessage
4350
put sErrorsList[item 1 of theErrors[tIndex]] into tMessage
4451
if tMessage is not empty then
4552
if item 4 of theErrors[tIndex] is not empty then
@@ -51,6 +58,7 @@ command Lint
5158
end repeat
5259
else if tScope is ".source.iRev" then
5360
-- write out to a temporary file and include
61+
local tFile
5462
put the temporary folder & slash & uuid() into tFile
5563
-- can't lint a whole web app...
5664
replace "include" with "# include" in tScript
@@ -67,14 +75,14 @@ command Lint
6775
end Lint
6876

6977
command scriptExecutionError pStack, pFiles
70-
local tHint, tFile
71-
--write 1,1,line 2 of pStack & linefeed to stdout
7278
split pStack with return
79+
local tIndex
7380
repeat with tIndex = 2 to the number of elements in pStack
7481
if item 1 of pStack[tIndex] is 730 then
7582
exit repeat
7683
end if
7784
if item 2 of pStack[tIndex] is not 0 and item 2 of pStack[tIndex] is not sLastLine then
85+
local tMessage
7886
put sErrorsList[item 1 of pStack[tIndex]] into tMessage
7987
if tMessage is not empty then
8088
if item 4 of pStack[tIndex] is not empty then
@@ -86,6 +94,7 @@ command scriptExecutionError pStack, pFiles
8694
end repeat
8795

8896
-- cleanup
97+
local tFile
8998
set the itemDelimiter to slash
9099
repeat for each line tFile in pFiles
91100
if item -1 of tFile is "Linter.lc" then

0 commit comments

Comments
 (0)