hls-explicit-imports-plugin 0.1.0.1 → 0.1.0.2
raw patch · 2 files changed
+26/−18 lines, 2 filesdep +lspdep +lsp-typesdep −haskell-lsp-typesPVP ok
version bump matches the API change (PVP)
Dependencies added: lsp, lsp-types
Dependencies removed: haskell-lsp-types
API changes (from Hackage documentation)
Files
hls-explicit-imports-plugin.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.2 name: hls-explicit-imports-plugin-version: 0.1.0.1+version: 0.1.0.2 synopsis: Explicit imports plugin for Haskell Language Server license: Apache-2.0 license-file: LICENSE@@ -19,7 +19,8 @@ , base >=4.12 && <5 , containers , deepseq- , haskell-lsp-types+ , lsp-types+ , lsp , hls-plugin-api , ghc , ghcide >= 0.7.4@@ -29,3 +30,4 @@ default-language: Haskell2010 include-dirs: include+ default-extensions: DataKinds, TypeOperators
src/Ide/Plugin/ExplicitImports.hs view
@@ -29,7 +29,8 @@ import GHC.Generics (Generic) import Ide.PluginUtils ( mkLspCommand ) import Ide.Types-import Language.Haskell.LSP.Types+import Language.LSP.Types+import Language.LSP.Server import PrelNames (pRELUDE) import RnNames ( findImportUsage,@@ -45,14 +46,17 @@ descriptor :: PluginId -> PluginDescriptor IdeState descriptor plId = (defaultPluginDescriptor plId)- { -- This plugin provides code lenses- pluginCodeLensProvider = Just lensProvider,+ { -- This plugin provides a command handler pluginCommands = [importLensCommand],- -- This plugin provides code actions- pluginCodeActionProvider = Just codeActionProvider, -- This plugin defines a new rule- pluginRules = minimalImportsRule+ pluginRules = minimalImportsRule,+ pluginHandlers = mconcat+ [ -- This plugin provides code lenses+ mkPluginHandler STextDocumentCodeLens lensProvider+ -- This plugin provides code actions+ , mkPluginHandler STextDocumentCodeAction codeActionProvider+ ] } -- | The command descriptor@@ -67,9 +71,10 @@ -- | The actual command handler runImportCommand :: CommandFunction IdeState ImportCommandParams-runImportCommand _lspFuncs _state (ImportCommandParams edit) = do+runImportCommand _state (ImportCommandParams edit) = do -- This command simply triggers a workspace edit!- return (Right Null, Just (WorkspaceApplyEdit, ApplyWorkspaceEditParams edit))+ _ <- sendRequest SWorkspaceApplyEdit (ApplyWorkspaceEditParams Nothing edit) (\_ -> pure ())+ return (Right Null) -- | For every implicit import statement, return a code lens of the corresponding explicit import -- Example - for the module below:@@ -81,15 +86,14 @@ -- the provider should produce one code lens associated to the import statement: -- -- > import Data.List (intercalate, sortBy)-lensProvider :: CodeLensProvider IdeState+lensProvider :: PluginMethodHandler IdeState TextDocumentCodeLens lensProvider- _lspFuncs -- LSP functions, not used state -- ghcide state, used to retrieve typechecking artifacts pId -- plugin Id CodeLensParams {_textDocument = TextDocumentIdentifier {_uri}} -- VSCode uses URIs instead of file paths -- haskell-lsp provides conversion functions- | Just nfp <- uriToNormalizedFilePath $ toNormalizedUri _uri =+ | Just nfp <- uriToNormalizedFilePath $ toNormalizedUri _uri = liftIO $ do mbMinImports <- runAction "" state $ useWithStale MinimalImports nfp case mbMinImports of@@ -110,10 +114,10 @@ -- | If there are any implicit imports, provide one code action to turn them all -- into explicit imports.-codeActionProvider :: CodeActionProvider IdeState-codeActionProvider _lspFuncs ideState _pId docId range _context+codeActionProvider :: PluginMethodHandler IdeState TextDocumentCodeAction+codeActionProvider ideState _pId (CodeActionParams _ _ docId range _context) | TextDocumentIdentifier {_uri} <- docId,- Just nfp <- uriToNormalizedFilePath $ toNormalizedUri _uri =+ Just nfp <- uriToNormalizedFilePath $ toNormalizedUri _uri = liftIO $ do pm <- runIde ideState $ use GetParsedModule nfp let insideImport = case pm of@@ -132,7 +136,7 @@ maybe [] getMinimalImportsResult minImports, Just e <- [mkExplicitEdit zeroMapping imp explicit] ]- caExplicitImports = CACodeAction CodeAction {..}+ caExplicitImports = InR CodeAction {..} _title = "Make all imports explicit" _kind = Just CodeActionQuickFix _command = Nothing@@ -140,6 +144,8 @@ _changes = Just $ HashMap.singleton _uri $ List edits _documentChanges = Nothing _diagnostics = Nothing+ _isPreferred = Nothing+ _disabled = Nothing return $ Right $ List [caExplicitImports | not (null edits)] | otherwise = return $ Right $ List []@@ -238,7 +244,7 @@ -- the command argument is simply the edit _arguments = Just [toJSON $ ImportCommandParams edit] -- create the command- _command <- Just <$> mkLspCommand pId importCommandId title _arguments+ _command = Just $ mkLspCommand pId importCommandId title _arguments -- create and return the code lens return $ Just CodeLens {..}