Skip to content

Commit ae3559f

Browse files
authored
Allow analyzer to be loaded from nuget (#1419)
* Add FS3397 to NoWarn to prevent null runtime errors from unit usage * POC: Allow nuget packages for analyzers * Readd original analyzer support via fsharp config. Small optimizations around loading analyzers * Refactor AddMarkingCallback to support weak callbacks in AsyncAValExtensions * Add "Finalizer" to cSpell.words for improved spell checking * Update Analyzers and ProjInfo
1 parent 3ed5671 commit ae3559f

File tree

12 files changed

+269
-95
lines changed

12 files changed

+269
-95
lines changed

.config/dotnet-tools.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
"rollForward": false
1818
},
1919
"fantomas": {
20-
"version": "7.0.1",
20+
"version": "7.0.3",
2121
"commands": [
2222
"fantomas"
2323
],
2424
"rollForward": false
2525
},
2626
"fsharp-analyzers": {
27-
"version": "0.32.1",
27+
"version": "0.33.0",
2828
"commands": [
2929
"fsharp-analyzers"
3030
],
@@ -38,4 +38,4 @@
3838
"rollForward": false
3939
}
4040
}
41-
}
41+
}

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
"failtest",
7979
"Fantomas",
8080
"fantomasignore",
81+
"Finalizer",
8182
"foldi",
8283
"FSAC",
8384
"fsautocomplete",

Directory.Build.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
<WarnOn Condition="'$(Configuration)' != 'Debug'">$(WarnOn);1182</WarnOn> <!-- Unused
1212
variables,https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/compiler-options#opt-in-warnings -->
1313
<NoWarn>$(NoWarn);FS0044</NoWarn> <!-- Ignore deprecations -->
14+
<NoWarn>$(NoWarn);FS3397</NoWarn> <!-- This expression uses unit for an obj-typed argument. This will lead to passing null at runtime -->
1415
<WarnOn>$(WarnOn);3390</WarnOn><!-- Malformed XML doc comments -->
16+
1517
<!-- Package Reference with no usable assets -->
1618
<NoWarn>$(NoWarn);NU1701</NoWarn>
1719
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

paket.dependencies

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ storage: none
1111
nuget BenchmarkDotNet
1212
nuget Fantomas.Client >= 0.9
1313
nuget FSharp.Compiler.Service >= 43.9.300
14-
nuget Ionide.Analyzers 0.14.7
14+
nuget Ionide.Analyzers 0.14.9
1515
nuget FSharp.Analyzers.Build
16-
nuget Ionide.ProjInfo >= 0.71.2
17-
nuget Ionide.ProjInfo.FCS >= 0.71.2
18-
nuget Ionide.ProjInfo.ProjectSystem >= 0.71.2
16+
nuget Ionide.ProjInfo >= 0.72.0
17+
nuget Ionide.ProjInfo.FCS >= 0.72.0
18+
nuget Ionide.ProjInfo.ProjectSystem >= 0.72.0
1919
nuget Microsoft.Build >= 17.2 copy_local:false
2020
nuget Microsoft.Build.Framework >= 17.4 copy_local:false
2121
nuget Microsoft.Build.Utilities.Core >= 17.4 copy_local:false
2222
nuget Microsoft.Build.Tasks.Core >= 17.4 copy_local: false
2323
nuget Nuget.Frameworks >= 6.3 copy_local: false
2424
nuget Microsoft.CodeAnalysis
25-
nuget FSharp.Analyzers.SDK 0.32.1
25+
nuget FSharp.Analyzers.SDK 0.33.1
2626
nuget ICSharpCode.Decompiler
2727
nuget Mono.Cecil >= 0.11.4
2828
nuget FSharpLint.Core
@@ -63,4 +63,4 @@ nuget System.Text.RegularExpressions
6363

6464
## Test Explorer
6565
nuget Microsoft.TestPlatform.TranslationLayer
66-
nuget Microsoft.TestPlatform.ObjectModel
66+
nuget Microsoft.TestPlatform.ObjectModel

paket.lock

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ NUGET
5050
FParsec (1.1.1) - restriction: || (== net8.0) (== net9.0) (&& (== netstandard2.0) (>= net5.0)) (&& (== netstandard2.1) (>= net5.0))
5151
FSharp.Core (>= 4.3.4)
5252
FSharp.Analyzers.Build (0.3)
53-
FSharp.Analyzers.SDK (0.32.1)
53+
FSharp.Analyzers.SDK (0.33.1)
5454
FSharp.Compiler.Service (43.9.300) - restriction: || (== net8.0) (== net9.0) (&& (== netstandard2.0) (>= net8.0)) (&& (== netstandard2.1) (>= net8.0))
5555
FSharp.Core (9.0.300) - restriction: || (== net8.0) (== net9.0) (&& (== netstandard2.0) (>= net8.0)) (&& (== netstandard2.1) (>= net8.0))
5656
McMaster.NETCore.Plugins (>= 1.4) - restriction: || (== net8.0) (== net9.0) (&& (== netstandard2.0) (>= net8.0)) (&& (== netstandard2.1) (>= net8.0))
@@ -124,23 +124,23 @@ NUGET
124124
ICSharpCode.Decompiler (8.2.0.7535)
125125
System.Collections.Immutable (>= 6.0)
126126
System.Reflection.Metadata (>= 6.0)
127-
Ionide.Analyzers (0.14.7)
127+
Ionide.Analyzers (0.14.9)
128128
Ionide.KeepAChangelog.Tasks (0.1.8) - copy_local: true
129129
Ionide.LanguageServerProtocol (0.7)
130130
FSharp.Core (>= 6.0)
131131
Newtonsoft.Json (>= 13.0.1)
132132
StreamJsonRpc (>= 2.16.36)
133-
Ionide.ProjInfo (0.71.2)
133+
Ionide.ProjInfo (0.72)
134134
FSharp.Core (>= 6.0) - restriction: || (== net8.0) (== net9.0) (&& (== netstandard2.0) (>= net8.0)) (&& (== netstandard2.1) (>= net8.0))
135135
Microsoft.VisualStudio.SolutionPersistence (>= 1.0.28) - restriction: || (== net8.0) (== net9.0) (&& (== netstandard2.0) (>= net8.0)) (&& (== netstandard2.1) (>= net8.0))
136136
SemanticVersioning (>= 2.0.2) - restriction: || (== net8.0) (== net9.0) (&& (== netstandard2.0) (>= net8.0)) (&& (== netstandard2.1) (>= net8.0))
137-
Ionide.ProjInfo.FCS (0.71.2)
137+
Ionide.ProjInfo.FCS (0.72)
138138
FSharp.Compiler.Service (>= 43.9.300) - restriction: || (== net8.0) (== net9.0) (&& (== netstandard2.0) (>= net8.0)) (&& (== netstandard2.1) (>= net8.0))
139139
FSharp.Core (>= 9.0.300) - restriction: || (== net8.0) (== net9.0) (&& (== netstandard2.0) (>= net8.0)) (&& (== netstandard2.1) (>= net8.0))
140-
Ionide.ProjInfo (>= 0.71.2) - restriction: || (== net8.0) (== net9.0) (&& (== netstandard2.0) (>= net8.0)) (&& (== netstandard2.1) (>= net8.0))
141-
Ionide.ProjInfo.ProjectSystem (0.71.2)
140+
Ionide.ProjInfo (>= 0.72) - restriction: || (== net8.0) (== net9.0) (&& (== netstandard2.0) (>= net8.0)) (&& (== netstandard2.1) (>= net8.0))
141+
Ionide.ProjInfo.ProjectSystem (0.72)
142142
Fsharp.Control.Reactive (>= 5.0.5) - restriction: || (== net8.0) (== net9.0) (&& (== netstandard2.0) (>= net8.0)) (&& (== netstandard2.1) (>= net8.0))
143-
Ionide.ProjInfo.FCS (>= 0.71.2) - restriction: || (== net8.0) (== net9.0) (&& (== netstandard2.0) (>= net8.0)) (&& (== netstandard2.1) (>= net8.0))
143+
Ionide.ProjInfo.FCS (>= 0.72) - restriction: || (== net8.0) (== net9.0) (&& (== netstandard2.0) (>= net8.0)) (&& (== netstandard2.1) (>= net8.0))
144144
Newtonsoft.Json (>= 13.0.3) - restriction: || (== net8.0) (== net9.0) (&& (== netstandard2.0) (>= net8.0)) (&& (== netstandard2.1) (>= net8.0))
145145
LinkDotNet.StringBuilder (1.18)
146146
McMaster.NETCore.Plugins (1.4) - restriction: || (== net8.0) (== net9.0) (&& (== netstandard2.0) (>= net8.0)) (&& (== netstandard2.1) (>= net8.0))

src/FsAutoComplete.Core/AdaptiveExtensions.fs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,3 +937,52 @@ module AdaptiveFile =
937937
()
938938

939939
AdaptiveFile.GetLastWriteTimeUtc path
940+
941+
942+
[<AutoOpen>]
943+
module AsyncAValExtensions =
944+
type asyncaval<'T> with
945+
/// Adds a disposable callback to the aval that will be executed whenever the
946+
/// avals value changed.
947+
member value.AddCallback(weak: bool, action: 'T -> Async<unit>) : IDisposable =
948+
949+
let last = ref ValueNone
950+
951+
let sub =
952+
let cb =
953+
if weak then
954+
value.AddWeakMarkingCallback
955+
else
956+
value.AddMarkingCallback
957+
958+
cb (fun () ->
959+
let t = Transaction.Running.Value
960+
961+
t.AddFinalizer(fun () ->
962+
async {
963+
let! v = AsyncAVal.forceAsync value
964+
965+
match last.Value with
966+
| ValueSome o when DefaultEquality.equals o v -> ()
967+
| _ ->
968+
last.Value <- ValueSome v
969+
do! action v
970+
}
971+
|> Async.StartImmediate))
972+
973+
match Transaction.Running with
974+
| ValueSome t ->
975+
t.AddFinalizer(fun () ->
976+
async {
977+
let! v = value |> AsyncAVal.forceAsync
978+
do! action v
979+
}
980+
|> Async.StartImmediate)
981+
| ValueNone ->
982+
async {
983+
let! v = value |> AsyncAVal.forceAsync
984+
do! action v
985+
}
986+
|> Async.StartImmediate
987+
988+
sub

src/FsAutoComplete.Core/AdaptiveExtensions.fsi

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,3 +418,13 @@ module AdaptiveFile =
418418
/// This will create the directory.
419419
/// </summary>
420420
val getLastWriteTimeUtcEnsureDir: path: string -> aval<DateTime>
421+
422+
[<AutoOpen>]
423+
module AsyncAValExtensions =
424+
type asyncaval<'T> with
425+
426+
/// <summary>
427+
/// Adds a disposable callback to the aval that will be executed whenever the
428+
/// avals value changed.
429+
/// </summary>
430+
member AddCallback: weak: bool * action: ('T -> Async<unit>) -> System.IDisposable

src/FsAutoComplete.Core/Commands.fs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,8 @@ module Commands =
11501150
pt,
11511151
tast,
11521152
checkFileResults: FSharpCheckFileResults,
1153-
projectOptions: AnalyzerProjectOptions
1153+
projectOptions: AnalyzerProjectOptions,
1154+
analyzerPredicate
11541155
) =
11551156
let ctx: SDK.EditorContext =
11561157
{ FileName = UMX.untag file
@@ -1159,7 +1160,8 @@ module Commands =
11591160
CheckFileResults = Some checkFileResults
11601161
TypedTree = Some tast
11611162
CheckProjectResults = None
1162-
ProjectOptions = projectOptions }
1163+
ProjectOptions = projectOptions
1164+
AnalyzerIgnoreRanges = Ignore.getAnalyzerIgnoreRanges pt content }
11631165

11641166
let extractResultsFromAnalyzer (r: SDK.AnalysisResult) =
11651167
match r.Output with
@@ -1185,7 +1187,8 @@ module Commands =
11851187

11861188
async {
11871189
try
1188-
let! r = client.RunAnalyzersSafely ctx
1190+
let! r = client.RunAnalyzersSafely(ctx, analyzerPredicate)
1191+
11891192
return r |> List.collect extractResultsFromAnalyzer |> List.toArray
11901193
with ex ->
11911194
Loggers.analyzers.error (

src/FsAutoComplete.Core/FsAutoComplete.Core.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,4 @@
6767
<Compile Include="Commands.fs" />
6868
</ItemGroup>
6969
<Import Project="..\..\.paket\Paket.Restore.targets" />
70-
</Project>
70+
</Project>

src/FsAutoComplete.Core/paket.references

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ FSharp.Analyzers.Build
1919
Serilog.Extensions.Logging
2020

2121
Microsoft.TestPlatform.ObjectModel
22-
Microsoft.TestPlatform.TranslationLayer
22+
Microsoft.TestPlatform.TranslationLayer

0 commit comments

Comments
 (0)