Skip to content

Commit

Permalink
Move lookupPluginId out of loop
Browse files Browse the repository at this point in the history
  • Loading branch information
wz1000 committed Aug 12, 2022
1 parent 1bbdb21 commit 76c92a3
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions ghcide/src/Development/IDE/Plugin/Completions/Logic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import GHC.Plugins (Depth (AllTheWay),
#endif
import Ide.PluginUtils (mkLspCommand, lookupPluginId)
import Ide.Types (CommandId (..),
IdePlugins)
IdePlugins, PluginId)
import Language.LSP.Types
import Language.LSP.Types.Capabilities
import qualified Language.LSP.VFS as VFS
Expand Down Expand Up @@ -161,9 +161,10 @@ occNameToComKind ty oc
showModName :: ModuleName -> T.Text
showModName = T.pack . moduleNameString

mkCompl :: IdePlugins a -> IdeOptions -> CompItem -> CompletionItem
mkCompl :: Maybe PluginId -- ^ Plugin to use for the extend import command
-> IdeOptions -> CompItem -> CompletionItem
mkCompl
plugins
pId
IdeOptions {..}
CI
{ compKind,
Expand All @@ -175,7 +176,7 @@ mkCompl
docs,
additionalTextEdits
} = do
let mbCommand = mkAdditionalEditsCommand plugins =<< additionalTextEdits
let mbCommand = mkAdditionalEditsCommand pId =<< additionalTextEdits
let ci = CompletionItem
{_label = label,
_kind = kind,
Expand Down Expand Up @@ -217,12 +218,9 @@ mkCompl
"line " <> printOutputable (srcLocLine loc) <> ", column " <> printOutputable (srcLocCol loc)


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

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

0 comments on commit 76c92a3

Please sign in to comment.