summaryrefslogtreecommitdiff
path: root/server/src/parser/lines.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-03-21 15:41:59 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-03-21 15:41:59 +0800
commita67da00e8e2b61a2fa197188b7ffb3e3b83a2a74 (patch)
tree749c08fa9ad3e5131c24592c72db121e1bb9d601 /server/src/parser/lines.lua
parentb80dc1e6acaf9df1c2f53ca83f0ed9cbf8e1fa71 (diff)
downloadlua-language-server-a67da00e8e2b61a2fa197188b7ffb3e3b83a2a74.zip
更加准确的分词
Diffstat (limited to 'server/src/parser/lines.lua')
-rw-r--r--server/src/parser/lines.lua32
1 files changed, 32 insertions, 0 deletions
diff --git a/server/src/parser/lines.lua b/server/src/parser/lines.lua
index e3b51aa2..d3d5c7c5 100644
--- a/server/src/parser/lines.lua
+++ b/server/src/parser/lines.lua
@@ -78,6 +78,38 @@ function mt:position(row, col, code)
return pos
end
+local function isCharByte(byte)
+ -- [0-9]
+ if byte >= 48 and byte <= 57 then
+ return true
+ end
+ -- [A-Z]
+ if byte >= 65 and byte <= 90 then
+ return true
+ end
+ -- [a-z]
+ if byte >= 97 and byte <= 122 then
+ return true
+ end
+ -- <utf8>
+ if byte >= 128 then
+ return true
+ end
+ return false
+end
+
+function mt:positionAsChar(row, col, code)
+ local pos = self:position(row, col+1, code)
+ if isCharByte(self.buf:byte(pos, pos)) then
+ return pos
+ elseif isCharByte(self.buf:byte(pos+1, pos+1)) then
+ return pos + 1
+ elseif isCharByte(self.buf:byte(pos-1, pos-1)) then
+ return pos - 1
+ end
+ return pos
+end
+
function mt:rowcol(pos, code)
if pos < 1 then
return 1, 1