wz1000 / HieDb

Generates a references DB from .hie files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improve CLI by documenting the expected format of SYMBOL

jhrcek opened this issue · comments

Some CLI commands of hiedb expect SYMBOL as an input.
For example

 Usage: hiedb unreachable SYMBOL
  Find all symbols unreachable from the given symbols

But when I try to use it I get

$ hiedb unreachable Main.main
cannot parse value `Main.main'

Usage: hiedb unreachable SYMBOL
  Find all symbols unreachable from the given symbols

Looking at source code it's clear to me that the parsing is based on Read instance of Symbol. But it's totally non-obvious how to format the SYMBOL when querrying from CLI. Could you add an example of the expected format to cli help message that gets printed?

The parser is here, but I think it could be massively simplified and brought in line with all the other queries: https://github.com/wz1000/HieDb/blob/master/src/HieDb/Types.hs#L264

I can look into this over the weekend.
In the meantime can you share your idea about what would be the format(s) that should be accepted by the parser?
Also do you think there are some reasonable defaults that could be filled in in cases when user doesn't provide part of the symbol (e.g. package name)? I saw that the db is stored in central location, so user is likely to index multiple projects into single DB. Also I wonder if it would make sense, after the symbol is successfully parsed, but not found in DB, to display something like "there is no x:y:z in database, but the following match your query [a:b:c, d:e:f, ...]"

I think we can just accept the format used by all the other commands. These commands also have graceful fallback in case information like the module name, package name isn't provided, so you can look into that.

format used by all the other command

By other commands do you mean these which take name + optionally module and unit id?
I'm afraid that this approach is only usable for commands that take single name+module+unitId.
The issue with the commands that currently take Symbol as input is that they take List of Symbols

HieDb/src/HieDb/Run.hs

Lines 91 to 93 in dd4e9f4

| Reachable [Symbol]
| Unreachable [Symbol]
| Html [Symbol]

Making that work in the cli parser would not be easy.

So I think we can keep the current symbol parsing, but we should also make it clear in some help message how a properly formatted Symbol looks OR give some hint as to how to list existing symbols from which user can pick?

I agree that we can improve the help message. However, the Symbol type can also be changed to make the module and unit-id optional, with the appropriate modifications to the parsing

Alternatively, we could consolidate all the input types into a single, easy to specify format like unit-id:Module.symbol, where both the unit-id and Module are optional.

Sounds good. I'll start by writing bunch of tests for parsing these InputSymbols or however we want to call them and once we agree on what should be accepted, we can start migrating the existing commands.
One complication I see at the outset: symbol allows specifying symbol namespace as the first character. But how should I determine a namespace from something like unit-id:Module.symbol?

Ah, in that case, it might be best to just document the existing format and leave everything else as is for now.