Repository navigation
Shorten type annotation for Code Lens + small fixes #5145
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
Changes from all commits
a5f8433
8441f29
5db861c
6c4867d
955a0d2
4a235c0
c8a617c
0dffbff
46850a0
9552970
992ca9e
e03b5ba
18caa0f
9f15b16
a9a14f1
d4da8e0
0216bd4
9ad0541
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,7 +61,15 @@ type internal FSharpCodeLensService | |
|
|
||
| override __.VisitTypeAbbrev( _, range) = Some range | ||
|
|
||
| override __.VisitLetOrUse(_, _, _, range) = Some range | ||
| override __.VisitLetOrUse(_, _, bindings, range) = | ||
| match bindings |> Seq.tryFind (fun b -> b.RangeOfHeadPat.StartLine = pos.Line) with | ||
| | Some entry -> | ||
| Some entry.RangeOfBindingAndRhs | ||
| | None -> | ||
| // We choose to use the default range because | ||
| // it wasn't possible to find the complete range | ||
| // including implementation code. | ||
| Some range | ||
|
|
||
| override __.VisitBinding (fn, binding) = | ||
| Some binding.RangeOfBindingAndRhs | ||
|
|
@@ -178,8 +186,7 @@ type internal FSharpCodeLensService | |
|
|
||
| let displayContext = Option.defaultValue displayContext maybeContext | ||
| let typeLayout = func.FormatLayout displayContext | ||
| let taggedText = ResizeArray() | ||
|
|
||
| let taggedText = ResizeArray() | ||
| Layout.renderL (Layout.taggedTextListR taggedText.Add) typeLayout |> ignore | ||
| let statusBar = StatusBar(serviceProvider.GetService<SVsStatusbar, IVsStatusbar>()) | ||
| let navigation = QuickInfoNavigation(statusBar, checker, projectInfoManager, document, realPosition) | ||
|
|
@@ -191,37 +198,37 @@ type internal FSharpCodeLensService | |
| #endif | ||
| return None | ||
| else return None | ||
| with e -> | ||
| with e -> | ||
| #if DEBUG | ||
| logErrorf "Error in lazy line lens computation. %A" e | ||
| #else | ||
| ignore e | ||
| #endif | ||
| return None | ||
| } | ||
|
|
||
| let inline setNewResultsAndWarnIfOverriden fullDeclarationText value = | ||
| #if DEBUG | ||
| if newResults.ContainsKey fullDeclarationText then | ||
| logWarningf "New results already contains: %A" fullDeclarationText | ||
| #endif | ||
| newResults.[fullDeclarationText] <- value | ||
|
|
||
| for symbolUse in symbolUses do | ||
| if symbolUse.IsFromDefinition then | ||
| match symbolUse.Symbol with | ||
| | :? FSharpMemberOrFunctionOrValue as func when func.IsModuleValueOrMember || func.IsProperty -> | ||
| let funcID = func.FullName | ||
| let fullDeclarationText = funcID | ||
| let funcID = func.LogicalName + (func.FullType.ToString() |> hash |> string) | ||
|
cartermp marked this conversation as resolved.
Resolved
|
||
| // Use a combination of the the function name + the hashed value of the type signature | ||
| let fullTypeSignature = func.FullType.ToString() | ||
| // Try to re-use the last results | ||
| if lastResults.ContainsKey fullDeclarationText then | ||
| if lastResults.ContainsKey funcID then | ||
|
Contributor
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. Since you're hashing the text, should
Contributor
Author
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. If we want to minimize allocations I need to look into this again. Maybe it would be enough to make a dictionary which maps from function name to the hash of the full type (last time it was used) and then only compare the value/hash of the last type to change only the code lens above functions which type has really changed. Would that allocate less?
Contributor
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. Generally no, it's preferable not to use a string as a key if you can get away with it. Although it's still all small allocations, if you're already hashing something then that would be adequate for a key. Though generally it's recommended to use more information than just a hash for a key, since there can be hash collisions. Alternatively, does this caching provide any notable benefits? That is, if nothing was cached, does it meaningfully affect UX when used?
Contributor
Author
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. Of course, I wouldn't apply it if it wouldn't be of benefit :D I think about removing the |
||
| // Make sure that the results are usable | ||
| let inline setNewResultsAndWarnIfOverridenLocal value = setNewResultsAndWarnIfOverriden fullDeclarationText value | ||
| let lastTrackingSpan, codeLens as lastResult = lastResults.[fullDeclarationText] | ||
| let inline setNewResultsAndWarnIfOverridenLocal value = setNewResultsAndWarnIfOverriden funcID value | ||
| let lastTrackingSpan, codeLens as lastResult = lastResults.[funcID] | ||
| if codeLens.FullTypeSignature = fullTypeSignature then | ||
| setNewResultsAndWarnIfOverridenLocal lastResult | ||
| oldResults.Remove fullDeclarationText |> ignore | ||
| oldResults.Remove funcID |> ignore | ||
| else | ||
| let declarationLine, range = | ||
| match visit func.DeclarationLocation.Start parsedInput with | ||
|
|
@@ -241,19 +248,19 @@ type internal FSharpCodeLensService | |
| fullTypeSignature, | ||
| null) | ||
| // The old results aren't computed at all, because the line might have changed create new results | ||
| tagsToUpdate.[lastTrackingSpan] <- (newTrackingSpan, fullDeclarationText, res) | ||
| tagsToUpdate.[lastTrackingSpan] <- (newTrackingSpan, funcID, res) | ||
| setNewResultsAndWarnIfOverridenLocal (newTrackingSpan, res) | ||
|
|
||
| oldResults.Remove fullDeclarationText |> ignore | ||
| oldResults.Remove funcID |> ignore | ||
| else | ||
| // The symbol might be completely new or has slightly changed. | ||
| // We need to track this and iterate over the left entries to ensure that there isn't anything | ||
| unattachedSymbols.Add((symbolUse, func, fullDeclarationText, fullTypeSignature)) | ||
| unattachedSymbols.Add((symbolUse, func, funcID, fullTypeSignature)) | ||
| | _ -> () | ||
|
|
||
| // In best case this works quite `covfefe` fine because often enough we change only a small part of the file and not the complete. | ||
| for unattachedSymbol in unattachedSymbols do | ||
| let symbolUse, func, fullDeclarationText, fullTypeSignature = unattachedSymbol | ||
| let symbolUse, func, funcID, fullTypeSignature = unattachedSymbol | ||
| let declarationLine, range = | ||
| match visit func.DeclarationLocation.Start parsedInput with | ||
| | Some range -> range.StartLine - 1, range | ||
|
|
@@ -272,8 +279,8 @@ type internal FSharpCodeLensService | |
| let newTrackingSpan = | ||
| textSnapshot.CreateTrackingSpan(declarationSpan, SpanTrackingMode.EdgeExclusive) | ||
| if codeLens.Computed && (isNull codeLens.UiElement |> not) then | ||
| newResults.[fullDeclarationText] <- (newTrackingSpan, codeLens) | ||
| tagsToUpdate.[trackingSpan] <- (newTrackingSpan, fullDeclarationText, codeLens) | ||
| newResults.[funcID] <- (newTrackingSpan, codeLens) | ||
| tagsToUpdate.[trackingSpan] <- (newTrackingSpan, funcID, codeLens) | ||
| else | ||
| let res = | ||
| CodeLens( | ||
|
|
@@ -282,8 +289,8 @@ type internal FSharpCodeLensService | |
| fullTypeSignature, | ||
| null) | ||
| // The tag might be still valid but it hasn't been computed yet so create fresh results | ||
| tagsToUpdate.[trackingSpan] <- (newTrackingSpan, fullDeclarationText, res) | ||
| newResults.[fullDeclarationText] <- (newTrackingSpan, res) | ||
| tagsToUpdate.[trackingSpan] <- (newTrackingSpan, funcID, res) | ||
| newResults.[funcID] <- (newTrackingSpan, res) | ||
| let key = res.Key | ||
| oldResults.Remove key |> ignore // no need to check this entry again | ||
| | None -> | ||
|
|
@@ -304,7 +311,7 @@ type internal FSharpCodeLensService | |
| let trackingSpan = | ||
| textSnapshot.CreateTrackingSpan(declarationSpan, SpanTrackingMode.EdgeExclusive) | ||
| codeLensToAdd.Add (trackingSpan, res) | ||
| newResults.[fullDeclarationText] <- (trackingSpan, res) | ||
| newResults.[funcID] <- (trackingSpan, res) | ||
| with e -> | ||
| #if DEBUG | ||
| logExceptionWithContext (e, "Line Lens tracking tag span creation") | ||
|
|
@@ -401,4 +408,4 @@ type internal FSharpCodeLensService | |
| bufferChangedCts.Cancel() // Stop all ongoing async workflow. | ||
| bufferChangedCts.Dispose() | ||
| bufferChangedCts <- new CancellationTokenSource() | ||
| executeCodeLenseAsync () |> Async.Ignore |> RoslynHelpers.StartAsyncSafe bufferChangedCts.Token "Buffer Changed" | ||
| executeCodeLenseAsync () |> Async.Ignore |> RoslynHelpers.StartAsyncSafe bufferChangedCts.Token "Buffer Changed" | ||
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.
Since this is a private function I think it's fine to leave the name as-is and just have the additional flag. Perhaps rename the flag to
shortMemberDisplay?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.
Ok will do. Thanks :)