Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wz1000 committed Dec 20, 2022
1 parent 64f76e3 commit 996c62a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
7 changes: 7 additions & 0 deletions ghcide/src/Development/IDE/GHC/Compat.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ module Development.IDE.GHC.Compat(
mkAstNode,
combineRealSrcSpans,

nonDetOccEnvElts,

isQualifiedImport,
GhcVersion(..),
ghcVersion,
Expand Down Expand Up @@ -268,6 +270,11 @@ import GHC.Types.Error
import GHC.Driver.Config.Stg.Pipeline
#endif

#if !MIN_VERSION_ghc(9,3,0)
nonDetOccEnvElts :: OccEnv a -> [a]
nonDetOccEnvElts = occEnvElts
#endif

type ModIfaceAnnotation = Annotation

#if MIN_VERSION_ghc(9,3,0)
Expand Down
2 changes: 1 addition & 1 deletion ghcide/src/Development/IDE/Plugin/Completions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ getCompletionsLSP ide plId
let exportsMap = fromMaybe mempty packageExportsMap <> projectExportsMap

let moduleExports = getModuleExportsMap exportsMap
exportsCompItems = foldMap (map (fromIdentInfo uri) . Set.toList) . occEnvElts . getExportsMap $ exportsMap
exportsCompItems = foldMap (map (fromIdentInfo uri) . Set.toList) . nonDetOccEnvElts . getExportsMap $ exportsMap
exportsCompls = mempty{anyQualCompls = exportsCompItems}
let compls = (fst <$> localCompls) <> (fst <$> nonLocalCompls) <> Just exportsCompls <> Just lModules

Expand Down
1 change: 1 addition & 0 deletions ghcide/src/Development/IDE/Plugin/Completions/Logic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ fromIdentInfo doc id@IdentInfo{..} q = CI
, insertText=rend
, provenance = DefinedIn mod
, label=rend
, typeText = Nothing
, isInfix=Nothing
, isTypeCompl= not (isDatacon id) && isUpper (T.head rend)
, additionalTextEdits= Just $
Expand Down
5 changes: 3 additions & 2 deletions ghcide/src/Development/IDE/Types/Exports.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ updateExportsMap old new = ExportsMap
| m_uniq <- nonDetKeysUFM (getModuleExportsMap new)]

size :: ExportsMap -> Int
size = sum . map (Set.size) . occEnvElts . getExportsMap
size = sum . map (Set.size) . nonDetOccEnvElts . getExportsMap

mkVarOrDataOcc :: Text -> OccName
mkVarOrDataOcc t = mkOcc $ mkFastStringByteString $ encodeUtf8 t
Expand Down Expand Up @@ -98,7 +98,8 @@ rendered = occNameText . name
-- TODO: pattern synonymoccNameText :: OccName -> Text
occNameText :: OccName -> Text
occNameText name
| isTcOcc name && isSymOcc name = "type " <> renderedOcc
| isSymOcc name = "(" <> renderedOcc <> ")"
| isTcOcc name && isSymOcc name = "type (" <> renderedOcc <> ")"
| otherwise = renderedOcc
where
renderedOcc = renderOcc name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Development.IDE.Plugin.Plugins.ImportUtils
import Data.List.NonEmpty (NonEmpty ((:|)))
import qualified Data.Text as T
import Development.IDE.Plugin.CodeAction.ExactPrint (wildCardSymbol)
import Development.IDE.Types.Exports (IdentInfo (..))
import Development.IDE.Types.Exports
import Language.LSP.Types (CodeActionKind (..))

-- | Possible import styles for an 'IdentInfo'.
Expand Down Expand Up @@ -49,16 +49,18 @@ data ImportStyle
deriving Show

importStyles :: IdentInfo -> NonEmpty ImportStyle
importStyles IdentInfo {parent, rendered, isDatacon}
| Just p <- parent
importStyles i@(IdentInfo {parent})
| Just p <- pr
-- Constructors always have to be imported via their parent data type, but
-- methods and associated type/data families can also be imported as
-- top-level exports.
= ImportViaParent rendered p
:| [ImportTopLevel rendered | not isDatacon]
= ImportViaParent rend p
:| [ImportTopLevel rend | not (isDatacon i)]
<> [ImportAllConstructors p]
| otherwise
= ImportTopLevel rendered :| []
= ImportTopLevel rend :| []
where rend = rendered i
pr = occNameText <$> parent

-- | Used for adding new imports
renderImportStyle :: ImportStyle -> T.Text
Expand Down

0 comments on commit 996c62a

Please sign in to comment.