Skip to content

Commit

Permalink
Merge pull request #2542 from dibarbet/completion_1_79_2
Browse files Browse the repository at this point in the history
Respond to vscode breaking change in 1.79.2 that triggers completion inside words
  • Loading branch information
JoeRobich authored Jun 16, 2023
2 parents beb1835 + 7477e09 commit 0ab5af7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
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 = @"public class C1 {}
pub$$class";

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

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

Expand Down

0 comments on commit 0ab5af7

Please sign in to comment.