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

Respond to vscode breaking change in 1.79.2 that triggers completion inside words #2542

Merged
merged 2 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,15 @@ private static void GetCompletionInfo(
}

changeSpan = updatedChange.Span;
// When inserting at the beginning or middle of a word, we want to only replace characters
// up until the caret position, but not after. For example when typing at the beginning of a word
// we only want to insert the completion before the rest of the word.
// However, Roslyn returns the entire word as the span to replace, so we have to adjust it.
if (position < changeSpan.End)
{
changeSpan = new(changeSpan.Start, length: position - changeSpan.Start);
}

(insertText, insertTextFormat) = getPossiblySnippetizedInsertText(updatedChange, adjustedNewPosition);

// If we're expecting there to be unimported types, put in an explicit sort text to put things already in scope first.
Expand Down
18 changes: 18 additions & 0 deletions tests/OmniSharp.Roslyn.CSharp.Tests/CompletionFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2250,6 +2250,24 @@ public C()
}
}

[Theory]
[InlineData("dummy.cs")]
[InlineData("dummy.csx")]
public async Task ReplacesUpUntilCursorInMiddleOfWord(string filename)
{
const string input =
@"pub$$class}";
dibarbet marked this conversation as resolved.
Show resolved Hide resolved

var completions = await FindCompletionsAsync(filename, input, SharedOmniSharpTestHost);
Assert.All(completions.Items, (completion) =>
{
Assert.Equal(0, completion.TextEdit.StartColumn);
Assert.Equal(0, completion.TextEdit.StartLine);
Assert.Equal(3, completion.TextEdit.EndColumn);
Assert.Equal(0, completion.TextEdit.EndLine);
});
}

private CompletionService GetCompletionService(OmniSharpTestHost host)
=> host.GetRequestHandler<CompletionService>(EndpointName);

Expand Down