summaryrefslogtreecommitdiff
path: root/script/core/noder.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-06-28 20:32:24 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-06-28 20:32:24 +0800
commit86c17f83e5b94ed478231b68bffc648a479e89f5 (patch)
treeda5c120855608d7473545473dad202ca3698d14b /script/core/noder.lua
parent845d1be1c9f3f74ac0674d4bb7d0a37ca83a3a65 (diff)
downloadlua-language-server-86c17f83e5b94ed478231b68bffc648a479e89f5.zip
cleanup
Diffstat (limited to 'script/core/noder.lua')
-rw-r--r--script/core/noder.lua23
1 files changed, 22 insertions, 1 deletions
diff --git a/script/core/noder.lua b/script/core/noder.lua
index 3dabf66c..b4480e66 100644
--- a/script/core/noder.lua
+++ b/script/core/noder.lua
@@ -6,6 +6,7 @@ local files = require 'files'
local SPLIT_CHAR = '\x1F'
local LAST_REGEX = SPLIT_CHAR .. '[^' .. SPLIT_CHAR .. ']*$'
local FIRST_REGEX = '^[^' .. SPLIT_CHAR .. ']*'
+local HEAD_REGEX = '^' .. SPLIT_CHAR .. '?[^' .. SPLIT_CHAR .. ']*'
local ANY_FIELD_CHAR = '*'
local INDEX_CHAR = '['
local RETURN_INDEX = SPLIT_CHAR .. '#'
@@ -1067,9 +1068,26 @@ function m.getFirstID(id)
if count == 0 then
return nil
end
+ if firstID == '' then
+ return nil
+ end
return firstID
end
+---根据ID来获取第一个节点的ID或field
+---@param id string
+---@return string
+function m.getHeadID(id)
+ local headID, count = id:match(HEAD_REGEX)
+ if count == 0 then
+ return nil
+ end
+ if headID == '' then
+ return nil
+ end
+ return headID
+end
+
---根据ID来获取上个节点的ID
---@param id string
---@return string
@@ -1078,6 +1096,9 @@ function m.getLastID(id)
if count == 0 then
return nil
end
+ if lastID == '' then
+ return nil
+ end
return lastID
end
@@ -1097,7 +1118,7 @@ end
---@return boolean
function m.hasField(id)
local firstID = m.getFirstID(id)
- if firstID == id then
+ if firstID == id or not firstID then
return false
end
local nextChar = id:sub(#firstID + 1, #firstID + 1)