Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggest import for name causing a UnknownName error #3716

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

csicar
Copy link

@csicar csicar commented Aug 16, 2019

This PR adds the adds a Hint to the UnknownName error, if a module exports the same name. It (should) support all names including types, type classes, values etc.

Changes

  • addition of a new Hint for UnknownName
  • renderning for the hint
  • call to add these suggestions in Make.make
  • add module for future suggestions

ToDos

  • Move from Hint to Field on UnknownName (to support JSON error suggestions)
  • Check performance. If needed limit search / build map from Name to possible imports
  • SourceSpans
  • Reuse existing imports if possible: E.g. if Prelude (map) is already imported, suggest Prelude (map, class Show)

If there is interest in this, I'll implement these ToDos.
Ensuring, that the value has the correct type would be nice but seems quite involved, as none of the data structures available at the necessary places seem to have type information available.

Example:

Error 3 of 4:

  in module Data.DotLang.Attr.Edge
  at src/Data/DotLang/Attr/Edge.purs:22:1 - 23:21 (line 22, column 1 - line 23, column 21)

    Unknown type class Show

  Perhaps you want to add it to the import list? 2 possible imports were found:
                                 
    import Data.Show (class Show)
    import Prelude (class Show)  
                                 

  See https://github.com/purescript/documentation/blob/master/errors/UnknownName.md for more information,
  or to contribute content related to this error.

@csicar
Copy link
Author

csicar commented Aug 16, 2019

stack test is passing all 904 tests

Previously errorSuggestion returned `(Just "")` for UnusedImport and
DuplicateImport and `Nothing` for any other ErrorMessage that has no
suggestions. Both `Just ""` and `Nothing` seem to be treated the same
and represented as `""` in the rendered versions.

The matching imports suggestions for UnknownName now are represented as
seperate suggestions, which allow for proper rendering.

The JSON represenation of multiple suggestions is still a single string,
as changing that would require changing the JSON schema.
to reflect the changed return type. Imports and shadowing were also
cleaned up.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant