Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Commit faea276

Browse files
author
Mikhail Arkhipov
authored
Merge pull request #316 from jakebailey/null-markup
[WIP] Ensure DocumentationBuilder never has a null preferred MarkupKind
2 parents 198e8dd + 6adcca8 commit faea276

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

src/Analysis/Engine/Impl/Documentation/DocumentationBuilder.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ internal abstract class DocumentationBuilder {
3838

3939
public static DocumentationBuilder Create(InformationDisplayOptions displayOptions) {
4040
displayOptions = displayOptions ?? DefaultDisplayOptions;
41+
displayOptions.preferredFormat = displayOptions.preferredFormat ?? MarkupKind.PlainText; // MarkupKind should never be null.
4142

4243
if (displayOptions.preferredFormat == MarkupKind.Markdown) {
4344
return new MarkdownDocumentationBuilder(displayOptions);

src/Analysis/Engine/Test/CompletionTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
using Microsoft.Python.LanguageServer.Implementation;
2828
using Microsoft.PythonTools;
2929
using Microsoft.PythonTools.Analysis;
30+
using Microsoft.PythonTools.Analysis.Documentation;
3031
using Microsoft.PythonTools.Analysis.FluentAssertions;
3132
using Microsoft.PythonTools.Analysis.Infrastructure;
3233
using Microsoft.PythonTools.Interpreter;
@@ -1012,6 +1013,22 @@ public async Task WithWhitespaceAroundDot() {
10121013
}
10131014
}
10141015

1016+
[TestMethod, Priority(0)]
1017+
public async Task MarkupKindValid() {
1018+
using (var s = await CreateServerAsync()) {
1019+
var u = await s.OpenDefaultDocumentAndGetUriAsync("import sys\nsys.\n");
1020+
1021+
await s.WaitForCompleteAnalysisAsync(CancellationToken.None);
1022+
var res = await s.Completion(new CompletionParams {
1023+
textDocument = new TextDocumentIdentifier { uri = u },
1024+
position = new SourceLocation(2, 5),
1025+
context = new CompletionContext { triggerCharacter = ".", triggerKind = CompletionTriggerKind.TriggerCharacter },
1026+
}, CancellationToken.None);
1027+
1028+
res.items?.Select(i => i.documentation.kind).Should().NotBeEmpty().And.BeSubsetOf(new[] { MarkupKind.PlainText, MarkupKind.Markdown });
1029+
}
1030+
}
1031+
10151032
private static async Task AssertCompletion(Server s, Uri uri, IReadOnlyCollection<string> contains, IReadOnlyCollection<string> excludes, Position? position = null, CompletionContext? context = null, Func<CompletionItem, string> cmpKey = null, string expr = null, Range? applicableSpan = null) {
10161033
await s.WaitForCompleteAnalysisAsync(CancellationToken.None);
10171034
var res = await s.Completion(new CompletionParams {

src/Analysis/Engine/Test/HoverTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
using Microsoft.Python.Tests.Utilities.FluentAssertions;
2626
using Microsoft.PythonTools;
2727
using Microsoft.PythonTools.Analysis;
28+
using Microsoft.PythonTools.Analysis.Documentation;
2829
using Microsoft.PythonTools.Analysis.FluentAssertions;
2930
using Microsoft.PythonTools.Interpreter;
3031
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -143,6 +144,21 @@ def fob_derived(self):
143144
}
144145
}
145146

147+
[TestMethod, Priority(0)]
148+
public async Task MarkupKindValid() {
149+
using (var s = await CreateServerAsync()) {
150+
var u = await s.OpenDefaultDocumentAndGetUriAsync("123");
151+
152+
await s.WaitForCompleteAnalysisAsync(CancellationToken.None);
153+
var hover = await s.Hover(new TextDocumentPositionParams {
154+
textDocument = new TextDocumentIdentifier { uri = u },
155+
position = new SourceLocation(1, 1),
156+
}, CancellationToken.None);
157+
158+
hover.contents.kind.Should().BeOneOf(MarkupKind.PlainText, MarkupKind.Markdown);
159+
}
160+
}
161+
146162
private static async Task AssertHover(Server s, Uri uri, SourceLocation position, string hoverText, IEnumerable<string> typeNames, SourceSpan? range = null, string expr = null) {
147163
await s.WaitForCompleteAnalysisAsync(CancellationToken.None);
148164
var hover = await s.Hover(new TextDocumentPositionParams {

0 commit comments

Comments
 (0)