Skip to content

Suggesting "Hiding other imports"-like action when ambiguity includes local definition #2114

Closed
@Ailrun

Description

@Ailrun

Your environment

Output of haskell-language-server --probe-tools or haskell-language-server-wrapper --probe-tools:

haskell-language-server version: 1.3.0.0 (GHC: 9.0.1) (PATH: $PATH/haskell-language-server) (GIT hash: 2857eeece0398e1cd4b2ffb6069b05c4d2308b39)
Tool versions found on the $PATH
cabal:          3.4.0.0
stack:          2.7.1
ghc:            8.10.5

Which OS do you use: Manjaro

Which lsp-client do you use: Emacs

Describe your project (alternative: link to the project):

Contents of hie.yaml: Implicit

Steps to reproduce

With this file,

module Test where

useLex :: String
useLex = lex "" -- 'lex' can be either the local definition or 'Prelude.lex'.

lex :: String -> String
lex = id

HLS does not give "Use local, hiding imports" or similar, and just shows "Replace with qualified: Prelude.lex". This works well when ambiguity is caused by two imported definitions.

Expected behaviour

Described as above.

Actual behaviour

Described as above.

Related information

suggestImportDisambiguation ::
DynFlags ->
Maybe T.Text ->
ParsedSource ->
Diagnostic ->
[(T.Text, [Either TextEdit Rewrite])]
suggestImportDisambiguation df (Just txt) ps@(L _ HsModule {hsmodImports}) diag@Diagnostic {..}
| Just [ambiguous] <-
matchRegexUnifySpaces
_message
"Ambiguous occurrence ‘([^’]+)’"
, Just modules <-
map last
<$> allMatchRegexUnifySpaces _message "imported from ‘([^’]+)’" =
suggestions ambiguous modules

checks only "imported from ...", whereas the actual error message with local definition is "defined at ...".

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions