Skip to content

Commit f322248

Browse files
committed
Getting recent typechecks is actually possible now
Previously the code compaired the file version number as managed by the vscode language server with the file hash given by FCS. Now we hash the file and compair using that hash. Also we now pass the source code in, without which we could never get recent results. This should result in some serious speedups and stop that problem where files constantly get rechecked.
1 parent d5e63db commit f322248

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

src/FSharpLanguageServer/Program.fs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,9 @@ type Server(client: ILanguageClient) =
229229
| _, None ->
230230
return Error(sprintf "%s was closed" file.FullName)
231231
| Ok(projectOptions), Some(sourceText) ->
232-
match checker.TryGetRecentCheckResultsForFile(file.FullName, projectOptions) with
232+
match checker.TryGetRecentCheckResultsForFile(file.FullName, projectOptions,sourceText|>SourceText.ofString) with
233233
| Some(parse, _, _) ->
234+
lgVerb "Getting cached parsing for file {@file}"file.FullName
234235
return Ok parse
235236
| None ->
236237
try
@@ -265,10 +266,11 @@ type Server(client: ILanguageClient) =
265266
| parseResult, FSharpCheckFileAnswer.Succeeded(checkResult) -> return Ok(parseResult, checkResult)
266267
}
267268

268-
match checker.TryGetRecentCheckResultsForFile(file.FullName, projectOptions) with
269-
| Some(parseResult, checkResult, version) ->
270-
lgVerb2 "Getting typecheck for file with version {newVers}, previous version {oldVers}" sourceVersion version
271-
if allowCached && version = sourceVersion then
269+
match checker.TryGetRecentCheckResultsForFile(file.FullName, projectOptions,SourceText.ofString sourceText) with
270+
| Some(parseResult, checkResult, hash) ->
271+
let newHash= sourceText.GetHashCode()
272+
lgVerb2 "Getting typecheck for file with hash {newHash}, previous hash {oldHash}" newHash hash
273+
if allowCached && hash = newHash then
272274
lgInfof "cached allowed and version is same,using recent Typecheck results"
273275
return Ok(parseResult, checkResult)
274276
else if allowCached && allowStale then
@@ -280,7 +282,7 @@ type Server(client: ILanguageClient) =
280282
lgInfof "Re-compile timed out, using stale results"
281283
return Ok(parseResult, checkResult)
282284
else
283-
lgInfo2 "Checking: cannot use stale results and currentVersion {currentVers} did not match cached version {cachedVers}" version sourceVersion
285+
lgInfo2 "Checking: cannot use stale results and currenthash {currentVers} did not match cached hash {cachedVers}" newHash hash
284286
return! recompile
285287
| _ ->
286288
lgInfof "recompiling file becuase could not get parseTesult or checkResult"

src/FSharpLanguageServer/ProjectManager.fs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,9 @@ type ProjectManager(checker: FSharpChecker) =
348348

349349

350350
/// All transitive deps of anproject, including itself
351-
let transitiveDeps(fsprojOrFsx: FileInfo) = //TODO: this is terrible project checker is stupid solution to this problem
351+
let transitiveDeps (fsprojOrFsx: FileInfo) = //TODO: this is terrible project checker is stupid solution to this problem
352+
let timer=Diagnostics.Stopwatch.StartNew()
353+
352354
let touched = new HashSet<String>()
353355
let result = new List<FSharpProjectOptions>()
354356
let rec walk(options: FSharpProjectOptions) =
@@ -361,7 +363,10 @@ type ProjectManager(checker: FSharpChecker) =
361363
result.Add(options)
362364
let root = cache.Get(fsprojOrFsx, analyzeLater)
363365
walk(root.resolved.Value.options)
364-
List.ofSeq(result)
366+
let deps=List.ofSeq(result)
367+
timer.Stop()
368+
lgDebug2 "Getting transitive deps for {@file} took {@time}ms" fsprojOrFsx.Name timer.ElapsedMilliseconds
369+
deps
365370
/// Find all .fsproj files referenced by a .sln file
366371
let slnProjectReferences (sln: FileInfo): list<FileInfo> =
367372
// From https://github.com/OmniSharp/omnisharp-roslyn/blob/master/src/OmniSharp.MSBuild/SolutionParsing/ProjectBlock.cs
@@ -480,7 +485,8 @@ type ProjectManager(checker: FSharpChecker) =
480485
/// All transitive dependencies of `projectFile`, in dependency order
481486
member this.TransitiveDeps(projectFile: FileInfo): FSharpProjectOptions list =
482487
//transitiveDeps(projectFile)(fun x ->this.FindProjectOptions (FileInfo(x.FileName))) //TODO: this might be terrible
483-
transitiveDeps(projectFile)
488+
transitiveDeps (projectFile)
489+
484490
/// Is `targetSourceFile` visible from `fromSourceFile`?
485491
member this.IsVisible(targetSourceFile: FileInfo, fromSourceFile: FileInfo) =
486492
match this.FindProjectOptions(fromSourceFile) with

src/LSP/DocumentStore.fs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ open System.Collections.Generic
77
open System.Text
88
open Types
99
open BaseTypes
10-
type private Version = {
10+
open FSharp
11+
type private VolatileFile = {
1112
text: StringBuilder
1213
mutable version: int
1314
}
@@ -36,7 +37,7 @@ open DocumentStoreUtils
3637

3738
type DocumentStore() =
3839
/// All open documents, organized by absolute path
39-
let activeDocuments = new Dictionary<string, Version>()
40+
let activeDocuments = new Dictionary<string, VolatileFile>()
4041
/// Replace a section of an open file
4142
let patch(doc: VersionedTextDocumentIdentifier, range: Range, text: string): unit =
4243
let file = FileInfo(doc.uri.LocalPath)

0 commit comments

Comments
 (0)