-
Notifications
You must be signed in to change notification settings - Fork 859
Narrow overload-error and symbol-use ranges to terminal identifier #19505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
1
commit into
main
Choose a base branch
from
copilot/fix-9141961-29048891-ac83c611-04a8-4bbc-9d1f-393ac1d7c4ba
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4160,14 +4160,36 @@ let private ResolveExprDotLongIdent (ncenv: NameResolver) m ad nenv ty (id: Iden | |
| | _ -> | ||
| ForceRaise adhocDotSearchAccessible | ||
|
|
||
| /// Returns a pair (itemRange, itemIdentRange): | ||
| /// | ||
| /// * `itemRange` is the structural range of the long identifier as consumed | ||
| /// by resolution — the whole-long-id span when `rest = []`, or the range | ||
| /// over the consumed prefix when `rest <> []`. This is what typed-tree | ||
| /// construction uses for expression ranges and sequence points, so we | ||
| /// never narrow it. | ||
| /// * `itemIdentRange` is the terminal identifier's own source range — the | ||
| /// piece the user perceives as "this item's name". It is used for | ||
| /// diagnostics and for sink-reported symbol ranges (Find Usages, symbol | ||
| /// highlight, FSharpSymbolUse) so error / IDE UI hits only the resolved | ||
| /// name. Fixes #14284 and #3920. | ||
| /// | ||
| /// For `T.Instance.Method("")`: | ||
| /// itemRange = `T.Instance.Method` | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @T-Gro In what cases we'd want to use this range instead of the item one? It seems that when the whole range is required, we'd usually get it from the whole expression. Do some features rely on it? |
||
| /// itemIdentRange = `Method` | ||
| let ComputeItemRange wholem (lid: Ident list) rest = | ||
| match rest with | ||
| | [] -> wholem | ||
| | _ -> | ||
| let ids = List.truncate (max 0 (lid.Length - rest.Length)) lid | ||
| match ids with | ||
| let itemRange = | ||
| match rest with | ||
| | [] -> wholem | ||
| | _ -> rangeOfLid ids | ||
| | _ -> | ||
| let ids = List.truncate (max 0 (lid.Length - rest.Length)) lid | ||
| match ids with | ||
| | [] -> wholem | ||
| | _ -> rangeOfLid ids | ||
| let itemIdentRange = | ||
| match rest, lid with | ||
| | [], _ :: _ -> (List.last lid).idRange | ||
| | _ -> itemRange | ||
| itemRange, itemIdentRange | ||
|
|
||
| /// Filters method groups that will be sent to Visual Studio IntelliSense | ||
| /// to include only static/instance members | ||
|
|
@@ -4215,7 +4237,7 @@ let ResolveLongIdentAsExprAndComputeRange (sink: TcResultsSink) (ncenv: NameReso | |
| match ResolveExprLongIdent sink ncenv wholem ad nenv typeNameResInfo lid maybeAppliedArgExpr with | ||
| | Exception e -> Exception e | ||
| | Result (tinstEnclosing, item1, rest) -> | ||
| let itemRange = ComputeItemRange wholem lid rest | ||
| let itemRange, itemIdentRange = ComputeItemRange wholem lid rest | ||
|
|
||
| let item = FilterMethodGroups ncenv itemRange item1 true | ||
|
|
||
|
|
@@ -4241,13 +4263,16 @@ let ResolveLongIdentAsExprAndComputeRange (sink: TcResultsSink) (ncenv: NameReso | |
| | Item.ActivePatternResult _ -> ItemOccurrence.Binding | ||
| | _ -> ItemOccurrence.Use | ||
|
|
||
| CallMethodGroupNameResolutionSink sink (itemRange, nenv, refinedItem, item, tpinst, occurrence, ad) | ||
| // Use the narrow terminal-identifier range for the sink so that | ||
| // FSharpSymbolUse / Find Usages / symbol-highlight surfaces report | ||
| // only on the name the user perceives as the item's name, not on | ||
| // the full long-id span. See #3920, #14284. | ||
| CallMethodGroupNameResolutionSink sink (itemIdentRange, nenv, refinedItem, item, tpinst, occurrence, ad) | ||
|
|
||
| // #16621 | ||
| match refinedItem with | ||
| | Item.Property(_, pinfos, _) -> | ||
| let propIdentRange = if rest.IsEmpty then (List.last lid).idRange else itemRange | ||
| RegisterUnionCaseTesterForProperty sink propIdentRange pinfos | ||
| RegisterUnionCaseTesterForProperty sink itemIdentRange pinfos | ||
| | _ -> () | ||
|
|
||
| let callSinkWithSpecificOverload (minfo: MethInfo, pinfoOpt: PropInfo option, tpinst) = | ||
|
|
@@ -4267,14 +4292,14 @@ let ResolveLongIdentAsExprAndComputeRange (sink: TcResultsSink) (ncenv: NameReso | |
| AfterResolution.RecordResolution(None, (fun tpinst -> callSink(item, tpinst)), callSinkWithSpecificOverload, (fun () -> callSink (item, emptyTyparInst))) | ||
|
|
||
| elif isWrongItemInExpr item then | ||
| CallNameResolutionSink sink (itemRange, nenv, item, emptyTyparInst, ItemOccurrence.InvalidUse, ad) | ||
| CallNameResolutionSink sink (itemIdentRange, nenv, item, emptyTyparInst, ItemOccurrence.InvalidUse, ad) | ||
| AfterResolution.DoNothing | ||
|
|
||
| else | ||
| callSink (item, emptyTyparInst) | ||
| AfterResolution.DoNothing | ||
|
|
||
| success (tinstEnclosing, item, itemRange, rest, afterResolution) | ||
| success (tinstEnclosing, item, itemRange, itemIdentRange, rest, afterResolution) | ||
|
|
||
| [<return: Struct>] | ||
| let (|NonOverridable|_|) namedItem = | ||
|
|
@@ -4292,11 +4317,11 @@ let ResolveExprDotLongIdentAndComputeRange (sink: TcResultsSink) (ncenv: NameRes | |
| | id :: rest -> | ||
| ResolveExprDotLongIdent ncenv wholem ad nenv ty id rest typeNameResInfo findFlag maybeAppliedArgExpr | ||
| | _ -> error(InternalError("ResolveExprDotLongIdentAndComputeRange", wholem)) | ||
| let itemRange = ComputeItemRange wholem lid rest | ||
| resInfo, item, rest, itemRange | ||
| let itemRange, itemIdentRange = ComputeItemRange wholem lid rest | ||
| resInfo, item, rest, itemRange, itemIdentRange | ||
|
|
||
| // "true" resolution | ||
| let resInfo, item, rest, itemRange = resolveExpr findFlag | ||
| let resInfo, item, rest, itemRange, itemIdentRange = resolveExpr findFlag | ||
| ResolutionInfo.SendEntityPathToSink(sink, ncenv, nenv, ItemOccurrence.Use, ad, resInfo, ResultTyparChecker(fun () -> CheckAllTyparsInferrable ncenv.amap itemRange item)) | ||
|
|
||
| // Record the precise resolution of the field for intellisense/goto definition | ||
|
|
@@ -4305,25 +4330,26 @@ let ResolveExprDotLongIdentAndComputeRange (sink: TcResultsSink) (ncenv: NameRes | |
| | None -> AfterResolution.DoNothing // do not refine the resolution if nobody listens | ||
| | Some _ -> | ||
| // resolution for goto definition | ||
| let unrefinedItem, itemRange, overrides = | ||
| let unrefinedItem, itemRange, itemIdentRange, overrides = | ||
| match findFlag, item with | ||
| | FindMemberFlag.PreferOverrides, _ | ||
| | _, NonOverridable() -> item, itemRange, false | ||
| | _, NonOverridable() -> item, itemRange, itemIdentRange, false | ||
| | FindMemberFlag.IgnoreOverrides, _ | ||
| | FindMemberFlag.DiscardOnFirstNonOverride, _ -> | ||
| let _, item, _, itemRange = resolveExpr FindMemberFlag.PreferOverrides | ||
| item, itemRange, true | ||
| let _, item, _, itemRange, itemIdentRange = resolveExpr FindMemberFlag.PreferOverrides | ||
| item, itemRange, itemIdentRange, true | ||
|
|
||
| let callSink (refinedItem, tpinst) = | ||
| let refinedItem = FilterMethodGroups ncenv itemRange refinedItem staticOnly | ||
| let unrefinedItem = FilterMethodGroups ncenv itemRange unrefinedItem staticOnly | ||
| CallMethodGroupNameResolutionSink sink (itemRange, nenv, refinedItem, unrefinedItem, tpinst, ItemOccurrence.Use, ad) | ||
| // Use narrow terminal-identifier range for the sink (FSharpSymbolUse / Find Usages | ||
| // / symbol highlight). See #3920, #14284. | ||
| CallMethodGroupNameResolutionSink sink (itemIdentRange, nenv, refinedItem, unrefinedItem, tpinst, ItemOccurrence.Use, ad) | ||
|
|
||
| // #16621 | ||
| match refinedItem with | ||
| | Item.Property(_, pinfos, _) -> | ||
| let propIdentRange = if rest.IsEmpty then (List.last lid).idRange else itemRange | ||
| RegisterUnionCaseTesterForProperty sink propIdentRange pinfos | ||
| RegisterUnionCaseTesterForProperty sink itemIdentRange pinfos | ||
| | _ -> () | ||
|
|
||
| let callSinkWithSpecificOverload (minfo: MethInfo, pinfoOpt: PropInfo option, tpinst) = | ||
|
|
@@ -4344,7 +4370,7 @@ let ResolveExprDotLongIdentAndComputeRange (sink: TcResultsSink) (ncenv: NameRes | |
| callSink (unrefinedItem, emptyTyparInst) | ||
| AfterResolution.DoNothing | ||
|
|
||
| item, itemRange, rest, afterResolution | ||
| item, itemRange, itemIdentRange, rest, afterResolution | ||
|
|
||
|
|
||
| //------------------------------------------------------------------------- | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the point of adding this parameter (
_mItemIdent) that's only discarded?