Skip to content

Commit c83aadc

Browse files
Apply Fantomas formatting to LSP and Core files
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 6986969 commit c83aadc

9 files changed

Lines changed: 233 additions & 138 deletions

File tree

src/Nap.Core/CurlGenerator.fs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,33 @@ open Nap.Core
66

77
let private methodString (m: HttpMethod) : string =
88
match m with
9-
| GET -> "GET" | POST -> "POST" | PUT -> "PUT"
10-
| PATCH -> "PATCH" | DELETE -> "DELETE"
11-
| HEAD -> "HEAD" | OPTIONS -> "OPTIONS"
9+
| GET -> "GET"
10+
| POST -> "POST"
11+
| PUT -> "PUT"
12+
| PATCH -> "PATCH"
13+
| DELETE -> "DELETE"
14+
| HEAD -> "HEAD"
15+
| OPTIONS -> "OPTIONS"
1216

13-
let private escapeShellArg (s: string) : string =
14-
s.Replace("'", "'\\''")
17+
let private escapeShellArg (s: string) : string = s.Replace("'", "'\\''")
1518

1619
let private headerFlag (key: string) (value: string) : string =
1720
$" -H '{escapeShellArg key}: {escapeShellArg value}'"
1821

19-
let private bodyFlag (body: RequestBody) : string =
20-
$" -d '{escapeShellArg body.Content}'"
22+
let private bodyFlag (body: RequestBody) : string = $" -d '{escapeShellArg body.Content}'"
2123

2224
/// Generate a curl command string from a NapRequest
2325
let toCurl (request: NapRequest) : string =
2426
let sb = System.Text.StringBuilder()
25-
sb.Append($"curl -X {methodString request.Method} '{escapeShellArg request.Url}'") |> ignore
2627

27-
request.Headers |> Map.iter (fun k v ->
28-
sb.Append(headerFlag k v) |> ignore
29-
)
28+
sb.Append($"curl -X {methodString request.Method} '{escapeShellArg request.Url}'")
29+
|> ignore
3030

31-
request.Body |> Option.iter (fun b ->
31+
request.Headers |> Map.iter (fun k v -> sb.Append(headerFlag k v) |> ignore)
32+
33+
request.Body
34+
|> Option.iter (fun b ->
3235
sb.Append($" -H 'Content-Type: {escapeShellArg b.ContentType}'") |> ignore
33-
sb.Append(bodyFlag b) |> ignore
34-
)
36+
sb.Append(bodyFlag b) |> ignore)
3537

3638
sb.ToString()

src/Nap.Core/Environment.fs

Lines changed: 50 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@ module Nap.Core.Environment
33

44
open System
55
open System.IO
6+
67
/// Parse a .napenv file (simple key = value format, TOML-like)
78
let parseEnvFile (content: string) : Map<string, string> =
8-
content.Split([|'\n'; '\r'|], StringSplitOptions.RemoveEmptyEntries)
9+
content.Split([| '\n'; '\r' |], StringSplitOptions.RemoveEmptyEntries)
910
|> Array.choose (fun line ->
1011
let line = line.Trim()
11-
if line = "" || line.StartsWith "#" then None
12+
13+
if line = "" || line.StartsWith "#" then
14+
None
1215
elif line.Contains "=" then
13-
let parts = line.Split([|'='|], 2)
14-
Some (parts.[0].Trim(), parts.[1].Trim().Trim('"'))
15-
else None
16-
)
16+
let parts = line.Split([| '=' |], 2)
17+
Some(parts.[0].Trim(), parts.[1].Trim().Trim('"'))
18+
else
19+
None)
1720
|> Map.ofArray
1821

1922
let private mergeInto (source: Map<string, string>) (target: Map<string, string>) =
@@ -26,21 +29,29 @@ let private mergeInto (source: Map<string, string>) (target: Map<string, string>
2629
/// 3. Named environment file (.napenv.{name})
2730
/// 4. Base .napenv
2831
/// 5. [vars] block in the .nap file
29-
let loadEnvironment (dir: string) (envName: string option) (cliVars: Map<string, string>) (fileVars: Map<string, string>) : Map<string, string> =
32+
let loadEnvironment
33+
(dir: string)
34+
(envName: string option)
35+
(cliVars: Map<string, string>)
36+
(fileVars: Map<string, string>)
37+
: Map<string, string> =
3038
let readIfExists path =
3139
if File.Exists path then
3240
File.ReadAllText path |> parseEnvFile
33-
else Map.empty
41+
else
42+
Map.empty
3443

3544
let baseEnv = readIfExists (Path.Combine(dir, ".napenv"))
3645
Logger.debug $"Loaded .napenv: {baseEnv.Count} vars"
46+
3747
let namedEnv =
3848
match envName with
3949
| Some name ->
4050
let env = readIfExists (Path.Combine(dir, $".napenv.{name}"))
4151
Logger.debug $"Loaded .napenv.{name}: {env.Count} vars"
4252
env
4353
| None -> Map.empty
54+
4455
let localEnv = readIfExists (Path.Combine(dir, ".napenv.local"))
4556
Logger.debug $"Loaded .napenv.local: {localEnv.Count} vars"
4657

@@ -54,69 +65,79 @@ let loadEnvironment (dir: string) (envName: string option) (cliVars: Map<string,
5465
let resolveVars (vars: Map<string, string>) (input: string) : string =
5566
let sb = System.Text.StringBuilder()
5667
let mutable i = 0
68+
5769
while i < input.Length do
5870
if i + 3 < input.Length && input.[i] = '{' && input.[i + 1] = '{' then
5971
let start = i + 2
6072
let mutable j = start
61-
while j < input.Length && input.[j] <> '}' && Char.IsLetterOrDigit(input.[j]) || input.[j] = '_' do
73+
74+
while j < input.Length && input.[j] <> '}' && Char.IsLetterOrDigit(input.[j])
75+
|| input.[j] = '_' do
6276
j <- j + 1
77+
6378
if j + 1 < input.Length && input.[j] = '}' && input.[j + 1] = '}' && j > start then
6479
let key = input.Substring(start, j - start)
80+
6581
match Map.tryFind key vars with
6682
| Some v -> sb.Append(v) |> ignore
6783
| None -> sb.Append(input, i, j + 2 - i) |> ignore
84+
6885
i <- j + 2
6986
else
7087
sb.Append(input.[i]) |> ignore
7188
i <- i + 1
7289
else
7390
sb.Append(input.[i]) |> ignore
7491
i <- i + 1
92+
7593
sb.ToString()
7694

7795
/// Detect available environment names by scanning a directory for .napenv.{name} files.
7896
/// Excludes .napenv (base) and .napenv.local (secrets). Returns sorted unique names.
7997
let detectEnvironmentNames (dir: string) : string list =
80-
if not (Directory.Exists dir) then []
98+
if not (Directory.Exists dir) then
99+
[]
81100
else
82101
let prefix = ".napenv."
83102
let localSuffix = ".local"
103+
84104
Directory.GetFiles(dir, ".napenv.*")
85105
|> Array.choose (fun path ->
86106
let fileName = Path.GetFileName(path)
87-
if fileName = ".napenv" then None
88-
elif fileName.EndsWith(localSuffix) then None
107+
108+
if fileName = ".napenv" then
109+
None
110+
elif fileName.EndsWith(localSuffix) then
111+
None
89112
elif fileName.StartsWith(prefix) then
90-
Some (fileName.Substring(prefix.Length))
91-
else None
92-
)
113+
Some(fileName.Substring(prefix.Length))
114+
else
115+
None)
93116
|> Array.distinct
94117
|> Array.sort
95118
|> Array.toList
96119

97120
/// Resolve all variables in a NapFile's request
98121
let resolveNapFile (vars: Map<string, string>) (napFile: NapFile) : NapFile =
99122
let resolve = resolveVars vars
123+
100124
{ napFile with
101-
Request = {
102-
napFile.Request with
125+
Request =
126+
{ napFile.Request with
103127
Url = resolve napFile.Request.Url
104128
Headers = napFile.Request.Headers |> Map.map (fun _ v -> resolve v)
105129
Body =
106130
napFile.Request.Body
107-
|> Option.map (fun b -> { b with Content = resolve b.Content })
108-
}
131+
|> Option.map (fun b -> { b with Content = resolve b.Content }) }
109132
Assertions =
110-
napFile.Assertions |> List.map (fun a ->
133+
napFile.Assertions
134+
|> List.map (fun a ->
111135
{ a with
112136
Op =
113137
match a.Op with
114-
| Equals v -> Equals (resolve v)
115-
| Contains v -> Contains (resolve v)
116-
| Matches v -> Matches (resolve v)
117-
| LessThan v -> LessThan (resolve v)
118-
| GreaterThan v -> GreaterThan (resolve v)
119-
| Exists -> Exists
120-
}
121-
)
122-
}
138+
| Equals v -> Equals(resolve v)
139+
| Contains v -> Contains(resolve v)
140+
| Matches v -> Matches(resolve v)
141+
| LessThan v -> LessThan(resolve v)
142+
| GreaterThan v -> GreaterThan(resolve v)
143+
| Exists -> Exists }) }

src/Nap.Core/SectionScanner.fs

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,30 @@
44
module Nap.Core.SectionScanner
55

66
/// A located section header with its line number (0-based) and name
7-
type SectionLocation = {
8-
Name : string
9-
Line : int
10-
EndLine : int
11-
}
7+
type SectionLocation =
8+
{ Name: string
9+
Line: int
10+
EndLine: int }
1211

1312
/// Known .nap section names
1413
let private napSections =
15-
Set.ofList [ "meta"; "vars"; "request"; "request.headers"; "request.body"; "assert"; "script" ]
14+
Set.ofList
15+
[ "meta"
16+
"vars"
17+
"request"
18+
"request.headers"
19+
"request.body"
20+
"assert"
21+
"script" ]
1622

1723
/// Known .naplist section names
18-
let private naplistSections =
19-
Set.ofList [ "meta"; "vars"; "steps" ]
24+
let private naplistSections = Set.ofList [ "meta"; "vars"; "steps" ]
2025

2126
let private isSectionHeader (line: string) : string option =
2227
let trimmed = line.Trim()
28+
2329
if trimmed.StartsWith "[" && trimmed.EndsWith "]" then
24-
Some (trimmed.TrimStart('[').TrimEnd(']').ToLowerInvariant())
30+
Some(trimmed.TrimStart('[').TrimEnd(']').ToLowerInvariant())
2531
else
2632
None
2733

@@ -34,16 +40,21 @@ let private isShorthandRequest (line: string) : bool =
3440
/// Also detects shorthand requests (e.g. "GET https://...") as a synthetic "request" section.
3541
let scanNapSections (content: string) : SectionLocation list =
3642
let lines = content.Split([| '\n' |])
37-
let mutable sections : SectionLocation list = []
43+
let mutable sections: SectionLocation list = []
3844
let mutable lastSectionStart = -1
3945
let mutable lastName = ""
4046

4147
let closeSection (endLine: int) =
4248
if lastSectionStart >= 0 then
43-
sections <- sections @ [ { Name = lastName; Line = lastSectionStart; EndLine = endLine } ]
49+
sections <-
50+
sections
51+
@ [ { Name = lastName
52+
Line = lastSectionStart
53+
EndLine = endLine } ]
4454

4555
for i in 0 .. lines.Length - 1 do
4656
let line = lines[i]
57+
4758
match isSectionHeader line with
4859
| Some name when napSections.Contains name ->
4960
closeSection (i - 1)
@@ -61,13 +72,17 @@ let scanNapSections (content: string) : SectionLocation list =
6172
/// Scan a .naplist file for section locations. Returns sections in file order.
6273
let scanNaplistSections (content: string) : SectionLocation list =
6374
let lines = content.Split([| '\n' |])
64-
let mutable sections : SectionLocation list = []
75+
let mutable sections: SectionLocation list = []
6576
let mutable lastSectionStart = -1
6677
let mutable lastName = ""
6778

6879
let closeSection (endLine: int) =
6980
if lastSectionStart >= 0 then
70-
sections <- sections @ [ { Name = lastName; Line = lastSectionStart; EndLine = endLine } ]
81+
sections <-
82+
sections
83+
@ [ { Name = lastName
84+
Line = lastSectionStart
85+
EndLine = endLine } ]
7186

7287
for i in 0 .. lines.Length - 1 do
7388
match isSectionHeader lines[i] with

src/Nap.Lsp.Tests/LspClient.fs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ open Xunit
1313

1414
let private lspBinaryPath =
1515
let baseDir = AppContext.BaseDirectory
16-
let repoRoot =
17-
DirectoryInfo(baseDir).Parent.Parent.Parent.Parent.Parent.FullName
16+
let repoRoot = DirectoryInfo(baseDir).Parent.Parent.Parent.Parent.Parent.FullName
1817
Path.Combine(repoRoot, "src", "Nap.Lsp", "bin", "Debug", "net10.0", "napper-lsp")
1918

2019
/// Encode a JSON-RPC message with Content-Length header (LSP wire format)
@@ -35,6 +34,7 @@ let private readMessage (reader: StreamReader) (ct: CancellationToken) : Task<Js
3534
while not (String.IsNullOrEmpty(headerLine)) do
3635
if headerLine.StartsWith("Content-Length:", StringComparison.OrdinalIgnoreCase) then
3736
contentLength <- headerLine.Substring(15).Trim() |> int
37+
3838
let! nextLine = reader.ReadLineAsync(ct)
3939
headerLine <- nextLine
4040

@@ -76,6 +76,7 @@ type LspServerProcess() =
7676
request["jsonrpc"] <- str "2.0"
7777
request["id"] <- num id
7878
request["method"] <- str method
79+
7980
match paramObj with
8081
| Some p -> request["params"] <- p
8182
| None -> ()
@@ -87,13 +88,13 @@ type LspServerProcess() =
8788

8889
use cts = new CancellationTokenSource(TimeSpan.FromSeconds(10.0))
8990
let reader = proc.StandardOutput
90-
let mutable result : JsonNode option = None
91+
let mutable result: JsonNode option = None
9192

9293
while result.IsNone do
9394
let! msg = readMessage reader cts.Token
95+
9496
match msg with
95-
| Some node when node["id"] <> null && node["id"].GetValue<int>() = id ->
96-
result <- Some node
97+
| Some node when node["id"] <> null && node["id"].GetValue<int>() = id -> result <- Some node
9798
| Some _ -> ()
9899
| None -> failwith "Stream ended before response received"
99100

@@ -105,6 +106,7 @@ type LspServerProcess() =
105106
let notification = JsonObject()
106107
notification["jsonrpc"] <- str "2.0"
107108
notification["method"] <- str method
109+
108110
match paramObj with
109111
| Some p -> notification["params"] <- p
110112
| None -> ()
@@ -121,11 +123,13 @@ type LspServerProcess() =
121123
do! proc.StandardInput.BaseStream.FlushAsync()
122124
}
123125

124-
member _.IsRunning : bool =
125-
started && not proc.HasExited
126+
member _.IsRunning: bool = started && not proc.HasExited
126127

127128
member _.ReadStdErr() : string =
128-
if proc.HasExited then proc.StandardError.ReadToEnd() else ""
129+
if proc.HasExited then
130+
proc.StandardError.ReadToEnd()
131+
else
132+
""
129133

130134
member this.Kill() : unit =
131135
if started && not proc.HasExited then

0 commit comments

Comments
 (0)