Skip to content

Commit d1a1471

Browse files
authored
Merge branch 'master' into fix/flaky-hie-bios-test
2 parents 801e365 + a734e1a commit d1a1471

15 files changed

+109
-61
lines changed

.github/workflows/bench.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
# change of the strategy may require changing the bootstrapping/run code
5757

5858
steps:
59-
- uses: actions/checkout@v4
59+
- uses: actions/checkout@v3
6060
with:
6161

6262
# By default, the `pull_request` event has a `GITHUB_SHA` env variable

.github/workflows/caching.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
should_skip: ${{ steps.skip_check.outputs.should_skip }}
5959
steps:
6060
# Need the repo checked out in order to read the file
61-
- uses: actions/checkout@v4
61+
- uses: actions/checkout@v3
6262
- id: ghcs
6363
run: echo "ghcs=$(cat ./.github/workflows/supported-ghc-versions.json)" >> $GITHUB_OUTPUT
6464
- id: skip_check
@@ -91,7 +91,7 @@ jobs:
9191
- macOS-latest
9292
- windows-latest
9393
steps:
94-
- uses: actions/checkout@v4
94+
- uses: actions/checkout@v3
9595

9696
- uses: ./.github/actions/setup-build
9797
with:

.github/workflows/flags.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
should_skip: ${{ steps.skip_check.outputs.should_skip }}
2323
steps:
2424
# Need the repo checked out in order to read the file
25-
- uses: actions/checkout@v4
25+
- uses: actions/checkout@v3
2626
- id: ghcs
2727
run: echo "ghcs=$(cat ./.github/workflows/supported-ghc-versions.json)" >> $GITHUB_OUTPUT
2828
- id: skip_check
@@ -54,7 +54,7 @@ jobs:
5454
- ubuntu-latest
5555

5656
steps:
57-
- uses: actions/checkout@v4
57+
- uses: actions/checkout@v3
5858
with:
5959

6060
# By default, the `pull_request` event has a `GITHUB_SHA` env variable

.github/workflows/hlint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
name: "Hlint check run"
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v4
13+
- uses: actions/checkout@v3
1414

1515
- name: 'Installing'
1616
uses: rwe/actions-hlint-setup@v1

.github/workflows/nix.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
os: [ubuntu-latest, macOS-latest]
5454

5555
steps:
56-
- uses: actions/checkout@v4
56+
- uses: actions/checkout@v3
5757

5858
- uses: cachix/install-nix-action@v23
5959
with:
@@ -85,7 +85,7 @@ jobs:
8585
os: [ubuntu-latest, macOS-latest]
8686

8787
steps:
88-
- uses: actions/checkout@v4
88+
- uses: actions/checkout@v3
8989

9090
- uses: cachix/install-nix-action@v23
9191
with:

.github/workflows/pre-commit.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
git-diff: ${{ steps.git-diff.outputs.diff }}
1313
steps:
1414
- name: Checkout code
15-
uses: actions/checkout@v4
15+
uses: actions/checkout@v3
1616
- name: Find changed files
1717
uses: technote-space/[email protected]
1818
id: git-diff
@@ -23,7 +23,7 @@ jobs:
2323
runs-on: ubuntu-latest
2424
needs: file-diff
2525
steps:
26-
- uses: actions/checkout@v4
26+
- uses: actions/checkout@v3
2727
- uses: ./.github/actions/setup-build
2828
with:
2929
# select a stable GHC version

.github/workflows/release.yaml

+16-16
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ jobs:
168168
echo "ID=linux" >> /etc/os-release
169169
echo "PRETTY_NAME=Linux" >> /etc/os-release
170170
171-
- uses: actions/checkout@v4
171+
- uses: actions/checkout@v3
172172

173173
- name: Run build
174174
run: |
@@ -226,7 +226,7 @@ jobs:
226226
shell: bash
227227

228228
- name: Checkout code
229-
uses: actions/checkout@v4
229+
uses: actions/checkout@v3
230230

231231
- uses: docker://hasufell/arm64v8-ubuntu-haskell:focal
232232
name: Run build (aarch64 linux)
@@ -276,7 +276,7 @@ jobs:
276276
ghc: ["9.6.2", "9.4.7", "9.2.8", "9.0.2"]
277277
steps:
278278
- name: Checkout code
279-
uses: actions/checkout@v4
279+
uses: actions/checkout@v3
280280

281281
- name: Run build
282282
run: |
@@ -321,7 +321,7 @@ jobs:
321321
ghc: ["9.6.2", "9.4.7", "9.2.8"]
322322
steps:
323323
- name: Checkout code
324-
uses: actions/checkout@v4
324+
uses: actions/checkout@v3
325325

326326
- name: Run build
327327
run: |
@@ -374,7 +374,7 @@ jobs:
374374
taskkill /F /FI "MODULES eq msys-2.0.dll"
375375
376376
- name: Checkout code
377-
uses: actions/checkout@v4
377+
uses: actions/checkout@v3
378378

379379
- name: Run build (windows)
380380
run: |
@@ -483,7 +483,7 @@ jobs:
483483
echo "ID=linux" >> /etc/os-release
484484
echo "PRETTY_NAME=Linux" >> /etc/os-release
485485
486-
- uses: actions/checkout@v4
486+
- uses: actions/checkout@v3
487487

488488
- uses: actions/download-artifact@v3
489489
with:
@@ -535,7 +535,7 @@ jobs:
535535
git config --global --get-all safe.directory | grep '^\*$' || git config --global --add safe.directory "*"
536536
shell: bash
537537

538-
- uses: actions/checkout@v4
538+
- uses: actions/checkout@v3
539539

540540
- uses: actions/download-artifact@v3
541541
with:
@@ -574,7 +574,7 @@ jobs:
574574
ARCH: 64
575575
ARTIFACT: "x86_64-apple-darwin"
576576
steps:
577-
- uses: actions/checkout@v4
577+
- uses: actions/checkout@v3
578578

579579
- uses: actions/download-artifact@v3
580580
with:
@@ -612,7 +612,7 @@ jobs:
612612
ARCH: ARM64
613613
ARTIFACT: "aarch64-apple-darwin"
614614
steps:
615-
- uses: actions/checkout@v4
615+
- uses: actions/checkout@v3
616616

617617
- uses: actions/download-artifact@v3
618618
with:
@@ -664,7 +664,7 @@ jobs:
664664
C:\msys64\usr\bin\bash -lc "pacman --disable-download-timeout --noconfirm -S unzip zip git"
665665
taskkill /F /FI "MODULES eq msys-2.0.dll"
666666
667-
- uses: actions/checkout@v4
667+
- uses: actions/checkout@v3
668668

669669
- uses: actions/download-artifact@v3
670670
with:
@@ -778,7 +778,7 @@ jobs:
778778
echo "ID=linux" >> /etc/os-release
779779
echo "PRETTY_NAME=Linux" >> /etc/os-release
780780
781-
- uses: actions/checkout@v4
781+
- uses: actions/checkout@v3
782782

783783
- uses: actions/download-artifact@v3
784784
with:
@@ -814,7 +814,7 @@ jobs:
814814
shell: bash
815815

816816
- name: Checkout code
817-
uses: actions/checkout@v4
817+
uses: actions/checkout@v3
818818

819819
- uses: actions/download-artifact@v3
820820
with:
@@ -838,7 +838,7 @@ jobs:
838838
DISTRO: na
839839
steps:
840840
- name: Checkout code
841-
uses: actions/checkout@v4
841+
uses: actions/checkout@v3
842842

843843
- uses: actions/download-artifact@v3
844844
with:
@@ -863,7 +863,7 @@ jobs:
863863
HOMEBREW_CHANGE_ARCH_TO_ARM: 1
864864
steps:
865865
- name: Checkout code
866-
uses: actions/checkout@v4
866+
uses: actions/checkout@v3
867867

868868
- uses: actions/download-artifact@v3
869869
with:
@@ -902,7 +902,7 @@ jobs:
902902
taskkill /F /FI "MODULES eq msys-2.0.dll"
903903
904904
- name: Checkout code
905-
uses: actions/checkout@v4
905+
uses: actions/checkout@v3
906906

907907
- uses: actions/download-artifact@v3
908908
with:
@@ -923,7 +923,7 @@ jobs:
923923
if: startsWith(github.ref, 'refs/tags/')
924924
steps:
925925
- name: Checkout code
926-
uses: actions/checkout@v4
926+
uses: actions/checkout@v3
927927

928928
- uses: actions/download-artifact@v3
929929
with:

.github/workflows/test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
ghcs: ${{ steps.ghcs.outputs.ghcs }}
2424
steps:
2525
# Need the repo checked out in order to read the file
26-
- uses: actions/checkout@v4
26+
- uses: actions/checkout@v3
2727
- id: ghcs
2828
run: echo "ghcs=$(cat ./.github/workflows/supported-ghc-versions.json)" >> $GITHUB_OUTPUT
2929
- id: skip_check
@@ -83,7 +83,7 @@ jobs:
8383
test: true
8484

8585
steps:
86-
- uses: actions/checkout@v4
86+
- uses: actions/checkout@v3
8787

8888
- uses: ./.github/actions/setup-build
8989
with:

plugins/hls-explicit-imports-plugin/src/Ide/Plugin/ExplicitImports.hs

+35-32
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import qualified Data.IntMap as IM (IntMap, elems,
2929
fromList, (!?))
3030
import Data.IORef (readIORef)
3131
import qualified Data.Map.Strict as Map
32-
import Data.Maybe (mapMaybe)
32+
import Data.Maybe (isNothing, mapMaybe)
3333
import qualified Data.Set as S
3434
import Data.String (fromString)
3535
import qualified Data.Text as T
@@ -316,42 +316,32 @@ minimalImportsRule recorder modFilter = defineNoDiagnostics (cmapWithPrio LogSha
316316
return $ mi_exports $ hirModIface imp_hir
317317

318318
-- Use the GHC api to extract the "minimal" imports
319-
(imports, mbMinImports) <- MaybeT $ liftIO $ extractMinimalImports hsc tmr
319+
locationImportWithMinimal <- MaybeT $ liftIO $ extractMinimalImports hsc tmr
320320

321-
let importsMap =
322-
Map.fromList
323-
[ (realSrcSpanStart l, printOutputable i)
324-
| L (locA -> RealSrcSpan l _) i <- mbMinImports
325-
]
326-
minimalImportsResult =
327-
[ (range, (minImport, ExplicitImport))
328-
| imp@(L _ impDecl) <- imports
321+
let minimalImportsResult =
322+
[ (range, (printOutputable minImport, ExplicitImport))
323+
| (location, impDecl, minImport) <- locationImportWithMinimal
329324
, not (isQualifiedImport impDecl)
330325
, not (isExplicitImport impDecl)
331326
, let L _ moduleName = ideclName impDecl
332327
, modFilter moduleName
333-
, RealSrcSpan location _ <- [getLoc imp]
334-
, let range = realSrcSpanToRange location
335-
, Just minImport <- [Map.lookup (realSrcSpanStart location) importsMap]
336-
]
328+
, let range = realSrcSpanToRange location]
329+
337330
refineImportsResult =
338331
[ (range, (T.intercalate "\n"
339-
. map (printOutputable . constructImport i)
332+
. map (printOutputable . constructImport origImport minImport)
340333
. Map.toList
341334
$ filteredInnerImports, RefineImport))
342335
-- for every minimal imports
343-
| minImports <- [mbMinImports]
344-
, i@(L _ ImportDecl{ideclName = L _ mn}) <- minImports
336+
| (location, origImport, minImport@(ImportDecl{ideclName = L _ mn})) <- locationImportWithMinimal
345337
-- (almost) no one wants to see an refine import list for Prelude
346338
, mn /= moduleName pRELUDE
347339
-- we check for the inner imports
348340
, Just innerImports <- [Map.lookup mn import2Map]
349341
-- and only get those symbols used
350-
, Just filteredInnerImports <- [filterByImport i innerImports]
342+
, Just filteredInnerImports <- [filterByImport minImport innerImports]
351343
-- if no symbols from this modules then don't need to generate new import
352344
, not $ null filteredInnerImports
353-
-- get the location
354-
, RealSrcSpan location _ <- [getLoc i]
355345
-- and then convert that to a Range
356346
, let range = realSrcSpanToRange location
357347
]
@@ -370,7 +360,7 @@ minimalImportsRule recorder modFilter = defineNoDiagnostics (cmapWithPrio LogSha
370360
extractMinimalImports ::
371361
HscEnvEq ->
372362
TcModuleResult ->
373-
IO (Maybe ([LImportDecl GhcRn], [LImportDecl GhcRn]))
363+
IO (Maybe [(RealSrcSpan, ImportDecl GhcRn, ImportDecl GhcRn)])
374364
extractMinimalImports hsc TcModuleResult {..} = runMaybeT $ do
375365
-- extract the original imports and the typechecking environment
376366
let tcEnv = tmrTypechecked
@@ -391,8 +381,17 @@ extractMinimalImports hsc TcModuleResult {..} = runMaybeT $ do
391381
(_, Just minimalImports) <- liftIO $
392382
initTcWithGbl (hscEnv hsc) tcEnv srcSpan $ getMinimalImports usage
393383

384+
let minimalImportsMap =
385+
Map.fromList
386+
[ (realSrcSpanStart l, impDecl)
387+
| L (locA -> RealSrcSpan l _) impDecl <- minimalImports
388+
]
389+
results =
390+
[ (location, imp, minImport)
391+
| L (locA -> RealSrcSpan location _) imp <- imports
392+
, Just minImport <- [Map.lookup (realSrcSpanStart location) minimalImportsMap]]
394393
-- return both the original imports and the computed minimal ones
395-
return (imports, minimalImports)
394+
return results
396395
where
397396
notExported :: [String] -> LImportDecl GhcRn -> Bool
398397
notExported [] _ = True
@@ -451,11 +450,11 @@ abbreviateImportTitle input =
451450
--------------------------------------------------------------------------------
452451

453452

454-
filterByImport :: LImportDecl GhcRn -> Map.Map ModuleName [AvailInfo] -> Maybe (Map.Map ModuleName [AvailInfo])
453+
filterByImport :: ImportDecl GhcRn -> Map.Map ModuleName [AvailInfo] -> Maybe (Map.Map ModuleName [AvailInfo])
455454
#if MIN_VERSION_ghc(9,5,0)
456-
filterByImport (L _ ImportDecl{ideclImportList = Just (_, L _ names)})
455+
filterByImport (ImportDecl{ideclImportList = Just (_, L _ names)})
457456
#else
458-
filterByImport (L _ ImportDecl{ideclHiding = Just (_, L _ names)})
457+
filterByImport (ImportDecl{ideclHiding = Just (_, L _ names)})
459458
#endif
460459
avails =
461460
-- if there is a function defined in the current module and is used
@@ -474,18 +473,22 @@ filterByImport (L _ ImportDecl{ideclHiding = Just (_, L _ names)})
474473
$ Map.elems res
475474
filterByImport _ _ = Nothing
476475

477-
constructImport :: LImportDecl GhcRn -> (ModuleName, [AvailInfo]) -> LImportDecl GhcRn
476+
constructImport :: ImportDecl GhcRn -> ImportDecl GhcRn -> (ModuleName, [AvailInfo]) -> ImportDecl GhcRn
478477
#if MIN_VERSION_ghc(9,5,0)
479-
constructImport (L lim imd@ImportDecl {ideclName = L _ _, ideclImportList = Just (hiding, L _ names)})
478+
constructImport ImportDecl{ideclQualified = qualified, ideclImportList = origHiding} imd@ImportDecl{ideclImportList = Just (hiding, L _ names)}
480479
#else
481-
constructImport (L lim imd@ImportDecl{ideclName = L _ _, ideclHiding = Just (hiding, L _ names)})
480+
constructImport ImportDecl{ideclQualified = qualified, ideclHiding = origHiding} imd@ImportDecl{ideclHiding = Just (hiding, L _ names)}
482481
#endif
483-
(newModuleName, avails) = L lim imd
482+
(newModuleName, avails) = imd
484483
{ ideclName = noLocA newModuleName
485484
#if MIN_VERSION_ghc(9,5,0)
486-
, ideclImportList = Just (hiding, noLocA newNames)
485+
, ideclImportList = if isNothing origHiding && qualified /= NotQualified
486+
then Nothing
487+
else Just (hiding, noLocA newNames)
487488
#else
488-
, ideclHiding = Just (hiding, noLocA newNames)
489+
, ideclHiding = if isNothing origHiding && qualified /= NotQualified
490+
then Nothing
491+
else Just (hiding, noLocA newNames)
489492
#endif
490493
}
491494
where newNames = filter (\n -> any (n `containsAvail`) avails) names
@@ -495,4 +498,4 @@ constructImport (L lim imd@ImportDecl{ideclName = L _ _, ideclHiding = Just (hid
495498
any (\an -> printOutputable an == (printOutputable . ieName . unLoc $ name))
496499
$ availNamesWithSelectors avail
497500

498-
constructImport lim _ = lim
501+
constructImport _ lim _ = lim

plugins/hls-explicit-imports-plugin/test/Main.hs

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ main = defaultTestRunner $ testGroup "import-actions"
3131
"Refine Imports"
3232
[ codeActionGoldenTest "RefineWithOverride" 3 1
3333
, codeLensGoldenTest isRefineImports "RefineUsualCase" 1
34+
, codeLensGoldenTest isRefineImports "RefineQualified" 0
35+
, codeLensGoldenTest isRefineImports "RefineQualifiedExplicit" 0
3436
],
3537
testGroup
3638
"Make imports explicit"

0 commit comments

Comments
 (0)