Skip to content

Replace TextDocumentIdentifier with Uri in getNormalizedFilePath #2912

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

Merged
merged 2 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions hls-plugin-api/src/Ide/PluginUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,12 @@ allLspCmdIds pid commands = concatMap go commands

-- ---------------------------------------------------------------------

getNormalizedFilePath :: Monad m => PluginId -> TextDocumentIdentifier -> ExceptT String m NormalizedFilePath
getNormalizedFilePath (PluginId plId) docId = handleMaybe errMsg
getNormalizedFilePath :: Monad m => PluginId -> Uri -> ExceptT String m NormalizedFilePath
getNormalizedFilePath (PluginId plId) uri = handleMaybe errMsg
$ uriToNormalizedFilePath
$ toNormalizedUri uri'
$ toNormalizedUri uri
where
errMsg = T.unpack $ "Error(" <> plId <> "): converting " <> getUri uri' <> " to NormalizedFilePath"
uri' = docId ^. uri
errMsg = T.unpack $ "Error(" <> plId <> "): converting " <> getUri uri <> " to NormalizedFilePath"

-- ---------------------------------------------------------------------
handleMaybe :: Monad m => e -> Maybe b -> ExceptT e m b
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ library
, ghcide ^>=1.6 || ^>=1.7
, ghc-boot-th
, hls-graph
, hls-plugin-api ^>=1.3 || ^>=1.4
, hls-plugin-api ^>=1.4
, hie-compat
, lens
, lsp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import Development.IDE (GetParsedModule (GetParsedModu
GhcSession (GhcSession),
IdeState, RuleResult, Rules,
define, getFileContents,
hscEnv, ideLogger,
realSrcSpanToRange, runAction,
use, useWithStale)
hscEnv, realSrcSpanToRange,
runAction, use, useWithStale)
import qualified Development.IDE.Core.Shake as Shake
import Development.IDE.GHC.Compat hiding (getSrcSpan)
import Development.IDE.GHC.Compat.Util (toList)
Expand All @@ -31,8 +30,8 @@ import Ide.Plugin.Conversion (AlternateFormat,
ExtensionNeeded (NeedsExtension, NoExtension),
alternateFormat)
import Ide.Plugin.Literals
import Ide.PluginUtils (handleMaybe, handleMaybeM,
response)
import Ide.PluginUtils (getNormalizedFilePath,
handleMaybeM, response)
import Ide.Types
import Language.LSP.Types
import Language.LSP.Types.Lens (uri)
Expand Down Expand Up @@ -84,8 +83,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 _ (CodeActionParams _ _ docId currRange _) = response $ do
nfp <- getNormalizedFilePath docId
codeActionHandler state plId (CodeActionParams _ _ docId currRange _) = response $ do
nfp <- getNormalizedFilePath plId (docId ^. uri)
CLR{..} <- requestLiterals state nfp
pragma <- getFirstPragma state nfp
-- remove any invalid literals (see validTarget comment)
Expand Down Expand Up @@ -151,12 +150,6 @@ getFirstPragma state nfp = handleMaybeM "Error: Could not get NextPragmaInfo" $
Just (hscEnv -> hsc_dflags -> sessionDynFlags, _) -> pure $ Just $ getNextPragmaInfo sessionDynFlags fileContents
Nothing -> pure Nothing


getNormalizedFilePath :: Monad m => TextDocumentIdentifier -> ExceptT String m NormalizedFilePath
getNormalizedFilePath docId = handleMaybe "Error: converting to NormalizedFilePath"
$ uriToNormalizedFilePath
$ toNormalizedUri (docId ^. uri)

requestLiterals :: MonadIO m => IdeState -> NormalizedFilePath -> ExceptT String m CollectLiteralsResult
requestLiterals state = handleMaybeM "Error: Could not Collect Literals"
. liftIO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ library
build-depends:
, base >=4.12 && < 5
, ghcide ^>=1.7
, hls-plugin-api ^>=1.3 || ^>=1.4
, hls-plugin-api ^>=1.4
, lsp-types
, regex-tdfa
, syb
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ descriptor plId = (defaultPluginDescriptor plId) { pluginHandlers = mkPluginHand

codeActionHandler :: PluginMethodHandler IdeState 'TextDocumentCodeAction
codeActionHandler ideState plId CodeActionParams {_textDocument = TextDocumentIdentifier uri, _context = CodeActionContext (List diags) _} = response $ do
nfp <- getNormalizedFilePath plId (TextDocumentIdentifier uri)
nfp <- getNormalizedFilePath plId uri
decls <- getDecls ideState nfp
let actions = mapMaybe (generateAction uri decls) diags
pure $ List actions
Expand Down