Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions script/core/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -663,14 +663,21 @@ local function buildTextEdit(start, finish, str, quo)
}
end

--- @param vm VM
--- @param source table
--- @param callback function
local function searchInRequire(vm, source, callback)
if not vm.lsp or not vm.lsp.workspace then
if not vm.lsp then
return
end
local ws = vm.lsp:findWorkspaceFor(vm.uri)
if not ws then
return
end
if source.type ~= 'string' then
return
end
local list, map = vm.lsp.workspace:matchPath(vm.uri, source[1])
local list, map = ws:matchPath(vm.uri, source[1])
if not list then
return
end
Expand Down Expand Up @@ -1039,6 +1046,11 @@ local function getSource(vm, pos, text, filter)
return source, pos, word
end

--- @param vm VM
--- @param text string
--- @param pos table
--- @param oldText string
--- @return table
return function (vm, text, pos, oldText)
local filter = {
['name'] = true,
Expand Down
8 changes: 6 additions & 2 deletions script/core/hover/hover.lua
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,14 @@ end

local function hoverAsTargetUri(source, lsp)
local uri = source:get 'target uri'
if not lsp or not lsp.workspace then
if not lsp then
return nil
end
local path = lsp.workspace:relativePathByUri(uri)
local ws = lsp:findWorkspaceFor(uri)
if not ws then
return nil
end
local path = ws:relativePathByUri(uri)
if not path then
return nil
end
Expand Down
1 change: 1 addition & 0 deletions script/method/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ init 'textDocument/semanticTokens'
init 'textDocument/signatureHelp'
init 'workspace/didChangeConfiguration'
init 'workspace/didChangeWatchedFiles'
init 'workspace/didChangeWorkspaceFolders'
init 'workspace/executeCommand'

return method
13 changes: 10 additions & 3 deletions script/method/initialize.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@ local function allWords()
return list
end

--- @param lsp LSP
--- @param params table
--- @return table
return function (lsp, params)
lsp._inited = true
lsp.client = params
client.init(params)
log.info(table.dump(params))

if params.rootUri then
lsp.workspace = workspace(lsp, 'root')
lsp.workspace:init(params.rootUri)
if params.workspaceFolders then
for _, folder in ipairs(params.workspaceFolders) do
lsp:addWorkspace(folder.name, folder.uri)
end
elseif params.rootUri then
lsp:addWorkspace('root', params.rootUri)
end

local server = {
Expand All @@ -45,6 +51,7 @@ return function (lsp, params)
workspace = {
workspaceFolders = {
supported = true,
changeNotifications = true,
}
},
documentOnTypeFormattingProvider = {
Expand Down
63 changes: 33 additions & 30 deletions script/method/initialized.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,37 @@
local rpc = require 'rpc'
local workspace = require 'workspace'
local rpc = require 'rpc'

--- @param lsp LSP
--- @return boolean
return function (lsp)
local ws = lsp.workspaces[1]

if ws then
-- 请求工作目录
local uri = ws.uri
-- 请求配置
rpc:request('workspace/configuration', {
items = {
{
scopeUri = uri,
section = 'Lua',
},
{
scopeUri = uri,
section = 'files.associations',
},
{
scopeUri = uri,
section = 'files.exclude',
}
},
}, function (configs)
lsp:onUpdateConfig(configs[1], {
associations = configs[2],
exclude = configs[3],
})
end)
end

local function initAfterConfig(lsp)
-- 必须动态注册的事件:
rpc:request('client/registerCapability', {
registrations = {
-- 监视文件变化
Expand All @@ -27,32 +56,6 @@ local function initAfterConfig(lsp)
}, function ()
log.debug('client/registerCapability Success!')
end)
end

return function (lsp)
local uri = lsp.workspace and lsp.workspace.uri
-- 请求配置
rpc:request('workspace/configuration', {
items = {
{
scopeUri = uri,
section = 'Lua',
},
{
scopeUri = uri,
section = 'files.associations',
},
{
scopeUri = uri,
section = 'files.exclude',
}
},
}, function (configs)
lsp:onUpdateConfig(configs[1], {
associations = configs[2],
exclude = configs[3],
})
initAfterConfig(lsp)
end)
return true
end
3 changes: 3 additions & 0 deletions script/method/textDocument/codeAction.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
local core = require 'core'

--- @param lsp LSP
--- @param params table
--- @return table
return function (lsp, params)
local uri = params.textDocument.uri
local vm, lines = lsp:getVM(uri)
Expand Down
3 changes: 3 additions & 0 deletions script/method/textDocument/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ local function cuterFactory(lines, text, position)
end
end

--- @param lsp LSP
--- @param params table
--- @return table
return function (lsp, params)
local uri = params.textDocument.uri
local text, oldText = lsp:getText(uri)
Expand Down
12 changes: 8 additions & 4 deletions script/method/textDocument/didChange.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
--- @param lsp LSP
--- @param params table
--- @return boolean
return function (lsp, params)
local doc = params.textDocument
local change = params.contentChanges
if lsp.workspace then
local path = lsp.workspace:relativePathByUri(doc.uri)
if not path or not lsp.workspace:isLuaFile(path) then
local ws = lsp:findWorkspaceFor(doc.uri)
if ws then
local path = ws:relativePathByUri(doc.uri)
if not path or not ws:isLuaFile(path) then
return
end
if not lsp:isOpen(doc.uri) and lsp.workspace.gitignore(path:string()) then
if not lsp:isOpen(doc.uri) and ws.gitignore(path:string()) then
return
end
end
Expand Down
3 changes: 3 additions & 0 deletions script/method/textDocument/didClose.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
--- @param lsp LSP
--- @param params table
--- @return boolean
return function (lsp, params)
local doc = params.textDocument
lsp:close(doc.uri)
Expand Down
3 changes: 3 additions & 0 deletions script/method/textDocument/didOpen.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
--- @param lsp LSP
--- @param params table
--- @return boolean
return function (lsp, params)
local doc = params.textDocument
lsp:open(doc.uri, doc.version, doc.text)
Expand Down
3 changes: 3 additions & 0 deletions script/method/textDocument/documentHighlight.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
local core = require 'core'

--- @param lsp LSP
--- @param params table
--- @return table
return function (lsp, params)
local uri = params.textDocument.uri
local vm, lines = lsp:loadVM(uri)
Expand Down
3 changes: 3 additions & 0 deletions script/method/textDocument/documentSymbol.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ local function convertRange(lines, symbol)
end
end

--- @param lsp LSP
--- @param params table
--- @return function
return function (lsp, params)
local uri = params.textDocument.uri

Expand Down
3 changes: 3 additions & 0 deletions script/method/textDocument/foldingRange.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ local function convertRange(lines, range)
return result
end

--- @param lsp LSP
--- @param params table
--- @return function
return function (lsp, params)
local uri = params.textDocument.uri
if timerCache[uri] then
Expand Down
3 changes: 3 additions & 0 deletions script/method/textDocument/hover.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
local core = require 'core'

--- @param lsp LSP
--- @param params table
--- @return table
return function (lsp, params)
local uri = params.textDocument.uri
local vm, lines = lsp:loadVM(uri)
Expand Down
3 changes: 3 additions & 0 deletions script/method/textDocument/implementation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ end

local LastTask

--- @param lsp LSP
--- @param params table
--- @return function
return function (lsp, params)
if LastTask then
LastTask:remove()
Expand Down
3 changes: 3 additions & 0 deletions script/method/textDocument/onTypeFormatting.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
--- @param lsp LSP
--- @param params table
--- @return any
return function (lsp, params)
local uri = params.textDocument.uri
local vm, lines = lsp:loadVM(uri)
Expand Down
3 changes: 3 additions & 0 deletions script/method/textDocument/publishDiagnostics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ local function buildError(err, lines, uri)
return diagnostic
end

--- @param lsp LSP
--- @param params table
--- @return table
return function (lsp, params)
local vm = params.vm
local lines = params.lines
Expand Down
3 changes: 3 additions & 0 deletions script/method/textDocument/references.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ local function findReferences(lsp, uri, position)
return locations, isGlobal
end

--- @param lsp LSP
--- @param params table
--- @return function
return function (lsp, params)
local uri = params.textDocument.uri
local declarat = params.context.includeDeclaration
Expand Down
3 changes: 3 additions & 0 deletions script/method/textDocument/rename.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
local core = require 'core'

--- @param lsp LSP
--- @param params table
--- @return table
return function (lsp, params)
local uri = params.textDocument.uri
local newName = params.newName
Expand Down
3 changes: 3 additions & 0 deletions script/method/textDocument/semanticTokens.lua
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ local function testTokens(vm, lines)
return tokens
end

--- @param lsp LSP
--- @param params table
--- @return function
return function (lsp, params)
local uri = params.textDocument.uri

Expand Down
3 changes: 3 additions & 0 deletions script/method/textDocument/signatureHelp.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
local core = require 'core'

--- @param lsp LSP
--- @param params table
--- @return table
return function (lsp, params)
local uri = params.textDocument.uri
local vm, lines = lsp:loadVM(uri)
Expand Down
47 changes: 25 additions & 22 deletions script/method/workspace/didChangeConfiguration.lua
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
local rpc = require 'rpc'

--- @param lsp LSP
return function (lsp)
local uri = lsp.workspace and lsp.workspace.uri
-- 请求配置
rpc:request('workspace/configuration', {
items = {
{
scopeUri = uri,
section = 'Lua',
for _, ws in ipairs(lsp.workspaces) do
local uri = ws.uri
-- 请求配置
rpc:request('workspace/configuration', {
items = {
{
scopeUri = uri,
section = 'Lua',
},
{
scopeUri = uri,
section = 'files.associations',
},
{
scopeUri = uri,
section = 'files.exclude',
}
},
{
scopeUri = uri,
section = 'files.associations',
},
{
scopeUri = uri,
section = 'files.exclude',
}
},
}, function (configs)
lsp:onUpdateConfig(configs[1], {
associations = configs[2],
exclude = configs[3],
})
end)
}, function (configs)
lsp:onUpdateConfig(configs[1], {
associations = configs[2],
exclude = configs[3],
})
end)
end
end
Loading