Skip to content
This repository was archived by the owner on Nov 18, 2022. It is now read-only.

Handle cases when the outer workspace is not a rust project #419

Open
samrg472 opened this issue Sep 4, 2018 · 9 comments
Open

Handle cases when the outer workspace is not a rust project #419

samrg472 opened this issue Sep 4, 2018 · 9 comments
Labels
enhancement Indicates new feature requests P-High rls Issue related to the RLS itself rather than the extension

Comments

@samrg472
Copy link

samrg472 commented Sep 4, 2018

I'm using Neon to create a NodeJS native module with Rust. The project layout consists of an npm project as the root and a subfolder "native" that has the rust project.

In VSCode I create a workspace with 2 folders:

  • neon-js/
  • neon-js/native

The function getOuterMostWorkspaceFolder presents an issue because the outer most folder is not a rust project.
https://github.com/rust-lang-nursery/rls-vscode/blob/096974566afe1ab34ae0f868c7dd6a127f41b059/src/extension.ts#L85-L97

I resolved this problem locally by checking if the outer most folder is a rust project. I'm not sure if this will cause problems with something else or if there's a better way, but this solution is working for me.

diff --git a/src/extension.ts b/src/extension.ts
--- a/src/extension.ts
+++ b/src/extension.ts
@@ -90,7 +90,13 @@ function getOuterMostWorkspaceFolder(folder: WorkspaceFolder): WorkspaceFolder {
             uri = uri + '/';
         }
         if (uri.startsWith(element)) {
-            return workspace.getWorkspaceFolder(Uri.parse(element)) || folder;
+            const ws = workspace.getWorkspaceFolder(Uri.parse(element)) || folder;
+            for (const f of fs.readdirSync(ws.uri.fsPath)) {
+                if (f === 'Cargo.toml') {
+                    return ws;
+                }
+            }
+            return folder;
         }
     }
     return folder;
@Aidiakapi
Copy link
Contributor

A similar usage scenario for this is with WebAssembly. The template project for this scenario (https://github.com/rustwasm/rust-webpack-template) also sets it up so a workspace root will be the webpack project, and the Rust project is stored under ./crate.

I will give the proposed diff a try.

@tim-stasse
Copy link

Any progress on this issue? Currently running into the same thing when using the rust-webpack-template and opening the root project folder, I instead have to open the ./crate folder separately.

I'm new to rust/WebAssembly and the whole ecosystem, but I'm loving it so far, and this extension goes a long way to making the transition nice and smooth, if this could be fixed, that'd be amazing.

Thanks.

@petkahl
Copy link

petkahl commented Dec 4, 2018

It seems like this is a duplicate of #222 which has a PR filed recently, but hasn't been merged.

@joepie91
Copy link

The mentioned PR in #222 has been merged, but I'm still running into this issue with a Neon project; the error message is slightly different for me than the one in #222, though:

selection_936

This occurs in a blank new Neon project, created with neon-cli 0.20. The folder structure is as follows:

selection_937

@Xanewok Xanewok added enhancement Indicates new feature requests P-High rls Issue related to the RLS itself rather than the extension labels Apr 7, 2019
@Xanewok
Copy link
Member

Xanewok commented Apr 7, 2019

This is high on the feature list of the RLS and ties into improving our project layout detection story. More of this is tracked in the RLS repository.

@snuk182
Copy link

snuk182 commented Oct 7, 2019

Is this the RLS repo story you mention?
rust-lang/rls#1202

@jli
Copy link

jli commented Apr 12, 2020

I believe this has been fixed by #638, which was merged on 2019-09-18 and included in release 0.7.0 on 2019-10-15.

Note that you need to explicitly set rust-client.enableMultiProjectSetup to true, however.

@jli
Copy link

jli commented Apr 12, 2020

Hm, after setting enableMultiProjectSetup, I no longer get the warning notification, and everything appears to be working (code warnings, go to definition, etc), except that the "build" and "check" tasks aren't working.

My workspace directory structure has root project folder with a "rust-dir" subdirectory:

project-root
|- rust-dir
|- rust-dir/src
|- rust-dir/Cargo.toml

When I do alt+shift+b and select the Rust: cargo build task, I see the following error in the terminal:

> Executing task in folder rust-learning: cargo build <

error: could not find Cargo.toml in /Users/me/src/project-root or any parent directory
The terminal process terminated with exit code: 101

I get the same error with the cargo check task as well.

@jannickj
Copy link
Contributor

@jli it should work in: #759

I tested it locally and it worked fine.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Indicates new feature requests P-High rls Issue related to the RLS itself rather than the extension
Projects
None yet
Development

No branches or pull requests

9 participants