summaryrefslogtreecommitdiff
path: root/server/src/core/highlight.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-03-28 10:39:18 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-03-28 10:39:18 +0800
commitee2b29b81b19d1d2a3bc28805b177b15d59088a1 (patch)
treeb63a6587cb2acc4749aa7074d735d335c7db0a56 /server/src/core/highlight.lua
parentde05c9167e2d9046d35bc5e6a9d4c587607ab219 (diff)
downloadlua-language-server-ee2b29b81b19d1d2a3bc28805b177b15d59088a1.zip
支持highlight
Diffstat (limited to 'server/src/core/highlight.lua')
-rw-r--r--server/src/core/highlight.lua54
1 files changed, 54 insertions, 0 deletions
diff --git a/server/src/core/highlight.lua b/server/src/core/highlight.lua
new file mode 100644
index 00000000..c71aab8b
--- /dev/null
+++ b/server/src/core/highlight.lua
@@ -0,0 +1,54 @@
+local findSource = require 'core.find_source'
+local parser = require 'parser'
+
+local DocumentHighlightKind = {
+ Text = 1,
+ Read = 2,
+ Write = 3,
+}
+
+local function parseResult(source)
+ local positions = {}
+ if source:bindLabel() then
+ source:bindLabel():eachInfo(function (info, src)
+ positions[#positions+1] = { src.start, src.finish, DocumentHighlightKind.Text }
+ end)
+ return positions
+ end
+ if source:bindLocal() then
+ local loc = source:bindLocal()
+ local mark = {}
+ loc:eachInfo(function (info, src)
+ if not mark[src] then
+ mark[src] = info
+ positions[#positions+1] = { src.start, src.finish, DocumentHighlightKind.Text }
+ end
+ end)
+ return positions
+ end
+ if source:bindValue() then
+ local parent = source:get 'parent'
+ local mark = {}
+ parent:eachInfo(function (info, src)
+ if not mark[src] then
+ mark[src] = info
+ if info.type == 'get child' or info.type == 'set child' then
+ if info[1] == source[1] then
+ positions[#positions+1] = {src.start, src.finish, DocumentHighlightKind.Text}
+ end
+ end
+ end
+ end)
+ return positions
+ end
+ return nil
+end
+
+return function (vm, pos)
+ local source = findSource(vm, pos)
+ if not source then
+ return nil
+ end
+ local positions = parseResult(source)
+ return positions
+end