diff options
Diffstat (limited to 'server-beta')
-rw-r--r-- | server-beta/src/core/highlight.lua | 44 | ||||
-rw-r--r-- | server-beta/src/proto/define.lua | 6 | ||||
-rw-r--r-- | server-beta/src/provider/capability.lua | 2 | ||||
-rw-r--r-- | server-beta/src/provider/init.lua | 23 | ||||
-rw-r--r-- | server-beta/test/highlight/init.lua | 4 |
5 files changed, 70 insertions, 9 deletions
diff --git a/server-beta/src/core/highlight.lua b/server-beta/src/core/highlight.lua index 1516187e..16c82a16 100644 --- a/server-beta/src/core/highlight.lua +++ b/server-beta/src/core/highlight.lua @@ -1,6 +1,7 @@ local guide = require 'parser.guide' local files = require 'files' local searcher = require 'searcher' +local define = require 'proto.define' local function ofLocal(source, callback) callback(source) @@ -54,8 +55,10 @@ local function find(source, uri, callback) elseif source.type == 'field' or source.type == 'method' then ofField(source, uri, callback) - elseif source.type == 'string' - or source.type == 'boolean' + elseif source.type == 'string' then + ofIndex(source, uri, callback) + callback(source) + elseif source.type == 'boolean' or source.type == 'number' then ofIndex(source, uri, callback) elseif source.type == 'goto' @@ -73,17 +76,41 @@ return function (uri, offset) local mark = {} guide.eachSourceContain(ast.ast, offset, function (source) find(source, uri, function (target) - if target.type == 'getfield' - or target.type == 'setfield' + local kind + if target.type == 'getfield' then + target = target.field + kind = define.DocumentHighlightKind.Read + elseif target.type == 'setfield' or target.type == 'tablefield' then target = target.field - elseif target.type == 'getmethod' - or target.type == 'setmethod' then + kind = define.DocumentHighlightKind.Write + elseif target.type == 'getmethod' then + target = target.method + kind = define.DocumentHighlightKind.Read + elseif target.type == 'setmethod' then target = target.method - elseif target.type == 'getindex' - or target.type == 'setindex' + kind = define.DocumentHighlightKind.Write + elseif target.type == 'getindex' then + target = target.index + kind = define.DocumentHighlightKind.Read + elseif target.type == 'setindex' or target.type == 'tableindex' then target = target.index + kind = define.DocumentHighlightKind.Write + elseif target.type == 'getlocal' + or target.type == 'getglobal' + or target.type == 'goto' then + kind = define.DocumentHighlightKind.Read + elseif target.type == 'setlocal' + or target.type == 'local' + or target.type == 'setglobal' + or target.type == 'label' then + kind = define.DocumentHighlightKind.Write + elseif target.type == 'string' then + kind = define.DocumentHighlightKind.Text + else + log.warn('Unknow target.type:', target.type) + return end if mark[target] then return @@ -92,6 +119,7 @@ return function (uri, offset) results[#results+1] = { start = target.start, finish = target.finish, + kind = kind, } end) end) diff --git a/server-beta/src/proto/define.lua b/server-beta/src/proto/define.lua index 9a890e2e..3771c726 100644 --- a/server-beta/src/proto/define.lua +++ b/server-beta/src/proto/define.lua @@ -114,4 +114,10 @@ m.DiagnosticTag = { Deprecated = 2, } +m.DocumentHighlightKind = { + Text = 1, + Read = 2, + Write = 3, +} + return m diff --git a/server-beta/src/provider/capability.lua b/server-beta/src/provider/capability.lua index c5762f0b..5cefd0c5 100644 --- a/server-beta/src/provider/capability.lua +++ b/server-beta/src/provider/capability.lua @@ -14,7 +14,7 @@ m.initer = { referencesProvider = true, --renameProvider = true, --documentSymbolProvider = true, - --documentHighlightProvider = true, + documentHighlightProvider = true, --codeActionProvider = true, --signatureHelpProvider = { -- triggerCharacters = { '(', ',' }, diff --git a/server-beta/src/provider/init.lua b/server-beta/src/provider/init.lua index 5e1a1a2a..0a70763e 100644 --- a/server-beta/src/provider/init.lua +++ b/server-beta/src/provider/init.lua @@ -207,6 +207,29 @@ proto.on('textDocument/references', function (params) return response end) +proto.on('textDocument/documentHighlight', function (params) + local core = require 'core.highlight' + local uri = params.textDocument.uri + if not files.exists(uri) then + return nil + end + local lines = files.getLines(uri) + local text = files.getText(uri) + local offset = define.offset(lines, text, params.position) + local result = core(uri, offset) + if not result then + return nil + end + local response = {} + for _, info in ipairs(result) do + response[#response+1] = { + range = define.range(lines, text, info.start, info.finish), + kind = info.kind, + } + end + return response +end) + proto.on('textDocument/completion', function (params) --log.info(util.dump(params)) return nil diff --git a/server-beta/test/highlight/init.lua b/server-beta/test/highlight/init.lua index ebde9204..6298fc2e 100644 --- a/server-beta/test/highlight/init.lua +++ b/server-beta/test/highlight/init.lua @@ -86,3 +86,7 @@ local function f(<!a!>) return <?a?> end ]] + +TEST [[ +local s = <?'asd/gadasd.fad.zxczg'?> +]] |