Skip to content

Commit dd8b887

Browse files
Merge pull request #10795 from MicrosoftDocs/main638847686543320976sync_temp
For protected branch, push strategy should use PR and merge to target branch method to work around git push error
2 parents 558ae8e + 6b984df commit dd8b887

24 files changed

+307
-178
lines changed
Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
title: Editor extensibility concepts
3-
description: An overview of the object model for editor-based extensions
2+
title: Editor Extensibility Concepts
3+
description: An overview of the object model for editor-based extensions.
44
ms.topic: conceptual
55
ms.date: 3/31/2023
66
ms.author: maiak
@@ -12,59 +12,57 @@ ms.subservice: extensibility-integration
1212

1313
# Editor extensibility concepts
1414

15-
This article describes the extensibility object model that represents the Visual Studio editor and the text document that is opened for editing. For an introduction to working with the editor extension functionality, see [Use Visual Studio editor extensibility](editor.md).
15+
This article describes the extensibility object model that represents the Visual Studio editor and the text document that's opened for editing. For an introduction to working with the editor extension functionality, see [Use Visual Studio editor extensibility](editor.md).
1616

17-
The Visual Studio Editor extensibility object model is composed of a few integral parts. This article covers [ITextViewSnapshot](/dotnet/api/microsoft.visualstudio.extensibility.editor.itextviewsnapshot), [ITextDocumentSnapshot](/dotnet/api/microsoft.visualstudio.extensibility.editor.itextdocumentsnapshot), and other abstract representations of the whole document, as well as [TextPosition](/dotnet/api/microsoft.visualstudio.extensibility.editor.textposition) and [TextRange](/dotnet/api/microsoft.visualstudio.extensibility.editor.textrange), which represent locations and spans of text, respectively.
17+
The extensibility object model for the Visual Studio editor consists of a few integral parts. This article covers [ITextViewSnapshot](/dotnet/api/microsoft.visualstudio.extensibility.editor.itextviewsnapshot), [ITextDocumentSnapshot](/dotnet/api/microsoft.visualstudio.extensibility.editor.itextdocumentsnapshot), and other abstract representations of the whole document. The article also introduces [TextPosition](/dotnet/api/microsoft.visualstudio.extensibility.editor.textposition) and [TextRange](/dotnet/api/microsoft.visualstudio.extensibility.editor.textrange), which represent locations and spans of text, respectively.
1818

1919
## ITextViewSnapshot
2020

21-
[ITextViewSnapshot](/dotnet/api/microsoft.visualstudio.extensibility.editor.itextviewsnapshot) contains the URI and version information necessary to acquire an [ITextDocumentSnapshot](/dotnet/api/microsoft.visualstudio.extensibility.editor.itextdocumentsnapshot) as well as some properties of the text view, such as selections.
21+
The [ITextViewSnapshot](/dotnet/api/microsoft.visualstudio.extensibility.editor.itextviewsnapshot) class contains the URI and version information necessary to acquire an [ITextDocumentSnapshot](/dotnet/api/microsoft.visualstudio.extensibility.editor.itextdocumentsnapshot) class and some properties of the text view, such as selections.
2222

23-
- This object is immutable and will never change after it is created.
24-
- You can use `ITextViewSnapshot.GetTextDocumentAsync()` to get the content from the document. Calling this method is expensive and only should be done if you need the document content.
25-
- `ITextViewSnapshot` can't be changed directly. All changes are requested via mutation. See [Make changes in a text document from an extension](./walkthroughs/editing-text.md).
23+
- This object is immutable and never changes after it's created.
24+
- You can use `ITextViewSnapshot.GetTextDocumentAsync()` to get the content from the document. Calling this method is expensive, and you should do it only if you need the document content.
25+
- The `ITextViewSnapshot` class can't be changed directly. All changes are requested via mutation. For more information, see [Make changes in a text document from an extension](./walkthroughs/editing-text.md).
2626

2727
## ITextDocumentSnapshot
2828

29-
[ITextDocumentSnapshot](/dotnet/api/microsoft.visualstudio.extensibility.editor.itextdocumentsnapshot) contains the content of the text document from a point in time or version.
29+
The [ITextDocumentSnapshot](/dotnet/api/microsoft.visualstudio.extensibility.editor.itextdocumentsnapshot) class contains the content of the text document from a point in time or version.
3030

31-
- This object is immutable and will never change after it is created.
32-
- `ITextDocumentSnapshot` can't be changed directly. All changes are requested via mutation. See [Make changes in a text document from an extension](./walkthroughs/editing-text.md).
31+
- This object is immutable and never changes after it's created.
32+
- The `ITextDocumentSnapshot` class can't be changed directly. All changes are requested via mutation. For more information, see [Make changes in a text document from an extension](./walkthroughs/editing-text.md).
3333

3434
If you're familiar with legacy Visual Studio extensions, [ITextDocumentSnapshot](/dotnet/api/microsoft.visualstudio.extensibility.editor.itextdocumentsnapshot) is almost the same as
3535
[ITextSnapshot](/dotnet/api/microsoft.visualstudio.text.itextsnapshot) and supports most of the same methods for accessing the text.
3636

37-
Best Practices:
37+
### Best practices
3838

39-
- You can use Position and Range to represent substrings in the document without expending resources copying or allocating strings. Most APIs operate in terms of these primitives.
40-
- You can use the indexer syntax, `textDocument[0]`, to read character by character in the document without copying it to a string.
41-
- If you must create a string such as for use as a dictionary key, use the overload that takes a `Range`, to avoid creating a large throwaway string from the entire line or document.
42-
- Avoid assuming lines or documents will be short. Many languages minify into huge lines or consume very large files
43-
- - [ITextDocumentSnapshot](/dotnet/api/microsoft.visualstudio.extensibility.editor.itextdocumentsnapshot) references large data structures that may consume memory if an old enough version is stored. Best practice is to periodically update positions and ranges that you're storing long term to the latest document version via their `TranslateTo()` method so the old `ITextDocumentSnapshot` version can be garbage collected.
39+
- Use position and range to represent substrings in the document without expending resources by copying or allocating strings. Most APIs operate in terms of these primitives.
40+
- Use the indexer syntax, `textDocument[0]`, to read character by character in the document without copying it to a string.
41+
- If you must create a string, such as for use as a dictionary key, use the overload that takes a `Range` to avoid creating a large throwaway string from the entire line or document.
42+
- Avoid the assumption that lines or documents are short. Many languages minify into huge lines or consume large files.
43+
- The [ITextDocumentSnapshot](/dotnet/api/microsoft.visualstudio.extensibility.editor.itextdocumentsnapshot) class references large data structures that might consume memory if an old-enough version is stored. The best practice is to periodically update positions and ranges that you're storing long term to the latest document version via their `TranslateTo()` method so that the old `ITextDocumentSnapshot` version can be garbage collected.
4444

4545
## Position
4646

47-
[TextPosition](/dotnet/api/microsoft.visualstudio.extensibility.editor.textposition) represents a position within the text document. As opposed to `int` positions, the `TextPosition` type is aware of the [ITextDocumentSnapshot](/dotnet/api/microsoft.visualstudio.extensibility.editor.itextdocumentsnapshot) it came from and supports `GetChar()` to directly get the character at that point.
47+
The [TextPosition](/dotnet/api/microsoft.visualstudio.extensibility.editor.textposition) class represents a position within the text document. As opposed to `int` positions, the `TextPosition` type is aware of the [ITextDocumentSnapshot](/dotnet/api/microsoft.visualstudio.extensibility.editor.itextdocumentsnapshot) class that it came from and supports `GetChar()` to get the character directly at that point.
4848

4949
If you're familiar with legacy Visual Studio extensions, `TextPosition` is almost the same as [SnapshotPoint](/dotnet/api/microsoft.visualstudio.text.snapshotpoint) and supports most of the same methods.
5050

5151
## Range
5252

53-
[TextRange](/dotnet/api/microsoft.visualstudio.extensibility.editor.textrange) represents a contiguous substring of characters within an [ITextDocumentSnapshot](/dotnet/api/microsoft.visualstudio.extensibility.editor.itextdocumentsnapshot). As opposed to a string created with `string.Substring()` or `ITextDocumentSnapshot.CopyToString()`, creating a `TextRange` doesn't require any allocations or additional memory. You can later call [CopyToString()](/dotnet/api/microsoft.visualstudio.extensibility.editor.textextensions.copytostring) to realize it into a string in a deferred fashion.
53+
The [TextRange](/dotnet/api/microsoft.visualstudio.extensibility.editor.textrange) class represents a contiguous substring of characters within an [ITextDocumentSnapshot](/dotnet/api/microsoft.visualstudio.extensibility.editor.itextdocumentsnapshot) class. As opposed to a string created with `string.Substring()` or `ITextDocumentSnapshot.CopyToString()`, creating a `TextRange` class doesn't require any allocations or extra memory. Later, you can call [CopyToString()](/dotnet/api/microsoft.visualstudio.extensibility.editor.textextensions.copytostring) to realize it into a string in a deferred fashion.
5454

5555
If you're familiar with legacy Visual Studio extensions, `TextRange` is almost the same as
5656
[SnapshotSpan](/dotnet/api/microsoft.visualstudio.text.snapshotSpan) and supports most of the same methods.
5757

5858
## Tracking modes
5959

60-
`TextPosition` and `TextRange` are associated with a specific `ITextDocumentSnapshot`: the state of the document at a specific time. Such positions and ranges can be translated to a different snapshot using the `TranslateTo` methods. Such translation takes in account any text added or removed before, after (or, in the case of ranges, in the middle) the position or range. When any of such edits happen exactly at the position or exactly at the edge of the range, [TextPositionTrackingMode](/dotnet/api/microsoft.visualstudio.extensibility.editor.textpositiontrackingmode) and [TextRangeTrackingMode](/dotnet/api/microsoft.visualstudio.extensibility.editor.textrangetrackingmode) are used to specify how the translation should behave.
60+
The `TextPosition` and `TextRange` classes are associated with a specific `ITextDocumentSnapshot` class, which is the state of the document at a specific time. You can use the `TranslateTo` methods to translate such positions and ranges to a different snapshot. Such translation takes into account any text that was added or removed before, after (or, in the case of ranges, in the middle of) the position or range. When any of these edits happen exactly at the position or exactly at the edge of the range, [TextPositionTrackingMode](/dotnet/api/microsoft.visualstudio.extensibility.editor.textpositiontrackingmode) and [TextRangeTrackingMode](/dotnet/api/microsoft.visualstudio.extensibility.editor.textrangetrackingmode) are used to specify how the translation should behave.
6161

6262
## Tag
6363

64-
[Taggers](./walkthroughs/taggers.md) are used to associate data (a [tag](/dotnet/api/microsoft.visualstudio.extensibility.editor.itag)) with spans of text, such data is consumed by other Visual Studio features (E.g., [CodeLens](./walkthroughs/codelens.md), [classification](./walkthroughs/classification.md), etc.).
64+
[Taggers](./walkthroughs/taggers.md) are used to associate data (a [tag](/dotnet/api/microsoft.visualstudio.extensibility.editor.itag)) with spans of text. Other Visual Studio features (for example, [CodeLens](./walkthroughs/codelens.md) and [classification](./walkthroughs/classification.md)) consume such data.
6565

6666
## Related content
6767

68-
Review sample code for a simple editor-based extension:
69-
70-
- [DocumentSelectorSample](https://github.com/Microsoft/VSExtensibility/tree/main/New_Extensibility_Model/Samples/DocumentSelectorSample/)
68+
- Review sample code for a simple editor-based extension in [DocumentSelectorSample](https://github.com/Microsoft/VSExtensibility/tree/main/New_Extensibility_Model/Samples/DocumentSelectorSample/).
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Editor remote procedure calls (RPC)
2+
title: Editor Remote Procedure Calls (RPC)
33
description: Learn about the RPC protocol for editor-based extensions.
44
ms.date: 3/31/2023
55
ms.topic: conceptual
@@ -12,21 +12,21 @@ ms.subservice: extensibility-integration
1212

1313
# Editor RPC support
1414

15-
Since the new Visual Studio extensibility model is entirely in a separate process, and communication between the extension process and the Visual Studio process occurs through a stream, all APIs have to at some level operate with serializable data types. Typically, extensions can ignore these implementation details. In some scenarios, an extension may need to interface directly with RPC services acquired from `this.Extensibility.ServiceBroker`.
15+
The new Visual Studio extensibility model is entirely in a separate process, and communication between the extension process and the Visual Studio process occurs through a stream. As a result, all APIs have to operate at some level with serializable data types. Typically, extensions can ignore these implementation details. In some scenarios, an extension might need to interface directly with remote procedure call (RPC) services acquired from `this.Extensibility.ServiceBroker`.
1616

1717
## Serializable RPC types
1818

1919
To facilitate interactions with RPC services, the object model exposes [RpcContract](/dotnet/api/microsoft.visualstudio.extensibility.editor.selection.rpccontract) properties on most core types, and the following serializable RPC types:
2020

21-
- `VersionedTextDocumentRange` - 1:1 serializable version of `Span`, which you can access through the `RpcContract` property. This type should be used in most RPC contracts between processes.
22-
- `VersionedTextDocumentPosition` - 1:1 serializable version of `Position`, which you can access through the `RpcContract` property. This type should be used in most RPC contracts between processes.
23-
- `Range` - Serializable version of Span, omitting the Uri and version number.
24-
- `Microsoft.VisualStudio.RpcContracts.Utilities.Position` - Serializable version of `Position`, omitting the Uri and version number.
25-
- `TextView` - 1:1 serialized form of `ITextView`, which you can access through the `RpcContract` property.
26-
- `TextDocument` - 1:1 serialized form of `ITextDocument` through the `RpcContract` property.
21+
- `VersionedTextDocumentRange`: 1:1 serializable version of `Span`, which you can access through the `RpcContract` property. Use this type in most RPC contracts between processes.
22+
- `VersionedTextDocumentPosition`: 1:1 serializable version of `Position`, which you can access through the `RpcContract` property. Use this type in most RPC contracts between processes.
23+
- `Range`: Serializable version of Span, which omits the URI and version number.
24+
- `Microsoft.VisualStudio.RpcContracts.Utilities.Position`: Serializable version of `Position`, which omits the URI and version number.
25+
- `TextView`: 1:1 serialized form of `ITextView`, which you can access through the `RpcContract` property.
26+
- `TextDocument`: 1:1 serialized form of `ITextDocument` through the `RpcContract` property.
2727

28-
As opposed to `VersionedTextDocumentRange` and `VersionedTextDocumentPosition`, `Range` and `Microsoft.VisualStudio.RpcContracts.Utilities.Position` omit the Uri and document version, making for a smaller serializable representation. This type should be used in RPC contracts that contain lots of span/range equivalents that need to reduce their payload size for performance. These RPC contracts need to pass the document Uri and version for the spans or range to be instantiated into `Span` and `Position` objects by the [IEditorHostService](/dotnet/api/microsoft.visualstudio.extensibility.editor.ieditorhostservice). `IEditorHostService` interfaces with extension-local copies of the text buffer, and manages opening and closing of documents described by the RPC types.
28+
As opposed to `VersionedTextDocumentRange` and `VersionedTextDocumentPosition`, `Range` and `Microsoft.VisualStudio.RpcContracts.Utilities.Position` omit the URI and document version, which makes for a smaller serializable representation. Use this type in RPC contracts that contain lots of span or range equivalents that need to reduce their payload size for performance. These RPC contracts need to pass the document URI and version for the spans or range to be instantiated into `Span` and `Position` objects by [IEditorHostService](/dotnet/api/microsoft.visualstudio.extensibility.editor.ieditorhostservice). The `IEditorHostService` interfaces with extension-local copies of the text buffer and manages the opening and closing of documents described by the RPC types.
2929

3030
## Related content
3131

32-
Learn more about Remote UI, the RPC model used in VS.Extensibilty at [Remote UI](../inside-the-sdk/remote-ui.md).
32+
- To learn more about Remote UI, the RPC model used in `VisualStudio.Extensibility`, see [Remote UI](../inside-the-sdk/remote-ui.md).

0 commit comments

Comments
 (0)