Skip to content

Fix cwd #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master

**Bugfixes:**

- Fix an issue that causes the plugin to change cwd (e.g. in a monorepo setup)

## 1.3.0

**Improvements:**
Expand Down
15 changes: 10 additions & 5 deletions autoload/rescript.vim
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ function! rescript#UpdateProjectEnv()
let l:res_bin_dir = finddir('node_modules/bs-platform/', ".;") . s:rescript_arch

"if !exists("g:rescript_compile_exe")
let g:rescript_compile_exe = l:res_bin_dir . "/bsc.exe"
let g:rescript_compile_exe = getcwd() . "/" . l:res_bin_dir . "/bsc.exe"
"endif

"if !exists("g:rescript_build_exe")
let g:rescript_build_exe = l:res_bin_dir . "/bsb.exe"
let g:rescript_build_exe = getcwd() . "/" . l:res_bin_dir . "/bsb.exe"
"endif

" Note that this doesn't find bsconfig when the editor was started without a
" specific file within the project
let g:rescript_project_config = findfile("bsconfig.json", ".;")
let g:rescript_project_config = getcwd() . "/" . findfile("bsconfig.json", ".;")

" Try to find the nearest .git folder instead
if g:rescript_project_config == ""
Expand All @@ -48,7 +48,7 @@ function! rescript#UpdateProjectEnv()
endif

" Make sure that our local working directory is in the rescript_project_root
exe "lcd " . g:rescript_project_root
"exe "lcd " . g:rescript_project_root
endfunction

" Inits the plugin variables, e.g. finding all the plugin related binaries
Expand Down Expand Up @@ -93,7 +93,9 @@ function! rescript#DetectVersion()
call rescript#UpdateProjectEnv()
let l:command = g:rescript_compile_exe . " -version"

exe "lcd " . g:rescript_project_root
silent let l:output = system(l:command)
exe "lcd -"

let l:version_list = matchlist(l:output, '.* \([0-9]\+\.[0-9]\+\.[0-9]\+.*\) (.*')

Expand Down Expand Up @@ -134,7 +136,9 @@ function! rescript#Format()
" bsc -format myFile.res > tempfile
let l:command = g:rescript_compile_exe . " -color never -format " . l:tmpname . " 2> " . l:stderr_tmpname

exe "lcd " . g:rescript_project_root
silent let l:out = systemlist(l:command)
exe "lcd -"

let l:stderr = readfile(l:stderr_tmpname)

Expand Down Expand Up @@ -398,7 +402,9 @@ function! rescript#BuildProject(...)
let l:cmd = g:rescript_build_exe . " " . a:1
endif

exe "lcd " . g:rescript_project_root
let out = system(l:cmd)
exe "lcd -"

" We don't rely too heavily on exit codes. If there's a compiler.log,
" then there is either an error or a warning, so we rely on the existence
Expand Down Expand Up @@ -493,7 +499,6 @@ function! rescript#ReasonToRescript()
endif
endfunction


function! rescript#Info()
let l:version = "ReScript version: " . rescript#DetectVersion()

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/compiler/compiler-log.exp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/Users/ryyppy/Projects/reason-association/vim-rescript/src/foo.res:12:6 -> [E] (Syntax) Did you forget a `=` here?
/Users/rescript/Projects/vim-rescript/src/foo.res:12:6 -> [E] (Syntax) Did you forget a `=` here?
/Users/rescript/Projects/vim-rescript/src/Text.res:47:11 -> [W] (Warning 20) deprecated: Pervasives.string_of_float Please use something else, otherwise we can't do much about it
/Users/rescript/Projects/vim-rescript/src/Button.res:50:58 -> [E] This has type: list<t> Somewhere wanted: string => int
/Users/rescript/Projects/vim-rescript/src/Json.res:20:11 -> [W] (Warning 3) deprecated: Pervasives.string_of_float Please use Js.Float.toString instead, string_of_float generates unparseable floats
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/compiler/compiler-log.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#Start(1402242571131)

Syntax error!
/Users/ryyppy/Projects/reason-association/vim-rescript/src/foo.res:12:6
/Users/rescript/Projects/vim-rescript/src/foo.res:12:6

10 │ let f = "test"
11 │
Expand Down
4 changes: 2 additions & 2 deletions test/test_all.vim
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ function! InitTest()
let l:platform = "linux"
endif

call assert_equal("node_modules/bs-platform/" . l:platform . "/bsc.exe", g:rescript_compile_exe)
call assert_equal("node_modules/bs-platform/" . l:platform . "/bsb.exe", g:rescript_build_exe)
call assert_equal(getcwd() . "/node_modules/bs-platform/" . l:platform . "/bsc.exe", g:rescript_compile_exe)
call assert_equal(getcwd() . "/node_modules/bs-platform/" . l:platform . "/bsb.exe", g:rescript_build_exe)
endfunction

function FormatErrorTest(fixtureName,...)
Expand Down