Skip to content

Commit

Permalink
Analyzer v3.26 improves parser and updates to latest fsharp sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaid-Ajaj committed May 6, 2021
1 parent 89f1b78 commit 237f46e
Show file tree
Hide file tree
Showing 23 changed files with 672 additions and 531 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
]
},
"fake-cli": {
"version": "5.20.3",
"version": "5.20.4",
"commands": [
"fake"
]
Expand Down
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 3.26.0 - 2021-05-06
* Allow the SQL parser to handle comments and update to latest FSharp Analyzers SDK

### 3.25.0 - 2021-04-26
* Improvements to the SQL parser

Expand Down
6 changes: 2 additions & 4 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@ source https://api.nuget.org/v3/index.json
storage: none
lowest_matching: true
clitool dotnet-mono 0.5.2
nuget FSharp.Core ~> 4.7.2
nuget Microsoft.SourceLink.GitHub prerelease copy_local: true
nuget Microsoft.NETFramework.ReferenceAssemblies copy_local: true
nuget Expecto 8.13.1
nuget YoloDev.Expecto.TestSdk 0.8.0
nuget Microsoft.NET.Test.Sdk 15.7.2
nuget altcover ~> 6
nuget FSharp.Analyzers.SDK 0.5.0
nuget FSharp.Analyzers.SDK 0.8.0
nuget Npgsql
nuget ThrowawayDb.Postgres
nuget Npgsql.FSharp
nuget Npgsql.FSharp ~> 4.0
nuget F23.StringSimilarity
nuget FParsec 1.1.1

// [ FAKE GROUP ]
group Build
Expand Down
911 changes: 515 additions & 396 deletions paket.lock

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions src/FParsec/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ open System.Reflection

[<assembly: AssemblyTitleAttribute("FParsec")>]
[<assembly: AssemblyProductAttribute("NpgsqlFSharpAnalyzer")>]
[<assembly: AssemblyVersionAttribute("3.25.0")>]
[<assembly: AssemblyMetadataAttribute("ReleaseDate","2021-04-26T00:00:00.0000000")>]
[<assembly: AssemblyFileVersionAttribute("3.25.0")>]
[<assembly: AssemblyInformationalVersionAttribute("3.25.0")>]
[<assembly: AssemblyVersionAttribute("3.26.0")>]
[<assembly: AssemblyMetadataAttribute("ReleaseDate","2021-05-06T00:00:00.0000000")>]
[<assembly: AssemblyFileVersionAttribute("3.26.0")>]
[<assembly: AssemblyInformationalVersionAttribute("3.26.0")>]
[<assembly: AssemblyMetadataAttribute("ReleaseChannel","release")>]
[<assembly: AssemblyMetadataAttribute("GitHash","675b6e17d558a9f77d590af1e6a5277572770739")>]
[<assembly: AssemblyMetadataAttribute("GitHash","89f1b78fc64964e3bc01f0738f8780c3f12099ae")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "FParsec"
let [<Literal>] AssemblyProduct = "NpgsqlFSharpAnalyzer"
let [<Literal>] AssemblyVersion = "3.25.0"
let [<Literal>] AssemblyMetadata_ReleaseDate = "2021-04-26T00:00:00.0000000"
let [<Literal>] AssemblyFileVersion = "3.25.0"
let [<Literal>] AssemblyInformationalVersion = "3.25.0"
let [<Literal>] AssemblyVersion = "3.26.0"
let [<Literal>] AssemblyMetadata_ReleaseDate = "2021-05-06T00:00:00.0000000"
let [<Literal>] AssemblyFileVersion = "3.26.0"
let [<Literal>] AssemblyInformationalVersion = "3.26.0"
let [<Literal>] AssemblyMetadata_ReleaseChannel = "release"
let [<Literal>] AssemblyMetadata_GitHash = "675b6e17d558a9f77d590af1e6a5277572770739"
let [<Literal>] AssemblyMetadata_GitHash = "89f1b78fc64964e3bc01f0738f8780c3f12099ae"
20 changes: 10 additions & 10 deletions src/NpgsqlFSharpAnalyzer.Core/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ open System.Reflection

[<assembly: AssemblyTitleAttribute("NpgsqlFSharpAnalyzer.Core")>]
[<assembly: AssemblyProductAttribute("NpgsqlFSharpAnalyzer")>]
[<assembly: AssemblyVersionAttribute("3.25.0")>]
[<assembly: AssemblyMetadataAttribute("ReleaseDate","2021-04-26T00:00:00.0000000")>]
[<assembly: AssemblyFileVersionAttribute("3.25.0")>]
[<assembly: AssemblyInformationalVersionAttribute("3.25.0")>]
[<assembly: AssemblyVersionAttribute("3.26.0")>]
[<assembly: AssemblyMetadataAttribute("ReleaseDate","2021-05-06T00:00:00.0000000")>]
[<assembly: AssemblyFileVersionAttribute("3.26.0")>]
[<assembly: AssemblyInformationalVersionAttribute("3.26.0")>]
[<assembly: AssemblyMetadataAttribute("ReleaseChannel","release")>]
[<assembly: AssemblyMetadataAttribute("GitHash","675b6e17d558a9f77d590af1e6a5277572770739")>]
[<assembly: AssemblyMetadataAttribute("GitHash","89f1b78fc64964e3bc01f0738f8780c3f12099ae")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "NpgsqlFSharpAnalyzer.Core"
let [<Literal>] AssemblyProduct = "NpgsqlFSharpAnalyzer"
let [<Literal>] AssemblyVersion = "3.25.0"
let [<Literal>] AssemblyMetadata_ReleaseDate = "2021-04-26T00:00:00.0000000"
let [<Literal>] AssemblyFileVersion = "3.25.0"
let [<Literal>] AssemblyInformationalVersion = "3.25.0"
let [<Literal>] AssemblyVersion = "3.26.0"
let [<Literal>] AssemblyMetadata_ReleaseDate = "2021-05-06T00:00:00.0000000"
let [<Literal>] AssemblyFileVersion = "3.26.0"
let [<Literal>] AssemblyInformationalVersion = "3.26.0"
let [<Literal>] AssemblyMetadata_ReleaseChannel = "release"
let [<Literal>] AssemblyMetadata_GitHash = "675b6e17d558a9f77d590af1e6a5277572770739"
let [<Literal>] AssemblyMetadata_GitHash = "89f1b78fc64964e3bc01f0738f8780c3f12099ae"
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="F23.StringSimilarity" Version="3.1.0" />
<PackageReference Include="FSharp.Compiler.Service" Version="36.0.3" />
<PackageReference Include="FSharp.Compiler.Service" Version="39.0.0" />
<PackageReference Update="FSharp.Core" Version="5.0.1" />
<PackageReference Include="Npgsql" Version="4.1.3" />
<PackageReference Update="FSharp.Core" Version="4.7.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NpgsqlFSharpParser\NpgsqlFSharpParser.fsproj" />
Expand Down
2 changes: 1 addition & 1 deletion src/NpgsqlFSharpAnalyzer.Core/SqlAnalysis.fs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Npgsql.FSharp.Analyzers.Core

open System
open FSharp.Compiler.Range
open FSharp.Compiler.Text
open F23.StringSimilarity
open NpgsqlFSharpParser
open InformationSchema
Expand Down
10 changes: 5 additions & 5 deletions src/NpgsqlFSharpAnalyzer.Core/SyntacticAnalysis.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Npgsql.FSharp.Analyzers.Core

open FSharp.Compiler.SourceCodeServices
open FSharp.Compiler.SyntaxTree
open FSharp.Compiler.Range
open FSharp.Compiler.Text

module SyntacticAnalysis =

Expand Down Expand Up @@ -434,7 +434,7 @@ module SyntacticAnalysis =
[ yield! findReadColumnAttempts funcExpr; yield! findReadColumnAttempts argExpr ]
| SynExpr.Paren(expr, leftRange, rightRange, range) ->
[ yield! findReadColumnAttempts expr ]
| SynExpr.Lambda(fromMethod, inLambdaSeq, args, body, range) ->
| SynExpr.Lambda(fromMethod, inLambdaSeq, args, body, parsedData, range) ->
[ yield! findReadColumnAttempts body ]
| SynExpr.LetOrUse(isRecursive, isUse, bindings, body, range) ->
[ yield! findReadColumnAttempts body
Expand Down Expand Up @@ -492,7 +492,7 @@ module SyntacticAnalysis =
| None -> ()
]

| SynExpr.Lambda(_, _, args, body, range) ->
| SynExpr.Lambda(_, _, args, body, parsedData, range) ->
[
yield! findReadColumnAttempts body
]
Expand Down Expand Up @@ -676,7 +676,7 @@ module SyntacticAnalysis =
| Some expr -> yield! visitSyntacticExpression expr range
]

| SynExpr.Lambda (fromMethod, inSeq, args, body, range) ->
| SynExpr.Lambda (fromMethod, inSeq, args, body, parsedData, range) ->
visitSyntacticExpression body range

| SynExpr.Sequential (debugSeqPoint, isTrueSeq, expr1, expr2, range) ->
Expand All @@ -695,7 +695,7 @@ module SyntacticAnalysis =

let findLiterals (ctx: SqlAnalyzerContext) =
let values = new ResizeArray<string * string>()
for symbol in ctx.Symbols |> Seq.collect (fun s -> s.TryGetMembersFunctionsAndValues) do
for symbol in ctx.Symbols |> Seq.collect (fun s -> s.TryGetMembersFunctionsAndValues()) do
match symbol.LiteralValue with
| Some value when value.GetType() = typeof<string> ->
values.Add((symbol.LogicalName, unbox<string> value))
Expand Down
18 changes: 15 additions & 3 deletions src/NpgsqlFSharpAnalyzer.Core/Types.fs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace Npgsql.FSharp.Analyzers.Core

open FSharp.Compiler.Range

open FSharp.Compiler.Text
open FSharp.Compiler.SyntaxTree
open FSharp.Compiler.SourceCodeServices

Expand Down Expand Up @@ -68,7 +67,20 @@ type SqlAnalyzerBlock =
| Parameters of UsedParameter list * range
| ReadingColumns of ColumnReadAttempt list
| Transaction of TransactionQuery list
| SkipAnalysis
| SkipAnalysis

member this.Range() =
match this with
| Query(value, range) -> Some range
| LiteralQuery(id, range) -> Some range
| StoredProcedure(name, range) -> Some range
| Parameters(parameterList, range) -> Some range
| Transaction(queries) ->
queries
|> List.tryHead
|> Option.map (fun query -> query.queryRange)
| _ ->
None

type SqlOperation = {
blocks : SqlAnalyzerBlock list
Expand Down
20 changes: 10 additions & 10 deletions src/NpgsqlFSharpAnalyzer/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ open System.Reflection

[<assembly: AssemblyTitleAttribute("NpgsqlFSharpAnalyzer")>]
[<assembly: AssemblyProductAttribute("NpgsqlFSharpAnalyzer")>]
[<assembly: AssemblyVersionAttribute("3.25.0")>]
[<assembly: AssemblyMetadataAttribute("ReleaseDate","2021-04-26T00:00:00.0000000")>]
[<assembly: AssemblyFileVersionAttribute("3.25.0")>]
[<assembly: AssemblyInformationalVersionAttribute("3.25.0")>]
[<assembly: AssemblyVersionAttribute("3.26.0")>]
[<assembly: AssemblyMetadataAttribute("ReleaseDate","2021-05-06T00:00:00.0000000")>]
[<assembly: AssemblyFileVersionAttribute("3.26.0")>]
[<assembly: AssemblyInformationalVersionAttribute("3.26.0")>]
[<assembly: AssemblyMetadataAttribute("ReleaseChannel","release")>]
[<assembly: AssemblyMetadataAttribute("GitHash","675b6e17d558a9f77d590af1e6a5277572770739")>]
[<assembly: AssemblyMetadataAttribute("GitHash","89f1b78fc64964e3bc01f0738f8780c3f12099ae")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "NpgsqlFSharpAnalyzer"
let [<Literal>] AssemblyProduct = "NpgsqlFSharpAnalyzer"
let [<Literal>] AssemblyVersion = "3.25.0"
let [<Literal>] AssemblyMetadata_ReleaseDate = "2021-04-26T00:00:00.0000000"
let [<Literal>] AssemblyFileVersion = "3.25.0"
let [<Literal>] AssemblyInformationalVersion = "3.25.0"
let [<Literal>] AssemblyVersion = "3.26.0"
let [<Literal>] AssemblyMetadata_ReleaseDate = "2021-05-06T00:00:00.0000000"
let [<Literal>] AssemblyFileVersion = "3.26.0"
let [<Literal>] AssemblyInformationalVersion = "3.26.0"
let [<Literal>] AssemblyMetadata_ReleaseChannel = "release"
let [<Literal>] AssemblyMetadata_GitHash = "675b6e17d558a9f77d590af1e6a5277572770739"
let [<Literal>] AssemblyMetadata_GitHash = "89f1b78fc64964e3bc01f0738f8780c3f12099ae"
2 changes: 1 addition & 1 deletion src/NpgsqlFSharpAnalyzer/NpgsqlFSharpAnalyzer.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Name>NpgsqlFSharpAnalyzer</Name>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
<Description>Advanced embedded static analysis and type-checking for SQL code from F#</Description>
Expand Down
2 changes: 0 additions & 2 deletions src/NpgsqlFSharpAnalyzer/SqlAnalyzer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ namespace Npgsql.FSharp.Analyzers

open FSharp.Analyzers.SDK
open System
open System.IO
open System.Linq

module SqlAnalyzer =

Expand Down
20 changes: 10 additions & 10 deletions src/NpgsqlFSharpParser/AssemblyInfo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ open System.Reflection

[<assembly: AssemblyTitleAttribute("NpgsqlFSharpParser")>]
[<assembly: AssemblyProductAttribute("NpgsqlFSharpAnalyzer")>]
[<assembly: AssemblyVersionAttribute("3.25.0")>]
[<assembly: AssemblyMetadataAttribute("ReleaseDate","2021-04-26T00:00:00.0000000")>]
[<assembly: AssemblyFileVersionAttribute("3.25.0")>]
[<assembly: AssemblyInformationalVersionAttribute("3.25.0")>]
[<assembly: AssemblyVersionAttribute("3.26.0")>]
[<assembly: AssemblyMetadataAttribute("ReleaseDate","2021-05-06T00:00:00.0000000")>]
[<assembly: AssemblyFileVersionAttribute("3.26.0")>]
[<assembly: AssemblyInformationalVersionAttribute("3.26.0")>]
[<assembly: AssemblyMetadataAttribute("ReleaseChannel","release")>]
[<assembly: AssemblyMetadataAttribute("GitHash","675b6e17d558a9f77d590af1e6a5277572770739")>]
[<assembly: AssemblyMetadataAttribute("GitHash","89f1b78fc64964e3bc01f0738f8780c3f12099ae")>]
do ()

module internal AssemblyVersionInformation =
let [<Literal>] AssemblyTitle = "NpgsqlFSharpParser"
let [<Literal>] AssemblyProduct = "NpgsqlFSharpAnalyzer"
let [<Literal>] AssemblyVersion = "3.25.0"
let [<Literal>] AssemblyMetadata_ReleaseDate = "2021-04-26T00:00:00.0000000"
let [<Literal>] AssemblyFileVersion = "3.25.0"
let [<Literal>] AssemblyInformationalVersion = "3.25.0"
let [<Literal>] AssemblyVersion = "3.26.0"
let [<Literal>] AssemblyMetadata_ReleaseDate = "2021-05-06T00:00:00.0000000"
let [<Literal>] AssemblyFileVersion = "3.26.0"
let [<Literal>] AssemblyInformationalVersion = "3.26.0"
let [<Literal>] AssemblyMetadata_ReleaseChannel = "release"
let [<Literal>] AssemblyMetadata_GitHash = "675b6e17d558a9f77d590af1e6a5277572770739"
let [<Literal>] AssemblyMetadata_GitHash = "89f1b78fc64964e3bc01f0738f8780c3f12099ae"
65 changes: 48 additions & 17 deletions src/NpgsqlFSharpVs/LintChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,19 +203,14 @@ public async Task DoUpdateAsync()
return;
}

var loadedSchema = SqlAnalysis.databaseSchema(connectionString);

if (loadedSchema.IsError)
{
return;
}


var source = _currentSnapshot.GetText();
var sourceText = SourceText.ofString(source);

var getProjectOptions = _provider.CheckerInstance.GetProjectOptionsFromScript(
filename: path,
sourceText: sourceText,
source: sourceText,
assumeDotNetFramework: false,
useSdkRefs: true,
useFsiAuxLib: true,
Expand All @@ -224,7 +219,8 @@ public async Task DoUpdateAsync()
loadedTimeStamp: FSharpOption<DateTime>.None,
extraProjectInfo: FSharpOption<object>.None,
optionsStamp: FSharpOption<long>.None,
userOpName: FSharpOption<string>.None
userOpName: FSharpOption<string>.None,
sdkDirOverride: FSharpOption<string>.None
);

var (options, errors) = await FSharpAsync.StartAsTask(getProjectOptions, null, token);
Expand All @@ -236,10 +232,9 @@ public async Task DoUpdateAsync()

var performParseAndCheck = _provider.CheckerInstance.ParseAndCheckFileInProject(
filename: path,
fileversion: 1,
fileVersion: 1,
sourceText: sourceText,
options: options,
textSnapshotInfo: FSharpOption<object>.None,
userOpName: FSharpOption<string>.None
);

Expand All @@ -259,12 +254,48 @@ public async Task DoUpdateAsync()
symbols: SqlAnalyzer.getSymbols(checkResults)
);

var databaseSchema = loadedSchema.ResultValue;
var operationBlocks = SyntacticAnalysis.findSqlOperations(context);
var loadedSchema = SqlAnalysis.databaseSchema(connectionString);

var errorMessages = new List<Message>();

var errorMessages =
from operation in SyntacticAnalysis.findSqlOperations(context)
from analysisOutput in SqlAnalysis.analyzeOperation(operation, connectionString, databaseSchema)
select analysisOutput;
if (loadedSchema.IsError)
{
foreach (var operation in operationBlocks)
{
var containsSkipAnalysis = operation.blocks.Any(block => block.IsSkipAnalysis);
foreach(var block in operation.blocks)
{
var blockRange = block.Range();
if ((block.IsQuery || block.IsTransaction) && OptionModule.IsSome(blockRange) && !containsSkipAnalysis)
{
var internalError = (loadedSchema.ErrorValue ?? "").Replace("3D000:", "").Replace("28P01:", "");
var fullError = $"Error occured while trying to connect to the database using the configured connection string in NPGSQL_FSHARP in order to perform static analysis:{internalError}";
var errorMessage = new Message(
type: "Error",
message: fullError,
code: "SQL101",
severity: Severity.Warning,
range: blockRange.Value,
fixes: Microsoft.FSharp.Collections.FSharpList<Fix>.Empty
);

errorMessages.Add(errorMessage);
}
}
}
}
else
{
var databaseSchema = loadedSchema.ResultValue;
foreach (var operation in operationBlocks)
{
foreach(var analysisOutput in SqlAnalysis.analyzeOperation(operation, connectionString, databaseSchema))
{
errorMessages.Add(analysisOutput);
}
}
}

var oldLintingErrors = this.Factory.CurrentSnapshot;
var newLintErrors = new LintingErrorsSnapshot(_document, oldLintingErrors.VersionNumber + 1);
Expand All @@ -282,7 +313,7 @@ from analysisOutput in SqlAnalysis.analyzeOperation(operation, connectionString,
UpdateLintingErrors(newLintErrors);
}

public static SnapshotSpan RangeToSpan(Range.range fsrange, ITextSnapshot textSnapshot)
public static SnapshotSpan RangeToSpan(Range fsrange, ITextSnapshot textSnapshot)
{
var from = fsrange.StartLine - 1;
ITextSnapshotLine anchor = textSnapshot.GetLineFromLineNumber(from);
Expand All @@ -292,7 +323,7 @@ public static SnapshotSpan RangeToSpan(Range.range fsrange, ITextSnapshot textSn
return new SnapshotSpan(textSnapshot, new Span(start, end - start));
}

public static ITrackingSpan RangeToTrackingSpan(Range.range fsrange, ITextSnapshot textSnapshot)
public static ITrackingSpan RangeToTrackingSpan(Range fsrange, ITextSnapshot textSnapshot)
{
var from = fsrange.StartLine - 1;
ITextSnapshotLine anchor = textSnapshot.GetLineFromLineNumber(from);
Expand Down
Loading

0 comments on commit 237f46e

Please sign in to comment.