Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add usings on paste #48501

Merged
merged 37 commits into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
2568592
Hook up paste command to also automatically add usings. Operation uses
ryzngard Oct 5, 2020
0091ea7
Merge remote-tracking branch 'upstream/master' into feature/usings_on…
ryzngard Oct 12, 2020
df94296
PR cleanup
ryzngard Oct 13, 2020
493b1b3
Split into analyze and add for imports service
ryzngard Oct 13, 2020
59ea5b0
Move to own paste handler
ryzngard Oct 14, 2020
152c6c4
Add options to disable using/import on paste
ryzngard Oct 14, 2020
3873ece
Update xlf files
ryzngard Oct 15, 2020
27d5d86
Update src/Features/Core/Portable/CodeRefactorings/AddMissingImports/…
ryzngard Oct 15, 2020
97ac747
String updates
ryzngard Oct 15, 2020
0524931
Fix for interactive window test. Fix paste integration test
ryzngard Oct 15, 2020
5f61773
Fix nullable stuff
ryzngard Oct 16, 2020
97f4015
Make IPackageInstallerService an optional service for implementation
ryzngard Oct 16, 2020
d8f65bf
Nullable enable IAddImportFeatureService
ryzngard Oct 16, 2020
fe5ee18
Undo unneeded changes
ryzngard Oct 19, 2020
166f67d
Small fixes from PR comments
ryzngard Oct 19, 2020
941bdb9
Merge remote-tracking branch 'upstream/master' into feature/usings_on…
ryzngard Oct 19, 2020
1e6b5ab
Fix change to document
ryzngard Oct 19, 2020
7b9804d
Update strings
ryzngard Oct 20, 2020
ec24927
Remove TextSpan and bool from AddMissingImportsAnalysisResult
ryzngard Oct 20, 2020
a515b46
Merge remote-tracking branch 'upstream/master' into feature/usings_on…
ryzngard Oct 23, 2020
ec66018
Only use CSharp and VB content type. Some PR feedback
ryzngard Oct 27, 2020
f3581a3
Add back check
ryzngard Oct 27, 2020
b425c0a
Go back to using a function
ryzngard Oct 27, 2020
37fd002
Merge branch 'feature/usings_on_paste' of https://github.com/ryzngard…
ryzngard Oct 27, 2020
bce4b47
Move the GetCommandState function
ryzngard Oct 27, 2020
78a0270
Split paste command handler into VB and CSharp
ryzngard Oct 27, 2020
0c61992
WIP
ryzngard Oct 28, 2020
44ca881
Merge branch 'master' into feature/usings_on_paste
ryzngard Nov 17, 2020
898f074
Turn off by default
ryzngard Nov 17, 2020
4c43c6a
idk anymore I'm just tired and want this in
ryzngard Nov 17, 2020
8567a39
Fix nullability warning
ryzngard Nov 18, 2020
4bbf76f
Apply suggestions from code review
ryzngard Nov 19, 2020
aaae96c
Merge remote-tracking branch 'upstream/master' into feature/usings_on…
ryzngard Nov 19, 2020
2bc116a
Fixup after merge/suggestions
ryzngard Nov 19, 2020
c33060a
Undo changes to GetChangesForCodeActionsAsync. Rename that was missed…
ryzngard Nov 20, 2020
4428713
Modify ExecuteCommand ordering
ryzngard Nov 20, 2020
279d531
Whitespace should never been seen nor heard
ryzngard Nov 20, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.ComponentModel.Composition;
using Microsoft.CodeAnalysis.Editor.Implementation.AddImports;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.VisualStudio.Commanding;
using Microsoft.VisualStudio.Utilities;

namespace Microsoft.CodeAnalysis.Editor.CSharp.AddImports
{
[Export]
[Export(typeof(ICommandHandler))]
[ContentType(ContentTypeNames.CSharpContentType)]
[Name(PredefinedCommandHandlerNames.AddImportsPaste)]
// Order is important here, this command needs to execute before PasteTracking
// since it may modify the pasted span. Paste tracking dismisses if
// the span is modified. It doesn't need to be before FormatDocument, but
// this helps the order of execution be more constant in case there
// are problems that arise. This command will always execute the next
// command before doing operations.
[Order(After = PredefinedCommandHandlerNames.PasteTrackingPaste)]
[Order(Before = PredefinedCommandHandlerNames.FormatDocument)]
internal class CSharpAddImportsPasteCommandHandler : AbstractAddImportsPasteCommandHandler
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public CSharpAddImportsPasteCommandHandler(IThreadingContext threadingContext) : base(threadingContext)
{
}

public override string DisplayName => CSharpEditorResources.Add_Missing_Usings_on_Paste;
protected override string DialogText => CSharpEditorResources.Adding_missing_usings;
}
}
8 changes: 8 additions & 0 deletions src/EditorFeatures/CSharp/CSharpEditorResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,12 @@
<data name="Generate_Event_Subscription" xml:space="preserve">
<value>Generate Event Subscription</value>
</data>
<data name="Adding_missing_usings" xml:space="preserve">
<value>Adding missing usings...</value>
<comment>Shown in a thread await dialog. "usings" is a language specific term and should not be localized</comment>
</data>
<data name="Add_Missing_Usings_on_Paste" xml:space="preserve">
<value>Add Missing Usings on Paste</value>
<comment>"usings" is a language specific term and should not be localized</comment>
</data>
</root>
10 changes: 10 additions & 0 deletions src/EditorFeatures/CSharp/xlf/CSharpEditorResources.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="cs" original="../CSharpEditorResources.resx">
<body>
<trans-unit id="Add_Missing_Usings_on_Paste">
<source>Add Missing Usings on Paste</source>
<target state="new">Add Missing Usings on Paste</target>
<note>"usings" is a language specific term and should not be localized</note>
</trans-unit>
<trans-unit id="Adding_missing_usings">
<source>Adding missing usings...</source>
<target state="new">Adding missing usings...</target>
<note>Shown in a thread await dialog. "usings" is a language specific term and should not be localized</note>
</trans-unit>
<trans-unit id="Chosen_version_0">
<source>Chosen version: '{0}'</source>
<target state="translated">Zvolená verze: {0}</target>
Expand Down
10 changes: 10 additions & 0 deletions src/EditorFeatures/CSharp/xlf/CSharpEditorResources.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="de" original="../CSharpEditorResources.resx">
<body>
<trans-unit id="Add_Missing_Usings_on_Paste">
<source>Add Missing Usings on Paste</source>
<target state="new">Add Missing Usings on Paste</target>
<note>"usings" is a language specific term and should not be localized</note>
</trans-unit>
<trans-unit id="Adding_missing_usings">
<source>Adding missing usings...</source>
<target state="new">Adding missing usings...</target>
<note>Shown in a thread await dialog. "usings" is a language specific term and should not be localized</note>
</trans-unit>
<trans-unit id="Chosen_version_0">
<source>Chosen version: '{0}'</source>
<target state="translated">Ausgewählte Version: {0}</target>
Expand Down
10 changes: 10 additions & 0 deletions src/EditorFeatures/CSharp/xlf/CSharpEditorResources.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="es" original="../CSharpEditorResources.resx">
<body>
<trans-unit id="Add_Missing_Usings_on_Paste">
<source>Add Missing Usings on Paste</source>
<target state="new">Add Missing Usings on Paste</target>
<note>"usings" is a language specific term and should not be localized</note>
</trans-unit>
<trans-unit id="Adding_missing_usings">
<source>Adding missing usings...</source>
<target state="new">Adding missing usings...</target>
<note>Shown in a thread await dialog. "usings" is a language specific term and should not be localized</note>
</trans-unit>
<trans-unit id="Chosen_version_0">
<source>Chosen version: '{0}'</source>
<target state="translated">Versión elegida: "{0}"</target>
Expand Down
10 changes: 10 additions & 0 deletions src/EditorFeatures/CSharp/xlf/CSharpEditorResources.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="fr" original="../CSharpEditorResources.resx">
<body>
<trans-unit id="Add_Missing_Usings_on_Paste">
<source>Add Missing Usings on Paste</source>
<target state="new">Add Missing Usings on Paste</target>
<note>"usings" is a language specific term and should not be localized</note>
</trans-unit>
<trans-unit id="Adding_missing_usings">
<source>Adding missing usings...</source>
<target state="new">Adding missing usings...</target>
<note>Shown in a thread await dialog. "usings" is a language specific term and should not be localized</note>
</trans-unit>
<trans-unit id="Chosen_version_0">
<source>Chosen version: '{0}'</source>
<target state="translated">Version choisie : '{0}'</target>
Expand Down
10 changes: 10 additions & 0 deletions src/EditorFeatures/CSharp/xlf/CSharpEditorResources.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="it" original="../CSharpEditorResources.resx">
<body>
<trans-unit id="Add_Missing_Usings_on_Paste">
<source>Add Missing Usings on Paste</source>
<target state="new">Add Missing Usings on Paste</target>
<note>"usings" is a language specific term and should not be localized</note>
</trans-unit>
<trans-unit id="Adding_missing_usings">
<source>Adding missing usings...</source>
<target state="new">Adding missing usings...</target>
<note>Shown in a thread await dialog. "usings" is a language specific term and should not be localized</note>
</trans-unit>
<trans-unit id="Chosen_version_0">
<source>Chosen version: '{0}'</source>
<target state="translated">Versione selezionata: '{0}'</target>
Expand Down
10 changes: 10 additions & 0 deletions src/EditorFeatures/CSharp/xlf/CSharpEditorResources.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="ja" original="../CSharpEditorResources.resx">
<body>
<trans-unit id="Add_Missing_Usings_on_Paste">
<source>Add Missing Usings on Paste</source>
<target state="new">Add Missing Usings on Paste</target>
<note>"usings" is a language specific term and should not be localized</note>
</trans-unit>
<trans-unit id="Adding_missing_usings">
<source>Adding missing usings...</source>
<target state="new">Adding missing usings...</target>
<note>Shown in a thread await dialog. "usings" is a language specific term and should not be localized</note>
</trans-unit>
<trans-unit id="Chosen_version_0">
<source>Chosen version: '{0}'</source>
<target state="translated">選択されたバージョン: '{0}'</target>
Expand Down
10 changes: 10 additions & 0 deletions src/EditorFeatures/CSharp/xlf/CSharpEditorResources.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="ko" original="../CSharpEditorResources.resx">
<body>
<trans-unit id="Add_Missing_Usings_on_Paste">
<source>Add Missing Usings on Paste</source>
<target state="new">Add Missing Usings on Paste</target>
<note>"usings" is a language specific term and should not be localized</note>
</trans-unit>
<trans-unit id="Adding_missing_usings">
<source>Adding missing usings...</source>
<target state="new">Adding missing usings...</target>
<note>Shown in a thread await dialog. "usings" is a language specific term and should not be localized</note>
</trans-unit>
<trans-unit id="Chosen_version_0">
<source>Chosen version: '{0}'</source>
<target state="translated">선택한 버전: '{0}'</target>
Expand Down
10 changes: 10 additions & 0 deletions src/EditorFeatures/CSharp/xlf/CSharpEditorResources.pl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="pl" original="../CSharpEditorResources.resx">
<body>
<trans-unit id="Add_Missing_Usings_on_Paste">
<source>Add Missing Usings on Paste</source>
<target state="new">Add Missing Usings on Paste</target>
<note>"usings" is a language specific term and should not be localized</note>
</trans-unit>
<trans-unit id="Adding_missing_usings">
<source>Adding missing usings...</source>
<target state="new">Adding missing usings...</target>
<note>Shown in a thread await dialog. "usings" is a language specific term and should not be localized</note>
</trans-unit>
<trans-unit id="Chosen_version_0">
<source>Chosen version: '{0}'</source>
<target state="translated">Wybrana wersja: „{0}”</target>
Expand Down
10 changes: 10 additions & 0 deletions src/EditorFeatures/CSharp/xlf/CSharpEditorResources.pt-BR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="pt-BR" original="../CSharpEditorResources.resx">
<body>
<trans-unit id="Add_Missing_Usings_on_Paste">
<source>Add Missing Usings on Paste</source>
<target state="new">Add Missing Usings on Paste</target>
<note>"usings" is a language specific term and should not be localized</note>
</trans-unit>
<trans-unit id="Adding_missing_usings">
<source>Adding missing usings...</source>
<target state="new">Adding missing usings...</target>
<note>Shown in a thread await dialog. "usings" is a language specific term and should not be localized</note>
</trans-unit>
<trans-unit id="Chosen_version_0">
<source>Chosen version: '{0}'</source>
<target state="translated">Versão escolhida: '{0}'</target>
Expand Down
10 changes: 10 additions & 0 deletions src/EditorFeatures/CSharp/xlf/CSharpEditorResources.ru.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="ru" original="../CSharpEditorResources.resx">
<body>
<trans-unit id="Add_Missing_Usings_on_Paste">
<source>Add Missing Usings on Paste</source>
<target state="new">Add Missing Usings on Paste</target>
<note>"usings" is a language specific term and should not be localized</note>
</trans-unit>
<trans-unit id="Adding_missing_usings">
<source>Adding missing usings...</source>
<target state="new">Adding missing usings...</target>
<note>Shown in a thread await dialog. "usings" is a language specific term and should not be localized</note>
</trans-unit>
<trans-unit id="Chosen_version_0">
<source>Chosen version: '{0}'</source>
<target state="translated">Выбранная версия: "{0}"</target>
Expand Down
10 changes: 10 additions & 0 deletions src/EditorFeatures/CSharp/xlf/CSharpEditorResources.tr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="tr" original="../CSharpEditorResources.resx">
<body>
<trans-unit id="Add_Missing_Usings_on_Paste">
<source>Add Missing Usings on Paste</source>
<target state="new">Add Missing Usings on Paste</target>
<note>"usings" is a language specific term and should not be localized</note>
</trans-unit>
<trans-unit id="Adding_missing_usings">
<source>Adding missing usings...</source>
<target state="new">Adding missing usings...</target>
<note>Shown in a thread await dialog. "usings" is a language specific term and should not be localized</note>
</trans-unit>
<trans-unit id="Chosen_version_0">
<source>Chosen version: '{0}'</source>
<target state="translated">Seçilen sürüm: '{0}'</target>
Expand Down
10 changes: 10 additions & 0 deletions src/EditorFeatures/CSharp/xlf/CSharpEditorResources.zh-Hans.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="zh-HANS" original="../CSharpEditorResources.resx">
<body>
<trans-unit id="Add_Missing_Usings_on_Paste">
<source>Add Missing Usings on Paste</source>
<target state="new">Add Missing Usings on Paste</target>
<note>"usings" is a language specific term and should not be localized</note>
</trans-unit>
<trans-unit id="Adding_missing_usings">
<source>Adding missing usings...</source>
<target state="new">Adding missing usings...</target>
<note>Shown in a thread await dialog. "usings" is a language specific term and should not be localized</note>
</trans-unit>
<trans-unit id="Chosen_version_0">
<source>Chosen version: '{0}'</source>
<target state="translated">所选版本: "{0}"</target>
Expand Down
10 changes: 10 additions & 0 deletions src/EditorFeatures/CSharp/xlf/CSharpEditorResources.zh-Hant.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="zh-HANT" original="../CSharpEditorResources.resx">
<body>
<trans-unit id="Add_Missing_Usings_on_Paste">
<source>Add Missing Usings on Paste</source>
<target state="new">Add Missing Usings on Paste</target>
<note>"usings" is a language specific term and should not be localized</note>
</trans-unit>
<trans-unit id="Adding_missing_usings">
<source>Adding missing usings...</source>
<target state="new">Adding missing usings...</target>
<note>Shown in a thread await dialog. "usings" is a language specific term and should not be localized</note>
</trans-unit>
<trans-unit id="Chosen_version_0">
<source>Chosen version: '{0}'</source>
<target state="translated">選擇的版本: '{0}'</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.ComponentModel.Composition;
using Microsoft.CodeAnalysis.Editor.Host;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.VisualStudio.Text;
Expand Down Expand Up @@ -56,9 +57,7 @@ public InlineHintsTaggerProvider(

public ITagger<T>? CreateTagger<T>(ITextView textView, ITextBuffer buffer) where T : ITag
{
// Determining of the textView's buffer does not match the buffer in order to skip showing the hints for
// the interactive window
if (buffer != textView.TextBuffer)
if (textView.IsNotSurfaceBufferOfTextView(buffer))
{
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ internal static class PredefinedCommandHandlerNames
/// </summary>
public const string PasteTrackingPaste = "Paste Tracking Paste Command Handler";

/// <summary>
/// Command handler name for Paste in Add Imports.
/// </summary>
public const string AddImportsPaste = "Add Imports Paste Command Handler";

/// <summary>
/// Command handler name for Edit and Continue file save handler.
/// </summary>
Expand Down
Loading