Remove current path argument

This commit is contained in:
Rúnar 2024-01-25 15:19:10 -05:00
parent 980a21ad19
commit 1415688b57
4 changed files with 47 additions and 55 deletions

View File

@ -171,9 +171,8 @@ renderTypeError ::
TypeError v loc ->
Env ->
String ->
Path.Absolute ->
Pretty ColorText
renderTypeError e env src _curPath = case e of
renderTypeError e env src = case e of
BooleanMismatch {..} ->
mconcat
[ Pr.wrap $
@ -1264,10 +1263,9 @@ renderNoteAsANSI ::
Pr.Width ->
Env ->
String ->
Path.Absolute ->
Note v a ->
String
renderNoteAsANSI w e s curPath n = Pr.toANSI w $ printNoteWithSource e s curPath n
renderNoteAsANSI w e s n = Pr.toANSI w $ printNoteWithSource e s n
renderParseErrorAsANSI :: (Var v) => Pr.Width -> String -> Parser.Err v -> String
renderParseErrorAsANSI w src = Pr.toANSI w . prettyParseError src
@ -1276,19 +1274,18 @@ printNoteWithSource ::
(Var v, Annotated a, Show a, Ord a) =>
Env ->
String ->
Path.Absolute ->
Note v a ->
Pretty ColorText
printNoteWithSource env _s _curPath (TypeInfo n) = prettyTypeInfo n env
printNoteWithSource _env s _curPath (Parsing e) = prettyParseError s e
printNoteWithSource env s curPath (TypeError e) = prettyTypecheckError e env s curPath
printNoteWithSource _env _s _curPath (NameResolutionFailures _es) = undefined
printNoteWithSource _env s _curPath (UnknownSymbol v a) =
printNoteWithSource env _s (TypeInfo n) = prettyTypeInfo n env
printNoteWithSource _env s (Parsing e) = prettyParseError s e
printNoteWithSource env s (TypeError e) = prettyTypecheckError e env s
printNoteWithSource _env _s (NameResolutionFailures _es) = undefined
printNoteWithSource _env s (UnknownSymbol v a) =
fromString ("Unknown symbol `" ++ Text.unpack (Var.name v) ++ "`\n\n")
<> annotatedAsErrorSite s a
printNoteWithSource env s _curPath (CompilerBug (Result.TypecheckerBug c)) =
printNoteWithSource env s (CompilerBug (Result.TypecheckerBug c)) =
renderCompilerBug env s c
printNoteWithSource _env _s _curPath (CompilerBug c) =
printNoteWithSource _env _s (CompilerBug c) =
fromString $ "Compiler bug: " <> show c
_printPosRange :: String -> L.Pos -> L.Pos -> String
@ -1899,10 +1896,9 @@ prettyTypecheckError ::
C.ErrorNote v loc ->
Env ->
String ->
Path.Absolute ->
Pretty ColorText
prettyTypecheckError note env src curPath =
renderTypeError (typeErrorFromNote note) env src curPath
prettyTypecheckError note env src =
renderTypeError (typeErrorFromNote note) env src
prettyTypeInfo ::
(Var v, Ord loc, Show loc, Parser.Annotated loc) =>

View File

@ -12,7 +12,6 @@ import Text.RawString.QQ (r)
import Unison.Builtin qualified as Builtin
import Unison.Codebase.CodeLookup (CodeLookup (..))
import Unison.Codebase.CodeLookup.Util qualified as CL
import Unison.Codebase.Path qualified as Path
import Unison.ConstructorReference (GConstructorReference (..))
import Unison.DataDeclaration qualified as DD
import Unison.DataDeclaration.ConstructorId qualified as DD
@ -1002,7 +1001,7 @@ type EitherResult = Either String TFile
showNotes :: (Foldable f) => String -> PrintError.Env -> f Note -> String
showNotes source env =
intercalateMap "\n\n" $ PrintError.renderNoteAsANSI 60 env source Path.absoluteEmpty
intercalateMap "\n\n" $ PrintError.renderNoteAsANSI 60 env source
ppEnv :: PPE.PrettyPrintEnv
ppEnv = PPE.makePPE (PPE.hqNamer 10 Builtin.names) PPE.dontSuffixify

View File

@ -1120,11 +1120,11 @@ notifyUser dir = \case
]
ParseErrors src es ->
pure . P.sep "\n\n" $ prettyParseError (Text.unpack src) <$> es
TypeErrors curPath src ppenv notes -> do
TypeErrors _curPath src ppenv notes -> do
let showNote =
intercalateMap "\n\n" (printNoteWithSource ppenv (Text.unpack src) curPath)
intercalateMap "\n\n" (printNoteWithSource ppenv (Text.unpack src))
. map Result.TypeError
pure . showNote $ notes
pure $ showNote notes
CompilerBugs src env bugs -> pure $ intercalateMap "\n\n" bug bugs
where
bug = renderCompilerBug env (Text.unpack src)
@ -2296,30 +2296,30 @@ prettyUploadEntitiesError = \case
prettyValidationFailure :: Share.EntityValidationError -> Pretty
prettyValidationFailure = \case
Share.EntityHashMismatch entityType (Share.HashMismatchForEntity{supplied, computed}) ->
P.lines
[ P.wrap $ "The hash associated with the given " <> prettyEntityType entityType <> " entity is incorrect.",
"",
P.wrap $ "The associated hash is: " <> prettyHash32 supplied,
P.wrap $ "The computed hash is: " <> prettyHash32 computed
]
Share.UnsupportedEntityType hash32 entityType ->
P.lines
[ P.wrap $ "The entity with hash " <> prettyHash32 hash32 <> " of type " <> prettyEntityType entityType <> " is not supported by your version of ucm.",
P.wrap $ "Try upgrading to the latest version of ucm."
]
Share.InvalidByteEncoding hash32 entityType msg ->
P.lines
[ P.wrap $ "Failed to decode a " <> prettyEntityType entityType <> " entity with the hash " <> prettyHash32 hash32 <> ".",
"Please create an issue and report this to the Unison team",
"",
P.wrap $ "The error was: " <> P.text msg
]
Share.HashResolutionFailure hash32 ->
P.lines
[ P.wrap $ "Failed to resolve a referenced hash when validating the hash for " <> prettyHash32 hash32 <> ".",
"Please create an issue and report this to the Unison team"
]
Share.EntityHashMismatch entityType (Share.HashMismatchForEntity {supplied, computed}) ->
P.lines
[ P.wrap $ "The hash associated with the given " <> prettyEntityType entityType <> " entity is incorrect.",
"",
P.wrap $ "The associated hash is: " <> prettyHash32 supplied,
P.wrap $ "The computed hash is: " <> prettyHash32 computed
]
Share.UnsupportedEntityType hash32 entityType ->
P.lines
[ P.wrap $ "The entity with hash " <> prettyHash32 hash32 <> " of type " <> prettyEntityType entityType <> " is not supported by your version of ucm.",
P.wrap $ "Try upgrading to the latest version of ucm."
]
Share.InvalidByteEncoding hash32 entityType msg ->
P.lines
[ P.wrap $ "Failed to decode a " <> prettyEntityType entityType <> " entity with the hash " <> prettyHash32 hash32 <> ".",
"Please create an issue and report this to the Unison team",
"",
P.wrap $ "The error was: " <> P.text msg
]
Share.HashResolutionFailure hash32 ->
P.lines
[ P.wrap $ "Failed to resolve a referenced hash when validating the hash for " <> prettyHash32 hash32 <> ".",
"Please create an issue and report this to the Unison team"
]
where
prettyEntityType = \case
Share.TermComponentType -> "term component"
@ -2737,7 +2737,7 @@ renderEditConflicts ppe Patch {..} = do
then "deprecated and also replaced with"
else "replaced with"
)
`P.hang` P.lines replacements
`P.hang` P.lines replacements
formatTermEdits ::
(Reference.TermReference, Set TermEdit.TermEdit) ->
Numbered Pretty
@ -2752,7 +2752,7 @@ renderEditConflicts ppe Patch {..} = do
then "deprecated and also replaced with"
else "replaced with"
)
`P.hang` P.lines replacements
`P.hang` P.lines replacements
formatConflict ::
Either
(Reference, Set TypeEdit.TypeEdit)

View File

@ -27,7 +27,6 @@ import Unison.ABT qualified as ABT
import Unison.Cli.TypeCheck (computeTypecheckingEnvironment)
import Unison.Cli.UniqueTypeGuidLookup qualified as Cli
import Unison.Codebase qualified as Codebase
import Unison.Codebase.Path qualified as Path
import Unison.DataDeclaration qualified as DD
import Unison.Debug qualified as Debug
import Unison.FileParsers (ShouldUseTndr (..))
@ -208,7 +207,6 @@ getTokenMap tokens =
analyseNotes :: (Foldable f) => Uri -> PrettyPrintEnv -> String -> f (Note Symbol Ann) -> Lsp ([Diagnostic], [RangedCodeAction])
analyseNotes fileUri ppe src notes = do
currentPath <- getCurrentPath
flip foldMapM notes \note -> case note of
Result.TypeError errNote@(Context.ErrorNote {cause}) -> do
let typeErr = TypeError.typeErrorFromNote errNote
@ -262,7 +260,7 @@ analyseNotes fileUri ppe src notes = do
shouldHaveBeenHandled e = do
Debug.debugM Debug.LSP "This diagnostic should have been handled by a previous case but was not" e
empty
diags = noteDiagnostic currentPath note ranges
diags = noteDiagnostic note ranges
-- Sort on match accuracy first, then name.
codeActions <- case cause of
Context.UnknownTerm _ v suggestions typ -> do
@ -274,7 +272,7 @@ analyseNotes fileUri ppe src notes = do
pure (diags, codeActions)
Result.NameResolutionFailures {} -> do
-- TODO: diagnostics/code actions for resolution failures
pure (noteDiagnostic currentPath note todoAnnotation, [])
pure (noteDiagnostic note todoAnnotation, [])
Result.Parsing err -> do
let diags = do
(errMsg, ranges) <- PrintError.renderParseErrors src err
@ -284,7 +282,7 @@ analyseNotes fileUri ppe src notes = do
-- TODO: Some parsing errors likely have reasonable code actions
pure (diags, [])
Result.UnknownSymbol _ loc ->
pure (noteDiagnostic currentPath note (singleRange loc), [])
pure (noteDiagnostic note (singleRange loc), [])
Result.TypeInfo {} ->
-- No relevant diagnostics from type info.
pure ([], [])
@ -307,7 +305,7 @@ analyseNotes fileUri ppe src notes = do
Context.UnknownExistentialVariable _sym _con -> todoAnnotation
Context.IllegalContextExtension _con _el _s -> todoAnnotation
Context.OtherBug _s -> todoAnnotation
pure (noteDiagnostic currentPath note ranges, [])
pure (noteDiagnostic note ranges, [])
where
-- Diagnostics with this return value haven't been properly configured yet.
todoAnnotation = []
@ -325,7 +323,6 @@ analyseNotes fileUri ppe src notes = do
withNeighbours (a : as) = (a, as) : (second (a :) <$> withNeighbours as)
-- Builds diagnostics for a note, one diagnostic per range.
noteDiagnostic ::
Path.Absolute ->
Note Symbol Ann ->
-- All ranges affected by this note, each range may have references to 'related'
-- ranges.
@ -333,8 +330,8 @@ analyseNotes fileUri ppe src notes = do
-- other conflicted name locations.
[(Range, [(Text, Range)])] ->
[Diagnostic]
noteDiagnostic currentPath note ranges =
let msg = Text.pack $ Pretty.toPlain 80 $ PrintError.printNoteWithSource ppe src currentPath note
noteDiagnostic note ranges =
let msg = Text.pack $ Pretty.toPlain 80 $ PrintError.printNoteWithSource ppe src note
in do
(range, references) <- ranges
pure $ mkDiagnostic fileUri range DiagnosticSeverity_Error msg references