From 09377c7ce742bdc29e9c5532d122ae39019345f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 4 Feb 2021 15:59:46 +0800 Subject: fix #379 semantic-tokens supports plugin --- changelog.md | 1 + script/core/semantic-tokens.lua | 15 +++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/changelog.md b/changelog.md index 2a2f8bdf..cca22554 100644 --- a/changelog.md +++ b/changelog.md @@ -5,6 +5,7 @@ * `FIX` [#375](https://github.com/sumneko/lua-language-server/issues/375) * `FIX` [#376](https://github.com/sumneko/lua-language-server/issues/376) * `FIX` [#378](https://github.com/sumneko/lua-language-server/issues/378) +* `FIX` [#379](https://github.com/sumneko/lua-language-server/issues/379) ## 1.14.1 `2021-2-2` diff --git a/script/core/semantic-tokens.lua b/script/core/semantic-tokens.lua index 73e0337b..56bfb5ef 100644 --- a/script/core/semantic-tokens.lua +++ b/script/core/semantic-tokens.lua @@ -135,16 +135,15 @@ Care['nonstandardSymbol.continue'] = function (source, results) } end -local function buildTokens(results, text, lines) +local function buildTokens(uri, results) local tokens = {} local lastLine = 0 local lastStartChar = 0 for i, source in ipairs(results) do - local row, col = guide.positionOf(lines, source.start) - local start = guide.lineRange(lines, row) - local ucol = util.utf8Len(text, start, start + col - 1) - local line = row - 1 - local startChar = ucol - 1 + local startPos = files.position(uri, source.start) + local finishPos = files.position(uri, source.finish) + local line = startPos.line + local startChar = startPos.character - 1 local deltaLine = line - lastLine local deltaStartChar if deltaLine == 0 then @@ -158,7 +157,7 @@ local function buildTokens(results, text, lines) local len = i * 5 - 5 tokens[len + 1] = deltaLine tokens[len + 2] = deltaStartChar - tokens[len + 3] = source.finish - source.start + 1 -- length + tokens[len + 3] = finishPos.character - startPos.character + 1 -- length tokens[len + 4] = source.type tokens[len + 5] = source.modifieres or 0 end @@ -201,7 +200,7 @@ return function (uri, start, finish) return a.start < b.start end) - local tokens = buildTokens(results, text, lines) + local tokens = buildTokens(uri, results) return tokens end -- cgit v1.2.3