summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
Diffstat (limited to 'script')
-rw-r--r--script/core/completion/completion.lua16
-rw-r--r--script/parser/guide.lua2
-rw-r--r--script/parser/newparser.lua2
-rw-r--r--script/proto/proto.lua7
-rw-r--r--script/provider/provider.lua7
-rw-r--r--script/service/service.lua2
6 files changed, 26 insertions, 10 deletions
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua
index 21f6ea0c..9a7847f8 100644
--- a/script/core/completion/completion.lua
+++ b/script/core/completion/completion.lua
@@ -1525,8 +1525,14 @@ local function tryTable(state, position, results)
end
local function getComment(state, position)
+ local offset = guide.positionToOffset(state, position)
+ local symbolOffset = lookBackward.findAnyOffset(state.lua, offset)
+ if not symbolOffset then
+ return
+ end
+ local symbolPosition = guide.offsetToPosition(state, symbolOffset)
for _, comm in ipairs(state.comms) do
- if position > comm.start and position <= comm.finish then
+ if symbolPosition > comm.start and symbolPosition <= comm.finish then
return comm
end
end
@@ -1534,8 +1540,14 @@ local function getComment(state, position)
end
local function getluaDoc(state, position)
+ local offset = guide.positionToOffset(state, position)
+ local symbolOffset = lookBackward.findAnyOffset(state.lua, offset)
+ if not symbolOffset then
+ return
+ end
+ local symbolPosition = guide.offsetToPosition(state, symbolOffset)
for _, doc in ipairs(state.ast.docs) do
- if position >= doc.start and position <= doc.range then
+ if symbolPosition >= doc.start and symbolPosition <= doc.range then
return doc
end
end
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index d55ba099..544f3eaa 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -781,7 +781,7 @@ function m.offsetToPositionByLines(lines, offset)
row = (left + right) // 2
if row == left then
if right ~= left then
- if lines[right] <= offset then
+ if lines[right] - 1 <= offset then
row = right
end
end
diff --git a/script/parser/newparser.lua b/script/parser/newparser.lua
index 15d2d600..c2ea8d13 100644
--- a/script/parser/newparser.lua
+++ b/script/parser/newparser.lua
@@ -537,7 +537,7 @@ local function skipComment(isAction)
State.comms[#State.comms+1] = {
type = chead and 'comment.cshort' or 'comment.short',
start = left,
- finish = getPosition(Tokens[Index], 'right'),
+ finish = lastRightPosition(),
text = ssub(Lua, start + 2, Tokens[Index] and (Tokens[Index] - 1) or #Lua),
}
return true
diff --git a/script/proto/proto.lua b/script/proto/proto.lua
index 7cdc461c..a73e462e 100644
--- a/script/proto/proto.lua
+++ b/script/proto/proto.lua
@@ -154,7 +154,7 @@ function m.doMethod(proto)
local response <close> = function ()
local passed = os.clock() - clock
if passed > 0.2 then
- log.debug(('Method [%s] takes [%.3f]sec.'):format(method, passed))
+ log.debug(('Method [%s] takes [%.3f]sec. %s'):format(method, passed, util.dump(proto)))
end
--log.debug('Finish method:', method)
if not proto.id then
@@ -164,7 +164,7 @@ function m.doMethod(proto)
if ok then
m.response(proto.id, res)
else
- m.responseErr(proto.id, proto._closeReason or define.ErrorCodes.InternalError, res)
+ m.responseErr(proto.id, proto._closeReason or define.ErrorCodes.InternalError, proto._closeMessage or res)
end
end
ok, res = xpcall(abil, log.error, proto.params)
@@ -172,12 +172,13 @@ function m.doMethod(proto)
end)
end
-function m.close(id, reason)
+function m.close(id, reason, message)
local proto = m.holdon[id]
if not proto then
return
end
proto._closeReason = reason
+ proto._closeMessage = message
await.close('proto:' .. id)
end
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index 11501b9c..51a10b19 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -252,6 +252,9 @@ m.register 'textDocument/hover' {
abortByFileUpdate = true,
---@async
function (params)
+ if not config.get('Lua.hover.enable') then
+ return
+ end
local doc = params.textDocument
local uri = files.getRealUri(doc.uri)
if not workspace.isReady() then
@@ -939,7 +942,7 @@ m.register 'textDocument/onTypeFormatting' {
m.register '$/cancelRequest' {
function (params)
- proto.close(params.id, define.ErrorCodes.RequestCancelled)
+ proto.close(params.id, define.ErrorCodes.RequestCancelled, 'Request cancelled.')
end
}
@@ -1042,7 +1045,7 @@ files.watch(function (ev, uri)
for id, p in pairs(proto.holdon) do
if m.attributes[p.method].abortByFileUpdate then
log.debug('close proto(ContentModified):', id, p.method)
- proto.close(id, define.ErrorCodes.ContentModified)
+ proto.close(id, define.ErrorCodes.ContentModified, 'Content modified.')
end
end
end
diff --git a/script/service/service.lua b/script/service/service.lua
index a961d03c..76478394 100644
--- a/script/service/service.lua
+++ b/script/service/service.lua
@@ -118,7 +118,7 @@ function m.reportProto()
end
local lines = {}
- lines[#lines+1] = ' --------------- Proto ---------------'
+ lines[#lines+1] = ' --------------- RPC ---------------'
lines[#lines+1] = (' Holdon: %d'):format(holdon)
lines[#lines+1] = (' Waiting: %d'):format(waiting)
return table.concat(lines, '\n')