Skip to content

Tweak project root heuristics #29

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

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Tweak heuristics to find the project root.
The project root means "this is a folder containing node_modules/bs-platform/{platform}/bsc.exe".
This path needs to be correct because it drives the formatter.

The previous heuristics seemed to fail in the case users where using yarn workspaces.
Yarn workspaces seem to have the following layout:
```
/root
  /node_modules
  - package.json
  - yarn.lock
  /folder1
    /node_modules
    - package.json
    - bsconfig.json
```

The compiler seems to be located in the `node_modules` under the root and not in the `node_modules` of `folder1`.
By searching for `bscPartialPath` instead of the nearest `bsconfig.json`,
we can correctly determine the root.
  • Loading branch information
Iwan authored and BlueHotDog committed Dec 16, 2020
commit 44911a3937941596ed675c9b89e1eea9fd915e72
2 changes: 1 addition & 1 deletion server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ process.on("message", (msg: m.Message) => {
if (projectRootPath == null) {
let params: p.ShowMessageParams = {
type: p.MessageType.Error,
message: `Cannot find a nearby ${c.bsconfigPartialPath}. It's needed for determining the project's root.`,
message: `Cannot find a nearby ${c.bscPartialPath}. It's needed for determining the project's root.`,
};
let response: m.NotificationMessage = {
jsonrpc: c.jsonrpcVersion,
Expand Down
2 changes: 1 addition & 1 deletion server/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export let findProjectRootOfFile = (
source: p.DocumentUri
): null | p.DocumentUri => {
let dir = path.dirname(source);
if (fs.existsSync(path.join(dir, c.bsconfigPartialPath))) {
if (fs.existsSync(path.join(dir, c.bscPartialPath))) {
return dir;
} else {
if (dir === source) {
Expand Down