-
-
Notifications
You must be signed in to change notification settings - Fork 398
Add throwPluginError
to Plugin Utilities
#2924
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
Changes from all commits
343357f
bc5d499
ea84a5d
6a5a3bc
a366ff5
0d5cfcd
4af875b
e447936
a471017
e5c450c
b91d84a
594f3ea
e52d364
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ module Ide.Plugin.AlternateNumberFormat (descriptor, Log(..)) where | |
import Control.Lens ((^.)) | ||
import Control.Monad.Except (ExceptT, MonadIO, liftIO) | ||
import qualified Data.HashMap.Strict as HashMap | ||
import Data.String (IsString) | ||
import Data.Text (Text) | ||
import qualified Data.Text as T | ||
import Development.IDE (GetParsedModule (GetParsedModule), | ||
|
@@ -31,19 +32,22 @@ import Ide.Plugin.Conversion (AlternateFormat, | |
alternateFormat) | ||
import Ide.Plugin.Literals | ||
import Ide.PluginUtils (getNormalizedFilePath, | ||
handleMaybeM, response) | ||
handleMaybeM, pluginResponse) | ||
import Ide.Types | ||
import Language.LSP.Types | ||
import Language.LSP.Types.Lens (uri) | ||
import qualified Language.LSP.Types.Lens as L | ||
|
||
newtype Log = LogShake Shake.Log deriving Show | ||
|
||
instance Pretty Log where | ||
pretty = \case | ||
LogShake log -> pretty log | ||
|
||
descriptor :: Recorder (WithPriority Log) -> PluginId -> PluginDescriptor IdeState | ||
descriptor recorder plId = (defaultPluginDescriptor plId) | ||
alternateNumberFormatId :: IsString a => a | ||
alternateNumberFormatId = "alternateNumberFormat" | ||
|
||
descriptor :: Recorder (WithPriority Log) -> PluginDescriptor IdeState | ||
descriptor recorder = (defaultPluginDescriptor alternateNumberFormatId) | ||
{ pluginHandlers = mkPluginHandler STextDocumentCodeAction codeActionHandler | ||
, pluginRules = collectLiteralsRule recorder | ||
} | ||
|
@@ -83,8 +87,8 @@ collectLiteralsRule recorder = define (cmapWithPrio LogShake recorder) $ \Collec | |
getExtensions = map GhcExtension . toList . extensionFlags . ms_hspp_opts . pm_mod_summary | ||
|
||
codeActionHandler :: PluginMethodHandler IdeState 'TextDocumentCodeAction | ||
codeActionHandler state plId (CodeActionParams _ _ docId currRange _) = response $ do | ||
nfp <- getNormalizedFilePath plId (docId ^. uri) | ||
codeActionHandler state plId (CodeActionParams _ _ docId currRange _) = pluginResponse $ do | ||
nfp <- getNormalizedFilePath plId (docId ^. L.uri) | ||
CLR{..} <- requestLiterals state nfp | ||
pragma <- getFirstPragma state nfp | ||
-- remove any invalid literals (see validTarget comment) | ||
|
@@ -144,14 +148,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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah #2919 I'm going to look to enhance the This is one of the big things I want to look at considering all plugins have this same model of There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I strongly want something that can wrap |
||
(_, fileContents) <- liftIO $ runAction (alternateNumberFormatId <> ".GetFileContents") state $ getFileContents nfp | ||
case ghcSession of | ||
Just (hscEnv -> hsc_dflags -> sessionDynFlags, _) -> pure $ Just $ getNextPragmaInfo sessionDynFlags fileContents | ||
Nothing -> pure Nothing | ||
Nothing -> pure Nothing | ||
|
||
requestLiterals :: MonadIO m => IdeState -> NormalizedFilePath -> ExceptT String m CollectLiteralsResult | ||
requestLiterals state = handleMaybeM "Error: Could not Collect Literals" | ||
. liftIO | ||
. runAction "AlternateNumberFormat.CollectLiterals" state | ||
. runAction (alternateNumberFormatId <> ".CollectLiterals") state | ||
. use CollectLiterals |
Uh oh!
There was an error while loading. Please reload this page.