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

Allow selection on move type to file.

上级 88fd618d
...@@ -19,7 +19,6 @@ private class State ...@@ -19,7 +19,6 @@ private class State
public string TypeName { get; set; } public string TypeName { get; set; }
public string DocumentNameWithoutExtension { get; set; } public string DocumentNameWithoutExtension { get; set; }
public bool IsDocumentNameAValidIdentifier { get; set; } public bool IsDocumentNameAValidIdentifier { get; set; }
public bool IsSelectionOnTypeHeader { get; set; }
private State(SemanticDocument document) private State(SemanticDocument document)
{ {
...@@ -28,10 +27,10 @@ private State(SemanticDocument document) ...@@ -28,10 +27,10 @@ private State(SemanticDocument document)
internal static State Generate( internal static State Generate(
SemanticDocument document, TTypeDeclarationSyntax typeDeclaration, SemanticDocument document, TTypeDeclarationSyntax typeDeclaration,
bool isSelectionOnTypeHeader, CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
var state = new State(document); var state = new State(document);
if (!state.TryInitialize(typeDeclaration, isSelectionOnTypeHeader, cancellationToken)) if (!state.TryInitialize(typeDeclaration, cancellationToken))
{ {
return null; return null;
} }
...@@ -41,7 +40,6 @@ private State(SemanticDocument document) ...@@ -41,7 +40,6 @@ private State(SemanticDocument document)
private bool TryInitialize( private bool TryInitialize(
TTypeDeclarationSyntax typeDeclaration, TTypeDeclarationSyntax typeDeclaration,
bool isSelectionOnTypeHeader,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
if (cancellationToken.IsCancellationRequested) if (cancellationToken.IsCancellationRequested)
...@@ -65,7 +63,6 @@ private State(SemanticDocument document) ...@@ -65,7 +63,6 @@ private State(SemanticDocument document)
TypeNode = typeDeclaration; TypeNode = typeDeclaration;
TypeName = typeSymbol.Name; TypeName = typeSymbol.Name;
IsSelectionOnTypeHeader = isSelectionOnTypeHeader;
DocumentNameWithoutExtension = Path.GetFileNameWithoutExtension(SemanticDocument.Document.Name); DocumentNameWithoutExtension = Path.GetFileNameWithoutExtension(SemanticDocument.Document.Name);
IsDocumentNameAValidIdentifier = syntaxFacts.IsValidIdentifier(DocumentNameWithoutExtension); IsDocumentNameAValidIdentifier = syntaxFacts.IsValidIdentifier(DocumentNameWithoutExtension);
......
...@@ -40,7 +40,7 @@ internal abstract partial class AbstractMoveTypeService<TService, TTypeDeclarati ...@@ -40,7 +40,7 @@ internal abstract partial class AbstractMoveTypeService<TService, TTypeDeclarati
{ {
var state = await CreateStateAsync(document, textSpan, cancellationToken).ConfigureAwait(false); var state = await CreateStateAsync(document, textSpan, cancellationToken).ConfigureAwait(false);
if (state == null || !state.IsSelectionOnTypeHeader) if (state == null)
{ {
return ImmutableArray<CodeAction>.Empty; return ImmutableArray<CodeAction>.Empty;
} }
...@@ -73,24 +73,16 @@ public override async Task<Solution> GetModifiedSolutionAsync(Document document, ...@@ -73,24 +73,16 @@ public override async Task<Solution> GetModifiedSolutionAsync(Document document,
private async Task<State> CreateStateAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken) 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 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) if (nodeToAnalyze == null)
{ {
return 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); 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) 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.
先完成此消息的编辑!
想要评论请 注册