Skip to content

Commit

Permalink
Switch to a LazyLock for static snippets (#667)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavisVaughan authored Jan 23, 2025
1 parent 281b8ca commit ceaf332
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions crates/ark/src/lsp/completions/sources/composite/snippets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

use std::collections::HashMap;
use std::sync::Once;
use std::sync::LazyLock;

use rust_embed::RustEmbed;
use serde::Deserialize;
Expand Down Expand Up @@ -48,14 +48,9 @@ pub(super) fn completions_from_snippets() -> Vec<CompletionItem> {
}

fn get_completions_from_snippets() -> &'static Vec<CompletionItem> {
static INIT: Once = Once::new();
static mut SNIPPETS: Option<Vec<CompletionItem>> = None;

INIT.call_once(|| unsafe {
SNIPPETS = Some(init_completions_from_snippets());
});

unsafe { SNIPPETS.as_ref().unwrap() }
static SNIPPETS: LazyLock<Vec<CompletionItem>> =
LazyLock::new(|| init_completions_from_snippets());
&SNIPPETS
}

fn init_completions_from_snippets() -> Vec<CompletionItem> {
Expand Down

0 comments on commit ceaf332

Please sign in to comment.