Skip to content

Commit

Permalink
update analyzer SDK and FSAC code
Browse files Browse the repository at this point in the history
  • Loading branch information
baronfel committed Mar 8, 2020
1 parent 130e6a9 commit cc3351c
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 10 deletions.
4 changes: 2 additions & 2 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ NUGET
FParsec (1.1.1)
FSharp.Core (>= 4.3.4)
System.ValueTuple (>= 4.4) - restriction: || (== net461) (&& (== netcoreapp2.1) (>= net45)) (&& (== netstandard2.0) (>= net45))
FSharp.Analyzers.SDK (0.3.1)
FSharp.Compiler.Service (>= 34.1) - restriction: || (&& (== net461) (>= netcoreapp2.0)) (== netcoreapp2.1) (&& (== netstandard2.0) (>= netcoreapp2.0))
FSharp.Analyzers.SDK (0.4)
FSharp.Compiler.Service (>= 34.1.1) - restriction: || (&& (== net461) (>= netcoreapp2.0)) (== netcoreapp2.1) (&& (== netstandard2.0) (>= netcoreapp2.0))
FSharp.Core (>= 4.7) - restriction: || (&& (== net461) (>= netcoreapp2.0)) (== netcoreapp2.1) (&& (== netstandard2.0) (>= netcoreapp2.0))
McMaster.NETCore.Plugins (>= 1.1) - restriction: || (&& (== net461) (>= netcoreapp2.0)) (== netcoreapp2.1) (&& (== netstandard2.0) (>= netcoreapp2.0))
FSharp.Compiler.Service (34.1.1)
Expand Down
23 changes: 21 additions & 2 deletions src/FsAutoComplete/FsAutoComplete.Lsp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -435,15 +435,34 @@ type FsharpLspServer(commands: Commands, lspClient: FSharpLspClient) =
Symbols = symbols
GetAllEntities = getAllEnts
}

let extractResultsFromAnalyzer (r: SDK.AnalysisResult) =
match r.Output with
| Ok results ->
Loggers.analyzers.info (Log.setMessage "Analyzer {analyzer} returned {count} diagnostics for file {file}"
>> Log.addContextDestructured "analyzer" r.AnalyzerName
>> Log.addContextDestructured "count" results.Length
>> Log.addContextDestructured "file" file)
results
| Error e ->
Loggers.analyzers.error (Log.setMessage "Analyzer {analyzer} errored while processing {file}: {message}"
>> Log.addContextDestructured "analyzer" r.AnalyzerName
>> Log.addContextDestructured "file" file
>> Log.addContextDestructured "message" e.Message
>> Log.addExn e)
[]

try
SDK.Client.runAnalyzers ctx |> Array.ofList |> box
SDK.Client.runAnalyzersSafely ctx
|> List.collect extractResultsFromAnalyzer
|> box
with
| ex ->
Loggers.analyzers.error (Log.setMessage "Error while processing analyzers for {file}: {message}"
>> Log.addContextDestructured "message" ex.Message
>> Log.addExn ex
>> Log.addContextDestructured "file" file)
box [||]
box []
commands.AnalyzerHandler <- Some analyzerHandler
#endif
let c =
Expand Down
4 changes: 0 additions & 4 deletions src/FsAutoComplete/FsAutoComplete.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.1' ">
<DefineConstants>ANALYZER_SUPPORT;$(DefineConstants);</DefineConstants>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.1' ">
<PackageReference Include="FSharp.Analyzers.SDK" Version="0.3.0" />
</ItemGroup>
<ItemGroup>
<Compile Include="Options.fs" />
<Compile Include="CommandResponse.fs" />
Expand All @@ -37,7 +34,6 @@
<ProjectReference Include="..\FsAutoComplete.BackgroundServices\FsAutoComplete.BackgroundServices.fsproj" />
<ProjectReference Include="..\LanguageServerProtocol\LanguageServerProtocol.fsproj" />
<ProjectReference Include="..\ProjectSystem\ProjectSystem.fsproj" />

</ItemGroup>

<!-- do not bundle the net461 exe inside the .net core tool package -->
Expand Down
1 change: 1 addition & 0 deletions src/FsAutoComplete/paket.references
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ FSharp.Data
Microsoft.Data.Sqlite
ICSharpCode.Decompiler
Fantomas
FSharp.Analyzers.SDK framework: netcoreapp2.1

Serilog
Serilog.Sinks.File
Expand Down
5 changes: 4 additions & 1 deletion test/FsAutoComplete.Tests.Lsp/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,9 @@ let analyzerTests =
EnableAnalyzers = Some true
AnalyzersPath = Some [| analyzerPath |] }

Helpers.runProcess (logDotnetRestore "RenameTest") path "dotnet" "restore"
|> expectExitCodeZero

let (server, events) = serverInitialize path analyzerEnabledConfig
let scriptPath = Path.Combine(path, "Script.fs")
do waitForWorkspaceFinishedParsing events
Expand All @@ -1052,7 +1055,7 @@ let analyzerTests =
let serverTest f () = f serverStart.Value

testList "analyzer integration" [
testCase "can run analyzer on file" (serverTest (fun (server, events, rootPath, testFilePath) ->
ftestCase "can run analyzer on file" (serverTest (fun (server, events, rootPath, testFilePath) ->
do server.TextDocumentDidOpen { TextDocument = loadDocument testFilePath } |> Async.RunSynchronously
// now wait for analyzer events for the file:

Expand Down
2 changes: 1 addition & 1 deletion test/OptionAnalyzer/Analyzer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ let notUsed() =
let option : Option<int> = None
option.Value

[<Analyzer>]
[<Analyzer "OptionAnalyzer">]
let optionValueAnalyzer : Analyzer =
fun ctx ->
let state = ResizeArray<range>()
Expand Down

0 comments on commit cc3351c

Please sign in to comment.