Skip to content

Commit 76c92a3

Browse files
committed
Move lookupPluginId out of loop
1 parent 1bbdb21 commit 76c92a3

File tree

1 file changed

+10
-11
lines changed
  • ghcide/src/Development/IDE/Plugin/Completions

1 file changed

+10
-11
lines changed

ghcide/src/Development/IDE/Plugin/Completions/Logic.hs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ import GHC.Plugins (Depth (AllTheWay),
5959
#endif
6060
import Ide.PluginUtils (mkLspCommand, lookupPluginId)
6161
import Ide.Types (CommandId (..),
62-
IdePlugins)
62+
IdePlugins, PluginId)
6363
import Language.LSP.Types
6464
import Language.LSP.Types.Capabilities
6565
import qualified Language.LSP.VFS as VFS
@@ -161,9 +161,10 @@ occNameToComKind ty oc
161161
showModName :: ModuleName -> T.Text
162162
showModName = T.pack . moduleNameString
163163

164-
mkCompl :: IdePlugins a -> IdeOptions -> CompItem -> CompletionItem
164+
mkCompl :: Maybe PluginId -- ^ Plugin to use for the extend import command
165+
-> IdeOptions -> CompItem -> CompletionItem
165166
mkCompl
166-
plugins
167+
pId
167168
IdeOptions {..}
168169
CI
169170
{ compKind,
@@ -175,7 +176,7 @@ mkCompl
175176
docs,
176177
additionalTextEdits
177178
} = do
178-
let mbCommand = mkAdditionalEditsCommand plugins =<< additionalTextEdits
179+
let mbCommand = mkAdditionalEditsCommand pId =<< additionalTextEdits
179180
let ci = CompletionItem
180181
{_label = label,
181182
_kind = kind,
@@ -217,12 +218,9 @@ mkCompl
217218
"line " <> printOutputable (srcLocLine loc) <> ", column " <> printOutputable (srcLocCol loc)
218219

219220

220-
mkAdditionalEditsCommand :: IdePlugins a -> ExtendImport -> Maybe Command
221-
mkAdditionalEditsCommand plugins edits = case lookupPluginId extendImportCommand plugins of
222-
Just pId -> Just $ mkLspCommand pId (CommandId extendImportCommandId) "extend import" (Just [toJSON edits])
223-
Nothing -> Nothing
224-
where
225-
extendImportCommand = CommandId extendImportCommandId
221+
mkAdditionalEditsCommand :: Maybe PluginId -> ExtendImport -> Maybe Command
222+
mkAdditionalEditsCommand (Just pId) edits = Just $ mkLspCommand pId (CommandId extendImportCommandId) "extend import" (Just [toJSON edits])
223+
mkAdditionalEditsCommand _ _ = Nothing
226224

227225
mkNameCompItem :: Uri -> Maybe T.Text -> OccName -> Provenance -> Maybe Type -> Maybe Backtick -> SpanDoc -> Maybe (LImportDecl GhcPs) -> CompItem
228226
mkNameCompItem doc thingParent origName provenance thingType isInfix docs !imp = CI {..}
@@ -666,7 +664,8 @@ getCompletions plugins ideOpts CC {allModNamesAsNS, anyQualCompls, unqualCompls,
666664
| otherwise -> do
667665
-- assumes that nubOrdBy is stable
668666
let uniqueFiltCompls = nubOrdBy (uniqueCompl `on` snd . Fuzzy.original) filtCompls
669-
let compls = (fmap.fmap.fmap) (mkCompl plugins ideOpts) uniqueFiltCompls
667+
let compls = (fmap.fmap.fmap) (mkCompl pId ideOpts) uniqueFiltCompls
668+
pId = lookupPluginId (CommandId extendImportCommandId) plugins
670669
return $
671670
(fmap.fmap) snd $
672671
sortBy (compare `on` lexicographicOrdering) $

0 commit comments

Comments
 (0)