Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork399
hls-render-plugin: Proof of Concept for a mechanism for customizable type driven "Actions"#4604
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
…es, based on their types
deemp commentedJun 4, 2025
@joe-warren in thedemo, you state that the current doctests approach isn't very ergonomic because it requires you to write a comment and to import functions that you're going to use. Not a HLS contributor, but I'd like to discuss the design that you propose. Local values, result types, types on hoverNew pluginWith your plugin, one can write a number of top-level functions that use local values that are unavailable in the configuration file. One will then be able to run some of these top-level functions using code lenses that call One will also be able to see the types of expressions on hover.
DoctestsWhen writing doctests, one can also write top-level functions that use local values that are unavailable in the configuration file. Doctests may produce not only Unfortunately, one can't interactively view the types of expressions in doctests. Hence, one needs to create auxiliary functions like
Unnecessary function importsNew pluginNew plugin avoids imports by loading the configuration file into a GHCi session.
From thedemo:
DoctestsDoctests do require imports. This fact leads to two problems:
After the second problem is resolved, one will be able to write imports that are necessary only for doctests into a Wrong code lensesNew pluginThe new plugin may display code lenses for combinations of render and ordinary functions that don't make sense. Such code lenses may create a lot of visual noise. Moreover, each part of the codebase may require own set of render functions. It may not be feasible to put all render functions into a single configuration because the visual noise from code lenses will increase even more. DoctestsWhen using the doctests approach, one will see Evaluate code lenses above each doctest. Relation to a Haskell packageNew pluginIt's unclear whether the configuration file should belong to the Haskell package where the file is used (i.e., be listed in the package's DoctestsDoctests in a module use functions imported from local and non-local modules (e.g. modules from dependencies on Hackage). Local modules and dependencies are tracked in ConclusionTo sum up, the new plugin provides a slightly less verbose way for composing and running Despite some overhead in the form of comments and auxiliary functions, doctests might be a more general, more precise, and less noisy solution to the problem of quickly composing and running |
I don't know if I'm too concerned about visual noise from render code lenses, because:
|
Uh oh!
There was an error while loading.Please reload this page.
Hi, new contributor here
I'm opening this as much as a proof of concept as anything.
This PR adds a new plugin, which is conceptually very similar to (and cribs heavily from) hls-eval-plugin.
However, unlike hls-eval-plugin, it's not triggered by doctest comments, instead it takes a "configuration" file, containing a number of Haskell functions, and for each combination of "value in the current module" and "function in the config", if the result of applying the function to the value is
IO ()
it generates a code lens which runs that result.There's a lot of duplication between this and the eval plugin, and I'd be open to adding this behaviour to the eval plugin instead, but my thought process was that a standalong plugin is more modular, and people might want to turn this off, and not the eval plugin,
I've recorded a demo of the plugin in use,which I've uploaded here
There are a handful of things that I think make this un-mergable as is:
The big one is the mechanism by which I'm evaluating the configuration file; I'm doing this with
runDecls
(after parsing out any imports).This seems to me to be inferior to compiling the file as a module, and then importing it qualified. As there's currently a risk of naming collisions (and the code I have for separating out imports is incomplete, and requires each import to take exactly one line).
I'm also open to changing the name "hls-render-plugin". I didn't want to use the word "action", because I'm aware that actions already means something else in the context of the Language Server Protocol.
I'm using the
Pretty
instance onType
, to convert the type of the applied "action" to a string in order to compare it toIO ()
, I highly suspect this isn't the right way to go about that.The "stylish-haskell" post-commit action doesn't seem to work if modified files contain C++ preprocessor directives?
Finally, this code is completely untested, and I'm more than happy to fix that if you have any suggestions for sensible tests.