Skip to content

Commit ba0defa

Browse files
committed
Add support for TextDocumentContentResult (#388)
1 parent e0edf52 commit ba0defa

File tree

4 files changed

+76
-40
lines changed

4 files changed

+76
-40
lines changed

generator/lsp.json

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,8 +1068,8 @@
10681068
"method": "workspace/textDocumentContent",
10691069
"typeName": "TextDocumentContentRequest",
10701070
"result": {
1071-
"kind": "base",
1072-
"name": "string"
1071+
"kind": "reference",
1072+
"name": "TextDocumentContentResult"
10731073
},
10741074
"messageDirection": "clientToServer",
10751075
"params": {
@@ -4420,6 +4420,22 @@
44204420
"since": "3.18.0",
44214421
"proposed": true
44224422
},
4423+
{
4424+
"name": "TextDocumentContentResult",
4425+
"properties": [
4426+
{
4427+
"name": "text",
4428+
"type": {
4429+
"kind": "base",
4430+
"name": "string"
4431+
},
4432+
"documentation": "The text content of the text document. Please note, that the content of\nany subsequent open notifications for the text document might differ\nfrom the returned content due to whitespace and line ending\nnormalizations done on the client"
4433+
}
4434+
],
4435+
"documentation": "Result of the `workspace/textDocumentContent` request.\n\n@since 3.18.0\n@proposed",
4436+
"since": "3.18.0",
4437+
"proposed": true
4438+
},
44234439
{
44244440
"name": "TextDocumentContentRegistrationOptions",
44254441
"properties": [],
@@ -6876,15 +6892,15 @@
68766892
"kind": "base",
68776893
"name": "uinteger"
68786894
},
6879-
"documentation": "Line position in a document (zero-based).\n\nIf a line number is greater than the number of lines in a document, it defaults back to the number of lines in the document.\nIf a line number is negative, it defaults to 0."
6895+
"documentation": "Line position in a document (zero-based)."
68806896
},
68816897
{
68826898
"name": "character",
68836899
"type": {
68846900
"kind": "base",
68856901
"name": "uinteger"
68866902
},
6887-
"documentation": "Character offset on a line in a document (zero-based).\n\nThe meaning of this offset is determined by the negotiated\n`PositionEncodingKind`.\n\nIf the character value is greater than the line length it defaults back to the\nline length."
6903+
"documentation": "Character offset on a line in a document (zero-based).\n\nThe meaning of this offset is determined by the negotiated\n`PositionEncodingKind`."
68886904
}
68896905
],
68906906
"documentation": "Position in a text document expressed as zero-based line and character\noffset. Prior to 3.17 the offsets were always based on a UTF-16 string\nrepresentation. So a string of the form `a𐐀b` the character offset of the\ncharacter `a` is 0, the character offset of `𐐀` is 1 and the character\noffset of b is 3 since `𐐀` is represented using two code units in UTF-16.\nSince 3.17 clients and servers can agree on a different string encoding\nrepresentation (e.g. UTF-8). The client announces it's supported encoding\nvia the client capability [`general.positionEncodings`](https://microsoft.github.io/language-server-protocol/specifications/specification-current/#clientCapabilities).\nThe value is an array of position encodings the client supports, with\ndecreasing preference (e.g. the encoding at index `0` is the most preferred\none). To stay backwards compatible the only mandatory encoding is UTF-16\nrepresented via the string `utf-16`. The server can pick one of the\nencodings offered by the client and signals that encoding back to the\nclient via the initialize result's property\n[`capabilities.positionEncoding`](https://microsoft.github.io/language-server-protocol/specifications/specification-current/#serverCapabilities). If the string value\n`utf-16` is missing from the client's capability `general.positionEncodings`\nservers can safely assume that the client supports UTF-16. If the server\nomits the position encoding in its initialize result the encoding defaults\nto the string value `utf-16`. Implementation considerations: since the\nconversion from one encoding into another requires the content of the\nfile / line the conversion is best done where the file is read which is\nusually on the server side.\n\nPositions are line end character agnostic. So you can not specify a position\nthat denotes `\\r|\\n` or `\\n|` where `|` represents the character offset.\n\n@since 3.17.0 - support for negotiated position encoding.",
@@ -7970,12 +7986,15 @@
79707986
"name": "TextDocumentContentOptions",
79717987
"properties": [
79727988
{
7973-
"name": "scheme",
7989+
"name": "schemes",
79747990
"type": {
7975-
"kind": "base",
7976-
"name": "string"
7991+
"kind": "array",
7992+
"element": {
7993+
"kind": "base",
7994+
"name": "string"
7995+
}
79777996
},
7978-
"documentation": "The scheme for which the server provides content."
7997+
"documentation": "The schemes for which the server provides content."
79797998
}
79807999
],
79818000
"documentation": "Text document content provider options.\n\n@since 3.18.0\n@proposed",

packages/python/lsprotocol/types.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2826,6 +2826,23 @@ class TextDocumentContentParams:
28262826
"""The uri of the text document."""
28272827

28282828

2829+
@attrs.define
2830+
class TextDocumentContentResult:
2831+
"""Result of the `workspace/textDocumentContent` request.
2832+
2833+
@since 3.18.0
2834+
@proposed"""
2835+
2836+
# Since: 3.18.0
2837+
# Proposed
2838+
2839+
text: str = attrs.field(validator=attrs.validators.instance_of(str))
2840+
"""The text content of the text document. Please note, that the content of
2841+
any subsequent open notifications for the text document might differ
2842+
from the returned content due to whitespace and line ending
2843+
normalizations done on the client"""
2844+
2845+
28292846
@attrs.define
28302847
class TextDocumentContentOptions:
28312848
"""Text document content provider options.
@@ -2836,8 +2853,8 @@ class TextDocumentContentOptions:
28362853
# Since: 3.18.0
28372854
# Proposed
28382855

2839-
scheme: str = attrs.field(validator=attrs.validators.instance_of(str))
2840-
"""The scheme for which the server provides content."""
2856+
schemes: Sequence[str] = attrs.field()
2857+
"""The schemes for which the server provides content."""
28412858

28422859

28432860
@attrs.define
@@ -2850,8 +2867,8 @@ class TextDocumentContentRegistrationOptions:
28502867
# Since: 3.18.0
28512868
# Proposed
28522869

2853-
scheme: str = attrs.field(validator=attrs.validators.instance_of(str))
2854-
"""The scheme for which the server provides content."""
2870+
schemes: Sequence[str] = attrs.field()
2871+
"""The schemes for which the server provides content."""
28552872

28562873
id: Optional[str] = attrs.field(
28572874
validator=attrs.validators.optional(attrs.validators.instance_of(str)),
@@ -5159,19 +5176,13 @@ class Position:
51595176
# Since: 3.17.0 - support for negotiated position encoding.
51605177

51615178
line: int = attrs.field(validator=validators.uinteger_validator)
5162-
"""Line position in a document (zero-based).
5163-
5164-
If a line number is greater than the number of lines in a document, it defaults back to the number of lines in the document.
5165-
If a line number is negative, it defaults to 0."""
5179+
"""Line position in a document (zero-based)."""
51665180

51675181
character: int = attrs.field(validator=validators.uinteger_validator)
51685182
"""Character offset on a line in a document (zero-based).
51695183
51705184
The meaning of this offset is determined by the negotiated
5171-
`PositionEncodingKind`.
5172-
5173-
If the character value is greater than the line length it defaults back to the
5174-
line length."""
5185+
`PositionEncodingKind`."""
51755186

51765187
def __eq__(self, o: object) -> bool:
51775188
if not isinstance(o, Position):
@@ -10442,9 +10453,6 @@ class InlineCompletionResponse:
1044210453
jsonrpc: str = attrs.field(default="2.0")
1044310454

1044410455

10445-
TextDocumentContentResult = str
10446-
10447-
1044810456
@attrs.define
1044910457
class TextDocumentContentRequest:
1045010458
"""The `workspace/textDocumentContent` request is sent from the client to the

packages/rust/lsprotocol/src/lib.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3576,6 +3576,21 @@ pub struct TextDocumentContentParams {
35763576
pub uri: Url,
35773577
}
35783578

3579+
/// Result of the `workspace/textDocumentContent` request.
3580+
///
3581+
/// @since 3.18.0
3582+
/// @proposed
3583+
#[cfg(feature = "proposed")]
3584+
#[derive(Serialize, Deserialize, PartialEq, Debug, Eq, Clone)]
3585+
#[serde(rename_all = "camelCase", deny_unknown_fields)]
3586+
pub struct TextDocumentContentResult {
3587+
/// The text content of the text document. Please note, that the content of
3588+
/// any subsequent open notifications for the text document might differ
3589+
/// from the returned content due to whitespace and line ending
3590+
/// normalizations done on the client
3591+
pub text: String,
3592+
}
3593+
35793594
/// Text document content provider registration options.
35803595
///
35813596
/// @since 3.18.0
@@ -3588,8 +3603,8 @@ pub struct TextDocumentContentRegistrationOptions {
35883603
/// the request again. See also Registration#id.
35893604
pub id: Option<String>,
35903605

3591-
/// The scheme for which the server provides content.
3592-
pub scheme: String,
3606+
/// The schemes for which the server provides content.
3607+
pub schemes: Vec<String>,
35933608
}
35943609

35953610
/// Parameters for the `workspace/textDocumentContent/refresh` request.
@@ -5326,15 +5341,9 @@ pub struct Position {
53265341
///
53275342
/// The meaning of this offset is determined by the negotiated
53285343
/// `PositionEncodingKind`.
5329-
///
5330-
/// If the character value is greater than the line length it defaults back to the
5331-
/// line length.
53325344
pub character: u32,
53335345

53345346
/// Line position in a document (zero-based).
5335-
///
5336-
/// If a line number is greater than the number of lines in a document, it defaults back to the number of lines in the document.
5337-
/// If a line number is negative, it defaults to 0.
53385347
pub line: u32,
53395348
}
53405349

@@ -5990,8 +5999,8 @@ pub struct InlineCompletionOptions {
59905999
#[derive(Serialize, Deserialize, PartialEq, Debug, Eq, Clone)]
59916000
#[serde(rename_all = "camelCase", deny_unknown_fields)]
59926001
pub struct TextDocumentContentOptions {
5993-
/// The scheme for which the server provides content.
5994-
pub scheme: String,
6002+
/// The schemes for which the server provides content.
6003+
pub schemes: Vec<String>,
59956004
}
59966005

59976006
/// General parameters to register for a notification or to register a provider.
@@ -10811,7 +10820,7 @@ pub struct TextDocumentContentResponse {
1081110820
/// The request id.
1081210821
pub id: LSPIdOptional,
1081310822

10814-
pub result: String,
10823+
pub result: TextDocumentContentResult,
1081510824
}
1081610825

1081710826
/// The `workspace/textDocumentContent` request is sent from the server to the client to refresh

requirements.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ exceptiongroup==1.2.2 \
2626
# via
2727
# cattrs
2828
# pytest
29-
importlib-resources==6.4.0 \
30-
--hash=sha256:50d10f043df931902d4194ea07ec57960f66a80449ff867bfe782b4c486ba78c \
31-
--hash=sha256:cdb2b453b8046ca4e3798eb1d84f3cce1446a0e8e7b5ef4efb600f19fc398145
29+
importlib-resources==6.4.4 \
30+
--hash=sha256:20600c8b7361938dc0bb2d5ec0297802e575df486f5a544fa414da65e13721f7 \
31+
--hash=sha256:dda242603d1c9cd836c3368b1174ed74cb4049ecd209e7a1a0104620c18c5c11
3232
# via
3333
# -r ./requirements.in
3434
# jsonschema
@@ -186,7 +186,7 @@ typing-extensions==4.12.2 \
186186
--hash=sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d \
187187
--hash=sha256:1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8
188188
# via cattrs
189-
zipp==3.19.2 \
190-
--hash=sha256:bf1dcf6450f873a13e952a29504887c89e6de7506209e5b1bcc3460135d4de19 \
191-
--hash=sha256:f091755f667055f2d02b32c53771a7a6c8b47e1fdbc4b72a8b9072b3eef8015c
189+
zipp==3.20.0 \
190+
--hash=sha256:0145e43d89664cfe1a2e533adc75adafed82fe2da404b4bbb6b026c0157bdb31 \
191+
--hash=sha256:58da6168be89f0be59beb194da1250516fdaa062ccebd30127ac65d30045e10d
192192
# via importlib-resources

0 commit comments

Comments
 (0)