diff options
-rw-r--r-- | locale/en-us/script.lua | 1 | ||||
-rw-r--r-- | locale/zh-cn/script.lua | 1 | ||||
-rw-r--r-- | script/config.lua | 3 | ||||
-rw-r--r-- | script/core/type-hint.lua | 2 | ||||
-rw-r--r-- | script/provider/provider.lua | 35 |
5 files changed, 25 insertions, 17 deletions
diff --git a/locale/en-us/script.lua b/locale/en-us/script.lua index 07cc15be..6265f608 100644 --- a/locale/en-us/script.lua +++ b/locale/en-us/script.lua @@ -200,6 +200,7 @@ WINDOW_PROCESSING_SYMBOL = 'Processing file symbols...' WINDOW_PROCESSING_WS_SYMBOL = 'Processing workspace symbols...' WINDOW_PROCESSING_SEMANTIC_FULL = 'Processing full semantic tokens...' WINDOW_PROCESSING_SEMANTIC_RANGE = 'Processing incremental semantic tokens...' +WINDOW_PROCESSING_TYPE_HINT = 'Processing type hint...' WINDOW_INCREASE_UPPER_LIMIT = 'Increase upper limit' WINDOW_CLOSE = 'Close' WINDOW_SETTING_WS_DIAGNOSTIC = 'You can delay or disable workspace diagnostics in settings' diff --git a/locale/zh-cn/script.lua b/locale/zh-cn/script.lua index 57b84cde..18a8168b 100644 --- a/locale/zh-cn/script.lua +++ b/locale/zh-cn/script.lua @@ -199,6 +199,7 @@ WINDOW_PROCESSING_SYMBOL = '正在处理文件符号...' WINDOW_PROCESSING_WS_SYMBOL = '正在处理工作区符号...' WINDOW_PROCESSING_SEMANTIC_FULL = '正在处理全量语义着色...' WINDOW_PROCESSING_SEMANTIC_RANGE = '正在处理差量语义着色...' +WINDOW_PROCESSING_TYPE_HINT = '正在处理类型提示...' WINDOW_INCREASE_UPPER_LIMIT = '增加上限' WINDOW_CLOSE = '关闭' WINDOW_SETTING_WS_DIAGNOSTIC = '你可以在设置中延迟或禁用工作目录诊断' diff --git a/script/config.lua b/script/config.lua index 1711052f..dcae15b4 100644 --- a/script/config.lua +++ b/script/config.lua @@ -154,6 +154,9 @@ local ConfigTemplate = { color = { mode = {'Semantic', String}, }, + typeHint = { + enable = {true, Boolean}, + }, intelliSense = { searchDepth = {0, Integer}, }, diff --git a/script/core/type-hint.lua b/script/core/type-hint.lua index ef2d7d08..9e717f14 100644 --- a/script/core/type-hint.lua +++ b/script/core/type-hint.lua @@ -33,7 +33,7 @@ return function (uri, start, finish) end edits[#edits+1] = { newText = (':%s'):format(infer), - start = src.finish, + start = src.finish + 1, finish = src.finish, } end) diff --git a/script/provider/provider.lua b/script/provider/provider.lua index 6c042f7a..be9b6fc9 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -736,23 +736,26 @@ proto.on('$/didChangeVisibleRanges', function (params) end -- compute type-hint - for _, range in ipairs(params.ranges) do - local start, finish = files.unrange(uri, range) - local piece = typeHint(uri, start, finish) - if piece then - for _, edit in ipairs(piece) do - edits[#edits+1] = { - newText = edit.newText, - range = files.range(uri, edit.start, edit.finish) - } + if config.config.typeHint.enable then + local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_TYPE_HINT, 0.5) + for _, range in ipairs(params.ranges) do + local start, finish = files.unrange(uri, range) + local piece = typeHint(uri, start, finish) + if piece then + for _, edit in ipairs(piece) do + edits[#edits+1] = { + newText = edit.newText, + range = files.range(uri, edit.start, edit.finish) + } + end end end + if #edits == 0 then + return + end + proto.notify('$/typeHint', { + uri = uri, + edits = edits, + }) end - if #edits == 0 then - return - end - proto.notify('$/typeHint', { - uri = uri, - edits = edits, - }) end) |