@@ -204,16 +204,21 @@ type internal GoToDefinition(checker: FSharpChecker, projectInfoManager: FSharpP
204204return ! rangeToNavigableItem( fsSymbolUse.RangeAlternate, targetDocument)
205205}
206206
207- /// Use the targetSymbol to find the first instance of its presence in the provided source file.
208- member private __.FindSymbolDeclarationInFile ( targetSymbolUse : FSharpSymbolUse , filePath : string , source : string , options : FSharpProjectOptions , fileVersion : int ) =
207+ /// if the symbol is defined in the given file, return its declaration location, otherwise use the targetSymbol to find the first
208+ /// instance of its presence in the provided source file. The first case is needed to return proper declaration location for
209+ /// recursive type definitions, where the first its usage may not be the declaration.
210+ member __.FindSymbolDeclarationInFile ( targetSymbolUse : FSharpSymbolUse , filePath : string , source : string , options : FSharpProjectOptions , fileVersion : int ) =
209211asyncMaybe {
210- let! _ , checkFileAnswer = checker.ParseAndCheckFileInProject( filePath, fileVersion, source, options, userOpName= userOpName) |> liftAsync
211- match checkFileAnswerwith
212- | FSharpCheckFileAnswer.Aborted-> return ! None
213- | FSharpCheckFileAnswer.Succeeded checkFileResults->
214- let! symbolUses = checkFileResults.GetUsesOfSymbolInFile targetSymbolUse.Symbol|> liftAsync
215- let! implSymbol = symbolUses|> Array.tryHead
216- return implSymbol.RangeAlternate
212+ match targetSymbolUse.Symbol.DeclarationLocationwith
213+ | Some declwhen decl.FileName= filePath-> return decl
214+ | _ ->
215+ let! _ , checkFileAnswer = checker.ParseAndCheckFileInProject( filePath, fileVersion, source, options, userOpName= userOpName) |> liftAsync
216+ match checkFileAnswerwith
217+ | FSharpCheckFileAnswer.Aborted-> return ! None
218+ | FSharpCheckFileAnswer.Succeeded checkFileResults->
219+ let! symbolUses = checkFileResults.GetUsesOfSymbolInFile targetSymbolUse.Symbol|> liftAsync
220+ let! implSymbol = symbolUses|> Array.tryHead
221+ return implSymbol.RangeAlternate
217222}
218223
219224member private this.FindDefinitionAtPosition ( originDocument : Document , position : int ) =