Skip to content

Commit

Permalink
Fix markdown in hover descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
NightrainsRbx committed Oct 25, 2021
1 parent 45a315e commit 2cf29ba
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
23 changes: 22 additions & 1 deletion server/script/provider/markdown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ local function checkSplitLine(self)
self[#self+1] = '\n---'
end

local function splitString(str, delimiter)
local result = {}
local from = 1
local delim_from, delim_to = string.find(str, delimiter, from, true)
while delim_from do
if (delim_from ~= 1) then
table.insert(result, string.sub(str, from, delim_from-1))
end
from = delim_to + 1
delim_from, delim_to = string.find(str, delimiter, from, true)
end
if (from <= #str) then table.insert(result, string.sub(str, from)) end
return result
end

function mt:add(language, text)
if not text or #text == 0 then
return
Expand All @@ -27,7 +42,13 @@ function mt:add(language, text)
if self._last == 'md' then
self[#self+1] = ''
end
self[#self+1] = text
local formattedLines = {}
local lines = splitString(text:gsub("\r", ""), "\n")
local indent = #(lines[1] or ""):match('^%s*')
for _, line in ipairs(lines) do
formattedLines[#formattedLines+1] = line:sub(indent + 1)
end
self[#self+1] = table.concat(formattedLines, "\n")
else
if #self > 0 then
self[#self+1] = ''
Expand Down
2 changes: 1 addition & 1 deletion server/script/provider/provider.lua
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ local function replaceSpaces(text)
end
return text:gsub(" +", function (s)
return (""):rep(#s)
end)
end):gsub("\t", "    ")
end

proto.on('textDocument/completion', function (params)
Expand Down

0 comments on commit 2cf29ba

Please sign in to comment.