@@ -17,7 +17,7 @@ open Microsoft.FSharp.Core.Printf
1717open Microsoft.FSharp .Compiler
1818open Microsoft.FSharp .Compiler .AbstractIL
1919open Microsoft.FSharp .Compiler .AbstractIL .IL
20- open Microsoft.FSharp .Compiler .AbstractIL .Diagnostics
20+ open Microsoft.FSharp .Compiler .AbstractIL .Diagnostics
2121open Microsoft.FSharp .Compiler .AbstractIL .Internal
2222open Microsoft.FSharp .Compiler .AbstractIL .Internal .Library
2323
@@ -88,12 +88,14 @@ type FSharpFindDeclFailureReason =
8888// trying to find declaration of ProvidedMember without TypeProviderDefinitionLocationAttribute
8989| ProvidedMemberof string
9090
91+ [<RequireQualifiedAccess>]
9192type FSharpFindDeclResult =
9293/// declaration not found + reason
9394| DeclNotFoundof FSharpFindDeclFailureReason
9495/// found declaration
9596| DeclFoundof range
96-
97+ /// Indicates an external declaration was found
98+ | ExternalDeclof assembly : string * externalSym : ExternalSymbol
9799
98100/// This type is used to describe what was found during the name resolution.
99101/// (Depending on the kind of the items, we may stop processing or continue to find better items)
@@ -1096,50 +1098,107 @@ type TypeCheckInfo
10961098( fun msg ->
10971099 Trace.TraceInformation( sprintf" FCS: recovering from error in GetMethodsAsSymbols: '%s '" msg)
10981100 None)
1099-
1101+
11001102member scope.GetDeclarationLocation ( ctok , line , lineStr , colAtEndOfNames , names , preferFlag ) =
11011103 ErrorScope.Protect Range.range0
11021104( fun () ->
11031105match GetDeclItemsForNamesAtPosition( ctok, None, Some( names), None, line, lineStr, colAtEndOfNames, ResolveTypeNamesToCtors, ResolveOverloads.Yes,( fun () -> []), fun _ -> false ) with
11041106| None
11051107| Some([], _, _, _) -> FSharpFindDeclResult.DeclNotFound( FSharpFindDeclFailureReason.Unknown" " )
1106- | Some( item:: _, _, _, _) ->
1107-
1108- // For IL-based entities, switch to a different item. This is because
1109- // rangeOfItem, ccuOfItem don't work on IL methods or fields.
1110- //
1111- // Later comment: to be honest, they aren't going to work on these new items either.
1112- // This is probably old code from when we supported 'go to definition' generating IL metadata.
1113- let item =
1108+ | Some( item:: _, _, _, _) ->
1109+ let getTypeVarNames ( ilinfo : ILMethInfo ) =
1110+ let classTypeParams = ilinfo.DeclaringTyconRef.ILTyconRawMetadata.GenericParams|> List.map( fun paramDef -> paramDef.Name)
1111+ let methodTypeParams = ilinfo.FormalMethodTypars|> List.map( fun typ -> typ.Name)
1112+ classTypeParams@ methodTypeParams|> Array.ofList
1113+
1114+ let result =
11141115match item.Itemwith
1115- | Item.MethodGroup(_, ( ILMeth(_, ilinfo,_)) :: _, _)
1116- | Item.CtorGroup(_, ( ILMeth(_, ilinfo,_)) :: _) -> Item.Types( " " , [ ilinfo.ApparentEnclosingType])
1117- | Item.ILField( ILFieldInfo( typeInfo, _)) -> Item.Types( " " , [ typeInfo.ToType])
1118- | Item.ImplicitOp(_, { contents= Some( TraitConstraintSln.FSMethSln(_, vref, _))}) -> Item.Value( vref)
1119- | _ -> item.Item
1120-
1121- let fail defaultReason =
1122- match itemwith
1116+ | Item.CtorGroup(_, ( ILMeth(_, ilinfo,_)) :: _) ->
1117+ match ilinfo.MetadataScopewith
1118+ | ILScopeRef.Assembly assref->
1119+ let typeVarNames = getTypeVarNames ilinfo
1120+ ParamTypeSymbol.tryOfILTypes typeVarNames ilinfo.ILMethodRef.ArgTypes
1121+ |> Option.map( fun args ->
1122+ let externalSym = ExternalSymbol.Constructor( ilinfo.ILMethodRef.EnclosingTypeRef.FullName, args)
1123+ FSharpFindDeclResult.ExternalDecl( assref.Name, externalSym))
1124+ | _ -> None
1125+
1126+ | Item.MethodGroup( name, ( ILMeth(_, ilinfo,_)) :: _, _) ->
1127+ match ilinfo.MetadataScopewith
1128+ | ILScopeRef.Assembly assref->
1129+ let typeVarNames = getTypeVarNames ilinfo
1130+ ParamTypeSymbol.tryOfILTypes typeVarNames ilinfo.ILMethodRef.ArgTypes
1131+ |> Option.map( fun args ->
1132+ let externalSym = ExternalSymbol.Method( ilinfo.ILMethodRef.EnclosingTypeRef.FullName, name, args, ilinfo.ILMethodRef.GenericArity)
1133+ FSharpFindDeclResult.ExternalDecl( assref.Name, externalSym))
1134+ | _ -> None
1135+
1136+ | Item.Property( name, ILProp(_, propInfo) :: _) ->
1137+ let methInfo =
1138+ if propInfo.HasGetterthen Some( propInfo.GetterMethod g)
1139+ elif propInfo.HasSetterthen Some( propInfo.SetterMethod g)
1140+ else None
1141+
1142+ match methInfowith
1143+ | Some methInfo->
1144+ match methInfo.MetadataScopewith
1145+ | ILScopeRef.Assembly assref->
1146+ let externalSym = ExternalSymbol.Property( methInfo.ILMethodRef.EnclosingTypeRef.FullName, name)
1147+ Some( FSharpFindDeclResult.ExternalDecl( assref.Name, externalSym))
1148+ | _ -> None
1149+ | None-> None
1150+
1151+ | Item.ILField( ILFieldInfo( ILTypeInfo( tr, _, _, _) & typeInfo, fieldDef)) when not tr.IsLocalRef->
1152+ match typeInfo.ILScopeRefwith
1153+ | ILScopeRef.Assembly assref->
1154+ let externalSym = ExternalSymbol.Field( typeInfo.ILTypeRef.FullName, fieldDef.Name)
1155+ Some( FSharpFindDeclResult.ExternalDecl( assref.Name, externalSym))
1156+ | _ -> None
1157+
1158+ | Item.Event( ILEvent(_, ILEventInfo( ILTypeInfo( tr, _, _, _) & typeInfo, eventDef))) when not tr.IsLocalRef->
1159+ match typeInfo.ILScopeRefwith
1160+ | ILScopeRef.Assembly assref->
1161+ let externalSym = ExternalSymbol.Event( typeInfo.ILTypeRef.FullName, eventDef.Name)
1162+ Some( FSharpFindDeclResult.ExternalDecl( assref.Name, externalSym))
1163+ | _ -> None
1164+
1165+ | Item.ImplicitOp(_, { contents= Some( TraitConstraintSln.FSMethSln(_, _ vref, _))}) ->
1166+ //Item.Value(vref)
1167+ None
1168+
1169+ | Item.Types(_, [ AppTy g( tr, _)]) when not tr.IsLocalRef->
1170+ match tr.TypeReprInfo, tr.PublicPathwith
1171+ | TILObjectRepr( TILObjectReprData( ILScopeRef.Assembly assref, _, _)), Some( PubPath parts) ->
1172+ let fullName = parts|> String.concat" ."
1173+ Some( FSharpFindDeclResult.ExternalDecl( assref.Name, ExternalSymbol.Type fullName))
1174+ | _ -> None
1175+ | _ -> None
1176+
1177+ match resultwith
1178+ | Some x-> x
1179+ | None->
1180+ let fail defaultReason =
1181+ match item.Itemwith
11231182#if EXTENSIONTYPING
1124- | SymbolHelpers.ItemIsProvidedType g( tcref) -> FSharpFindDeclResult.DeclNotFound( FSharpFindDeclFailureReason.ProvidedType( tcref.DisplayName))
1125- | Item.CtorGroup( name, ProvidedMeth(_)::_)
1126- | Item.MethodGroup( name, ProvidedMeth(_)::_, _)
1127- | Item.Property( name, ProvidedProp(_)::_) -> FSharpFindDeclResult.DeclNotFound( FSharpFindDeclFailureReason.ProvidedMember( name))
1128- | Item.Event( ProvidedEvent(_) as e) -> FSharpFindDeclResult.DeclNotFound( FSharpFindDeclFailureReason.ProvidedMember( e.EventName))
1129- | Item.ILField( ProvidedField(_) as f) -> FSharpFindDeclResult.DeclNotFound( FSharpFindDeclFailureReason.ProvidedMember( f.FieldName))
1183+ | SymbolHelpers.ItemIsProvidedType g( tcref) -> FSharpFindDeclResult.DeclNotFound( FSharpFindDeclFailureReason.ProvidedType( tcref.DisplayName))
1184+ | Item.CtorGroup( name, ProvidedMeth(_)::_)
1185+ | Item.MethodGroup( name, ProvidedMeth(_)::_, _)
1186+ | Item.Property( name, ProvidedProp(_)::_) -> FSharpFindDeclResult.DeclNotFound( FSharpFindDeclFailureReason.ProvidedMember( name))
1187+ | Item.Event( ProvidedEvent(_) as e) -> FSharpFindDeclResult.DeclNotFound( FSharpFindDeclFailureReason.ProvidedMember( e.EventName))
1188+ | Item.ILField( ProvidedField(_) as f) -> FSharpFindDeclResult.DeclNotFound( FSharpFindDeclFailureReason.ProvidedMember( f.FieldName))
11301189#endif
1131- | _ -> FSharpFindDeclResult.DeclNotFound defaultReason
1132-
1133- match rangeOfItem g preferFlag itemwith
1134- | None-> fail( FSharpFindDeclFailureReason.Unknown" " )
1135- | Some itemRange->
1136-
1137- let projectDir = Filename.directoryName( if projectFileName= " " then mainInputFileNameelse projectFileName)
1138- let filename = fileNameOfItem g( Some projectDir) itemRange item
1139- if FileSystem.SafeExists filenamethen
1140- FSharpFindDeclResult.DeclFound( mkRange filename itemRange.Start itemRange.End)
1141- else
1142- fail FSharpFindDeclFailureReason.NoSourceCode// provided items may have TypeProviderDefinitionLocationAttribute that binds them to some location
1190+ | _ -> FSharpFindDeclResult.DeclNotFound defaultReason
1191+
1192+ match rangeOfItem g preferFlag item.Item with
1193+ | None-> fail( FSharpFindDeclFailureReason.Unknown" " )
1194+ | Some itemRange->
1195+
1196+ let projectDir = Filename.directoryName( if projectFileName= " " then mainInputFileNameelse projectFileName)
1197+ let filename = fileNameOfItem g( Some projectDir) itemRange item.Item
1198+ if FileSystem.SafeExists filenamethen
1199+ FSharpFindDeclResult.DeclFound( mkRange filename itemRange.Start itemRange.End)
1200+ else
1201+ fail FSharpFindDeclFailureReason.NoSourceCode// provided items may have TypeProviderDefinitionLocationAttribute that binds them to some location
11431202)
11441203( fun msg ->
11451204 Trace.TraceInformation( sprintf" FCS: recovering from error in GetDeclarationLocation: '%s '" msg)