@@ -341,6 +341,18 @@ type FSharpTextEditorCompletion() =
341341
342342
343343open Microsoft.FSharp .Compiler .Range
344+
345+ [<AutoOpen>]
346+ module Helper =
347+ type UntypedParseInfo with
348+ // GetNavigationItems is not 100% solid and throws occasional exceptions
349+ member x.GetNavigationItemsDeclarationsSafe () =
350+ try x.GetNavigationItems() .Declarations
351+ with _ ->
352+ Debug.Assert( false , " couldn't update navigation items, ignoring" )
353+ [| |]
354+
355+
344356type FSharpPathExtension () =
345357 inherit TextEditorExtension()
346358
@@ -387,7 +399,10 @@ type FSharpPathExtension() =
387399 let cursor = ( docloc.Column, docloc.Line)
388400 posGeq cursor start && posGeq finish cursor
389401
390- let toplevel = ast.Untyped.GetNavigationItems() .Declarations
402+ let toplevel =
403+ // GetNavigationItems is not 100% solid and throws occasional exceptions
404+ try ast.Untyped.GetNavigationItemsDeclarationsSafe()
405+ with _ -> [| |]
391406
392407 #if DEBUG
393408 let allthings = [| for tl in toplevel do yield ( tl.Declaration.Name, tl.Nested |> Array.map ( fun n -> n.Name)) |]
@@ -454,13 +469,13 @@ and FSharpDataProvider(ext:FSharpPathExtension, tag) =
454469 memberList.Clear()
455470 match tag with
456471 | :? TypedParseResult as tpr ->
457- let navitems = tpr.Untyped.GetNavigationItems ()
458- for decl in navitems.Declarations do
472+ let navitems = tpr.Untyped.GetNavigationItemsDeclarationsSafe ()
473+ for decl in navitems do
459474 memberList.Add( decl.Declaration)
460475 | :? ( TypedParseResult * string) as typeAndFilter ->
461476 let tpr , filter = typeAndFilter
462- let navitems = tpr.Untyped.GetNavigationItems ()
463- for decl in navitems.Declarations do
477+ let navitems = tpr.Untyped.GetNavigationItemsDeclarationsSafe ()
478+ for decl in navitems do
464479 if decl.Declaration.Name.StartsWith( filter) then
465480 memberList.Add( decl.Declaration)
466481 | :? TopLevelDeclaration as tld ->
0 commit comments