diff options
author | sumneko <sumneko@hotmail.com> | 2021-11-25 00:19:42 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2021-11-25 00:19:42 +0800 |
commit | 8a4e2274e25d005a2c9e30512105b3a5e527b8df (patch) | |
tree | 3c4513b97901c07adf3fa227249721c02482ad9a | |
parent | 3b7f8cee482d4980a4d0d5ec8fde3b76337a1a50 (diff) | |
parent | 35ecea910789fbd470d0c6d68b75409ac3c3e21e (diff) | |
download | lua-language-server-8a4e2274e25d005a2c9e30512105b3a5e527b8df.zip |
Merge remote-tracking branch 'origin/bugfix'
-rw-r--r-- | changelog.md | 5 | ||||
-rw-r--r-- | script/core/searcher.lua | 7 | ||||
-rw-r--r-- | script/files.lua | 29 | ||||
-rw-r--r-- | script/provider/provider.lua | 47 | ||||
-rw-r--r-- | script/text-merger.lua | 15 | ||||
-rw-r--r-- | test/basic/textmerger.lua | 5 | ||||
-rw-r--r-- | test/crossfile/hover.lua | 23 |
7 files changed, 94 insertions, 37 deletions
diff --git a/changelog.md b/changelog.md index 6acc14a8..9392b263 100644 --- a/changelog.md +++ b/changelog.md @@ -30,6 +30,11 @@ * `CHG` skip huge files (>= 10 MB) * `CHG` after using `Lua.runtime.nonstandardSymbol` to treat `//` as a comment, `//` is no longer parsed as an operator +## 2.4.11 +* `FIX` [#817](https://github.com/sumneko/lua-language-server/issues/817) +* `FIX` [#818](https://github.com/sumneko/lua-language-server/issues/818) +* `FIX` [#820](https://github.com/sumneko/lua-language-server/issues/820) + ## 2.4.10 `2021-11-23` * `FIX` [#790](https://github.com/sumneko/lua-language-server/issues/790) diff --git a/script/core/searcher.lua b/script/core/searcher.lua index 6d1a03b6..e5de6395 100644 --- a/script/core/searcher.lua +++ b/script/core/searcher.lua @@ -786,6 +786,13 @@ function m.searchRefsByID(status, suri, expect, mode) end elseif mode == 'field' or mode == 'allfield' then + for _, guri in ceach('def:' .. id) do + if uri == guri then + goto CONTINUE + end + searchID(guri, id, field, uri) + ::CONTINUE:: + end for _, guri in ceach('field:' .. id) do if uri == guri then goto CONTINUE diff --git a/script/files.lua b/script/files.lua index a779f0f6..d5344847 100644 --- a/script/files.lua +++ b/script/files.lua @@ -1,4 +1,5 @@ local platform = require 'bee.platform' +local fs = require 'bee.filesystem' local config = require 'config' local glob = require 'glob' local furi = require 'file-uri' @@ -29,6 +30,33 @@ m.fileCount = 0 m.astCount = 0 m.astMap = {} -- setmetatable({}, { __mode = 'v' }) +local fixedUri = {} +--- 获取文件的真实uri(真实大小写) +---@param uri uri +---@return uri +function m.getRealUri(uri) + if platform.OS ~= 'Windows' then + return uri + end + local filename = furi.decode(uri) + local path = fs.path(filename) + local suc, res = pcall(fs.exists, path) + if not suc or not res then + return uri + end + suc, res = pcall(fs.canonical, path) + if not suc or res:string() == filename then + return uri + end + filename = res:string() + local ruri = furi.encode(filename) + if not fixedUri[ruri] then + fixedUri[ruri] = true + log.warn(('Fix real file uri: %s -> %s'):format(uri, ruri)) + end + return ruri +end + --- 打开文件 ---@param uri uri function m.open(uri) @@ -156,6 +184,7 @@ function m.setText(uri, text, isTrust, version) file.text = newText file.trusted = isTrust file.originText = text + file.rows = nil file.words = nil m.astMap[uri] = nil file.cache = {} diff --git a/script/provider/provider.lua b/script/provider/provider.lua index 08d3a719..7f025f78 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -208,7 +208,7 @@ m.register 'textDocument/didOpen' { function (params) workspace.awaitReady() local doc = params.textDocument - local uri = doc.uri + local uri = files.getRealUri(doc.uri) local text = doc.text log.debug('didOpen', uri) files.setText(uri, text, true) @@ -219,7 +219,7 @@ m.register 'textDocument/didOpen' { m.register 'textDocument/didClose' { function (params) local doc = params.textDocument - local uri = doc.uri + local uri = files.getRealUri(doc.uri) log.debug('didClose', uri) files.close(uri) if not files.isLua(uri) then @@ -234,10 +234,13 @@ m.register 'textDocument/didChange' { workspace.awaitReady() local doc = params.textDocument local changes = params.contentChanges - local uri = doc.uri + local uri = files.getRealUri(doc.uri) --log.debug('changes', util.dump(changes)) - local text = tm(uri, changes) - files.setText(uri, text, true, doc.version) + local text = files.getOriginText(uri) or '' + local rows = files.getCachedRows(uri) + text, rows = tm(text, rows, changes) + files.setText(uri, text, true) + files.setCachedRows(uri, rows) end } @@ -246,7 +249,7 @@ m.register 'textDocument/hover' { ---@async function (params) local doc = params.textDocument - local uri = doc.uri + local uri = files.getRealUri(doc.uri) if not workspace.isReady() then local count, max = workspace.getLoadProcess() return { @@ -283,7 +286,7 @@ m.register 'textDocument/definition' { workspace.awaitReady() local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_DEFINITION, 0.5) local core = require 'core.definition' - local uri = params.textDocument.uri + local uri = files.getRealUri(params.textDocument.uri) if not files.exists(uri) then return nil end @@ -322,7 +325,7 @@ m.register 'textDocument/typeDefinition' { workspace.awaitReady() local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_TYPE_DEFINITION, 0.5) local core = require 'core.type-definition' - local uri = params.textDocument.uri + local uri = files.getRealUri(params.textDocument.uri) if not files.exists(uri) then return nil end @@ -361,7 +364,7 @@ m.register 'textDocument/references' { workspace.awaitReady() local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_REFERENCE, 0.5) local core = require 'core.reference' - local uri = params.textDocument.uri + local uri = files.getRealUri(params.textDocument.uri) if not files.exists(uri) then return nil end @@ -385,7 +388,7 @@ m.register 'textDocument/documentHighlight' { abortByFileUpdate = true, function (params) local core = require 'core.highlight' - local uri = params.textDocument.uri + local uri = files.getRealUri(params.textDocument.uri) if not files.exists(uri) then return nil end @@ -412,7 +415,7 @@ m.register 'textDocument/rename' { workspace.awaitReady() local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_RENAME, 0.5) local core = require 'core.rename' - local uri = params.textDocument.uri + local uri = files.getRealUri(params.textDocument.uri) if not files.exists(uri) then return nil end @@ -440,7 +443,7 @@ m.register 'textDocument/prepareRename' { abortByFileUpdate = true, function (params) local core = require 'core.rename' - local uri = params.textDocument.uri + local uri = files.getRealUri(params.textDocument.uri) if not files.exists(uri) then return nil end @@ -459,7 +462,7 @@ m.register 'textDocument/prepareRename' { m.register 'textDocument/completion' { ---@async function (params) - local uri = params.textDocument.uri + local uri = files.getRealUri(params.textDocument.uri) if not workspace.isReady() then local count, max = workspace.getLoadProcess() return { @@ -617,7 +620,7 @@ m.register 'textDocument/signatureHelp' { end workspace.awaitReady() local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_SIGNATURE, 0.5) - local uri = params.textDocument.uri + local uri = files.getRealUri(params.textDocument.uri) if not files.exists(uri) then return nil end @@ -661,7 +664,7 @@ m.register 'textDocument/documentSymbol' { workspace.awaitReady() local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_SYMBOL, 0.5) local core = require 'core.document-symbol' - local uri = params.textDocument.uri + local uri = files.getRealUri(params.textDocument.uri) local symbols = core(uri) if not symbols then @@ -704,7 +707,7 @@ m.register 'textDocument/codeAction' { abortByFileUpdate = true, function (params) local core = require 'core.code-action' - local uri = params.textDocument.uri + local uri = files.getRealUri(params.textDocument.uri) local range = params.range local diagnostics = params.context.diagnostics if not files.exists(uri) then @@ -794,7 +797,7 @@ m.register 'textDocument/semanticTokens/full' { abortByFileUpdate = true, ---@async function (params) - local uri = params.textDocument.uri + local uri = files.getRealUri(params.textDocument.uri) workspace.awaitReady() local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_SEMANTIC_FULL, 0.5) local core = require 'core.semantic-tokens' @@ -809,7 +812,7 @@ m.register 'textDocument/semanticTokens/range' { abortByFileUpdate = true, ---@async function (params) - local uri = params.textDocument.uri + local uri = files.getRealUri(params.textDocument.uri) workspace.awaitReady() local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_SEMANTIC_RANGE, 0.5) local core = require 'core.semantic-tokens' @@ -834,7 +837,7 @@ m.register 'textDocument/foldingRange' { ---@async function (params) local core = require 'core.folding' - local uri = params.textDocument.uri + local uri = files.getRealUri(params.textDocument.uri) if not files.exists(uri) then return nil end @@ -873,7 +876,7 @@ m.register 'window/workDoneProgress/cancel' { m.register '$/didChangeVisibleRanges' { ---@async function (params) - local uri = params.uri + local uri = files.getRealUri(params.uri) await.close('visible:' .. uri) await.setID('visible:' .. uri) await.delay() @@ -906,7 +909,7 @@ m.register 'textDocument/onTypeFormatting' { workspace.awaitReady() local _ <close> = progress.create(lang.script.WINDOW_PROCESSING_TYPE_FORMATTING, 0.5) local ch = params.ch - local uri = params.textDocument.uri + local uri = files.getRealUri(params.textDocument.uri) if not files.exists(uri) then return nil end @@ -945,7 +948,7 @@ m.register '$/requestHint' { return end workspace.awaitReady() - local uri = params.textDocument.uri + local uri = files.getRealUri(params.textDocument.uri) local start, finish = converter.unpackRange(uri, params.range) local results = core(uri, start, finish) local hintResults = {} diff --git a/script/text-merger.lua b/script/text-merger.lua index ac3fd765..c3b144c3 100644 --- a/script/text-merger.lua +++ b/script/text-merger.lua @@ -99,25 +99,18 @@ local function mergeRows(rows, change) end end -return function (uri, changes) - local text +return function (text, rows, changes) for _, change in ipairs(changes) do if change.range then - local rows = files.getCachedRows(uri) - if not rows then - text = text or files.getOriginText(uri) or '' - rows = splitRows(text) - end + rows = rows or splitRows(text) mergeRows(rows, change) - files.setCachedRows(uri, rows) else - files.setCachedRows(uri, nil) + rows = nil text = change.text end end - local rows = files.getCachedRows(uri) if rows then text = table.concat(rows) end - return text + return text, rows end diff --git a/test/basic/textmerger.lua b/test/basic/textmerger.lua index a3a11f62..1ffd36f0 100644 --- a/test/basic/textmerger.lua +++ b/test/basic/textmerger.lua @@ -1,12 +1,9 @@ -local files = require 'files' local tm = require 'text-merger' local function TEST(source) return function (expect) return function (changes) - files.removeAll() - files.setText('', source) - local text = tm('', changes) + local text = tm(source, nil, changes) assert(text == expect) end end diff --git a/test/crossfile/hover.lua b/test/crossfile/hover.lua index f23850a5..5c1ad130 100644 --- a/test/crossfile/hover.lua +++ b/test/crossfile/hover.lua @@ -1052,3 +1052,26 @@ end local x: any ```]] } + +TEST { + { + path = 'a.lua', + content = [[ +---@class A +---@field x number +G = {} +]], + }, + { + path = 'b.lua', + content = [[ +<?G?> +]], + }, + hover = [[ +```lua +global G: A { + x: number, +} +```]] +} |