@@ -46,21 +46,25 @@ module internal SourceFileImpl =
4646
4747type CompletionPath = string list* string option// plid * residue
4848
49+ [<RequireQualifiedAccess>]
4950type InheritanceOrigin =
5051| Class
5152| Interface
5253| Unknown
5354
55+ [<RequireQualifiedAccess>]
5456type InheritanceContext =
5557| Class
5658| Interface
5759| Unknown
5860
61+ [<RequireQualifiedAccess>]
5962type RecordContext =
6063| CopyOnUpdateof range * CompletionPath // range of copy-expr + current field
6164| Constructorof string // typename
6265| Newof CompletionPath
6366
67+ [<RequireQualifiedAccess>]
6468type CompletionContext =
6569// completion context cannot be determined due to errors
6670| Invalid
@@ -391,6 +395,7 @@ type FSharpParseFileResults(errors : FSharpErrorInfo[], input : Ast.ParsedInput
391395
392396type ModuleKind = { IsAutoOpen: bool ; HasModuleSuffix: bool }
393397
398+ [<RequireQualifiedAccess>]
394399type EntityKind =
395400| Attribute
396401| Type
@@ -994,7 +999,7 @@ module UntypedParseImpl =
994999
9951000let GetCompletionContextForInheritSynMember (( ComponentInfo ( synAttributes , _ , _ , _ , _ , _ , _ , _ )), typeDefnKind : SynTypeDefnKind , completionPath ) =
9961001
997- let success k = Some( Inherit( k, completionPath))
1002+ let success k = Some( CompletionContext. Inherit( k, completionPath))
9981003
9991004// if kind is specified - take it
10001005// if kind is non-specified
@@ -1003,22 +1008,22 @@ module UntypedParseImpl =
10031008match typeDefnKindwith
10041009| TyconClass->
10051010match synAttributeswith
1006- | Class| Unknown-> success Class
1011+ | Class| Unknown-> successInheritanceContext. Class
10071012| _ -> Some CompletionContext.Invalid// non-matching attributes
10081013| TyconInterface->
10091014match synAttributeswith
1010- | Interface| Unknown-> success Interface
1015+ | Interface| Unknown-> successInheritanceContext. Interface
10111016| _ -> Some CompletionContext.Invalid// non-matching attributes
10121017| TyconStruct->
10131018// display nothing for structs
10141019 Some CompletionContext.Invalid
10151020| TyconUnspecified->
10161021match synAttributeswith
1017- | Class-> success Class
1018- | Interface-> success Interface
1022+ | Class-> successInheritanceContext. Class
1023+ | Interface-> successInheritanceContext. Interface
10191024| Unknown->
10201025// user do not specify kind explicitly or via attributes
1021- success Unknown
1026+ successInheritanceContext. Unknown
10221027| _ ->
10231028// unable to uniquely detect kind from the attributes - return invalid context
10241029 Some CompletionContext.Invalid
@@ -1074,16 +1079,16 @@ module UntypedParseImpl =
10741079| ( SynExpr.New(_, SynType.App( SynType.LongIdent typeName, _, _, _, mGreaterThan, _, _), arg, _)) ->
10751080// new A<_>()
10761081 Some( endOfClosingTokenOrLastIdent mGreaterThan typeName, findSetters arg)
1077- | ( SynExpr.App( ExprAtomicFlag.Atomic , false , SynExpr.Ident id, arg, _)) ->
1082+ | ( SynExpr.App(_ , false , SynExpr.Ident id, arg, _)) ->
10781083// A()
10791084 Some( id.idRange.End, findSetters arg)
1080- | ( SynExpr.App( ExprAtomicFlag.Atomic , false , SynExpr.TypeApp( SynExpr.Ident id, _, _, _, mGreaterThan, _, _), arg, _)) ->
1085+ | ( SynExpr.App(_ , false , SynExpr.TypeApp( SynExpr.Ident id, _, _, _, mGreaterThan, _, _), arg, _)) ->
10811086// A<_>()
10821087 Some( endOfClosingTokenOrIdent mGreaterThan id, findSetters arg)
1083- | ( SynExpr.App( ExprAtomicFlag.Atomic , false , SynExpr.LongIdent(_, lid, _, _), arg, _)) ->
1088+ | ( SynExpr.App(_ , false , SynExpr.LongIdent(_, lid, _, _), arg, _)) ->
10841089// A.B()
10851090 Some( endOfLastIdent lid, findSetters arg)
1086- | ( SynExpr.App( ExprAtomicFlag.Atomic , false , SynExpr.TypeApp( SynExpr.LongIdent(_, lid, _, _), _, _, _, mGreaterThan, _, _), arg, _)) ->
1091+ | ( SynExpr.App(_ , false , SynExpr.TypeApp( SynExpr.LongIdent(_, lid, _, _), _, _, _, mGreaterThan, _, _), arg, _)) ->
10871092// A.B<_>()
10881093 Some( endOfClosingTokenOrLastIdent mGreaterThan lid, findSetters arg)
10891094| _ -> None
@@ -1120,40 +1125,41 @@ module UntypedParseImpl =
11201125let walker =
11211126{
11221127new AstTraversal.AstVisitorBase<_>() with
1123- member this.VisitExpr ( path , traverseSynExpr , defaultTraverse , expr ) =
1128+ member __.VisitExpr ( path , _ , defaultTraverse , expr ) =
1129+
11241130if isInRhsOfRangeOp paththen
11251131match defaultTraverse exprwith
1126- | None-> Some( CompletionContext.RangeOperator) // nothing was found - report that we were in the context of range operator
1132+ | None-> Some CompletionContext.RangeOperator// nothing was found - report that we were in the context of range operator
11271133| x-> x// ok, we found something - return it
11281134else
1129- match exprwith
1130- // new A($)
1131- | SynExpr.Const( SynConst.Unit, m) when rangeContainsPos m pos->
1132- match pathwith
1133- | TS.Expr( NewObjectOrMethodCall args)::_ ->
1134- Some( CompletionContext.ParameterList args)
1135- | _ ->
1136- defaultTraverse expr
1137- // new (... A$)
1138- | SynExpr.Ident idwhen id.idRange.End= pos->
1139- match pathwith
1140- | PartOfParameterList None args->
1141- Some( CompletionContext.ParameterList args)
1142- | _ ->
1143- defaultTraverse expr
1144- // new (A$ = 1)
1145- // new (A = 1,$)
1146- | Setter idwhen id.idRange.End= pos|| rangeBeforePos expr.Range pos->
1147- let precedingArgument = if id.idRange.End= posthen Noneelse Some expr
1148- match pathwith
1149- | PartOfParameterList precedingArgument args->
1150- Some( CompletionContext.ParameterList args)
1151- | _ ->
1152- defaultTraverse expr
1153-
1154- | _ -> defaultTraverse expr
1155-
1156- member this .VisitRecordField( path , copyOpt , field ) =
1135+ match exprwith
1136+ // new A($)
1137+ | SynExpr.Const( SynConst.Unit, m) when rangeContainsPos m pos->
1138+ match pathwith
1139+ | TS.Expr( NewObjectOrMethodCall args)::_ ->
1140+ Some( CompletionContext.ParameterList args)
1141+ | _ ->
1142+ defaultTraverse expr
1143+ // new (... A$)
1144+ | SynExpr.Ident idwhen id.idRange.End= pos->
1145+ match pathwith
1146+ | PartOfParameterList None args->
1147+ Some( CompletionContext.ParameterList args)
1148+ | _ ->
1149+ defaultTraverse expr
1150+ // new (A$ = 1)
1151+ // new (A = 1,$)
1152+ | Setter idwhen id.idRange.End= pos|| rangeBeforePos expr.Range pos->
1153+ let precedingArgument = if id.idRange.End= posthen Noneelse Some expr
1154+ match pathwith
1155+ | PartOfParameterList precedingArgument args->
1156+ Some( CompletionContext.ParameterList args)
1157+ | _ ->
1158+ defaultTraverse expr
1159+
1160+ | _ -> defaultTraverse expr
1161+
1162+ member __ .VisitRecordField( path , copyOpt , field ) =
11571163let contextFromTreePath completionPath =
11581164// detect records usage in constructor
11591165match pathwith
@@ -1177,15 +1183,15 @@ module UntypedParseImpl =
11771183| None-> contextFromTreePath([], None)
11781184 Some( CompletionContext.RecordField recordContext)
11791185
1180- member this .VisitInheritSynMemberDefn( componentInfo , typeDefnKind , synType , _members , _range ) =
1186+ member __ .VisitInheritSynMemberDefn( componentInfo , typeDefnKind , synType , _members , _range ) =
11811187match synTypewith
11821188| SynType.LongIdent lidwd->
11831189match parseLid lidwdwith
11841190| Some( completionPath) -> GetCompletionContextForInheritSynMember( componentInfo, typeDefnKind, completionPath)
11851191| None-> Some( CompletionContext.Invalid) // A $ .B -> no completion list
11861192| _ -> None
11871193
1188- member this .VisitBinding( defaultTraverse , ( Binding ( headPat = headPat) as synBinding)) =
1194+ member __ .VisitBinding( defaultTraverse , ( Binding ( headPat = headPat) as synBinding)) =
11891195
11901196let visitParam = function
11911197| SynPat.Named( range= range) when rangeContainsPos range pos->
@@ -1215,11 +1221,11 @@ module UntypedParseImpl =
12151221| _ -> defaultTraverse synBinding
12161222| _ -> defaultTraverse synBinding
12171223
1218- member this .VisitHashDirective( range ) =
1224+ member __ .VisitHashDirective( range ) =
12191225if rangeContainsPos range posthen Some CompletionContext.Invalid
12201226else None
12211227
1222- member this .VisitModuleOrNamespace( SynModuleOrNamespace ( longId = idents)) =
1228+ member __ .VisitModuleOrNamespace( SynModuleOrNamespace ( longId = idents)) =
12231229match List.tryLast identswith
12241230| Some lastIdentwhen pos.Line= lastIdent.idRange.EndLine->
12251231let stringBetweenModuleNameAndPos = lineStr.[ lastIdent.idRange.EndColumn.. pos.Column- 1 ]
@@ -1228,24 +1234,24 @@ module UntypedParseImpl =
12281234else None
12291235| _ -> None
12301236
1231- member this .VisitComponentInfo( ComponentInfo ( range = range)) =
1237+ member __ .VisitComponentInfo( ComponentInfo ( range = range)) =
12321238if rangeContainsPos range posthen Some CompletionContext.Invalid
12331239else None
12341240
1235- member this .VisitLetOrUse( bindings , range ) =
1241+ member __ .VisitLetOrUse( bindings , range ) =
12361242match bindingswith
12371243| [] when range.StartLine= pos.Line-> Some CompletionContext.Invalid
12381244| _ -> None
12391245
1240- member this .VisitSimplePats( pats ) =
1246+ member __ .VisitSimplePats( pats ) =
12411247 pats|> List.tryPick( fun pat ->
12421248match patwith
12431249| SynSimplePat.Id( range= range)
12441250| SynSimplePat.Typed( SynSimplePat.Id( range= range),_,_) when rangeContainsPos range pos->
12451251 Some CompletionContext.Invalid
12461252| _ -> None)
12471253
1248- member this .VisitModuleDecl( defaultTraverse , decl ) =
1254+ member __ .VisitModuleDecl( defaultTraverse , decl ) =
12491255match declwith
12501256| SynModuleDecl.Open(_, m) ->
12511257// in theory, this means we're "in an open"