fix: nameless file crash (#84)
This commit is contained in:
parent
50b62bd107
commit
0d035901f0
|
@ -176,7 +176,7 @@ impl Document {
|
||||||
let rope = Rope::from_str(text);
|
let rope = Rope::from_str(text);
|
||||||
let text_len = rope.len_chars();
|
let text_len = rope.len_chars();
|
||||||
let end_idx = idx + text_len;
|
let end_idx = idx + text_len;
|
||||||
self.text.insert(idx, text);
|
self.text.try_insert(idx, text)?;
|
||||||
(
|
(
|
||||||
end_idx,
|
end_idx,
|
||||||
Point {
|
Point {
|
||||||
|
@ -189,7 +189,7 @@ impl Document {
|
||||||
+ (range.end.character as usize);
|
+ (range.end.character as usize);
|
||||||
let slice_size = removal_idx - start_idx;
|
let slice_size = removal_idx - start_idx;
|
||||||
self.text.try_remove(start_idx..removal_idx)?;
|
self.text.try_remove(start_idx..removal_idx)?;
|
||||||
self.text.insert(start_idx, text);
|
self.text.try_insert(start_idx, text)?;
|
||||||
let rope = Rope::from_str(text);
|
let rope = Rope::from_str(text);
|
||||||
let text_len = rope.len_chars();
|
let text_len = rope.len_chars();
|
||||||
let character_difference = text_len as isize - slice_size as isize;
|
let character_difference = text_len as isize - slice_size as isize;
|
||||||
|
|
|
@ -429,12 +429,22 @@ impl LlmService {
|
||||||
) -> LspResult<GetCompletionsResult> {
|
) -> LspResult<GetCompletionsResult> {
|
||||||
let request_id = Uuid::new_v4();
|
let request_id = Uuid::new_v4();
|
||||||
let span = info_span!("completion_request", %request_id);
|
let span = info_span!("completion_request", %request_id);
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
let document_map = self.document_map.read().await;
|
let document_map = self.document_map.read().await;
|
||||||
|
|
||||||
let document = document_map
|
let document =
|
||||||
.get(params.text_document_position.text_document.uri.as_str())
|
match document_map.get(params.text_document_position.text_document.uri.as_str()) {
|
||||||
.ok_or_else(|| internal_error("failed to find document"))?;
|
Some(doc) => doc,
|
||||||
|
None => {
|
||||||
|
debug!("failed to find document");
|
||||||
|
return Ok(GetCompletionsResult {
|
||||||
|
request_id,
|
||||||
|
completions: vec![],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
info!(
|
info!(
|
||||||
document_url = %params.text_document_position.text_document.uri,
|
document_url = %params.text_document_position.text_document.uri,
|
||||||
cursor_line = ?params.text_document_position.position.line,
|
cursor_line = ?params.text_document_position.position.line,
|
||||||
|
@ -545,6 +555,9 @@ impl LanguageServer for LlmService {
|
||||||
|
|
||||||
async fn did_open(&self, params: DidOpenTextDocumentParams) {
|
async fn did_open(&self, params: DidOpenTextDocumentParams) {
|
||||||
let uri = params.text_document.uri.to_string();
|
let uri = params.text_document.uri.to_string();
|
||||||
|
if uri == "file:///" {
|
||||||
|
return;
|
||||||
|
}
|
||||||
match Document::open(
|
match Document::open(
|
||||||
¶ms.text_document.language_id,
|
¶ms.text_document.language_id,
|
||||||
¶ms.text_document.text,
|
¶ms.text_document.text,
|
||||||
|
@ -567,6 +580,9 @@ impl LanguageServer for LlmService {
|
||||||
|
|
||||||
async fn did_change(&self, params: DidChangeTextDocumentParams) {
|
async fn did_change(&self, params: DidChangeTextDocumentParams) {
|
||||||
let uri = params.text_document.uri.to_string();
|
let uri = params.text_document.uri.to_string();
|
||||||
|
if uri == "file:///" {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if params.content_changes.is_empty() {
|
if params.content_changes.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -593,7 +609,7 @@ impl LanguageServer for LlmService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
warn!("textDocument/didChange {uri}: document not found");
|
debug!("textDocument/didChange {uri}: document not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue