Repository: autozimu/LanguageClient-neovim (language: rust)

Issue:
Have `completionPreferTextEdit` toggle the handling of `additional text edit`s.
This is more of a question than a feature request or a bug report. Currently, `additional text edits` from a `completionItem/resolve` call are being processed even though the `LanguageClient_completionPreferTextEdit` option is set to `0`. I think it would make sense for those text edits not to happen if the user has the option set to `0`.
Another alternative would be to add an option specifically for this, but I think it makes sense to handle that under the same flag.

So the question is, should we move [this line](https://github.com/autozimu/LanguageClient-neovim/blob/next/src/language_server_protocol.rs#L3101) inside the `if block` where we check the value of `LanguageClient_completionPreferTextEdit`?

This would be a fairly straight forward change, so if this is something that we want to see I can open a PR for it.


Discussion / hints:
Yes, current behavior is not expected. PR is always welcomed.

BTW, the line link has been outdated due to a recent merge. Actually GitHub support [permalink](https://help.github.com/en/github/managing-your-work-on-github/creating-a-permanent-link-to-a-code-snippet) if you haven't aware of.

Fix patch:
diff --git a/doc/LanguageClient.txt b/doc/LanguageClient.txt
index 5c915162..866b26b1 100644
--- a/doc/LanguageClient.txt
+++ b/doc/LanguageClient.txt
@@ -500,6 +500,14 @@ Example configuration for eclipse.jdt.ls:
      highlight! JavaStaticMemberFunction ctermfg=Green cterm=none guifg=Green gui=none
      highlight! JavaMemberVariable ctermfg=White cterm=italic guifg=White gui=italic
 
+
+2.31 g:LanguageClient_applyCompletionAdditionalTextEdits *g:LanguageClient__applyCompletionAdditionalTextEdits*
+
+Indicates whether completionItem additional text edits should be applied.
+
+Default: 1
+Valid options: 1 | 0
+
 ==============================================================================
 3. Commands                                           *LanguageClientCommands*
 
diff --git a/src/language_server_protocol.rs b/src/language_server_protocol.rs
index dfc06a48..1009aa22 100644
--- a/src/language_server_protocol.rs
+++ b/src/language_server_protocol.rs
@@ -124,6 +124,7 @@ impl LanguageClient {
             echo_project_root,
             semanticHighlightMaps,
             semanticScopeSeparator,
+            applyCompletionAdditionalTextEdits,
         ): (
             Option<u64>,
             String,
@@ -133,6 +134,7 @@ impl LanguageClient {
             u8,
             HashMap<String, HashMap<String, String>>,
             String,
+            u8,
         ) = self.vim()?.eval(
             [
                 "get(g:, 'LanguageClient_diagnosticsSignsMax', v:null)",
@@ -143,6 +145,7 @@ impl LanguageClient {
                 "!!s:GetVar('LanguageClient_echoProjectRoot', 1)",
                 "s:GetVar('LanguageClient_semanticHighlightMaps', {})",
                 "s:GetVar('LanguageClient_semanticScopeSeparator', ':')",
+                "get(g:, 'LanguageClient_applyCompletionAdditionalTextEdits', 1)",
             ]
             .as_ref(),
         )?;
@@ -201,6 +204,7 @@ impl LanguageClient {
         };
 
         let completionPreferTextEdit = completionPreferTextEdit == 1;
+        let applyCompletionAdditionalTextEdits = applyCompletionAdditionalTextEdits == 1;
 
         let is_nvim = is_nvim == 1;
 
@@ -247,6 +251,7 @@ impl LanguageClient {
             state.wait_output_timeout = wait_output_timeout;
             state.hoverPreview = hoverPreview;
             state.completionPreferTextEdit = completionPreferTextEdit;
+            state.applyCompletionAdditionalTextEdits = applyCompletionAdditionalTextEdits;
             state.use_virtual_text = use_virtual_text;
             state.echo_project_root = echo_project_root == 1;
             state.loggingFile = loggingFile;
@@ -3111,9 +3116,12 @@ impl LanguageClient {
                 edits.push(edit);
             };
         }
-        if let Some(aedits) = lspitem.additional_text_edits {
-            edits.extend(aedits);
-        };
+
+        if self.get(|state| state.applyCompletionAdditionalTextEdits)? {
+            if let Some(aedits) = lspitem.additional_text_edits {
+                edits.extend(aedits);
+            };
+        }
 
         if edits.is_empty() {
             return Ok(());
diff --git a/src/types.rs b/src/types.rs
index f5e36d3c..581792fc 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -177,6 +177,7 @@ pub struct State {
     pub wait_output_timeout: Duration,
     pub hoverPreview: HoverPreviewOption,
     pub completionPreferTextEdit: bool,
+    pub applyCompletionAdditionalTextEdits: bool,
     pub use_virtual_text: UseVirtualText,
     pub echo_project_root: bool,
 
@@ -258,6 +259,7 @@ impl State {
             wait_output_timeout: Duration::from_secs(10),
             hoverPreview: HoverPreviewOption::default(),
             completionPreferTextEdit: false,
+            applyCompletionAdditionalTextEdits: true,
             use_virtual_text: UseVirtualText::All,
             echo_project_root: true,
             loggingFile: None,


Test patch: