Skip to content

Commit 0ab5af7

Browse files
authored
Merge pull request #2542 from dibarbet/completion_1_79_2
Respond to vscode breaking change in 1.79.2 that triggers completion inside words
2 parents beb1835 + 7477e09 commit 0ab5af7

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

src/OmniSharp.Roslyn.CSharp/Services/Completion/CompletionListBuilder_Sync.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,15 @@ private static void GetCompletionInfo(
220220
}
221221

222222
changeSpan = updatedChange.Span;
223+
// When inserting at the beginning or middle of a word, we want to only replace characters
224+
// up until the caret position, but not after. For example when typing at the beginning of a word
225+
// we only want to insert the completion before the rest of the word.
226+
// However, Roslyn returns the entire word as the span to replace, so we have to adjust it.
227+
if (position < changeSpan.End)
228+
{
229+
changeSpan = new(changeSpan.Start, length: position - changeSpan.Start);
230+
}
231+
223232
(insertText, insertTextFormat) = getPossiblySnippetizedInsertText(updatedChange, adjustedNewPosition);
224233

225234
// If we're expecting there to be unimported types, put in an explicit sort text to put things already in scope first.

tests/OmniSharp.Roslyn.CSharp.Tests/CompletionFacts.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,6 +2250,24 @@ public C()
22502250
}
22512251
}
22522252

2253+
[Theory]
2254+
[InlineData("dummy.cs")]
2255+
[InlineData("dummy.csx")]
2256+
public async Task ReplacesUpUntilCursorInMiddleOfWord(string filename)
2257+
{
2258+
const string input = @"public class C1 {}
2259+
pub$$class";
2260+
2261+
var completions = await FindCompletionsAsync(filename, input, SharedOmniSharpTestHost);
2262+
Assert.All(completions.Items, (completion) =>
2263+
{
2264+
Assert.Equal(0, completion.TextEdit.StartColumn);
2265+
Assert.Equal(1, completion.TextEdit.StartLine);
2266+
Assert.Equal(3, completion.TextEdit.EndColumn);
2267+
Assert.Equal(1, completion.TextEdit.EndLine);
2268+
});
2269+
}
2270+
22532271
private CompletionService GetCompletionService(OmniSharpTestHost host)
22542272
=> host.GetRequestHandler<CompletionService>(EndpointName);
22552273

0 commit comments

Comments
 (0)