summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-09-17 10:14:23 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-09-17 10:14:23 +0800
commitaec86b21100c6522df5498111b0408b4d1601c27 (patch)
treebca23aa6084e8960129c8c87b1412c355615ab28
parentac4ff86df32af5b0c0c2c730e5374130326f6129 (diff)
downloadlua-language-server-aec86b21100c6522df5498111b0408b4d1601c27.zip
暂存
-rw-r--r--server/main.lua2
-rw-r--r--server/src/method/initialized.lua2
-rw-r--r--server/src/rpc.lua2
-rw-r--r--server/src/service.lua2
-rw-r--r--server/src/vm/special.lua23
-rw-r--r--server/src/vm/vm.lua35
6 files changed, 33 insertions, 33 deletions
diff --git a/server/main.lua b/server/main.lua
index 99143461..afb32f03 100644
--- a/server/main.lua
+++ b/server/main.lua
@@ -15,7 +15,7 @@ log.info('Lua Lsp startup, root: ', ROOT)
log.debug('ROOT:', ROOT:string())
ac = {}
-xpcall(dofile, log.debug, rootPath .. '/debugger.lua')
+--xpcall(dofile, log.debug, rootPath .. '/debugger.lua')
require 'utility'
local service = require 'service'
local session = service()
diff --git a/server/src/method/initialized.lua b/server/src/method/initialized.lua
index 1348e03b..d84a2159 100644
--- a/server/src/method/initialized.lua
+++ b/server/src/method/initialized.lua
@@ -1,4 +1,4 @@
-local rpc = require 'rpc'
+local rpc = require 'rpc'
local workspace = require 'workspace'
local function initAfterConfig(lsp, firstScope)
diff --git a/server/src/rpc.lua b/server/src/rpc.lua
index 2456cbd3..4a495695 100644
--- a/server/src/rpc.lua
+++ b/server/src/rpc.lua
@@ -1,6 +1,6 @@
local json = require 'json'
-local TIMEOUT = 1.0
+local TIMEOUT = 600.0
local ID = 0
local BUF = {}
diff --git a/server/src/service.lua b/server/src/service.lua
index a22dadc4..0e0f459a 100644
--- a/server/src/service.lua
+++ b/server/src/service.lua
@@ -498,7 +498,7 @@ function mt:compileVM(uri)
self:_clearGlobal(uri)
local clock = os.clock()
- local vm, err = buildVM(ast, self, uri, file)
+ local vm, err = buildVM(ast, self, uri, file:getText())
if vm then
CachedVM[vm] = true
end
diff --git a/server/src/vm/special.lua b/server/src/vm/special.lua
index c2bf0e99..e93c4445 100644
--- a/server/src/vm/special.lua
+++ b/server/src/vm/special.lua
@@ -1,7 +1,8 @@
-local mt = require 'vm.manager'
-local multi = require 'vm.multi'
-local library = require 'core.library'
+local mt = require 'vm.manager'
+local multi = require 'vm.multi'
+local library = require 'core.library'
local libraryBuilder = require 'vm.library'
+local plugin = require 'plugin'
---@param func emmyFunction
---@param values table
@@ -42,7 +43,7 @@ function mt:callEmmyDoFile(func, values, index)
if type(str) ~= 'string' then
return
end
- local requireValue = self:tryRequireOne(values[index], 'dofile')
+ local requireValue = self:tryRequireOne(str, values[index], 'dofile')
if not requireValue then
requireValue = self:createValue('any', self:getDefaultSource())
requireValue.isRequire = true
@@ -61,7 +62,7 @@ function mt:callEmmyLoadFile(func, values, index)
if type(str) ~= 'string' then
return
end
- local requireValue = self:tryRequireOne(values[index], 'loadfile')
+ local requireValue = self:tryRequireOne(str, values[index], 'loadfile')
if not requireValue then
requireValue = self:createValue('any', self:getDefaultSource())
requireValue:set('cross file', true)
@@ -104,10 +105,14 @@ function mt:callEmmyRequire(func, values, index)
if not values[index] then
values[index] = self:createValue('any', self:getDefaultSource())
end
- local str = values[index]:getLiteral()
- if type(str) ~= 'string' then
- return
+ local strValue = values[index]
+ local strSource = strValue:getSource()
+ if not strSource then
+ return nil
end
+ local str = strValue:getLiteral()
+ local raw = self.text:sub(strSource.start, strSource.finish)
+ str = plugin.call('OnRequirePath', str, raw) or str
local lib = library.library[str]
if lib then
local value = libraryBuilder.value(lib)
@@ -115,7 +120,7 @@ function mt:callEmmyRequire(func, values, index)
func:setReturn(1, value)
return
else
- local requireValue = self:tryRequireOne(values[1], 'require')
+ local requireValue = self:tryRequireOne(str, strValue, 'require')
if not requireValue then
requireValue = self:createValue('any', self:getDefaultSource())
requireValue:set('cross file', true)
diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua
index 6717a403..93b9eb8e 100644
--- a/server/src/vm/vm.lua
+++ b/server/src/vm/vm.lua
@@ -167,17 +167,14 @@ function mt:callSetMetaTable(func, values, source)
values[1]:setMetaTable(values[2])
end
-function mt:tryRequireOne(strValue, mode)
+function mt:tryRequireOne(str, strValue, mode)
if not self.lsp or not self.lsp.workspace then
return nil
end
- local str = strValue:getLiteral()
local strSource = strValue:getSource()
if not strSource then
return nil
end
- local raw = self.file:getText():sub(strSource.start, strSource.finish)
- str = plugin.call('OnRequirePath', str, raw) or str
if type(str) == 'string' then
-- 支持 require 'xxx' 的转到定义
self:instantSource(strSource)
@@ -204,10 +201,14 @@ function mt:callRequire(func, values)
if not values[1] then
values[1] = self:createValue('any', self:getDefaultSource())
end
- local str = values[1]:getLiteral()
- if type(str) ~= 'string' then
- return
+ local strValue = values[1]
+ local strSource = strValue:getSource()
+ if not strSource then
+ return nil
end
+ local str = strValue:getLiteral()
+ local raw = self.text:sub(strSource.start, strSource.finish)
+ str = plugin.call('OnRequirePath', str, raw) or str
local lib = library.library[str]
if lib then
local value = libraryBuilder.value(lib)
@@ -215,7 +216,7 @@ function mt:callRequire(func, values)
func:setReturn(1, value)
return
else
- local requireValue = self:tryRequireOne(values[1], 'require')
+ local requireValue = self:tryRequireOne(str, values[1], 'require')
if not requireValue then
requireValue = self:createValue('any', self:getDefaultSource())
requireValue:set('cross file', true)
@@ -228,11 +229,8 @@ function mt:callLoadFile(func, values)
if not values[1] then
values[1] = self:createValue('any', self:getDefaultSource())
end
- local str = values[1]:getLiteral()
- if type(str) ~= 'string' then
- return
- end
- local requireValue = self:tryRequireOne(values[1], 'loadfile')
+ local strValue = values[1]
+ local requireValue = self:tryRequireOne(strValue:getLiteral(), values[1], 'loadfile')
if not requireValue then
requireValue = self:createValue('any', self:getDefaultSource())
requireValue:set('cross file', true)
@@ -244,11 +242,8 @@ function mt:callDoFile(func, values)
if not values[1] then
values[1] = self:createValue('any', self:getDefaultSource())
end
- local str = values[1]:getLiteral()
- if type(str) ~= 'string' then
- return
- end
- local requireValue = self:tryRequireOne(values[1], 'dofile')
+ local strValue = values[1]
+ local requireValue = self:tryRequireOne(strValue:getLiteral(), values[1], 'dofile')
if not requireValue then
requireValue = self:createValue('any', self:getDefaultSource())
requireValue.isRequire = true
@@ -1310,7 +1305,7 @@ local function compile(vm, ast, lsp, uri)
return vm
end
-return function (ast, lsp, uri, file)
+return function (ast, lsp, uri, text)
if not ast then
return nil, 'Ast failed'
end
@@ -1324,7 +1319,7 @@ return function (ast, lsp, uri, file)
emmyMgr = lsp and lsp.emmy or emmyMgr(),
lsp = lsp,
uri = uri or '',
- file = file,
+ text = text or '',
}, mt)
local suc, res = xpcall(compile, log.error, vm, ast, lsp, uri)
if not suc then