diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-03-05 18:25:43 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-03-05 18:25:43 +0800 |
commit | 49ae0b9abc5e9ddaebda9da9fc41341ba1576e66 (patch) | |
tree | 46ab0b41097e763c59d14064af86997469e97e42 /script/vm | |
parent | 26138568cd004fa922f0aa7d96052ebd28ca63ee (diff) | |
download | lua-language-server-49ae0b9abc5e9ddaebda9da9fc41341ba1576e66.zip |
stash
Diffstat (limited to 'script/vm')
-rw-r--r-- | script/vm/getDocs.lua | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/script/vm/getDocs.lua b/script/vm/getDocs.lua index e5a6d865..05ecfdd3 100644 --- a/script/vm/getDocs.lua +++ b/script/vm/getDocs.lua @@ -238,3 +238,84 @@ function vm.isDeprecated(value, deep) return isDeprecated(value) end end + +local function makeDiagRange(uri, doc, results) + local lines = files.getLines(uri) + local names + if doc.names then + names = {} + for i, nameUnit in ipairs(doc.names) do + names[i] = nameUnit[1] + end + end + local row = guide.positionOf(lines, doc.start) + if doc.mode == 'disable-next-line' then + if lines[row+1] then + results[#results+1] = { + mode = 'disable', + names = names, + offset = lines[row+1].start, + source = doc, + } + results[#results+1] = { + mode = 'enable', + names = names, + offset = lines[row+1].finish, + source = doc, + } + end + elseif doc.mode == 'disable-line' then + results[#results+1] = { + mode = 'disable', + names = names, + offset = lines[row].start, + source = doc, + } + results[#results+1] = { + mode = 'enable', + names = names, + offset = lines[row].finish, + source = doc, + } + elseif doc.mode == 'disable' then + if lines[row+1] then + results[#results+1] = { + mode = 'disable', + names = names, + offset = lines[row+1].start, + source = doc, + } + end + elseif doc.mode == 'enable' then + if lines[row+1] then + results[#results+1] = { + mode = 'enable', + names = names, + offset = lines[row+1].start, + source = doc, + } + end + end +end + +function vm.isDiagDisabledAt(uri, offset, name) + local status = files.getAst(uri) + if not status then + return false + end + if not status.ast.docs then + return false + end + local cache = files.getCache(uri) + if not cache.diagnosticRanges then + cache.diagnosticRanges = {} + for _, doc in ipairs(status.ast.docs) do + if doc.type == 'doc.diagnostic' then + makeDiagRange(uri, doc, cache.diagnosticRanges) + end + end + table.sort(cache.diagnosticRanges, function (a, b) + return a.offset < b.offset + end) + end +end |