Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure Analyzer Loading failures are shown to user properly #1350

Open
5 tasks done
TheAngryByrd opened this issue Jan 21, 2025 · 2 comments
Open
5 tasks done

Ensure Analyzer Loading failures are shown to user properly #1350

TheAngryByrd opened this issue Jan 21, 2025 · 2 comments
Labels

Comments

@TheAngryByrd
Copy link
Member

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
@TheAngryByrd
Copy link
Member Author

Initial discussion: ionide/FSharp.Analyzers.SDK#225 (comment)

@TheAngryByrd
Copy link
Member Author

Since we use Serilog, using something like: https://github.com/serilog/serilog-extensions-logging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant