Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/FsAutoComplete.Core/ParseAndCheckResults.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ type FindDeclarationResult =
/// The declaration refers to a file.
| File of string


/// TODO: remove this extension when we get https://github.com/dotnet/fsharp/pull/10480/files#diff-5d99a1a2e89452abe0d275ce060600f65c0c24d995703b5bc067106c38cb5e67R108 merged
module FCSPatches =
let (|Ident|_|) ofName =
function | SynExpr.Ident ident when ident.idText = ofName -> Some ()
| _ -> None

type FSharpParseFileResults with

member scope.IsPositionContainedInACurriedParameter pos =
match scope.ParseTree with
| Some input ->
Expand All @@ -49,6 +55,28 @@ module FCSPatches =
result.IsSome
| _ -> false

member scope.TryRangeOfParenEnclosingOpEqualsGreaterUsage opGreaterEqualPos =
let (|InfixAppOfOpEqualsGreater|_|) =
function | SynExpr.App(ExprAtomicFlag.NonAtomic, false, SynExpr.App(ExprAtomicFlag.NonAtomic, true, Ident "op_EqualsGreater", actualParamListExpr, _), actualLambdaBodyExpr, _) -> Some (actualParamListExpr, actualLambdaBodyExpr)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I freaking love active patterns

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so fun fact: this is the shape of this erroneous usage, so any more cases we want to cover should just be a matter of plugging this into the appropriate expr match.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without active patterns, matching the F# AST would be so much harder!

| _ -> None
match scope.ParseTree with
| None -> None
| Some input ->
let visitor = {
new AstTraversal.AstVisitorBase<_>() with
member _.VisitExpr(_, _, defaultTraverse, expr) =
match expr with
| SynExpr.Paren((InfixAppOfOpEqualsGreater(lambdaArgs, lambdaBody) as app), _, _, _) ->
Some (app.Range, lambdaArgs.Range, lambdaBody.Range)
| _ -> defaultTraverse expr
member _.VisitBinding(defaultTraverse, binding) =
match binding with
| SynBinding.Binding (_, SynBindingKind.NormalBinding, _, _, _, _, _, _, _, (InfixAppOfOpEqualsGreater(lambdaArgs, lambdaBody) as app), _, _) ->
Some(app.Range, lambdaArgs.Range, lambdaBody.Range)
| _ -> defaultTraverse binding
}
AstTraversal.Traverse(opGreaterEqualPos, input, visitor)

member scope.TryRangeOfRefCellDereferenceContainingPos expressionPos =
match scope.ParseTree with
| Some input ->
Expand Down
5 changes: 5 additions & 0 deletions src/FsAutoComplete.Core/UntypedAstUtils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1483,6 +1483,11 @@ let getModuleOrNamespacePath (pos: pos) (ast: ParsedInput) =
|> Seq.map (fun ident -> ident.idText)
|> String.concat "."

let getIdentUsagesByName ast name =
let idents = getLongIdents (Some ast)
idents
|> Seq.choose (fun (KeyValue(pos, ident)) -> if ident = name then Some pos else None)
|> List.ofSeq

module HashDirectiveInfo =
open System.IO
Expand Down
Loading