Skip to content

Commit 8a9028f

Browse files
committed
PR feedback: Folder check
1 parent 998a46a commit 8a9028f

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

src/FSharpLint.Client/FSharpLintToolLocator.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ let private startProcess (ps: ProcessStartInfo) : Result<Process, ProcessStartEr
5656
)
5757
| ex -> Error(ProcessStartError.UnExpectedException(ps.FileName, ps.Arguments, ex.Message))
5858

59-
let private runToolListCmd (Folder workingDir: Folder) (globalFlag: bool) : Result<string list, DotNetToolListError> =
59+
let private runToolListCmd (workingDir: Folder) (globalFlag: bool) : Result<string list, DotNetToolListError> =
6060
let ps = ProcessStartInfo("dotnet")
61-
ps.WorkingDirectory <- workingDir
61+
ps.WorkingDirectory <- Folder.unwrap workingDir
6262
ps.EnvironmentVariables.["DOTNET_CLI_UI_LANGUAGE"] <- "en-us" //ensure we have predictible output for parsing
6363

6464
let toolArguments =
@@ -194,9 +194,9 @@ let findFSharpLintTool (workingDir: Folder) : Result<FSharpLintToolFound, FSharp
194194
let createFor (startInfo: FSharpLintToolStartInfo) : Result<RunningFSharpLintTool, ProcessStartError> =
195195
let processStart =
196196
match startInfo with
197-
| FSharpLintToolStartInfo.LocalTool(Folder workingDirectory) ->
197+
| FSharpLintToolStartInfo.LocalTool(workingDirectory: Folder) ->
198198
let ps = ProcessStartInfo("dotnet")
199-
ps.WorkingDirectory <- workingDirectory
199+
ps.WorkingDirectory <- Folder.unwrap workingDirectory
200200
ps.Arguments <- $"{fsharpLintToolName} --daemon"
201201
ps
202202
| FSharpLintToolStartInfo.GlobalTool ->

src/FSharpLint.Client/LSPFSharpLintService.fs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,9 @@ let private getFolderFor filePath (): Result<Folder, FSharpLintServiceError> =
150150
let handleFile filePath =
151151
if not (isPathAbsolute filePath) then
152152
Error FSharpLintServiceError.FilePathIsNotAbsolute
153-
elif not (File.Exists filePath) then
154-
Error FSharpLintServiceError.FileDoesNotExist
155-
else
156-
Path.GetDirectoryName filePath |> Folder |> Ok
153+
else match Folder.from filePath with
154+
| None -> Error FSharpLintServiceError.FileDoesNotExist
155+
| Some folder -> Ok folder
157156

158157
handleFile filePath
159158

src/FSharpLint.Client/LSPFSharpLintServiceTypes.fs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
open System
44
open System.Diagnostics
5+
open System.IO
56
open StreamJsonRpc
67

78
type FSharpLintResponseCode =
@@ -14,7 +15,18 @@ type FSharpLintResponseCode =
1415

1516
type FSharpLintVersion = FSharpLintVersion of string
1617
type FSharpLintExecutableFile = FSharpLintExecutableFile of string
17-
type Folder = Folder of path: string
18+
type Folder = private Folder of string
19+
with
20+
static member from (filePath: string) =
21+
if File.Exists(filePath) then
22+
let folder = Path.GetFullPath(filePath) |> Path.GetDirectoryName
23+
if DirectoryInfo(folder).Exists then
24+
folder |> Folder |> Some
25+
else
26+
None
27+
else
28+
None
29+
static member unwrap(Folder f) = f
1830

1931
[<RequireQualifiedAccess>]
2032
type FSharpLintToolStartInfo =

src/FSharpLint.Client/LSPFSharpLintServiceTypes.fsi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ type FSharpLintVersion = FSharpLintVersion of string
1212

1313
type FSharpLintExecutableFile = FSharpLintExecutableFile of string
1414

15-
type Folder = Folder of path: string
15+
type Folder = private Folder of string
16+
with
17+
static member from: string -> Folder option
18+
static member unwrap: Folder -> string
1619

1720
[<RequireQualifiedAccess>]
1821
type FSharpLintToolStartInfo =

0 commit comments

Comments
 (0)