Skip to content

Commit 98554fe

Browse files
committed
Merge branch 'master' of https://github.com/haskell/haskell-ide-engine into completion-contexts
2 parents d53a0af + 6b606bc commit 98554fe

29 files changed

+443
-145
lines changed

.circleci/config.yml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ defaults: &defaults
2222

2323
- restore_cache:
2424
keys:
25-
- stack-cache-08-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "stack-build.txt" }}-{{ checksum "all-cabal.txt" }}
26-
- stack-cache-08-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "stack-build.txt" }}
27-
- stack-cache-08-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "resolver.txt" }}
25+
- stack-cache-10-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "stack-build.txt" }}-{{ checksum "all-cabal.txt" }}
26+
- stack-cache-10-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "stack-build.txt" }}
27+
- stack-cache-10-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "resolver.txt" }}
2828

2929
- run:
3030
name: Stack setup
@@ -50,8 +50,12 @@ defaults: &defaults
5050
name: Generate Hoogle database
5151
command: stack --stack-yaml=${STACK_FILE} exec hoogle generate
5252

53+
- run:
54+
name: Clear cabal-helper cache
55+
command: rm -fr ~/.cache/cabal-helper
56+
5357
- save_cache:
54-
key: stack-cache-08-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "resolver.txt" }}
58+
key: stack-cache-10-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "resolver.txt" }}
5559
paths:
5660
- ~/.stack
5761
- ~/.cache
@@ -72,7 +76,7 @@ defaults: &defaults
7276
path: test-logs
7377

7478
- save_cache:
75-
key: stack-cache-08-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "stack-build.txt" }}
79+
key: stack-cache-10-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "stack-build.txt" }}
7680
paths:
7781
- ~/.stack
7882
- ~/.cache
@@ -85,7 +89,7 @@ defaults: &defaults
8589
- ~/build/submodules/cabal-helper/.stack-work
8690

8791
- save_cache:
88-
key: stack-cache-08-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "stack-build.txt" }}-{{ checksum "all-cabal.txt" }}
92+
key: stack-cache-10-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "stack-build.txt" }}-{{ checksum "all-cabal.txt" }}
8993
paths:
9094
- ~/.stack
9195
- ~/.cache
@@ -124,6 +128,12 @@ jobs:
124128
- STACK_FILE: "stack-8.4.3.yaml"
125129
<<: *defaults
126130

131+
ghc-8.4.4:
132+
environment:
133+
- STACK_FILE: "stack-8.4.4.yaml"
134+
<<: *defaults
135+
136+
127137
ghc-nightly:
128138
environment:
129139
- STACK_FILE: "stack.yaml"
@@ -170,5 +180,6 @@ workflows:
170180
- ghc-8.2.2
171181
- ghc-8.4.2
172182
- ghc-8.4.3
183+
- ghc-8.4.4
173184
- ghc-nightly
174185
- cabal

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,4 @@ test-logs/
6363
.DS_Store
6464

6565
.hspec-failures
66+
/test/testdata/addPragmas/stack.yaml

Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ STACKLOCALBINDIR:=$(shell stack path --local-bin)
44
all: help
55
.PHONY: all
66

7-
## Builds hie for all supported GHC versions (8.2.1, 8.2.2, 8.4.2 and 8.4.3)
8-
build: hie-8.2.1 hie-8.2.2 hie-8.4.2 hie-8.4.3
7+
## Builds hie for all supported GHC versions (8.2.1, 8.2.2, 8.4.2 and 8.4.3, 8.4.4)
8+
build: hie-8.2.1 hie-8.2.2 hie-8.4.2 hie-8.4.3 hie-8.4.4
99
.PHONY: build
1010

1111
## Builds hie and hoogle databases for all supported GHC versions
@@ -48,6 +48,14 @@ hie-8.4.3: submodules
4848
&& cp '$(STACKLOCALBINDIR)/hie-8.4.3' '$(STACKLOCALBINDIR)/hie-8.4'
4949
.PHONY: hie-8.4.3
5050

51+
## Builds hie for GHC version 8.4.4 only
52+
hie-8.4.4: submodules
53+
stack --stack-yaml=stack-8.4.4.yaml build
54+
stack --stack-yaml=stack-8.4.4.yaml install \
55+
&& cp '$(STACKLOCALBINDIR)/hie' '$(STACKLOCALBINDIR)/hie-8.4.4' \
56+
&& cp '$(STACKLOCALBINDIR)/hie-8.4.4' '$(STACKLOCALBINDIR)/hie-8.4'
57+
.PHONY: hie-8.4.4
58+
5159
# ------------------------------------------------------
5260

5361
## Updates local git submodules

app/HieWrapper.hs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ main = do
5454

5555
run :: GlobalOpts -> IO ()
5656
run opts = do
57-
let mLogFileName = case optLogFile opts of
58-
Just f -> Just f
59-
Nothing -> Nothing
57+
let mLogFileName = optLogFile opts
6058

6159
logLevel = if optDebugOn opts
6260
then L.DEBUG
@@ -85,20 +83,18 @@ run opts = do
8583

8684
let
8785
hieBin = "hie-" ++ ghcVersion
88-
backupHieBin = "hie-" ++ reverse (tail $ dropWhile (/='.') $ reverse ghcVersion)
86+
backupHieBin = "hie-" ++ init (dropWhileEnd (/='.') ghcVersion)
87+
candidates' = [hieBin, backupHieBin, "hie"]
88+
candidates = map (++ exeExtension) candidates'
8989

90-
logm $ "hie exe candidates :" ++ show (hieBin,backupHieBin)
91-
92-
let candidates' = [hieBin, backupHieBin, "hie"]
93-
candidates = map (++ exeExtension) candidates'
90+
logm $ "hie exe candidates :" ++ show candidates
9491

9592
mexes <- traverse findExecutable candidates
9693

9794
case asum mexes of
9895
Nothing -> logm $ "cannot find any hie exe, looked for:" ++ intercalate ", " candidates
9996
Just e -> do
10097
logm $ "found hie exe at:" ++ e
101-
-- putStrLn $ "found hie exe at:" ++ e
10298
args <- getArgs
10399
logm $ "args:" ++ show args
104100
logm "launching ....\n\n\n"

app/MainHie.hs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ import qualified System.Remote.Monitoring.Wai as EKG
2727
-- plugins
2828

2929
import Haskell.Ide.Engine.Plugin.ApplyRefact
30+
import Haskell.Ide.Engine.Plugin.Base
3031
import Haskell.Ide.Engine.Plugin.Brittany
3132
import Haskell.Ide.Engine.Plugin.Build
32-
import Haskell.Ide.Engine.Plugin.Base
3333
import Haskell.Ide.Engine.Plugin.Example2
3434
import Haskell.Ide.Engine.Plugin.GhcMod
3535
import Haskell.Ide.Engine.Plugin.HaRe
36+
import Haskell.Ide.Engine.Plugin.Haddock
37+
import Haskell.Ide.Engine.Plugin.HfaAlign
3638
import Haskell.Ide.Engine.Plugin.Hoogle
3739
import Haskell.Ide.Engine.Plugin.HsImport
3840
import Haskell.Ide.Engine.Plugin.Liquid
3941
import Haskell.Ide.Engine.Plugin.Package
40-
import Haskell.Ide.Engine.Plugin.Haddock
41-
import Haskell.Ide.Engine.Plugin.HfaAlign
42-
42+
import Haskell.Ide.Engine.Plugin.Pragmas
4343

4444
-- ---------------------------------------------------------------------
4545

@@ -51,17 +51,18 @@ plugins includeExamples = pluginDescToIdePlugins allPlugins
5151
then basePlugins ++ examplePlugins
5252
else basePlugins
5353
basePlugins =
54-
[applyRefactDescriptor "applyrefact"
55-
,baseDescriptor "base"
56-
,brittanyDescriptor "brittany"
57-
,buildPluginDescriptor "build"
58-
,ghcmodDescriptor "ghcmod"
59-
,hareDescriptor "hare"
60-
,hoogleDescriptor "hoogle"
61-
,hsimportDescriptor "hsimport"
62-
,liquidDescriptor "liquid"
63-
,packageDescriptor "package"
64-
,haddockDescriptor "haddock"
54+
[ applyRefactDescriptor "applyrefact"
55+
, baseDescriptor "base"
56+
, brittanyDescriptor "brittany"
57+
, buildPluginDescriptor "build"
58+
, ghcmodDescriptor "ghcmod"
59+
, haddockDescriptor "haddock"
60+
, hareDescriptor "hare"
61+
, hoogleDescriptor "hoogle"
62+
, hsimportDescriptor "hsimport"
63+
, liquidDescriptor "liquid"
64+
, packageDescriptor "package"
65+
, pragmasDescriptor "pragmas"
6566
]
6667
examplePlugins =
6768
[example2Descriptor "eg2"
@@ -100,9 +101,7 @@ main = do
100101

101102
run :: GlobalOpts -> IO ()
102103
run opts = do
103-
let mLogFileName = case optLogFile opts of
104-
Just f -> Just f
105-
Nothing -> Nothing
104+
let mLogFileName = optLogFile opts
106105

107106
logLevel = if optDebugOn opts
108107
then L.DEBUG

docs/Hacking.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ To build and test with all of them, use
1717
make test
1818
```
1919

20+
Note that some tests require `liquid` binary to be present in your PATH.
21+
To install it follow the instructions in [liquidhaskell](https://github.com/ucsd-progsys/liquidhaskell/blob/develop/INSTALL.md).
22+
2023
To see what version/compiler you are running
2124

2225
```bash
@@ -130,7 +133,7 @@ the `plugins` table.
130133

131134
### Operation
132135

133-
When a request is recived from any of the frontends, this is routed to the
136+
When a request is received from any of the frontends, this is routed to the
134137
central dispatcher via a `Chan`. Based on the specified plugin name and
135138
`IdeRequest` `ideCommand` value the appropriate `UiCommand` is identified and
136139
its `uiFunc` is called.
@@ -144,5 +147,5 @@ type Dispatcher = forall m. (MonadIO m,GHC.GhcMonad m,HasIdeState m) => IdeReque
144147
This type is not the monad used in `HIE`, but does guarantee that it can access
145148
IO and the `HIE` state, which is currently only the table of plugins.
146149

147-
It also makes the `GhcMonad` available. In a fully general version this my not
150+
It also makes the `GhcMonad` available. In a fully general version this may not
148151
be necessary.

docs/Protocol.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md
66

7-
Advantages include widespread tooling and IDE support, and standarisation.
7+
Advantages include widespread tooling and IDE support, and standardization.
88

99
Implemented in [LspStdio.hs](../src/Haskell/Ide/Engine/Transport/LspStdio.hs)
1010

docs/hcar/2015.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
Idris community has done toward an interactive editing environment as well. This
2626
is a deliberately broad scope, the initial versions will be very limited at
2727
first. The sooner we can get started the sooner we will have something concrete
28-
to criticise and improve.
28+
to criticize and improve.
2929

3030
Help is very much needed and wanted so if this is a problem that interests you,
3131
please pitch in! This is not a project just for a small inner circle. Anyone

haskell-ide-engine.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ library
4040
Haskell.Ide.Engine.Plugin.Liquid
4141
Haskell.Ide.Engine.Plugin.Package
4242
Haskell.Ide.Engine.Plugin.Package.Compat
43+
Haskell.Ide.Engine.Plugin.Pragmas
4344
Haskell.Ide.Engine.Transport.JsonStdio
4445
Haskell.Ide.Engine.Transport.LspStdio
4546
Haskell.Ide.Engine.Types

src/Haskell/Ide/Engine/Plugin/Base.hs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,18 @@ getProjectGhcVersion = do
111111
if isStackProject && isStackInstalled
112112
then do
113113
L.infoM "hie" "Using stack GHC version"
114-
catch (tryCommand "stack ghc -- --version") $ \e -> do
114+
catch (tryCommand "stack ghc -- --numeric-version") $ \e -> do
115115
L.errorM "hie" $ show (e :: SomeException)
116116
L.infoM "hie" "Couldn't find stack version, falling back to plain GHC"
117-
tryCommand "ghc --version"
117+
tryCommand "ghc --numeric-version"
118118
else do
119119
L.infoM "hie" "Using plain GHC version"
120-
tryCommand "ghc --version"
120+
tryCommand "ghc --numeric-version"
121121

122122
where
123123
tryCommand cmd =
124-
crackGhcVersion <$> readCreateProcess (shell cmd) ""
125-
-- "The Glorious Glasgow Haskell Compilation System, version 8.4.3\n"
126-
-- "The Glorious Glasgow Haskell Compilation System, version 8.4.2\n"
127-
crackGhcVersion :: String -> String
128-
crackGhcVersion st = reverse $ takeWhile (/=' ') $ tail $ reverse st
124+
-- Drop '\n' from the output like "7.10.3\n", "8.4.3\n"
125+
init <$> readCreateProcess (shell cmd) ""
129126

130127
hieGhcVersion :: String
131128
hieGhcVersion = VERSION_ghc

src/Haskell/Ide/Engine/Plugin/GhcMod.hs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,10 +410,13 @@ codeActionProvider' supportsDocChanges _ docId _ _ _ context =
410410
typedHoleActions = concatMap mkTypedHoleActions (mapMaybe getTypedHoles diags)
411411
missingSignatures = mapMaybe getMissingSignatures diags
412412
topLevelSignatureActions = map (uncurry mkMissingSignatureAction) missingSignatures
413+
unusedTerms = mapMaybe getUnusedTerms diags
414+
unusedTermActions = map (uncurry mkUnusedTermAction) unusedTerms
413415
in return $ IdeResultOk $ concat [ renameActions
414416
, redundantActions
415417
, typedHoleActions
416418
, topLevelSignatureActions
419+
, unusedTermActions
417420
]
418421

419422
where
@@ -512,6 +515,26 @@ codeActionProvider' supportsDocChanges _ docId _ _ _ context =
512515
kind = LSP.CodeActionQuickFix
513516
codeAction = LSP.CodeAction title (Just kind) (Just diags) (Just edit) Nothing
514517

518+
getUnusedTerms :: LSP.Diagnostic -> Maybe (LSP.Diagnostic, T.Text)
519+
getUnusedTerms diag@(LSP.Diagnostic _ _ _ (Just "ghcmod") msg _) =
520+
case extractUnusedTerm msg of
521+
Nothing -> Nothing
522+
Just signature -> Just (diag, signature)
523+
getUnusedTerms _ = Nothing
524+
525+
mkUnusedTermAction :: LSP.Diagnostic -> T.Text -> LSP.CodeAction
526+
mkUnusedTermAction diag term = LSP.CodeAction title (Just kind) (Just diags) Nothing (Just cmd)
527+
where title :: T.Text
528+
title = "Prefix " <> term <> " with _"
529+
diags = LSP.List [diag]
530+
newTerm = "_" <> term
531+
pos = diag ^. (LSP.range . LSP.start)
532+
kind = LSP.CodeActionQuickFix
533+
cmdArgs = LSP.List
534+
[ Object $ HM.fromList [("file", toJSON docUri),("pos", toJSON pos), ("text", toJSON newTerm)]]
535+
-- The command label isen't used since the command is never presented to the user
536+
cmd = LSP.Command "Unused command label" "hare:rename" (Just cmdArgs)
537+
515538
extractRenamableTerms :: T.Text -> [T.Text]
516539
extractRenamableTerms msg
517540
-- Account for both "Variable not in scope" and "Not in scope"
@@ -601,6 +624,14 @@ extractMissingSignature msg = extractSignature <$> stripMessageStart msg
601624
. T.strip
602625
extractSignature = T.strip
603626

627+
extractUnusedTerm :: T.Text -> Maybe T.Text
628+
extractUnusedTerm msg = extractTerm <$> stripMessageStart msg
629+
where
630+
stripMessageStart = T.stripPrefix "Defined but not used:"
631+
. T.strip
632+
extractTerm = T.dropWhile (== '')
633+
. T.dropWhileEnd (== '')
634+
. T.dropAround (\c -> c /= '' && c /= '')
604635

605636
-- ---------------------------------------------------------------------
606637

0 commit comments

Comments
 (0)