@@ -211,6 +211,7 @@ type Server(client: ILanguageClient) as this =
211211 let checker = FSharpChecker.Create()
212212 let projects = ProjectManager( checker)
213213 let mutable codelensShowReferences = true
214+ let mutable showUnusedDeclarations = true
214215
215216 /// Get a file from docs, or read it from disk
216217 let getOrRead ( file : FileInfo ): string option =
@@ -303,7 +304,6 @@ type Server(client: ILanguageClient) as this =
303304
304305 /// When did we last check each file on disk?
305306 let lastCheckedOnDisk = dict< string, DateTime>()
306- // TODO there might be a thread safety issue here---is this getting called from a separate thread?
307307 do checker.BeforeBackgroundFileCheck.Add( fun ( fileName , _ ) ->
308308 let file = FileInfo( fileName)
309309 lastCheckedOnDisk.[ file.FullName] <- file.LastWriteTime)
@@ -344,23 +344,28 @@ type Server(client: ILanguageClient) as this =
344344 | Ok( parseResult, checkResult) ->
345345 let parseErrors = asDiagnostics( parseResult.Errors)
346346 let typeErrors = asDiagnostics( checkResult.Errors)
347+ let! uses = checkResult.GetAllUsesOfAllSymbolsInFile()
348+ fileSymbolUses.[ file.FullName] <- Array.map ( fun ( x : FSharpSymbolUse ) -> x.Symbol.FullName) uses
347349 // This is just too slow. Also, it's sometimes wrong.
348350 // Find unused opens
349351 // let timeUnusedOpens = Stopwatch.StartNew()
350352 // let! unusedOpenRanges = UnusedOpens.getUnusedOpens(checkResult, fun(line) -> lineContent(file, line))
351353 // let unusedOpenErrors = [for r in unusedOpenRanges do yield diagnostic("Unused open", r, DiagnosticSeverity.Information)]
352354 // dprintfn "Found %d unused opens in %dms" unusedOpenErrors.Length timeUnusedOpens.ElapsedMilliseconds
355+ let unusedOpenErrors = []
356+
353357 // Find unused declarations
354- let timeUnusedDeclarations = Stopwatch.StartNew()
355- let! uses = checkResult.GetAllUsesOfAllSymbolsInFile()
356- let unusedDeclarationRanges = UnusedDeclarations.getUnusedDeclarationRanges( uses, file.Name.EndsWith( " .fsx" ))
357- let unusedDeclarationErrors = [ for r in unusedDeclarationRanges do yield diagnostic( " Unused declaration" , r, DiagnosticSeverity.Hint)]
358- dprintfn " Found %d unused declarations in %d ms" unusedDeclarationErrors.Length timeUnusedDeclarations.ElapsedMilliseconds
358+ let unusedDeclarationErrors =
359+ if showUnusedDeclarations then
360+ let timeUnusedDeclarations = Stopwatch.StartNew()
361+ let unusedDeclarationRanges = UnusedDeclarations.getUnusedDeclarationRanges( uses, file.Name.EndsWith( " .fsx" ))
362+ let unusedDeclarationErrors = [ for r in unusedDeclarationRanges do yield diagnostic( " Unused declaration" , r, DiagnosticSeverity.Hint)]
363+ dprintfn " Found %d unused declarations in %d ms" unusedDeclarationErrors.Length timeUnusedDeclarations.ElapsedMilliseconds
364+ unusedDeclarationErrors
365+ else []
359366
360- fileSymbolUses.[ file.FullName] <- Array.map ( fun ( x : FSharpSymbolUse ) -> x.Symbol.FullName) uses
361367 // Combine
362- // return parseErrors@typeErrors@unusedOpenErrors@unusedDeclarationErrors
363- return parseErrors@ typeErrors@ unusedDeclarationErrors
368+ return parseErrors@ typeErrors@ unusedOpenErrors@ unusedDeclarationErrors
364369 }
365370 let doCheck ( file : FileInfo ): Async < unit > =
366371 async {
@@ -618,6 +623,7 @@ type Server(client: ILanguageClient) as this =
618623 projects.ConditionalCompilationDefines <- List.ofArray fsconfig.Project.Define
619624 projects.OtherCompilerFlags <- List.ofArray fsconfig.Project.OtherFlags
620625 codelensShowReferences <- fsconfig.Codelens.References
626+ showUnusedDeclarations <- fsconfig.Analysis.UnusedDeclaration
621627 ProjectCracker.includeCompileBeforeItems <- fsconfig.Project.IncludeCompileBefore
622628 dprintfn " New configuration %O " ( fsconfig.JsonValue)
623629
@@ -833,11 +839,11 @@ type Server(client: ILanguageClient) as this =
833839 }
834840
835841 /// <summary>
836- /// TODO match: [fsharp 39: typecheck] [E] The value, namespace, type or module 'Thread' is not defined.
842+ /// match: [fsharp 39: typecheck] [E] The value, namespace, type or module 'Thread' is not defined.
837843 /// then: 1. search a reflection-based cache for a matching entry. if found, suggest opening a module/namespace
838844 /// 2. search for workspace symbol. if found, suggest opening a module/namespace
839- /// 3. search for nuget packages
840- /// 4. off-by-one corrections
845+ /// TODO 3. search for nuget packages
846+ /// TODO 4. off-by-one corrections
841847 /// TODO match: [fsharp] [H] Unused declaration
842848 /// then: 1. offer refactoring to _
843849 /// 2. offer refactoring to __
0 commit comments