summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/src/core/definition.lua20
-rw-r--r--server/src/core/implementation.lua20
-rw-r--r--server/src/core/value.lua1
-rw-r--r--server/src/core/vm.lua30
-rw-r--r--server/src/service.lua4
5 files changed, 48 insertions, 27 deletions
diff --git a/server/src/core/definition.lua b/server/src/core/definition.lua
index 3507d02b..806007b1 100644
--- a/server/src/core/definition.lua
+++ b/server/src/core/definition.lua
@@ -73,7 +73,7 @@ local function findFieldCrossUriByName(positions, vm, result, lsp)
end
end
-local function parseResult(vm, result, lsp)
+local function parseResultAsVar(vm, result, lsp)
local positions = {}
local tp = result.type
if tp == 'local' then
@@ -123,12 +123,19 @@ local function parseResult(vm, result, lsp)
}
end
end
- elseif tp == 'string' then
+ end
+ return positions
+end
+
+local function parseResultAsValue(vm, value, lsp)
+ local tp = value:getType()
+ local positions = {}
+ if tp == 'string' then
-- require 'XXX' 专用
positions[#positions+1] = {
0,
0,
- result.uri,
+ value.uri,
}
end
return positions
@@ -138,6 +145,9 @@ return function (vm, result, lsp)
if not result then
return nil
end
- local positions = parseResult(vm, result, lsp)
- return positions
+ if result.type == 'value' then
+ return parseResultAsValue(vm, result, lsp)
+ else
+ return parseResultAsVar(vm, result, lsp)
+ end
end
diff --git a/server/src/core/implementation.lua b/server/src/core/implementation.lua
index c0cd0f76..6879c9b9 100644
--- a/server/src/core/implementation.lua
+++ b/server/src/core/implementation.lua
@@ -72,7 +72,7 @@ local function findFieldCrossUriByName(positions, vm, result, lsp)
end
end
-local function parseResult(vm, result, lsp)
+local function parseResultAsVar(vm, result, lsp)
local positions = {}
local tp = result.type
if tp == 'local' then
@@ -122,12 +122,19 @@ local function parseResult(vm, result, lsp)
}
end
end
- elseif tp == 'string' then
+ end
+ return positions
+end
+
+local function parseResultAsValue(vm, value, lsp)
+ local tp = value:getType()
+ local positions = {}
+ if tp == 'string' then
-- require 'XXX' 专用
positions[#positions+1] = {
0,
0,
- result.uri,
+ value.uri,
}
end
return positions
@@ -137,6 +144,9 @@ return function (vm, result, lsp)
if not result then
return nil
end
- local positions = parseResult(vm, result, lsp)
- return positions
+ if result.type == 'value' then
+ return parseResultAsValue(vm, result, lsp)
+ else
+ return parseResultAsVar(vm, result, lsp)
+ end
end
diff --git a/server/src/core/value.lua b/server/src/core/value.lua
index 35e59816..0cab8516 100644
--- a/server/src/core/value.lua
+++ b/server/src/core/value.lua
@@ -215,6 +215,7 @@ return function (tp, source, value)
-- TODO lib里的多类型
local self = setmetatable({
source = source or DefaultSource,
+ uri = source and source.uri,
}, mt)
if value ~= nil then
self:setValue(value)
diff --git a/server/src/core/vm.lua b/server/src/core/vm.lua
index 1291383b..b7eb2535 100644
--- a/server/src/core/vm.lua
+++ b/server/src/core/vm.lua
@@ -1038,15 +1038,15 @@ function mt:getBinary(exp)
v2:inference('string', 0.1)
if math.type(v1:getValue()) == 'integer' and math.type(v2:getValue()) == 'integer' then
if op == '|' then
- return self:createValue('integer', v1:getValue() | v2:getValue())
+ return self:createValue('integer', exp, v1:getValue() | v2:getValue())
elseif op == '~' then
- return self:createValue('integer', v1:getValue() ~ v2:getValue())
+ return self:createValue('integer', exp, v1:getValue() ~ v2:getValue())
elseif op == '&' then
- return self:createValue('integer', v1:getValue() &v2:getValue())
+ return self:createValue('integer', exp, v1:getValue() &v2:getValue())
elseif op == '<<' then
- return self:createValue('integer', v1:getValue() << v2:getValue())
+ return self:createValue('integer', exp, v1:getValue() << v2:getValue())
elseif op == '>>' then
- return self:createValue('integer', v1:getValue() >> v2:getValue())
+ return self:createValue('integer', exp, v1:getValue() >> v2:getValue())
end
end
return self:createValue('integer')
@@ -1071,24 +1071,24 @@ function mt:getBinary(exp)
v2:inference('number', 0.9)
if type(v1:getValue()) == 'number' and type(v2:getValue()) == 'number' then
if op == '+' then
- return self:createValue('number', nil, v1:getValue() + v2:getValue())
+ return self:createValue('number', exp, v1:getValue() + v2:getValue())
elseif op == '-' then
- return self:createValue('number', nil, v1:getValue() - v2:getValue())
+ return self:createValue('number', exp, v1:getValue() - v2:getValue())
elseif op == '*' then
- return self:createValue('number', nil, v1:getValue() * v2:getValue())
+ return self:createValue('number', exp, v1:getValue() * v2:getValue())
elseif op == '/' then
if v2:getValue() ~= 0 then
- return self:createValue('number', nil, v1:getValue() / v2:getValue())
+ return self:createValue('number', exp, v1:getValue() / v2:getValue())
end
elseif op == '^' then
- return self:createValue('number', nil, v1:getValue() ^ v2:getValue())
+ return self:createValue('number', exp, v1:getValue() ^ v2:getValue())
elseif op == '%' then
if v2:getValue() ~= 0 then
- return self:createValue('number', nil, v1:getValue() % v2:getValue())
+ return self:createValue('number', exp, v1:getValue() % v2:getValue())
end
elseif op == '//' then
if v2:getValue() ~= 0 then
- return self:createValue('number', nil, v1:getValue() // v2:getValue())
+ return self:createValue('number', exp, v1:getValue() // v2:getValue())
end
end
end
@@ -1108,19 +1108,19 @@ function mt:getUnary(exp)
v1:inference('table', 0.9)
v1:inference('string', 0.9)
if type(v1:getValue()) == 'string' then
- return self:createValue('integer', nil, #v1:getValue())
+ return self:createValue('integer', exp, #v1:getValue())
end
return self:createValue('integer')
elseif op == '-' then
v1:inference('number', 0.9)
if type(v1:getValue()) == 'number' then
- return self:createValue('number', nil, -v1:getValue())
+ return self:createValue('number', exp, -v1:getValue())
end
return self:createValue('number')
elseif op == '~' then
v1:inference('integer', 0.9)
if math.type(v1:getValue()) == 'integer' then
- return self:createValue('integer', nil, ~v1:getValue())
+ return self:createValue('integer', exp, ~v1:getValue())
end
return self:createValue('integer')
end
diff --git a/server/src/service.lua b/server/src/service.lua
index 886eef10..f1110a23 100644
--- a/server/src/service.lua
+++ b/server/src/service.lua
@@ -309,7 +309,7 @@ function mt:compileVM(uri)
local version = obj.version
obj.astCost = os.clock() - clock
self:_clearChainNode(obj, uri)
- self._global:clearGlobal(uri)
+ --self._global:clearGlobal(uri)
local clock = os.clock()
local vm = core.vm(ast, self, uri)
@@ -337,7 +337,7 @@ function mt:compileVM(uri)
end
self:_compileChain(obj, compiled)
- self:_compileGlobal(obj, compiled)
+ --self:_compileGlobal(obj, compiled)
return obj
end