From 9638e32f677f6e0b93ebed9f7195e3ff66484fc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Sodi=C4=87?= Date: Tue, 10 Dec 2024 11:49:47 +0100 Subject: [PATCH] Add elaborating comments and improve type for wasp file --- waspc/src/Wasp/Analyzer.hs | 10 ++++++++++ waspc/src/Wasp/Error.hs | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/waspc/src/Wasp/Analyzer.hs b/waspc/src/Wasp/Analyzer.hs index 8c4c98a68a..1c78f1d7d4 100644 --- a/waspc/src/Wasp/Analyzer.hs +++ b/waspc/src/Wasp/Analyzer.hs @@ -164,6 +164,16 @@ analyze prismaSchemaAst = >=> (wrapAnalyzerError TypeError . typeCheck stdTypes) >=> (wrapAnalyzerError EvaluationError . evaluate stdTypes) +-- | When writing main.wasp.ts, TypeScript should know about all the available +-- entities. +-- Since Wasp's AST includes entity declarations, the easiest way to get a list +-- of all entities defined in the Prisma Schema is by: +-- 1. Creating an AST with (and only with) the declarations for the Prisma +-- schema Entities. +-- 2. Type-checking that AST and returning the result. +-- This gives us a list of entity declarations we can then forward to +-- TypeScript (which then validates the user config only uses existing +-- entities). getEntityDecls :: Psl.Schema.Schema -> Either [AnalyzeError] [Decl] getEntityDecls schema = wrapAnalyzerError TypeError (typeCheck stdTypes astWithEntitiesOnly) diff --git a/waspc/src/Wasp/Error.hs b/waspc/src/Wasp/Error.hs index aa4ef8474a..a02cb070f6 100644 --- a/waspc/src/Wasp/Error.hs +++ b/waspc/src/Wasp/Error.hs @@ -7,13 +7,14 @@ import StrongPath.Types (File) import Wasp.Analyzer.Parser.Ctx (Ctx, getCtxRgn) import Wasp.Analyzer.Parser.SourcePosition (SourcePosition (..)) import Wasp.Analyzer.Parser.SourceRegion (SourceRegion (..)) +import Wasp.Project.Common (WaspLangFile) import Wasp.Util (indent, insertAt, leftPad) import qualified Wasp.Util.Terminal as T -- | Transforms compiler error (error with parse context) into an informative, pretty String that -- can be printed directly into the terminal. It uses terminal features like escape codes -- (colors, styling, ...). -showCompilerErrorForTerminal :: (Path' Abs (File f), String) -> (String, Ctx) -> String +showCompilerErrorForTerminal :: (Path' Abs (File WaspLangFile), String) -> (String, Ctx) -> String showCompilerErrorForTerminal (waspFilePath, waspFileContent) (errMsg, errCtx) = let srcRegion = getCtxRgn errCtx in intercalate