lsp: Add support for linked editing range edits (HTML tag autorenaming) (#12769)

This PR adds support for [linked editing of
ranges](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_linkedEditingRange),
which in short means that editing one part of a file can now change
related parts in that same file. Think of automatically renaming
HTML/TSX closing tags when the opening one is changed.
TODO:
- [x] proto changes
- [x] Allow disabling linked editing ranges on a per language basis.

Fixes #4535 

Release Notes:
- Added support for linked editing ranges LSP request. Editing opening
tags in HTML/TSX files (with vtsls) performs the same edit on the
closing tag as well (and vice versa). It can be turned off on a language-by-language basis with the following setting:
```
  "languages": {
    "HTML": {
      "linked_edits": true
    },
  }
```

---------

Co-authored-by: Bennet <bennet@zed.dev>
This commit is contained in:
Piotr Osiewicz 2024-06-11 15:52:38 +02:00 committed by GitHub
parent 98659eabf1
commit b6ea393d14
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 574 additions and 8 deletions

View file

@ -116,6 +116,8 @@ pub struct LanguageSettings {
pub always_treat_brackets_as_autoclosed: bool,
/// Which code actions to run on save
pub code_actions_on_format: HashMap<String, bool>,
/// Whether to perform linked edits
pub linked_edits: bool,
}
impl LanguageSettings {
@ -326,6 +328,11 @@ pub struct LanguageSettingsContent {
///
/// Default: {} (or {"source.organizeImports": true} for Go).
pub code_actions_on_format: Option<HashMap<String, bool>>,
/// Whether to perform linked edits of associated ranges, if the language server supports it.
/// For example, when editing opening <html> tag, the contents of the closing </html> tag will be edited as well.
///
/// Default: true
pub linked_edits: Option<bool>,
}
/// The contents of the inline completion settings.
@ -785,6 +792,7 @@ fn merge_settings(settings: &mut LanguageSettings, src: &LanguageSettingsContent
&mut settings.code_actions_on_format,
src.code_actions_on_format.clone(),
);
merge(&mut settings.linked_edits, src.linked_edits);
merge(
&mut settings.preferred_line_length,