Skip to content

Commit 708b751

Browse files
committed
Add note to constructor expositions for Evergreen
1 parent 3159b5a commit 708b751

File tree

8 files changed

+177
-14
lines changed

8 files changed

+177
-14
lines changed

compiler/src/Elm/Docs.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import qualified Reporting.Error.Docs as E
4848
import qualified Reporting.Result as Result
4949

5050

51-
import qualified Lamdera.Suggestions
51+
import qualified Lamdera.Reporting.Suggestions
5252

5353
-- DOCUMENTATION
5454

@@ -420,7 +420,7 @@ checkNames exports_ names =
420420
loneDoc = Map.traverseMissing onlyInDocs
421421
loneExport = Map.traverseMissing onlyInExports
422422
checkBoth = Map.zipWithAMatched (\n _ r -> isUnique n r)
423-
exports = Lamdera.Suggestions.hideWireExports exports_
423+
exports = Lamdera.Reporting.Suggestions.hideWireExports exports_
424424
in
425425
case Result.run (Map.mergeA loneExport loneDoc checkBoth exports docs) of
426426
(_, Right _) -> Right ()
@@ -467,7 +467,7 @@ checkDefs exportDict_ overview comments (Can.Module name _ _ decls unions aliase
467467
let
468468
types = gatherTypes decls Map.empty
469469
info = Info comments types unions aliases infixes effects
470-
exportDict = Lamdera.Suggestions.hideWireExports exportDict_
470+
exportDict = Lamdera.Reporting.Suggestions.hideWireExports exportDict_
471471
in
472472
case Result.run (Map.traverseWithKey (checkExport info) exportDict) of
473473
(_, Left problems ) -> Left $ E.DefProblems (OneOrMore.destruct NE.List problems)

compiler/src/Reporting/Error/Canonicalize.hs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ import qualified Reporting.Suggest as Suggest
3434

3535

3636
import Lamdera
37-
import qualified Lamdera.Suggestions
37+
import qualified Lamdera.Reporting.Suggestions
38+
import qualified Lamdera.Reporting.Evergreen
3839

3940
-- CANONICALIZATION ERRORS
4041

@@ -317,7 +318,7 @@ toReport source err =
317318
let
318319
suggestions =
319320
map Name.toChars $ take 4 $
320-
Lamdera.Suggestions.hideWireSuggestionsName $
321+
Lamdera.Reporting.Suggestions.hideWireSuggestionsName $
321322
Suggest.sort (Name.toChars rawName) Name.toChars possibleNames
322323
in
323324
Report.Report "UNKNOWN EXPORT" region suggestions $
@@ -399,7 +400,7 @@ toReport source err =
399400
let
400401
suggestions =
401402
map Name.toChars $ take 4 $
402-
Lamdera.Suggestions.hideWireSuggestionsName $
403+
Lamdera.Reporting.Suggestions.hideWireSuggestionsName $
403404
Suggest.sort (Name.toChars home) Name.toChars possibleNames
404405
in
405406
Report.Report "BAD IMPORT" region suggestions $
@@ -1049,12 +1050,14 @@ notFound source region maybePrefix name thing (PossibleNames locals quals) =
10491050
Set.foldr (\x xs -> toQualString prefix x : xs) allNames localSet
10501051
in
10511052
Map.foldrWithKey addQuals (map Name.toChars (Set.toList locals)) quals
1052-
& Lamdera.Suggestions.hideWireSuggestions
1053+
& Lamdera.Reporting.Suggestions.hideWireSuggestions
10531054

10541055
nearbyNames =
10551056
take 4 (Suggest.sort givenName id possibleNames)
10561057

10571058
toDetails noSuggestionDetails yesSuggestionDetails =
1059+
Lamdera.alternativeImplementationWhen Lamdera.isLamdera_
1060+
(Lamdera.Reporting.Evergreen.exposureHintToDetails nearbyNames givenName noSuggestionDetails yesSuggestionDetails) $
10581061
case nearbyNames of
10591062
[] ->
10601063
D.stack

elm.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ Executable lamdera
245245
Lamdera.PostCompile
246246
Lamdera.Project
247247
Lamdera.Relative
248-
Lamdera.Suggestions
248+
Lamdera.Reporting.Evergreen
249+
Lamdera.Reporting.Suggestions
249250
Lamdera.TypeHash
250251
Lamdera.Types
251252
Lamdera.Update

ext-elm-pages/Ext/ElmPages.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import qualified Data.List as List
77
import qualified Data.Map as Map
88
import qualified Data.Text as T
99
import qualified Data.Set as Set
10+
import System.FilePath ((</>))
1011

1112
import qualified Data.Name as N
1213
import qualified AST.Canonical as Can
@@ -23,6 +24,18 @@ import Lamdera.Wire3.Helpers
2324
import Lamdera.Types (Interfaces)
2425

2526

27+
isElmPages :: IO Bool
28+
isElmPages = do
29+
root <- getProjectRoot "Ext.ElmPages.isElmPages"
30+
fileContains (root </> ".elm-pages/Main.elm") "type PageData"
31+
32+
33+
{-# NOINLINE isElmPages_ #-}
34+
isElmPages_ :: Bool
35+
isElmPages_ = unsafePerformIO $ isDebug
36+
37+
38+
2639
data DiffableType
2740
= DRecord ModuleName.Canonical Text [(Text, DiffableType)]
2841
| DCustom Text [(Text, [DiffableType])]

extra/Lamdera.hs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ module Lamdera
3737
, isExperimental
3838
, isExperimental_
3939
-- , isTypeSnapshot
40+
, isLamdera
41+
, isLamdera_
4042
, isTest
4143
, isLiveMode
4244
, setLiveMode
@@ -394,6 +396,18 @@ isExperimental_ :: Bool
394396
isExperimental_ = unsafePerformIO $ isExperimental
395397

396398

399+
isLamdera :: IO Bool
400+
isLamdera = do
401+
root <- getProjectRoot "Lamdera.isLamdera"
402+
fileContains (root </> "elm.json") "lamdera/core"
403+
404+
405+
{-# NOINLINE isLamdera_ #-}
406+
isLamdera_ :: Bool
407+
isLamdera_ = unsafePerformIO $ isLamdera
408+
409+
410+
397411
isTest :: IO Bool
398412
isTest = do
399413
debugM <- lookupEnv "LTEST"

extra/Lamdera/PostCompile.hs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,16 @@ import Lamdera
1818
check :: Details.Details -> Build.Artifacts -> (Exit.BuildProblem -> b) -> Task.Task b ()
1919
check details artifacts errorWrapper =
2020
Task.eio errorWrapper $ do
21-
root <- getProjectRoot "Lamdera.PostCompile.check"
22-
hasElmPagesPageData <- fileContains (root </> ".elm-pages/Main.elm") "type PageData"
23-
if hasElmPagesPageData
21+
if Ext.ElmPages.isElmPages_
2422
then checkElmPagesTypes details artifacts
2523
else pure $ Right ()
2624

2725

28-
2926
checkElmPagesTypes :: Details.Details -> Build.Artifacts -> IO (Either Exit.BuildProblem ())
3027
checkElmPagesTypes details artifacts = do
3128
-- Unfortunately Build.Artifacts only contains project deps, we need the full tree...
3229
interfaces <- Ext.Query.Interfaces.artifactsToFullInterfaces details artifacts
3330

3431
case Ext.ElmPages.checkPageDataType interfaces of
3532
Right _ -> pure $ Right ()
36-
Left err -> pure $ Left err
33+
Left err -> pure $ Left err
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
module Lamdera.Reporting.Evergreen where
3+
4+
import qualified Reporting.Doc as D
5+
6+
7+
import Lamdera
8+
9+
10+
exposureHint givenName =
11+
D.reflow $
12+
"Note: Evergreen migrations need access to all custom type variants. Make sure both `" ++
13+
givenName ++ "` and `Evergreen.VX." ++ givenName ++ "` are exposed."
14+
15+
16+
exposureHintToDetails nearbyNames givenName noSuggestionDetails yesSuggestionDetails =
17+
case nearbyNames of
18+
[] ->
19+
D.stack
20+
[ D.reflow noSuggestionDetails
21+
, exposureHint givenName
22+
, D.link "Hint" "Read" "imports" "to see how `import` declarations work in Elm."
23+
]
24+
25+
suggestions ->
26+
D.stack
27+
[ D.reflow yesSuggestionDetails
28+
, D.indent 4 $ D.vcat $ map D.dullyellow $ map D.fromChars suggestions
29+
, exposureHint givenName
30+
, D.link "Hint" "Read" "imports" "to see how `import` declarations work in Elm."
31+
]
32+
33+
34+
35+
-- Maybe in future if we figure out a way to get the filename context we can do a much more fine-grained error message
36+
37+
38+
-- import qualified Data.Char as Char
39+
-- import qualified Data.List as List
40+
-- import qualified Data.Map as Map
41+
-- import qualified Data.Name as Name
42+
-- import qualified Data.OneOrMore as OneOrMore
43+
-- import qualified Data.Set as Set
44+
45+
-- import qualified AST.Canonical as Can
46+
-- import qualified AST.Source as Src
47+
-- import qualified Data.Index as Index
48+
-- import qualified Elm.ModuleName as ModuleName
49+
-- import qualified Reporting.Annotation as A
50+
-- import Reporting.Doc (Doc, (<+>), (<>))
51+
-- import qualified Reporting.Render.Code as Code
52+
-- import qualified Reporting.Render.Type as RT
53+
-- import qualified Reporting.Report as Report
54+
-- import qualified Reporting.Suggest as Suggest
55+
56+
-- import qualified Lamdera.Reporting.Suggestions
57+
58+
59+
-- explainExposureErrors :: Code.Source -> A.Region -> Maybe Name.Name -> Name.Name -> String -> Locals -> Quals -> Report.Report
60+
-- explainExposureErrors source region maybePrefix name thing locals quals =
61+
-- notFound source region maybePrefix name thing locals quals
62+
63+
64+
-- type Locals = Set.Set Name.Name
65+
-- type Quals = Map.Map Name.Name (Set.Set Name.Name)
66+
67+
68+
-- -- Clone of Reporting.Error.Canonicalize.notFound
69+
-- notFound :: Code.Source -> A.Region -> Maybe Name.Name -> Name.Name -> String -> Locals -> Quals -> Report.Report
70+
-- notFound source region maybePrefix name thing locals quals =
71+
-- let
72+
-- evergreenExposureHint =
73+
-- D.reflow $ "Note: Evergreen migrations need access to all custom type constructors, make sure the `" ++ givenName ++ "` constructor is exposed and not just the `Evergreen.VX." ++ givenName ++ "` one."
74+
75+
-- givenName =
76+
-- maybe Name.toChars toQualString maybePrefix name
77+
78+
-- possibleNames =
79+
-- let
80+
-- addQuals prefix localSet allNames =
81+
-- Set.foldr (\x xs -> toQualString prefix x : xs) allNames localSet
82+
-- in
83+
-- Map.foldrWithKey addQuals (map Name.toChars (Set.toList locals)) quals
84+
-- & Lamdera.Reporting.Suggestions.hideWireSuggestions
85+
86+
-- nearbyNames =
87+
-- take 4 (Suggest.sort givenName id possibleNames)
88+
89+
-- toDetails noSuggestionDetails yesSuggestionDetails =
90+
-- case nearbyNames of
91+
-- [] ->
92+
-- D.stack
93+
-- [ D.reflow noSuggestionDetails
94+
-- , evergreenExposureHint
95+
-- , D.link "Hint" "Read" "imports" "to see how `import` declarations work in Elm."
96+
-- ]
97+
98+
-- suggestions ->
99+
-- D.stack
100+
-- [ D.reflow yesSuggestionDetails
101+
-- , D.indent 4 $ D.vcat $ map D.dullyellow $ map D.fromChars suggestions
102+
-- , evergreenExposureHint
103+
-- , D.link "Hint" "Read" "imports" "to see how `import` declarations work in Elm."
104+
-- ]
105+
106+
-- in
107+
-- Report.Report "NAMING ERROR" region nearbyNames $
108+
-- Code.toSnippet source region Nothing
109+
-- (
110+
-- D.reflow $
111+
-- "I cannot find a `" ++ givenName ++ "` " ++ thing ++ ":"
112+
-- ,
113+
-- case maybePrefix of
114+
-- Nothing ->
115+
-- toDetails
116+
-- "Is there an `import` or `exposing` missing up top?"
117+
-- "These names seem close though:"
118+
119+
-- Just prefix ->
120+
-- case Map.lookup prefix quals of
121+
-- Nothing ->
122+
-- toDetails
123+
-- ("I cannot find a `" ++ Name.toChars prefix ++ "` module. Is there an `import` for it?")
124+
-- ("I cannot find a `" ++ Name.toChars prefix ++ "` import. These names seem close though:")
125+
126+
-- Just _ ->
127+
-- toDetails
128+
-- ("The `" ++ Name.toChars prefix ++ "` module does not expose a `" ++ Name.toChars name ++ "` " ++ thing ++ ".")
129+
-- ("The `" ++ Name.toChars prefix ++ "` module does not expose a `" ++ Name.toChars name ++ "` " ++ thing ++ ". These names seem close though:")
130+
-- )
131+
132+
133+
-- toQualString :: Name.Name -> Name.Name -> String
134+
-- toQualString prefix name =
135+
-- Name.toChars prefix ++ "." ++ Name.toChars name

extra/Lamdera/Suggestions.hs renamed to extra/Lamdera/Reporting/Suggestions.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{-# LANGUAGE OverloadedStrings #-}
2-
module Lamdera.Suggestions where
2+
module Lamdera.Reporting.Suggestions where
33

44
{- Helper to remove wire generations from suggestions such as:
55

0 commit comments

Comments
 (0)