---

- name: Editors
  hosts: all
  tags: editors
  tasks:

    - name: Install Visual Studio Code
      homebrew_cask:
        name: visual-studio-code
      tags: vscode

    - name: Vim
      when: not install_macvim | bool
      block:
        - name: Uninstall MacVim
          homebrew:
            name: macvim
            state: absent
          tags: vim
        - name: Install Vim
          homebrew:
            name: vim
            state: present
          tags: vim

    - name: MacVim
      when: install_macvim | bool
      block:
        - name: Uninstall Vim
          homebrew:
            name: vim
            state: absent
          tags: vim
        - name: Install MacVim
          homebrew:
            name: macvim
            state: present
          tags: vim

    - name: JetBrains Toolbox
      when: install_jetbrains_toolbox | bool
      block:
        - name: Check if JetBrains Toolbox has been installed
          stat:
            path: "/Applications/JetBrains Toolbox.app"
          register: jetbrains_toolbox_st
          changed_when: false
        - name: Install JetBrains Toolbox
          homebrew_cask:
            name: jetbrains-toolbox
          when: not jetbrains_toolbox_st.stat.exists

---

- name: Editors
  hosts: all
  tags: editors
  tasks:

    - name: Check if Visual Studio Code has been installed
      stat:
        path: "/Applications/Visual Studio Code.app"
      register: vscode_st
      changed_when: false

    - name: Install Visual Studio Code
      homebrew_cask:
        name: visual-studio-code
      tags: vscode
      when: not vscode_st.stat.exists

    - name: Vim
      when: not install_macvim | bool
      block:
        - name: Uninstall MacVim
          homebrew:
            name: macvim
            state: absent
          tags: vim
        - name: Install Vim
          homebrew:
            name: vim
            state: present
          tags: vim

    - name: MacVim
      when: install_macvim | bool
      block:
        - name: Uninstall Vim
          homebrew:
            name: vim
            state: absent
          tags: vim
        - name: Install MacVim
          homebrew:
            name: macvim
            state: present
          tags: vim

    - name: JetBrains Toolbox
      when: install_jetbrains_toolbox | bool
      block:
        - name: Check if JetBrains Toolbox has been installed
          stat:
            path: "/Applications/JetBrains Toolbox.app"
          register: jetbrains_toolbox_st
          changed_when: false
        - name: Install JetBrains Toolbox
          homebrew_cask:
            name: jetbrains-toolbox
          when: not jetbrains_toolbox_st.stat.exists

Add check that VS Code isn't already installed
Add check that VS Code isn't already installed
