summaryrefslogtreecommitdiff
path: root/script-beta
diff options
context:
space:
mode:
Diffstat (limited to 'script-beta')
-rw-r--r--script-beta/core/completion.lua17
-rw-r--r--script-beta/files.lua24
-rw-r--r--script-beta/provider/init.lua1
-rw-r--r--script-beta/workspace/workspace.lua13
4 files changed, 47 insertions, 8 deletions
diff --git a/script-beta/core/completion.lua b/script-beta/core/completion.lua
index e9c3cc00..73111268 100644
--- a/script-beta/core/completion.lua
+++ b/script-beta/core/completion.lua
@@ -627,15 +627,18 @@ end
local function completion(uri, offset)
local ast = files.getAst(uri)
- if not ast then
- return nil
- end
- clearStack()
local text = files.getText(uri)
local results = {}
-
- tryWord(ast, text, offset, results)
- trySymbol(ast, text, offset, results)
+ clearStack()
+ if ast then
+ tryWord(ast, text, offset, results)
+ trySymbol(ast, text, offset, results)
+ else
+ local word = findWord(text, offset)
+ if word then
+ checkCommon(word, text, results)
+ end
+ end
if #results == 0 then
return nil
diff --git a/script-beta/files.lua b/script-beta/files.lua
index 711e275c..9388487f 100644
--- a/script-beta/files.lua
+++ b/script-beta/files.lua
@@ -5,11 +5,14 @@ local furi = require 'file-uri'
local parser = require 'parser'
local vm = require 'vm.vm'
local guide = require 'parser.guide'
+local proto = require 'proto'
+local lang = require 'language'
local m = {}
m.openMap = {}
m.fileMap = {}
+m.notifyCache = {}
m.assocVersion = -1
m.assocMatcher = nil
m.globalVersion = 0
@@ -157,6 +160,7 @@ function m.removeAll()
m.fileMap[uri] = nil
end
m.globalVersion = m.globalVersion + 1
+ m.notifyCache = {}
vm.refreshCache()
end
@@ -173,6 +177,26 @@ function m.getAst(uri)
uri = uri:lower()
end
local file = m.fileMap[uri]
+ if #file.text >= config.config.workspace.maxPreload * 1000 then
+ if not m.notifyCache['maxPreload'] then
+ m.notifyCache['maxPreload'] = {}
+ end
+ if not m.notifyCache['maxPreload'][uri] then
+ m.notifyCache['maxPreload'][uri] = true
+ local ws = require 'workspace'
+ proto.notify('window/showMessage', {
+ type = 3,
+ -- TODO 翻译
+ message = lang.script('已跳过过大的文件:{}。当前设置的大小限制为:{} KB,该文件大小为:{} KB'
+ , ws.getRelativePath(file.uri)
+ , config.config.workspace.maxPreload
+ , #file.text / 1000
+ ),
+ })
+ end
+ file.ast = nil
+ return nil
+ end
if file.ast == nil then
local clock = os.clock()
local state, err = parser:compile(file.text, 'lua', config.config.runtime.version)
diff --git a/script-beta/provider/init.lua b/script-beta/provider/init.lua
index 9c06fd1e..e887e3e0 100644
--- a/script-beta/provider/init.lua
+++ b/script-beta/provider/init.lua
@@ -51,6 +51,7 @@ local function updateConfig()
or not util.equal(oldOther.associations, newOther.associations)
or not util.equal(oldOther.exclude, newOther.exclude)
then
+ workspace.reload()
end
if newConfig.completion.enable then
diff --git a/script-beta/workspace/workspace.lua b/script-beta/workspace/workspace.lua
index deee764a..f24f825a 100644
--- a/script-beta/workspace/workspace.lua
+++ b/script-beta/workspace/workspace.lua
@@ -12,6 +12,7 @@ local m = {}
m.type = 'workspace'
m.ignoreVersion = -1
m.ignoreMatcher = nil
+m.preloadVersion = 0
m.uri = ''
m.path = ''
@@ -133,7 +134,9 @@ function m.awaitPreload()
if read >= max then
break
end
- await.sleep(0.1)
+ await.sleep(0.1, function ()
+ return m.preloadVersion
+ end)
end
log.info('Preload finish.')
@@ -193,4 +196,12 @@ function m.getRelativePath(uri)
return fs.relative(fs.path(path), fs.path(m.path)):string()
end
+function m.reload()
+ m.preloadVersion = m.preloadVersion + 1
+ files.removeAll()
+ await.create(function ()
+ m.awaitPreload()
+ end)
+end
+
return m