Skip to content

Commit 297dc7b

Browse files
authored
Merge pull request #32 from rescript-lang/fix-cwd
Fix cwd
2 parents 4f88784 + 59823ef commit 297dc7b

5 files changed

Lines changed: 18 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## master
44

5+
**Bugfixes:**
6+
7+
- Fix an issue that causes the plugin to change cwd (e.g. in a monorepo setup)
8+
59
## 1.3.0
610

711
**Improvements:**

autoload/rescript.vim

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ function! rescript#UpdateProjectEnv()
2929
let l:res_bin_dir = finddir('node_modules/bs-platform/', ".;") . s:rescript_arch
3030

3131
"if !exists("g:rescript_compile_exe")
32-
let g:rescript_compile_exe = l:res_bin_dir . "/bsc.exe"
32+
let g:rescript_compile_exe = getcwd() . "/" . l:res_bin_dir . "/bsc.exe"
3333
"endif
3434

3535
"if !exists("g:rescript_build_exe")
36-
let g:rescript_build_exe = l:res_bin_dir . "/bsb.exe"
36+
let g:rescript_build_exe = getcwd() . "/" . l:res_bin_dir . "/bsb.exe"
3737
"endif
3838

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

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

5050
" Make sure that our local working directory is in the rescript_project_root
51-
exe "lcd " . g:rescript_project_root
51+
"exe "lcd " . g:rescript_project_root
5252
endfunction
5353

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

96+
exe "lcd " . g:rescript_project_root
9697
silent let l:output = system(l:command)
98+
exe "lcd -"
9799

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

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

139+
exe "lcd " . g:rescript_project_root
137140
silent let l:out = systemlist(l:command)
141+
exe "lcd -"
138142

139143
let l:stderr = readfile(l:stderr_tmpname)
140144

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

405+
exe "lcd " . g:rescript_project_root
401406
let out = system(l:cmd)
407+
exe "lcd -"
402408

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

496-
497502
function! rescript#Info()
498503
let l:version = "ReScript version: " . rescript#DetectVersion()
499504

test/fixtures/compiler/compiler-log.exp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/Users/ryyppy/Projects/reason-association/vim-rescript/src/foo.res:12:6 -> [E] (Syntax) Did you forget a `=` here?
1+
/Users/rescript/Projects/vim-rescript/src/foo.res:12:6 -> [E] (Syntax) Did you forget a `=` here?
22
/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
33
/Users/rescript/Projects/vim-rescript/src/Button.res:50:58 -> [E] This has type: list<t> Somewhere wanted: string => int
44
/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

test/fixtures/compiler/compiler-log.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#Start(1402242571131)
22

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

66
10 │ let f = "test"
77
11 │

test/test_all.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ function! InitTest()
3838
let l:platform = "linux"
3939
endif
4040

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

4545
function FormatErrorTest(fixtureName,...)

0 commit comments

Comments
 (0)