summaryrefslogtreecommitdiff
path: root/source/Felix/Source.hs
diff options
context:
space:
mode:
Diffstat (limited to 'source/Felix/Source.hs')
-rw-r--r--source/Felix/Source.hs20
1 files changed, 20 insertions, 0 deletions
diff --git a/source/Felix/Source.hs b/source/Felix/Source.hs
index a30b5f9..64a88cd 100644
--- a/source/Felix/Source.hs
+++ b/source/Felix/Source.hs
@@ -25,6 +25,7 @@ module Felix.Source
, RootRequest
, searchedRoot
, existingRoot
+ , canonicalizeExistingSourcePath
, rootRequestSpelling
, ResolvedSource
, resolvedSourceCanonicalPath
@@ -230,6 +231,21 @@ existingRoot path
fmap (\canonical -> ExistingRoot canonical path) <$>
canonicalize ExistingRootCanonicalizationFailed path
+-- | Validate and canonicalize an existing source path without assigning it
+-- to a source mount.
+canonicalizeExistingSourcePath
+ :: FilePath
+ -> IO (Either SourceError CanonicalPath)
+canonicalizeExistingSourcePath path =
+ fmap extract <$> existingRoot path
+ where
+ extract = \case
+ ExistingRoot canonical _spelling ->
+ canonical
+ SearchedRoot{} ->
+ impossible
+ "canonicalizeExistingSourcePath produced a searched root"
+
-- | The user-facing spelling retained only for diagnostics.
rootRequestSpelling :: RootRequest -> FilePath
rootRequestSpelling = \case
@@ -450,6 +466,7 @@ data SourceError
!ResolvedSource
!LocationRegistrationError
| SourceImportCycle !(NonEmpty SourceCycleStep)
+ | PackagedPreludeSelectedAsOrdinarySource !ResolvedSource
| SourceGraphInvariantViolation !Text
deriving stock (Show, Eq)
@@ -551,6 +568,9 @@ renderSourceError = \case
<> sourceLabel (cycleImported step)
| step <- toList steps
]
+ PackagedPreludeSelectedAsOrdinarySource source ->
+ "the packaged final prelude cannot be used as ordinary source "
+ <> quotePath (resolvedSourceLocationPath source)
SourceGraphInvariantViolation reason ->
"source graph invariant failed: " <> reason