Skip to content

Commit

Permalink
Refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAngryByrd committed Feb 25, 2023
1 parent d951d0c commit 46919e8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 31 deletions.
7 changes: 5 additions & 2 deletions src/FsAutoComplete.Core/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,9 @@ module List =
[<RequireQualifiedAccess>]
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module String =
/// Concatenates all the elements of a string array, using the specified separator between each element.
let inline join (separator: string) (items: string seq) = String.Join(separator, items)

let inline toCharArray (str: string) = str.ToCharArray()

let lowerCaseFirstChar (str: string) =
Expand Down Expand Up @@ -898,8 +901,8 @@ module Tracing =
if activity <> null then
activity.TraceStateString <- request.TraceState

if request.TraceParent <> null then
activity.SetParentId(request.TraceParent) |> ignore
if request.TraceParent <> null then
activity.SetParentId(request.TraceParent) |> ignore

activity

Expand Down
44 changes: 15 additions & 29 deletions src/FsAutoComplete/LspServers/FSharpLspClient.fs
Original file line number Diff line number Diff line change
Expand Up @@ -160,19 +160,6 @@ type ProgressListener(lspClient: FSharpLspClient, traceNamespace: string array)
let strContains (substring: string) (str: string) = str.Contains(substring)

let interestingActivities = traceNamespace |> Array.map strContains
// [
// strEquals "BoundModel.TypeCheck"
// strContains "BackgroundCompiler."
// // strContains "BoundModel."
// // strContains "IncrementalBuild."
// // strContains "CheckDeclarations."
// // strContains "ParseAndCheckInputs."
// // strContains "BackgroundCompiler."
// // strContains "IncrementalBuildSyntaxTree."
// // strContains "ParseAndCheckFile."
// // strContains "ParseAndCheckInputs."
// // strContains "CheckDeclarations."
// ]

let logger = LogProvider.getLoggerByName "Compiler"

Expand All @@ -182,15 +169,12 @@ type ProgressListener(lspClient: FSharpLspClient, traceNamespace: string array)
ConcurrentDictionary<_, System.Diagnostics.Activity * ServerProgressReport>()

let isStopped (activity: Activity) =
#if NET6_0
false
||
#else
#if NET7_0_OR_GREATER
activity.IsStopped
||
#endif
// giving this 1 seconds to report something, otherwise assume it's a dead activity
((DateTime.UtcNow - activity.StartTimeUtc) > TimeSpan.FromSeconds(5.)
// giving this 2 seconds to report something, otherwise assume it's a dead activity
((DateTime.UtcNow - activity.StartTimeUtc) > TimeSpan.FromSeconds(2.)
&& activity.Duration = TimeSpan.Zero)

let getTagItemSafe key (a: Activity) = a.GetTagItem key |> Option.ofObj
Expand Down Expand Up @@ -224,8 +208,10 @@ type ProgressListener(lspClient: FSharpLspClient, traceNamespace: string array)
inflightEvents.TryRemove(a.Id) |> ignore
else
// FSC doesn't start their spans with tags so we have to see if it's been added later https://github.com/dotnet/fsharp/issues/14776
let message = String.Join(" - ", [ getFileName a; getProject a; getUserOpName a ])

let message =
[ getFileName a; getProject a; getUserOpName a ]
|> List.filter (String.IsNullOrEmpty >> not)
|> String.join " - "

do! p.Report(message = message)

Expand All @@ -240,10 +226,10 @@ type ProgressListener(lspClient: FSharpLspClient, traceNamespace: string array)
let fileName = getFileName activity
let userOpName = getUserOpName activity

// logger.debug (
// Log.setMessageI
// $"Started : {activity.DisplayName:DisplayName} - {userOpName:UserOpName} - {fileName:fileName}"
// )
logger.trace (
Log.setMessageI
$"Started : {activity.DisplayName:DisplayName} - {userOpName:UserOpName} - {fileName:fileName}"
)

if
activity.DisplayName |> isOneOf interestingActivities
Expand All @@ -260,10 +246,10 @@ type ProgressListener(lspClient: FSharpLspClient, traceNamespace: string array)
let userOpName = getUserOpName activity
let duration = activity.Duration.ToString()

// logger.debug (
// Log.setMessageI
// $"Finished : {activity.DisplayName:DisplayName} - {userOpName:UserOpName} - {fileName:fileName} - took {duration:duration}"
// )
logger.trace (
Log.setMessageI
$"Finished : {activity.DisplayName:DisplayName} - {userOpName:UserOpName} - {fileName:fileName} - took {duration:duration}"
)

if activity.DisplayName |> isOneOf interestingActivities then
match inflightEvents.TryRemove(activity.Id) with
Expand Down

0 comments on commit 46919e8

Please sign in to comment.