@@ -680,6 +680,66 @@ public async Task TryGetProvisionalCompletionsAsync_ProjectionAtStartOfLine_Retu
680680 Assert . Null ( result ) ;
681681 }
682682
683+ [ Fact ]
684+ public async Task TryGetProvisionalCompletionsAsync_NullHostDocumentVersion_ReturnsFalse ( )
685+ {
686+ // Arrange
687+ var completionRequest = new CompletionParams ( )
688+ {
689+ TextDocument = new TextDocumentIdentifier ( ) { Uri = Uri } ,
690+ Context = new CompletionContext ( )
691+ {
692+ TriggerKind = CompletionTriggerKind . TriggerCharacter ,
693+ TriggerCharacter = "."
694+ } ,
695+ Position = new Position ( 0 , 1 )
696+ } ;
697+
698+ var virtualDocumentUri = new Uri ( "C:/path/to/file.razor__virtual.cs" ) ;
699+
700+ var documentManager = new TestDocumentManager ( ) ;
701+
702+ var languageServerCalled = false ;
703+ var expectedItem = new CompletionItem ( ) { InsertText = "DateTime" } ;
704+ var requestInvoker = new Mock < LSPRequestInvoker > ( MockBehavior . Strict ) ;
705+ requestInvoker
706+ . Setup ( r => r . ReinvokeRequestOnServerAsync < CompletionParams , SumType < CompletionItem [ ] , CompletionList > ? > ( It . IsAny < string > ( ) , RazorLSPConstants . CSharpContentTypeName , It . IsAny < CompletionParams > ( ) , It . IsAny < CancellationToken > ( ) ) )
707+ . Callback < string , string , CompletionParams , CancellationToken > ( ( method , serverContentType , completionParams , ct ) =>
708+ {
709+ Assert . Equal ( Methods . TextDocumentCompletionName , method ) ;
710+ Assert . Equal ( RazorLSPConstants . CSharpContentTypeName , serverContentType ) ;
711+ languageServerCalled = true ;
712+ } )
713+ . Returns ( Task . FromResult < SumType < CompletionItem [ ] , CompletionList > ? > ( new [ ] { expectedItem } ) ) ;
714+
715+ var projectionResult = new ProjectionResult ( )
716+ {
717+ LanguageKind = RazorLanguageKind . Html ,
718+ Position = new Position ( 1 , 7 )
719+ } ;
720+ var previousCharacterProjection = new ProjectionResult ( )
721+ {
722+ LanguageKind = RazorLanguageKind . CSharp ,
723+ Position = new Position ( 100 , 10 ) ,
724+ PositionIndex = 1000 ,
725+ Uri = virtualDocumentUri ,
726+ HostDocumentVersion = null ,
727+ } ;
728+ var projectionProvider = new Mock < LSPProjectionProvider > ( ) ;
729+ projectionProvider . Setup ( p => p . GetProjectionAsync ( It . IsAny < LSPDocumentSnapshot > ( ) , It . IsAny < Position > ( ) , It . IsAny < CancellationToken > ( ) ) ) . Returns ( Task . FromResult ( previousCharacterProjection ) ) ;
730+
731+ var completionHandler = new CompletionHandler ( JoinableTaskContext , requestInvoker . Object , documentManager , projectionProvider . Object ) ;
732+
733+ // Act
734+ var ( succeeded , result ) = await completionHandler . TryGetProvisionalCompletionsAsync ( completionRequest , Mock . Of < LSPDocumentSnapshot > ( ) , projectionResult , CancellationToken . None ) . ConfigureAwait ( false ) ;
735+
736+ // Assert
737+ Assert . False ( succeeded ) ;
738+ Assert . False ( languageServerCalled ) ;
739+ Assert . Equal ( 0 , documentManager . UpdateVirtualDocumentCallCount ) ;
740+ Assert . Null ( result ) ;
741+ }
742+
683743 [ Fact ]
684744 public async Task TryGetProvisionalCompletionsAsync_AtCorrectProvisionalCompletionPoint_ReturnsExpectedResult ( )
685745 {
@@ -722,7 +782,8 @@ public async Task TryGetProvisionalCompletionsAsync_AtCorrectProvisionalCompleti
722782 LanguageKind = RazorLanguageKind . CSharp ,
723783 Position = new Position ( 100 , 10 ) ,
724784 PositionIndex = 1000 ,
725- Uri = virtualDocumentUri
785+ Uri = virtualDocumentUri ,
786+ HostDocumentVersion = 1 ,
726787 } ;
727788 var projectionProvider = new Mock < LSPProjectionProvider > ( ) ;
728789 projectionProvider . Setup ( p => p . GetProjectionAsync ( It . IsAny < LSPDocumentSnapshot > ( ) , It . IsAny < Position > ( ) , It . IsAny < CancellationToken > ( ) ) ) . Returns ( Task . FromResult ( previousCharacterProjection ) ) ;
0 commit comments