From 021f97dd5b57a7913fed4f3233b488919399da23 Mon Sep 17 00:00:00 2001 From: webwarrior Date: Mon, 22 Jan 2024 12:52:27 +0100 Subject: [PATCH] WIP: introduce File type --- src/FSharpLint.Client/FSharpLintToolLocator.fs | 5 +++-- src/FSharpLint.Client/LSPFSharpLintServiceTypes.fs | 12 +++++++++++- src/FSharpLint.Client/LSPFSharpLintServiceTypes.fsi | 7 ++++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/FSharpLint.Client/FSharpLintToolLocator.fs b/src/FSharpLint.Client/FSharpLintToolLocator.fs index a6242dcd3..83990cd39 100644 --- a/src/FSharpLint.Client/FSharpLintToolLocator.fs +++ b/src/FSharpLint.Client/FSharpLintToolLocator.fs @@ -141,10 +141,11 @@ let private fsharpLintVersionOnPath () : (FSharpLintExecutableFile * FSharpLintV if File.Exists fsharpLint then Some fsharpLint else None) |> Seq.tryHead + |> Option.bind File.From fsharpLintExecutableOnPathOpt |> Option.bind (fun fsharpLintExecutablePath -> - let processStart = ProcessStartInfo(fsharpLintExecutablePath) + let processStart = ProcessStartInfo(File.Unwrap fsharpLintExecutablePath) processStart.Arguments <- "--version" processStart.RedirectStandardOutput <- true processStart.CreateNoWindow <- true @@ -210,7 +211,7 @@ let createFor (startInfo: FSharpLintToolStartInfo) : Result - let ps = ProcessStartInfo(executableFile) + let ps = ProcessStartInfo(File.Unwrap executableFile) ps.Arguments <- "--daemon" ps diff --git a/src/FSharpLint.Client/LSPFSharpLintServiceTypes.fs b/src/FSharpLint.Client/LSPFSharpLintServiceTypes.fs index e308ef022..d363581d1 100644 --- a/src/FSharpLint.Client/LSPFSharpLintServiceTypes.fs +++ b/src/FSharpLint.Client/LSPFSharpLintServiceTypes.fs @@ -13,8 +13,18 @@ type FSharpLintResponseCode = | ErrDaemonCreationFailed = -1 | OkCurrentDaemonVersion = 0 +type File = private File of string +with + static member From (filePath: string) = + if File.Exists(filePath) then + filePath |> File |> Some + else + None + + static member Unwrap(File f) = f + type FSharpLintVersion = FSharpLintVersion of string -type FSharpLintExecutableFile = FSharpLintExecutableFile of string +type FSharpLintExecutableFile = FSharpLintExecutableFile of File type Folder = private Folder of string with static member from (filePath: string) = diff --git a/src/FSharpLint.Client/LSPFSharpLintServiceTypes.fsi b/src/FSharpLint.Client/LSPFSharpLintServiceTypes.fsi index 9a1d13f57..a2c219892 100644 --- a/src/FSharpLint.Client/LSPFSharpLintServiceTypes.fsi +++ b/src/FSharpLint.Client/LSPFSharpLintServiceTypes.fsi @@ -8,9 +8,14 @@ type FSharpLintResponseCode = | ErrDaemonCreationFailed = -1 | OkCurrentDaemonVersion = 0 +type File = private File of string +with + static member From: string -> File option + static member Unwrap: File -> string + type FSharpLintVersion = FSharpLintVersion of string -type FSharpLintExecutableFile = FSharpLintExecutableFile of string +type FSharpLintExecutableFile = FSharpLintExecutableFile of File type Folder = private Folder of string with