Skip to content

[plugin][refine-import] Do not refine to Internal module #1832

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

Closed

Conversation

rayshih
Copy link
Contributor

@rayshih rayshih commented May 14, 2021

So we shouldn't refine imports to use internal modules, for example the following should not happen:

import H

refined to

import H.Internal (h)

corresponding test attached :)

-- directly
let notContainInternalModule :: [AvailInfo] -> Bool
notContainInternalModule = not . any (\a ->
"Internal" `isSuffixOf` prettyPrint (availName a))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't be too hard to add configuration for the internal suffix - @berberman and @isovector are the experts

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, an example of Properties in type lenses plugin:

descriptor :: PluginId -> PluginDescriptor IdeState
descriptor plId =
(defaultPluginDescriptor plId)
{ pluginHandlers = mkPluginHandler STextDocumentCodeLens codeLensProvider
, pluginCommands = [PluginCommand (CommandId typeLensCommandId) "adds a signature" commandHandler]
, pluginRules = rules
, pluginConfigDescriptor = defaultConfigDescriptor {configCustomConfig = mkCustomConfig properties}
}
properties :: Properties '[ 'PropertyKey "mode" ('TEnum Mode)]
properties = emptyProperties
& defineEnumProperty #mode "Control how type lenses are shown"
[ (Always, "Always displays type lenses of global bindings")
, (Exported, "Only display type lenses of exported global bindings")
, (Diagnostics, "Follows error messages produced by GHC about missing signatures")
] Always
codeLensProvider ::
IdeState ->
PluginId ->
CodeLensParams ->
LSP.LspM Config (Either ResponseError (List CodeLens))
codeLensProvider ideState pId CodeLensParams{_textDocument = TextDocumentIdentifier uri} = do
mode <- usePropertyLsp #mode pId properties

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rayshih had the example above helped to implement the config of the internal suffix?

@jneira jneira added the status: needs info Not actionable, because there's missing information label Jun 22, 2021
@jneira
Copy link
Member

jneira commented Dec 15, 2021

@rayshih it seems it only needs make configurable the internal modules prefix, do you have still plans to continue working on this? thanks!

@Anton-Latukha Anton-Latukha changed the title [pluging][refine-import] Do not refine to Internal module [plugin][refine-import] Do not refine to Internal module Dec 20, 2021
@Anton-Latukha
Copy link
Collaborator

Anton-Latukha commented Dec 21, 2021

I would operate on the fact that rayshih contributed the PR but after that never responded to a request & rerequests.

I consider it as good. As it is an improvement. & I can understand the both design approaches, to encourage only recommended & to complicate the bad, and the approach to allow customization even if Internal is a bad practice...


What we currently have is done in the default way & seems to roughly cover the Pareto balance. In the majority of cases, we do want this default.

Generally, people indeed do not want/should not depend on Internal modules if that is possible (& that is what HLS should advise by default).

& in 20% of cases when they want to depend on Internal uncontrollable API - we initially can allow them to do that manually.
As it is said in the good tooling/language design - the good style should be encouraged, but the bad style should be discouraged (in this case requiring manual work that is also a statement person wants it & knows what is doing).

Why to avoid Internal?
Because: http://nikita-volkov.github.io/internal-convention-is-a-mistake/

@Anton-Latukha
Copy link
Collaborator

Anton-Latukha commented Dec 21, 2021

I would appeal to reason that to keep people away from refining into Internals is better than to allow them. As refining into Internal is simply dangerous - as Internal explicitly by own-put definition states that permanent refining behavior into it would mean to encourage refining into modules where changes would have no notification, no documentation, no support, no consistency or expectancy of API breakages.
& to reason in http://nikita-volkov.github.io/internal-convention-is-a-mistake

@Anton-Latukha
Copy link
Collaborator

Anton-Latukha commented Dec 21, 2021

When a contributor does not address a request - there is no way around it.

In that case it is useful to readdress the request to the community to decide if that would be needed enough to be implemented.

I relocated the request for the plugin customization option into report #2521.

Copy link
Collaborator

@Anton-Latukha Anton-Latukha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code seems simple enough that I can review it & the code is clear to me. Indeed even tests are there.

@jneira
Copy link
Member

jneira commented Dec 22, 2021

well I think configure the name schema to filter suggestions would generalise this nicely to "filter out modules which I don't want" in suggestions, for any reason, not only being internal
and it would allow to opt out at same time left the option null or blank

imo the last thing is required, as we are gonna change an actual behaviour and bother users who want to use internal modules

@michaelpj
Copy link
Collaborator

Closing as dead.

@michaelpj michaelpj closed this Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs info Not actionable, because there's missing information
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants