@@ -105,6 +105,86 @@ public async Task Hover_Success()
105105 ) ;
106106 }
107107
108+ /// <summary>
109+ /// Ensure that the language client can successfully request Completions.
110+ /// </summary>
111+ [ Fact ( DisplayName = "Language client can successfully request completions" ) ]
112+ public async Task Completions_Success ( )
113+ {
114+ await Connect ( ) ;
115+
116+ const int line = 5 ;
117+ const int column = 5 ;
118+ string expectedDocumentPath = AbsoluteDocumentPath ;
119+ Uri expectedDocumentUri = DocumentUri . FromFileSystemPath ( expectedDocumentPath ) ;
120+
121+ var expectedCompletionItems = new CompletionItem [ ]
122+ {
123+ new CompletionItem
124+ {
125+ Kind = CompletionItemKind . Class ,
126+ Label = "Class1" ,
127+ TextEdit = new TextEdit
128+ {
129+ Range = new Range
130+ {
131+ Start = new Position
132+ {
133+ Line = line ,
134+ Character = column
135+ } ,
136+ End = new Position
137+ {
138+ Line = line ,
139+ Character = column
140+ }
141+ } ,
142+ NewText = "Class1" ,
143+ }
144+ }
145+ } ;
146+
147+ ServerDispatcher . HandleRequest < TextDocumentPositionParams , CompletionList > ( "textDocument/completion" , ( request , cancellationToken ) =>
148+ {
149+ Assert . NotNull ( request . TextDocument ) ;
150+
151+ Assert . Equal ( expectedDocumentUri , request . TextDocument . Uri ) ;
152+
153+ Assert . Equal ( line , request . Position . Line ) ;
154+ Assert . Equal ( column , request . Position . Character ) ;
155+
156+ return Task . FromResult ( new CompletionList (
157+ expectedCompletionItems ,
158+ isIncomplete : true
159+ ) ) ;
160+ } ) ;
161+
162+ CompletionList actualCompletions = await LanguageClient . TextDocument . Completions ( AbsoluteDocumentPath , line , column ) ;
163+
164+ Assert . True ( actualCompletions . IsIncomplete , "completions.IsIncomplete" ) ;
165+ Assert . NotNull ( actualCompletions . Items ) ;
166+
167+ CompletionItem [ ] actualCompletionItems = actualCompletions . Items . ToArray ( ) ;
168+ Assert . Collection ( actualCompletionItems , actualCompletionItem =>
169+ {
170+ CompletionItem expectedCompletionItem = expectedCompletionItems [ 0 ] ;
171+
172+ Assert . Equal ( expectedCompletionItem . Kind , actualCompletionItem . Kind ) ;
173+ Assert . Equal ( expectedCompletionItem . Label , actualCompletionItem . Label ) ;
174+
175+ Assert . NotNull ( actualCompletionItem . TextEdit ) ;
176+ Assert . Equal ( expectedCompletionItem . TextEdit . NewText , actualCompletionItem . TextEdit . NewText ) ;
177+
178+ Assert . NotNull ( actualCompletionItem . TextEdit . Range ) ;
179+ Assert . NotNull ( actualCompletionItem . TextEdit . Range . Start ) ;
180+ Assert . NotNull ( actualCompletionItem . TextEdit . Range . End ) ;
181+ Assert . Equal ( expectedCompletionItem . TextEdit . Range . Start . Line , actualCompletionItem . TextEdit . Range . Start . Line ) ;
182+ Assert . Equal ( expectedCompletionItem . TextEdit . Range . Start . Character , actualCompletionItem . TextEdit . Range . Start . Character ) ;
183+ Assert . Equal ( expectedCompletionItem . TextEdit . Range . End . Line , actualCompletionItem . TextEdit . Range . End . Line ) ;
184+ Assert . Equal ( expectedCompletionItem . TextEdit . Range . End . Character , actualCompletionItem . TextEdit . Range . End . Character ) ;
185+ } ) ;
186+ }
187+
108188 /// <summary>
109189 /// Ensure that the language client can successfully receive Diagnostics from the server.
110190 /// </summary>
0 commit comments