Skip to content

Commit

Permalink
fix and improve
Browse files Browse the repository at this point in the history
fix: completions with same label have same description
add: filter completions by full name under fullNameExternalAutocomplete
add: tests for fullNameExternalAutocomplete
  • Loading branch information
Tangent-90 committed Oct 19, 2023
1 parent 537faf9 commit b053be9
Show file tree
Hide file tree
Showing 7 changed files with 317 additions and 135 deletions.
6 changes: 5 additions & 1 deletion src/FsAutoComplete.Core/KeywordList.fs
Expand Up @@ -42,13 +42,16 @@ module KeywordList =
let hashSymbolCompletionItems =
hashDirectives
|> Seq.map (fun kv ->
let label = "#" + kv.Key

{ CompletionItem.Create(kv.Key) with
Data = Some(Newtonsoft.Json.Linq.JValue(label))
Kind = Some CompletionItemKind.Keyword
InsertText = Some kv.Key
FilterText = Some kv.Key
SortText = Some kv.Key
Documentation = Some(Documentation.String kv.Value)
Label = "#" + kv.Key })
Label = label })
|> Seq.toArray

let allKeywords: string list =
Expand All @@ -58,6 +61,7 @@ module KeywordList =
allKeywords
|> List.mapi (fun id k ->
{ CompletionItem.Create(k) with
Data = Some(Newtonsoft.Json.Linq.JValue(k))
Kind = Some CompletionItemKind.Keyword
InsertText = Some k
SortText = Some(sprintf "1000000%d" id)
Expand Down
25 changes: 15 additions & 10 deletions src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs
Expand Up @@ -2597,7 +2597,7 @@ type AdaptiveFSharpLspServer
transact (fun () ->
HashMap.OfList(
[ for d in decls do
getCodeToInsert d, (d, pos, filePath, volatileFile.Source.GetLine, typeCheckResults.GetAST) ]
d.FullName, (d, pos, filePath, volatileFile.Source.GetLine, typeCheckResults.GetAST) ]
)
|> autoCompleteItems.UpdateTo)
|> ignore<bool>
Expand All @@ -2607,17 +2607,22 @@ type AdaptiveFSharpLspServer
let items =
decls
|> Array.mapi (fun id d ->
let label =
let code = getCodeToInsert d

let label, filterText =
match d.NamespaceToOpen with
| Some no when config.FullNameExternalAutocomplete -> sprintf "%s (of %s)" d.NameInList no
| Some no -> sprintf "%s (open %s)" d.NameInList no
| None -> d.NameInList
| Some no when config.FullNameExternalAutocomplete ->
// allow filter "Ceiling (System.Math)" by "System.Math.Ceiling" or "CeilingSystem.Math"
sprintf "%s (%s)" d.NameInList no, d.NameInList + code
| Some no -> sprintf "%s (open %s)" d.NameInList no, d.NameInList
| None -> d.NameInList, d.NameInList

{ CompletionItem.Create(d.NameInList) with
Data = Some(JValue(d.FullName))
Kind = (AVal.force glyphToCompletionKind) d.Glyph
InsertText = Some(getCodeToInsert d)
SortText = Some(sprintf "%06d" id)
FilterText = Some d.NameInList
FilterText = Some filterText
Label = label })

let its =
Expand Down Expand Up @@ -2723,10 +2728,10 @@ type AdaptiveFSharpLspServer
)

return!
match ci.InsertText with
| None -> LspResult.internalError "No InsertText"
| Some insertText ->
helpText insertText
match ci.Data with
| None -> LspResult.internalError "No FullName"
| Some fullName ->
helpText (fullName.ToString())
|> Result.ofCoreResponse
|> Result.bimap
(function
Expand Down

0 comments on commit b053be9

Please sign in to comment.