@@ -30,7 +30,8 @@ export class RazorCompletionItemProvider extends RazorLanguageFeatureBase implem
30
30
hostDocumentPosition : vscode . Position ,
31
31
projectedPosition : vscode . Position ,
32
32
context : vscode . CompletionContext ,
33
- language : LanguageKind
33
+ language : LanguageKind ,
34
+ razorDocument : vscode . TextDocument
34
35
) {
35
36
if ( projectedUri ) {
36
37
// "@" is not a valid trigger character for C# / HTML and therefore we need to translate
@@ -86,6 +87,11 @@ export class RazorCompletionItemProvider extends RazorLanguageFeatureBase implem
86
87
// In the code behind it's represented as __o = DateTime.
87
88
const completionCharacterOffset = projectedPosition . character - hostDocumentPosition . character ;
88
89
for ( const completionItem of completionItems ) {
90
+ // vscode.CompletionItemKind is off by one compared to the LSP CompletionItemKind.
91
+ if ( completionItem . kind !== undefined ) {
92
+ completionItem . kind = completionItem . kind - 1 ;
93
+ }
94
+
89
95
const doc = completionItem . documentation as vscode . MarkdownString ;
90
96
if ( doc && doc . value ) {
91
97
// Without this, the documentation doesn't get rendered in the editor.
@@ -166,6 +172,8 @@ export class RazorCompletionItemProvider extends RazorLanguageFeatureBase implem
166
172
}
167
173
}
168
174
175
+ this . addUsingKeyword ( language , razorDocument , hostDocumentPosition , completionItems ) ;
176
+
169
177
const isIncomplete = completions instanceof Array ? false : completions ? completions . isIncomplete : false ;
170
178
return new vscode . CompletionList ( completionItems , isIncomplete ) ;
171
179
}
@@ -221,7 +229,8 @@ export class RazorCompletionItemProvider extends RazorLanguageFeatureBase implem
221
229
position ,
222
230
projection . position ,
223
231
context ,
224
- projection . languageKind
232
+ projection . languageKind ,
233
+ document
225
234
) ;
226
235
227
236
return completionList ;
@@ -278,6 +287,38 @@ export class RazorCompletionItemProvider extends RazorLanguageFeatureBase implem
278
287
279
288
return item ;
280
289
}
290
+
291
+ private static addUsingKeyword (
292
+ language : LanguageKind ,
293
+ razorDocument : vscode . TextDocument ,
294
+ hostDocumentPosition : vscode . Position ,
295
+ completionItems : vscode . CompletionItem [ ]
296
+ ) {
297
+ // This is an ugly hack, but it's needed to get the "using" keyword to show up in the completion list.
298
+ // The reason it doesn't show up is because the C# generated document puts the position of the cursor
299
+ // at '__o = [||]', which isn't a valid location for a using statement.
300
+ if ( language == LanguageKind . CSharp ) {
301
+ const line = razorDocument . lineAt ( hostDocumentPosition . line ) ;
302
+ const lineText = line . text . substring ( 0 , hostDocumentPosition . character ) ;
303
+ if (
304
+ lineText . endsWith ( '@' ) ||
305
+ lineText . endsWith (
306
+ '@u' ||
307
+ lineText . endsWith ( '@us' ) ||
308
+ lineText . endsWith ( '@usi' ) ||
309
+ lineText . endsWith ( '@usin' ) ||
310
+ lineText . endsWith ( '@using' )
311
+ )
312
+ ) {
313
+ const usingItem = new vscode . CompletionItem ( 'using' , vscode . CompletionItemKind . Keyword ) ;
314
+
315
+ // Matching Roslyn's documentation behavior
316
+ ( < CompletionItem > usingItem ) . documentation = vscode . l10n . t ( '{0} Keyword' , 'using' ) ;
317
+
318
+ completionItems . push ( usingItem ) ;
319
+ }
320
+ }
321
+ }
281
322
}
282
323
283
324
function getTriggerKind ( triggerKind : vscode . CompletionTriggerKind ) : CompletionTriggerKind {
0 commit comments