diff --git a/vsintegration/src/FSharp.Editor/Common/RoslynHelpers.fs b/vsintegration/src/FSharp.Editor/Common/RoslynHelpers.fs index ae8c5fe4fb6c7f0c6fffc96595c9cf0f0f3b366f..83b79f198c369de7a0d06334e801ae41b38afc3c 100644 --- a/vsintegration/src/FSharp.Editor/Common/RoslynHelpers.fs +++ b/vsintegration/src/FSharp.Editor/Common/RoslynHelpers.fs @@ -187,19 +187,30 @@ module internal OpenDeclarationHelper = let getLineStr line = sourceText.Lines.[line].ToString().Trim() let pos = ParsedInput.adjustInsertionPoint getLineStr ctx - let docLine = pos.Line - 1 + let docLine = Line.toZ pos.Line let lineStr = (String.replicate pos.Column " ") + "open " + ns - let sourceText = sourceText |> insert docLine lineStr + + // If we're at the top of a file (e.g., F# script) then add a newline before adding the open declaration + let sourceText = + if docLine = 0 then + sourceText + |> insert docLine Environment.NewLine + |> insert docLine lineStr + else + sourceText |> insert docLine lineStr + // if there's no a blank line between open declaration block and the rest of the code, we add one let sourceText = if sourceText.Lines.[docLine + 1].ToString().Trim() <> "" then sourceText |> insert (docLine + 1) "" else sourceText + let sourceText = // for top level module we add a blank line between the module declaration and first open statement if (pos.Column = 0 || ctx.ScopeKind = ScopeKind.Namespace) && docLine > 0 && not (sourceText.Lines.[docLine - 1].ToString().Trim().StartsWith "open") then sourceText |> insert docLine "" else sourceText + sourceText, minPos |> Option.defaultValue 0 diff --git a/vsintegration/src/FSharp.Editor/Completion/CompletionProvider.fs b/vsintegration/src/FSharp.Editor/Completion/CompletionProvider.fs index c2f16284cf670def58f8d70f1ce1592b466e1cdb..11c5f3f0c57cc3e7f414771a71bfd9b5e36d398a 100644 --- a/vsintegration/src/FSharp.Editor/Completion/CompletionProvider.fs +++ b/vsintegration/src/FSharp.Editor/Completion/CompletionProvider.fs @@ -143,10 +143,10 @@ type internal FSharpCompletionProvider declarationItems |> Array.iteri (fun number declarationItem -> let glyph = Tokenizer.FSharpGlyphToRoslynGlyph (declarationItem.Glyph, declarationItem.Accessibility) - let name = + let namespaceName = match declarationItem.NamespaceToOpen with - | Some namespaceToOpen -> sprintf "%s (open %s)" declarationItem.Name namespaceToOpen - | _ -> declarationItem.Name + | Some namespaceToOpen -> namespaceToOpen + | _ -> null // Icky, but this is how roslyn handles it let filterText = match declarationItem.NamespaceToOpen, declarationItem.Name.Split '.' with @@ -157,8 +157,14 @@ type internal FSharpCompletionProvider | _, idents -> Array.last idents let completionItem = - FSharpCommonCompletionItem.Create(name, null, rules = getRules intellisenseOptions.ShowAfterCharIsTyped, glyph = Nullable glyph, filterText = filterText) - .AddProperty(FullNamePropName, declarationItem.FullName) + FSharpCommonCompletionItem.Create( + declarationItem.Name, + null, + rules = getRules intellisenseOptions.ShowAfterCharIsTyped, + glyph = Nullable glyph, + filterText = filterText, + inlineDescription = namespaceName) + .AddProperty(FullNamePropName, declarationItem.FullName) let completionItem = match declarationItem.Kind with @@ -167,7 +173,7 @@ type internal FSharpCompletionProvider | _ -> completionItem let completionItem = - if name <> declarationItem.NameInCode then + if declarationItem.Name <> declarationItem.NameInCode then completionItem.AddProperty(NameInCodePropName, declarationItem.NameInCode) else completionItem