summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-07-29 19:49:26 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-07-29 19:49:26 +0800
commit8c44ca7459ed6df935cb2859fb45ef32207eef55 (patch)
tree021f05b801936f360e07ed63cc7fa5413ab3ce31 /script
parent4f391eea466b3d04b058e83d1c166780ad885f2f (diff)
downloadlua-language-server-8c44ca7459ed6df935cb2859fb45ef32207eef55.zip
update
Diffstat (limited to 'script')
-rw-r--r--script/core/generic.lua16
-rw-r--r--script/core/noder.lua85
-rw-r--r--script/core/searcher.lua21
3 files changed, 85 insertions, 37 deletions
diff --git a/script/core/generic.lua b/script/core/generic.lua
index f5ede5d7..ce957a71 100644
--- a/script/core/generic.lua
+++ b/script/core/generic.lua
@@ -141,10 +141,18 @@ local function createValue(closure, proto, callback, road)
return value
end
if proto.type == 'doc.type.field' then
- road[#road+1] = ('%s%q'):format(
- noder.SPLIT_CHAR,
- proto.name[1]
- )
+ local name = proto.name[1]
+ if type(name) == 'string' then
+ road[#road+1] = ('%s%s'):format(
+ noder.STRING_FIELD,
+ name
+ )
+ else
+ road[#road+1] = ('%s%s'):format(
+ noder.SPLIT_CHAR,
+ name
+ )
+ end
local typeUnit = createValue(closure, proto.extends, callback, road)
road[#road] = nil
if not typeUnit then
diff --git a/script/core/noder.lua b/script/core/noder.lua
index 9a641e3b..4c93aed5 100644
--- a/script/core/noder.lua
+++ b/script/core/noder.lua
@@ -6,13 +6,15 @@ local files = require 'files'
local SPLIT_CHAR = '\x1F'
local LAST_REGEX = SPLIT_CHAR .. '[^' .. SPLIT_CHAR .. ']*$'
local FIRST_REGEX = '^[^' .. SPLIT_CHAR .. ']*'
-local HEAD_REGEX = '^' .. SPLIT_CHAR .. '?[^' .. SPLIT_CHAR .. ']*'
+local HEAD_REGEX = '^' .. SPLIT_CHAR .. '?[^' .. SPLIT_CHAR .. ']*'
+local STRING_CHAR = '.'
local ANY_FIELD_CHAR = '*'
local INDEX_CHAR = '['
local RETURN_INDEX = SPLIT_CHAR .. '#'
local PARAM_INDEX = SPLIT_CHAR .. '&'
local TABLE_KEY = SPLIT_CHAR .. '<'
local WEAK_TABLE_KEY = SPLIT_CHAR .. '<<'
+local STRING_FIELD = SPLIT_CHAR .. STRING_CHAR
local INDEX_FIELD = SPLIT_CHAR .. INDEX_CHAR
local ANY_FIELD = SPLIT_CHAR .. ANY_FIELD_CHAR
local WEAK_ANY_FIELD = SPLIT_CHAR .. ANY_FIELD_CHAR .. ANY_FIELD_CHAR
@@ -111,24 +113,24 @@ local getKeyMap = util.switch()
: call(function (source)
local node = source.node
if node.tag == '_ENV' then
- return ('%q'):format(source[1] or ''), nil
+ return STRING_CHAR .. (source[1] or ''), nil
else
- return ('%q'):format(source[1] or ''), node
+ return STRING_CHAR .. (source[1] or ''), node
end
end)
: case 'getfield'
: case 'setfield'
: call(function (source)
- return ('%q'):format(source.field and source.field[1] or ''), source.node
+ return STRING_CHAR .. (source.field and source.field[1] or ''), source.node
end)
: case 'tablefield'
: call(function (source)
- return ('%q'):format(source.field and source.field[1] or ''), source.parent
+ return STRING_CHAR .. (source.field and source.field[1] or ''), source.parent
end)
: case 'getmethod'
: case 'setmethod'
: call(function (source)
- return ('%q'):format(source.method and source.method[1] or ''), source.node
+ return STRING_CHAR .. (source.method and source.method[1] or ''), source.node
end)
: case 'setindex'
: case 'getindex'
@@ -137,11 +139,12 @@ local getKeyMap = util.switch()
if not index then
return INDEX_CHAR, source.node
end
- if index.type == 'string'
- or index.type == 'boolean'
- or index.type == 'integer'
- or index.type == 'number' then
- return ('%q'):format(index[1] or ''), source.node
+ if index.type == 'string' then
+ return STRING_CHAR .. (index[1] or ''), source.node
+ elseif index.type == 'boolean'
+ or index.type == 'integer'
+ or index.type == 'number' then
+ return tostring(index[1] or ''), source.node
else
return INDEX_CHAR, source.node
end
@@ -152,11 +155,12 @@ local getKeyMap = util.switch()
if not index then
return ANY_FIELD_CHAR, source.parent
end
- if index.type == 'string'
- or index.type == 'boolean'
- or index.type == 'integer'
- or index.type == 'number' then
- return ('%q'):format(index[1] or ''), source.parent
+ if index.type == 'string' then
+ return STRING_CHAR .. (index[1] or ''), source.parent
+ elseif index.type == 'boolean'
+ or index.type == 'integer'
+ or index.type == 'number' then
+ return tostring(index[1] or ''), source.parent
elseif index.type ~= 'function'
and index.type ~= 'table' then
return ANY_FIELD_CHAR, source.parent
@@ -232,7 +236,7 @@ local getKeyMap = util.switch()
return nil, nil
end
if key.type == 'string' then
- return ('%q'):format(key[1] or ''), tbl
+ return STRING_CHAR .. (key[1] or ''), tbl
else
return '', tbl
end
@@ -307,7 +311,7 @@ local getKeyMap = util.switch()
end)
: case 'doc.see.field'
: call(function (source)
- return ('%q'):format(source[1]), source.parent.name
+ return STRING_CHAR .. (source[1]), source.parent.name
end)
: case 'generic.closure'
: call(function (source)
@@ -474,6 +478,8 @@ end
local m = {}
m.SPLIT_CHAR = SPLIT_CHAR
+m.STRING_CHAR = STRING_CHAR
+m.STRING_FIELD = STRING_FIELD
m.RETURN_INDEX = RETURN_INDEX
m.PARAM_INDEX = PARAM_INDEX
m.TABLE_KEY = TABLE_KEY
@@ -705,9 +711,9 @@ local function compileCallReturn(noders, call, sourceID, returnIndex)
local metaID = getID(call.args and call.args[2])
local indexID
if metaID then
- indexID = ('%s%s%q'):format(
+ indexID = ('%s%s%s'):format(
metaID,
- SPLIT_CHAR,
+ STRING_FIELD,
'__index'
)
end
@@ -826,11 +832,21 @@ function m.compileDocValue(noders, tp, id, source)
pushForward(noders, keyID, 'dn:string')
pushForward(noders, valueID, getID(firstField.extends))
for _, field in ipairs(source.fields) do
- local extendsID = ('%s%s%q'):format(
- id,
- SPLIT_CHAR,
- field.name[1]
- )
+ local fname = field.name[1]
+ local extendsID
+ if type(fname) == 'string' then
+ extendsID = ('%s%s%s'):format(
+ id,
+ STRING_FIELD,
+ fname
+ )
+ else
+ extendsID = ('%s%s%s'):format(
+ id,
+ SPLIT_CHAR,
+ fname
+ )
+ end
pushForward(noders, extendsID, getID(field))
pushForward(noders, extendsID, getID(field.extends))
end
@@ -947,11 +963,20 @@ function m.compileNode(noders, source)
for _, field in ipairs(source.fields) do
local key = field.field[1]
if key then
- local keyID = ('%s%s%q'):format(
- id,
- SPLIT_CHAR,
- key
- )
+ local keyID
+ if type(key) == 'string' then
+ keyID = ('%s%s%s'):format(
+ id,
+ STRING_FIELD,
+ key
+ )
+ else
+ keyID = ('%s%s%s'):format(
+ id,
+ SPLIT_CHAR,
+ key
+ )
+ end
pushForward(noders, keyID, getID(field.field))
pushForward(noders, getID(field.field), keyID)
pushForward(noders, keyID, getID(field.extends))
diff --git a/script/core/searcher.lua b/script/core/searcher.lua
index 16af5798..50b26d23 100644
--- a/script/core/searcher.lua
+++ b/script/core/searcher.lua
@@ -959,7 +959,12 @@ function m.findGlobals(uri, mode, name)
local status = m.status(mode)
if name then
- local fullID = ('g:%q'):format(name)
+ local fullID
+ if type(name) == 'string' then
+ fullID = ('%s%s%s'):format('g:', noder.STRING_CHAR, name)
+ else
+ fullID = ('%s%s%s'):format('g:', '', name)
+ end
searchAllGlobalByUri(status, mode, uri, fullID)
else
searchAllGlobalByUri(status, mode, uri)
@@ -1019,13 +1024,23 @@ function m.searchFields(status, source, mode, field)
end
else
if source.special == '_G' then
- local fullID = ('g:%q'):format(field)
+ local fullID
+ if type(field) == 'string' then
+ fullID = ('%s%s%s'):format('g:', noder.STRING_CHAR, field)
+ else
+ fullID = ('%s%s%s'):format('g:', '', field)
+ end
if checkCache(status, uri, fullID, mode) then
return
end
m.searchRefsByID(status, uri, fullID, mode)
else
- local fullID = ('%s%s%q'):format(id, noder.SPLIT_CHAR, field)
+ local fullID
+ if type(field) == 'string' then
+ fullID = ('%s%s%s'):format(id, noder.STRING_FIELD, field)
+ else
+ fullID = ('%s%s%s'):format(id, noder.SPLIT_CHAR, field)
+ end
if checkCache(status, uri, fullID, mode) then
return
end