Skip to content

Commit

Permalink
mostly working scripts and projects
Browse files Browse the repository at this point in the history
  • Loading branch information
baronfel committed Nov 6, 2021
1 parent 777b6c7 commit 3e71b75
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 108 deletions.
8 changes: 4 additions & 4 deletions src/FsAutoComplete.Core/CodeGeneration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ type CodeGenerationService(checker : FSharpCompilerServiceChecker, state : State
if symbol.Kind = kind then
match state.TryGetFileCheckerOptionsWithLinesAndLineStr(fileName, pos) with
| ResultOrString.Error _ -> return! None
| ResultOrString.Ok (opts, _, line) ->
let! result = checker.TryGetRecentCheckResultsForFile(fileName, opts)
| ResultOrString.Ok (opts, text, line) ->
let! result = checker.TryGetRecentCheckResultsForFile(fileName, opts, text)
let symbolUse = result.TryGetSymbolUse pos line
return! Some (symbol, symbolUse)
else
Expand All @@ -50,9 +50,9 @@ type CodeGenerationService(checker : FSharpCompilerServiceChecker, state : State
member x.ParseFileInProject(fileName) =
match state.TryGetFileCheckerOptionsWithLines fileName with
| ResultOrString.Error _ -> None
| ResultOrString.Ok (opts, lines) ->
| ResultOrString.Ok (opts, text) ->
try
checker.TryGetRecentCheckResultsForFile(fileName, opts) |> Option.map (fun n -> n.GetParseResults)
checker.TryGetRecentCheckResultsForFile(fileName, opts, text) |> Option.map (fun n -> n.GetParseResults)
with
| _ -> None

Expand Down
61 changes: 28 additions & 33 deletions src/FsAutoComplete.Core/Commands.fs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,14 @@ type Commands

let parseFilesInTheBackground files =
async {
let rec loopForProjOpts file = async {
match state.GetProjectOptions file with
| None ->
do! Async.Sleep (TimeSpan.FromSeconds 1.)
return! loopForProjOpts file
| Some opts -> return Utils.projectOptionsToParseOptions opts
}

for file in files do
try
let sourceOpt =
Expand Down Expand Up @@ -377,11 +385,8 @@ type Commands
match sourceOpt with
| None -> ()
| Some source ->
let opts =
state.GetProjectOptions' file
|> Utils.projectOptionsToParseOptions

async {
let! opts = loopForProjOpts file
let! parseRes = checker.ParseFile(file, source, opts)
fileParsed.Trigger parseRes
}
Expand Down Expand Up @@ -675,13 +680,16 @@ type Commands
state.GetCancellationTokens filename
|> List.iter (fun cts -> cts.Cancel())

member x.TryGetRecentTypeCheckResultsForFile(file: string<LocalPath>, opts) =
checker.TryGetRecentCheckResultsForFile(file, opts)
member x.TryGetRecentTypeCheckResultsForFile(file: string<LocalPath>) =
match state.TryGetFileCheckerOptionsWithLines file with
| Ok (opts, text) ->
checker.TryGetRecentCheckResultsForFile(file, opts, text)
| _ -> None

///Gets recent type check results, waiting for the results of in-progress type checking
/// if version of file in memory is grater than last type checked version.
/// if version of file in memory is greater than last type checked version.
/// It also waits if there are no FSharpProjectOptions available for given file
member x.TryGetLatestTypeCheckResultsForFile(file: string<LocalPath>) =
member x.GetLatestTypeCheckResultsForFile(file: string<LocalPath>) =
let stateVersion = state.TryGetFileVersion file
let checkedVersion = state.TryGetLastCheckedVersion file

Expand All @@ -698,28 +706,23 @@ type Commands
|> Event.filter (fun (_, n, _) -> n = file)
|> Event.map ignore
|> Async.AwaitEvent
|> Async.bind (fun _ -> x.TryGetLatestTypeCheckResultsForFile(file))
|> Async.bind (fun _ -> x.GetLatestTypeCheckResultsForFile(file))
| Some _, None
| None, Some _ ->
x.FileChecked
|> Event.filter (fun (_, n, _) -> n = file)
|> Event.map ignore
|> Async.AwaitEvent
|> Async.bind (fun _ -> x.TryGetLatestTypeCheckResultsForFile(file))
|> Async.bind (fun _ -> x.GetLatestTypeCheckResultsForFile(file))
| _ ->
match state.TryGetFileCheckerOptionsWithLines(file) with
| ResultOrString.Ok (opts, _) ->
x.TryGetRecentTypeCheckResultsForFile(file, opts)
|> async.Return
| ResultOrString.Error _ ->
match x.TryGetRecentTypeCheckResultsForFile(file) with
| Some results -> async.Return results
| None ->
x.FileChecked
|> Event.filter (fun (_, n, _) -> n = file)
|> Event.map ignore
|> Async.AwaitEvent
|> Async.bind (fun _ -> x.TryGetLatestTypeCheckResultsForFile(file))



|> Async.bind (fun _ -> x.GetLatestTypeCheckResultsForFile(file))

member x.TryGetFileCheckerOptionsWithLinesAndLineStr(file: string<LocalPath>, pos) =
state.TryGetFileCheckerOptionsWithLinesAndLineStr(file, pos)
Expand Down Expand Up @@ -1334,7 +1337,7 @@ type Commands
asyncResult {
let! (opts, source) = state.TryGetFileCheckerOptionsWithLines file

let tyResOpt = checker.TryGetRecentCheckResultsForFile(file, opts)
let tyResOpt = checker.TryGetRecentCheckResultsForFile(file, opts, source)

match tyResOpt with
| None -> ()
Expand All @@ -1352,7 +1355,7 @@ type Commands
asyncResult {
let! (opts, source) = state.TryGetFileCheckerOptionsWithLines file

match checker.TryGetRecentCheckResultsForFile(file, opts) with
match checker.TryGetRecentCheckResultsForFile(file, opts, source) with
| None -> return ()
| Some tyRes ->
let! unused = UnusedOpens.getUnusedOpens (tyRes.GetCheckResults, (fun i -> source.GetLineString(i - 1)))
Expand Down Expand Up @@ -1468,18 +1471,10 @@ type Commands
/// gets the semantic classification ranges for a file, optionally filtered by a given range.
member x.GetHighlighting(file: string<LocalPath>, range: Range option) =
async {
let! res = x.TryGetLatestTypeCheckResultsForFile file

let res =
match res with
| Some res ->
let r = res.GetCheckResults.GetSemanticClassification(range)

let filteredRanges = scrubRanges r
Some filteredRanges
| None -> None

return CoreResponse.Res res
let! res = x.GetLatestTypeCheckResultsForFile file
let r = res.GetCheckResults.GetSemanticClassification(range)
let filteredRanges = scrubRanges r
return CoreResponse.Res filteredRanges
}

member __.SetWorkspaceRoot(root: string option) = workspaceRoot <- root
Expand Down
4 changes: 2 additions & 2 deletions src/FsAutoComplete.Core/CompilerServiceInterface.fs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ type FSharpCompilerServiceChecker(backgroundServiceEnabled, hasAnalyzers) =
| ex -> return ResultOrString.Error(ex.ToString())
}

member __.TryGetRecentCheckResultsForFile(file: string<LocalPath>, options, ?source) =
member __.TryGetRecentCheckResultsForFile(file: string<LocalPath>, options, source) =
let opName = sprintf "TryGetRecentCheckResultsForFile - %A" file

checkerLogger.info
Expand All @@ -338,7 +338,7 @@ type FSharpCompilerServiceChecker(backgroundServiceEnabled, hasAnalyzers) =

let options = clearProjectReferences options

checker.TryGetRecentCheckResultsForFile(UMX.untag file, options, ?sourceText = source, userOpName = opName)
checker.TryGetRecentCheckResultsForFile(UMX.untag file, options, sourceText = source, userOpName = opName)
|> Option.map (fun (pr, cr, _) -> ParseAndCheckResults(pr, cr, entityCache))

member x.GetUsesOfSymbol
Expand Down
32 changes: 19 additions & 13 deletions src/FsAutoComplete.Core/Debug.fs
Original file line number Diff line number Diff line change
Expand Up @@ -66,29 +66,35 @@ module Debug =
override __.OnEventWritten eventArgs =

let message =
match eventArgs.EventName with
| "Log" -> Log.setMessage "Inside Compiler Function {function}" >> logFunctionName eventArgs.Payload.[0]
| "LogMessage" -> Log.setMessage "({function}) {message}" >> logFunctionName eventArgs.Payload.[1] >> Log.addContextDestructured "message" (eventArgs.Payload.[0] :?> string)
| "BlockStart" | "BlockMessageStart" ->
match eventArgs.EventId with
| 0 -> Log.setMessage (string eventArgs.Payload.[0])
| 1 -> Log.setMessage "In {function}" >> logFunctionName eventArgs.Payload.[0]
| 2 -> Log.setMessage "{function}: {message}" >> logFunctionName eventArgs.Payload.[1] >> Log.addContextDestructured "message" eventArgs.Payload.[0]
| 3 ->
inflightEvents.TryAdd(eventArgs.Task, DateTimeOffset.UtcNow) |> ignore
id
| "BlockEnd" ->
Log.setMessage "Started {function}" >> logFunctionName eventArgs.Payload.[0]
| 4 ->
match inflightEvents.TryRemove(eventArgs.Task) with
| true, startTime ->
let delta = DateTimeOffset.UtcNow - startTime
Log.setMessage "Finished compiler function {function} in {seconds}" >> logFunctionName eventArgs.Payload.[0] >> Log.addContextDestructured "seconds" delta.TotalSeconds
| false, _ -> id
| "BlockMessageStop" ->
Log.setMessage "Finished {function} in {seconds}" >> logFunctionName eventArgs.Payload.[0] >> Log.addContextDestructured "seconds" delta.TotalSeconds
| false, _ ->
Log.setMessage "Finished {function}" >> logFunctionName eventArgs.Payload.[0]
| 5 ->
inflightEvents.TryAdd(eventArgs.Task, DateTimeOffset.UtcNow) |> ignore
Log.setMessage "Started {function}: {message}" >> logFunctionName eventArgs.Payload.[1] >> Log.addContextDestructured "message" eventArgs.Payload.[0]
| 6 ->
match inflightEvents.TryRemove(eventArgs.Task) with
| true, startTime ->
let delta = DateTimeOffset.UtcNow - startTime
Log.setMessage "Finished compiler function {function} with parameter {parameter} in {seconds}"
Log.setMessage "Finished {function}: {message} ({seconds} seconds)"
>> logFunctionName eventArgs.Payload.[1]
>> Log.addContextDestructured "seconds" delta.TotalSeconds
>> Log.addContextDestructured "parameter" (eventArgs.Payload.[0])
| false, _ -> id
>> Log.addContextDestructured "message" (eventArgs.Payload.[0])
| false, _ ->
Log.setMessage "Finished {function}: {message}" >> logFunctionName eventArgs.Payload.[1] >> Log.addContextDestructured "message" eventArgs.Payload.[0]
| other ->
Log.setMessage "Unknown event {name} with payload {payload}" >> Log.addContextDestructured "name" eventArgs.EventName >> Log.addContextDestructured "payload" (eventArgs.Payload |> Seq.toList)
Log.setMessage "Unknown event {name}({id}) with payload {payload}" >> Log.addContext "id" other >> Log.addContextDestructured "name" eventArgs.EventName >> Log.addContextDestructured "payload" (eventArgs.Payload |> Seq.toList)

(eventLevelToLogLevel eventArgs.Level) message

Expand Down
1 change: 0 additions & 1 deletion src/FsAutoComplete.Core/Sourcelink.fs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ let private compareRepoPath (d: Document) targetFile =
if Environment.isWindows then
let s = UMX.untag d.Name
let s' = normalizePath s |> UMX.untag
let s' = s'.Replace(@"\", "/")
let s' = UMX.tag<NormalizedRepoPathSegment> s'
s' = targetFile
else
Expand Down
Loading

0 comments on commit 3e71b75

Please sign in to comment.