summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog.md1
-rw-r--r--script/core/reference.lua8
-rw-r--r--script/provider/provider.lua2
-rw-r--r--script/vm/operator.lua7
-rw-r--r--test/crossfile/references.lua2
-rw-r--r--test/references/init.lua2
6 files changed, 16 insertions, 6 deletions
diff --git a/changelog.md b/changelog.md
index 50972610..87086803 100644
--- a/changelog.md
+++ b/changelog.md
@@ -93,6 +93,7 @@ server will generate `doc.json` and `doc.md` in `LOGPATH`.
end
end
```
+* `CHG` find reference: respect `includeDeclaration` (although I don't know how to turn off this option in VSCode)
* `FIX` [#1567]
* `FIX` [#1593]
* `FIX` [#1595]
diff --git a/script/core/reference.lua b/script/core/reference.lua
index c1d99ed9..b338e9ec 100644
--- a/script/core/reference.lua
+++ b/script/core/reference.lua
@@ -55,7 +55,10 @@ local accept = {
}
---@async
-return function (uri, position)
+---@param uri uri
+---@param position integer
+---@param includeDeclaration boolean
+return function (uri, position, includeDeclaration)
local ast = files.getState(uri)
if not ast then
return nil
@@ -82,6 +85,9 @@ return function (uri, position)
if src.type == 'self' then
goto CONTINUE
end
+ if not includeDeclaration and guide.isSet(src) then
+ goto CONTINUE
+ end
src = src.field or src.method or src
if src.type == 'getindex'
or src.type == 'setindex'
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index 7386ded0..8e99b354 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -484,7 +484,7 @@ m.register 'textDocument/references' {
end
local core = require 'core.reference'
local pos = converter.unpackPosition(state, params.position)
- local result = core(uri, pos)
+ local result = core(uri, pos, params.context.includeDeclaration)
if not result then
return nil
end
diff --git a/script/vm/operator.lua b/script/vm/operator.lua
index 9dea01c1..015eba38 100644
--- a/script/vm/operator.lua
+++ b/script/vm/operator.lua
@@ -273,7 +273,7 @@ vm.binarySwitch = util.switch()
or op == '//' and a // b
or op == '^' and a ^ b
vm.setNode(source, {
- type = math.type(result) == 'integer' and 'integer' or 'number',
+ type = (op == '//' or math.type(result) == 'integer') and 'integer' or 'number',
start = source.start,
finish = source.finish,
parent = source,
@@ -288,7 +288,6 @@ vm.binarySwitch = util.switch()
if op == '+'
or op == '-'
or op == '*'
- or op == '//'
or op == '%' then
local uri = guide.getUri(source)
local infer1 = vm.getInfer(source[1])
@@ -302,6 +301,10 @@ vm.binarySwitch = util.switch()
end
end
end
+ if op == '//' then
+ vm.setNode(source, node or vm.declareGlobal('type', 'integer'))
+ return
+ end
vm.setNode(source, node or vm.declareGlobal('type', 'number'))
end
end)
diff --git a/test/crossfile/references.lua b/test/crossfile/references.lua
index 1a9f2508..22b13f42 100644
--- a/test/crossfile/references.lua
+++ b/test/crossfile/references.lua
@@ -83,7 +83,7 @@ function TEST(datas)
end
local sourcePos = (sourceList[1][1] + sourceList[1][2]) // 2
- local positions = core(sourceUri, sourcePos)
+ local positions = core(sourceUri, sourcePos, true)
if positions then
local result = {}
for i, position in ipairs(positions) do
diff --git a/test/references/init.lua b/test/references/init.lua
index eee0ac61..3ecc46bd 100644
--- a/test/references/init.lua
+++ b/test/references/init.lua
@@ -25,7 +25,7 @@ function TEST(script)
local input = catched['?'] + catched['~']
local expect = catched['!'] + catched['~']
- local results = core(TESTURI, input[1][1])
+ local results = core(TESTURI, input[1][1], true)
if results then
local positions = {}
for i, result in ipairs(results) do