Skip to content

Syntax checker does not work with workspaces in PowerShell #495

@fleetingbytes

Description

@fleetingbytes
  • rust.vim version: current

Steps to reproduce:

  • have MS PowerShell as the shell in which vim runs (e.g. $Env:ComSpec=C:\WINDOWS\SysWOW64\WindowsPowerShell\v1.0\powershell.exe)
" in .vimrc
" Set Powershell as the shell of choice
let &shell = has('win32') ? 'powershell' : 'pwsh'
let &shellcmdflag = '-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command [Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.Encoding]::UTF8;'
let &shellredir = '2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode'
let &shellpipe = '2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode'
set shellquote=\" shellxquote=
set noshelltemp
  • have a rust project with a workspace
  • edit a file inside the workspace (e.g. a .rs file inside the embedded library) so that syntax-checkers/rust/cargo.vim would have to enter this fork of the cargo.vim script
  • save the .rs source file so that rust syntax-checker runs

Expected vs. actual behavior:

Actual:
2023-03-18 09_47_51-lib rs (C__Users_ssiegmun_src_serial2-updater_sulib_src) (3 of 6) - GVIM2

  • This happens because PowerShell does not chain commands with && like other shells, so it errors out at (cd <path> && cargo check)

Expected:

  • Chain commands with ; if Powershell is used.
  • I corrected it for myself like this (replaced && with ) ; () in here:
    if rust#GetConfigVar('rust_cargo_avoid_whole_workspace', 1)
        if l:root_cargo_toml !=# l:nearest_cargo_toml
            let makeprg = "cd " . fnamemodify(l:nearest_cargo_toml, ":p:h")
                        \ . ") ; (" . makeprg
        endif
    else
        let makeprg = "cd " . fnamemodify(l:root_cargo_toml, ":p:h")
                    \ . ") ; (" . makeprg
    endif
  • a mere ; is not enough because then you'd end one powershell command without closing the parenthesis.
  • The script needs some logic to do this type of command chaining only when PowerShell is used as shell.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions