hsdev
hsdev copied to clipboard
Request for hsdev light
Hereby my proposal.
Hsdev light API
Commands
Project files
| Function | Argument |
|---|---|
| Names of all modules which can be imported | target or file path |
| All top-level declarations | file path |
| All exported top-level declarations | file path |
| Info about identifier | location |
| Type of identifier | location |
| Type of selection | from location and to location |
| Location and module name of where identifier is defined | location |
| Check file | file path with ghc options and always clear |
Libraries
| Function | Argument |
|---|---|
| All exported top-level declarations | module name |
| Info about identifier | module name and name of identifier |
If you can offer more (detailed) info for library modules and identifiers it would be great!
location is file path, row and column.
target is stack target, stack ide targets
Remarks
- I assume the
scancommand always has to be run after startinghsdevserver but it would do only the minimal work to get the commands working. - Preloading or caching inside
hsdevis not necessary. - It has to be clear when client knows when to stop reading output from
hsdev. - The way how
hsdevcurrently works with starting server, opening socket connection and request/respond json objects is okay. - It would be nice if asking for info and definition locations also works inside import module declarations.
Questions:
- Is it possible to run multiple
hsdevprocesses on different ports? One for each IntelliJ project. - Are multi-package projects supported? If so, how does
scanhave to be executed? Only in project root or for each package? - About
scancommand. What do flagscabalandinfermean? How doesscanlook like forcabalprojects?
Remarks:
- What do you mean by caching? Does hsdev use it now? It uses sqlite as primary storage, not cache.
- It works
Questions:
- I think yes. While experimenting I'm often hold 2-3 hsdev processes.
- Probably not, as I haven't used such projects. Can you post some rtfm links? Is it stack's or cabal's feature?
inferdoesn't affect installed modules. In fact this flag now disabled, you can infer types for files or projects by separate commandinfer. Inferring all types for all source modules is too slow, if you have several projects scanned.
Remarks:
What do you mean by caching? Does hsdev use it now? It uses sqlite as primary storage, not cache.
I mean, get info by demand and do not everything upfront. For example, I noticed for example with Hledge project (https://github.com/simonmichael/hledger) that it can take very long time before scan is finished. And after that, the server did not always respond to client commands.
Questions
- It's a cabal and stack feature. For stack see https://docs.haskellstack.org/en/stable/GUIDE/#multi-package-projects. It are multiple cabal projects with one
stack.yamlorcabal.projectFor example: Hledger (https://github.com/simonmichael/hledger) , Servant(https://github.com/haskell-servant/servant) - So
inferis now disabled. What doescabaloption do?
It took 13 seconds to scan hledger with current version (not pushed yet).
SQLite defaults not good for inserting many rows.
Another source of slowdown may be asking stack path each time. Fixed too.
- Asks
hsdevto scan installed modules inglobal-dbanduser-db
It took 13 seconds to scan hledger with current version (not pushed yet).
Did you first build the complete project? In which directory did you run the scan command? In my case it was running for minutes with 4 GHC processes at 100% CPU. I also noticed that the hsdev process can about 1,5 - 2 GB large. That would not be not a big problem, at least if it does not keep growing while using hsdev.
No, i haven't built it. I've ran:
hsdev start
hsdev scan --cabal
hsdev scan --path hledger
In which directory? Do you not have to add the sandbox path?
Ok, got it.
There was a problem - hsdev called stack build --only-configure, but it builds all dependencies, which can last long. I've removed such implicit building.
There also was another bug: Cabal-2.0 changed namings of package-db in sandbox, now they use OS 'windows' for System.Info.os == "mingw32" too, and hsdev can't find it.
Fixed both.
After cabal sandbox init and installing these packages I started hsdev used commands in project root (of git repo)
hledger§ hsdev start
hledger§ hsdev scan --sandbox . --project hledger-lib --project hledger --project hledger-ui --project hledger-web --project hledger-api
Took ~30 secs
You can use just hsdev scan --path . command, which will try find everything under current directory, but it also can some irrelevants files/projects. In this case it also found project hakyll-std under site\hakyll-std directory
Another problem is that hsdev detects this project as stack project, but it can be built with both cabal too. I think there should be command 'scan project' with flags for different options - whether to cabal or stack? Scan sandbox too?
Great!
Yes, I think it's good idea to denote if it's a stack or cabal project because there "sandbox" or "working" directory has a different structure. Btw, I have not used cabal for a long time since I switched to stack. But cabal 2 should be a big improvement over previous versions of cabal (with cabal I mean cabal-install).
Can you explain me the idea of various arguments of the scan command? Also in context of stack vs cabal project.
Have you read API.md#scan?
scan is command to inspect both installed modules and source files, it accepts flags to specify scan targets:
project(flag can be repeated) — scan projects; it scans only sources and doesn't scan global-db/user-db or any other installed modules (*)cabal— unclear flag name, it's for scanning global-db/user-dbsandbox(repeated) — scan installed modules in sandbox (cabal-sandbox or stack-work), it scans package-dbs for specified sandboxfile(repeated) — scan standalone (non-project) file, it also doesn't scan any dependenciespath(repeated) — scan anything within directory (projects, sandboxes, standalone files)
Normally you scan project(s) and dependent cabal/sandboxes.
(*) But it "detects" build tool (looking for .cabal-sandbox and stack.yaml) and expect corresponding installed modules as dependencies. As a result, if it "detects" stack, it won't use modules from cabal-sandbox, even if you scanned only cabal-sandbox and no stack-work.
For now you can't specify which build tool to use, there issue #77 for it.
Have you read API.md#scan?
Yes, but was not clear, for example difference between project and path.
Okay, so if I want to scan a Stack project, the most simple solution is to scan the whole project inside the project root is:
scan --path . --cabal
Not sure about --cabal. It will scan user-db, which may not be related to project.
I'd prefer
hsdev scan --project . --sandbox .
--project to scan project sources, and --sandbox to scan stack package-dbs (it will scan not only local package-db, but all related)
I wonder if you have time to work on this request. Otherwise I will look for an alternative solution. Same for issues #77, #78 and #74.
Hi! I indend to work on this.
#77 i have a branch which supports specifying build tool when scanning project with scan project command (flags --cabal or --stack), will merge it soon
#78 doesn't look hard to implement, i'll try to add benchmarks next week.
#74 needs some investigation
Let's continue discussing details on gitter
Thanks!
Do you some specific issues to discuss on gitter?
When you have an initial light version developed I will have to integrate it with my plugin so I can test it.
Do you some specific issues to discuss on gitter?
Well, i don't know how to make it lighter than now (except by removing auto rescan) and meet your requirements :) I think, when discussing this in gitter, we will faster reach an understanding of exactly what the first version should be