Skip to content

Commit a57f443

Browse files
committed
Fix issue in the calculation of struct/signature scopes.
Fixes #323 The computation of scope for a struct/signatures takes the first and last items, ignoring the fact that they could be ghost locations. In particular, using `@react.component` triggers the ppx which leaves ghost definitions at the end, making the end scope wrong.
1 parent c485964 commit a57f443

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Fix issue in JSX autocompletion where the `key` label would always appear.
99
- Fix issue in record field autocomplete not working with type aliases.
1010
- Support autocomplete of records for variables defined in other files.
11+
- Fix issue where autocomplete for local values would not work in the presence of `@react.component` annotations.
1112

1213
## 1.1.3
1314

analysis/src/ProcessCmt.ml

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ open Typedtree
22
open SharedTypes
33

44
let itemsExtent items =
5+
let items = items |> List.filter (fun item -> not item.str_loc.loc_ghost) in
56
match items with
67
| [] -> Location.none
78
| first :: _ ->
@@ -18,6 +19,7 @@ let itemsExtent items =
1819
}
1920

2021
let sigItemsExtent items =
22+
let items = items |> List.filter (fun item -> not item.sig_loc.loc_ghost) in
2123
match items with
2224
| [] -> Location.none
2325
| first :: _ ->

analysis/tests/src/Completion.res

+9-1
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,12 @@ type rAlias = r
8989
let r:rAlias = assert false
9090
// ^com r.
9191

92-
// ^com Obj.Rec.recordVal.
92+
// ^com Obj.Rec.recordVal.
93+
94+
let myAmazingFunction = (x,y) => x+y
95+
96+
@react.component
97+
let make = () => {
98+
// ^com my
99+
<> </>
100+
}

analysis/tests/src/expected/Completion.res.txt

+19
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,16 @@ DocumentSymbol tests/src/Completion.res
569569
"name": "r",
570570
"kind": 13,
571571
"location": {"uri": "Completion.res", "range": {"start": {"line": 88, "character": 4}, "end": {"line": 88, "character": 5}}}
572+
},
573+
{
574+
"name": "myAmazingFunction",
575+
"kind": 12,
576+
"location": {"uri": "Completion.res", "range": {"start": {"line": 93, "character": 4}, "end": {"line": 93, "character": 21}}}
577+
},
578+
{
579+
"name": "make",
580+
"kind": 12,
581+
"location": {"uri": "Completion.res", "range": {"start": {"line": 96, "character": 4}, "end": {"line": 96, "character": 8}}}
572582
}
573583
]
574584

@@ -710,3 +720,12 @@ Complete tests/src/Completion.res 90:3
710720
"documentation": null
711721
}]
712722

723+
Complete tests/src/Completion.res 96:3
724+
[{
725+
"label": "myAmazingFunction",
726+
"kind": 12,
727+
"tags": [],
728+
"detail": "(int, int) => int",
729+
"documentation": null
730+
}]
731+

0 commit comments

Comments
 (0)