提交 12b023c4 编写于 作者: I Ivan Basov

more binding attempts

上级 6831f7f7
......@@ -2,8 +2,6 @@
using System.Composition;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.ChangeSignature;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Notification;
......@@ -21,12 +19,12 @@ public TestChangeSignatureOptionsService()
{
}
public Task AttachToEditorAsync(Document document, CancellationToken cancellationToken)
public AddedParameterResult GetAddedParameter(Document document)
{
return Task.CompletedTask;
throw new System.NotImplementedException();
}
public ChangeSignatureOptionsResult GetChangeSignatureOptions(ISymbol symbol, ParameterConfiguration parameters, INotificationService notificationService)
public ChangeSignatureOptionsResult GetChangeSignatureOptions(ISymbol symbol, ParameterConfiguration parameters, Document document, INotificationService notificationService)
{
var list = parameters.ToListOfParameters();
......@@ -38,10 +36,5 @@ public ChangeSignatureOptionsResult GetChangeSignatureOptions(ISymbol symbol, Pa
UpdatedSignature == null ? parameters : ParameterConfiguration.Create(UpdatedSignature.Select(i => list[i]).ToList(), parameters.ThisParameter != null, selectedIndex: 0))
};
}
public ChangeSignatureOptionsResult GetChangeSignatureOptions(ISymbol symbol, ParameterConfiguration parameters, Document document, INotificationService notificationService)
{
throw new System.NotImplementedException();
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.CodeAnalysis.ChangeSignature
{
internal sealed class AddedParameterResult
{
public AddedParameter AddedParameter;
public bool IsCancelled { get; set; }
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Notification;
......@@ -15,6 +13,6 @@ internal interface IChangeSignatureOptionsService : IWorkspaceService
Document document,
INotificationService notificationService);
Task AttachToEditorAsync(Document document, CancellationToken cancellationToken);
AddedParameterResult GetAddedParameter(Document document);
}
}
......@@ -27,13 +27,9 @@
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Height="Auto" Width="Auto" Orientation="Vertical">
<!--<StackPanel Orientation="Horizontal">
<Label>Modifier:</Label>
<Label Content="{Binding Modifier}"/>
</StackPanel>-->
<StackPanel Orientation="Horizontal">
<Label>Type:</Label>
<TextBox Width="200" Text="{Binding TypeName}"/>
<TextBox Width="200" Text="{Binding TypeNameEditorControl, Mode=OneTime}"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label>Name:</Label>
......
......@@ -6,10 +6,16 @@ namespace Microsoft.VisualStudio.LanguageServices.Implementation.ChangeSignature
{
internal class AddParameterDialogViewModel : AbstractNotifyPropertyChanged
{
public string TypeName { get; set; }
public AddParameterDialogViewModel(ParameterTypeEditorControl parameterTypeEditorControl)
{
TypeNameEditorControl = parameterTypeEditorControl;
}
public string ParameterName { get; set; }
public string CallsiteValue { get; set; }
public ParameterTypeEditorControl TypeNameEditorControl { get; }
internal bool TrySubmit()
{
return true;
......
......@@ -132,19 +132,12 @@ private void Restore_Click(object sender, RoutedEventArgs e)
private void Add_Click(object sender, RoutedEventArgs e)
{
var addParameterViewModel = new AddParameterDialogViewModel();
var dialog = new AddParameterDialog(addParameterViewModel);
var changeSignatureOptionsService = _viewModel.Document.Project.Solution.Workspace.Services.GetService<IChangeSignatureOptionsService>();
var result = changeSignatureOptionsService.GetAddedParameter(_viewModel.Document);
// TODO Wait?
changeSignatureOptionsService.AttachToEditorAsync(_viewModel.Document, CancellationToken.None).Wait();
var result = dialog.ShowModal();
if (result == true)
if (!result.IsCancelled)
{
_viewModel.AddParameter(addParameterViewModel);
_viewModel.AddParameter(result.AddedParameter);
}
SetFocusToSelectedRow();
......
......@@ -183,9 +183,9 @@ internal void Restore()
RemoveRestoreNotifyPropertyChanged();
}
internal void AddParameter(AddParameterDialogViewModel addParameterViewModel)
internal void AddParameter(AddedParameter addedParameter)
{
_parameterGroup1.Add(new AddedParameterViewModel(this, addParameterViewModel));
_parameterGroup1.Add(new AddedParameterViewModel(this, addedParameter));
RemoveRestoreNotifyPropertyChanged();
}
......@@ -539,23 +539,23 @@ public ParameterViewModel(ChangeSignatureDialogViewModel changeSignatureDialogVi
public class AddedParameterViewModel : ParameterViewModel
{
private readonly AddParameterDialogViewModel _addParameterViewModel;
private readonly AddedParameter _addedParameter;
public AddedParameterViewModel(ChangeSignatureDialogViewModel changeSignatureDialogViewModel, AddParameterDialogViewModel addParameterViewModel)
public AddedParameterViewModel(ChangeSignatureDialogViewModel changeSignatureDialogViewModel, AddedParameter addedParameter)
: base(changeSignatureDialogViewModel)
{
_addParameterViewModel = addParameterViewModel;
_addedParameter = addedParameter;
}
public override string Type => _addParameterViewModel.TypeName;
public override string Type => _addedParameter.TypeName;
public override string Parameter => _addParameterViewModel.ParameterName;
public override string Parameter => _addedParameter.ParameterName;
public override bool IsRemoved { get => false; set => throw new InvalidOperationException(); }
public override string ParameterAutomationText => $"{Type} {Parameter}";
public override bool IsDisabled => false;
public override string Callsite => _addParameterViewModel.CallsiteValue;
public override string Callsite => _addedParameter.CallsiteValue;
internal override Parameter CreateParameter()
=> new AddedParameter(Type, Parameter, Callsite);
......
using System;
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.CodeAnalysis.Editor;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.VisualStudio.Editor;
......@@ -7,9 +9,9 @@
namespace Microsoft.VisualStudio.LanguageServices.Implementation.ChangeSignature
{
internal sealed class AddParameterDialogOleCommandTarget : AbstractOleCommandTarget
internal sealed class ParameterTypeEditorControl : AbstractOleCommandTarget
{
internal AddParameterDialogOleCommandTarget(
internal ParameterTypeEditorControl(
IWpfTextView wpfTextView,
IVsEditorAdaptersFactoryService editorAdaptersFactory,
IServiceProvider serviceProvider)
......@@ -21,5 +23,7 @@ protected override ITextBuffer GetSubjectBufferContainingCaret()
{
return this.WpfTextView.GetBufferContainingCaret(contentType: ContentTypeNames.RoslynContentType);
}
public string GetText() => this.WpfTextView.TextSnapshot.GetText();
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.ComponentModel.Composition;
using System.Composition;
using System.Threading;
using System.Threading.Tasks;
......@@ -11,7 +10,6 @@
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.Editor;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Text.Classification;
......@@ -82,12 +80,37 @@ internal class VisualStudioChangeSignatureOptionsService : IChangeSignatureOptio
}
}
public async System.Threading.Tasks.Task AttachToEditorAsync(Document document, CancellationToken cancellationToken)
public AddedParameterResult GetAddedParameter(Document document)
{
var vsTextView = (await GetTextViewAsync(document, cancellationToken).ConfigureAwait(false)).Item1;
// TODO async?
var vsTextView = GetTextViewAsync(document, CancellationToken.None).Result.Item1;
var wpfTextView = _editorAdaptersFactoryService.GetWpfTextView(vsTextView);
var target = new AddParameterDialogOleCommandTarget(wpfTextView, _editorAdaptersFactoryService, _originalServiceProvider);
target.AttachToVsTextView();
var parameterTypeEditorControl = new ParameterTypeEditorControl(
wpfTextView,
_editorAdaptersFactoryService,
_originalServiceProvider);
parameterTypeEditorControl.AttachToVsTextView();
var viewModel = new AddParameterDialogViewModel(parameterTypeEditorControl);
var dialog = new AddParameterDialog(viewModel);
var result = dialog.ShowModal();
if (result.HasValue && result.Value)
{
return new AddedParameterResult
{
IsCancelled = false,
AddedParameter = new AddedParameter(
viewModel.TypeNameEditorControl.GetText(),
viewModel.ParameterName,
viewModel.CallsiteValue)
};
}
else
{
return new AddedParameterResult { IsCancelled = true };
}
}
private async Task<string> GetDocumentTextAsync(Document document, CancellationToken cancellationToken)
......@@ -98,7 +121,7 @@ private async Task<string> GetDocumentTextAsync(Document document, CancellationT
return sourceText.ToString();
}
private async Task<(IVsTextView, IWpfTextViewHost)> GetTextViewAsync(Document document, CancellationToken cancellationToken)
public async Task<(IVsTextView, IWpfTextViewHost)> GetTextViewAsync(Document document, CancellationToken cancellationToken)
{
var documentText = await GetDocumentTextAsync(document, cancellationToken).ConfigureAwait(false);
......@@ -111,8 +134,8 @@ private async Task<(IVsTextView, IWpfTextViewHost)> GetTextViewAsync(Document do
var bufferAdapter = _vsEditorAdaptersFactoryService.CreateVsTextBufferAdapter(_serviceProvider, _contentType);
bufferAdapter.InitializeContent(documentText, documentText.Length);
// var textBuffer = _vsEditorAdaptersFactoryService.GetDataBuffer(bufferAdapter);
// document.Project.Solution.Workspace.OnDocumentOpened(document.Id, textBuffer.AsTextContainer());
// var textBuffer = _vsEditorAdaptersFactoryService.GetDataBuffer(bufferAdapter);
// document.Project.Solution.Workspace.OnDocumentOpened(document.Id, textBuffer.AsTextContainer());
var initView = new[] {
new INITVIEW()
......
......@@ -438,6 +438,7 @@ class MyClass
New TestNotificationService(),
ParameterConfiguration.Create(symbol.GetParameters().Select(Function(p) DirectCast(New ExistingParameter(p), Parameter)).ToList(), symbol.IsExtensionMethod(), selectedIndex:=0),
symbol,
workspaceDoc,
workspace.ExportProvider.GetExportedValue(Of IClassificationFormatMapService)().GetClassificationFormatMap("text"),
workspace.ExportProvider.GetExportedValue(Of ClassificationTypeMap)())
Return New ChangeSignatureViewModelTestState(viewModel, symbol.GetParameters())
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册