-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better Completion for ExternalAutocomplete functions #1178
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
932a30b
Try fix insert "Array.map" become "``Array.map``"
ijklam c16da84
fix format
ijklam b7837ea
Fix: Completion insert wrong open statement
ijklam 537faf9
fix
ijklam b053be9
fix and improve
ijklam 0462309
fix
ijklam c17a9d0
minor refactor: extract completion item to function and expand on docs
baronfel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2575,6 +2575,11 @@ type AdaptiveFSharpLspServer | |
getCompletions forceGetOpenFileTypeCheckResults | ||
| _ -> getCompletions forceGetOpenFileTypeCheckResultsStale | ||
|
||
let getCodeToInsert (d: DeclarationListItem) = | ||
match d.NamespaceToOpen with | ||
| Some no when config.FullNameExternalAutocomplete -> sprintf "%s.%s" no d.NameInCode | ||
| _ -> d.NameInCode | ||
|
||
match! | ||
retryAsyncOption | ||
(TimeSpan.FromMilliseconds(15.)) | ||
|
@@ -2592,7 +2597,7 @@ type AdaptiveFSharpLspServer | |
transact (fun () -> | ||
HashMap.OfList( | ||
[ for d in decls do | ||
d.NameInList, (d, pos, filePath, volatileFile.Source.GetLine, typeCheckResults.GetAST) ] | ||
d.FullName, (d, pos, filePath, volatileFile.Source.GetLine, typeCheckResults.GetAST) ] | ||
) | ||
|> autoCompleteItems.UpdateTo) | ||
|> ignore<bool> | ||
|
@@ -2602,26 +2607,22 @@ type AdaptiveFSharpLspServer | |
let items = | ||
decls | ||
|> Array.mapi (fun id d -> | ||
let code = | ||
if | ||
System.Text.RegularExpressions.Regex.IsMatch(d.NameInList, """^[a-zA-Z][a-zA-Z0-9']+$""") | ||
then | ||
d.NameInList | ||
elif d.NamespaceToOpen.IsSome then | ||
d.NameInList | ||
else | ||
FSharpKeywords.NormalizeIdentifierBackticks d.NameInList | ||
|
||
let label = | ||
let code = getCodeToInsert d | ||
|
||
let label, filterText = | ||
match d.NamespaceToOpen with | ||
| 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 code | ||
InsertText = Some(getCodeToInsert d) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
SortText = Some(sprintf "%06d" id) | ||
FilterText = Some d.NameInList | ||
FilterText = Some filterText | ||
Label = label }) | ||
|
||
let its = | ||
|
@@ -2650,6 +2651,8 @@ type AdaptiveFSharpLspServer | |
} | ||
|
||
override __.CompletionItemResolve(ci: CompletionItem) = | ||
let config = AVal.force config | ||
|
||
let mapHelpText (ci: CompletionItem) (text: HelpText) = | ||
match text with | ||
| HelpText.Simple(symbolName, text) -> | ||
|
@@ -2708,8 +2711,8 @@ type AdaptiveFSharpLspServer | |
|
||
let n = | ||
match getAutoCompleteNamespacesByDeclName sym |> AVal.force with | ||
| None -> None | ||
| Some s -> Some s | ||
| Some s when not config.FullNameExternalAutocomplete -> Some s | ||
| _ -> None | ||
|
||
CoreResponse.Res(HelpText.Full(sym, tip, n)) | ||
|
||
|
@@ -2725,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 | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you describe in a comment the logic going on here? how does the label selection and the filter text impact the user experience of searching/filtering in the IDE?
The previous implementation didn't document why decisions were made, and so we don't have any sort of record for justification for making changes.