jaredly / reason-language-server

A language server for reason, in reason
MIT License
659 stars 84 forks source link

Unknown error in vscode plugin #374

Open pszmagaj opened 4 years ago

pszmagaj commented 4 years ago

Hi,

I have got an unknown error when using vscode plugin.

Plugin version 1.7.4

bs-platform: 5.2.1 but also tried on 7.0.1 with the same effect.

bsconfig.json

{
  "name": "ProjectName",
  "sources": [
    {
      "dir": "src",
      "subdirs": true
    },
    {
      "dir": "__tests__",
      "subdirs": true,
      "type": "dev"
    }
  ],
  "package-specs": {
    "module": "commonjs",
    "in-source": true
  },
  "suffix": ".bs.js",
  "bs-dependencies": [
    "reason-react",
    "@glennsl/bs-json",
    "bs-webapi",
    "bs-fetch",
    "bs-moment",
    "reason-date-fns",
    "re-classnames",
    "reason-apollo",
    "reason-apollo-hooks",
    "re-debouncer",
    "bs-reform",
    "reschema"
  ],
  "bs-dev-dependencies": [
    "@glennsl/bs-jest",
    "bs-react-test-renderer"
  ],
  "ppx-flags": [
    "graphql_ppx/ppx",
    "lenses-ppx/ppx"
  ],
  "reason": {
    "react-jsx": 3
  },
  "refmt": 3,
  "generate-merlin": true,
  "warnings": {
    "number": "-45"
  }
}

The plugin doesn't work. It seems that it cannot compile the code but gets no error. I found in debug log only "type error here " but with no details.

... '/home/pawel/workspace/Leon/client/react/lib/bs/__tests__/src/components/DocumentsManager/List/__snapshots__' -I '/home/pawel/workspace/Leon/client/react/lib/bs/__tests__/src/components/DocumentsManager/Data' -I '/home/pawel/workspace/Leon/client/react/lib/bs/__tests__/src/components/DocumentsManager/Data/__snapshots__' -I '/home/pawel/workspace/Leon/client/react/lib/bs/__tests__/src/components/DocumentsManager/__snapshots__' -I '/home/pawel/workspace/Leon/client/react/node_modules/bs-platform/lib/ocaml' -I '/home/pawel/workspace/Leon/client/react/node_modules/reschema/lib/bs/src' -I '/home/pawel/workspace/Leon/client/react/node_modules/bs-reform/lib/bs' -I '/home/pawel/workspace/Leon/client/react/node_modules/bs-reform/lib/bs/src' -I '/home/pawel/workspace/Leon/client/react/node_modules/re-debouncer/lib/bs/src' -I '/home/pawel/workspace/Leon/client/react/node_modules/reason-apollo-hooks/lib/bs' -I '/home/pawel/workspace/Leon/client/react/node_modules/reason-apollo-hooks/lib/bs/src' -I '/home/pawel/workspace/Leon/client/react/node_modules/reason-apollo/lib/bs/src' -I '/home/pawel/workspace/Leon/client/react/node_modules/reason-apollo/lib/bs/src/graphql-types' -I '/home/pawel/workspace/Leon/client/react/node_modules/re-classnames/lib/bs/src' -I '/home/pawel/workspace/Leon/client/react/node_modules/reason-date-fns/lib/bs' -I '/home/pawel/workspace/Leon/client/react/node_modules/reason-date-fns/lib/bs/src' -I '/home/pawel/workspace/Leon/client/react/node_modules/bs-moment/lib/bs/src' -I '/home/pawel/workspace/Leon/client/react/node_modules/bs-fetch/lib/bs/src' -I '/home/pawel/workspace/Leon/client/react/node_modules/bs-webapi/lib/bs/src' -I '/home/pawel/workspace/Leon/client/react/node_modules/bs-webapi/lib/bs/src/Webapi' -I '/home/pawel/workspace/Leon/client/react/node_modules/bs-webapi/lib/bs/src/Webapi/Webapi__Canvas' -I '/home/pawel/workspace/Leon/client/react/node_modules/bs-webapi/lib/bs/src/Webapi/Webapi__Dom' -I '/home/pawel/workspace/Leon/client/react/node_modules/@glennsl/bs-json/lib/bs/src' -I '/home/pawel/workspace/Leon/client/react/node_modules/reason-react/lib/bs/src' -I '/home/pawel/workspace/Leon/client/react/node_modules/bs-react-test-renderer/lib/bs/src' -I '/home/pawel/workspace/Leon/client/react/node_modules/@glennsl/bs-jest/lib/bs/src' -I '/home/pawel/workspace/Leon/client/react/node_modules/bs-platform/lib/ocaml' -bin-annot -bs-no-builtin-ppx-ml -ppx '/home/pawel/workspace/Leon/client/react/node_modules/graphql_ppx/ppx' -ppx '/home/pawel/workspace/Leon/client/react/node_modules/lenses-ppx/ppx' -ppx '/home/pawel/workspace/Leon/client/react/node_modules/bs-platform/lib/bsppx.exe -bs-jsx 3' -nostdlib -w -30-40+6+7+27+32..39+44+45+101-45 -bs-re-out -impl /home/pawel/workspace/Leon/client/react/node_modules/.lsp/LeonAccountModulesServiceCoder.ast with pwd /home/pawel/workspace/Leon/client/react
type error here

Or something like below (many times for multiple different modules)

<< Making lastDefinitions with type error for file:///home/pawel/workspace/Leon/client/react/__tests__/src/components/Eapis/EapisPersonsTableRow_test.re
type error here 

The project builds and works when compiling by using npx bsb -make-world Any ideas what it can be?

jaredly commented 4 years ago

@pszmagaj any chance you could make a public example repo so I can investigate?

pszmagaj commented 4 years ago

@jaredly I cannot share the repo but I can try to create a new project with the same dependencies to reproduce the problem. I may also try to debug the issue by myself but I would need some advice on how it can be done.

a-gierczak commented 4 years ago

@jaredly @pszmagaj I think I've managed to track down the issue. In our project we have two source directories listed in bsconfig.json.

"sources": [
    {
      "dir": "src",
      "subdirs": true
    },
    {
      "dir": "__tests__",
      "subdirs": true,
      "type": "dev"
    }
  ],

When I remove one of them, the plugin works again. I will try to create minimal reproducible example later.

Edit: After further investigation I've noticed that it's more related to number of directories, not sources. I created empty project with 2 files and 2600 empty directories and RLS stopped working. With 2400 directories it was still doing fine.

cristianoc commented 4 years ago

Similar issue in spirit (integration wit bsb): https://github.com/jaredly/reason-language-server/issues/414

IwanKaramazow commented 4 years ago

@selenir do you have a repo with that test?

a-gierczak commented 4 years ago

There it is: https://github.com/selenir/rls-374-repro

a-gierczak commented 4 years ago

I've managed to reproduce the issue on Windows 10, there are some logs in the "Output" tab, which didn't appear on Linux: https://gist.github.com/selenir/371e3b357a662e4f737ed4364ac80734

Also while checking logs I've noticed that each directory in project is passed as -I paramter to bsc. Maybe it could be related to max command length in cmd/bash.

pszmagaj commented 4 years ago

@jaredly Hello. I have investigated a problem and it seems to be linux / ubuntu specific problem. The problem can be recreated using https://github.com/selenir/rls-374-repro. It seems that bsc exits 127 code when run by RLS. The command that RLS uses to compile the project works perfectly when run from command line.

The repro repo causes a problem on Windows and WSL as well however it seems that the cause is different.

[Edit] I think the problem may be related to MAX_ARG_STRLEN which is 32 * PAGE_SIZE (4KB). When command goes below 128kB it starts working. I do not know how to resolve the problem without recompiling the kernel. Perhaps bsc could take arguments from a file?

pszmagaj commented 4 years ago

I can see that OCaml compiler has "args" option (http://caml.inria.fr/pub/docs/manual-ocaml/comp.html#s%3Acomp-options). According to https://bucklescript.github.io/docs/en/extended-compiler-options BSC should inherit options from OCAML compiler but I cannot see args option in BSC.

@bobzhang Perhaps you can help us with that? Can BSC expose "-args" OCAML compiler option?

jazithedev commented 4 years ago

Can some1 fix this in the reason-language-server :)?

bobzhang commented 4 years ago

@pszmagaj Any idea why the command line is that long? 128KB seems a lot

a-gierczak commented 4 years ago

@bobzhang It's because BSB passes paths of all subdirectories in the project to the compiler. You can easily reach the 128KB mark when you have bigger project.

pszmagaj commented 4 years ago

@bobzhang I confirm. The project is really big. We have hundreds of Reason and JS modules in a project what makes compiler command very long (~150kB).

bobzhang commented 4 years ago

@pszmagaj I guess you meant hundreds of directories?

pszmagaj commented 4 years ago

@bobzhang Yes. There are hundreds directories.