haskell / haskell/haskell-language-server

"Refine imports" code lens suggests to import internal module in multi-component project

Open
#2,851 2 comments 2 reactions 0 assignees View on GitHub
component: imports plugin multi-component type: bug
Dominant language
Haskell
Stars
3k
Forks
455
Avg merge
3d 21h
Merged PRs (30d)
13

Description

### Example

Project structure:
```
├── hls-issues.cabal
├── src
│ ├── Internal.hs
│ └── Lib.hs
└── test
└── Test.hs
```

#### Internal.hs

```hs
module Internal (example) where

example :: Int
example = 5
```

#### hls-issues.cabal

```
cabal-version: 2.4
name: hls-issues
version: 0.1.0.0

library
exposed-modules: Lib
other-modules:
Internal
build-depends: base ^>= 4.15, containers
hs-source-dirs: src
default-language: Haskell2010

test-suite test
hs-source-dirs: test
main-is: Test.hs
type: exitcode-stdio-1.0
build-depends: base ^>= 4.15, hls-issues
default-language: Haskell2010
```

#### Lib.hs

```hs
module Lib (example) where

import Internal
```

#### Test.hs

```hs
import Lib (example)

lol :: Int
lol = example
```

![image](https://user-images.githubusercontent.com/44230978/164944308-c33f7be8-4264-4f37-8516-5f80787b3a70.png)

HLS suggests to refine the imports to import `Internal`, eventhough `Internal` is not exposed from the library component and thus can't be used in the test suite.

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the issue with the supplied hls-issues.cabal project and its src/Internal.hs, src/Lib.hs, and test/Test.hs files. Start by tracing HLS's "Refine imports" code lens for the test component; done means it no longer suggests importing Internal when that module is not exposed by the library component.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.