Skip to content

Commit aa989a3

Browse files
authored
Merge pull request #51 from isaacabraham/codeanalysis-clean
Various refactorings
2 parents ef0f176 + 7f906c6 commit aa989a3

1 file changed

Lines changed: 35 additions & 73 deletions

File tree

src/FSharp.CosmosDb.Analyzer/CosmosCodeAnalysis.fs

Lines changed: 35 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,30 @@ open FSharp.Compiler.Range
55
open FSharp.Compiler.SyntaxTree
66

77
module CosmosCodeAnalysis =
8-
let (|Apply|_|) =
9-
function
10-
| SynExpr.TypeApp (funcExpr, lessRange, typeNames, commasRange, greaterRange, typeArgsRange, range) ->
11-
match funcExpr with
12-
| SynExpr.Ident ident -> Some(ident.idText, funcExpr, funcExpr.Range, range)
13-
| SynExpr.LongIdent (isOptional, longDotId, altName, identRange) ->
14-
match longDotId with
15-
| LongIdentWithDots (listOfIds, ranges) ->
16-
let fullName =
17-
listOfIds
18-
|> List.map (fun id -> id.idText)
19-
|> String.concat "."
208

21-
Some(fullName, funcExpr, funcExpr.Range, range)
22-
| _ -> None
23-
| SynExpr.App (atomicFlag, isInfix, funcExpr, argExpr, applicationRange) ->
24-
match funcExpr with
25-
| SynExpr.Ident ident -> Some(ident.idText, argExpr, funcExpr.Range, applicationRange)
26-
| SynExpr.LongIdent (isOptional, longDotId, altName, identRange) ->
27-
match longDotId with
28-
| LongIdentWithDots (listOfIds, ranges) ->
29-
let fullName =
30-
listOfIds
31-
|> List.map (fun id -> id.idText)
32-
|> String.concat "."
9+
let dotConcat = List.map(fun (id:Ident) -> id.idText) >> String.concat "."
3310

34-
Some(fullName, argExpr, funcExpr.Range, applicationRange)
35-
| _ -> None
11+
let checkIfApply funcExpr argExpr range =
12+
match funcExpr with
13+
| SynExpr.Ident ident ->
14+
Some(ident.idText, argExpr, funcExpr.Range, range)
15+
| SynExpr.LongIdent (_, LongIdentWithDots (listOfIds, _), _, _) ->
16+
Some(dotConcat listOfIds, argExpr, funcExpr.Range, range)
17+
| _ ->
18+
None
19+
20+
let (|Apply|_|) synExpr =
21+
match synExpr with
22+
| SynExpr.TypeApp (funcExpr, _, _, _, _, _, range) -> checkIfApply funcExpr funcExpr range
23+
| SynExpr.App (_, _, funcExpr, argExpr, range) -> checkIfApply funcExpr argExpr range
3624
| _ -> None
3725

3826
let (|LongIdent|_|) =
3927
function
40-
| SynExpr.LongIdent (isOptional, longDotId, altName, identRange) ->
41-
match longDotId with
42-
| LongIdentWithDots (listOfIds, ranges) ->
43-
let fullName =
44-
listOfIds
45-
|> List.map (fun id -> id.idText)
46-
|> String.concat "."
47-
48-
Some(fullName, range)
49-
| _ -> None
28+
| SynExpr.LongIdent (isOptional, LongIdentWithDots (listOfIds, ranges), altName, identRange) ->
29+
Some(dotConcat listOfIds, range)
30+
| _ ->
31+
None
5032

5133
let (|Query|_|) =
5234
function
@@ -58,44 +40,24 @@ module CosmosCodeAnalysis =
5840
| Apply ("Cosmos.query", SynExpr.Ident (identifier), funcRange, appRange) -> Some(identifier.idText, funcRange)
5941
| _ -> None
6042

61-
let (|TypedQuery|_|) =
62-
function
63-
| SynExpr.App (exprAtomic,
64-
isInfix,
65-
(SynExpr.TypeApp (funcExpr, lessRange, typeNames, commasRange, greaterRange, typeArgsRange, typeAppRange)),
66-
SynExpr.Const (SynConst.String (query, queryRange), constRange),
67-
appRange) ->
68-
match funcExpr with
69-
| SynExpr.LongIdent (isOptional, longDotId, altName, identRange) ->
70-
match longDotId with
71-
| LongIdentWithDots (listOfIds, ranges) ->
72-
let fullName =
73-
listOfIds
74-
|> List.map (fun id -> id.idText)
75-
|> String.concat "."
76-
77-
match fullName with
78-
| "Cosmos.query" ->
79-
let names =
80-
typeNames
81-
|> List.filter (fun typeName ->
82-
match typeName with
83-
| SynType.LongIdent (_) -> true
84-
| _ -> false)
85-
|> List.map (fun typeName ->
86-
match typeName with
87-
| SynType.LongIdent (dots) ->
88-
match dots with
89-
| LongIdentWithDots (listOfIds, _) ->
90-
listOfIds
91-
|> List.map (fun id -> id.idText)
92-
|> String.concat "."
93-
| _ -> "")
94-
95-
Some(names, query, typeAppRange)
96-
| _ -> None
43+
let (|TypedQuery|_|) synExpr =
44+
match synExpr with
45+
| SynExpr.App (_, _, (SynExpr.TypeApp (SynExpr.LongIdent (_, LongIdentWithDots (listOfIds, _), _, _), _, typeNames, _, _, _, typeAppRange)), SynExpr.Const (SynConst.String (query, _), _), _) ->
46+
match dotConcat listOfIds with
47+
| "Cosmos.query" ->
48+
let names =
49+
typeNames
50+
|> List.choose (fun typeName ->
51+
match typeName with
52+
| SynType.LongIdent (LongIdentWithDots (listOfIds, _)) ->
53+
dotConcat listOfIds |> Some
54+
| _ ->
55+
None)
56+
57+
Some(names, query, typeAppRange)
9758
| _ -> None
98-
| _ -> None
59+
| _ ->
60+
None
9961

10062
let (|Database|_|) =
10163
function

0 commit comments

Comments
 (0)