This repository was archived by the owner on Jan 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 95
Code action to suggest adding missing imports from pkg db #437
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97fbbe2
to
d496231
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a nice feature, thank you!
Could you also add a test-case for this?
@@ -333,6 +347,37 @@ suggestSignature isQuickFix Diagnostic{_range=_range@Range{..},..} | |||
| otherwise = nm <> ty | |||
suggestSignature _ _ = [] | |||
|
|||
suggestNewImport :: ExternalPackageState -> ParsedModule -> Diagnostic -> [(T.Text, [TextEdit])] | |||
suggestNewImport eps ParsedModule {pm_parsed_source = L _ HsModule {..}} Diagnostic{_message} | |||
| Just [name, _typ] <- matchRegex (unifySpaces _message) "Variable not in scope: ([^ ]+) :: ([^*•]+)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GHC's error message does not always contain the type. E.g. in
foo = fromJust
The error reads
Variable not in scope: fromJust
This suggestion doesn't use the type anyway. Could you change the regex to make the type annotation optional?
d496231
to
b9ad57f
Compare
The implementation looks in modules loaded from the package database. It should only look in packages declared as dependencies of the project. The package modules are loaded lazily and are global to the HscEnv, so the success rate will depend on what has been loaded so far in the env.
> import Data.Text (Text) > foo = pack "foo" Teach ghcide to suggest only: "Add pack to the import list of Data.Text" and avoid suggesting also: "Import Data.Text (pack)"
b9ad57f
to
de333b7
Compare
aherrmann-da
approved these changes
Feb 18, 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, looks good!
pepeiborra
added a commit
to pepeiborra/ghcide
that referenced
this pull request
Feb 22, 2020
* Code action to suggest adding missing imports from pkg db The implementation looks in modules loaded from the package database. It should only look in packages declared as dependencies of the project. The package modules are loaded lazily and are global to the HscEnv, so the success rate will depend on what has been loaded so far in the env. * Avoid overlapping with extend import suggestions > import Data.Text (Text) > foo = pack "foo" Teach ghcide to suggest only: "Add pack to the import list of Data.Text" and avoid suggesting also: "Import Data.Text (pack)"
pepeiborra
added a commit
to pepeiborra/ide
that referenced
this pull request
Dec 29, 2020
…cide#437) * Code action to suggest adding missing imports from pkg db The implementation looks in modules loaded from the package database. It should only look in packages declared as dependencies of the project. The package modules are loaded lazily and are global to the HscEnv, so the success rate will depend on what has been loaded so far in the env. * Avoid overlapping with extend import suggestions > import Data.Text (Text) > foo = pack "foo" Teach ghcide to suggest only: "Add pack to the import list of Data.Text" and avoid suggesting also: "Import Data.Text (pack)"
pepeiborra
added a commit
to pepeiborra/ide
that referenced
this pull request
Dec 29, 2020
…cide#437) * Code action to suggest adding missing imports from pkg db The implementation looks in modules loaded from the package database. It should only look in packages declared as dependencies of the project. The package modules are loaded lazily and are global to the HscEnv, so the success rate will depend on what has been loaded so far in the env. * Avoid overlapping with extend import suggestions > import Data.Text (Text) > foo = pack "foo" Teach ghcide to suggest only: "Add pack to the import list of Data.Text" and avoid suggesting also: "Import Data.Text (pack)"
pepeiborra
added a commit
to pepeiborra/ide
that referenced
this pull request
Dec 29, 2020
…cide#437) * Code action to suggest adding missing imports from pkg db The implementation looks in modules loaded from the package database. It should only look in packages declared as dependencies of the project. The package modules are loaded lazily and are global to the HscEnv, so the success rate will depend on what has been loaded so far in the env. * Avoid overlapping with extend import suggestions > import Data.Text (Text) > foo = pack "foo" Teach ghcide to suggest only: "Add pack to the import list of Data.Text" and avoid suggesting also: "Import Data.Text (pack)"
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The implementation looks in modules loaded from the package database. It should
only look in packages declared as dependencies of the project. The package
modules are loaded lazily and are global to the HscEnv, so the success rate will
depend on what has been loaded so far in the env.
I intended to make this as a standalone plugin but we cannot have two plugins providing code actions, see haskell/haskell-language-server#25 (comment)