diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-08-20 17:52:06 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-08-20 17:52:06 +0800 |
commit | cb1a412bc7c205c73aec3ef2b1f8f8baf4564fb0 (patch) | |
tree | 1175e6ac7bbf1a0747780b8bad6728b8b4da5b00 /script/provider | |
parent | fd86458f11ee270884af730a4344ac000265e64e (diff) | |
download | lua-language-server-cb1a412bc7c205c73aec3ef2b1f8f8baf4564fb0.zip |
stash
Diffstat (limited to 'script/provider')
-rw-r--r-- | script/provider/markdown.lua | 9 | ||||
-rw-r--r-- | script/provider/provider.lua | 10 |
2 files changed, 11 insertions, 8 deletions
diff --git a/script/provider/markdown.lua b/script/provider/markdown.lua index 140267d7..3a215f0f 100644 --- a/script/provider/markdown.lua +++ b/script/provider/markdown.lua @@ -15,6 +15,7 @@ function mt:add(language, text) if not text then return end + self._cacheResult = nil if type(text) == 'table' then self[#self+1] = { type = 'markdown', @@ -34,12 +35,16 @@ function mt:add(language, text) end function mt:splitLine() + self._cacheResult = nil self[#self+1] = { type = 'splitline', } end function mt:string() + if self._cacheResult then + return self._cacheResult + end local lines = {} local language = 'md' @@ -97,7 +102,9 @@ function mt:string() end end - return table.concat(lines, '\n') + local result = table.concat(lines, '\n') + self._cacheResult = result + return result end return function () diff --git a/script/provider/provider.lua b/script/provider/provider.lua index 09a031cc..6ffb0837 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -186,20 +186,16 @@ proto.on('textDocument/hover', function (params) return nil end local offset = files.offsetOfWord(uri, params.position) - local hover = core.byUri(uri, offset) + local hover, source = core.byUri(uri, offset) if not hover then return nil end - local md = markdown() - md:add('lua', hover.label) - md:splitLine() - md:add('md', hover.description) return { contents = { - value = md:string(), + value = tostring(hover), kind = 'markdown', }, - range = files.range(uri, hover.source.start, hover.source.finish), + range = files.range(uri, source.start, source.finish), } end) |