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

Add LintFile method to API layer #663

Draft
wants to merge 22 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions FSharpLint.sln
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "rules", "rules", "{AEBB56D7
docs\content\how-tos\rules\FL0082.md = docs\content\how-tos\rules\FL0082.md
EndProjectSection
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharpLint.Client", "src\FSharpLint.Client\FSharpLint.Client.fsproj", "{0452CA18-2599-4D8B-8A48-01A8B78F3984}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharpLint.Client.Tests", "tests\FSharpLint.Client.Tests\FSharpLint.Client.Tests.fsproj", "{72A7ED5D-8279-4375-B5EA-EFF9C33DD280}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -194,6 +198,30 @@ Global
{B4A92AC6-F74A-4709-B2F7-6C5BABBFDEB0}.Release|x64.Build.0 = Release|Any CPU
{B4A92AC6-F74A-4709-B2F7-6C5BABBFDEB0}.Release|x86.ActiveCfg = Release|Any CPU
{B4A92AC6-F74A-4709-B2F7-6C5BABBFDEB0}.Release|x86.Build.0 = Release|Any CPU
{0452CA18-2599-4D8B-8A48-01A8B78F3984}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0452CA18-2599-4D8B-8A48-01A8B78F3984}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0452CA18-2599-4D8B-8A48-01A8B78F3984}.Debug|x64.ActiveCfg = Debug|Any CPU
{0452CA18-2599-4D8B-8A48-01A8B78F3984}.Debug|x64.Build.0 = Debug|Any CPU
{0452CA18-2599-4D8B-8A48-01A8B78F3984}.Debug|x86.ActiveCfg = Debug|Any CPU
{0452CA18-2599-4D8B-8A48-01A8B78F3984}.Debug|x86.Build.0 = Debug|Any CPU
{0452CA18-2599-4D8B-8A48-01A8B78F3984}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0452CA18-2599-4D8B-8A48-01A8B78F3984}.Release|Any CPU.Build.0 = Release|Any CPU
{0452CA18-2599-4D8B-8A48-01A8B78F3984}.Release|x64.ActiveCfg = Release|Any CPU
{0452CA18-2599-4D8B-8A48-01A8B78F3984}.Release|x64.Build.0 = Release|Any CPU
{0452CA18-2599-4D8B-8A48-01A8B78F3984}.Release|x86.ActiveCfg = Release|Any CPU
{0452CA18-2599-4D8B-8A48-01A8B78F3984}.Release|x86.Build.0 = Release|Any CPU
{72A7ED5D-8279-4375-B5EA-EFF9C33DD280}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{72A7ED5D-8279-4375-B5EA-EFF9C33DD280}.Debug|Any CPU.Build.0 = Debug|Any CPU
{72A7ED5D-8279-4375-B5EA-EFF9C33DD280}.Debug|x64.ActiveCfg = Debug|Any CPU
{72A7ED5D-8279-4375-B5EA-EFF9C33DD280}.Debug|x64.Build.0 = Debug|Any CPU
{72A7ED5D-8279-4375-B5EA-EFF9C33DD280}.Debug|x86.ActiveCfg = Debug|Any CPU
{72A7ED5D-8279-4375-B5EA-EFF9C33DD280}.Debug|x86.Build.0 = Debug|Any CPU
{72A7ED5D-8279-4375-B5EA-EFF9C33DD280}.Release|Any CPU.ActiveCfg = Release|Any CPU
{72A7ED5D-8279-4375-B5EA-EFF9C33DD280}.Release|Any CPU.Build.0 = Release|Any CPU
{72A7ED5D-8279-4375-B5EA-EFF9C33DD280}.Release|x64.ActiveCfg = Release|Any CPU
{72A7ED5D-8279-4375-B5EA-EFF9C33DD280}.Release|x64.Build.0 = Release|Any CPU
{72A7ED5D-8279-4375-B5EA-EFF9C33DD280}.Release|x86.ActiveCfg = Release|Any CPU
{72A7ED5D-8279-4375-B5EA-EFF9C33DD280}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -207,6 +235,8 @@ Global
{B4A92AC6-F74A-4709-B2F7-6C5BABBFDEB0} = {1CD44876-BCDC-4C93-9DC2-C45244BD62AE}
{E1E03FFE-30DF-4522-83DA-9089147B431E} = {270E691D-ECA1-4BC5-B851-C5431A64E9FA}
{AEBB56D7-30B4-40D7-B065-54B8BE960298} = {E1E03FFE-30DF-4522-83DA-9089147B431E}
{0452CA18-2599-4D8B-8A48-01A8B78F3984} = {40C2798B-7078-4D4F-BD37-195240CB827B}
{72A7ED5D-8279-4375-B5EA-EFF9C33DD280} = {1CD44876-BCDC-4C93-9DC2-C45244BD62AE}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B54B4B7D-F019-48A3-BB5B-635B68FE41C3}
Expand Down
2 changes: 2 additions & 0 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ nuget NUnit3TestAdapter
nuget Microsoft.NET.Test.Sdk 17.7.2
nuget Newtonsoft.Json
nuget Microsoft.Build.Locator
nuget SemanticVersioning 2.0.2
nuget StreamJsonRpc ~> 2.8.28

# don't expose as a package reference
nuget Microsoft.SourceLink.GitHub copy_local: true
Expand Down
55 changes: 52 additions & 3 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,17 @@ NUGET
Ionide.ProjInfo.Sln (>= 0.58) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= net6.0))
Newtonsoft.Json (>= 13.0.1) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= net6.0))
Ionide.ProjInfo.Sln (0.58)
Microsoft.Bcl.AsyncInterfaces (8.0) - restriction: || (&& (== net6.0) (>= net462)) (&& (== net6.0) (< netstandard2.1)) (== netstandard2.0)
MessagePack (2.5.140)
MessagePack.Annotations (>= 2.5.140)
Microsoft.Bcl.AsyncInterfaces (>= 6.0) - restriction: == netstandard2.0
Microsoft.NET.StringTools (>= 17.6.3)
System.Collections.Immutable (>= 6.0) - restriction: == netstandard2.0
System.Reflection.Emit (>= 4.7) - restriction: == netstandard2.0
System.Reflection.Emit.Lightweight (>= 4.7) - restriction: == netstandard2.0
System.Runtime.CompilerServices.Unsafe (>= 6.0)
System.Threading.Tasks.Extensions (>= 4.5.4) - restriction: == netstandard2.0
MessagePack.Annotations (2.5.140)
Microsoft.Bcl.AsyncInterfaces (8.0)
System.Threading.Tasks.Extensions (>= 4.5.4) - restriction: || (&& (== net6.0) (>= net462)) (&& (== net6.0) (< netstandard2.1)) (== netstandard2.0)
Microsoft.Build (16.11) - copy_local: false
Microsoft.Build.Framework (>= 16.11) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= net472)) (&& (== netstandard2.0) (>= net5.0))
Expand Down Expand Up @@ -188,6 +198,15 @@ NUGET
Microsoft.TestPlatform.TestHost (17.8) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp3.1))
Microsoft.TestPlatform.ObjectModel (>= 17.8) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp3.1))
Newtonsoft.Json (>= 13.0.1) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= netcoreapp3.1))
Microsoft.VisualStudio.Threading (17.8.14)
Microsoft.Bcl.AsyncInterfaces (>= 7.0)
Microsoft.VisualStudio.Threading.Analyzers (>= 17.8.14)
Microsoft.VisualStudio.Validation (>= 17.8.8)
Microsoft.Win32.Registry (>= 5.0)
System.Runtime.CompilerServices.Unsafe (>= 6.0) - restriction: || (&& (== net6.0) (>= net472)) (== netstandard2.0)
System.Threading.Tasks.Extensions (>= 4.5.4)
Microsoft.VisualStudio.Threading.Analyzers (17.8.14)
Microsoft.VisualStudio.Validation (17.8.8)
Microsoft.Win32.Primitives (4.3)
Microsoft.NETCore.Platforms (>= 1.1)
Microsoft.NETCore.Targets (>= 1.1)
Expand All @@ -197,6 +216,12 @@ NUGET
System.Memory (>= 4.5.4) - restriction: || (&& (== net6.0) (< netcoreapp2.0)) (&& (== net6.0) (< netcoreapp2.1)) (&& (== net6.0) (>= uap10.1)) (== netstandard2.0)
System.Security.AccessControl (>= 5.0)
System.Security.Principal.Windows (>= 5.0)
Nerdbank.Streams (2.10.72)
Microsoft.Bcl.AsyncInterfaces (>= 7.0)
Microsoft.VisualStudio.Threading (>= 17.6.40)
Microsoft.VisualStudio.Validation (>= 17.6.11)
System.IO.Pipelines (>= 7.0)
System.Runtime.CompilerServices.Unsafe (>= 6.0)
NETStandard.Library (2.0.3)
Microsoft.NETCore.Platforms (>= 1.1)
Newtonsoft.Json (13.0.3)
Expand Down Expand Up @@ -249,7 +274,22 @@ NUGET
runtime.ubuntu.16.04-x64.runtime.native.System.Security.Cryptography.OpenSsl (4.3.3)
runtime.ubuntu.16.10-x64.runtime.native.System.Security.Cryptography.OpenSsl (4.3.3)
runtime.ubuntu.18.04-x64.runtime.native.System.Security.Cryptography.OpenSsl (4.3.3)
SemanticVersioning (2.0.2) - restriction: || (== net6.0) (&& (== netstandard2.0) (>= net6.0))
SemanticVersioning (2.0.2)
StreamJsonRpc (2.8.28)
MessagePack (>= 2.2.85)
Microsoft.Bcl.AsyncInterfaces (>= 5.0)
Microsoft.VisualStudio.Threading (>= 16.9.60)
Nerdbank.Streams (>= 2.6.81)
Newtonsoft.Json (>= 12.0.2)
System.Collections.Immutable (>= 5.0)
System.Diagnostics.DiagnosticSource (>= 5.0.1)
System.IO.Pipelines (>= 5.0.1)
System.Memory (>= 4.5.4)
System.Net.Http (>= 4.3.4)
System.Net.WebSockets (>= 4.3)
System.Reflection.Emit (>= 4.7)
System.Threading.Tasks.Dataflow (>= 5.0)
System.Threading.Tasks.Extensions (>= 4.5.4)
System.Buffers (4.5.1)
System.CodeDom (8.0) - copy_local: false
System.Collections (4.3)
Expand Down Expand Up @@ -352,6 +392,10 @@ NUGET
System.Threading.Tasks (>= 4.3)
System.IO.FileSystem.Primitives (4.3)
System.Runtime (>= 4.3)
System.IO.Pipelines (8.0)
System.Buffers (>= 4.5.1) - restriction: || (&& (== net6.0) (>= net462)) (== netstandard2.0)
System.Memory (>= 4.5.5) - restriction: || (&& (== net6.0) (>= net462)) (== netstandard2.0)
System.Threading.Tasks.Extensions (>= 4.5.4) - restriction: || (&& (== net6.0) (>= net462)) (== netstandard2.0)
System.Linq (4.3)
System.Collections (>= 4.3)
System.Diagnostics.Debug (>= 4.3)
Expand Down Expand Up @@ -471,6 +515,11 @@ NUGET
System.Resources.ResourceManager (>= 4.3)
System.Runtime (>= 4.3)
System.Runtime.Extensions (>= 4.3)
System.Net.WebSockets (4.3)
Microsoft.Win32.Primitives (>= 4.3)
System.Resources.ResourceManager (>= 4.3)
System.Runtime (>= 4.3)
System.Threading.Tasks (>= 4.3)
System.Numerics.Vectors (4.5) - restriction: == netstandard2.0
System.ObjectModel (4.3)
System.Collections (>= 4.3)
Expand Down Expand Up @@ -674,7 +723,7 @@ NUGET
Microsoft.NETCore.Targets (>= 1.1)
System.Runtime (>= 4.3)
System.Threading.Tasks.Dataflow (8.0) - copy_local: false
System.Threading.Tasks.Extensions (4.5.4) - restriction: || (&& (== net6.0) (>= net472)) (&& (== net6.0) (< netcoreapp3.1)) (&& (== net6.0) (>= uap10.1)) (== netstandard2.0)
System.Threading.Tasks.Extensions (4.5.4)
System.Runtime.CompilerServices.Unsafe (>= 4.5.3) - restriction: || (&& (== net6.0) (>= net461)) (&& (== net6.0) (< netcoreapp2.1)) (&& (== net6.0) (< netstandard1.0)) (&& (== net6.0) (< netstandard2.0)) (&& (== net6.0) (>= wp8)) (== netstandard2.0)
System.Threading.Tasks.Parallel (4.3)
System.Collections.Concurrent (>= 4.3)
Expand Down
97 changes: 97 additions & 0 deletions src/FSharpLint.Client/Contracts.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
module FSharpLint.Client.Contracts

open System
open System.Threading
open System.Threading.Tasks

[<RequireQualifiedAccess>]
module Methods =
[<Literal>]
let Version = "fsharplint/version"

[<Literal>]
let LintFile = "fsharplint/lintfile"

type VersionRequest =
{
FilePath: string
}

type LintFileRequest =
{
FilePath: string
LintConfigPath: string option
}

type ClientRange =
class
val StartLine: int
val StartColumn: int
val EndLine: int
val EndColumn: int
new(startLine: int, startColumn: int, endLine: int, endColumn: int) =
{ StartLine = startLine
StartColumn = startColumn
EndLine = endLine
EndColumn = endColumn }
end

type ClientSuggestedFix = {
/// Text to be replaced.
FromText:string

/// Location of the text to be replaced.
FromRange:ClientRange

/// Text to replace the `FromText`, i.e. the fix.
ToText:string
}

[<NoEquality; NoComparison>]
type ClientWarningDetails = {
/// Location of the code that prompted the suggestion.
Range:ClientRange

/// Suggestion message to describe the possible problem to the user.
Message:string

/// Information to provide an automated fix.
SuggestedFix:ClientSuggestedFix option
}

/// A lint "warning", sources the location of the warning with a suggestion on how it may be fixed.
[<NoEquality; NoComparison>]
type ClientLintWarning = {
/// Unique identifier for the rule that caused the warning.
RuleIdentifier:string

/// Unique name for the rule that caused the warning.
RuleName:string

/// Path to the file where the error occurs.
FilePath:string

/// Text that caused the error (the `Range` of the content of `FileName`).
ErrorText:string

/// Details for the warning.
Details:ClientWarningDetails
}

type FSharpLintResult =
| Content of string
| LintResult of ClientLintWarning list

type FSharpLintResponse = {
Code: int
FilePath: string
Result : FSharpLintResult
}

type FSharpLintService =
interface
inherit IDisposable

abstract member VersionAsync: VersionRequest * ?cancellationToken: CancellationToken -> Task<FSharpLintResponse>
abstract member LintFileAsync: LintFileRequest * ?cancellationToken: CancellationToken -> Task<FSharpLintResponse>
end
91 changes: 91 additions & 0 deletions src/FSharpLint.Client/Contracts.fsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
module FSharpLint.Client.Contracts

open System.Threading
open System.Threading.Tasks

module Methods =

[<Literal>]
val Version: string = "fsharplint/version"

[<Literal>]
val LintFile: string = "fsharplint/lintfile"

type VersionRequest =
{
FilePath: string
}

type LintFileRequest =
{
FilePath: string
LintConfigPath: string option
}


type ClientRange =
class
new: startLine: int * startColumn: int * endLine: int * endColumn: int -> ClientRange
val StartLine: int
val StartColumn: int
val EndLine: int
val EndColumn: int
end

type ClientSuggestedFix = {
/// Text to be replaced.
FromText:string

/// Location of the text to be replaced.
FromRange:ClientRange

/// Text to replace the `FromText`, i.e. the fix.
ToText:string
}

[<NoEquality; NoComparison>]
type ClientWarningDetails = {
/// Location of the code that prompted the suggestion.
Range:ClientRange

/// Suggestion message to describe the possible problem to the user.
Message:string

/// Information to provide an automated fix.
SuggestedFix:ClientSuggestedFix option
}

/// A lint "warning", sources the location of the warning with a suggestion on how it may be fixed.
[<NoEquality; NoComparison>]
type ClientLintWarning = {
/// Unique identifier for the rule that caused the warning.
RuleIdentifier:string

/// Unique name for the rule that caused the warning.
RuleName:string

/// Path to the file where the error occurs.
FilePath:string

/// Text that caused the error (the `Range` of the content of `FileName`).
ErrorText:string

/// Details for the warning.
Details:ClientWarningDetails
}

type FSharpLintResult =
| Content of string
| LintResult of ClientLintWarning list

type FSharpLintResponse = {
Code: int
FilePath: string
Result : FSharpLintResult
}

type FSharpLintService =
inherit System.IDisposable

abstract VersionAsync: VersionRequest * ?cancellationToken: CancellationToken -> Task<FSharpLintResponse>
abstract LintFileAsync: LintFileRequest * ?cancellationToken: CancellationToken -> Task<FSharpLintResponse>
23 changes: 23 additions & 0 deletions src/FSharpLint.Client/FSharpLint.Client.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<IsPackable>true</IsPackable>
<RootNamespace>FSharpLint.Client</RootNamespace>
<EnableDefaultItems>false</EnableDefaultItems>
<Title>FSharpLint.Client</Title>
<Description>Companion library to format using FSharpLint tool.</Description>
<PackageTags>F#;fsharp;lint;FSharpLint;fslint;api</PackageTags>
</PropertyGroup>
<ItemGroup>
<Compile Include="Contracts.fsi" />
<Compile Include="Contracts.fs" />
<Compile Include="LSPFSharpLintServiceTypes.fsi" />
<Compile Include="LSPFSharpLintServiceTypes.fs" />
<Compile Include="FSharpLintToolLocator.fsi" />
<Compile Include="FSharpLintToolLocator.fs" />
<Compile Include="LSPFSharpLintService.fsi" />
<Compile Include="LSPFSharpLintService.fs" />
</ItemGroup>
<Import Project="..\..\.paket\Paket.Restore.targets" />
</Project>
Loading
Loading