diff options
-rw-r--r-- | script/files.lua | 15 | ||||
-rw-r--r-- | script/provider/provider.lua | 12 |
2 files changed, 23 insertions, 4 deletions
diff --git a/script/files.lua b/script/files.lua index c21cd211..aefdbd4a 100644 --- a/script/files.lua +++ b/script/files.lua @@ -59,7 +59,9 @@ end function m.open(uri) local originUri = uri uri = getUriKey(uri) - m.openMap[uri] = true + m.openMap[uri] = { + cache = {}, + } m.onWatch('open', originUri) end @@ -81,7 +83,16 @@ end ---@return boolean function m.isOpen(uri) uri = getUriKey(uri) - return m.openMap[uri] == true + return m.openMap[uri] ~= nil +end + +function m.getOpenedCache(uri) + uri = getUriKey(uri) + local data = m.openMap[uri] + if not data then + return nil + end + return data.cache end --- 标记为库文件 diff --git a/script/provider/provider.lua b/script/provider/provider.lua index ac167867..e90bbeff 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -758,8 +758,16 @@ proto.on('textDocument/semanticTokens/range', function (params) local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_SEMANTIC_RANGE, 0.5) local core = require 'core.semantic-tokens' local uri = params.textDocument.uri - local start = files.offsetOfWord(uri, params.range.start) - local finish = files.offsetOfWord(uri, params.range['end']) + local cache = files.getOpenedCache(uri) + local start, finish + if cache and not cache['firstSemantic'] then + cache['firstSemantic'] = true + start = 0 + finish = #files.getText(uri) + else + start = files.offsetOfWord(uri, params.range.start) + finish = files.offsetOfWord(uri, params.range['end']) + end local results = core(uri, start, finish) return { data = results |