Commit 7538517
committed
feat: introduce import suggestion for coerce
In a context where we want to `coerce` to a type for which constructor
is not in scope, GHC fails with (e.g., for `Sum Int`):
```
• Couldn't match representation of type ‘Int’ with that of ‘Sum Int’
arising from a use of ‘coerce’
The data constructor ‘base-4.18.2.1:Data.Semigroup.Internal.Sum’
of newtype ‘Sum’ is not in scope
```
This code action detects the missing `newtype` and suggests to add the
required import.
This is convenient because otherwise the user need to interpret the
error message and most of the time manually find which module and type to import.
Note that a better implementation could try to decet that the type is
already imported (if that's the case) and just suggest to add the
constructor (e.g. `(..)`) in the import list, but this is too much
complexity to implement. It could lead to duplicated import lines which
will be "cleaned" by formatter or other extensions.1 parent a154cd6 commit 7538517
File tree
2 files changed
+27
-0
lines changed- plugins/hls-refactor-plugin
- src/Development/IDE/Plugin
- test
2 files changed
+27
-0
lines changedLines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1840 | 1840 | | |
1841 | 1841 | | |
1842 | 1842 | | |
| 1843 | + | |
| 1844 | + | |
1843 | 1845 | | |
1844 | 1846 | | |
1845 | 1847 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
| 303 | + | |
303 | 304 | | |
304 | 305 | | |
305 | 306 | | |
| |||
1871 | 1872 | | |
1872 | 1873 | | |
1873 | 1874 | | |
| 1875 | + | |
| 1876 | + | |
| 1877 | + | |
| 1878 | + | |
| 1879 | + | |
| 1880 | + | |
| 1881 | + | |
| 1882 | + | |
| 1883 | + | |
| 1884 | + | |
| 1885 | + | |
| 1886 | + | |
| 1887 | + | |
| 1888 | + | |
| 1889 | + | |
| 1890 | + | |
| 1891 | + | |
| 1892 | + | |
| 1893 | + | |
| 1894 | + | |
| 1895 | + | |
| 1896 | + | |
| 1897 | + | |
| 1898 | + | |
1874 | 1899 | | |
1875 | 1900 | | |
1876 | 1901 | | |
| |||
0 commit comments