Skip to content

Commit f1cfe64

Browse files
fix: much more stable, no longer panic based on out of bounds (#33)
Fixes #32 - Trying to initiate autocomplete at coord 0 0 - Trying to initiate autocomplete in new file - Having to match from start of title/login is painful
1 parent 1e40712 commit f1cfe64

File tree

3 files changed

+30
-23
lines changed

3 files changed

+30
-23
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/backend.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl Backend {
5252
let completion_items = self
5353
.issue_map
5454
.iter()
55-
.filter(|issue| issue.title.starts_with(needle)) //TODO: smarter fuzzy match
55+
.filter(|issue| issue.get_detail().contains(needle)) //TODO: smarter fuzzy match
5656
.map(|issue| CompletionItem {
5757
label: issue.get_label(),
5858
detail: Some(issue.get_detail()),
@@ -83,7 +83,7 @@ impl Backend {
8383
let completion_items = self
8484
.member_map
8585
.iter()
86-
.filter(|member| member.login.starts_with(needle)) //TODO: smarter fuzzy match
86+
.filter(|member| member.get_detail().contains(needle)) //TODO: smarter fuzzy match
8787
.map(|member| CompletionItem {
8888
label: member.get_label(),
8989
detail: Some(member.get_detail()),
@@ -114,7 +114,7 @@ impl Backend {
114114
let completion_items = self
115115
.wiki_map
116116
.iter()
117-
.filter(|member| member.title.starts_with(needle)) //TODO: smarter fuzzy match
117+
.filter(|member| member.title.contains(needle)) //TODO: smarter fuzzy match
118118
.map(|member| CompletionItem {
119119
label: member.title.to_owned(),
120120
detail: None,
@@ -146,7 +146,7 @@ impl Backend {
146146
let completion_items = self
147147
.repository_map
148148
.iter()
149-
.filter(|repo| repo.name.starts_with(needle)) //TODO: smarter fuzzy match
149+
.filter(|repo| repo.get_detail().contains(needle)) //TODO: smarter fuzzy match
150150
.map(|repo| CompletionItem {
151151
label: repo.get_label(),
152152
detail: Some(repo.get_detail()),
@@ -214,9 +214,9 @@ impl Backend {
214214

215215
async fn initialize_repos_as(&self, affiliation: &str) {
216216
self.client
217-
.log_message(
217+
.show_message(
218218
MessageType::INFO,
219-
format!("initialize_repos_as: {}", affiliation),
219+
format!("initializing repos with affiliation `{}`", affiliation),
220220
)
221221
.await;
222222
let mut page: u8 = 0;
@@ -254,7 +254,7 @@ impl Backend {
254254

255255
async fn initialize_issues(&self) {
256256
self.client
257-
.log_message(MessageType::INFO, "initialize_issues")
257+
.show_message(MessageType::LOG, "initializing issues")
258258
.await;
259259
let mut page: u8 = 0;
260260
let mut issues: Vec<Issue> = vec![];
@@ -287,7 +287,7 @@ impl Backend {
287287

288288
async fn initialize_wiki(&self) {
289289
self.client
290-
.log_message(MessageType::INFO, "initialize_wiki")
290+
.show_message(MessageType::INFO, "initializing wiki")
291291
.await;
292292
let wikis = gh::wiki::find_wiki_articles(&self.owner, &self.repo).await;
293293
match wikis {
@@ -305,7 +305,7 @@ impl Backend {
305305

306306
async fn initialize_members(&self) {
307307
self.client
308-
.log_message(MessageType::INFO, "initialize_members")
308+
.show_message(MessageType::INFO, "initializing members")
309309
.await;
310310
let mut page: u8 = 0;
311311
let mut members: Vec<Author> = vec![];

src/lsp.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ impl LanguageServer for Backend {
2222
})),
2323
},
2424
)),
25-
// text_document_sync: Some(TextDocumentSyncCapability::Kind(
26-
// TextDocumentSyncKind::FULL,
27-
// )),
2825
completion_provider: Some(CompletionOptions {
2926
resolve_provider: Some(false),
3027
trigger_characters: Some(vec![
@@ -38,15 +35,16 @@ impl LanguageServer for Backend {
3835
all_commit_characters: None,
3936
..Default::default()
4037
}),
41-
execute_command_provider: Some(ExecuteCommandOptions {
42-
commands: vec!["dummy.do_something".to_string()],
43-
work_done_progress_options: Default::default(),
44-
}),
38+
// execute_command_provider: Some(ExecuteCommandOptions {
39+
// commands: vec!["dummy.do_something".to_string()],
40+
// work_done_progress_options: Default::default(),
41+
// }),
4542
workspace: Some(WorkspaceServerCapabilities {
4643
workspace_folders: Some(WorkspaceFoldersServerCapabilities {
4744
supported: Some(true),
4845
change_notifications: Some(OneOf::Left(true)),
4946
}),
47+
5048
file_operations: None,
5149
}),
5250
..ServerCapabilities::default()
@@ -57,9 +55,6 @@ impl LanguageServer for Backend {
5755

5856
async fn initialized(&self, _: InitializedParams) {
5957
self.initialize().await;
60-
self.client
61-
.log_message(MessageType::INFO, "initialized!")
62-
.await;
6358
}
6459

6560
async fn shutdown(&self) -> Result<()> {
@@ -168,11 +163,17 @@ impl LanguageServer for Backend {
168163
.document_map
169164
.get(&uri.to_string())
170165
.ok_or(tower_lsp::jsonrpc::Error::invalid_request())?;
166+
171167
let line = rope
172168
.get_line(position.line as usize)
173-
.ok_or(tower_lsp::jsonrpc::Error::internal_error())?
174-
.to_string();
175-
let line = line.split_at(position.character as usize).0;
169+
.ok_or(tower_lsp::jsonrpc::Error::internal_error())?;
170+
let character_pos = if position.character as usize >= line.len_chars() {
171+
line.len_chars() - 1
172+
} else {
173+
position.character as usize
174+
};
175+
let line = line.to_string();
176+
let line = line.split_at(character_pos).0;
176177
let word = line
177178
.chars()
178179
.rev()
@@ -181,7 +182,11 @@ impl LanguageServer for Backend {
181182
.chars()
182183
.rev()
183184
.collect::<String>();
184-
let parts = word.split_at(1);
185+
let parts = if word.len() <= 1 {
186+
(word.as_str(), "")
187+
} else {
188+
word.split_at(1)
189+
};
185190
let completions = match parts.0 {
186191
"#" => self.search_issue_and_pr(position, parts.1).await,
187192
"@" => self.search_user(position, parts.1).await,

0 commit comments

Comments
 (0)