on master help sign in
add option to enable/disable lsp snippets
commit9fe3adcff9866ef18953a067fbc0b84e7eb968b5 authorPascal Kuthe <pascal.kuthe@semimod.de> dateFri 31 Mar 2023, 04:26 (4 years ago) parenta48d1a4
5 files changed+35−12
book/src/configuration.md+1 helix-lsp/src/client.rs+2−2 helix-lsp/src/lib.rs+20−5 helix-term/src/commands/typed.rs+6−3 helix-view/src/editor.rs+6−2
book/src/configuration.md+1
@@ -127,6 +127,7 @@ The following statusline elements can be configured:
127127| `auto-signature-help` | Enable automatic popup of signature help (parameter hints) | `true` |
128128| `display-inlay-hints` | Display inlay hints[^2] | `false` |
129129| `display-signature-help-docs` | Display docs under signature help popup | `true` |
130+| `snippets` | Enables snippet completions. Requires a server restart (`:lsp-restart`) to take effect after `:config-reload`/`:set`. | `true` |
130131
131132[^1]: By default, a progress spinner is shown in the statusline beside the file path.
132133[^2]: You may also have to activate them in the LSP config for them to appear, not just in Helix.
helix-lsp/src/client.rs+2−2
@@ -411,7 +411,7 @@ impl Client {
411411 // General messages
412412 // -------------------------------------------------------------------------------------------
413413
414− pub(crate) async fn initialize(&self) -> Result<lsp::InitializeResult> {
414+ pub(crate) async fn initialize(&self, enable_snippets: bool) -> Result<lsp::InitializeResult> {
415415 if let Some(config) = &self.config {
416416 log::info!("Using custom LSP config: {}", config);
417417 }
@@ -459,7 +459,7 @@ impl Client {
459459 text_document: Some(lsp::TextDocumentClientCapabilities {
460460 completion: Some(lsp::CompletionClientCapabilities {
461461 completion_item: Some(lsp::CompletionItemCapability {
462− snippet_support: Some(true),
462+ snippet_support: Some(enable_snippets),
463463 resolve_support: Some(lsp::CompletionItemCapabilityResolveSupport {
464464 properties: vec![
465465 String::from("documentation"),
helix-lsp/src/lib.rs+20−5
@@ -647,6 +647,7 @@ impl Registry {
647647 language_config: &LanguageConfiguration,
648648 doc_path: Option<&std::path::PathBuf>,
649649 root_dirs: &[PathBuf],
650+ enable_snippets: bool,
650651 ) -> Result<Option<Arc<Client>>> {
651652 let config = match &language_config.language_server {
652653 Some(config) => config,
@@ -661,8 +662,14 @@ impl Registry {
661662 // initialize a new client
662663 let id = self.counter.fetch_add(1, Ordering::Relaxed);
663664
664− let NewClientResult(client, incoming) =
665− start_client(id, language_config, config, doc_path, root_dirs)?;
665+ let NewClientResult(client, incoming) = start_client(
666+ id,
667+ language_config,
668+ config,
669+ doc_path,
670+ root_dirs,
671+ enable_snippets,
672+ )?;
666673 self.incoming.push(UnboundedReceiverStream::new(incoming));
667674
668675 let old_clients = entry.insert(vec![(id, client.clone())]);
@@ -695,6 +702,7 @@ impl Registry {
695702 language_config: &LanguageConfiguration,
696703 doc_path: Option<&std::path::PathBuf>,
697704 root_dirs: &[PathBuf],
705+ enable_snippets: bool,
698706 ) -> Result<Option<Arc<Client>>> {
699707 let config = match &language_config.language_server {
700708 Some(config) => config,
@@ -711,8 +719,14 @@ impl Registry {
711719 // initialize a new client
712720 let id = self.counter.fetch_add(1, Ordering::Relaxed);
713721
714− let NewClientResult(client, incoming) =
715− start_client(id, language_config, config, doc_path, root_dirs)?;
722+ let NewClientResult(client, incoming) = start_client(
723+ id,
724+ language_config,
725+ config,
726+ doc_path,
727+ root_dirs,
728+ enable_snippets,
729+ )?;
716730 clients.push((id, client.clone()));
717731 self.incoming.push(UnboundedReceiverStream::new(incoming));
718732 Ok(Some(client))
@@ -811,6 +825,7 @@ fn start_client(
811825 ls_config: &LanguageServerConfiguration,
812826 doc_path: Option<&std::path::PathBuf>,
813827 root_dirs: &[PathBuf],
828+ enable_snippets: bool,
814829) -> Result<NewClientResult> {
815830 let (client, incoming, initialize_notify) = Client::start(
816831 &ls_config.command,
@@ -834,7 +849,7 @@ fn start_client(
834849 .capabilities
835850 .get_or_try_init(|| {
836851 _client
837− .initialize()
852+ .initialize(enable_snippets)
838853 .map_ok(|response| response.capabilities)
839854 })
840855 .await;
helix-term/src/commands/typed.rs+6−3
@@ -1378,9 +1378,12 @@ fn lsp_restart(
13781378 .context("LSP not defined for the current document")?;
13791379
13801380 let scope = config.scope.clone();
1381− cx.editor
1382− .language_servers
1383− .restart(config, doc.path(), &editor_config.workspace_lsp_roots)?;
1381+ cx.editor.language_servers.restart(
1382+ config,
1383+ doc.path(),
1384+ &editor_config.workspace_lsp_roots,
1385+ editor_config.lsp.snippets,
1386+ )?;
13841387
13851388 // This collect is needed because refresh_language_server would need to re-borrow editor.
13861389 let document_ids_to_refresh: Vec<DocumentId> = cx
helix-view/src/editor.rs+6−2
@@ -352,6 +352,8 @@ pub struct LspConfig {
352352 pub display_signature_help_docs: bool,
353353 /// Display inlay hints
354354 pub display_inlay_hints: bool,
355+ /// Whether to enable snippet support
356+ pub snippets: bool,
355357}
356358
357359impl Default for LspConfig {
@@ -362,6 +364,7 @@ impl Default for LspConfig {
362364 auto_signature_help: true,
363365 display_signature_help_docs: true,
364366 display_inlay_hints: false,
367+ snippets: true,
365368 }
366369 }
367370}
@@ -1092,12 +1095,13 @@ impl Editor {
10921095 // if doc doesn't have a URL it's a scratch buffer, ignore it
10931096 let doc = self.document(doc_id)?;
10941097 let (lang, path) = (doc.language.clone(), doc.path().cloned());
1095− let root_dirs = &doc.config.load().workspace_lsp_roots;
1098+ let config = doc.config.load();
1099+ let root_dirs = &config.workspace_lsp_roots;
10961100
10971101 // try to find a language server based on the language name
10981102 let language_server = lang.as_ref().and_then(|language| {
10991103 self.language_servers
1100− .get(language, path.as_ref(), root_dirs)
1104+ .get(language, path.as_ref(), root_dirs, config.lsp.snippets)
11011105 .map_err(|e| {
11021106 log::error!(
11031107 "Failed to initialize the LSP for `{}` {{ {} }}",