diff options
-rw-r--r-- | server/src/core/completion.lua | 14 | ||||
-rw-r--r-- | server/src/core/hover/hover.lua | 20 | ||||
-rw-r--r-- | server/src/vm/value.lua | 8 | ||||
-rw-r--r-- | server/src/vm/vm.lua | 6 | ||||
-rw-r--r-- | server/test/completion/init.lua | 17 | ||||
-rw-r--r-- | server/test/crossfile/hover.lua | 19 |
6 files changed, 72 insertions, 12 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua index 34eecb0e..3575622e 100644 --- a/server/src/core/completion.lua +++ b/server/src/core/completion.lua @@ -76,6 +76,20 @@ local function getDucumentation(name, value) value = text, } end + local lib = value:getLib() + if lib then + return { + kind = 'markdown', + value = lib.description, + } + end + local comment = value:getComment() + if comment then + return { + kind = 'markdown', + value = comment, + } + end return nil end diff --git a/server/src/core/hover/hover.lua b/server/src/core/hover/hover.lua index 25a1bc3b..d78b8add 100644 --- a/server/src/core/hover/hover.lua +++ b/server/src/core/hover/hover.lua @@ -191,15 +191,17 @@ local function getValueHover(source, name, value, lib) valueType = '*' .. valueType end - local tip + local tips = {} local literal if lib then literal = lib.code or (lib.value and formatLiteral(lib.value)) - tip = lib.description + tips[#tips+1] = lib.description else literal = value:getLiteral() and formatLiteral(value:getLiteral()) end + tips[#tips+1] = value:getComment() + local tp if source:bindLocal() then tp = 'local' @@ -214,14 +216,7 @@ local function getValueHover(source, name, value, lib) end end end - local comment = loc:getComment() - if comment then - if tip then - tip = tip .. '\n\n-------------\n\n' .. comment - else - tip = comment - end - end + tips[#tips+1] = loc:getComment() elseif source:get 'global' then tp = 'global' elseif source:get 'simple' then @@ -249,6 +244,11 @@ local function getValueHover(source, name, value, lib) text = ('%s %s: %s = %s'):format(tp, name, valueType, literal) end end + + local tip + if #tips > 0 then + tip = table.concat(tips, '\n\n-------------\n\n') + end return { label = text, description = tip, diff --git a/server/src/vm/value.lua b/server/src/vm/value.lua index bf20468d..5de0d8e8 100644 --- a/server/src/vm/value.lua +++ b/server/src/vm/value.lua @@ -620,6 +620,14 @@ function mt:getEmmy() return self._emmy end +function mt:setComment(comment) + self._comment = comment +end + +function mt:getComment(comment) + return self._comment +end + return { create = create, watch = Watch, diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua index f8632dab..f0e30537 100644 --- a/server/src/vm/vm.lua +++ b/server/src/vm/vm.lua @@ -793,11 +793,12 @@ function mt:doGoTo(source) end end -function mt:setOne(var, value, emmy) +function mt:setOne(var, value, emmy, comment) if not value then value = valueMgr.create('nil', self:getDefaultSource()) end value:setEmmy(emmy) + value:setComment(comment) self:instantSource(var) if var.type == 'name' then self:setName(var[1], var, value) @@ -822,6 +823,7 @@ end function mt:doSet(action) local emmy = self:getEmmy() + local comment = self:getEmmyComment() if not action[2] then return end @@ -844,7 +846,7 @@ function mt:doSet(action) local i = 0 self:forList(vars, function (var) i = i + 1 - self:setOne(var, values[i], emmy) + self:setOne(var, values[i], emmy, comment) end) end diff --git a/server/test/completion/init.lua b/server/test/completion/init.lua index 2b63358e..c60e8ea0 100644 --- a/server/test/completion/init.lua +++ b/server/test/completion/init.lua @@ -1321,3 +1321,20 @@ JustTest }, } } + +TEST [[ +--- abc +zzz = 1 +zz$ +]] +{ + { + label = 'zzz', + kind = CompletionItemKind.Enum, + detail = '(number) = 1', + documentation = { + kind = 'markdown', + value = 'abc', + } + } +} diff --git a/server/test/crossfile/hover.lua b/server/test/crossfile/hover.lua index 6941edb8..b0b8ab61 100644 --- a/server/test/crossfile/hover.lua +++ b/server/test/crossfile/hover.lua @@ -240,3 +240,22 @@ TEST { description = 'abc', } } + +TEST { + { + path = 'a.lua', + content = '', + }, + { + path = 'b.lua', + content = [[ + --- abc + <?x?> = 1 + ]], + }, + hover = { + label = [[global x: number = 1]], + name = 'x', + description = 'abc', + } +} |