summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-09-15 16:35:06 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-09-15 16:35:06 +0800
commit33eff2cb98efe8380513b1cc2712baab2be3c940 (patch)
treeb17063a9d75aef90ad3b992fda8f2aec5641915a /script
parent8880b7d63931469c0b7bfb69004f342236ce2811 (diff)
downloadlua-language-server-33eff2cb98efe8380513b1cc2712baab2be3c940.zip
update
Diffstat (limited to 'script')
-rw-r--r--script/parser/guide.lua4
-rw-r--r--script/parser/luadoc.lua21
-rw-r--r--script/parser/newparser.lua23
3 files changed, 29 insertions, 19 deletions
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index 14e19094..16ee3e30 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -781,10 +781,6 @@ function m.lineRange(lines, row, ignoreNL)
end
end
-function m.lineData(lines, row)
- return lines[row]
-end
-
local isSetMap = {
['setglobal'] = true,
['local'] = true,
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua
index 548539a9..10694918 100644
--- a/script/parser/luadoc.lua
+++ b/script/parser/luadoc.lua
@@ -4,7 +4,7 @@ local guide = require 'parser.guide'
local grammar = require 'parser.grammar'
local TokenTypes, TokenStarts, TokenFinishs, TokenContents
-local Ci, Offset, pushError, NextComment
+local Ci, Offset, pushError, NextComment, Lines
local parseType
local Parser = re.compile([[
Main <- (Token / Sp)*
@@ -1171,19 +1171,13 @@ local function buildLuaDoc(comment)
}
end
----当前行在注释doc前是否有代码
-local function haveCodeBeforeDocInCurLine(text, lineData, docStart)
- return text:sub(lineData.start + 1, docStart - 1):find '[%w_]'
-end
-
local function isTailComment(text, binded)
- local lastDoc = binded[#binded]
- local lastDocStartRow = guide.rowColOf(lastDoc.originalComment.start)
- local lastDocStartLineData = guide.lineData(lastDocStartRow)
- if haveCodeBeforeDocInCurLine(text, lastDocStartLineData, lastDoc.originalComment.start) then
- return true
- end
- return false
+ local lastDoc = binded[#binded]
+ local left = lastDoc.originalComment.start
+ local row, col = guide.rowColOf(left)
+ local lineStart = Lines[row] or 0
+ local hasCodeBefore = text:sub(lineStart, lineStart + col):find '[%w_]'
+ return hasCodeBefore
end
local function isNextLine(binded, doc)
@@ -1386,6 +1380,7 @@ return function (state)
}
pushError = state.pushError
+ Lines = state.lines
local ci = 1
NextComment = function (offset, peek)
diff --git a/script/parser/newparser.lua b/script/parser/newparser.lua
index 0137397d..201ca0aa 100644
--- a/script/parser/newparser.lua
+++ b/script/parser/newparser.lua
@@ -488,13 +488,19 @@ local function skipComment(isAction)
local token = Tokens[Index + 1]
if token == '--'
or (token == '//' and isAction) then
- local left = getPosition(Tokens[Index], 'left')
+ local start = Tokens[Index]
+ local left = getPosition(start, 'left')
if token == '//' then
pushCommentHeadError(left)
end
Index = Index + 2
local longComment = parseLongString()
if longComment then
+ longComment.type = 'comment.long'
+ longComment.text = longComment[1]
+ longComment[1] = nil
+ longComment[2] = nil
+ State.comms[#State.comms+1] = longComment
return true
end
while true do
@@ -504,13 +510,26 @@ local function skipComment(isAction)
end
Index = Index + 2
end
+ State.comms[#State.comms+1] = {
+ type = 'comment.shot',
+ start = left,
+ finish = getPosition(Tokens[Index], 'right'),
+ text = ssub(start, Tokens[Index] or #Lua),
+ }
return true
end
if token == '/*' then
- local left = getPosition(Tokens[Index], 'left')
+ local start = Tokens[Index]
+ local left = getPosition(start, 'left')
Index = Index + 2
local result, right = resolveLongString '*/'
pushLongCommentError(left, right)
+ State.comms[#State.comms+1] = {
+ type = 'comment.long',
+ start = left,
+ finish = right,
+ text = result,
+ }
return true
end
return false