refactor.sh

  1#!/bin/bash
  2
  3# Merge process:
  4#
  5# * Use mergiraf for merge, with `git merge main -X theirs`
  6#
  7#    - Need to use it with a patched tree-sitter-rust. I (Michael)
  8#      haven't yet uploaded a fork for this, can do if helpful.
  9#      https://github.com/tree-sitter/tree-sitter-rust/pull/245
 10#
 11#    - Watch for newlines between top level decls sometimes disappearing
 12#
 13# * Run this script.
 14
 15dry=true
 16if [ "$1" = "apply" ]; then
 17    dry=false
 18fi
 19
 20re() {
 21    echo "$1" "    -->    " "$2"
 22    if [ "$dry" = true ]; then
 23        ruplacer "$1" "$2" crates/ --type *.rs
 24    else
 25        ruplacer "$1" "$2" crates/ --type *.rs --go
 26    fi
 27}
 28
 29re '\.new_view\('                    '.new_model('
 30re 'cx.view\('                       'cx.model('
 31re '\.observe_new_views\('           '.observe_new_models('
 32re 'View<'                           'Model<'
 33re 'FocusableView'                   'Focusable'
 34
 35# closure parameters
 36re ', &mut WindowContext\)'          ', &mut Window, &mut AppContext)'
 37re ', &mut ViewContext<([^>]+)>\)'   ', &mut Window, &mut ModelContext<$1>)'
 38re '\(&mut WindowContext\)'          '(&mut Window, &mut AppContext)'
 39re '\(&mut ViewContext<([^>]+)>\)'   '(&mut Window, &mut ModelContext<$1>)'
 40
 41# function parameters
 42re '_: &mut WindowContext\)'          '_window: &mut Window, _cx: &mut AppContext)'
 43re '_: &mut ViewContext<([^>]+)>\)'   '_window: &mut Window, _cx: &mut ModelContext<$1>)'
 44re '_: &mut WindowContext,'           '_window: &mut Window, _cx: &mut AppContext,'
 45re '_: &mut ViewContext<([^>]+)>,'    '_window: &mut Window, _cx: &mut ModelContext<$1>,'
 46re '_cx: &mut WindowContext\)'        '_window: &mut Window, _cx: &mut AppContext)'
 47re '_cx: &mut ViewContext<([^>]+)>\)' '_window: &mut Window, _cx: &mut ModelContext<$1>)'
 48re '_cx: &mut WindowContext,'         '_window: &mut Window, _cx: &mut AppContext,'
 49re '_cx: &mut ViewContext<([^>]+)>,'  '_window: &mut Window, _cx: &mut ModelContext<$1>,'
 50re 'cx: &mut WindowContext\)'         'window: &mut Window, cx: &mut AppContext)'
 51re 'cx: &mut ViewContext<([^>]+)>\)'  'window: &mut Window, cx: &mut ModelContext<$1>)'
 52re 'cx: &mut WindowContext,'          'window: &mut Window, cx: &mut AppContext,'
 53re 'cx: &mut ViewContext<([^>]+)>,'   'window: &mut Window, cx: &mut ModelContext<$1>,'
 54
 55re '_: &WindowContext\)'              '_window: &Window, _cx: &AppContext)'
 56re '_: &ViewContext<([^>]+)>\)'       '_window: &Window, _cx: &ModelContext<$1>)'
 57re '_: &WindowContext,'               '_window: &Window, _cx: &AppContext,'
 58re '_: &ViewContext<([^>]+)>,'        '_window: &Window, _cx: &ModelContext<$1>,'
 59re '_cx: &WindowContext\)'            '_window: &Window, _cx: &AppContext)'
 60re '_cx: &ViewContext<([^>]+)>\)'     '_window: &Window, _cx: &ModelContext<$1>)'
 61re '_cx: &WindowContext,'             '_window: &Window, _cx: &AppContext,'
 62re '_cx: &ViewContext<([^>]+)>,'      '_window: &Window, _cx: &ModelContext<$1>,'
 63re 'cx: &WindowContext\)'             'window: &Window, cx: &AppContext)'
 64re 'cx: &ViewContext<([^>]+)>\)'      'window: &Window, cx: &ModelContext<$1>)'
 65re 'cx: &WindowContext,'              'window: &Window, cx: &AppContext,'
 66re 'cx: &ViewContext<([^>]+)>,'       'window: &Window, cx: &ModelContext<$1>,'
 67
 68# VisualContext methods moved to window, that take context
 69re 'cx.dismiss_view\(' 'window.dismiss_view(cx, '
 70re 'cx.focus_view\(' 'window.focus_view(cx, '
 71re 'cx.new_view\(' 'window.new_view(cx, '
 72re 'cx.replace_root_view\(' 'window.replace_root_view(cx, '
 73
 74# AppContext methods moved to window, that take context
 75re 'cx.appearance_changed\(\)' 'window.appearance_changed(cx)'
 76re 'cx.available_actions\(\)' 'window.available_actions(cx)'
 77re 'cx.dispatch_keystroke_observers\(' 'window.dispatch_keystroke_observers(cx, '
 78re 'cx.display\(\)' 'window.display(cx)'
 79re 'cx.focused\(\)' 'window.focused(cx)'
 80re 'cx.handle_input\(' 'window.handle_input(cx, '
 81re 'cx.paint_svg\(' 'window.paint_svg(cx, '
 82re 'cx.request_layout\(' 'window.request_layout(cx, '
 83re 'cx.use_asset\(' 'window.use_asset(cx, '
 84
 85# Subset of AppContext methods moved to window that don't take context
 86re 'cx\.set_cursor_style\('           'window.set_cursor_style('
 87re 'cx\.modifiers\('                  'window.modifiers('
 88re 'cx\.mouse_position\('             'window.mouse_position('
 89re 'cx\.text_style\('                 'window.text_style('
 90re 'cx\.line_height\('                'window.line_height('
 91
 92# common closure patterns
 93re 'cx.listener\(move \|this, _, cx\|' 'cx.listener(move |this, _, window, cx|'
 94re 'cx.listener\(\|this, _, cx\|'     'cx.listener(|this, _, window, cx|'
 95re 'cx.listener\(move \|_, _, cx\|'   'cx.listener(move |_, _, window, cx|'
 96re 'cx.listener\(\|_, _, cx\|'        'cx.listener(|_, _, window, cx|'
 97re '\.on_click\(move \|_, cx\|'       '.on_click(move |_, window, cx|'
 98re '\.on_mouse_move\(\|_, cx\|'       '.on_mouse_move(|_, window, cx|'
 99
100# cleanup imports
101re ' ViewContext,'                     ''
102re ' WindowContext,'                   ''
103re ' WeakView,'                        ''
104re ' View,'                            ''
105re ', ViewContext\}'                   '}'
106re ', WindowContext\}'                 '}'
107re ', WeakView\}'                      '}'
108re ', View\}'                          '}'
109
110# other patterns
111re '\.detach_and_notify_err\(cx'       '.detach_and_notify_err(window, cx'