Skip to content

Commit 8f6ac61

Browse files
clippy lint
1 parent 3fb8dc4 commit 8f6ac61

File tree

3 files changed

+26
-42
lines changed

3 files changed

+26
-42
lines changed

crates/djls-server/src/documents.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,21 @@ impl Store {
2323
pub fn handle_did_open(
2424
&mut self,
2525
db: &dyn Database,
26-
params: DidOpenTextDocumentParams,
27-
) -> Result<()> {
26+
params: &DidOpenTextDocumentParams,
27+
) {
2828
let uri = params.text_document.uri.to_string();
2929
let version = params.text_document.version;
3030

31-
let document = TextDocument::from_did_open_params(db, &params);
31+
let document = TextDocument::from_did_open_params(db, params);
3232

3333
self.add_document(document, uri.clone());
3434
self.versions.insert(uri, version);
35-
36-
Ok(())
3735
}
3836

3937
pub fn handle_did_change(
4038
&mut self,
4139
db: &dyn Database,
42-
params: DidChangeTextDocumentParams,
40+
params: &DidChangeTextDocumentParams,
4341
) -> Result<()> {
4442
let uri = params.text_document.uri.as_str().to_string();
4543
let version = params.text_document.version;
@@ -56,10 +54,8 @@ impl Store {
5654
Ok(())
5755
}
5856

59-
pub fn handle_did_close(&mut self, params: DidCloseTextDocumentParams) -> Result<()> {
57+
pub fn handle_did_close(&mut self, params: &DidCloseTextDocumentParams) {
6058
self.remove_document(params.text_document.uri.as_str());
61-
62-
Ok(())
6359
}
6460

6561
fn add_document(&mut self, document: TextDocument, uri: String) {
@@ -173,7 +169,7 @@ pub struct TextDocument {
173169
impl TextDocument {
174170
pub fn from_did_open_params(db: &dyn Database, params: &DidOpenTextDocumentParams) -> Self {
175171
let uri = params.text_document.uri.to_string();
176-
let contents = params.text_document.text.clone();
172+
let contents = params.text_document.text.clone(); // Need to clone here since we don't own params
177173
let version = params.text_document.version;
178174
let language_id = LanguageId::from(params.text_document.language_id.as_str());
179175

@@ -182,7 +178,7 @@ impl TextDocument {
182178
}
183179

184180
pub fn with_changes(
185-
&self,
181+
self,
186182
db: &dyn Database,
187183
changes: &[TextDocumentContentChangeEvent],
188184
new_version: i32,
@@ -209,7 +205,7 @@ impl TextDocument {
209205
}
210206
} else {
211207
// Full document update
212-
new_contents = change.text.clone();
208+
new_contents.clone_from(&change.text);
213209
}
214210
}
215211

@@ -225,20 +221,20 @@ impl TextDocument {
225221
}
226222

227223
#[allow(dead_code)]
228-
pub fn get_text(&self, db: &dyn Database) -> String {
224+
pub fn get_text(self, db: &dyn Database) -> String {
229225
self.contents(db).to_string()
230226
}
231227

232228
#[allow(dead_code)]
233-
pub fn get_text_range(&self, db: &dyn Database, range: Range) -> Option<String> {
229+
pub fn get_text_range(self, db: &dyn Database, range: Range) -> Option<String> {
234230
let index = self.index(db);
235231
let start = index.offset(range.start)? as usize;
236232
let end = index.offset(range.end)? as usize;
237233
let contents = self.contents(db);
238234
Some(contents[start..end].to_string())
239235
}
240236

241-
pub fn get_line(&self, db: &dyn Database, line: u32) -> Option<String> {
237+
pub fn get_line(self, db: &dyn Database, line: u32) -> Option<String> {
242238
let index = self.index(db);
243239
let start = index.line_starts.get(line as usize)?;
244240
let end = index
@@ -252,12 +248,12 @@ impl TextDocument {
252248
}
253249

254250
#[allow(dead_code)]
255-
pub fn line_count(&self, db: &dyn Database) -> usize {
251+
pub fn line_count(self, db: &dyn Database) -> usize {
256252
self.index(db).line_starts.len()
257253
}
258254

259255
pub fn get_template_tag_context(
260-
&self,
256+
self,
261257
db: &dyn Database,
262258
position: Position,
263259
) -> Option<TemplateTagContext> {
@@ -300,7 +296,7 @@ impl LineIndex {
300296
let mut pos = 0;
301297

302298
for c in text.chars() {
303-
pos += c.len_utf8() as u32;
299+
pos += u32::try_from(c.len_utf8()).unwrap_or(0);
304300
if c == '\n' {
305301
line_starts.push(pos);
306302
}
@@ -328,7 +324,7 @@ impl LineIndex {
328324
let line_start = self.line_starts[line];
329325
let character = offset - line_start;
330326

331-
Position::new(line as u32, character)
327+
Position::new(u32::try_from(line).unwrap_or(0), character)
332328
}
333329
}
334330

crates/djls-server/src/server.rs

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ impl LanguageServer for DjangoLanguageServer {
8686
})
8787
}
8888

89+
#[allow(clippy::too_many_lines)]
8990
async fn initialized(&self, _params: InitializedParams) {
9091
self.client
9192
.log_message(
@@ -240,16 +241,11 @@ impl LanguageServer for DjangoLanguageServer {
240241
)
241242
.await;
242243

243-
let result = self
244-
.with_session_mut(|session| {
244+
self.with_session_mut(|session| {
245245
let db = session.db_handle().db();
246-
session.documents_mut().handle_did_open(&db, params.clone())
246+
session.documents_mut().handle_did_open(&db, &params);
247247
})
248248
.await;
249-
250-
if let Err(e) = result {
251-
eprintln!("Error handling document open: {e}");
252-
}
253249
}
254250

255251
async fn did_change(&self, params: DidChangeTextDocumentParams) {
@@ -260,18 +256,13 @@ impl LanguageServer for DjangoLanguageServer {
260256
)
261257
.await;
262258

263-
let result = self
264-
.with_session_mut(|session| {
259+
self.with_session_mut(|session| {
265260
let db = session.db_handle().db();
266-
session
261+
let _ = session
267262
.documents_mut()
268-
.handle_did_change(&db, params.clone())
263+
.handle_did_change(&db, &params);
269264
})
270265
.await;
271-
272-
if let Err(e) = result {
273-
eprintln!("Error handling document change: {e}");
274-
}
275266
}
276267

277268
async fn did_close(&self, params: DidCloseTextDocumentParams) {
@@ -282,13 +273,10 @@ impl LanguageServer for DjangoLanguageServer {
282273
)
283274
.await;
284275

285-
let result = self
286-
.with_session_mut(|session| session.documents_mut().handle_did_close(params.clone()))
276+
self.with_session_mut(|session| {
277+
session.documents_mut().handle_did_close(&params);
278+
})
287279
.await;
288-
289-
if let Err(e) = result {
290-
eprintln!("Error handling document close: {e}");
291-
}
292280
}
293281

294282
async fn completion(&self, params: CompletionParams) -> LspResult<Option<CompletionResponse>> {

crates/djls-server/src/session.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ impl Session {
2525
}
2626
}
2727

28-
pub fn client_capabilities(&self) -> &Option<ClientCapabilities> {
29-
&self.client_capabilities
28+
pub fn client_capabilities(&self) -> Option<&ClientCapabilities> {
29+
self.client_capabilities.as_ref()
3030
}
3131

3232
pub fn client_capabilities_mut(&mut self) -> &mut Option<ClientCapabilities> {

0 commit comments

Comments
 (0)