From fdab3eaed0f5e3e85252d5126e1f1927b633c80d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= <sumneko@hotmail.com>
Date: Mon, 23 Aug 2021 11:41:41 +0800
Subject: [PATCH] resolve #645 only search first file by `require`

---
 changelog.md                  |  1 +
 script/core/searcher.lua      |  1 +
 test/crossfile/definition.lua | 22 ++++++++++++++--------
 3 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/changelog.md b/changelog.md
index 492e79cc9..ed39ed42f 100644
--- a/changelog.md
+++ b/changelog.md
@@ -9,6 +9,7 @@
 * `CHG` hover: improve showing multi defines
 * `CHG` hover: improve showing multi comments at enums
 * `CHG` hint: `Lua.hint.paramName` now supports `Disable`, `Literal` and `All`
+* `CHG` only search first file by `require`
 * `CHG` no longer ignore file names case in Windows
 * `CHG` watching library changes
 * `FIX` runtime errors
diff --git a/script/core/searcher.lua b/script/core/searcher.lua
index e75293f1b..108a9c37f 100644
--- a/script/core/searcher.lua
+++ b/script/core/searcher.lua
@@ -753,6 +753,7 @@ function m.searchRefsByID(status, suri, expect, mode)
             local ruri = uris[i]
             if uri ~= ruri then
                 searchID(ruri, 'mainreturn', field, uri)
+                break
             end
         end
     end
diff --git a/test/crossfile/definition.lua b/test/crossfile/definition.lua
index 749231838..66e9b2693 100644
--- a/test/crossfile/definition.lua
+++ b/test/crossfile/definition.lua
@@ -834,18 +834,24 @@ TEST {
     {
         path = 'a.lua',
         content = [[
----@type Class
-local m
-m.<!xx!> = 1
-        ]]
+return {
+    <!x!> = 1,
+}
+]],
+    },
+    {
+        path = 'f/a.lua',
+        content = [[
+return {
+    x = 1,
+}
+]]
     },
     {
         path = 'b.lua',
         content = [[
----@class Class
-local m
-
-print(m.<?xx?>)
+local t = require 'a'
+print(t.<?x?>)
         ]]
     }
 }
-- 
GitLab