Skip to content

Commit 536ee62

Browse files
afnanenayetautozimu
authored andcommitted
Use self to avoid name repetition (#796)
* Refactor code to use `Self` when possible Avoid unnecessary name repetition by using `Self` instead of repeating a struct name (suggested by clippy lint) * Refactor function signature to use self Update function signature to conform more with Rust coding standards
1 parent 0ed9b69 commit 536ee62

File tree

6 files changed

+20
-23
lines changed

6 files changed

+20
-23
lines changed

src/language_server_protocol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl LanguageClient {
2525

2626
pub fn loop_call(&self, rx: &crossbeam_channel::Receiver<Call>) -> Fallible<()> {
2727
for call in rx.iter() {
28-
let language_client = LanguageClient(self.0.clone());
28+
let language_client = Self(self.0.clone());
2929
thread::spawn(move || {
3030
if let Err(err) = language_client.handle_call(call) {
3131
error!("Error handling request:\n{:?}", err);

src/rpcclient.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl RpcClient {
4747
}
4848
})?;
4949

50-
Ok(RpcClient {
50+
Ok(Self {
5151
languageId,
5252
id: Arc::new(Mutex::new(0)),
5353
process_id,

src/sign.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ pub struct Sign {
77
}
88

99
impl Sign {
10-
pub fn new(line: u64, name: String) -> Sign {
11-
Sign {
10+
pub fn new(line: u64, name: String) -> Self {
11+
Self {
1212
// Placeholder id. Will be updated when actually get displayed.
1313
id: 0,
1414
line,

src/types.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ pub struct State {
171171

172172
impl State {
173173
#[allow(clippy::new_ret_no_self)]
174-
pub fn new(tx: crossbeam_channel::Sender<Call>) -> Fallible<State> {
174+
pub fn new(tx: crossbeam_channel::Sender<Call>) -> Fallible<Self> {
175175
let logger = logger::init()?;
176176

177177
let client = RpcClient::new(
@@ -182,7 +182,7 @@ impl State {
182182
tx.clone(),
183183
)?;
184184

185-
Ok(State {
185+
Ok(Self {
186186
tx,
187187

188188
clients: hashmap! {
@@ -333,11 +333,11 @@ pub struct DiagnosticsDisplay {
333333
}
334334

335335
impl DiagnosticsDisplay {
336-
pub fn default() -> HashMap<u64, DiagnosticsDisplay> {
336+
pub fn default() -> HashMap<u64, Self> {
337337
let mut map = HashMap::new();
338338
map.insert(
339339
1,
340-
DiagnosticsDisplay {
340+
Self {
341341
name: "Error".to_owned(),
342342
texthl: "ALEError".to_owned(),
343343
signText: "✖".to_owned(),
@@ -347,7 +347,7 @@ impl DiagnosticsDisplay {
347347
);
348348
map.insert(
349349
2,
350-
DiagnosticsDisplay {
350+
Self {
351351
name: "Warning".to_owned(),
352352
texthl: "ALEWarning".to_owned(),
353353
signText: "⚠".to_owned(),
@@ -357,7 +357,7 @@ impl DiagnosticsDisplay {
357357
);
358358
map.insert(
359359
3,
360-
DiagnosticsDisplay {
360+
Self {
361361
name: "Information".to_owned(),
362362
texthl: "ALEInfo".to_owned(),
363363
signText: "ℹ".to_owned(),
@@ -367,7 +367,7 @@ impl DiagnosticsDisplay {
367367
);
368368
map.insert(
369369
4,
370-
DiagnosticsDisplay {
370+
Self {
371371
name: "Hint".to_owned(),
372372
texthl: "ALEInfo".to_owned(),
373373
signText: "➤".to_owned(),
@@ -386,25 +386,25 @@ pub struct DocumentHighlightDisplay {
386386
}
387387

388388
impl DocumentHighlightDisplay {
389-
pub fn default() -> HashMap<u64, DocumentHighlightDisplay> {
389+
pub fn default() -> HashMap<u64, Self> {
390390
let mut map = HashMap::new();
391391
map.insert(
392392
1,
393-
DocumentHighlightDisplay {
393+
Self {
394394
name: "Text".to_owned(),
395395
texthl: "SpellCap".to_owned(),
396396
},
397397
);
398398
map.insert(
399399
2,
400-
DocumentHighlightDisplay {
400+
Self {
401401
name: "Read".to_owned(),
402402
texthl: "SpellLocal".to_owned(),
403403
},
404404
);
405405
map.insert(
406406
3,
407-
DocumentHighlightDisplay {
407+
Self {
408408
name: "Write".to_owned(),
409409
texthl: "SpellRare".to_owned(),
410410
},
@@ -526,10 +526,7 @@ pub struct VimCompleteItemUserData {
526526
}
527527

528528
impl VimCompleteItem {
529-
pub fn from_lsp(
530-
lspitem: &CompletionItem,
531-
complete_position: Option<u64>,
532-
) -> Fallible<VimCompleteItem> {
529+
pub fn from_lsp(lspitem: &CompletionItem, complete_position: Option<u64>) -> Fallible<Self> {
533530
let abbr = lspitem.label.clone();
534531
let mut word = lspitem.insert_text.clone().unwrap_or_default();
535532
if word.is_empty() {
@@ -573,7 +570,7 @@ impl VimCompleteItem {
573570
snippet: snippet.clone(),
574571
};
575572

576-
Ok(VimCompleteItem {
573+
Ok(Self {
577574
word,
578575
abbr,
579576
icase: Some(1),
@@ -1027,7 +1024,7 @@ impl FromLSP<SymbolInformation> for QuickfixEntry {
10271024
fn from_lsp(sym: &SymbolInformation) -> Fallible<Self> {
10281025
let start = sym.location.range.start;
10291026

1030-
Ok(QuickfixEntry {
1027+
Ok(Self {
10311028
filename: sym.location.uri.filepath()?.to_string_lossy().into_owned(),
10321029
lnum: start.line + 1,
10331030
col: Some(start.character + 1),

src/viewport.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct Viewport {
1212
impl Viewport {
1313
#[allow(dead_code)]
1414
pub fn new(start: u64, end: u64) -> Self {
15-
Viewport { start, end }
15+
Self { start, end }
1616
}
1717

1818
fn contains(&self, line: u64) -> bool {

src/vim.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub struct Vim {
2020

2121
impl Vim {
2222
pub fn new(rpcclient: RpcClient) -> Self {
23-
Vim { rpcclient }
23+
Self { rpcclient }
2424
}
2525

2626
/// Fundamental functions.

0 commit comments

Comments
 (0)