Skip to content

Commit 2d7237c

Browse files
cartermpKevinRansom
authored andcommitted
No IVTs for CodeLenses (#6906)
* Don't expose Legacy MSBuildReferenceResolver * Move the files boss hoss * Remove unused opens * Fix tests * Remove IVT dependency for CodeLens and put logging behind a flag * oopsie doopsie * meep morp * blub glub * heepers jeepers * Update fsi.fs * Update service.fs * Update service.fsi * Update FSharpCheckerProvider.fs * Update FSharpLanguageServiceTestable.fs * Update TestLib.LanguageService.fs * Updates for build in release * I'm not touching MSBuildReferenceResolver I'm not touching MSBuildReferenceResolver I'm not touching MSBuildReferenceResolver * Different ignore and adjust ifdefs
1 parent 7c39a4f commit 2d7237c

File tree

9 files changed

+146
-63
lines changed

9 files changed

+146
-63
lines changed

src/fsharp/FSharp.Compiler.Private/FSharp.Compiler.Private.fsproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@
677677
<Compile Include="..\service\ServiceAnalysis.fs">
678678
<Link>Service/ServiceAnalysis.fs</Link>
679679
</Compile>
680-
680+
681681
<!-- the core of the F# Interactive fsi.exe implementation -->
682682
<EmbeddedText Include="..\fsi\FSIstrings.txt">
683683
<Link>FSIstrings.txt</Link>
@@ -688,7 +688,7 @@
688688
<Compile Include="..\fsi\fsi.fs">
689689
<Link>InteractiveSession/fsi.fs</Link>
690690
</Compile>
691-
691+
692692
<Compile Include="..\MSBuildReferenceResolver.fs" Condition="'$(MonoPackaging)' != 'true'">
693693
<Link>Misc/MSBuildReferenceResolver.fs</Link>
694694
</Compile>

src/fsharp/service/service.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,12 +2102,12 @@ type FSharpCheckFileResults(filename: string, errors: FSharpErrorInfo[], scopeOp
21022102
RequireCompilationThread ctok
21032103
scope.IsRelativeNameResolvableFromSymbol(pos, plid, symbol))
21042104

2105-
member info.GetDisplayEnvForPos(pos: pos) : Async<DisplayEnv option> =
2105+
member info.GetDisplayContextForPos(pos: pos) : Async<FSharpDisplayContext option> =
21062106
let userOpName = "CodeLens"
21072107
reactorOp userOpName "GetDisplayContextAtPos" None (fun ctok scope ->
21082108
DoesNotRequireCompilerThreadTokenAndCouldPossiblyBeMadeConcurrent ctok
21092109
let (nenv, _), _ = scope.GetBestDisplayEnvForPos pos
2110-
Some nenv.DisplayEnv)
2110+
Some(FSharpDisplayContext(fun _ -> nenv.DisplayEnv)))
21112111

21122112
member info.ImplementationFile =
21132113
if not keepAssemblyContents then invalidOp "The 'keepAssemblyContents' flag must be set to true on the FSharpChecker in order to access the checked contents of assemblies"

src/fsharp/service/service.fsi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ type public FSharpCheckFileResults =
244244

245245
member internal GetVisibleNamespacesAndModulesAtPoint : pos -> Async<Tast.ModuleOrNamespaceRef[]>
246246

247-
/// Find the most precise display environment for the given line and column.
248-
member internal GetDisplayEnvForPos : pos : pos -> Async<DisplayEnv option>
247+
/// Find the most precise display context for the given line and column.
248+
member GetDisplayContextForPos : pos : pos -> Async<FSharpDisplayContext option>
249249

250250
/// Determines if a long ident is resolvable at a specific point.
251251
/// <param name="userOpName">An optional string used for tracing compiler operations associated with this request.</param>

vsintegration/src/FSharp.Editor/CodeLens/AbstractCodeLensDisplayService.fs

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace rec Microsoft.VisualStudio.FSharp.Editor
44

5-
open System
65
open System.Windows.Controls
76
open Microsoft.VisualStudio.Text
87
open Microsoft.VisualStudio.Text.Editor
@@ -123,7 +122,9 @@ type CodeLensDisplayService (view : IWpfTextView, buffer : ITextBuffer, layerNam
123122
let startLineNumber = snapshot.GetLineNumberFromPosition(trackingSpan.GetStartPoint(snapshot).Position)
124123
let uiElement =
125124
if self.UiElements.ContainsKey trackingSpan then
125+
#if DEBUG
126126
logErrorf "Added a tracking span twice, this is not allowed and will result in invalid values! %A" (trackingSpan.GetText snapshot)
127+
#endif
127128
self.UiElements.[trackingSpan]
128129
else
129130
let defaultStackPanel = self.CreateDefaultStackPanel()
@@ -152,7 +153,12 @@ type CodeLensDisplayService (view : IWpfTextView, buffer : ITextBuffer, layerNam
152153
let firstLine = view.TextViewLines.FirstVisibleLine
153154
view.DisplayTextLineContainingBufferPosition (firstLine.Start, 0., ViewRelativePosition.Top)
154155
self.RelayoutRequested.Enqueue(())
155-
with e -> logErrorf "Error in line lens provider: %A" e
156+
with e ->
157+
#if DEBUG
158+
logErrorf "Error in line lens provider: %A" e
159+
#else
160+
ignore e
161+
#endif
156162

157163
/// Public non-thread-safe method to add line lens for a given tracking span.
158164
/// Returns an UIElement which can be used to add Ui elements and to remove the line lens later.
@@ -171,20 +177,30 @@ type CodeLensDisplayService (view : IWpfTextView, buffer : ITextBuffer, layerNam
171177
self.UiElements.Remove trackingSpan |> ignore
172178
try
173179
self.CodeLensLayer.RemoveAdornment(Grid)
174-
with e ->
180+
with e ->
181+
#if DEBUG
175182
logExceptionWithContext(e, "Removing line lens")
183+
#else
184+
ignore e
185+
#endif
186+
#if DEBUG
176187
else
177188
logWarningf "No ui element is attached to this tracking span!"
189+
#endif
178190
let lineNumber =
179191
(trackingSpan.GetStartPoint self.CurrentBufferSnapshot).Position
180192
|> self.CurrentBufferSnapshot.GetLineNumberFromPosition
181193
if self.TrackingSpans.ContainsKey lineNumber then
194+
#if DEBUG
182195
if self.TrackingSpans.[lineNumber].Remove trackingSpan |> not then
183196
logWarningf "No tracking span is accociated with this line number %d!" lineNumber
197+
#endif
184198
if self.TrackingSpans.[lineNumber].Count = 0 then
185199
self.TrackingSpans.Remove lineNumber |> ignore
200+
#if DEBUG
186201
else
187202
logWarningf "No tracking span is accociated with this line number %d!" lineNumber
203+
#endif
188204

189205
abstract member AddUiElementToCodeLens : ITrackingSpan * UIElement -> unit
190206
default self.AddUiElementToCodeLens (trackingSpan:ITrackingSpan, uiElement:UIElement) =
@@ -234,7 +250,12 @@ type CodeLensDisplayService (view : IWpfTextView, buffer : ITextBuffer, layerNam
234250
applyFuncOnLineStackPanels line (fun ui ->
235251
ui.Visibility <- Visibility.Hidden
236252
)
237-
with e -> logErrorf "Error in non visible lines iteration %A" e
253+
with e ->
254+
#if DEBUG
255+
logErrorf "Error in non visible lines iteration %A" e
256+
#else
257+
ignore e
258+
#endif
238259
for lineNumber in newVisibleLineNumbers do
239260
try
240261
let line =
@@ -244,7 +265,12 @@ type CodeLensDisplayService (view : IWpfTextView, buffer : ITextBuffer, layerNam
244265
ui.Visibility <- Visibility.Visible
245266
self.LayoutUIElementOnLine view line ui
246267
)
247-
with e -> logErrorf "Error in new visible lines iteration %A" e
268+
with e ->
269+
#if DEBUG
270+
logErrorf "Error in new visible lines iteration %A" e
271+
#else
272+
ignore e
273+
#endif
248274
if not e.VerticalTranslation && e.NewViewState.ViewportHeight <> e.OldViewState.ViewportHeight then
249275
self.RelayoutRequested.Enqueue() // Unfortunately zooming requires a relayout too, to ensure that no weird layout happens due to unkown reasons.
250276
if self.RelayoutRequested.Count > 0 then
@@ -267,8 +293,13 @@ type CodeLensDisplayService (view : IWpfTextView, buffer : ITextBuffer, layerNam
267293

268294
self.AsyncCustomLayoutOperation visibleLineNumbers buffer
269295
|> RoslynHelpers.StartAsyncSafe self.LayoutChangedCts.Token "HandleLayoutChanged"
270-
with e -> logExceptionWithContext (e, "Layout changed")
296+
with e ->
297+
#if DEBUG
298+
logExceptionWithContext (e, "Layout changed")
299+
#else
300+
ignore e
301+
#endif
271302

272303
abstract LayoutUIElementOnLine : IWpfTextView -> ITextViewLine -> Grid -> unit
273304

274-
abstract AsyncCustomLayoutOperation : int Set -> ITextSnapshot -> unit Async
305+
abstract AsyncCustomLayoutOperation : int Set -> ITextSnapshot -> unit Async

vsintegration/src/FSharp.Editor/CodeLens/CodeLensGeneralTagger.fs

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ open Microsoft.VisualStudio.Text
88
open Microsoft.VisualStudio.Text.Editor
99
open Microsoft.VisualStudio.Text.Formatting
1010
open System.Windows
11-
open System.Collections.Generic
1211
open Microsoft.VisualStudio.Text.Tagging
1312

1413
open Microsoft.VisualStudio.FSharp.Editor.Logging
@@ -32,7 +31,9 @@ type CodeLensGeneralTagger (view, buffer) as self =
3231
let left = Canvas.GetLeft parent
3332
let top = Canvas.GetTop parent
3433
let width = parent.ActualWidth
34+
#if DEBUG
3535
logInfof "Width of parent: %.4f" width
36+
#endif
3637
left + width, top
3738
| _ ->
3839
try
@@ -47,12 +48,18 @@ type CodeLensGeneralTagger (view, buffer) as self =
4748
// Calling the method twice fixes this bug and ensures that all values are correct.
4849
// Okay not really :( Must be replaced later with an own calculation depending on editor font settings!
4950
if 7 * offset > int g.Left then
51+
#if DEBUG
5052
logErrorf "Incorrect return from geometry measure"
53+
#endif
5154
Canvas.GetLeft ui, g.Top
5255
else
5356
g.Left, g.Top
5457
with e ->
58+
#if DEBUG
5559
logExceptionWithContext (e, "Error in layout ui element on line")
60+
#else
61+
ignore e
62+
#endif
5663
Canvas.GetLeft ui, Canvas.GetTop ui
5764
Canvas.SetLeft(ui, left)
5865
Canvas.SetTop(ui, top)
@@ -89,7 +96,12 @@ type CodeLensGeneralTagger (view, buffer) as self =
8996
self, stackPanel, AdornmentRemovedCallback(fun _ _ -> ())) |> ignore
9097
self.AddedAdornments.Add stackPanel |> ignore
9198
| _ -> ()
92-
with e -> logExceptionWithContext (e, "LayoutChanged, processing new visible lines")
99+
with e ->
100+
#if DEBUG
101+
logExceptionWithContext (e, "LayoutChanged, processing new visible lines")
102+
#else
103+
ignore e
104+
#endif
93105
} |> Async.Ignore
94106

95107
override self.AddUiElementToCodeLens (trackingSpan:ITrackingSpan, uiElement:UIElement)=
@@ -114,7 +126,13 @@ type CodeLensGeneralTagger (view, buffer) as self =
114126
let lineNumber =
115127
try
116128
snapshot.GetLineNumberFromPosition(span.Start.Position)
117-
with e -> logExceptionWithContext (e, "line number tagging"); 0
129+
with e ->
130+
#if DEBUG
131+
logExceptionWithContext (e, "line number tagging")
132+
#else
133+
ignore e
134+
#endif
135+
0
118136
if self.TrackingSpans.ContainsKey(lineNumber) && self.TrackingSpans.[lineNumber] |> Seq.isEmpty |> not then
119137

120138
let tagSpan = snapshot.GetLineFromLineNumber(lineNumber).Extent
@@ -128,26 +146,46 @@ type CodeLensGeneralTagger (view, buffer) as self =
128146
let span =
129147
try
130148
tagSpan.TranslateTo(span.Snapshot, SpanTrackingMode.EdgeExclusive)
131-
with e -> logExceptionWithContext (e, "tag span translation"); tagSpan
149+
with e ->
150+
#if DEBUG
151+
logExceptionWithContext (e, "tag span translation")
152+
#else
153+
ignore e
154+
#endif
155+
tagSpan
132156
let sizes =
133157
try
134158
stackPanels |> Seq.map (fun ui ->
135159
ui.Measure(Size(10000., 10000.))
136160
ui.DesiredSize )
137-
with e -> logExceptionWithContext (e, "internal tagging"); Seq.empty
161+
with e ->
162+
#if DEBUG
163+
logExceptionWithContext (e, "internal tagging")
164+
#else
165+
ignore e
166+
#endif
167+
Seq.empty
138168
let height =
139169
try
140170
sizes
141171
|> Seq.map (fun size -> size.Height)
142172
|> Seq.sortDescending
143173
|> Seq.tryHead
144174
|> Option.defaultValue 0.
145-
with e -> logExceptionWithContext (e, "height tagging"); 0.
175+
with e ->
176+
#if DEBUG
177+
logExceptionWithContext (e, "height tagging")
178+
#else
179+
ignore e
180+
#endif
181+
0.0
146182

147183
yield TagSpan(span, CodeLensGeneralTag(0., height, 0., 0., 0., PositionAffinity.Predecessor, stackPanels, self)) :> ITagSpan<CodeLensGeneralTag>
148184
}
149-
with e ->
185+
with e ->
186+
#if DEBUG
150187
logErrorf "Error in code lens get tags %A" e
151-
Seq.empty
152-
153-
188+
#else
189+
ignore e
190+
#endif
191+
Seq.empty

vsintegration/src/FSharp.Editor/CodeLens/CodeLensProvider.fs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,15 @@
22

33
namespace rec Microsoft.VisualStudio.FSharp.Editor
44

5-
65
open System
76
open Microsoft.VisualStudio.Text
87
open Microsoft.VisualStudio.Text.Editor
98
open System.ComponentModel.Composition
109
open Microsoft.VisualStudio.Utilities
11-
open Microsoft.CodeAnalysis
1210
open Microsoft.VisualStudio.Shell
1311
open Microsoft.VisualStudio
1412
open Microsoft.VisualStudio.LanguageServices
15-
open System.Collections.Generic
16-
open Microsoft.CodeAnalysis.Editor.Shared.Utilities
1713
open Microsoft.VisualStudio.Text.Tagging
18-
open Microsoft.VisualStudio.Text.Classification
19-
open Microsoft.VisualStudio.ComponentModelHost
20-
open System.Threading
21-
open Microsoft.VisualStudio.FSharp.Editor.Logging
2214
open Microsoft.CodeAnalysis.ExternalAccess.FSharp.Editor.Shared.Utilities
2315

2416
[<Export(typeof<IWpfTextViewCreationListener>)>]
@@ -108,4 +100,4 @@ type internal CodeLensProvider
108100
interface IWpfTextViewCreationListener with
109101
override __.TextViewCreated view =
110102
if settings.CodeLens.Enabled && settings.CodeLens.ReplaceWithLineLens then
111-
addLineLensProviderOnce view (view.TextBuffer) |> ignore
103+
addLineLensProviderOnce view (view.TextBuffer) |> ignore

0 commit comments

Comments
 (0)