Skip to content

node_modules are not located correctly #45

Open

Description

@wokalski

For some reason finddir returns the full path on my system so getCwd() . finddir() causes the path to be /Users/user/path/to/project//Users/user/path/to/project/node_modules/.... I had to remove getCwd() calls from rescript#UpdateProjectEnv() and it all works. It's probably something about my setup but I cannot figure it out.

Activity

  1. ryyppy commented on Jul 6, 2021

    @ryyppy
    Member

    what vim / nvim version?

  2. leeN commented on Aug 20, 2021

    @leeN

    I have the same issue.

    Vim: 8.2
    Included patches: 1-2891

  3. rnmmnen commented on Feb 2, 2022

    @rnmmnen

    I've been running into an issue that looks very similar.

    I can reproduce it by simply cloning the official project template and changing the current working directory to src. Plugin no longer works.

    $ git clone https://github.com/rescript-lang/rescript-project-template.git
    $ cd rescript-project-template
    $ npm install
    $ vim src/Demo.src # Works
    $ cd src
    $ vim Demo.src # FAIL
    

    A bit more involved way to reproduce the problem is to create a monorepo setup with a single top-level node_modules and to change the current working directory to something more specific than the project root.

    Minimal setup using npm workspaces (requires a relatively recent version of npm):

    $ mkdir demo
    $ cd demo
    $ npm init --yes
    $ npm init --yes -w packages/mydemo
    $ npm install rescript --save -w packages/mydemo
    $ cat >packages/mydemo/bsconfig.json <<END
    {
      "name": "mydemo",
      "sources": [
        {
          "dir": "src",
          "subdirs": true
        }
      ],
      "package-specs": [
        {
          "module": "es6",
          "in-source": true
        }
      ],
      "suffix": ".bs.js",
      "bs-dependencies": []
    }
    END
    $ mkdir packages/mydemo/src
    $ echo 'Js.log("Hello, World!")' > packages/mydemo/src/Demo.res
    

    Reproduction using Apple's default vim:

    $ vim --version|head -n 1
    VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Nov 13 2021 05:04:57)
    $ vim packages/mydemo/src/Demo.res # Works
    $ (cd ..; vim demo/packages/mydemo/src/Demo.res) # Works
    $ (cd packages; vim mydemo/src/Demo.res) # FAIL
    $ (cd packages/mydemo; vim src/Demo.res) # FAIL
    $ (cd packages/mydemo/src; vim Demo.res) # FAIL
    

    Reproduction using latest Neovim:

    $ nvim --version|head -n 1
    NVIM v0.6.1
    $ nvim packages/mydemo/src/Demo.res # Works
    $ (cd ..; nvim demo/packages/mydemo/src/Demo.res) # Works
    $ (cd packages; nvim mydemo/src/Demo.res) # FAIL
    $ (cd packages/mydemo; nvim src/Demo.res) # FAIL
    $ (cd packages/mydemo/src; nvim Demo.res) # FAIL
    

    These changes fix the issue for me:

    diff --git a/autoload/rescript.vim b/autoload/rescript.vim
    index 14a7486..a3dcbc0 100644
    --- a/autoload/rescript.vim
    +++ b/autoload/rescript.vim
    @@ -38,16 +38,16 @@ function! rescript#UpdateProjectEnv()
       else
         " Here we are handling a project that is based on the rescript npm package
         " This package only uses a rescript.exe, no bsc, nor bsb
    -    let g:rescript_exe = getcwd() . "/" . l:res_bin_dir . "/rescript.exe"
    +    let g:rescript_exe = fnamemodify(l:res_bin_dir, ":p:h") . "/rescript.exe"
       endif
     
       " These variables are only used in legacy mode (bs-platform based projects)
    -  let g:rescript_bsc_exe = getcwd() . "/" . l:res_bin_dir . "/bsc.exe"
    -  let g:rescript_bsb_exe = getcwd() . "/" . l:res_bin_dir . "/bsb.exe"
    +  let g:rescript_bsc_exe = fnamemodify(l:res_bin_dir, ":p:h") . "/bsc.exe"
    +  let g:rescript_bsb_exe = fnamemodify(l:res_bin_dir, ":p:h") . "/bsb.exe"
     
       " Note that this doesn't find bsconfig when the editor was started without a
       " specific file within the project
    -  let g:rescript_project_config = getcwd() . "/" . findfile("bsconfig.json", ".;")
    +  let g:rescript_project_config = findfile("bsconfig.json", ".;")
     
       " Try to find the nearest .git folder instead
       if g:rescript_project_config == ""
    

    After applying the patch all working directories seem to work as expected (both in vim and in Neovim).

  4. rnmmnen commented on Feb 2, 2022

    @rnmmnen
    -    let g:rescript_exe = getcwd() . "/" . l:res_bin_dir . "/rescript.exe"
    +    let g:rescript_exe = fnamemodify(l:res_bin_dir, ":p:h") . "/rescript.exe"
       endif
     
       " These variables are only used in legacy mode (bs-platform based projects)
    -  let g:rescript_bsc_exe = getcwd() . "/" . l:res_bin_dir . "/bsc.exe"
    -  let g:rescript_bsb_exe = getcwd() . "/" . l:res_bin_dir . "/bsb.exe"
    +  let g:rescript_bsc_exe = fnamemodify(l:res_bin_dir, ":p:h") . "/bsc.exe"
    +  let g:rescript_bsb_exe = fnamemodify(l:res_bin_dir, ":p:h") . "/bsb.exe"
    

    …or one could modify the l:res_bin_dir variable before these lines to save some cycles. 😉

  5. rnmmnen commented on Feb 11, 2022

    @rnmmnen

    Okay, the changes above were just a partial fix.

    They fixed these:

    • rescript#Format (:RescriptFormat)
    • rescript#Clean (:RescriptClean and :RescriptCleanWithDeps)
    • rescript#Build (:RescriptBuild and :RescriptBuildWithDeps)
    • probably rescript#ReasonToRescript, too (:RescriptUpgradeFromReason)

    Didn't fix these:

    • rescript#TypeHint (:RescriptTypeHint)
    • rescript#JumpToDefinition (:RescriptJumpToDefinition)
    • rescript#Complete (omni completion).

    The latter three will call rescript-editor-analysis.exe. The detected path shown by :RescriptInfo remains correct but the returned data is just null whenever the current working directory is something more specific than project root. This can be demonstrated with the official project template just by running cd src and trying to use those commands.

  6. rnmmnen commented on Feb 11, 2022

    @rnmmnen

    As a side note, I noticed that the analysis exe returns null type hint when no type hint is available. This causes a nasty-looking error message which could be handled better.

  7. ryyppy commented on Feb 14, 2022

    @ryyppy
    Member

    Interesting 🤔

    Thanks for the instructions to reproduce this issue. Will try it myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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