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

Allow selection on move type to file.

上级 88fd618d
......@@ -19,7 +19,6 @@ private class State
public string TypeName { get; set; }
public string DocumentNameWithoutExtension { get; set; }
public bool IsDocumentNameAValidIdentifier { get; set; }
public bool IsSelectionOnTypeHeader { get; set; }
private State(SemanticDocument document)
{
......@@ -28,10 +27,10 @@ private State(SemanticDocument document)
internal static State Generate(
SemanticDocument document, TTypeDeclarationSyntax typeDeclaration,
bool isSelectionOnTypeHeader, CancellationToken cancellationToken)
CancellationToken cancellationToken)
{
var state = new State(document);
if (!state.TryInitialize(typeDeclaration, isSelectionOnTypeHeader, cancellationToken))
if (!state.TryInitialize(typeDeclaration, cancellationToken))
{
return null;
}
......@@ -41,7 +40,6 @@ private State(SemanticDocument document)
private bool TryInitialize(
TTypeDeclarationSyntax typeDeclaration,
bool isSelectionOnTypeHeader,
CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
......@@ -65,7 +63,6 @@ private State(SemanticDocument document)
TypeNode = typeDeclaration;
TypeName = typeSymbol.Name;
IsSelectionOnTypeHeader = isSelectionOnTypeHeader;
DocumentNameWithoutExtension = Path.GetFileNameWithoutExtension(SemanticDocument.Document.Name);
IsDocumentNameAValidIdentifier = syntaxFacts.IsValidIdentifier(DocumentNameWithoutExtension);
......
......@@ -40,7 +40,7 @@ internal abstract partial class AbstractMoveTypeService<TService, TTypeDeclarati
{
var state = await CreateStateAsync(document, textSpan, cancellationToken).ConfigureAwait(false);
if (state == null || !state.IsSelectionOnTypeHeader)
if (state == null)
{
return ImmutableArray<CodeAction>.Empty;
}
......@@ -73,24 +73,16 @@ public override async Task<Solution> GetModifiedSolutionAsync(Document document,
private async Task<State> CreateStateAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken)
{
if (!textSpan.IsEmpty)
{
return null;
}
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var nodeToAnalyze = root.FindToken(textSpan.Start).GetAncestor<TTypeDeclarationSyntax>();
var nodeToAnalyze = await document.TryGetRelevantNodeAsync<TTypeDeclarationSyntax>(textSpan, cancellationToken).ConfigureAwait(false);
if (nodeToAnalyze == null)
{
return null;
}
var syntaxFacts = document.GetLanguageService<ISyntaxFactsService>();
var isOnTypeHeader = syntaxFacts.IsOnTypeHeader(root, textSpan.Start, out _);
var semanticDocument = await SemanticDocument.CreateAsync(document, cancellationToken).ConfigureAwait(false);
return State.Generate(semanticDocument, nodeToAnalyze, isOnTypeHeader, cancellationToken);
return State.Generate(semanticDocument, nodeToAnalyze, cancellationToken);
}
private ImmutableArray<CodeAction> CreateActions(State state, CancellationToken cancellationToken)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册