Skip to content

Commit

Permalink
Fix naming
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAngryByrd committed Jun 27, 2023
1 parent 787eb05 commit 6871bfe
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 28 deletions.
6 changes: 3 additions & 3 deletions src/FsAutoComplete.Core/AdaptiveExtensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ module AsyncAVal =


/// <summary>
/// Returns a new async adaptive value that adaptively applies the mapping fun tion to the given
/// Returns a new async adaptive value that adaptively applies the mapping function to the given
/// adaptive inputs.
/// </summary>
let map (mapping: 'a -> CancellationToken -> Task<'b>) (input: asyncaval<'a>) =
Expand Down Expand Up @@ -573,7 +573,7 @@ module AsyncAVal =


/// <summary>
/// Returns a new async adaptive value that adaptively applies the mapping fun tion to the given
/// Returns a new async adaptive value that adaptively applies the mapping function to the given
/// adaptive inputs.
/// </summary>
let mapAsync (mapping: 'a -> Async<'b>) (input: asyncaval<'a>) =
Expand Down Expand Up @@ -605,7 +605,7 @@ module AsyncAVal =


/// <summary>
/// Returns a new async adaptive value that adaptively applies the mapping fun tion to the given
/// Returns a new async adaptive value that adaptively applies the mapping function to the given
/// adaptive inputs.
/// </summary>
let mapSync (mapping: 'a -> CancellationToken -> 'b) (input: asyncaval<'a>) =
Expand Down
2 changes: 1 addition & 1 deletion src/FsAutoComplete.Core/Commands.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1349,7 +1349,7 @@ type Commands
let text = sourceTextFactory.Create(file, ctn)

state.Files.[file] <-
{ Touched = DateTime.Now
{ LastTouched = DateTime.Now
Source = text
Version = None }

Expand Down
24 changes: 11 additions & 13 deletions src/FsAutoComplete.Core/FileSystem.fs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ type NamedText(fileName: string<LocalPath>, str: string) =
startRange, endRange

/// create a new IFSACSourceText for this file with the given text inserted at the given range.
member x.ModifyText(m: FSharp.Compiler.Text.Range, text: string) : Result<IFSACSourceText, string> =
member x.ModifyText(m: FSharp.Compiler.Text.Range, text: string) : Result<NamedText, string> =
result {
let startRange, endRange = x.SplitAt(m)
let! startText = x[startRange] |> Result.mapError (fun x -> $"startRange -> {x}")
Expand Down Expand Up @@ -442,8 +442,7 @@ type NamedText(fileName: string<LocalPath>, str: string) =
member x.TryGetNextChar p = x.TryGetNextChar p
member x.PrevPos p = x.PrevPos p
member x.TryGetPrevChar p = x.TryGetPrevChar p

member x.ModifyText(r, t) = x.ModifyText(r, t)
member x.ModifyText(r, t) = x.ModifyText(r, t) |> Result.map unbox

member x.Item
with get (m: FSharp.Compiler.Text.Range) = x.Item m
Expand Down Expand Up @@ -712,7 +711,6 @@ type ISourceTextFactory =
type NamedTextFactory() =
interface ISourceTextFactory with
member this.Create(fileName: string<LocalPath>, text: string) : IFSACSourceText = NamedText(fileName, text)

member this.Create(fileName: string<LocalPath>, stream: Stream) : ValueTask<IFSACSourceText> =
valueTask {
use reader = new StreamReader(stream)
Expand All @@ -734,14 +732,15 @@ type RoslynSourceTextFactory() =
|> ValueTask.FromResult

module File =
let getLastWriteTimeOrDefaultNow (path: string) =
let getLastWriteTimeOrDefaultNow (path: string<LocalPath>) =
let path = UMX.untag path
if File.Exists path then
File.GetLastWriteTimeUtc path
else
DateTime.UtcNow

type VolatileFile =
{ Touched: DateTime
{ LastTouched: DateTime
Source: IFSACSourceText
Version: int option }

Expand All @@ -751,25 +750,24 @@ type VolatileFile =
member this.SetSource(source) = { this with Source = source }

/// <summary>Updates the Touched value</summary>
member this.SetTouched touched = { this with Touched = touched }
member this.SetLastTouched touched = { this with LastTouched = touched }

/// <summary>Updates the Touched value attempting to use the file on disk's GetLastWriteTimeUtc otherwise uses DateTime.UtcNow. </summary>
member this.UpdateTouched() =
let path = UMX.untag this.Source.FileName
let dt = File.getLastWriteTimeOrDefaultNow path
this.SetTouched dt
let dt = File.getLastWriteTimeOrDefaultNow this.Source.FileName
this.SetLastTouched dt


/// <summary>Helper method to create a VolatileFile</summary>
static member Create(source: IFSACSourceText, ?version: int, ?touched: DateTime) =
let touched =
match touched with
| Some t -> t
| None -> File.getLastWriteTimeOrDefaultNow source.RawFileName
| None -> File.getLastWriteTimeOrDefaultNow source.FileName

{ Source = source
Version = version
Touched = touched }
LastTouched = touched }

type FileSystem(actualFs: IFileSystem, tryFindFile: string<LocalPath> -> VolatileFile option) =
let fsLogger = LogProvider.getLoggerByName "FileSystem"
Expand Down Expand Up @@ -834,7 +832,7 @@ type FileSystem(actualFs: IFileSystem, tryFindFile: string<LocalPath> -> Volatil
filename
|> Utils.normalizePath
|> tryFindFile
|> Option.map (fun f -> f.Touched)
|> Option.map (fun f -> f.LastTouched)
|> Option.defaultWith (fun () -> actualFs.GetLastWriteTimeShim filename)

// fsLogger.debug (
Expand Down
6 changes: 3 additions & 3 deletions src/FsAutoComplete.Core/State.fs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ type State =
|> Option.map (fun opts ->
x.Files.[file] <-
{ Source = text
Touched = DateTime.Now
LastTouched = DateTime.Now
Version = None }

opts)
Expand Down Expand Up @@ -219,7 +219,7 @@ type State =
member x.AddFileTextAndCheckerOptions(file: string<LocalPath>, text: IFSACSourceText, opts, version) =
let fileState =
{ Source = text
Touched = DateTime.Now
LastTouched = DateTime.Now
Version = version }

x.Files.[file] <- fileState
Expand All @@ -228,7 +228,7 @@ type State =
member x.AddFileText(file: string<LocalPath>, text: IFSACSourceText, version) =
let fileState =
{ Source = text
Touched = DateTime.Now
LastTouched = DateTime.Now
Version = version }

x.Files.[file] <- fileState
Expand Down
13 changes: 5 additions & 8 deletions src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ type AdaptiveFSharpLspServer

match parseAndCheck.GetCheckResults.ImplementationFile with
| Some tast ->
do! Async.SwitchToNewThread()
// do! Async.SwitchToNewThread()

let res =
Commands.analyzerHandler (
Expand Down Expand Up @@ -843,7 +843,7 @@ type AdaptiveFSharpLspServer
logger.debug (
Log.setMessage "TextChanged for file : {fileName} {touched} {version}"
>> Log.addContextDestructured "fileName" v.FileName
>> Log.addContextDestructured "touched" v.Touched
>> Log.addContextDestructured "touched" v.LastTouched
>> Log.addContextDestructured "version" v.Version
)

Expand Down Expand Up @@ -936,7 +936,7 @@ type AdaptiveFSharpLspServer
else
let inline getSourceFromFile untaggedFile =
async {
do! Async.SwitchToNewThread()
// do! Async.SwitchToNewThread()
use s = File.OpenRead(untaggedFile)
return! sourceTextFactory.Create(localPath, s) |> Async.AwaitValueTask
}
Expand All @@ -947,7 +947,7 @@ type AdaptiveFSharpLspServer
let! source = getSourceFromFile untagged |> AsyncAVal.ofAsync

let file =
{ Touched = lastWriteTime
{ LastTouched = lastWriteTime
Source = source
Version = None }

Expand Down Expand Up @@ -993,8 +993,6 @@ type AdaptiveFSharpLspServer
let forceFindOpenFile filePath =
findFileInOpenFiles filePath |> AVal.force



let forceFindOpenFileOrRead file =
asyncOption {

Expand Down Expand Up @@ -1029,7 +1027,6 @@ type AdaptiveFSharpLspServer
// flattening openFilesWithChanges makes this check a lot quicker as it's not needing to recalculate each value.

fileshimChanges |> AMap.force |> HashMap.tryFind file
// |> Option.orElseWith(fun () -> try (getCachedSourceFiles file |> AsyncAVal.force).Task.GetAwaiter().GetResult() with _ -> None)

FSharp.Compiler.IO.FileSystemAutoOpens.FileSystem <-
FileSystem(FSharp.Compiler.IO.FileSystemAutoOpens.FileSystem, filesystemShim)
Expand Down Expand Up @@ -1176,7 +1173,7 @@ type AdaptiveFSharpLspServer
Log.setMessage "Getting typecheck results for {file} - {hash} - {date}"
>> Log.addContextDestructured "file" file.Source.FileName
>> Log.addContextDestructured "hash" (file.Source.GetHashCode())
>> Log.addContextDestructured "date" (file.Touched)
>> Log.addContextDestructured "date" (file.LastTouched)
)

let! ct = Async.CancellationToken
Expand Down

0 comments on commit 6871bfe

Please sign in to comment.