From 8aa74ec3f8993d2a5b051f68e95b84884b6e1ac9 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Thu, 19 Nov 2026 17:01:37 +0000 Subject: [PATCH] Tell interface files from implementation files again in editor analysis MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Why: Since #8436, `Uri.is_interface` passes its arguments to `Filename.check_suffix` in the wrong order, so it always returns false. Editor analysis then pairs a `.resi` declaration with itself instead of with its `.res` side: references list the `.resi` location twice and miss the `.res` one, rename edits the `.resi` twice and leaves the `.res` unchanged, and go to definition from a `.resi` declaration stays in the interface. References modified (a value with an interface): Example: // ReferencesWithInterface.res let x = 2 // ReferencesWithInterface.resi let x: int Before (text): references of x from the .resi … ReferencesWithInterface.resi 0:4 ReferencesWithInterface.resi 0:4 After (text): references of x from the .resi … ReferencesWithInterface.resi 0:4 ReferencesWithInterface.res 0:4 Definition modified (from a declaration in a .resi): Before (text): tests/analysis_tests/tests/src/DefinitionWithInterface.resi DefinitionWithInterface.resi After (text): tests/analysis_tests/tests/src/DefinitionWithInterface.resi DefinitionWithInterface.res Review: Why `String.ends_with ~suffix:Literals.suffix_resi`? Its labeled argument cannot be swapped the way the positional arguments of `Filename.check_suffix` were, and the compiler's `.resi` constant says what is meant. It tests the URI's path (`Lsp.Uri.to_path`), which ignores query and fragment, instead of the whole encoded URI. `Shared_types.get_cmt_path`, which picks the `.cmti` for an interface URI, had its own copy of the test and now calls `Uri.is_interface`. Review: Which snapshots change? Cross, DefinitionWithInterface.resi, Jsx2, References, ReferencesWithInterface.resi and RenameWithInterface.resi: each duplicate `.resi` entry becomes the `.res` entry, and definitions from a `.resi` reach the implementation, as they did before #8436. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Kbf3gGbYDy2DBe5YmGdHTL Signed-off-by: Christoph Knittel --- analysis/src/shared_types.ml | 4 +--- analysis/src/uri.ml | 3 ++- changes/editor-interface-file-check.fix.md | 1 + .../tests/src/expected/Cross.res.txt | 22 +++++++++++++------ .../expected/DefinitionWithInterface.resi.txt | 8 +++---- .../tests/src/expected/Jsx2.res.txt | 2 +- .../tests/src/expected/References.res.txt | 2 +- .../expected/ReferencesWithInterface.resi.txt | 2 +- .../src/expected/RenameWithInterface.resi.txt | 12 ++++++++-- 9 files changed, 36 insertions(+), 20 deletions(-) create mode 100644 changes/editor-interface-file-check.fix.md diff --git a/analysis/src/shared_types.ml b/analysis/src/shared_types.ml index f376f000d1a..4378978a54b 100644 --- a/analysis/src/shared_types.ml +++ b/analysis/src/shared_types.ml @@ -430,9 +430,7 @@ let get_cmt_path ~uri p = match p with | Impl {cmt} -> cmt | Namespace {cmt} -> cmt - | IntfAndImpl {cmti; cmt} -> - let interface = String.ends_with ~suffix:"i" (Uri.to_path uri) in - if interface then cmti else cmt + | IntfAndImpl {cmti; cmt} -> if Uri.is_interface uri then cmti else cmt module Tip = struct type t = Value | Type | Field of string | Constructor of string | Module diff --git a/analysis/src/uri.ml b/analysis/src/uri.ml index 143b97c8fbd..edceb82213f 100644 --- a/analysis/src/uri.ml +++ b/analysis/src/uri.ml @@ -4,7 +4,8 @@ let strip_path = ref false (* for use in tests *) let from_path path = Lsp.Uri.of_path path let from_string str = Lsp.Uri.of_string str -let is_interface uri = uri |> Lsp.Uri.to_string |> Filename.check_suffix "i" +let is_interface uri = + Lsp.Uri.to_path uri |> String.ends_with ~suffix:Literals.suffix_resi let to_path uri = (* Lsp.Uri.to_path remove the schema file:// but keep the `/` on start of path. *) let p = Lsp.Uri.to_path uri in diff --git a/changes/editor-interface-file-check.fix.md b/changes/editor-interface-file-check.fix.md new file mode 100644 index 00000000000..43e0cd5250a --- /dev/null +++ b/changes/editor-interface-file-check.fix.md @@ -0,0 +1 @@ +- Find References and Rename no longer list a value of a `.resi` file twice and miss its `.res` side, and go to definition from a `.resi` declaration opens the implementation again. diff --git a/tests/analysis_tests/tests/src/expected/Cross.res.txt b/tests/analysis_tests/tests/src/expected/Cross.res.txt index 76e18caf18a..fea0c190188 100644 --- a/tests/analysis_tests/tests/src/expected/Cross.res.txt +++ b/tests/analysis_tests/tests/src/expected/Cross.res.txt @@ -126,7 +126,15 @@ Rename src/Cross.res 21:28 xPrime "end": { "character": 5, "line": 0 }, "start": { "character": 4, "line": 0 } } - }, + } + ], + "textDocument": { + "uri": "file:///RenameWithInterface.resi", + "version": 0 + } + }, + { + "edits": [ { "newText": "xPrime", "range": { @@ -136,7 +144,7 @@ Rename src/Cross.res 21:28 xPrime } ], "textDocument": { - "uri": "file:///RenameWithInterface.resi", + "uri": "file:///RenameWithInterface.res", "version": 0 } }, @@ -176,7 +184,7 @@ Definition src/Cross.res 27:32 "end": { "character": 5, "line": 0 }, "start": { "character": 4, "line": 0 } }, - "uri": "file:///DefinitionWithInterface.resi" + "uri": "file:///DefinitionWithInterface.res" } Definition src/Cross.res 30:36 @@ -185,7 +193,7 @@ Definition src/Cross.res 30:36 "end": { "character": 6, "line": 3 }, "start": { "character": 5, "line": 3 } }, - "uri": "file:///DefinitionWithInterface.resi" + "uri": "file:///DefinitionWithInterface.res" } TypeDefinition src/Cross.res 33:37 @@ -210,9 +218,9 @@ Path DefinitionWithInterface.a Definition src/Cross.res 39:39 { "range": { - "end": { "character": 12, "line": 6 }, - "start": { "character": 2, "line": 6 } + "end": { "character": 7, "line": 9 }, + "start": { "character": 6, "line": 9 } }, - "uri": "file:///DefinitionWithInterface.resi" + "uri": "file:///DefinitionWithInterface.res" } diff --git a/tests/analysis_tests/tests/src/expected/DefinitionWithInterface.resi.txt b/tests/analysis_tests/tests/src/expected/DefinitionWithInterface.resi.txt index e6f9264f2ce..3db63ec2b03 100644 --- a/tests/analysis_tests/tests/src/expected/DefinitionWithInterface.resi.txt +++ b/tests/analysis_tests/tests/src/expected/DefinitionWithInterface.resi.txt @@ -4,15 +4,15 @@ Definition src/DefinitionWithInterface.resi 0:4 "end": { "character": 5, "line": 0 }, "start": { "character": 4, "line": 0 } }, - "uri": "file:///DefinitionWithInterface.resi" + "uri": "file:///DefinitionWithInterface.res" } Definition src/DefinitionWithInterface.resi 6:6 { "range": { - "end": { "character": 12, "line": 6 }, - "start": { "character": 2, "line": 6 } + "end": { "character": 7, "line": 9 }, + "start": { "character": 6, "line": 9 } }, - "uri": "file:///DefinitionWithInterface.resi" + "uri": "file:///DefinitionWithInterface.res" } diff --git a/tests/analysis_tests/tests/src/expected/Jsx2.res.txt b/tests/analysis_tests/tests/src/expected/Jsx2.res.txt index 57e0fa331e5..c980c563349 100644 --- a/tests/analysis_tests/tests/src/expected/Jsx2.res.txt +++ b/tests/analysis_tests/tests/src/expected/Jsx2.res.txt @@ -164,7 +164,7 @@ Definition src/Jsx2.res 58:11 "end": { "character": 8, "line": 1 }, "start": { "character": 4, "line": 1 } }, - "uri": "file:///Component.resi" + "uri": "file:///Component.res" } Complete src/Jsx2.res 68:10 diff --git a/tests/analysis_tests/tests/src/expected/References.res.txt b/tests/analysis_tests/tests/src/expected/References.res.txt index de784200433..dd867386771 100644 --- a/tests/analysis_tests/tests/src/expected/References.res.txt +++ b/tests/analysis_tests/tests/src/expected/References.res.txt @@ -108,7 +108,7 @@ References src/References.res 23:15 "end": { "character": 8, "line": 1 }, "start": { "character": 4, "line": 1 } }, - "uri": "file:///ComponentInner.resi" + "uri": "file:///ComponentInner.res" }, { "range": { diff --git a/tests/analysis_tests/tests/src/expected/ReferencesWithInterface.resi.txt b/tests/analysis_tests/tests/src/expected/ReferencesWithInterface.resi.txt index 29dbae2b2bd..a621bd81525 100644 --- a/tests/analysis_tests/tests/src/expected/ReferencesWithInterface.resi.txt +++ b/tests/analysis_tests/tests/src/expected/ReferencesWithInterface.resi.txt @@ -26,7 +26,7 @@ References src/ReferencesWithInterface.resi 0:4 "end": { "character": 5, "line": 0 }, "start": { "character": 4, "line": 0 } }, - "uri": "file:///ReferencesWithInterface.resi" + "uri": "file:///ReferencesWithInterface.res" }, { "range": { diff --git a/tests/analysis_tests/tests/src/expected/RenameWithInterface.resi.txt b/tests/analysis_tests/tests/src/expected/RenameWithInterface.resi.txt index dc259e411ae..f9050b485b8 100644 --- a/tests/analysis_tests/tests/src/expected/RenameWithInterface.resi.txt +++ b/tests/analysis_tests/tests/src/expected/RenameWithInterface.resi.txt @@ -8,7 +8,15 @@ Rename src/RenameWithInterface.resi 0:4 y "end": { "character": 5, "line": 0 }, "start": { "character": 4, "line": 0 } } - }, + } + ], + "textDocument": { + "uri": "file:///RenameWithInterface.resi", + "version": 0 + } + }, + { + "edits": [ { "newText": "y", "range": { @@ -18,7 +26,7 @@ Rename src/RenameWithInterface.resi 0:4 y } ], "textDocument": { - "uri": "file:///RenameWithInterface.resi", + "uri": "file:///RenameWithInterface.res", "version": 0 } },