diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-10-26 20:56:42 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-10-26 20:56:42 +0800 |
commit | 6a237a482e05088fcd07247310aa0e895235c773 (patch) | |
tree | 56f465720888d4db1cce4a9d3c7253624b70a457 /script-beta | |
parent | 0b708180509007bfb6c54d8112f85d5f85ec9210 (diff) | |
download | lua-language-server-6a237a482e05088fcd07247310aa0e895235c773.zip |
type.function
Diffstat (limited to 'script-beta')
-rw-r--r-- | script-beta/core/diagnostics/undefined-doc-class.lua | 2 | ||||
-rw-r--r-- | script-beta/core/diagnostics/undefined-doc-name.lua | 2 | ||||
-rw-r--r-- | script-beta/core/hover/arg.lua | 16 | ||||
-rw-r--r-- | script-beta/core/hover/init.lua | 10 | ||||
-rw-r--r-- | script-beta/core/hover/label.lua | 12 | ||||
-rw-r--r-- | script-beta/core/hover/return.lua | 19 | ||||
-rw-r--r-- | script-beta/parser/guide.lua | 10 |
7 files changed, 67 insertions, 4 deletions
diff --git a/script-beta/core/diagnostics/undefined-doc-class.lua b/script-beta/core/diagnostics/undefined-doc-class.lua index db68c74e..1fc19259 100644 --- a/script-beta/core/diagnostics/undefined-doc-class.lua +++ b/script-beta/core/diagnostics/undefined-doc-class.lua @@ -4,9 +4,11 @@ local lang = require 'language' local define = require 'proto.define' local vm = require 'vm' +-- TODO local builtin = { ['any'] = true, ['nil'] = true, + ['void'] = true, ['boolean'] = true, ['number'] = true, ['integer'] = true, diff --git a/script-beta/core/diagnostics/undefined-doc-name.lua b/script-beta/core/diagnostics/undefined-doc-name.lua index 65d3a8ab..6a60fe65 100644 --- a/script-beta/core/diagnostics/undefined-doc-name.lua +++ b/script-beta/core/diagnostics/undefined-doc-name.lua @@ -4,9 +4,11 @@ local lang = require 'language' local define = require 'proto.define' local vm = require 'vm' +-- TODO local builtin = { ['any'] = true, ['nil'] = true, + ['void'] = true, ['boolean'] = true, ['number'] = true, ['integer'] = true, diff --git a/script-beta/core/hover/arg.lua b/script-beta/core/hover/arg.lua index a6d3a14b..5dcf94b6 100644 --- a/script-beta/core/hover/arg.lua +++ b/script-beta/core/hover/arg.lua @@ -82,6 +82,19 @@ local function asFunction(source, oop) end end +local function asDocFunction(source) + if not source.args then + return '' + end + local args = {} + for i = 1, #source.args do + local arg = source.args[i] + local name = arg.name[1] + args[i] = ('%s: %s'):format(name, vm.getInferType(arg.extends)) + end + return table.concat(args, ', ') +end + return function (source, oop) if source.type == 'library' then return asLibrary(source.value, oop) @@ -91,5 +104,8 @@ return function (source, oop) if source.type == 'function' then return asFunction(source, oop) end + if source.type == 'doc.type.function' then + return asDocFunction(source) + end return '' end diff --git a/script-beta/core/hover/init.lua b/script-beta/core/hover/init.lua index f8e4c65f..77f9d6d9 100644 --- a/script-beta/core/hover/init.lua +++ b/script-beta/core/hover/init.lua @@ -20,10 +20,12 @@ local function getHoverAsFunction(source) for _, value in ipairs(values) do if value.type == 'function' then local label = getLabel(value.source, oop) - defs = defs + 1 - labels[label] = (labels[label] or 0) + 1 - if labels[label] == 1 then - protos = protos + 1 + if label then + defs = defs + 1 + labels[label] = (labels[label] or 0) + 1 + if labels[label] == 1 then + protos = protos + 1 + end end elseif value.type == 'table' or value.type == 'boolean' diff --git a/script-beta/core/hover/label.lua b/script-beta/core/hover/label.lua index 3b1c5d0a..7533d3f1 100644 --- a/script-beta/core/hover/label.lua +++ b/script-beta/core/hover/label.lua @@ -19,6 +19,16 @@ local function asFunction(source, oop) return table.concat(lines, '\n') end +local function asDocFunction(source) + local name = '' + local arg = buildArg(source) + local rtn = buildReturn(source) + local lines = {} + lines[1] = ('function %s(%s)'):format(name, arg) + lines[2] = rtn + return table.concat(lines, '\n') +end + local function asValue(source, title) local name = buildName(source) local infers = vm.getInfers(source) @@ -160,5 +170,7 @@ return function (source, oop) return asNumber(source) elseif source.type == 'library' then return asLibrary(source) + elseif source.type == 'doc.type.function' then + return asDocFunction(source) end end diff --git a/script-beta/core/hover/return.lua b/script-beta/core/hover/return.lua index d42ee5b2..6b0fdb0b 100644 --- a/script-beta/core/hover/return.lua +++ b/script-beta/core/hover/return.lua @@ -120,6 +120,22 @@ local function asFunction(source) return table.concat(returns, '\n') end +local function asDocFunction(source) + if not source.returns then + return '' + end + local returns = {} + for i, rtn in ipairs(source.returns) do + local rtnText = vm.getInferType(rtn) + if i == 1 then + returns[#returns+1] = (' -> %s'):format(rtnText) + else + returns[#returns+1] = ('% 3d. %s'):format(i, rtnText) + end + end + return table.concat(returns, '\n') +end + return function (source) if source.type == 'library' then return asLibrary(source.value) @@ -129,4 +145,7 @@ return function (source) if source.type == 'function' then return asFunction(source) end + if source.type == 'doc.type.function' then + return asDocFunction(source) + end end diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua index 4c18a695..dec29ca0 100644 --- a/script-beta/parser/guide.lua +++ b/script-beta/parser/guide.lua @@ -3303,6 +3303,15 @@ local function mergeFunctionReturns(status, source, index, call) end end +local function mergeDocTypeFunctionReturns(status, source, index) + if not source.bindDocs then + return + end + for _, doc in ipairs(source.bindDocs) do + + end +end + function m.inferByCallReturnAndIndex(status, call, index) local node = call.node local newStatus = m.status(nil, status.interface) @@ -3317,6 +3326,7 @@ function m.inferByCallReturnAndIndex(status, call, index) end end end + mergeDocTypeFunctionReturns(status, src, index) end end |