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

Adds snippets support in LSP mode. #1422

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,28 @@ public async Task<CompletionList> Handle(CompletionParams request, CancellationT
Line = Convert.ToInt32(request.Position.Line),
WantKind = true,
WantDocumentationForEveryCompletionResult = true,
WantReturnType = true
WantReturnType = true,
WantSnippet = true,
};

var omnisharpResponse = await _autoCompleteHandler.Handle(omnisharpRequest);

var completions = new Dictionary<string, List<CompletionItem>>();
foreach (var response in omnisharpResponse)
{
bool isSnippet = !string.IsNullOrEmpty(response.Snippet);
demelev marked this conversation as resolved.
Show resolved Hide resolved
string text = isSnippet ? response.Snippet : response.CompletionText;
demelev marked this conversation as resolved.
Show resolved Hide resolved
var textFormat = isSnippet ? InsertTextFormat.Snippet : InsertTextFormat.PlainText;

var completionItem = new CompletionItem {
Label = response.CompletionText,
Detail = !string.IsNullOrEmpty(response.ReturnType) ?
response.DisplayText :
$"{response.ReturnType} {response.DisplayText}",
Documentation = response.Description,
Kind = GetCompletionItemKind(response.Kind),
InsertText = response.CompletionText,
InsertText = text,
InsertTextFormat = textFormat,
};

if(!completions.ContainsKey(completionItem.Label))
Expand Down