Skip to content

Commit eeb1d20

Browse files
authored
Replace TextDocumentIdentifier with Uri (#2912)
1 parent a1ead72 commit eeb1d20

File tree

5 files changed

+13
-21
lines changed

5 files changed

+13
-21
lines changed

hls-plugin-api/src/Ide/PluginUtils.hs

+4-5
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,12 @@ allLspCmdIds pid commands = concatMap go commands
246246

247247
-- ---------------------------------------------------------------------
248248

249-
getNormalizedFilePath :: Monad m => PluginId -> TextDocumentIdentifier -> ExceptT String m NormalizedFilePath
250-
getNormalizedFilePath (PluginId plId) docId = handleMaybe errMsg
249+
getNormalizedFilePath :: Monad m => PluginId -> Uri -> ExceptT String m NormalizedFilePath
250+
getNormalizedFilePath (PluginId plId) uri = handleMaybe errMsg
251251
$ uriToNormalizedFilePath
252-
$ toNormalizedUri uri'
252+
$ toNormalizedUri uri
253253
where
254-
errMsg = T.unpack $ "Error(" <> plId <> "): converting " <> getUri uri' <> " to NormalizedFilePath"
255-
uri' = docId ^. uri
254+
errMsg = T.unpack $ "Error(" <> plId <> "): converting " <> getUri uri <> " to NormalizedFilePath"
256255

257256
-- ---------------------------------------------------------------------
258257
handleMaybe :: Monad m => e -> Maybe b -> ExceptT e m b

plugins/hls-alternate-number-format-plugin/hls-alternate-number-format-plugin.cabal

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ library
2929
, ghcide ^>=1.6 || ^>=1.7
3030
, ghc-boot-th
3131
, hls-graph
32-
, hls-plugin-api ^>=1.3 || ^>=1.4
32+
, hls-plugin-api ^>=1.4
3333
, hie-compat
3434
, lens
3535
, lsp

plugins/hls-alternate-number-format-plugin/src/Ide/Plugin/AlternateNumberFormat.hs

+6-13
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ import Development.IDE (GetParsedModule (GetParsedModu
1414
GhcSession (GhcSession),
1515
IdeState, RuleResult, Rules,
1616
define, getFileContents,
17-
hscEnv, ideLogger,
18-
realSrcSpanToRange, runAction,
19-
use, useWithStale)
17+
hscEnv, realSrcSpanToRange,
18+
runAction, use, useWithStale)
2019
import qualified Development.IDE.Core.Shake as Shake
2120
import Development.IDE.GHC.Compat hiding (getSrcSpan)
2221
import Development.IDE.GHC.Compat.Util (toList)
@@ -31,8 +30,8 @@ import Ide.Plugin.Conversion (AlternateFormat,
3130
ExtensionNeeded (NeedsExtension, NoExtension),
3231
alternateFormat)
3332
import Ide.Plugin.Literals
34-
import Ide.PluginUtils (handleMaybe, handleMaybeM,
35-
response)
33+
import Ide.PluginUtils (getNormalizedFilePath,
34+
handleMaybeM, response)
3635
import Ide.Types
3736
import Language.LSP.Types
3837
import Language.LSP.Types.Lens (uri)
@@ -84,8 +83,8 @@ collectLiteralsRule recorder = define (cmapWithPrio LogShake recorder) $ \Collec
8483
getExtensions = map GhcExtension . toList . extensionFlags . ms_hspp_opts . pm_mod_summary
8584

8685
codeActionHandler :: PluginMethodHandler IdeState 'TextDocumentCodeAction
87-
codeActionHandler state _ (CodeActionParams _ _ docId currRange _) = response $ do
88-
nfp <- getNormalizedFilePath docId
86+
codeActionHandler state plId (CodeActionParams _ _ docId currRange _) = response $ do
87+
nfp <- getNormalizedFilePath plId (docId ^. uri)
8988
CLR{..} <- requestLiterals state nfp
9089
pragma <- getFirstPragma state nfp
9190
-- remove any invalid literals (see validTarget comment)
@@ -151,12 +150,6 @@ getFirstPragma state nfp = handleMaybeM "Error: Could not get NextPragmaInfo" $
151150
Just (hscEnv -> hsc_dflags -> sessionDynFlags, _) -> pure $ Just $ getNextPragmaInfo sessionDynFlags fileContents
152151
Nothing -> pure Nothing
153152

154-
155-
getNormalizedFilePath :: Monad m => TextDocumentIdentifier -> ExceptT String m NormalizedFilePath
156-
getNormalizedFilePath docId = handleMaybe "Error: converting to NormalizedFilePath"
157-
$ uriToNormalizedFilePath
158-
$ toNormalizedUri (docId ^. uri)
159-
160153
requestLiterals :: MonadIO m => IdeState -> NormalizedFilePath -> ExceptT String m CollectLiteralsResult
161154
requestLiterals state = handleMaybeM "Error: Could not Collect Literals"
162155
. liftIO

plugins/hls-change-type-signature-plugin/hls-change-type-signature-plugin.cabal

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ library
2424
build-depends:
2525
, base >=4.12 && < 5
2626
, ghcide ^>=1.7
27-
, hls-plugin-api ^>=1.3 || ^>=1.4
27+
, hls-plugin-api ^>=1.4
2828
, lsp-types
2929
, regex-tdfa
3030
, syb

plugins/hls-change-type-signature-plugin/src/Ide/Plugin/ChangeTypeSignature.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ descriptor plId = (defaultPluginDescriptor plId) { pluginHandlers = mkPluginHand
3535

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

0 commit comments

Comments
 (0)