Smit Barmase
c5991e74bb
project: Handle textDocument/didSave and textDocument/didChange (un)registration and usage correctly (#36441)
Follow-up of https://github.com/zed-industries/zed/pull/35306
This PR contains two changes:
Both changes are inspired from:
https://github.com/microsoft/vscode-languageserver-node/blob/d90a87f9557a0df9142cfb33e251cfa6fe27d970/client/src/common/textSynchronization.ts
1. Handling `textDocument/didSave` and `textDocument/didChange`
registration and unregistration correctly:
```rs
#[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)]
#[serde(untagged)]
pub enum TextDocumentSyncCapability {
Kind(TextDocumentSyncKind),
Options(TextDocumentSyncOptions),
}
```
- `textDocument/didSave` dynamic registration contains "includeText"
- `textDocument/didChange` dynamic registration contains "syncKind"
While storing this to Language Server, we use
`TextDocumentSyncCapability::Options` instead of
`TextDocumentSyncCapability::Kind` since it also include
[change](https://github.com/gluon-lang/lsp-types/blob/be7336e92a6ad23f214df19bcdceab17f39531a9/src/lib.rs#L1714-L1717)
field as `TextDocumentSyncCapability::Kind` as well as
[save](https://github.com/gluon-lang/lsp-types/blob/be7336e92a6ad23f214df19bcdceab17f39531a9/src/lib.rs#L1727-L1729)
field as `TextDocumentSyncSaveOptions`. This way while registering or
unregistering both of them, we don't accidentaly mess with other data.
So, if at intialization we end up getting
`TextDocumentSyncCapability::Kind` and we receive any above kind of
dynamic registration, we change `TextDocumentSyncCapability::Kind` to
`TextDocumentSyncCapability::Options` so we can store more data anyway.
2. Modify `include_text` method to only depend on
`TextDocumentSyncSaveOptions`, instead of depending on
`TextDocumentSyncKind`. Idea behind this is,
`TextDocumentSyncSaveOptions` should be responsible for
"textDocument/didSave" notification, and `TextDocumentSyncKind` should
be responsible for "textDocument/didChange", which it already is:
https://github.com/zed-industries/zed/blob/4b79eade1da2f5f7dfa18208cf882c8e6ca8a97f/crates/project/src/lsp_store.rs#L7324-L7331
Release Notes:
- N/A
2025-08-19 02:27:40 +05:30
..
2025-08-18 20:40:59 +00:00
2025-08-11 17:24:48 +00:00
2025-08-12 17:04:30 -07:00
2025-08-18 04:07:32 +00:00
2025-08-18 10:22:00 +00:00
2025-08-18 20:40:59 +00:00
2025-08-15 21:03:50 +00:00
2025-08-18 20:40:59 +00:00
2025-08-18 20:40:59 +00:00
2025-08-05 18:16:47 +00:00
2025-07-11 23:20:35 +00:00
2025-08-13 13:25:52 -06:00
2025-08-13 20:11:32 +00:00
2025-07-10 19:25:10 +00:00
2025-08-16 19:00:31 +00:00
2025-08-10 21:57:55 +00:00
2025-08-13 01:48:28 +00:00
2025-08-15 10:10:52 +00:00
2025-08-12 17:04:30 -07:00
2025-08-13 15:01:00 -07:00
2025-07-03 14:22:28 +00:00
2025-07-22 11:55:24 -04:00
2025-08-05 18:16:47 +00:00
2025-05-30 08:32:54 -07:00
2025-07-22 18:20:48 +02:00
2025-08-14 17:02:51 +02:00
2025-08-05 00:37:22 +00:00
2025-08-12 22:37:11 +00:00
2025-08-18 19:57:28 +00:00
2025-08-07 01:28:41 +00:00
2025-08-07 01:28:41 +00:00
2025-08-11 15:34:34 +02:00
2025-08-16 14:11:36 +00:00
2025-08-15 20:27:44 +00:00
2025-08-06 15:28:18 -04:00
2025-08-05 23:11:43 +00:00
2025-08-04 13:49:41 +00:00
2025-08-14 23:28:15 +05:30
2025-08-16 06:33:32 +00:00
2025-08-06 18:10:17 -04:00
2025-08-18 14:48:38 +00:00
2025-06-15 19:51:04 +00:00
2025-07-06 14:52:16 +02:00
2025-07-12 15:56:05 +00:00
2025-08-15 20:27:44 +00:00
2025-06-25 09:42:30 +02:00
2025-08-15 18:34:22 +00:00
2025-08-10 18:01:54 +00:00
2025-08-07 18:27:29 +03:00
2025-08-15 20:27:44 +00:00
2025-08-18 12:35:54 +00:00
2025-08-08 23:26:38 +00:00
2025-07-10 21:08:43 +02:00
2025-08-16 19:00:31 +00:00
2025-07-01 20:02:12 +00:00
2025-08-16 19:00:31 +00:00
2025-08-18 11:43:52 +02:00
2025-08-18 19:48:02 +00:00
2025-08-07 22:14:25 +00:00
2025-07-02 21:14:33 -04:00
2025-08-08 18:32:13 -03:00
2025-08-13 11:59:59 -04:00
2025-08-13 15:46:28 +00:00
2025-08-06 10:53:20 +02:00
2025-08-13 15:46:28 +00:00
2025-08-08 01:39:32 +00:00
2025-08-18 19:48:02 +00:00
2025-08-16 09:19:38 +03:00
2025-06-17 20:26:27 +00:00
2025-08-18 20:40:59 +00:00
2025-08-12 05:08:58 +00:00
2025-07-11 21:01:09 -04:00
2025-08-11 07:20:03 +00:00
2025-08-17 13:25:05 -03:00
2025-06-03 13:18:29 +02:00
2025-07-17 09:22:04 +00:00
2025-07-02 21:14:33 -04:00
2025-05-17 16:42:45 +00:00
2025-06-18 16:01:28 +05:30
2025-07-02 21:14:33 -04:00
2025-08-18 18:58:12 +03:00
2025-08-18 11:43:52 +02:00
2025-08-18 20:40:59 +00:00
2025-08-18 20:40:59 +00:00
2025-08-08 05:04:30 +00:00
2025-08-15 20:27:44 +00:00
2025-08-18 11:48:21 +00:00
2025-05-20 23:06:07 +00:00
2025-08-15 10:10:52 +00:00
2025-07-25 09:36:43 -04:00
2025-08-14 08:16:25 +00:00
2025-08-13 13:25:52 -06:00
2025-08-06 00:02:26 +00:00
2025-05-20 23:06:07 +00:00
2025-07-02 21:14:33 -04:00
2025-08-04 16:22:18 +00:00
2025-08-09 15:25:47 -04:00
2025-08-05 00:37:22 +00:00
2025-07-17 14:25:55 +00:00
2025-07-08 14:34:57 +00:00
2025-08-14 23:28:15 +05:30
2025-08-08 15:34:36 -03:00
2025-08-06 10:44:15 -04:00
2025-08-18 20:40:59 +00:00
2025-08-18 08:54:31 +00:00
2025-07-16 11:44:08 -04:00
2025-06-27 14:31:31 -06:00
2025-08-15 20:27:44 +00:00
2025-07-08 11:23:36 -03:00
2025-07-29 15:31:54 +00:00
2025-08-06 00:02:26 +00:00
2025-07-24 15:24:53 +00:00
2025-08-19 02:27:40 +05:30
2025-08-17 17:27:42 +00:00
2025-06-27 14:31:31 -06:00
2025-08-13 20:11:32 +00:00
2025-08-16 06:33:32 +00:00
2025-08-17 17:03:58 +00:00
2025-05-26 17:43:57 +00:00
2025-05-23 14:53:53 +00:00
2025-08-16 06:33:32 +00:00
2025-08-18 11:43:52 +02:00
2025-08-15 20:27:44 +00:00
2025-08-04 18:19:42 -07:00
2025-08-07 13:24:29 +00:00
2025-08-07 23:07:33 +00:00
2025-08-04 16:22:18 +00:00
2025-08-15 22:21:21 +02:00
2025-08-06 00:02:26 +00:00
2025-05-20 23:06:07 +00:00
2025-08-18 11:01:32 +00:00
2025-07-31 17:31:12 +00:00
2025-08-18 11:01:32 +00:00
2025-05-20 23:06:07 +00:00
2025-07-04 00:57:43 +00:00
2025-08-08 15:34:36 -03:00
2025-05-20 23:06:07 +00:00
2025-05-16 17:35:44 +02:00
2025-08-15 20:27:44 +00:00
2025-08-05 00:37:22 +00:00
2025-08-07 18:27:29 +03:00
2025-06-17 14:39:45 +00:00
2025-07-02 21:14:33 -04:00
2025-07-02 21:14:33 -04:00
2025-07-08 14:57:37 +00:00
2025-08-04 11:58:31 -03:00
2025-08-15 15:37:52 -04:00
2025-08-13 17:45:50 -04:00
2025-08-15 20:27:44 +00:00
2025-08-14 13:04:07 -04:00
2025-08-16 14:35:06 +00:00
2025-07-18 16:55:03 +00:00
2025-08-08 15:34:36 -03:00
2025-08-18 16:27:26 +00:00
2025-08-12 13:36:28 +00:00
2025-08-18 11:01:32 +00:00
2025-08-07 11:50:11 -03:00
2025-05-23 19:31:25 +00:00
2025-07-30 23:03:53 +05:30
2025-08-13 18:07:49 -04:00
2025-06-13 06:32:29 +00:00
2025-08-15 13:54:24 +03:00
2025-08-18 09:57:53 -06:00
2025-06-18 21:26:12 +00:00
2025-06-09 13:11:57 +02:00
2025-07-30 00:09:14 +00:00
2025-07-30 00:09:14 +00:00
2025-08-18 19:48:02 +00:00
2025-08-05 00:37:22 +00:00
2025-08-15 13:54:24 +03:00
2025-08-18 19:48:02 +00:00
2025-08-14 13:39:33 +00:00
2025-08-12 06:47:54 +00:00
2025-08-08 23:26:38 +00:00
2025-07-29 23:01:03 +00:00