Skip to content

Commit

Permalink
Fix diagnostic still reporting when no unused bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPenner committed Jul 5, 2024
1 parent 0587dde commit dd17539
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/unison-prelude/src/Unison/Debug.hs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ debugPatternCoverageConstraintSolver = PatternCoverageConstraintSolver `Set.memb
debug :: (Show a) => DebugFlag -> String -> a -> a
debug flag msg a =
if shouldDebug flag
then (pTrace (msg <> ":\n" <> into @String (pShow a)) a)
then (trace (msg <> ":\n" <> into @String (pShow a)) a)
else a

-- | Use for selective debug logging in monadic contexts.
Expand Down
8 changes: 6 additions & 2 deletions unison-cli/src/Unison/LSP/FileAnalysis/UnusedBindings.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Unison.Parser.Ann (Ann)
import Unison.Prelude
import Unison.Symbol (Symbol (..))
import Unison.Term (Term)
import Unison.Util.Monoid qualified as Monoid
import Unison.Util.Range qualified as Range
import Unison.Var qualified as Var

Expand All @@ -34,14 +35,17 @@ analyseTerm fileUri topLevelTermAnn tm =
Nothing -> []
Just lspRange ->
let bindings = Text.intercalate ", " (tShow <$> vars)
in [Diagnostic.mkDiagnostic fileUri lspRange Diagnostic.DiagnosticSeverity_Warning ("Unused binding(s) " <> bindings <> " inside this term.\nUse the binding, or prefix it with an _ to dismiss this warning.") []]
in Monoid.whenM (not $ null vars) [Diagnostic.mkDiagnostic fileUri lspRange Diagnostic.DiagnosticSeverity_Warning ("Unused binding(s) " <> bindings <> " inside this term.\nUse the binding(s), or prefix them with an _ to dismiss this warning.") []]
where
getRelevantVarName :: Symbol -> Maybe Text
getRelevantVarName = \case
-- Sometimes 'do' gets a binding of '()', which we don't care about
Symbol _ (Var.User "()") -> Nothing
Symbol _ (Var.User "") -> Nothing
-- We only care about user bindings which don't start with an underscore
Symbol _ (Var.User n) -> do
guard (not (Text.isPrefixOf "_" n))
pure n
Just n
_ -> Nothing
alg :: (Foldable f, Ord v) => Ann -> ABT f v (Map v Ann, Set v) -> (Map v Ann, Set v)
alg ann abt = case abt of
Expand Down

0 comments on commit dd17539

Please sign in to comment.