summaryrefslogtreecommitdiff
path: root/server
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
parentb80dc1e6acaf9df1c2f53ca83f0ed9cbf8e1fa71 (diff)
downloadlua-language-server-a67da00e8e2b61a2fa197188b7ffb3e3b83a2a74.zip
更加准确的分词
Diffstat (limited to 'server')
-rw-r--r--server/src/core/completion.lua2
-rw-r--r--server/src/core/find_source.lua2
-rw-r--r--server/src/core/signature.lua4
-rw-r--r--server/src/method/textDocument/completion.lua2
-rw-r--r--server/src/method/textDocument/definition.lua2
-rw-r--r--server/src/method/textDocument/hover.lua2
-rw-r--r--server/src/method/textDocument/implementation.lua2
-rw-r--r--server/src/method/textDocument/references.lua2
-rw-r--r--server/src/method/textDocument/rename.lua3
-rw-r--r--server/src/method/textDocument/signatureHelp.lua3
-rw-r--r--server/src/parser/lines.lua32
11 files changed, 43 insertions, 13 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua
index fcea333d..67527d22 100644
--- a/server/src/core/completion.lua
+++ b/server/src/core/completion.lua
@@ -525,7 +525,7 @@ local function makeList(source, word)
end
return function (vm, pos, word)
- local source = findSource(vm, pos)
+ local source = findSource(vm, pos) or findSource(vm, pos-1)
if not source then
return nil
end
diff --git a/server/src/core/find_source.lua b/server/src/core/find_source.lua
index 4c4c460c..79ff85f9 100644
--- a/server/src/core/find_source.lua
+++ b/server/src/core/find_source.lua
@@ -1,5 +1,5 @@
local function isContainPos(obj, pos)
- if obj.start <= pos and obj.finish + 1 >= pos then
+ if obj.start <= pos and obj.finish >= pos then
return true
end
return false
diff --git a/server/src/core/signature.lua b/server/src/core/signature.lua
index 3e551e38..1e629308 100644
--- a/server/src/core/signature.lua
+++ b/server/src/core/signature.lua
@@ -68,8 +68,8 @@ local function getHover(call, pos)
end
return function (vm, pos)
- local source = findSource(vm, pos)
- if source.type == 'string' then
+ local source = findSource(vm, pos) or findSource(vm, pos-1)
+ if not source or source.type == 'string' then
return
end
local calls = findCall(vm, pos)
diff --git a/server/src/method/textDocument/completion.lua b/server/src/method/textDocument/completion.lua
index 0b559145..439cf0c1 100644
--- a/server/src/method/textDocument/completion.lua
+++ b/server/src/method/textDocument/completion.lua
@@ -64,7 +64,7 @@ return function (lsp, params)
local lines = parser:lines(text, 'utf8')
-- lua是从1开始的,因此都要+1
- local position = lines:position(params.position.line + 1, params.position.character + 1)
+ local position = lines:positionAsChar(params.position.line + 1, params.position.character)
local word = findWord(position, text)
local startPos = findStartPos(position, text)
diff --git a/server/src/method/textDocument/definition.lua b/server/src/method/textDocument/definition.lua
index a9c05752..e1c45317 100644
--- a/server/src/method/textDocument/definition.lua
+++ b/server/src/method/textDocument/definition.lua
@@ -17,7 +17,7 @@ return function (lsp, params)
return nil
end
-- lua是从1开始的,因此都要+1
- local position = lines:position(params.position.line + 1, params.position.character + 1)
+ local position = lines:positionAsChar(params.position.line + 1, params.position.character)
local source = core.findSource(vm, position)
if not source then
return nil
diff --git a/server/src/method/textDocument/hover.lua b/server/src/method/textDocument/hover.lua
index 5bb8cbb9..4ea76d6d 100644
--- a/server/src/method/textDocument/hover.lua
+++ b/server/src/method/textDocument/hover.lua
@@ -7,7 +7,7 @@ return function (lsp, params)
return nil
end
-- lua是从1开始的,因此都要+1
- local position = lines:position(params.position.line + 1, params.position.character + 1)
+ local position = lines:positionAsChar(params.position.line + 1, params.position.character)
local source = core.findSource(vm, position)
if not source then
diff --git a/server/src/method/textDocument/implementation.lua b/server/src/method/textDocument/implementation.lua
index c9062180..8bd35a6c 100644
--- a/server/src/method/textDocument/implementation.lua
+++ b/server/src/method/textDocument/implementation.lua
@@ -17,7 +17,7 @@ return function (lsp, params)
return nil
end
-- lua是从1开始的,因此都要+1
- local position = lines:position(params.position.line + 1, params.position.character + 1)
+ local position = lines:positionAsChar(params.position.line + 1, params.position.character)
local source = core.findSource(vm, position)
if not source then
return nil
diff --git a/server/src/method/textDocument/references.lua b/server/src/method/textDocument/references.lua
index 8b5fcab7..cdc25f05 100644
--- a/server/src/method/textDocument/references.lua
+++ b/server/src/method/textDocument/references.lua
@@ -9,7 +9,7 @@ return function (lsp, params)
end
-- lua是从1开始的,因此都要+1
- local position = lines:position(params.position.line + 1, params.position.character + 1)
+ local position = lines:positionAsChar(params.position.line + 1, params.position.character)
local positions = core.references(vm, position, declarat)
if not positions then
return {}
diff --git a/server/src/method/textDocument/rename.lua b/server/src/method/textDocument/rename.lua
index fcbdfef7..95ee0cfe 100644
--- a/server/src/method/textDocument/rename.lua
+++ b/server/src/method/textDocument/rename.lua
@@ -7,8 +7,7 @@ return function (lsp, params)
if not vm then
return {}
end
- -- lua是从1开始的,因此都要+1
- local position = lines:position(params.position.line + 1, params.position.character + 1)
+ local position = lines:positionAsChar(params.position.line + 1, params.position.character)
local positions = core.rename(vm, position, newName)
if not positions then
return {}
diff --git a/server/src/method/textDocument/signatureHelp.lua b/server/src/method/textDocument/signatureHelp.lua
index cf9935bd..98d2ea9b 100644
--- a/server/src/method/textDocument/signatureHelp.lua
+++ b/server/src/method/textDocument/signatureHelp.lua
@@ -6,8 +6,7 @@ return function (lsp, params)
if not vm then
return
end
- -- lua是从1开始的,因此都要+1
- local position = lines:position(params.position.line + 1, params.position.character + 1)
+ local position = lines:positionAsChar(params.position.line + 1, params.position.character)
local hovers = core.signature(vm, position)
if not hovers then
return
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