summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Aubry2012-07-13 05:44:26 (EDT)
committer sbernard2012-07-13 05:44:26 (EDT)
commita4b892dd3d655d6327e98adcb3bfd89e5948fe92 (patch)
tree0b590cc33fa729cd30882f615c54127a5a4b6e07
parentb84f91c3dba6e0d1cffb6cd6b46668bdca2332cb (diff)
downloadorg.eclipse.koneki.ldt-a4b892dd3d655d6327e98adcb3bfd89e5948fe92.zip
org.eclipse.koneki.ldt-a4b892dd3d655d6327e98adcb3bfd89e5948fe92.tar.gz
org.eclipse.koneki.ldt-a4b892dd3d655d6327e98adcb3bfd89e5948fe92.tar.bz2
Bug 385019 - [formatter] No formatting of the file first line
-rw-r--r--libraries/luaformatter/luaformatter.lua17
1 files changed, 7 insertions, 10 deletions
diff --git a/libraries/luaformatter/luaformatter.lua b/libraries/luaformatter/luaformatter.lua
index 39d4da7..14499c4 100644
--- a/libraries/luaformatter/luaformatter.lua
+++ b/libraries/luaformatter/luaformatter.lua
@@ -58,7 +58,7 @@ local function getindentlevel(source,indenttable)
--
-- Define AST walker
--
- local linetodepth = {}
+ local linetodepth = {0}
local walker = {
block = {},
expr = {},
@@ -72,14 +72,12 @@ local function getindentlevel(source,indenttable)
-- get first line of the block
local startline,startoffset = getfirstline(node)
local endline = getlastline(node)
- if source:sub(1,startoffset-1):find("[\r\n]%s*$") then
- for i=startline, endline do
- linetodepth[i]=walker.depth
- end
- else
- for i=startline+1, endline do
- linetodepth[i]=walker.depth
- end
+ -- If the block don't start by a new line, don't indent the first line
+ if not source:sub(1,startoffset-1):find("[\r\n]%s*$") then
+ startline = startline + 1
+ end
+ for i=startline, endline do
+ linetodepth[i]=walker.depth
end
walker.depth = walker.depth + 1
end
@@ -205,7 +203,6 @@ function M.indentcode(source, delimiter,indenttable, ...)
-- calculate indentation
local linetodepth = getindentlevel(source,indenttable)
-
-- Concatenate string with right identation
local indented = {}
for position=1, #positions do