Skip to content

Ensure Analyzer Loading failures are shown to user properly #1350

@TheAngryByrd

Description

@TheAngryByrd

Version

v0.75.0

Dotnet Info

n/a

Steps to reproduce

let analyzersClient =
FSharp.Analyzers.SDK.Client<FSharp.Analyzers.SDK.EditorAnalyzerAttribute, FSharp.Analyzers.SDK.EditorContext>(
Microsoft.Extensions.Logging.Abstractions.NullLogger.Instance
)
/// <summary>Loads F# Analyzers from the configured directories</summary>
/// <param name="config">The FSharpConfig</param>
/// <param name="rootPath">The RootPath</param>
/// <returns></returns>
let loadAnalyzers (config: FSharpConfig) (rootPath: string option) =
if config.EnableAnalyzers then
Loggers.analyzers.info (Log.setMessageI $"Using analyzer roots of {config.AnalyzersPath:roots}")
let excludeInclude =
match config.ExcludeAnalyzers, config.IncludeAnalyzers with
| e, [||] -> FSharp.Analyzers.SDK.ExcludeInclude.ExcludeFilter(fun (s: string) -> Array.contains s e)
| [||], i -> FSharp.Analyzers.SDK.ExcludeInclude.IncludeFilter(fun (s: string) -> Array.contains s i)
| _e, i ->
Loggers.analyzers.warn (
Log.setMessage
"--exclude-analyzers and --include-analyzers are mutually exclusive, ignoring --exclude-analyzers"
)
FSharp.Analyzers.SDK.ExcludeInclude.IncludeFilter(fun (s: string) -> Array.contains s i)
config.AnalyzersPath
|> Array.iter (fun analyzerPath ->
match rootPath with
| None -> ()
| Some workspacePath ->
let dir =
if
System.IO.Path.IsPathRooted analyzerPath
// if analyzer is using absolute path, use it as is
then
analyzerPath
// otherwise, it is a relative path and should be combined with the workspace path
else
System.IO.Path.Combine(workspacePath, analyzerPath)
Loggers.analyzers.info (Log.setMessageI $"Loading analyzers from {dir:dir}")
let assemblyLoadStats = analyzersClient.LoadAnalyzers(dir, excludeInclude)
Loggers.analyzers.info (
Log.setMessageI
$"From {analyzerPath:name}: {assemblyLoadStats.AnalyzerAssemblies:dllNo} dlls including {assemblyLoadStats.Analyzers:analyzersNo} analyzers"
))
else
Loggers.analyzers.info (Log.setMessage "Analyzers disabled")

Details

Should implement analyzer logger and possibly show a window error once.

Logs

No response

Checklist

  • I have looked through existing issues to make sure that this bug has not been reported before
  • I have provided a descriptive title for this issue
  • I have made sure that that this bug is reproducible on the latest version of the package
  • I have provided all the information needed to reproduce this bug as efficiently as possible
  • I or my company would be willing to contribute this fix

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions