Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@
<Compile Include="..\service\ServiceAnalysis.fs">
<Link>Service/ServiceAnalysis.fs</Link>
</Compile>

<!-- the core of the F# Interactive fsi.exe implementation -->
<EmbeddedText Include="..\fsi\FSIstrings.txt">
<Link>FSIstrings.txt</Link>
Expand All @@ -681,7 +681,7 @@
<Compile Include="..\fsi\fsi.fs">
<Link>InteractiveSession/fsi.fs</Link>
</Compile>

<Compile Include="..\MSBuildReferenceResolver.fs" Condition="'$(MonoPackaging)' != 'true'">
<Link>Misc/MSBuildReferenceResolver.fs</Link>
</Compile>
Expand Down
4 changes: 2 additions & 2 deletions src/fsharp/service/service.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2135,12 +2135,12 @@ type FSharpCheckFileResults(filename: string, errors: FSharpErrorInfo[], scopeOp
RequireCompilationThread ctok
scope.IsRelativeNameResolvableFromSymbol(pos, plid, symbol))

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

member info.ImplementationFile =
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"
Expand Down
4 changes: 2 additions & 2 deletions src/fsharp/service/service.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ type public FSharpCheckFileResults =

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

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

/// Determines if a long ident is resolvable at a specific point.
/// <param name="userOpName">An optional string used for tracing compiler operations associated with this request.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace rec Microsoft.VisualStudio.FSharp.Editor

open System
open System.Windows.Controls
open Microsoft.VisualStudio.Text
open Microsoft.VisualStudio.Text.Editor
Expand Down Expand Up @@ -123,7 +122,9 @@ type CodeLensDisplayService (view : IWpfTextView, buffer : ITextBuffer, layerNam
let startLineNumber = snapshot.GetLineNumberFromPosition(trackingSpan.GetStartPoint(snapshot).Position)
let uiElement =
if self.UiElements.ContainsKey trackingSpan then
#if DEBUG
logErrorf "Added a tracking span twice, this is not allowed and will result in invalid values! %A" (trackingSpan.GetText snapshot)
#endif
self.UiElements.[trackingSpan]
else
let defaultStackPanel = self.CreateDefaultStackPanel()
Expand Down Expand Up @@ -152,7 +153,12 @@ type CodeLensDisplayService (view : IWpfTextView, buffer : ITextBuffer, layerNam
let firstLine = view.TextViewLines.FirstVisibleLine
view.DisplayTextLineContainingBufferPosition (firstLine.Start, 0., ViewRelativePosition.Top)
self.RelayoutRequested.Enqueue(())
with e -> logErrorf "Error in line lens provider: %A" e
with e ->
#if DEBUG
logErrorf "Error in line lens provider: %A" e
#else
ignore e
#endif

/// Public non-thread-safe method to add line lens for a given tracking span.
/// Returns an UIElement which can be used to add Ui elements and to remove the line lens later.
Expand All @@ -171,20 +177,30 @@ type CodeLensDisplayService (view : IWpfTextView, buffer : ITextBuffer, layerNam
self.UiElements.Remove trackingSpan |> ignore
try
self.CodeLensLayer.RemoveAdornment(Grid)
with e ->
with e ->
#if DEBUG
logExceptionWithContext(e, "Removing line lens")
#else
ignore e
#endif
#if DEBUG
else
logWarningf "No ui element is attached to this tracking span!"
#endif
let lineNumber =
(trackingSpan.GetStartPoint self.CurrentBufferSnapshot).Position
|> self.CurrentBufferSnapshot.GetLineNumberFromPosition
if self.TrackingSpans.ContainsKey lineNumber then
#if DEBUG
if self.TrackingSpans.[lineNumber].Remove trackingSpan |> not then
logWarningf "No tracking span is accociated with this line number %d!" lineNumber
#endif
if self.TrackingSpans.[lineNumber].Count = 0 then
self.TrackingSpans.Remove lineNumber |> ignore
#if DEBUG
else
logWarningf "No tracking span is accociated with this line number %d!" lineNumber
#endif

abstract member AddUiElementToCodeLens : ITrackingSpan * UIElement -> unit
default self.AddUiElementToCodeLens (trackingSpan:ITrackingSpan, uiElement:UIElement) =
Expand Down Expand Up @@ -234,7 +250,12 @@ type CodeLensDisplayService (view : IWpfTextView, buffer : ITextBuffer, layerNam
applyFuncOnLineStackPanels line (fun ui ->
ui.Visibility <- Visibility.Hidden
)
with e -> logErrorf "Error in non visible lines iteration %A" e
with e ->
#if DEBUG
logErrorf "Error in non visible lines iteration %A" e
#else
ignore e
#endif
for lineNumber in newVisibleLineNumbers do
try
let line =
Expand All @@ -244,7 +265,12 @@ type CodeLensDisplayService (view : IWpfTextView, buffer : ITextBuffer, layerNam
ui.Visibility <- Visibility.Visible
self.LayoutUIElementOnLine view line ui
)
with e -> logErrorf "Error in new visible lines iteration %A" e
with e ->
#if DEBUG
logErrorf "Error in new visible lines iteration %A" e
#else
ignore e
#endif
if not e.VerticalTranslation && e.NewViewState.ViewportHeight <> e.OldViewState.ViewportHeight then
self.RelayoutRequested.Enqueue() // Unfortunately zooming requires a relayout too, to ensure that no weird layout happens due to unkown reasons.
if self.RelayoutRequested.Count > 0 then
Expand All @@ -267,8 +293,13 @@ type CodeLensDisplayService (view : IWpfTextView, buffer : ITextBuffer, layerNam

self.AsyncCustomLayoutOperation visibleLineNumbers buffer
|> RoslynHelpers.StartAsyncSafe self.LayoutChangedCts.Token "HandleLayoutChanged"
with e -> logExceptionWithContext (e, "Layout changed")
with e ->
#if DEBUG
logExceptionWithContext (e, "Layout changed")
#else
ignore e
#endif

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

abstract AsyncCustomLayoutOperation : int Set -> ITextSnapshot -> unit Async
abstract AsyncCustomLayoutOperation : int Set -> ITextSnapshot -> unit Async
58 changes: 48 additions & 10 deletions vsintegration/src/FSharp.Editor/CodeLens/CodeLensGeneralTagger.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ open Microsoft.VisualStudio.Text
open Microsoft.VisualStudio.Text.Editor
open Microsoft.VisualStudio.Text.Formatting
open System.Windows
open System.Collections.Generic
open Microsoft.VisualStudio.Text.Tagging

open Microsoft.VisualStudio.FSharp.Editor.Logging
Expand All @@ -32,7 +31,9 @@ type CodeLensGeneralTagger (view, buffer) as self =
let left = Canvas.GetLeft parent
let top = Canvas.GetTop parent
let width = parent.ActualWidth
#if DEBUG
logInfof "Width of parent: %.4f" width
#endif
left + width, top
| _ ->
try
Expand All @@ -47,12 +48,18 @@ type CodeLensGeneralTagger (view, buffer) as self =
// Calling the method twice fixes this bug and ensures that all values are correct.
// Okay not really :( Must be replaced later with an own calculation depending on editor font settings!
if 7 * offset > int g.Left then
#if DEBUG
logErrorf "Incorrect return from geometry measure"
#endif
Canvas.GetLeft ui, g.Top
else
g.Left, g.Top
with e ->
#if DEBUG
logExceptionWithContext (e, "Error in layout ui element on line")
#else
ignore e
#endif
Canvas.GetLeft ui, Canvas.GetTop ui
Canvas.SetLeft(ui, left)
Canvas.SetTop(ui, top)
Expand Down Expand Up @@ -89,7 +96,12 @@ type CodeLensGeneralTagger (view, buffer) as self =
self, stackPanel, AdornmentRemovedCallback(fun _ _ -> ())) |> ignore
self.AddedAdornments.Add stackPanel |> ignore
| _ -> ()
with e -> logExceptionWithContext (e, "LayoutChanged, processing new visible lines")
with e ->
#if DEBUG
logExceptionWithContext (e, "LayoutChanged, processing new visible lines")
#else
ignore e
#endif
} |> Async.Ignore

override self.AddUiElementToCodeLens (trackingSpan:ITrackingSpan, uiElement:UIElement)=
Expand All @@ -114,7 +126,13 @@ type CodeLensGeneralTagger (view, buffer) as self =
let lineNumber =
try
snapshot.GetLineNumberFromPosition(span.Start.Position)
with e -> logExceptionWithContext (e, "line number tagging"); 0
with e ->
#if DEBUG
logExceptionWithContext (e, "line number tagging")
#else
ignore e
#endif
0
if self.TrackingSpans.ContainsKey(lineNumber) && self.TrackingSpans.[lineNumber] |> Seq.isEmpty |> not then

let tagSpan = snapshot.GetLineFromLineNumber(lineNumber).Extent
Expand All @@ -128,26 +146,46 @@ type CodeLensGeneralTagger (view, buffer) as self =
let span =
try
tagSpan.TranslateTo(span.Snapshot, SpanTrackingMode.EdgeExclusive)
with e -> logExceptionWithContext (e, "tag span translation"); tagSpan
with e ->
#if DEBUG
logExceptionWithContext (e, "tag span translation")
#else
ignore e
#endif
tagSpan
let sizes =
try
stackPanels |> Seq.map (fun ui ->
ui.Measure(Size(10000., 10000.))
ui.DesiredSize )
with e -> logExceptionWithContext (e, "internal tagging"); Seq.empty
with e ->
#if DEBUG
logExceptionWithContext (e, "internal tagging")
#else
ignore e
#endif
Seq.empty
let height =
try
sizes
|> Seq.map (fun size -> size.Height)
|> Seq.sortDescending
|> Seq.tryHead
|> Option.defaultValue 0.
with e -> logExceptionWithContext (e, "height tagging"); 0.
with e ->
#if DEBUG
logExceptionWithContext (e, "height tagging")
#else
ignore e
#endif
0.0

yield TagSpan(span, CodeLensGeneralTag(0., height, 0., 0., 0., PositionAffinity.Predecessor, stackPanels, self)) :> ITagSpan<CodeLensGeneralTag>
}
with e ->
with e ->
#if DEBUG
logErrorf "Error in code lens get tags %A" e
Seq.empty


#else
ignore e
#endif
Seq.empty
10 changes: 1 addition & 9 deletions vsintegration/src/FSharp.Editor/CodeLens/CodeLensProvider.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,15 @@

namespace rec Microsoft.VisualStudio.FSharp.Editor


open System
open Microsoft.VisualStudio.Text
open Microsoft.VisualStudio.Text.Editor
open System.ComponentModel.Composition
open Microsoft.VisualStudio.Utilities
open Microsoft.CodeAnalysis
open Microsoft.VisualStudio.Shell
open Microsoft.VisualStudio
open Microsoft.VisualStudio.LanguageServices
open System.Collections.Generic
open Microsoft.CodeAnalysis.Editor.Shared.Utilities
open Microsoft.VisualStudio.Text.Tagging
open Microsoft.VisualStudio.Text.Classification
open Microsoft.VisualStudio.ComponentModelHost
open System.Threading
open Microsoft.VisualStudio.FSharp.Editor.Logging
open Microsoft.CodeAnalysis.ExternalAccess.FSharp.Editor.Shared.Utilities

[<Export(typeof<IWpfTextViewCreationListener>)>]
Expand Down Expand Up @@ -108,4 +100,4 @@ type internal CodeLensProvider
interface IWpfTextViewCreationListener with
override __.TextViewCreated view =
if settings.CodeLens.Enabled && settings.CodeLens.ReplaceWithLineLens then
addLineLensProviderOnce view (view.TextBuffer) |> ignore
addLineLensProviderOnce view (view.TextBuffer) |> ignore
Loading