提交 d8184b7f 编写于 作者: D David Barbet

Update documentation/naming for retrieving collidable symbols.

上级 17a9a685
......@@ -26,7 +26,7 @@ private CSharpSemanticFactsService()
{
}
protected override IEnumerable<ISymbol> GetUsedSymbols(SemanticModel semanticModel, SyntaxNode location, SyntaxNode container, CancellationToken cancellationToken)
protected override IEnumerable<ISymbol> GetCollidableSymbols(SemanticModel semanticModel, SyntaxNode location, SyntaxNode container, CancellationToken cancellationToken)
{
// Get all the symbols visible to the current location.
var visibleSymbols = semanticModel.LookupSymbols(location.SpanStart);
......@@ -36,7 +36,7 @@ protected override IEnumerable<ISymbol> GetUsedSymbols(SemanticModel semanticMod
// Walk through the enclosing block to find them, but avoid exploring local functions because
// a) Visible local function symbols would be returned from LookupSymbols
// (e.g. location is inside a local function or the local function method name).
// b) Local function symbols are not affected by outer variables and do not contribute to the outer scope.
// b) Symbols declared inside a local function do not cause collisions with symbols declared outside the local function, so avoid considering them.
var symbolsInBlock = semanticModel.GetExistingSymbols(container, cancellationToken,
descendInto: n => !n.IsKind(SyntaxKind.LocalFunctionStatement));
......
......@@ -60,13 +60,18 @@ internal abstract class AbstractSemanticFactsService
var container = containerOpt ?? location.AncestorsAndSelf().FirstOrDefault(
a => syntaxFacts.IsExecutableBlock(a) || syntaxFacts.IsMethodBody(a));
var candidates = GetUsedSymbols(semanticModel, location, container, cancellationToken);
var candidates = GetCollidableSymbols(semanticModel, location, container, cancellationToken);
var filteredCandidates = filter != null ? candidates.Where(filter) : candidates;
return GenerateUniqueName(baseName, filteredCandidates.Select(s => s.Name).Concat(usedNames));
}
protected virtual IEnumerable<ISymbol> GetUsedSymbols(SemanticModel semanticModel, SyntaxNode location, SyntaxNode container, CancellationToken cancellationToken)
/// <summary>
/// Retrieves all symbols that could collide with a symbol at the specified location.
/// A symbol can possibly collide with the location if it is available to that location and/or
/// could cause a compiler error if its name is re-used at that location.
/// </summary>
protected virtual IEnumerable<ISymbol> GetCollidableSymbols(SemanticModel semanticModel, SyntaxNode location, SyntaxNode container, CancellationToken cancellationToken)
=> semanticModel.LookupSymbols(location.SpanStart).Concat(semanticModel.GetExistingSymbols(container, cancellationToken));
private SyntaxToken GenerateUniqueName(string baseName, IEnumerable<string> usedNames)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册