Skip to content

Commit ed9df5e

Browse files
committed
separate for different type
1 parent 94cec42 commit ed9df5e

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

src/basecode_lsp/backend.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,21 +118,19 @@ impl LanguageServer for Backend {
118118

119119
let trie_lock = self.trie.lock().await;
120120
let words = trie_lock.suggest_completions(&prefix);
121-
let mut all_words = words;
121+
let suffixes = get_possible_current_word(&current_line, position.character as i32);
122+
words_to_completion_items(words, &suffixes, &mut completions, CompletionItemKind::TEXT);
122123

123124
let tmux_words = self.prepare_tmux_words().await;
124-
all_words.extend(tmux_words);
125+
words_to_completion_items(tmux_words, &suffixes, &mut completions, CompletionItemKind::REFERENCE);
125126

126127
if self.lsp_args.command_source {
127-
let command_words = get_command_completions();
128-
all_words.extend(command_words);
128+
let mut command_words = get_command_completions();
129+
command_words.sort();
130+
command_words.dedup();
131+
words_to_completion_items(command_words, &suffixes, &mut completions, CompletionItemKind::KEYWORD);
129132
}
130133

131-
let suffixes = get_possible_current_word(&current_line, position.character as i32);
132-
all_words.sort();
133-
all_words.dedup();
134-
words_to_completion_items(all_words, &suffixes, &mut completions);
135-
136134
let file_uri = params.text_document_position.text_document.uri.to_string();
137135
let snippets = self.suggest_snippets(&file_uri, &prefix).await;
138136
snippets_to_completion_items(snippets, &mut completions);
@@ -209,7 +207,7 @@ impl Backend {
209207

210208
async fn maybe_update_tmux(&self) {
211209
if self.lsp_args.tmux_source {
212-
let tmux_content = retrieve_tmux_words();
210+
let tmux_content = retrieve_tmux_words(self.lsp_args.min_word_len);
213211
let mut data = self.tmux_source.lock().await;
214212
data.clear();
215213
data.extend(tmux_content);

src/basecode_lsp/tmux.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use regex::Regex;
22
use std::process::Command;
3+
use super::util::*;
34

45
fn is_tmux_executable() -> bool {
56
let output = Command::new("tmux").arg("-V").output();
@@ -53,7 +54,7 @@ fn capture_alphanumeric_sequences(input: &str) -> Vec<String> {
5354
.collect()
5455
}
5556

56-
pub fn retrieve_tmux_words() -> Vec<String> {
57+
pub fn retrieve_tmux_words(min_len: usize) -> Vec<String> {
5758
if !is_tmux_executable() {
5859
return Vec::new();
5960
}
@@ -68,7 +69,7 @@ pub fn retrieve_tmux_words() -> Vec<String> {
6869

6970
result = result
7071
.into_iter()
71-
.filter(|s| s.len() >= 3 && !s.chars().all(|c| c.is_numeric())) // Filters out numbers and strings shorter than 3 characters
72+
.filter(|s| is_token(&s.chars().collect(), min_len))
7273
.collect();
7374
result.sort();
7475
result.dedup();

src/basecode_lsp/util.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,14 @@ pub fn words_to_completion_items(
7575
words: Vec<String>,
7676
suffixes: &Vec<String>,
7777
completions: &mut Vec<CompletionItem>,
78+
kind: CompletionItemKind,
7879
) {
7980
let items: Vec<CompletionItem> = words
8081
.iter()
8182
.filter(|&word| !suffixes.contains(word))
8283
.map(|word| CompletionItem {
8384
label: word.clone(),
84-
kind: Some(CompletionItemKind::TEXT),
85+
kind: Some(kind),
8586
sort_text: Some(word.clone()),
8687
..CompletionItem::default()
8788
})

0 commit comments

Comments
 (0)