Skip to content

Commit 998a46a

Browse files
committed
PR feedback: clearer FSharpLintResponseCode
1 parent bc88d44 commit 998a46a

File tree

4 files changed

+25
-25
lines changed

4 files changed

+25
-25
lines changed

src/FSharpLint.Client/LSPFSharpLintService.fs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,14 @@ let private getDaemon (agent: MailboxProcessor<Msg>) (folder: Folder) : Result<J
165165
| Error gde -> Error(FSharpLintServiceError.DaemonNotFound gde)
166166

167167
let private fileNotFoundResponse filePath : Task<FSharpLintResponse> =
168-
{ Code = int FSharpLintResponseCode.FileNotFound
168+
{ Code = int FSharpLintResponseCode.ErrFileNotFound
169169
FilePath = filePath
170170
Result = Content $"File \"%s{filePath}\" does not exist."
171171
}
172172
|> Task.FromResult
173173

174174
let private fileNotAbsoluteResponse filePath : Task<FSharpLintResponse> =
175-
{ Code = int FSharpLintResponseCode.FilePathIsNotAbsolute
175+
{ Code = int FSharpLintResponseCode.ErrFilePathIsNotAbsolute
176176
FilePath = filePath
177177
Result = Content $"\"%s{filePath}\" is not an absolute file path. Relative paths are not supported."
178178
}
@@ -192,25 +192,25 @@ let private daemonNotFoundResponse filePath (error: GetDaemonError) : Task<FShar
192192
pathEnvironmentVariable,
193193
error)) ->
194194
$"FSharpLint.Client tried to run `%s{executableFile} %s{arguments}` inside working directory \"{workingDirectory}\" but could not find \"%s{executableFile}\" on the PATH (%s{pathEnvironmentVariable}). Error: %s{error}",
195-
FSharpLintResponseCode.DaemonCreationFailed
195+
FSharpLintResponseCode.ErrDaemonCreationFailed
196196
| GetDaemonError.DotNetToolListError(DotNetToolListError.ProcessStartError(ProcessStartError.UnExpectedException(executableFile,
197197
arguments,
198198
error)))
199199
| GetDaemonError.FSharpLintProcessStart(ProcessStartError.UnExpectedException(executableFile, arguments, error)) ->
200200
$"FSharpLint.Client tried to run `%s{executableFile} %s{arguments}` but failed with \"%s{error}\"",
201-
FSharpLintResponseCode.DaemonCreationFailed
201+
FSharpLintResponseCode.ErrDaemonCreationFailed
202202
| GetDaemonError.DotNetToolListError(DotNetToolListError.ExitCodeNonZero(executableFile,
203203
arguments,
204204
exitCode,
205205
error)) ->
206206
$"FSharpLint.Client tried to run `%s{executableFile} %s{arguments}` but exited with code {exitCode} {error}",
207-
FSharpLintResponseCode.DaemonCreationFailed
207+
FSharpLintResponseCode.ErrDaemonCreationFailed
208208
| GetDaemonError.InCompatibleVersionFound ->
209209
"FSharpLint.Client did not found a compatible dotnet tool version to launch as daemon process",
210-
FSharpLintResponseCode.ToolNotFound
210+
FSharpLintResponseCode.ErrToolNotFound
211211
| GetDaemonError.CompatibleVersionIsKnownButNoDaemonIsRunning(FSharpLintVersion version) ->
212212
$"FSharpLint.Client found a compatible version `%s{version}` but no daemon could be launched.",
213-
FSharpLintResponseCode.DaemonCreationFailed
213+
FSharpLintResponseCode.ErrDaemonCreationFailed
214214

215215
{ Code = int code
216216
FilePath = filePath
@@ -219,7 +219,7 @@ let private daemonNotFoundResponse filePath (error: GetDaemonError) : Task<FShar
219219
|> Task.FromResult
220220

221221
let private cancellationWasRequestedResponse filePath : Task<FSharpLintResponse> =
222-
{ Code = int FSharpLintResponseCode.CancellationWasRequested
222+
{ Code = int FSharpLintResponseCode.ErrCancellationWasRequested
223223
FilePath = filePath
224224
Result = Content "FSharpLintService is being or has been disposed."
225225
}
@@ -254,7 +254,7 @@ type LSPFSharpLintService() =
254254
cancellationToken = Option.defaultValue cts.Token cancellationToken
255255
)
256256
.ContinueWith(fun (t: Task<string>) ->
257-
{ Code = int FSharpLintResponseCode.Version
257+
{ Code = int FSharpLintResponseCode.OkCurrentDaemonVersion
258258
Result = Content t.Result
259259
FilePath = versionRequest.FilePath }))
260260
|> mapResultToResponse versionRequest.FilePath

src/FSharpLint.Client/LSPFSharpLintServiceTypes.fs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ open System.Diagnostics
55
open StreamJsonRpc
66

77
type FSharpLintResponseCode =
8-
| ToolNotFound = 1
9-
| FileNotFound = 2
10-
| FilePathIsNotAbsolute = 3
11-
| CancellationWasRequested = 4
12-
| DaemonCreationFailed = 5
13-
| Version = 6
8+
| ErrToolNotFound = -5
9+
| ErrFileNotFound = -4
10+
| ErrFilePathIsNotAbsolute = -3
11+
| ErrCancellationWasRequested = -2
12+
| ErrDaemonCreationFailed = -1
13+
| OkCurrentDaemonVersion = 0
1414

1515
type FSharpLintVersion = FSharpLintVersion of string
1616
type FSharpLintExecutableFile = FSharpLintExecutableFile of string

src/FSharpLint.Client/LSPFSharpLintServiceTypes.fsi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
module FSharpLint.Client.LSPFSharpLintServiceTypes
22

33
type FSharpLintResponseCode =
4-
| ToolNotFound = 1
5-
| FileNotFound = 2
6-
| FilePathIsNotAbsolute = 3
7-
| CancellationWasRequested = 4
8-
| DaemonCreationFailed = 5
9-
| Version = 6
4+
| ErrToolNotFound = -5
5+
| ErrFileNotFound = -4
6+
| ErrFilePathIsNotAbsolute = -3
7+
| ErrCancellationWasRequested = -2
8+
| ErrDaemonCreationFailed = -1
9+
| OkCurrentDaemonVersion = 0
1010

1111
type FSharpLintVersion = FSharpLintVersion of string
1212

tests/FSharpLint.Client.Tests/TestClient.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ let TestDaemonNotFound() =
5656
let fsharpLintService: FSharpLintService = new LSPFSharpLintService() :> FSharpLintService
5757
let versionResponse = runVersionCall testHintsFile fsharpLintService
5858

59-
Assert.AreEqual(LanguagePrimitives.EnumToValue FSharpLintResponseCode.ToolNotFound, versionResponse.Code)
59+
Assert.AreEqual(LanguagePrimitives.EnumToValue FSharpLintResponseCode.ErrToolNotFound, versionResponse.Code)
6060

6161
[<Test>]
6262
let TestDaemonVersion() =
@@ -70,7 +70,7 @@ let TestDaemonVersion() =
7070
| Content result -> Assert.IsFalse (String.IsNullOrWhiteSpace result)
7171
// | _ -> Assert.Fail("Response should be a version number")
7272

73-
Assert.AreEqual(LanguagePrimitives.EnumToValue FSharpLintResponseCode.Version, versionResponse.Code)
73+
Assert.AreEqual(LanguagePrimitives.EnumToValue FSharpLintResponseCode.OkCurrentDaemonVersion, versionResponse.Code)
7474

7575
[<Test>]
7676
let TestFilePathShouldBeAbsolute() =
@@ -80,7 +80,7 @@ let TestFilePathShouldBeAbsolute() =
8080
let fsharpLintService: FSharpLintService = new LSPFSharpLintService() :> FSharpLintService
8181
let versionResponse = runVersionCall testHintsFile fsharpLintService
8282

83-
Assert.AreEqual(LanguagePrimitives.EnumToValue FSharpLintResponseCode.FilePathIsNotAbsolute, versionResponse.Code)
83+
Assert.AreEqual(LanguagePrimitives.EnumToValue FSharpLintResponseCode.ErrFilePathIsNotAbsolute, versionResponse.Code)
8484

8585
[<Test>]
8686
let TestFileShouldExists() =
@@ -90,4 +90,4 @@ let TestFileShouldExists() =
9090
let fsharpLintService: FSharpLintService = new LSPFSharpLintService() :> FSharpLintService
9191
let versionResponse = runVersionCall testHintsFile fsharpLintService
9292

93-
Assert.AreEqual(LanguagePrimitives.EnumToValue FSharpLintResponseCode.FileNotFound, versionResponse.Code)
93+
Assert.AreEqual(LanguagePrimitives.EnumToValue FSharpLintResponseCode.ErrFileNotFound, versionResponse.Code)

0 commit comments

Comments
 (0)