on master help sign in
Fix panic when using set-language on a scratch (#1996)

Skip launching a language server if a document doesn't have a valid URL.

commita0c6c45c1b5dc36f3c5151363d3f360bea388a99 authorRoland Kovacs <zen3ger@tutanota.com> dateWed 13 Apr 2022, 03:02 (5 years ago) parent3deb1c9
1 file changed+4−1
helix-view/src/editor.rs+4−1
helix-view/src/editor.rs+4−1
@@ -453,6 +453,9 @@ impl Editor {
453453
454454 /// Launch a language server for a given document
455455 fn launch_language_server(ls: &mut helix_lsp::Registry, doc: &mut Document) -> Option<()> {
456+ // if doc doesn't have a URL it's a scratch buffer, ignore it
457+ let doc_url = doc.url()?;
458+
456459 // try to find a language server based on the language name
457460 let language_server = doc.language.as_ref().and_then(|language| {
458461 ls.get(language)
@@ -476,7 +479,7 @@ impl Editor {
476479
477480 // TODO: this now races with on_init code if the init happens too quickly
478481 tokio::spawn(language_server.text_document_did_open(
479− doc.url().unwrap(),
482+ doc_url,
480483 doc.version(),
481484 doc.text(),
482485 language_id,