Skip to content

Commit dd8563e

Browse files
authored
Fix Razor completion tooltip documentation (#5839)
1 parent 7caec7e commit dd8563e

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/razor/src/Completion/RazorCompletionItemProvider.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { getUriPath } from '../UriPaths';
1313
import { ProvisionalCompletionOrchestrator } from './ProvisionalCompletionOrchestrator';
1414
import { LanguageKind } from '../RPC/LanguageKind';
1515
import { RoslynLanguageServer } from '../../../lsptoolshost/roslynLanguageServer';
16-
import { CompletionItem, CompletionParams, CompletionTriggerKind } from 'vscode-languageclient';
16+
import { CompletionItem, CompletionList, CompletionParams, CompletionTriggerKind, MarkupContent } from 'vscode-languageclient';
1717
import { UriConverter } from '../../../lsptoolshost/uriConverter';
1818
import * as RazorConventions from '../RazorConventions';
1919
import { MappingHelpers } from '../Mapping/MappingHelpers';
@@ -35,11 +35,6 @@ export class RazorCompletionItemProvider
3535

3636
let completions: vscode.CompletionList | vscode.CompletionItem[];
3737

38-
// For CSharp, completions need to keep the "data" field
39-
// on the completion item for lazily resolving the edits in
40-
// the resolveCompletionItem step. Using the vs code command
41-
// drops that field because it doesn't exist in the declared vs code
42-
// CompletionItem type.
4338
if (language === LanguageKind.CSharp) {
4439
const params: CompletionParams = {
4540
context: {
@@ -52,6 +47,11 @@ export class RazorCompletionItemProvider
5247
position: projectedPosition
5348
};
5449

50+
// For CSharp, completions need to keep the "data" field on the
51+
// completion item for lazily resolving the edits in the
52+
// resolveCompletionItem step. Using the vs code command drops
53+
// that field because it doesn't exist in the declared vs code
54+
// CompletionItem type.
5555
completions = await vscode
5656
.commands
5757
.executeCommand<vscode.CompletionList | vscode.CompletionItem[]>(
@@ -71,6 +71,8 @@ export class RazorCompletionItemProvider
7171
completions instanceof Array ? completions // was vscode.CompletionItem[]
7272
: completions ? completions.items // was vscode.CompletionList
7373
: [];
74+
75+
const data = (<CompletionList>completions)?.itemDefaults?.data;
7476

7577
// There are times when the generated code will not line up with the content of the .razor/.cshtml file.
7678
// Therefore, we need to offset all completion items' characters by a certain amount in order
@@ -79,7 +81,7 @@ export class RazorCompletionItemProvider
7981
const completionCharacterOffset = projectedPosition.character - hostDocumentPosition.character;
8082
for (const completionItem of completionItems) {
8183
const doc = completionItem.documentation as vscode.MarkdownString;
82-
if (doc) {
84+
if (doc && doc.value) {
8385
// Without this, the documentation doesn't get rendered in the editor.
8486
const newDoc = new vscode.MarkdownString(doc.value);
8587
newDoc.isTrusted = doc.isTrusted;
@@ -128,6 +130,10 @@ export class RazorCompletionItemProvider
128130
completionItem.insertText = intellicodeCompletion.textEditText;
129131
}
130132
}
133+
134+
if (!(<CompletionItem>completionItem).data) {
135+
(<CompletionItem>completionItem).data = data;
136+
}
131137
}
132138

133139
const isIncomplete = completions instanceof Array ? false
@@ -204,6 +210,13 @@ export class RazorCompletionItemProvider
204210

205211
item = newItem;
206212

213+
// The documentation object Roslyn returns is a MarkupContent,
214+
// which we need to convert to a MarkdownString.
215+
const markupContent = <MarkupContent>(<unknown>(item.documentation));
216+
if (markupContent && markupContent.value) {
217+
item.documentation = new vscode.MarkdownString(markupContent.value);
218+
}
219+
207220
if (item.command && item.command.arguments?.length === 4) {
208221
let uri = vscode.Uri.parse(item.command.arguments[0]);
209222

@@ -238,4 +251,3 @@ function getTriggerKind(triggerKind: vscode.CompletionTriggerKind): CompletionTr
238251

239252
}
240253
}
241-

0 commit comments

Comments
 (0)