summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
Diffstat (limited to 'server/src')
-rw-r--r--server/src/core/hover/hover.lua3
-rw-r--r--server/src/method/textDocument/didChange.lua2
-rw-r--r--server/src/method/workspace/didChangeWatchedFiles.lua4
-rw-r--r--server/src/service.lua6
-rw-r--r--server/src/uri.lua2
-rw-r--r--server/src/workspace.lua20
6 files changed, 32 insertions, 5 deletions
diff --git a/server/src/core/hover/hover.lua b/server/src/core/hover/hover.lua
index ca1e03d4..2ee5cf46 100644
--- a/server/src/core/hover/hover.lua
+++ b/server/src/core/hover/hover.lua
@@ -298,6 +298,9 @@ local function hoverAsTargetUri(source, lsp)
return nil
end
local path = lsp.workspace:relativePathByUri(uri)
+ if not path then
+ return nil
+ end
return {
description = ('[%s](%s)'):format(path:string(), uri),
}
diff --git a/server/src/method/textDocument/didChange.lua b/server/src/method/textDocument/didChange.lua
index b2cad74d..82e6c096 100644
--- a/server/src/method/textDocument/didChange.lua
+++ b/server/src/method/textDocument/didChange.lua
@@ -3,7 +3,7 @@ return function (lsp, params)
local change = params.contentChanges
if lsp.workspace then
local path = lsp.workspace:relativePathByUri(doc.uri)
- if not lsp.workspace:isLuaFile(path) then
+ if not path or not lsp.workspace:isLuaFile(path) then
return
end
if not lsp:isOpen(doc.uri) and lsp.workspace.gitignore(path:string()) then
diff --git a/server/src/method/workspace/didChangeWatchedFiles.lua b/server/src/method/workspace/didChangeWatchedFiles.lua
index dcca48f1..3ce68924 100644
--- a/server/src/method/workspace/didChangeWatchedFiles.lua
+++ b/server/src/method/workspace/didChangeWatchedFiles.lua
@@ -14,6 +14,9 @@ return function (lsp, params)
local needReset
for _, change in ipairs(params.changes) do
local path = uric.decode(change.uri)
+ if not path then
+ goto CONTINUE
+ end
if change.type == FileChangeType.Created then
lsp.workspace:addFile(path)
if lsp:getVM(change.uri) then
@@ -32,6 +35,7 @@ return function (lsp, params)
then
lsp:reScanFiles()
end
+ ::CONTINUE::
end
-- 缓存过的文件发生变化后,重新计算
if needReset then
diff --git a/server/src/service.lua b/server/src/service.lua
index 7245b4e7..c763d73a 100644
--- a/server/src/service.lua
+++ b/server/src/service.lua
@@ -178,6 +178,9 @@ function mt:isLua(uri)
return true
end
local path = self.workspace:absolutePathByUri(uri)
+ if not path then
+ return false
+ end
if self.workspace:isLuaFile(path) then
return true
end
@@ -192,6 +195,9 @@ function mt:isIgnored(uri)
return true
end
local path = self.workspace:relativePathByUri(uri)
+ if not path then
+ return true
+ end
if self.workspace.gitignore(path:string()) then
return true
end
diff --git a/server/src/uri.lua b/server/src/uri.lua
index ec3cdad6..9053447c 100644
--- a/server/src/uri.lua
+++ b/server/src/uri.lua
@@ -9,7 +9,7 @@ local OS = platform.OS == 'Windows' and 'win32' or 'unix'
local function decode(uri)
local obj = URI:new(uri)
if not obj.filesystem_path then
- return ''
+ return nil
end
local fullPath = obj:filesystem_path(OS)
local path = fs.path(fullPath)
diff --git a/server/src/workspace.lua b/server/src/workspace.lua
index c5db8c5a..d50deca7 100644
--- a/server/src/workspace.lua
+++ b/server/src/workspace.lua
@@ -236,7 +236,11 @@ end
function mt:findPath(baseUri, searchers)
local results = {}
- local baseName = getFileName(uric.decode(baseUri))
+ local basePath = uric.decode(baseUri)
+ if not basePath then
+ return nil
+ end
+ local baseName = getFileName(basePath)
for filename, uri in pairs(self.files) do
if filename ~= baseName then
for _, searcher in ipairs(searchers) do
@@ -370,8 +374,12 @@ function mt:matchPath(baseUri, input)
return nil
end
first = first:gsub('%W', '%%%1')
- local baseName = getFileName(uric.decode(baseUri))
- local rootLen = #self.root:string()
+ local basePath = uric.decode(baseUri)
+ if not basePath then
+ return nil
+ end
+ local baseName = getFileName()
+ local rootLen = #self.root:string(basePath)
local map = {}
for filename in pairs(self.files) do
if filename ~= baseName then
@@ -477,6 +485,9 @@ end
---@return path
function mt:relativePathByUri(uri)
local path = uric.decode(uri)
+ if not path then
+ return nil
+ end
local relate = fs.relative(path, self.root)
return relate
end
@@ -485,6 +496,9 @@ end
---@return path
function mt:absolutePathByUri(uri)
local path = uric.decode(uri)
+ if not path then
+ return nil
+ end
return fs.absolute(path)
end