未验证 提交 d43aed44 编写于 作者: P Phillip Carter 提交者: GitHub

Use roslyn API to display extended completion and fix quirks with scripts/top of file (#9165)

* Use roslyn API to show unopened namespace in extended completion

* Properly add open decls when at the top of a file
上级 5f02ed23
......@@ -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
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册