Skip to content
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}";
Comment thread
dibarbet marked this conversation as resolved.
Outdated

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