From 48d6a735573664230c70ec2bb93493dfb9cba0f0 Mon Sep 17 00:00:00 2001 From: Patrick Stapfer Date: Mon, 22 Feb 2021 09:25:30 +0100 Subject: [PATCH 1/3] After lcd, always set back to the previous cwd after executing a command Also don't lcd on ProjectEnvUpdate. --- autoload/rescript.vim | 15 ++++++++++----- test/test_all.vim | 4 ++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/autoload/rescript.vim b/autoload/rescript.vim index 14ce88a..bee512b 100644 --- a/autoload/rescript.vim +++ b/autoload/rescript.vim @@ -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 == "" @@ -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 @@ -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]\+.*\) (.*') @@ -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) @@ -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 @@ -493,7 +499,6 @@ function! rescript#ReasonToRescript() endif endfunction - function! rescript#Info() let l:version = "ReScript version: " . rescript#DetectVersion() diff --git a/test/test_all.vim b/test/test_all.vim index 94142b0..3e18353 100644 --- a/test/test_all.vim +++ b/test/test_all.vim @@ -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,...) From f187c255bf0f45fc25991a819118784ab5ac2001 Mon Sep 17 00:00:00 2001 From: Patrick Stapfer Date: Mon, 22 Feb 2021 09:26:35 +0100 Subject: [PATCH 2/3] Refine test fixtures for compiler-log --- test/fixtures/compiler/compiler-log.exp | 2 +- test/fixtures/compiler/compiler-log.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/fixtures/compiler/compiler-log.exp b/test/fixtures/compiler/compiler-log.exp index f4d4c56..771f065 100644 --- a/test/fixtures/compiler/compiler-log.exp +++ b/test/fixtures/compiler/compiler-log.exp @@ -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 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 diff --git a/test/fixtures/compiler/compiler-log.txt b/test/fixtures/compiler/compiler-log.txt index 2f4d400..6f57613 100644 --- a/test/fixtures/compiler/compiler-log.txt +++ b/test/fixtures/compiler/compiler-log.txt @@ -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 │ From 59823ef9ef755e17595a100c74c5f05ee98aa243 Mon Sep 17 00:00:00 2001 From: Patrick Stapfer Date: Fri, 2 Apr 2021 17:01:26 +0200 Subject: [PATCH 3/3] Update Changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a80fce0..8b12991 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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:**