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
8 changes: 8 additions & 0 deletions docs/release-notes/.VisualStudio/18.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### Fixed
* Split package init into foreground+background, fix background analysis setting ([Issue #18623](https://github.com/dotnet/fsharp/issues/18623), [Issue #18904](https://github.com/dotnet/fsharp/issues/18904), [PR #18646](https://github.com/dotnet/fsharp/pull/18646))

### Added

### Changed

### Breaking Changes
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
namespace Microsoft.VisualStudio.FSharp.Editor.Logging
namespace Microsoft.VisualStudio.FSharp.Editor.DebugHelpers

open System
open System.Diagnostics
open System.ComponentModel.Composition
open Microsoft.VisualStudio.Shell
open Microsoft.VisualStudio.Shell.Interop
open Microsoft.VisualStudio.FSharp.Editor

open FSharp.Compiler.Diagnostics

Expand All @@ -32,75 +30,57 @@ module Config =
open Config
open System.Diagnostics.Metrics
open System.Text
open Microsoft.VisualStudio.Threading

[<Export>]
type Logger [<ImportingConstructor>] ([<Import(typeof<SVsServiceProvider>)>] serviceProvider: IServiceProvider) =
let outputWindow =
serviceProvider.GetService<SVsOutputWindow, IVsOutputWindow>() |> Option.ofObj

let createPane () =
outputWindow
|> Option.iter (fun x ->
x.CreatePane(ref fsharpOutputGuid, "F# Language Service", Convert.ToInt32 true, Convert.ToInt32 false)
|> ignore)

do createPane ()

let getPane () =
match outputWindow |> Option.map (fun x -> x.GetPane(ref fsharpOutputGuid)) with
| Some(0, pane) ->
pane.Activate() |> ignore
Some pane
| _ -> None

static let mutable globalServiceProvider: IServiceProvider option = None

static member GlobalServiceProvider
with get () =
globalServiceProvider
|> Option.defaultValue (ServiceProvider.GlobalProvider :> IServiceProvider)
and set v = globalServiceProvider <- Some v

member _.FSharpLoggingPane =
getPane ()
|> function
| Some pane -> Some pane
| None ->
createPane ()
getPane ()

member self.Log(msgType: LogType, msg: string) =
let time = DateTime.Now.ToString("hh:mm:ss tt")

match self.FSharpLoggingPane, msgType with
| None, _ -> ()
| Some pane, LogType.Message ->
String.Format("[{0}{1}] {2}{3}", "", time, msg, Environment.NewLine)
|> pane.OutputString
|> ignore
| Some pane, LogType.Info ->
String.Format("[{0}{1}] {2}{3}", "INFO ", time, msg, Environment.NewLine)
|> pane.OutputString
|> ignore
| Some pane, LogType.Warn ->
String.Format("[{0}{1}] {2}{3}", "WARN ", time, msg, Environment.NewLine)
|> pane.OutputString
|> ignore
| Some pane, LogType.Error ->
String.Format("[{0}{1}] {2}{3}", "ERROR ", time, msg, Environment.NewLine)
|> pane.OutputString
|> ignore

[<AutoOpen>]
module Logging =
module FSharpOutputPane =

let inline debug msg = Printf.kprintf Debug.WriteLine msg
let private pane =
AsyncLazy(
fun () ->
task {
do! ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync()
let! window = AsyncServiceProvider.GlobalProvider.GetServiceAsync<SVsOutputWindow, IVsOutputWindow>()

window.CreatePane(ref fsharpOutputGuid, "F# Language Service", Convert.ToInt32 true, Convert.ToInt32 false)
|> ignore

let private logger = lazy Logger(Logger.GlobalServiceProvider)
match window.GetPane(ref fsharpOutputGuid) with
| 0, pane -> return pane
| _ -> return failwith "Could not get F# output pane"
}
, ThreadHelper.JoinableTaskFactory
)

let inline debug msg = Printf.kprintf Debug.WriteLine msg

let private log logType msg =
logger.Value.Log(logType, msg)
System.Diagnostics.Trace.TraceInformation(msg)
task {
System.Diagnostics.Trace.TraceInformation(msg)
let time = DateTime.Now.ToString("hh:mm:ss tt")

let! pane = pane.GetValueAsync()

do! ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync()

match logType with
| LogType.Message ->
String.Format("[{0}{1}] {2}{3}", "", time, msg, Environment.NewLine)
|> pane.OutputStringThreadSafe
|> ignore
| LogType.Info ->
String.Format("[{0}{1}] {2}{3}", "INFO ", time, msg, Environment.NewLine)
|> pane.OutputStringThreadSafe
|> ignore
| LogType.Warn ->
String.Format("[{0}{1}] {2}{3}", "WARN ", time, msg, Environment.NewLine)
|> pane.OutputStringThreadSafe
|> ignore
| LogType.Error ->
String.Format("[{0}{1}] {2}{3}", "ERROR ", time, msg, Environment.NewLine)
|> pane.OutputStringThreadSafe
|> ignore
}
|> ignore

let logMsg msg = log LogType.Message msg
let logInfo msg = log LogType.Info msg
Expand Down Expand Up @@ -145,7 +125,7 @@ module FSharpServiceTelemetry =
ActivitySamplingResult.AllData
else
ActivitySamplingResult.None),
ActivityStarted = (fun a -> logMsg $"{indent a}{a.OperationName} {collectTags a}")
ActivityStarted = (fun a -> FSharpOutputPane.logMsg $"{indent a}{a.OperationName} {collectTags a}")
)

ActivitySource.AddActivityListener(listener)
Expand Down
4 changes: 2 additions & 2 deletions vsintegration/src/FSharp.Editor/Common/RoslynHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ open FSharp.Compiler.EditorServices
open FSharp.Compiler.Text
open FSharp.Compiler.Text
open FSharp.Compiler.Text.Range
open Microsoft.VisualStudio.FSharp.Editor.Logging
open Microsoft.VisualStudio.FSharp.Editor.DebugHelpers
open Microsoft.CodeAnalysis.ExternalAccess.FSharp.Diagnostics

type RoslynTaggedText = Microsoft.CodeAnalysis.TaggedText
Expand Down Expand Up @@ -221,7 +221,7 @@ module internal RoslynHelpers =
try
return! computation
with e ->
logExceptionWithContext (e, context)
FSharpOutputPane.logExceptionWithContext (e, context)
return Unchecked.defaultof<_>
}

Expand Down
2 changes: 1 addition & 1 deletion vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<Compile Include="Common\Constants.fs" />
<Compile Include="Common\Extensions.fs" />
<Compile Include="Common\Error.fs" />
<Compile Include="Common\Logging.fs" />
<Compile Include="Common\DebugHelpers.fs" />
<Compile Include="Common\RoslynHelpers.fs" />
<Compile Include="Common\FSharpCodeAnalysisExtensions.fs" />
<Compile Include="Common\CodeAnalysisExtensions.fs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.ExternalAccess.FSharp.Diagnostics
open Microsoft.VisualStudio.FSharp.Editor
open Microsoft.VisualStudio.FSharp.Editor.Logging
open Microsoft.VisualStudio.FSharp.Editor.DebugHelpers
open Microsoft.VisualStudio.Text.Editor.Commanding.Commands
open Microsoft.VisualStudio.Commanding
open Microsoft.VisualStudio.Utilities
Expand Down Expand Up @@ -90,7 +90,7 @@ type internal FSharpAnalysisSaveFileCommandHandler [<ImportingConstructor>] (ana
analyzerService.Reanalyze(workspace, documentIds = docIdsToReanalyze)
with ex ->
TelemetryReporter.ReportFault(TelemetryEvents.AnalysisSaveFileHandler, e = ex)
logException ex
FSharpOutputPane.logException ex
}
|> CancellableTask.startWithoutCancellation
|> ignore // fire and forget
Expand Down
Loading
Loading