summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-08 19:13:50 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-08 19:13:50 +0800
commit2a8a23aec9cceec42f288750b3ed19ec8bd23fc7 (patch)
treea9cb5d3430c422a0e26035150c45a4732cf2e631 /server
parentb7217e6433587f7be77660f05f1b0257aeab02c8 (diff)
downloadlua-language-server-2a8a23aec9cceec42f288750b3ed19ec8bd23fc7.zip
不用每次指定编码了
Diffstat (limited to 'server')
-rw-r--r--server/src/matcher/diagnostics.lua4
-rw-r--r--server/src/method/textDocument/definition.lua6
-rw-r--r--server/src/method/textDocument/hover.lua2
-rw-r--r--server/src/method/textDocument/implementation.lua6
-rw-r--r--server/src/method/textDocument/publishDiagnostics.lua8
-rw-r--r--server/src/method/textDocument/references.lua6
-rw-r--r--server/src/method/textDocument/rename.lua6
-rw-r--r--server/src/parser/lines.lua3
-rw-r--r--server/src/service.lua2
9 files changed, 22 insertions, 21 deletions
diff --git a/server/src/matcher/diagnostics.lua b/server/src/matcher/diagnostics.lua
index 2b66c490..29cd4559 100644
--- a/server/src/matcher/diagnostics.lua
+++ b/server/src/matcher/diagnostics.lua
@@ -127,8 +127,8 @@ local function searchNewLineCall(results, lines, callback)
if not call.lastobj.start then
goto NEXT_CALL
end
- local callline = lines:rowcol(call.call.start, 'utf8')
- local lastline = lines:rowcol(call.lastobj.start, 'utf8')
+ local callline = lines:rowcol(call.call.start)
+ local lastline = lines:rowcol(call.lastobj.start)
if callline > lastline then
callback(call.call.start, call.call.finish)
end
diff --git a/server/src/method/textDocument/definition.lua b/server/src/method/textDocument/definition.lua
index 4d3d861e..d44ec1f6 100644
--- a/server/src/method/textDocument/definition.lua
+++ b/server/src/method/textDocument/definition.lua
@@ -7,7 +7,7 @@ return function (lsp, params)
return {}
end
-- lua是从1开始的,因此都要+1
- local position = lines:position(params.position.line + 1, params.position.character + 1, 'utf8')
+ local position = lines:position(params.position.line + 1, params.position.character + 1)
local positions = matcher.definition(results, position)
if not positions then
return {}
@@ -16,8 +16,8 @@ return function (lsp, params)
local locations = {}
for i, position in ipairs(positions) do
local start, finish = position[1], position[2]
- local start_row, start_col = lines:rowcol(start, 'utf8')
- local finish_row, finish_col = lines:rowcol(finish, 'utf8')
+ local start_row, start_col = lines:rowcol(start)
+ local finish_row, finish_col = lines:rowcol(finish)
locations[i] = {
uri = uri,
range = {
diff --git a/server/src/method/textDocument/hover.lua b/server/src/method/textDocument/hover.lua
index b9493c86..29f7304a 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, 'utf8')
+ local position = lines:position(params.position.line + 1, params.position.character + 1)
local text = matcher.hover(results, position)
if not text then
return nil
diff --git a/server/src/method/textDocument/implementation.lua b/server/src/method/textDocument/implementation.lua
index aef9f1a0..07d48870 100644
--- a/server/src/method/textDocument/implementation.lua
+++ b/server/src/method/textDocument/implementation.lua
@@ -7,7 +7,7 @@ return function (lsp, params)
return {}
end
-- lua是从1开始的,因此都要+1
- local position = lines:position(params.position.line + 1, params.position.character + 1, 'utf8')
+ local position = lines:position(params.position.line + 1, params.position.character + 1)
local positions = matcher.implementation(results, position)
if not positions then
return {}
@@ -16,8 +16,8 @@ return function (lsp, params)
local locations = {}
for i, position in ipairs(positions) do
local start, finish = position[1], position[2]
- local start_row, start_col = lines:rowcol(start, 'utf8')
- local finish_row, finish_col = lines:rowcol(finish, 'utf8')
+ local start_row, start_col = lines:rowcol(start)
+ local finish_row, finish_col = lines:rowcol(finish)
locations[i] = {
uri = uri,
range = {
diff --git a/server/src/method/textDocument/publishDiagnostics.lua b/server/src/method/textDocument/publishDiagnostics.lua
index d9a21c8b..b0b36cb9 100644
--- a/server/src/method/textDocument/publishDiagnostics.lua
+++ b/server/src/method/textDocument/publishDiagnostics.lua
@@ -27,8 +27,8 @@ export interface DiagnosticRelatedInformation {
]]--
local function getRange(start, finish, lines)
- local start_row, start_col = lines:rowcol(start, 'utf8')
- local finish_row, finish_col = lines:rowcol(finish, 'utf8')
+ local start_row, start_col = lines:rowcol(start)
+ local finish_row, finish_col = lines:rowcol(finish)
return {
start = {
line = start_row - 1,
@@ -54,8 +54,8 @@ local function createInfo(data, lines)
for i, info in ipairs(data.related) do
local message = info.message
if not message then
- local start_line = lines:rowcol(info.start, 'utf8')
- local finish_line = lines:rowcol(info.finish, 'utf8')
+ local start_line = lines:rowcol(info.start)
+ local finish_line = lines:rowcol(info.finish)
local chars = {}
for n = start_line, finish_line do
chars[#chars+1] = lines:line(n)
diff --git a/server/src/method/textDocument/references.lua b/server/src/method/textDocument/references.lua
index 4b17700e..a4d8e6ab 100644
--- a/server/src/method/textDocument/references.lua
+++ b/server/src/method/textDocument/references.lua
@@ -8,7 +8,7 @@ return function (lsp, params)
return {}
end
-- lua是从1开始的,因此都要+1
- local position = lines:position(params.position.line + 1, params.position.character + 1, 'utf8')
+ local position = lines:position(params.position.line + 1, params.position.character + 1)
local positions = matcher.references(results, position, declarat)
if not positions then
return {}
@@ -17,8 +17,8 @@ return function (lsp, params)
local locations = {}
for i, position in ipairs(positions) do
local start, finish = position[1], position[2]
- local start_row, start_col = lines:rowcol(start, 'utf8')
- local finish_row, finish_col = lines:rowcol(finish, 'utf8')
+ local start_row, start_col = lines:rowcol(start)
+ local finish_row, finish_col = lines:rowcol(finish)
locations[i] = {
uri = uri,
range = {
diff --git a/server/src/method/textDocument/rename.lua b/server/src/method/textDocument/rename.lua
index bfb5cbba..6dd0d5ae 100644
--- a/server/src/method/textDocument/rename.lua
+++ b/server/src/method/textDocument/rename.lua
@@ -8,7 +8,7 @@ return function (lsp, params)
return {}
end
-- lua是从1开始的,因此都要+1
- local position = lines:position(params.position.line + 1, params.position.character + 1, 'utf8')
+ local position = lines:position(params.position.line + 1, params.position.character + 1)
local positions = matcher.rename(results, position, newName)
if not positions then
return {}
@@ -17,8 +17,8 @@ return function (lsp, params)
local TextEdit = {}
for i, position in ipairs(positions) do
local start, finish = position[1], position[2]
- local start_row, start_col = lines:rowcol(start, 'utf8')
- local finish_row, finish_col = lines:rowcol(finish, 'utf8')
+ local start_row, start_col = lines:rowcol(start)
+ local finish_row, finish_col = lines:rowcol(finish)
TextEdit[i] = {
newText = newName,
range = {
diff --git a/server/src/parser/lines.lua b/server/src/parser/lines.lua
index 88966bda..e3b51aa2 100644
--- a/server/src/parser/lines.lua
+++ b/server/src/parser/lines.lua
@@ -142,12 +142,13 @@ function mt:set_code(code)
self.code = code
end
-return function (self, buf)
+return function (self, buf, code)
local lines, err = parser:match(buf)
if not lines then
return nil, err
end
lines.buf = buf
+ lines.code = code
return setmetatable(lines, mt)
end
diff --git a/server/src/service.lua b/server/src/service.lua
index 652fa7d5..109a8c1c 100644
--- a/server/src/service.lua
+++ b/server/src/service.lua
@@ -203,7 +203,7 @@ function mt:compileText(uri)
if not obj.results then
return obj
end
- obj.lines = parser:lines(obj.text)
+ obj.lines = parser:lines(obj.text, 'utf8')
self._needDiagnostics[uri] = {
ast = ast,