Skip to content
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

"No root directory found" #334

Open
RogerTarani opened this issue Sep 28, 2019 · 13 comments
Open

"No root directory found" #334

RogerTarani opened this issue Sep 28, 2019 · 13 comments

Comments

@RogerTarani
Copy link

RogerTarani commented Sep 28, 2019

The Ocaml syntax is supported but I continuously get "No root directory found" when I save a .ml file.
I see that there is no node_modules/ directory. I just created a directory, "added it to workspace" and "saved workspace as".
Can you give a hint about how to use (ocaml)reason-language-server the right way?

Is there a feature that generates the .merlin files without using Dune build tool (that generates them)?

Also, how do you enable the indentation feature? (ocp-indent)

Thanks

Version: 1.38.1
Commit: b37e54c98e1a74ba89e03073e5a3761284e3ffb0
Date: 2019-09-11T13:30:08.229Z
Electron: 4.2.10
Chrome: 69.0.3497.128
Node.js: 10.11.0
V8: 6.9.427.31-electron.0
OS: Linux x64 4.19.0-5-amd64

@atombender
Copy link

I'm getting this, too. Happens with new, empty OCaml project with just one .ml file.

@RogerTarani
Copy link
Author

It happens even if create 2 or 3 .ml files.

I see a function getPackage L525 of Packages.re that seems to trigger that message "No root directory found" on L 529.
I see a function reportDiagnostics L15 of NotificationHandlers.re talking about BuildFailed or BuildSucceeded.

What is happening is unclear to me. I can say that Hashtbl.mem(state.rootForUri, uri) is false

type state is defined here: TopTypes.re

rootForUri is defined her: TestUtils.re

What do you think about that code?

BTW, is there an reason2ocaml converter? I chose OCaml for its conciseness and little number of brackets/curly braces/parens, and this bunch of reason curly braces and parens is making me sick!
ocamlformat should do the job but I had a compilation error with ocamlformat_reason.~dev

@atombender
Copy link

atombender commented Sep 30, 2019

I got a little further by creating a dune-project file containing just the line (lang dune 1.1). Now it no longer complains about "No root directory".

But now I got this error error instead:

Unable to read .../ocamlfun/jbuild

I created an empty file by that name (even though Dune says it's deprecated file), and the error went away.

Instead, I now get:

Could not run compiler (ran /Users/alex/.opam/4.07.1/bin/ocamlopt.opt -version)

I have an ~/.opam, but I don't have ~/.opam/4.07.1. Why does the extension expect this to exist? I have OCaml installed via HomeBrew:

$ which ocamlopt.opt
/usr/local/bin/ocamlopt.opt

$ $ ls -l $(which ocamlopt.opt)
lrwxr-xr-x 1 alex admin 39 Dec 18  2018 /usr/local/bin/ocamlopt.opt -> ../Cellar/ocaml/4.07.1/bin/ocamlopt.opt

So I did ln -sf /usr/local/Cellar/ocaml/4.07.1 ~/.opam/4.07.1, and now the extension crashes with:

Fatal error: exception Invalid_argument("Filename.chop_extension")
Raised at file "stdlib.ml", line 34, characters 20-45
Called from file "src/analyze/FindFiles.re", line 122, characters 19-66
Called from file "src/analyze/State.re", line 225, characters 88-111
Called from file "src/lsp/Diagnostics.re", line 43, characters 27-75
Called from file "src/lsp/Diagnostics.re", line 81, characters 25-62
Called from file "hashtbl.ml", line 317, characters 23-40
Called from file "hashtbl.ml", line 324, characters 14-35
Re-raised at file "hashtbl.ml", line 330, characters 4-13
Called from file "src/lsp/Diagnostics.re", line 78, characters 16-414
Called from file "src/lsp/BasicServer.re", line 105, characters 16-27
Called from file "src/lsp/Main.re", line 314, characters 6-255
Called from file "bin/Bin.re", line 3, characters 9-24
[Info  - 12:57:05 AM] Connection to server got closed. Server will restart.

I restarted my VSCode window and, for kicks, deleted jbuild, and I no longer see that error. Now instead I see this error:

[Error - 12:59:11 AM] Request textDocument/documentSymbol failed.
  Message: bs-platform could not be found
  Code: -32603 

I had no idea what bs-platform was, but apparently it's an NPM module. So I did npm i bs-platform (even though this isn't a JavaScript project) and now I no longer get that error.

(Now VSCode says Extensions have been modified on disk. Please reload the window. which is odd, but I did it, and the message went away.)

Now I don't get any extension errors, at least not yet... However, I do get errors about unbound modules, even though my file compiles fine and the module is declared in dune.

Why is this so difficult?

(I tried to get formatting to work. I select the VSCode command "Format document with..." and select reason-vscode, and the extension now logs Cannot refmt ocaml yet. Doesn't ocamlformat exist? This is like 75% of why I wanted to install an extension!)

I'm also a little unnerved by the fact that the extension creates a node_modules folder under my project's root, and starts writing to the file <root>/node_modules/.lsp/debug.log. Why is this? I don't want a node_modules folder.

@RogerTarani
Copy link
Author

I'm also a little unnerved by the fact that the extension creates a node_modules folder under my project's root, and starts writing to the file /node_modules/.lsp/debug.log. Why is this? I don't want a node_modules folder.

One of my files tree has node_modules/.lsp/debug.log
Another one hasn't.
I don't really know why.

I didn't find any documentation.
So, before @jaredly can help us, one way would be to analyze how this program works.

@strdr4605
Copy link

strdr4605 commented Oct 3, 2019

Same issue when creating a new project with

bsb -init test-project -theme basic-reason

Actual error

/test-project/node_modules/.lsp/debug.log
[Error - 8:21:35 PM] Request textDocument/documentSymbol failed.
  Message: No root directory found
  Code: -32603 
[Error - 8:21:35 PM] Request textDocument/codeAction failed.
  Message: No root directory found
  Code: -32603 

autocompletion and suggestions do not work

@Coobaha
Copy link

Coobaha commented Oct 26, 2019

Same issue for folders starting with @.

@smorimoto
Copy link

Related issue: #177

@tgrecojs
Copy link

for what it's worth, i'm pretty sure that this issue blew up after upgrading to a newer version of npm. I had received this error in the past when trying to work with sample projects that had been built using previous versions of bucklescript, whereas my global bsb is linked to the lastest release.

@kittipatv
Copy link

kittipatv commented Dec 23, 2019

Instead, I now get:

Could not run compiler (ran /Users/alex/.opam/4.07.1/bin/ocamlopt.opt -version)

I have an ~/.opam, but I don't have ~/.opam/4.07.1. Why does the extension expect this to exist? I have OCaml installed via HomeBrew:

$ which ocamlopt.opt
/usr/local/bin/ocamlopt.opt

$ $ ls -l $(which ocamlopt.opt)
lrwxr-xr-x 1 alex admin 39 Dec 18  2018 /usr/local/bin/ocamlopt.opt -> ../Cellar/ocaml/4.07.1/bin/ocamlopt.opt

So I did ln -sf /usr/local/Cellar/ocaml/4.07.1 ~/.opam/4.07.1, and now the extension crashes with:

edit: opam switch create 4.08.1 will solve the compiler issue.

Don't do this: I did ln -s /usr/local/bin/ocamlopt.opt ~/.opam/default/bin/ocamlopt.opt instead. It works mostly as far as I can tell.

I still get Unable to find project root dir when looking up Core library installed via OPAM though.

For code formatting, I use OCaml Formatter

@atmichalak
Copy link

I'm having this same issue, VSCode extension fails to find a root directory when I created a new directory. Am I doing something wrong in regards to using Dune? Does Dune require you to essentially mkdir using Dune itself like cargo new in Rust?

@abhijat
Copy link

abhijat commented Feb 29, 2020

I have this same issue but since I was using dune, I created a minimal dune build definition and executed dune build foo.exe and autocomplete works starts working.

It seems looking at findRoot at

let findRoot = (uri, packagesByRoot, overrides) => {
it looks for project definitions or a .merlin file while walking up the directory tree, terminating at /.

dune build generates a .merlin file so things start to work. Unfortunately a dune clean again results in the same error because it removes .merlin, but I can just run dune build for regenerating the file.

@jplew
Copy link
Contributor

jplew commented Apr 21, 2020

as @abhijat mentioned, that findRoot function is looking for a bsconfig.json, a dune directory, or a .merlin file in the current directory.
I added a basic bsconfig.json file, ran the bsb command, and it removed the error message.

@addamove
Copy link

as @abhijat mentioned, that findRoot function is looking for a bsconfig.json, a dune directory, or a .merlin file in the current directory.
I added a basic bsconfig.json file, ran the bsb command, and it removed the error message.

This works!

@atombender
I feel your pain, yesterday I did all the same and I didn't found this thread :/
I ended just using old depreciated Ocaml vscode extension and it jsut works if you add .merlin file. Wish everything was fine with this extension or at least @jplew advice was at readme.md.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests