Skip to content

Commit

Permalink
wait for workspace ready
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Jan 27, 2021
1 parent 954826c commit 43a29d8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
11 changes: 10 additions & 1 deletion script/provider/provider.lua
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ proto.on('initialized', function (params)
}
}
})
await.call(workspace.awaitPreload)
workspace.awaitReload()
return true
end)

Expand Down Expand Up @@ -216,6 +216,7 @@ end)
proto.on('textDocument/hover', function (params)
await.close 'hover'
await.setID 'hover'
workspace.awaitReady()
local core = require 'core.hover'
local doc = params.textDocument
local uri = doc.uri
Expand Down Expand Up @@ -244,6 +245,7 @@ proto.on('textDocument/hover', function (params)
end)

proto.on('textDocument/definition', function (params)
workspace.awaitReady()
local core = require 'core.definition'
local uri = params.textDocument.uri
if not files.exists(uri) then
Expand Down Expand Up @@ -271,6 +273,7 @@ proto.on('textDocument/definition', function (params)
end)

proto.on('textDocument/references', function (params)
workspace.awaitReady()
local core = require 'core.reference'
local uri = params.textDocument.uri
if not files.exists(uri) then
Expand Down Expand Up @@ -313,6 +316,7 @@ proto.on('textDocument/documentHighlight', function (params)
end)

proto.on('textDocument/rename', function (params)
workspace.awaitReady()
local core = require 'core.rename'
local uri = params.textDocument.uri
if not files.exists(uri) then
Expand Down Expand Up @@ -355,6 +359,7 @@ proto.on('textDocument/prepareRename', function (params)
end)

proto.on('textDocument/completion', function (params)
workspace.awaitReady()
--log.info(util.dump(params))
local core = require 'core.completion'
--log.debug('textDocument/completion')
Expand Down Expand Up @@ -478,6 +483,7 @@ proto.on('textDocument/signatureHelp', function (params)
if not config.config.signatureHelp.enable then
return nil
end
workspace.awaitReady()
local uri = params.textDocument.uri
if not files.exists(uri) then
return nil
Expand Down Expand Up @@ -601,6 +607,7 @@ proto.on('workspace/executeCommand', function (params)
end)

proto.on('workspace/symbol', function (params)
workspace.awaitReady()
local core = require 'core.workspace-symbol'

await.close('workspace/symbol')
Expand Down Expand Up @@ -632,6 +639,7 @@ end)


proto.on('textDocument/semanticTokens/full', function (params)
workspace.awaitReady()
local core = require 'core.semantic-tokens'
local uri = params.textDocument.uri
log.debug('semanticTokens/full', uri)
Expand All @@ -647,6 +655,7 @@ proto.on('textDocument/semanticTokens/full', function (params)
end)

proto.on('textDocument/semanticTokens/range', function (params)
workspace.awaitReady()
local core = require 'core.semantic-tokens'
local uri = params.textDocument.uri
log.debug('semanticTokens/range', uri)
Expand Down
15 changes: 14 additions & 1 deletion script/workspace/workspace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -402,14 +402,27 @@ function m.getCache(name)
end

function m.reload()
await.call(m.awaitReload)
end

function m.awaitReload()
local rpath = require 'workspace.require-path'
local plugin = require 'plugin'
m.ready = false
files.flushAllLibrary()
files.removeAllClosed()
files.flushCache()
rpath.flush()
plugin.init()
await.call(m.awaitPreload)
m.awaitPreload()
m.ready = true
end

---等待工作目录加载完成
function m.awaitReady()
while not m.ready do
await.sleep(0.1)
end
end

files.watch(function (ev, uri)
Expand Down

0 comments on commit 43a29d8

Please sign in to comment.