@@ -9,8 +9,8 @@ extern crate toml;
99
1010use git2:: Repository ;
1111use nvim_oxi:: api;
12- use nvim_oxi:: api:: opts:: { CmdOpts , CreateCommandOpts } ;
13- use nvim_oxi:: api:: types:: { CmdInfos , CommandArgs , CommandNArgs , CommandRange } ;
12+ use nvim_oxi:: api:: opts:: CreateCommandOpts ;
13+ use nvim_oxi:: api:: types:: { CommandArgs , CommandNArgs , CommandRange } ;
1414use nvim_oxi:: string;
1515use nvim_oxi:: { self as oxi, Array , Dictionary , Object } ;
1616use regex:: Regex ;
@@ -51,8 +51,8 @@ enum StatusLineAction {
5151
5252thread_local ! {
5353 static EXPANDED_COMMENTS : RefCell <HashSet <usize >> = RefCell :: new( HashSet :: new( ) ) ;
54- static STATUS_BUFFER_HANDLE : RefCell <Option <nvim_oxi:: api:: Buffer >> = RefCell :: new( None ) ;
55- static STATUS_LINE_ACTIONS : RefCell <Vec <StatusLineAction >> = RefCell :: new( Vec :: new( ) ) ;
54+ static STATUS_BUFFER_HANDLE : RefCell <Option <nvim_oxi:: api:: Buffer >> = const { RefCell :: new( None ) } ;
55+ static STATUS_LINE_ACTIONS : RefCell <Vec <StatusLineAction >> = const { RefCell :: new( Vec :: new( ) ) } ;
5656}
5757
5858/// Git backend type (GitHub or GitLab)
@@ -339,10 +339,10 @@ fn vim_reviewer() -> oxi::Result<()> {
339339 "UpdateReviewSigns" ,
340340 "Update the gutter symbols for review comments" ,
341341 CommandNArgs :: ZeroOrOne ,
342- |args : CommandArgs | -> ApiResult <( ) > {
342+ |_args : CommandArgs | -> ApiResult <( ) > {
343343 let review = get_current_review( ) ;
344344 match review {
345- None => return Ok ( ( ) ) ,
345+ None => Ok ( ( ) ) ,
346346 Some ( review) => {
347347 let mut sign_idx = 0 ;
348348 api:: command( "sign unplace * group=PrReviewSigns" ) ?;
@@ -359,7 +359,7 @@ fn vim_reviewer() -> oxi::Result<()> {
359359 . comments
360360 . iter( )
361361 . filter( |comment| {
362- comment. path == buffer_path. to_str( ) . unwrap( ) . to_string ( )
362+ comment. path == buffer_path. to_str( ) . unwrap( )
363363 } )
364364 . collect( ) ;
365365 for comment in comments_in_buffer {
@@ -396,7 +396,7 @@ fn vim_reviewer() -> oxi::Result<()> {
396396 match get_config_from_file( ) {
397397 None => {
398398 api:: err_writeln( "Could not read configuration file." ) ;
399- return Ok ( ( ) ) ;
399+ Ok ( ( ) )
400400 }
401401 Some ( mut config) => {
402402 let raw = args. args. unwrap_or_default( ) ;
@@ -424,18 +424,16 @@ fn vim_reviewer() -> oxi::Result<()> {
424424 update_configuration( config) ;
425425
426426 // Optionally try API fetch for enrichment
427- if let Some ( config) = get_config_from_file( ) {
428- if let Some ( pr_info) = fetch_pr_info_from_api( & config, pr_number) {
427+ if let Some ( config) = get_config_from_file( )
428+ && let Some ( pr_info) = fetch_pr_info_from_api( & config, pr_number) {
429429 // Cache the enriched info
430- if let Ok ( json) = serde_json:: to_string( & pr_info) {
431- if let Ok ( mut file) =
430+ if let Ok ( json) = serde_json:: to_string( & pr_info)
431+ && let Ok ( mut file) =
432432 File :: create( get_pr_info_cache_path( pr_number) )
433433 {
434434 let _ = file. write_all( json. as_bytes( ) ) ;
435435 }
436- }
437436 }
438- }
439437
440438 Ok ( ( ) )
441439 }
@@ -547,7 +545,7 @@ fn vim_reviewer() -> oxi::Result<()> {
547545 CommandNArgs :: ZeroOrOne ,
548546 |args: CommandArgs | -> ApiResult <( ) > {
549547 let command_args = args. args. unwrap_or( "" . to_string( ) ) ;
550- let is_new_comment = command_args == "new" . to_string ( ) ;
548+ let is_new_comment = command_args == "new" ;
551549 let review = get_current_review( ) ;
552550 match review {
553551 None => {
@@ -692,7 +690,7 @@ fn vim_reviewer() -> oxi::Result<()> {
692690 "QuickfixAllComments" ,
693691 "Load all review comments into the quickfix list" ,
694692 CommandNArgs :: ZeroOrOne ,
695- |args : CommandArgs | -> ApiResult <( ) > {
693+ |_args : CommandArgs | -> ApiResult <( ) > {
696694 let review = get_current_review( ) ;
697695 match review {
698696 None => {
@@ -749,12 +747,11 @@ fn vim_reviewer() -> oxi::Result<()> {
749747 CommandNArgs :: ZeroOrOne ,
750748 |_args: CommandArgs | -> ApiResult <( ) > {
751749 // Invalidate PrInfo cache so files are re-computed from git
752- if let Some ( config) = get_config_from_file( ) {
753- if let Some ( pr_number) = config. active_pr {
750+ if let Some ( config) = get_config_from_file( )
751+ && let Some ( pr_number) = config. active_pr {
754752 let cache_path = get_pr_info_cache_path( pr_number) ;
755753 let _ = std:: fs:: remove_file( & cache_path) ;
756754 }
757- }
758755 refresh_status_buffer( ) ?;
759756 Ok ( ( ) )
760757 }
@@ -785,7 +782,7 @@ fn vim_reviewer() -> oxi::Result<()> {
785782 api:: command( "wincmd j" ) ?;
786783 api:: command( & format!( "edit {}" , path) ) ?;
787784 let diff_cmd = format!( "Gvdiffsplit origin/{}" , base_branch) ;
788- if let Err ( _ ) = api:: command( & diff_cmd) {
785+ if api:: command( & diff_cmd) . is_err ( ) {
789786 // Fallback: just open the file without diff
790787 api:: err_writeln(
791788 "Could not open fugitive diff. Is vim-fugitive installed?" ,
@@ -831,21 +828,18 @@ fn vim_reviewer() -> oxi::Result<()> {
831828 actions. get( line_idx) . cloned( )
832829 } ) ;
833830
834- match action {
835- Some ( StatusLineAction :: ToggleComment ( idx) ) => {
836- EXPANDED_COMMENTS . with( |e| {
837- let mut set = e. borrow_mut( ) ;
838- if set. contains( & idx) {
839- set. remove( & idx) ;
840- } else {
841- set. insert( idx) ;
842- }
843- } ) ;
844- let saved_cursor = api:: get_current_win( ) . get_cursor( ) ?;
845- refresh_status_buffer( ) ?;
846- let _ = api:: get_current_win( ) . set_cursor( saved_cursor. 0 , saved_cursor. 1 ) ;
847- }
848- _ => { }
831+ if let Some ( StatusLineAction :: ToggleComment ( idx) ) = action {
832+ EXPANDED_COMMENTS . with( |e| {
833+ let mut set = e. borrow_mut( ) ;
834+ if set. contains( & idx) {
835+ set. remove( & idx) ;
836+ } else {
837+ set. insert( idx) ;
838+ }
839+ } ) ;
840+ let saved_cursor = api:: get_current_win( ) . get_cursor( ) ?;
841+ refresh_status_buffer( ) ?;
842+ let _ = api:: get_current_win( ) . set_cursor( saved_cursor. 0 , saved_cursor. 1 ) ;
849843 }
850844 Ok ( ( ) )
851845 }
@@ -997,13 +991,12 @@ fn get_files_changed(base_branch: &str) -> Result<Vec<FileChange>, String> {
997991 let mut additions: u32 = 0 ;
998992 let mut deletions: u32 = 0 ;
999993
1000- if let Ok ( patch) = git2:: Patch :: from_diff ( & diff, idx) {
1001- if let Some ( ref patch) = patch {
994+ if let Ok ( patch) = git2:: Patch :: from_diff ( & diff, idx)
995+ && let Some ( ref patch) = patch {
1002996 let ( _, adds, dels) = patch. line_stats ( ) . unwrap_or ( ( 0 , 0 , 0 ) ) ;
1003997 additions = adds as u32 ;
1004998 deletions = dels as u32 ;
1005999 }
1006- }
10071000
10081001 files. push ( FileChange {
10091002 path,
@@ -1026,18 +1019,15 @@ fn get_or_build_pr_info(config: &Config, pr_number: u32) -> Option<PrInfo> {
10261019 let base_branch = config. base_branch . as_deref ( ) . unwrap_or ( "main" ) . to_string ( ) ;
10271020
10281021 // Try loading from cache
1029- if cache_path. exists ( ) {
1030- if let Ok ( mut file) = File :: open ( & cache_path) {
1022+ if cache_path. exists ( )
1023+ && let Ok ( mut file) = File :: open ( & cache_path) {
10311024 let mut contents = String :: new ( ) ;
1032- if file. read_to_string ( & mut contents) . is_ok ( ) {
1033- if let Ok ( cached) = serde_json:: from_str :: < PrInfo > ( & contents) {
1034- if cached. base_branch == base_branch {
1025+ if file. read_to_string ( & mut contents) . is_ok ( )
1026+ && let Ok ( cached) = serde_json:: from_str :: < PrInfo > ( & contents)
1027+ && cached. base_branch == base_branch {
10351028 return Some ( cached) ;
10361029 }
1037- }
1038- }
10391030 }
1040- }
10411031
10421032 // Build locally
10431033 let files_changed = match get_files_changed ( & base_branch) {
@@ -1057,11 +1047,10 @@ fn get_or_build_pr_info(config: &Config, pr_number: u32) -> Option<PrInfo> {
10571047 } ;
10581048
10591049 // Cache to disk
1060- if let Ok ( json) = serde_json:: to_string ( & pr_info) {
1061- if let Ok ( mut file) = File :: create ( & cache_path) {
1050+ if let Ok ( json) = serde_json:: to_string ( & pr_info)
1051+ && let Ok ( mut file) = File :: create ( & cache_path) {
10621052 let _ = file. write_all ( json. as_bytes ( ) ) ;
10631053 }
1064- }
10651054
10661055 Some ( pr_info)
10671056}
@@ -1108,10 +1097,7 @@ fn fetch_pr_info_from_api(config: &Config, pr_number: u32) -> Option<PrInfo> {
11081097 . map ( |s| s. to_string ( ) )
11091098 . unwrap_or ( base_branch) ;
11101099
1111- let files_changed = match get_files_changed ( & api_base) {
1112- Ok ( f) => f,
1113- Err ( _) => Vec :: new ( ) ,
1114- } ;
1100+ let files_changed = get_files_changed ( & api_base) . unwrap_or_default ( ) ;
11151101
11161102 Some ( PrInfo {
11171103 pr_number,
@@ -1151,10 +1137,7 @@ fn fetch_pr_info_from_api(config: &Config, pr_number: u32) -> Option<PrInfo> {
11511137 . map ( |s| s. to_string ( ) )
11521138 . unwrap_or ( base_branch) ;
11531139
1154- let files_changed = match get_files_changed ( & api_base) {
1155- Ok ( f) => f,
1156- Err ( _) => Vec :: new ( ) ,
1157- } ;
1140+ let files_changed = get_files_changed ( & api_base) . unwrap_or_default ( ) ;
11581141
11591142 Some ( PrInfo {
11601143 pr_number,
@@ -1285,16 +1268,15 @@ fn build_status_lines(
12851268 actions. push ( StatusLineAction :: None ) ;
12861269
12871270 // Review body
1288- if let Some ( review) = review {
1289- if !review. body . is_empty ( ) {
1271+ if let Some ( review) = review
1272+ && !review. body . is_empty ( ) {
12901273 lines. push ( "Review body:" . to_string ( ) ) ;
12911274 actions. push ( StatusLineAction :: None ) ;
12921275 for body_line in review. body . lines ( ) {
12931276 lines. push ( format ! ( " {}" , body_line) ) ;
12941277 actions. push ( StatusLineAction :: None ) ;
12951278 }
12961279 }
1297- }
12981280
12991281 ( lines, actions)
13001282}
@@ -1766,9 +1748,7 @@ impl Review {
17661748
17671749 // Use the backend_url from config, or default to gitlab.com
17681750 let base_url = self
1769- . backend_url
1770- . as_ref ( )
1771- . map ( |s| s. as_str ( ) )
1751+ . backend_url . as_deref ( )
17721752 . unwrap_or ( "https://gitlab.com" ) ;
17731753
17741754 let encoded_project = format ! ( "{}/{}" , self . owner, self . repo) . replace ( "/" , "%2F" ) ;
@@ -1862,8 +1842,7 @@ impl Review {
18621842
18631843 // Build position object
18641844 // For multi-line comments, use line_range instead of new_line/old_line
1865- let mut position = if is_multi_line {
1866- serde_json:: json!( {
1845+ let mut position = serde_json:: json!( {
18671846 "position_type" : "text" ,
18681847 "base_sha" : base_sha,
18691848 "start_sha" : start_sha,
@@ -1872,19 +1851,7 @@ impl Review {
18721851 "old_path" : old_path,
18731852 "new_line" : new_line,
18741853 "old_line" : old_line,
1875- } )
1876- } else {
1877- serde_json:: json!( {
1878- "position_type" : "text" ,
1879- "base_sha" : base_sha,
1880- "start_sha" : start_sha,
1881- "head_sha" : head_sha,
1882- "new_path" : new_path,
1883- "old_path" : old_path,
1884- "new_line" : new_line,
1885- "old_line" : old_line,
1886- } )
1887- } ;
1854+ } ) ;
18881855
18891856 // Add line_range for multi-line comments
18901857 if is_multi_line {
@@ -2047,7 +2014,7 @@ impl Review {
20472014 }
20482015 Ok ( file) => file,
20492016 } ;
2050- file. write_all ( & serde_json:: to_string ( & self ) . unwrap ( ) . as_bytes ( ) )
2017+ file. write_all ( serde_json:: to_string ( & self ) . unwrap ( ) . as_bytes ( ) )
20512018 . unwrap ( ) ;
20522019 }
20532020
@@ -2059,14 +2026,14 @@ impl Review {
20592026 . iter ( )
20602027 . enumerate ( )
20612028 . filter ( |( _idx, comment) | {
2062- return comment. path == path
2029+ comment. path == path
20632030 && ( comment. line == line
20642031 || ( comment. start_line . is_some ( )
20652032 && comment. start_line . unwrap ( ) <= line
2066- && comment. line >= line) ) ;
2033+ && comment. line >= line) )
20672034 } )
20682035 . collect ( ) ;
2069- if eligible_comments. len ( ) > 0 {
2036+ if ! eligible_comments. is_empty ( ) {
20702037 Some ( eligible_comments[ 0 ] )
20712038 } else {
20722039 None
@@ -2103,7 +2070,7 @@ impl Review {
21032070 match get_config_from_file ( ) {
21042071 None => {
21052072 api:: err_writeln ( "Could not read configuration file." ) ;
2106- return None ;
2073+ None
21072074 }
21082075 Some ( config) => Some ( Review :: new (
21092076 config. owner . to_string ( ) ,
@@ -2125,7 +2092,7 @@ impl Review {
21252092/// If the line is only in the new file (added), old_line will be None
21262093fn get_line_mapping (
21272094 repo : & Repository ,
2128- file_path : & str ,
2095+ _file_path : & str ,
21292096 base_sha : & str ,
21302097 head_sha : & str ,
21312098 line_number : u32 ,
@@ -2160,17 +2127,7 @@ fn get_line_mapping(
21602127 let mut line_map: Vec < ( Option < u32 > , Option < u32 > ) > = Vec :: new ( ) ;
21612128
21622129 diff. foreach (
2163- & mut |delta, _progress| {
2164- let delta_path = delta
2165- . new_file ( )
2166- . path ( )
2167- . unwrap_or ( delta. old_file ( ) . path ( ) . unwrap ( ) ) ;
2168- if delta_path. to_str ( ) == Some ( file_path) {
2169- true
2170- } else {
2171- true
2172- }
2173- } ,
2130+ & mut |_delta, _progress| { true } ,
21742131 None ,
21752132 None ,
21762133 Some ( & mut |_delta, _hunk, line| {
@@ -2199,18 +2156,16 @@ fn get_line_mapping(
21992156 for ( old_line, new_line) in & line_map {
22002157 if side == Side :: LEFT {
22012158 // Looking for old line number
2202- if let Some ( old) = old_line {
2203- if * old == line_number {
2159+ if let Some ( old) = old_line
2160+ && * old == line_number {
22042161 return Ok ( ( * old_line, * new_line) ) ;
22052162 }
2206- }
22072163 } else {
22082164 // Looking for new line number
2209- if let Some ( new) = new_line {
2210- if * new == line_number {
2165+ if let Some ( new) = new_line
2166+ && * new == line_number {
22112167 return Ok ( ( * old_line, * new_line) ) ;
22122168 }
2213- }
22142169 }
22152170 }
22162171
@@ -2228,7 +2183,7 @@ fn get_review_directory() -> PathBuf {
22282183 let git_dir = Path :: new ( git_output. trim ( ) ) ;
22292184 let review_dir = git_dir. join ( Path :: new ( "reviews" ) ) ;
22302185 std:: fs:: create_dir_all ( & review_dir) . unwrap ( ) ;
2231- return review_dir;
2186+ review_dir
22322187}
22332188
22342189fn get_review_file_path ( pr_number : u32 ) -> PathBuf {
@@ -2272,6 +2227,6 @@ pub fn update_configuration(config: Config) {
22722227 }
22732228 Ok ( file) => file,
22742229 } ;
2275- file. write_all ( & serde_json:: to_string ( & config) . unwrap ( ) . as_bytes ( ) )
2230+ file. write_all ( serde_json:: to_string ( & config) . unwrap ( ) . as_bytes ( ) )
22762231 . unwrap ( ) ;
22772232}
0 commit comments