Skip to content

Commit bac8c19

Browse files
authored
Merge pull request #15 from dawedawe/fix_14
Construct fallback xml path
2 parents 1133967 + 2ddbd22 commit bac8c19

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [1.0.3] - 2024-08-20
4+
5+
### Fixed
6+
7+
* Fixed support for non-FSharp.Core namespaces, #14.
8+
39
## [1.0.2] - 2024-05-18
410

511
### Fixed

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "8.0.300",
3+
"version": "8.0.400",
44
"rollForward": "latestPatch"
55
}
66
}

src/Fsih.Tests/Tests.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ let expressions =
3030
<@ Array2D.blit @> :> Expr, "Microsoft.FSharp.Collections.Array2DModule.blit"
3131
<@ HashIdentity.Reference @> :> Expr, "Microsoft.FSharp.Collections.HashIdentity.Reference"
3232
<@ Array.Parallel.tryFind @> :> Expr, "Microsoft.FSharp.Collections.ArrayModule.Parallel.tryFind"
33-
<@ (|>) @> :> Expr, "Microsoft.FSharp.Core.Operators.op_PipeRight" ]
33+
<@ (|>) @> :> Expr, "Microsoft.FSharp.Core.Operators.op_PipeRight"
34+
<@ System.Console.ReadLine @> :> Expr, "System.Console.ReadLine" ]
3435
)
3536

3637
[<Theory>]

src/Fsih/Parser.fs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module Fsih.Parser
22

33
open System
44
open System.IO
5+
open System.Text.RegularExpressions
56
open System.Xml
67
open Spectre.Console
78

@@ -68,6 +69,23 @@ let trimDotNet (s: string) =
6869
// WTF, seems like we loose inner xml (example content) if we cache an XmlDocument
6970
let xmlDocCache = Collections.Generic.Dictionary<string, string>()
7071

72+
let toFallbackXmlPath (xmlPath: string) =
73+
let replaceLast (s: string) (oldValue: string) (newValue: string) =
74+
let idx = s.LastIndexOf(oldValue)
75+
76+
if idx >= 0 then
77+
s.Substring(0, idx) + newValue + s.Substring(idx + oldValue.Length)
78+
else
79+
s
80+
81+
let sep = Path.DirectorySeparatorChar
82+
let xmlPath = replaceLast xmlPath "shared" "packs"
83+
let xmlPath = replaceLast xmlPath $".App{sep}" $".App.Ref{sep}"
84+
let version = Regex.Match(xmlPath, @"\d+\.\d+\.\d+").Value
85+
let release = version.Substring(0, version.LastIndexOf('.'))
86+
let xmlPath = replaceLast xmlPath version $"{version}{sep}ref{sep}net{release}"
87+
xmlPath
88+
7189
let tryGetXmlDocument xmlPath =
7290
#if DEBUG
7391
printfn $"trying xml file: %s{xmlPath}"
@@ -79,14 +97,26 @@ let tryGetXmlDocument xmlPath =
7997
xmlDocument.LoadXml(value)
8098
Some xmlDocument
8199
| _ ->
82-
let rawXml = System.IO.File.ReadAllText(xmlPath)
100+
let fileExists = File.Exists(xmlPath)
101+
102+
let xmlPath =
103+
if fileExists then
104+
xmlPath
105+
else
106+
let fallback = toFallbackXmlPath xmlPath
107+
#if DEBUG
108+
printfn $"falling back to xml file: %s{fallback}"
109+
#endif
110+
fallback
111+
112+
let rawXml = File.ReadAllText(xmlPath)
83113
let xmlDocument = XmlDocument()
84114
xmlDocument.LoadXml(rawXml)
85-
xmlDocCache.Add(xmlPath, rawXml)
115+
xmlDocCache[xmlPath] <- rawXml
86116
Some xmlDocument
87117
with _ ->
88118
#if DEBUG
89-
printfn $"xml file not found: {xmlPath}"
119+
printfn $"xml file not found"
90120
#endif
91121
None
92122

0 commit comments

Comments
 (0)