hsdev icon indicating copy to clipboard operation
hsdev copied to clipboard

Limitations for spawning hsdev servers

Open carymrobbins opened this issue 5 years ago • 5 comments

Can a single hsdev server be used for scanning multiple projects? Or do you need to spawn a separate hsdev server for each project? In my case, I have one mega stack project (with a single stack.yaml file) with a ton of sub-projects, each with various dependencies on one another.

For context: I seem to get weird state issues, where I add a module to project A, then I work on project B, which depends on A, and hsdev can't see the newly added module. Also it seems to get confused about which language extensions are enabled (it would alternate between telling me that I needed to enable LambdaCase (which was already enabled in the package.yaml) and telling me the "real" compiler errors, like 'symbol not found').

carymrobbins avatar Dec 05 '19 17:12 carymrobbins

Bump, mostly curious about the answer to this question -

Can a single hsdev server be used for scanning multiple projects? Or do you need to spawn a separate hsdev server for each project?

I'm fine if this is a limitation for now. Trying to see how well this works in HaskForce.

carymrobbins avatar Dec 17 '19 00:12 carymrobbins

Hi! It can be used to scan several projects, but as far as i remember source project will depend only on installed packages, i.e.

If you have project projects/A and projects/B, and also you have B installed, then projects/A will depend on B instead of projects/B. This, of course, can be fixed, as long as after scanning both projects hsdev will have all necessary info in db.

Normally if you have two projects, building projects/A will not cause projects/B to be rebuilt and so new functions won't be visible until you build it.

mvoidex avatar Dec 17 '19 07:12 mvoidex

Let's consider the following project - https://github.com/Simspace/servant-websockets

There are five packages in the directories core, client, server, examples, and test. If I have my IDE spin up an hsdev server, can I just rely on scan and check to "just work" regardless of the source file I'm working in? Do I need to go ahead and pre-scan all of the package sources at one time? Or do I need to spin up 5 separate servers, each scaning and checking their respective package sources?

It's also tough to know how scoping works with the other commands, e.g. if I'm working in file, let's say in the core package, how do I know what modules are available for import? The module command seems to give me everything, including things not depended on by core, and I'm not sure how to scope it for core explicitly.

carymrobbins avatar Dec 17 '19 09:12 carymrobbins

I've cloned repo and played around. Scanning all packages

hsdev scan project core --stack
hsdev scan project client --stack
...

and then asking for completions etc works ok, but if you modify sources in, for example, API.hs and Client.hs, something definitely goes wrong, so I have to dive into find out what's going on. As I can see in logs, hsdev passes correct flags to ghc, but check fails. Thanks for reporting issue.

To get visible modules, use hsdev scope modules -f core/src/Servant/WebSocket.hs/API.hs. It will return modules, that can be imported.

mvoidex avatar Dec 17 '19 21:12 mvoidex

I've found at least two bugs:

Consider multiproject with projects pkg1 with Module1 and pkg2 with Module2, where Module2 imports Module1 and uses var1 from it.

Then rename var1 to var100 and stack build multiproject:

  1. hsdev reloads info about installed packages, but it doesn't update imports refs and scope symbols of dependent source files. I.e. Module2.hs won't see this update.
  2. hsdev doesn't restart ghc session and thus check will use old compiled library and return errors.

I'll try to find time to fix on weekend.

Another issue is that hsdev doesn't know anything about multiprojects and thus internally pkg2s Module2.hs may depend only on installed pkg1 instead of source. This, of course, may be improved.

mvoidex avatar Dec 18 '19 13:12 mvoidex