From 40e117a1a5fa219f393df53c9fc4f77c92f41b91 Mon Sep 17 00:00:00 2001 From: Vasily Kirichenko Date: Sat, 14 Oct 2017 17:48:35 +0300 Subject: [PATCH] fix IndexOutOfRange exception in advanced completion --- src/fsharp/vs/service.fs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/fsharp/vs/service.fs b/src/fsharp/vs/service.fs index d387ca9702a..a6af069f33b 100644 --- a/src/fsharp/vs/service.fs +++ b/src/fsharp/vs/service.fs @@ -567,14 +567,17 @@ type TypeCheckInfo | Item.Value _ -> CompletionItemKind.Field | _ -> CompletionItemKind.Other + let getNamespace (idents: Idents) = + if idents.Length > 1 then Some idents.[..idents.Length - 2] else None + let unresolved = unresolvedEntity |> Option.map (fun x -> - let ns = - match x.TopRequireQualifiedAccessParent with - | Some parent when not (Array.isEmpty parent) -> - parent.[..parent.Length - 2] - | _ -> x.CleanedIdents.[..x.CleanedIdents.Length - 2] + let ns = + x.TopRequireQualifiedAccessParent + |> Option.bind getNamespace + |> Option.orElseWith (fun () -> getNamespace x.CleanedIdents) + |> Option.defaultValue [||] let displayName = x.CleanedIdents |> Array.skip ns.Length |> String.concat "."