Skip to content

Commit 20def1e

Browse files
authored
Minor updates to getting started docs
1 parent fb893a1 commit 20def1e

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

docs/extensibility/visualstudio.extensibility/get-started/create-your-first-extension.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ The command has a configuration property named `CommandConfiguration`, which def
6363
// Use this object initializer to set optional parameters for the command. The required parameter,
6464
// displayName, is set above. DisplayName is localized and references an entry in .vsextension\string-resources.json.
6565
Icon = new(ImageMoniker.KnownValues.Extension, IconSettings.IconAndText),
66-
Placements = new[] { CommandPlacement.KnownPlacements.ExtensionsMenu },
66+
Placements = new[] { CommandPlacement.KnownPlacements.ExtensionsMenu() },
6767
};
6868
```
6969

docs/extensibility/visualstudio.extensibility/get-started/tutorial-create-simple-extension.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ The project template or the sample you created in the [Create your first extensi
3333
```csharp
3434
public override CommandConfiguration CommandConfiguration => new("%InsertGuidCommand.DisplayName%")
3535
{
36-
Placements = new[] { CommandPlacement.KnownPlacements.ExtensionsMenu },
36+
Placements = new[] { CommandPlacement.KnownPlacements.ExtensionsMenu() },
3737
};
3838
```
3939

@@ -54,7 +54,7 @@ The argument to the `CommandConfiguration` constructor is the command's display
5454
```csharp
5555
public override CommandConfiguration CommandConfiguration => new("%InsertGuidCommand.DisplayName%")
5656
{
57-
Placements = new[] { CommandPlacement.KnownPlacements.ExtensionsMenu },
57+
Placements = new[] { CommandPlacement.KnownPlacements.ExtensionsMenu() },
5858
Icon = new(ImageMoniker.KnownValues.OfficeWebExtension, IconSettings.IconAndText),
5959
};
6060
```
@@ -66,7 +66,7 @@ You can specify a known built-in icon, in this case `OfficeWebExtension`, or upl
6666
```csharp
6767
public override CommandConfiguration CommandConfiguration => new("%InsertGuidCommand.DisplayName%")
6868
{
69-
Placements = new[] { CommandPlacement.KnownPlacements.ExtensionsMenu },
69+
Placements = new[] { CommandPlacement.KnownPlacements.ExtensionsMenu() },
7070
Icon = new(ImageMoniker.KnownValues.OfficeWebExtension, IconSettings.IconAndText),
7171
VisibleWhen = ActivationConstraint.ClientContext(ClientContextKey.Shell.ActiveEditorContentType, ".+"),
7272
};
@@ -93,11 +93,10 @@ public override async Task ExecuteCommandAsync(IClientContext context, Cancellat
9393
return;
9494
}
9595

96-
var document = await textView.GetTextDocumentAsync(cancellationToken);
9796
await this.Extensibility.Editor().EditAsync(
9897
batch =>
9998
{
100-
document.AsEditable(batch).Replace(textView.Selection.Extent, newGuidString);
99+
textView.Document.AsEditable(batch).Replace(textView.Selection.Extent, newGuidString);
101100
},
102101
cancellationToken);
103102
}
@@ -107,8 +106,6 @@ The first line validates the arguments, then we create a new `Guid` to use later
107106

108107
Then, we create an `ITextViewSnapshot` (the `textView` object here) by calling the asynchronous method `GetActiveTextViewAsync`. A cancellation token is passed in to preserve the ability to cancel the asynchronous request, but this isn't demonstrated in this sample. If we don't get a text view successfully, we'll write to the log and terminate without doing anything else.
109108

110-
Next, we request the document, an instance of `ITextDocumentSnapshot` (here `document`).
111-
112109
Now we're ready to call the asynchronous method that submits an edit request to Visual Studio's editor. The method we want is `EditAsync`. That's a member of the `EditorExtensibility` class, which allows interaction with the running Visual Studio Editor in the IDE. The `Command` type, which your own `InsertGuidCommand` class inherits from, has a member `Extensibility` that provides access to the `EditorExtensibility` object, so we can get to the `EditorExtensibility` class with a call to `this.Extensibility.Editor()`.
113110

114111
The `EditAsync` method takes an `Action<IEditBatch>` as a parameter. This is called `editorSource`,
@@ -119,7 +116,7 @@ The call to `EditAsync` uses a lambda expression. To break this down a little, y
119116
await this.Extensibility.Editor().EditAsync(
120117
batch =>
121118
{
122-
var editor = document.AsEditable(batch);
119+
var editor = textView.Document.AsEditable(batch);
123120
// specify the desired changes here:
124121
editor.Replace(textView.Selection.Extent, newGuidString);
125122
},

0 commit comments

Comments
 (0)