diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-11-04 17:28:42 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-11-04 17:28:42 +0800 |
commit | 137ede024f4ddeac7c602351371447cd6cf36091 (patch) | |
tree | bff1d78ec63125294bf9337a192902f706db731a /server-beta/src/proto/define.lua | |
parent | eb1fffc9ddfaa804973b1e05c7001d84194ce5a6 (diff) | |
download | lua-language-server-137ede024f4ddeac7c602351371447cd6cf36091.zip |
更新诊断
Diffstat (limited to 'server-beta/src/proto/define.lua')
-rw-r--r-- | server-beta/src/proto/define.lua | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/server-beta/src/proto/define.lua b/server-beta/src/proto/define.lua new file mode 100644 index 00000000..9401e9e5 --- /dev/null +++ b/server-beta/src/proto/define.lua @@ -0,0 +1,109 @@ +local guide = require 'parser.guide' + +local m = {} + +--- 获取 position 对应的光标位置 +---@param lines table +---@param text string +---@param position position +---@return integer +function m.offset(lines, text, position) + local row = position.line + local start = guide.lineRange(lines, row) + local offset = utf8.offset(text, position.character + 1, start) + return offset +end + +--- 将光标位置转化为 position +---@alias position table +---@param lines table +---@param text string +---@param offset integer +---@return position +function m.position(lines, text, offset) + local row, col = guide.positionOf(lines, offset) + local start = guide.lineRange(lines, row) + local ucol = utf8.len(text, start + 1, start + col, true) + return { + line = row, + character = ucol, + } +end + +--- 将2个光标位置转化为 range +---@alias range table +---@param lines table +---@param text string +---@param offset1 integer +---@param offset2 integer +function m.range(lines, text, offset1, offset2) + return { + start = m.position(lines, text, offset1), + ['end'] = m.position(lines, text, offset2), + } +end + +---@alias location table +---@param uri string +---@param range range +---@return location +function m.location(uri, range) + return { + uri = uri, + range = range, + } +end + +---@alias locationLink table +---@param uri string +---@param range range +---@param selection range +---@param origin range +function m.locationLink(uri, range, selection, origin) + return { + targetUri = uri, + targetRange = range, + targetSelectionRange = selection, + originSelectionRange = origin, + } +end + +--- 诊断等级 +m.DiagnosticSeverity = { + Error = 1, + Warning = 2, + Information = 3, + Hint = 4, +} + +--- 诊断类型与默认等级 +m.DiagnosticDefaultSeverity = { + ['unused-local'] = 'Hint', + ['unused-function'] = 'Hint', + ['undefined-global'] = 'Warning', + ['global-in-nil-env'] = 'Warning', + ['unused-label'] = 'Hint', + ['unused-vararg'] = 'Hint', + ['trailing-space'] = 'Hint', + ['redefined-local'] = 'Hint', + ['newline-call'] = 'Information', + ['newfield-call'] = 'Warning', + ['redundant-parameter'] = 'Hint', + ['ambiguity-1'] = 'Warning', + ['lowercase-global'] = 'Information', + ['undefined-env-child'] = 'Information', + ['duplicate-index'] = 'Warning', + ['duplicate-method'] = 'Warning', + ['empty-block'] = 'Hint', + ['redundant-value'] = 'Hint', + ['emmy-lua'] = 'Warning', + ['set-const'] = 'Error', +} + +--- 诊断报告标签 +m.DiagnosticTag = { + Unnecessary = 1, + Deprecated = 2, +} + +return m |