summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/files.lua7
-rw-r--r--script/plugin.lua4
-rw-r--r--script/provider/provider.lua7
-rw-r--r--script/workspace/workspace.lua2
4 files changed, 18 insertions, 2 deletions
diff --git a/script/files.lua b/script/files.lua
index 7cdbf343..05a7e099 100644
--- a/script/files.lua
+++ b/script/files.lua
@@ -11,6 +11,7 @@ local plugin = require 'plugin'
local util = require 'utility'
local guide = require 'parser.guide'
local smerger = require 'string-merger'
+local plugin = require 'plugin'
local m = {}
@@ -145,6 +146,7 @@ function m.setText(uri, text)
file.text = newText
file.originText = text
m.linesMap[uri] = nil
+ m.originLinesMap[uri] = nil
m.astMap[uri] = nil
file.cache = {}
file.cacheActiveTime = math.huge
@@ -155,6 +157,11 @@ function m.setText(uri, text)
m.onWatch('create', originUri)
end
m.onWatch('update', originUri)
+ if DEVELOP then
+ if text ~= newText then
+ util.saveFile(LOGPATH .. '/diffed.lua', newText)
+ end
+ end
end
--- 获取文件版本
diff --git a/script/plugin.lua b/script/plugin.lua
index dfe18b98..82964656 100644
--- a/script/plugin.lua
+++ b/script/plugin.lua
@@ -22,6 +22,10 @@ function m.dispatch(event, ...)
return false
end
+function m.isReady()
+ return m.interface ~= nil
+end
+
function m.init()
local ws = require 'workspace'
m.interface = {}
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index 74ee11db..f5a0f6a6 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -52,11 +52,11 @@ local function updateConfig()
config.setConfig(updated, other)
local newConfig = config.config
local newOther = config.other
+
if not util.equal(oldConfig.runtime, newConfig.runtime) then
library.init()
workspace.reload()
semantic.refresh()
- plugin.init()
end
if not util.equal(oldConfig.diagnostics, newConfig.diagnostics) then
diagnostics.diagnosticsAll()
@@ -169,6 +169,9 @@ proto.on('textDocument/didOpen', function (params)
local uri = doc.uri
local text = doc.text
files.open(uri)
+ while not plugin.isReady() do
+ await.sleep(0.1)
+ end
files.setText(uri, text)
end)
@@ -191,7 +194,7 @@ proto.on('textDocument/didChange', function (params)
local text = files.getOriginText(uri) or ''
for _, change in ipairs(changes) do
if change.range then
- local start, finish = files.unrange(uri, change.range, true)
+ local start, finish = files.unrange(uri, change.range)
start = files.diffedOffsetBack(uri, start)
finish = files.diffedOffsetBack(uri, finish)
text = text:sub(1, start) .. change.text .. text:sub(finish + 1)
diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua
index 6f99891e..ec30c9ea 100644
--- a/script/workspace/workspace.lua
+++ b/script/workspace/workspace.lua
@@ -403,10 +403,12 @@ end
function m.reload()
local rpath = require 'workspace.require-path'
+ local plugin = require 'plugin'
files.flushAllLibrary()
files.removeAllClosed()
files.flushCache()
rpath.flush()
+ plugin.init()
await.call(m.awaitPreload)
end