Skip to content

Conversation

doorgan
Copy link
Collaborator

@doorgan doorgan commented May 28, 2025

This adds support for multiple projects within the server node, and starts a project node for each detected project within the workspace. The detection implemented here is just using the presence of a mix.exs file to assume it's a project root.

It also changes the manager node to use the name of the workspace folder instead of the name of the first project that starts distribution. The reason is that if you have projects a and b in the same root folder foo, and you start Expert on the root folder, then the manager node will be named after the first project node that is started. Running epmd -names shows this:

  • project-a-entropy
  • project-b-entropy
  • manager-a-entropy

I htink having the manager be named manager-foo-entropy sounds more correct.

To test this branch you can clone this repo: https://github.com/doorgan/monorepo_test
Then check on files from both main and secondary that:

  • Completions work
  • Go to definition and workspace symbols work
  • Code actions (like Refactorex refactors) work
  • Instructing the LSP to reindex everything runs the indexer on all projects

Additionally you can also test that Lexical works on .exs or .ex files in a workspace without a mix.exs file.

It is worth noting that this should be tested with VS Code using the Lexical LSP extension and pointing it to an expert release using this branch, or some other editor (like emacs) that doesn't automatically start a new Expert server(ie something other than Neovim)

@doorgan doorgan force-pushed the doorgan/multiroot_support branch 2 times, most recently from 328d567 to 63af087 Compare May 28, 2025 19:22
@doorgan doorgan force-pushed the doorgan/multiroot_support branch from be99c6d to 96a16cd Compare June 20, 2025 22:56
doorgan added 5 commits June 23, 2025 15:50
This adds support for multiple projects within the server node,
and starts a project node for each detected project within the
workspace.

It also changes the manager node to use the name of the workspace
folder instead of the name of the first project that starts
distribution.
@doorgan doorgan force-pushed the doorgan/multiroot_support branch from 2c69620 to c0c879a Compare June 23, 2025 18:57
@doorgan doorgan changed the title Support multiple root projects feat: support multiple root projects Jul 4, 2025
Copy link
Member

@mhanberg mhanberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you able to add tests that validate adding and removing workspace folders?

Otherwise looks good, just change the PR title to say "feat: workspace folders"

@doorgan doorgan changed the title feat: support multiple root projects feat: workspace folders Jul 9, 2025
@doorgan doorgan force-pushed the doorgan/multiroot_support branch from a423e25 to 90ab70a Compare July 9, 2025 20:50
@doorgan
Copy link
Collaborator Author

doorgan commented Jul 9, 2025

@mhanberg using GenLSP test helpers sometimes exunit will not terminate after running all tests(or sometimes it will run only a subset of the new tests), do you know if this may be related to the GenLSP helpers? Other tests that start project nodes like apps/expert/test/expert/engine_node_test.exs don't have this problem, so it seems unlikely the project node is what's causing this

@doorgan doorgan force-pushed the doorgan/multiroot_support branch from 13a9a77 to d6279f4 Compare July 9, 2025 21:17
@mhanberg
Copy link
Member

mhanberg commented Jul 9, 2025

@mhanberg using GenLSP test helpers sometimes exunit will not terminate after running all tests(or sometimes it will run only a subset of the new tests), do you know if this may be related to the GenLSP helpers? Other tests that start project nodes like apps/expert/test/expert/engine_node_test.exs don't have this problem, so it seems unlikely the project node is what's causing this

Not that I know of, but I'll pull it down and see what happens.

@mhanberg
Copy link
Member

@mhanberg using GenLSP test helpers sometimes exunit will not terminate after running all tests(or sometimes it will run only a subset of the new tests), do you know if this may be related to the GenLSP helpers? Other tests that start project nodes like apps/expert/test/expert/engine_node_test.exs don't have this problem, so it seems unlikely the project node is what's causing this

Not that I know of, but I'll pull it down and see what happens.

Sorry about the wait, but I pulled this down. The tests seem to just run as normal, except for one test failing of a code error.

@doorgan
Copy link
Collaborator Author

doorgan commented Jul 14, 2025

except for one test failing of a code error.

Can you share the error? Besides the issue I mentioned, all tests are green on my end

@mhanberg
Copy link
Member

except for one test failing of a code error.

Can you share the error? Besides the issue I mentioned, all tests are green on my end

The first couple of times i ran it, this was the failure

  1) test find references returns locations that the entity returns (Expert.Provider.Handlers.FindReferencesTest)
     test/expert/provider/handlers/find_references_test.exs:55
     ** (FunctionClauseError) no function clause matching in anonymous fn/4 in Expert.Provider.Handlers.FindReferencesTest."test find references returns locations that the entity returns"/1


     code: assert {:ok, [%Location{} = location]} = handle(request, project)
     stacktrace:
       (patch 0.15.0) lib/patch/mock/server.ex:81: Patch.Mock.Server.delegate/3
       (expert 0.7.2) lib/expert/provider/handlers/find_references.ex:25: Expert.Provider.Handlers.FindReferences.handle/2
       test/expert/provider/handlers/find_references_test.exs:72: (test)

But I just ran it again and a different test failed

  1) test opening files starts a project node when opening a file in a folder not specified as workspace folder (ExpertTest)
     test/expert/expert_test.exs:216
     Assertion with == failed
     code:  assert project.root_uri == secondary_project.root_uri
     left:  "file:///home/mitchell/src/expert/apps/forge/test/fixtures/workspace_folders/main"
     right: "file:///home/mitchell/src/expert/apps/forge/test/fixtures/workspace_folders/secondary"
     stacktrace:
       test/expert/expert_test.exs:263: (test)

@mhanberg
Copy link
Member

I think I just ran into the problem tho

@mhanberg
Copy link
Member

Something is definitely strange. Sometimes I'll run the test file and It'll only run a single test.
image

doorgan added 2 commits July 15, 2025 15:40
This test was failing because the context project's entropy did not match what the patched function received. Matching on the uri instead(which is what actually identifies the project) fixes the test.
@doorgan
Copy link
Collaborator Author

doorgan commented Jul 15, 2025

I think I fixed both issues. I'm still experiencing the issue where mix test won't always terminate after all tests run, but I'm not sure if something is wrong in my setup.

@doorgan doorgan force-pushed the doorgan/multiroot_support branch from 9df9074 to 04968a1 Compare August 21, 2025 02:04
@mhanberg
Copy link
Member

Are you still experiencing that weird tests don't end problem? CI seems to be passing.

@doorgan
Copy link
Collaborator Author

doorgan commented Aug 27, 2025

@mhanberg I'm not so I think we're good, I'm holding off a bit because @scohen seemed to be having some issues with this branch; I'm not yet sure if they were introduced by this pr or if they're preexisting

@mhanberg
Copy link
Member

@mhanberg I'm not so I think we're good, I'm holding off a bit because @scohen seemed to be having some issues with this branch; I'm not yet sure if they were introduced by this pr or if they're preexisting

It might be worth it to move the "multi root but not workspace folders" work to a different branch and merge in the actual workspace folders support

@doorgan
Copy link
Collaborator Author

doorgan commented Aug 28, 2025

@mhanberg I'm not sure, Steve reported that the project node would sometimes crash and that would happen regardless of the project node being spawned via workspace folders or some other way
I haven't been able to reproduce that issue though, not even after I installed Emacs on my machine

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

Successfully merging this pull request may close these issues.

2 participants