Skip to content

Commit 2fde8ad

Browse files
authored
Fix LSP format not works. (#273)
1 parent 9a81398 commit 2fde8ad

File tree

4 files changed

+13
-26
lines changed

4 files changed

+13
-26
lines changed

autocorrect-lsp/src/lib.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,10 @@ impl Backend {
3131
}
3232

3333
fn upsert_document(&self, doc: Arc<TextDocumentItem>) {
34-
let uri = doc.uri.clone();
3534
self.documents
3635
.write()
3736
.unwrap()
38-
.get_mut(&uri)
39-
.map(|old| std::mem::replace(old, doc.clone()));
37+
.insert(doc.uri.clone(), doc.clone());
4038
}
4139

4240
fn get_document(&self, uri: &Url) -> Option<Arc<TextDocumentItem>> {
@@ -105,7 +103,6 @@ impl Backend {
105103
}
106104

107105
async fn clear_diagnostics(&self, uri: &Url) {
108-
self.diagnostics.write().unwrap().remove(uri);
109106
self.client
110107
.publish_diagnostics(uri.clone(), vec![], None)
111108
.await;
@@ -263,14 +260,14 @@ impl LanguageServer for Backend {
263260
return;
264261
}
265262

266-
self.client
267-
.log_message(MessageType::INFO, format!("did_change {}\n", uri))
268-
.await;
269-
270263
assert_eq!(content_changes.len(), 1);
271264
let change = content_changes.into_iter().next().unwrap();
272265
assert!(change.range.is_none());
273266

267+
self.client
268+
.log_message(MessageType::INFO, format!("did_change {}", uri))
269+
.await;
270+
274271
let updated_doc =
275272
TextDocumentItem::new(uri.clone(), "".to_string(), version, change.text.clone());
276273
self.upsert_document(Arc::new(updated_doc.clone()));
@@ -316,7 +313,13 @@ impl LanguageServer for Backend {
316313
self.clear_diagnostics(&text_document.uri).await;
317314
let input = document.text.as_str();
318315

316+
self.client
317+
.log_message(MessageType::INFO, format!("before: {}", input))
318+
.await;
319319
let result = autocorrect::format_for(input, document.uri.path());
320+
self.client
321+
.log_message(MessageType::INFO, format!("after: {}", result.out))
322+
.await;
320323
let range = Range::new(
321324
Position::new(0, 0),
322325
Position {

autocorrect/src/code/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub fn get_file_extension(filename: &str) -> String {
2525
return String::from(filename);
2626
}
2727

28-
let filename = filename.split('/').last().unwrap().to_string();
28+
let filename = filename.split('/').next_back().unwrap().to_string();
2929
let path_parts: Vec<&str> = filename.split('.').collect();
3030
let mut ext: String = path_parts.last().unwrap().to_string();
3131

autocorrect/src/result/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ pub trait Results {
6969

7070
/// Is AutoCorrrect current is enable
7171
fn is_enabled(&self) -> bool {
72-
match self.get_toggle().match_rule("") {
73-
Some(enable) => enable,
74-
_ => true,
75-
}
72+
self.get_toggle().match_rule("").unwrap_or(true)
7673
}
7774
}
7875

autocorrect/src/result/rdjson.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,6 @@
33
use super::LintResult;
44
use serde::{Deserialize, Serialize};
55

6-
#[derive(Serialize, Deserialize, Clone)]
7-
struct RdfJson {
8-
source: RdfSource,
9-
severity: String,
10-
diagnostics: String,
11-
}
12-
13-
#[derive(Serialize, Deserialize, Clone)]
14-
struct RdfSource {
15-
name: String,
16-
url: String,
17-
}
18-
196
#[derive(Serialize, Deserialize, Clone)]
207
struct RdfDiagnostic {
218
message: String,

0 commit comments

Comments
 (0)