提交 3cbf7dfd 编写于 作者: R Ravi Chande 提交者: GitHub

Merge pull request #14868 from rchande/sighelpLinkedFiles

Fix sighelp crash in linked files
......@@ -200,5 +200,35 @@ static void Main(string[] args)
await TestAsync(markup, expectedOrderedItems, usePreviousCharAsTrigger: true);
}
[WorkItem(14793, "https://github.com/dotnet/roslyn/issues/14793")]
[Fact, Trait(Traits.Feature, Traits.Features.SignatureHelp)]
public async Task DoNotCrashInLinkedFile()
{
var markup = @"<Workspace>
<Project Language=""C#"" CommonReferences=""true"" AssemblyName=""Proj1"" PreprocessorSymbols=""FOO"">
<Document FilePath=""SourceDocument""><![CDATA[
class C
{
#if FOO
void bar()
{
}
#endif
void foo()
{
(int, string) x = ($$
}
}
]]>
</Document>
</Project>
<Project Language=""C#"" CommonReferences=""true"" AssemblyName=""Proj2"">
<Document IsLinkFile=""true"" LinkAssemblyName=""Proj1"" LinkFilePath=""SourceDocument""/>
</Project>
</Workspace>";
var expectedDescription = new SignatureHelpTestItem($"(int, string)", currentParameterIndex: 0);
await VerifyItemWithReferenceWorkerAsync(markup, new[] { expectedDescription }, false);
}
}
}
......@@ -152,21 +152,30 @@ protected override async Task<SignatureHelpItems> GetItemsWorkerAsync(Document d
private SignatureHelpItems CreateItems(int position, SyntaxNode root, ISyntaxFactsService syntaxFacts,
SyntaxNode targetExpression, SemanticModel semanticModel, IEnumerable<INamedTypeSymbol> tupleTypes, CancellationToken cancellationToken)
{
var prefixParts = SpecializedCollections.SingletonEnumerable(new SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, null, "("));
var suffixParts = SpecializedCollections.SingletonEnumerable(new SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, null, ")"));
var separatorParts = GetSeparatorParts();
var prefixParts = SpecializedCollections.SingletonEnumerable(new SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, null, "(")).ToTaggedText();
var suffixParts = SpecializedCollections.SingletonEnumerable(new SymbolDisplayPart(SymbolDisplayPartKind.Punctuation, null, ")")).ToTaggedText();
var separatorParts = GetSeparatorParts().ToTaggedText();
var items = tupleTypes.Select(t =>
new SignatureHelpItem(isVariadic: false,
var items = tupleTypes.Select(tupleType => Convert(
tupleType, prefixParts, suffixParts, separatorParts, semanticModel, position))
.ToList();
var state = GetCurrentArgumentState(root, position, syntaxFacts, targetExpression.FullSpan, cancellationToken);
return CreateSignatureHelpItems(items, targetExpression.Span, state);
}
SignatureHelpItem Convert(INamedTypeSymbol tupleType, ImmutableArray<TaggedText> prefixParts, ImmutableArray<TaggedText> suffixParts,
ImmutableArray<TaggedText> separatorParts, SemanticModel semanticModel, int position)
{
return new SymbolKeySignatureHelpItem(
symbol: tupleType,
isVariadic: false,
documentationFactory: null,
prefixParts: prefixParts,
separatorParts: separatorParts,
suffixParts: suffixParts,
parameters: ConvertTupleMembers(t, semanticModel, position),
descriptionParts: null)).ToList();
var state = GetCurrentArgumentState(root, position, syntaxFacts, targetExpression.FullSpan, cancellationToken);
return CreateSignatureHelpItems(items, targetExpression.Span, state);
parameters: ConvertTupleMembers(tupleType, semanticModel, position),
descriptionParts: null);
}
private IEnumerable<SignatureHelpParameter> ConvertTupleMembers(INamedTypeSymbol tupleType, SemanticModel semanticModel, int position)
......
......@@ -188,7 +188,7 @@ where part.Symbol.IsNormalAnonymousType()
var finalItems = new List<SignatureHelpItem>();
foreach (var item in itemsForCurrentDocument.Items)
{
var symbolKey = ((SymbolKeySignatureHelpItem)item).SymbolKey;
var symbolKey = (item as SymbolKeySignatureHelpItem)?.SymbolKey;
if (symbolKey == null)
{
finalItems.Add(item);
......@@ -224,7 +224,7 @@ where part.Symbol.IsNormalAnonymousType()
foreach (var related in relatedDocuments)
{
// If we don't have symbol keys, give up.
if (related.Item2.Any(s => ((SymbolKeySignatureHelpItem)s).SymbolKey == null))
if (related.Item2.Any(s => (s as SymbolKeySignatureHelpItem)?.SymbolKey == null))
{
continue;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册