Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add throwPluginError to Plugin Utilities #2924

Merged
merged 13 commits into from May 27, 2022

Conversation

drsooch
Copy link
Collaborator

@drsooch drsooch commented May 23, 2022

Add the function throwPluginError. This function is intended to
provide a common ResponseError message for use in logging.

Renamed response to pluginResponse in PluginUtils for more clarity.

Shifting away from using descriptor :: PluginID -> PluginDescriptor. Instead the plugin ID is pulled out and defined as part of a plugin directly. This provides easy access to the PluginID rather than having to feed it through functions.

I used the callHierarchyPlugin as a pseudo-testing ground for how it would look in practice. There will be a follow up PR that actually makes use of the error message (see #2919).

I've also updated plugins I wrote to use the new descriptor model.

Add the function `throwPluginError`. This function is intended to
provide a common `ResponseError` message for use in logging.

Renamed `response` to `pluginResponse` for more clarity.
Copy link
Collaborator

@kokobd kokobd left a comment

Choose a reason for hiding this comment

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

LGTM. And I will update selection range plugin accordingly after this PR is merged.

Copy link
Collaborator

@michaelpj michaelpj left a comment

Choose a reason for hiding this comment

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

Looks fine.

hls-plugin-api/src/Ide/PluginUtils.hs Show resolved Hide resolved
hls-plugin-api/src/Ide/PluginUtils.hs Show resolved Hide resolved
@@ -144,14 +146,14 @@ p `isInsideRealSrcSpan` r = let (Range sp ep) = realSrcSpanToRange r in sp <= p

getFirstPragma :: MonadIO m => IdeState -> NormalizedFilePath -> ExceptT String m NextPragmaInfo
getFirstPragma state nfp = handleMaybeM "Error: Could not get NextPragmaInfo" $ do
ghcSession <- liftIO $ runAction "AlternateNumberFormat.GhcSession" state $ useWithStale GhcSession nfp
(_, fileContents) <- liftIO $ runAction "AlternateNumberFormat.GetFileContents" state $ getFileContents nfp
ghcSession <- liftIO $ runAction (alternateNumberFormatId <> ".GhcSession") state $ useWithStale GhcSession nfp
Copy link
Collaborator

Choose a reason for hiding this comment

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

This does make me feel like we need some kind of "component context" for our logs and errors.... seems to be one of those things that everyone invents eventually.

Copy link
Collaborator Author

@drsooch drsooch May 24, 2022

Choose a reason for hiding this comment

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

Yeah #2919 I'm going to look to enhance the pluginRecorder to hopefully be able to decorate it with the plugin id. The other question is how to integrate that with runAction logging.

This is one of the big things I want to look at considering all plugins have this same model of id.Action.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, I guess what I'm wondering is whether we want some more generic "log context" stack in our recorders or something. It comes up a lot.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I strongly want something that can wrap runAction and return ExceptT String m ActionResult, then we can clean much boilerplate code.

exe/Plugins.hs Show resolved Hide resolved
@drsooch
Copy link
Collaborator Author

drsooch commented May 25, 2022

@michaelpj I've been thinking about this more. Would it make sense to just log the error within throwPluginError. This saves some follow up work with #2919.

Something like this:

throwPluginError' :: (HasCallStack, MonadIO m) => Recorder (WithPriority String) -> PluginId -> String -> String -> ExceptT String m b
throwPluginError' r (PluginId who) what _where' = logWith r Warning msg >> throwE msg

@drsooch
Copy link
Collaborator Author

drsooch commented May 25, 2022

@michaelpj I've been thinking about this more. Would it make sense to just log the error within throwPluginError. This saves some follow up work with #2919.

Something like this:

throwPluginError' :: (HasCallStack, MonadIO m) => Recorder (WithPriority String) -> PluginId -> String -> String -> ExceptT String m b
throwPluginError' r (PluginId who) what _where' = logWith r Warning msg >> throwE msg

Now that I actually played around with it, I forgot we'd need to depend on ghcide, which I assume we don't want for hls-plugins-api

@michaelpj
Copy link
Collaborator

I've been thinking about this more. Would it make sense to just log the error within throwPluginError.

That's basically what I was thinking about. The ghcide dependency issue is annoying, though. I wonder if some of the logging stuff should live in hls-plugin-api? It's not inconceivable that we might want to e.g. specify that some plugin types get loggers, or allow plugins to log without depending on ghcide. It could just be the types and the functions for actually performing logging, the code for actually creating recorders could live in ghcide still? Or maybe we need the hls-plugin-utils package that @July541 has been thinking about.

@drsooch drsooch added the merge me Label to trigger pull request merge label May 27, 2022
@mergify mergify bot merged commit 8f68882 into haskell:master May 27, 2022
hololeap pushed a commit to hololeap/haskell-language-server that referenced this pull request Aug 26, 2022
* Add new PluginUtility function.

Add the function `throwPluginError`. This function is intended to
provide a common `ResponseError` message for use in logging.

Renamed `response` to `pluginResponse` for more clarity.

* Call hierarchy clean up

* Make Descriptor usable as String/Text or PluginID

* Update reference to ChangeTypeSignature descriptor

* Use unpack rather than show

* Import cleanup

* Merge cleanup

* Fix test suites for effected plugins

* forgot to change the CodeAction kind in the test suite...

* Update new plugin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge me Label to trigger pull request merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants