Skip to content
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

Add default completion commit characters #1494

Merged
merged 3 commits into from
May 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -553,21 +553,6 @@
"command": "o.showOutput",
"key": "Ctrl+L L",
"mac": "Cmd+L L"
},
{
"key": "shift+0",
"command": "^acceptSelectedSuggestion",
"when": "editorTextFocus && suggestWidgetVisible && editorLangId == 'csharp' && suggestionSupportsAcceptOnKey"
},
{
"key": "shift+9",
"command": "^acceptSelectedSuggestion",
"when": "editorTextFocus && suggestWidgetVisible && editorLangId == 'csharp' && suggestionSupportsAcceptOnKey"
},
{
"key": ".",
"command": "^acceptSelectedSuggestion",
"when": "editorTextFocus && suggestWidgetVisible && editorLangId == 'csharp' && suggestionSupportsAcceptOnKey"
}
],
"snippets": [
Expand Down
12 changes: 10 additions & 2 deletions src/features/completionItemProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import {CompletionItemProvider, CompletionItem, CompletionItemKind, Cancellation

export default class OmniSharpCompletionItemProvider extends AbstractSupport implements CompletionItemProvider {

// copied from Roslyn here: https://github.com/dotnet/roslyn/blob/6e8f6d600b6c4bc0b92bc3d782a9e0b07e1c9f8e/src/Features/Core/Portable/Completion/CompletionRules.cs#L166-L169
private static DefaultCommitCharacters = [
' ', '{', '}', '[', ']', '(', ')', '.', ',', ':',
';', '+', '-', '*', '/', '%', '&', '|', '^', '!',
'~', '=', '<', '>', '?', '@', '#', '\'', '\"', '\\'];

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is one long list 😄 Unsure if all commit characters make sense on all completion item kinds but the API is used as indented.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are precisely the characters we commit on in Visual Studio. 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that there are cases where we tweak the list for various commit characters for some items, but this matches 99.9% of them.

public provideCompletionItems(document: TextDocument, position: Position, token: CancellationToken): Promise<CompletionItem[]> {

let wordToComplete = '';
Expand All @@ -40,7 +46,7 @@ export default class OmniSharpCompletionItemProvider extends AbstractSupport imp
// transform AutoCompleteResponse to CompletionItem and
// group by code snippet
for (let response of responses) {
let completion = new CompletionItem(response.DisplayText);
let completion = new CompletionItem(response.CompletionText);

completion.detail = response.ReturnType
? `${response.ReturnType} ${response.DisplayText}`
Expand All @@ -49,6 +55,7 @@ export default class OmniSharpCompletionItemProvider extends AbstractSupport imp
completion.documentation = extractSummaryText(response.Description);
completion.kind = _kinds[response.Kind] || CompletionItemKind.Property;
completion.insertText = response.CompletionText.replace(/<>/g, '');
completion.commitCharacters = OmniSharpCompletionItemProvider.DefaultCommitCharacters;

let array = completions[completion.label];
if (!array) {
Expand Down Expand Up @@ -98,11 +105,12 @@ _kinds['Parameter'] = CompletionItemKind.Variable;
_kinds['RangeVariable'] = CompletionItemKind.Variable;

// members
_kinds['Const'] = CompletionItemKind.Constant;
_kinds['EnumMember'] = CompletionItemKind.EnumMember;
_kinds['Event'] = CompletionItemKind.Event;
_kinds['Field'] = CompletionItemKind.Field;
_kinds['Property'] = CompletionItemKind.Property;
_kinds['Method'] = CompletionItemKind.Method;
_kinds['Property'] = CompletionItemKind.Property;

// other stuff
_kinds['Label'] = CompletionItemKind.Unit; // need a better option for this.
Expand Down