Skip to content

Commit d330009

Browse files
committed
fill in boolean/enum completion values
1 parent 3340ec4 commit d330009

File tree

3 files changed

+102
-58
lines changed

3 files changed

+102
-58
lines changed

plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ instance Pretty Log where
9393
"Closed text document:" <+> pretty (getUri uri)
9494
LogFOI files ->
9595
"Set files of interest to:" <+> viaShow files
96+
LogCompletionContext context position ->
97+
"Determined completion context:"
98+
<+> pretty context
99+
<+> "for cursor position:"
100+
<+> pretty position
101+
LogCompletions logs -> pretty logs
96102

97103
descriptor :: Recorder (WithPriority Log) -> PluginId -> PluginDescriptor IdeState
98104
descriptor recorder plId =

plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject/Completion/Completions.hs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,33 +33,32 @@ contextToCompleter :: Context -> Completer
3333
-- we can write any top level keywords or a stanza declaration
3434
contextToCompleter (TopLevel, None) =
3535
constantCompleter $
36-
Map.keys cabalProjectKeywords ++ Map.keys packageFields
36+
Map.keys cabalProjectKeywords ++ Map.keys stanzaKeywordMap
3737
-- if we are in a keyword context in the top level,
3838
-- we look up that keyword in the top level context and can complete its possible values
39-
-- contextToCompleter (TopLevel, KeyWord kw) =
40-
-- case Map.lookup kw (cabalVersionKeyword <> cabalKeywords) of
41-
-- Nothing -> errorNoopCompleter (LogUnknownKeyWordInContextError kw)
42-
-- Just l -> l
39+
contextToCompleter (TopLevel, KeyWord kw) =
40+
case Map.lookup kw cabalProjectKeywords of
41+
Nothing -> errorNoopCompleter (LogUnknownKeyWordInContextError kw)
42+
Just l -> l
4343
-- if we are in a stanza and not in a keyword context,
4444
-- we can write any of the stanza's keywords or a stanza declaration
4545
contextToCompleter (Stanza s _, None) =
4646
case Map.lookup s stanzaKeywordMap of
4747
Nothing -> errorNoopCompleter (LogUnknownStanzaNameInContextError s)
4848
Just l -> constantCompleter $ Map.keys l
4949
-- if we are in a stanza's keyword's context we can complete possible values of that keyword
50-
-- contextToCompleter (Stanza s _, KeyWord kw) =
51-
-- case Map.lookup s stanzaKeywordMap of
52-
-- Nothing -> errorNoopCompleter (LogUnknownStanzaNameInContextError s)
53-
-- Just m -> case Map.lookup kw m of
54-
-- Nothing -> errorNoopCompleter (LogUnknownKeyWordInContextError kw)
55-
-- Just l -> l
50+
contextToCompleter (Stanza s _, KeyWord kw) =
51+
case Map.lookup s stanzaKeywordMap of
52+
Nothing -> errorNoopCompleter (LogUnknownStanzaNameInContextError s)
53+
Just m -> case Map.lookup kw m of
54+
Nothing -> errorNoopCompleter (LogUnknownKeyWordInContextError kw)
55+
Just l -> l
5656

5757
-- | Takes prefix info about the previously written text
5858
-- and a rope (representing a file), returns the corresponding context.
5959
--
6060
-- Can return Nothing if an error occurs.
6161
--
62-
-- TODO: first line can only have cabal-version: keyword
6362
getContext :: (MonadIO m) => Recorder (WithPriority Log) -> CabalPrefixInfo -> [Syntax.Field Syntax.Position] -> m Context
6463
getContext recorder prefInfo fields = do
6564
let ctx = findCursorContext cursor (NE.singleton (0, TopLevel)) (completionPrefix prefInfo) fields

plugins/hls-cabal-project-plugin/src/Ide/Plugin/CabalProject/Completion/Data.hs

Lines changed: 85 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ import Ide.Plugin.Cabal.Completion.Completer.Types (Completer)
1616
import Ide.Plugin.Cabal.Completion.Types
1717
-- import Ide.Plugin.Cabal.LicenseSuggest (licenseNames)
1818

19+
-- | Ad-hoc data type for modelling the available top-level stanzas.
20+
-- Not intended right now for anything else but to avoid string
21+
-- comparisons in 'stanzaKeywordMap' and 'libExecTestBenchCommons'.
22+
data TopLevelStanza
23+
= Package
24+
| ProgramOptions
25+
1926
-- ----------------------------------------------------------------
2027
-- Completion Data
2128
-- ----------------------------------------------------------------
@@ -44,27 +51,27 @@ cabalProjectKeywords =
4451
("optional-packages:", noopCompleter),
4552
("extra-packages:", noopCompleter),
4653
-- projectConfigBuildOnlyFieldGrammar
47-
("verbose:", constantCompleter ["0", "1", "2", "3"]), -- not sure if this works/makes sense?
54+
("verbose:", constantCompleter ["0", "1", "2", "3"]),
4855
("build-summary:", noopCompleter),
4956
("build-log:", noopCompleter),
5057
("remote-build-reporting:", noopCompleter),
5158
("report-planning-failure:", noopCompleter),
5259
("symlink-bindir:", noopCompleter),
5360
("jobs:", noopCompleter),
5461
("semaphore:", noopCompleter),
55-
("keep-going:", noopCompleter),
62+
("keep-going:", constantCompleter ["False", "True"]),
5663
("offline:", noopCompleter),
57-
("haddock-keep-temp-files:", noopCompleter),
58-
("http-transport:", noopCompleter),
59-
("ignore-expiry:", noopCompleter),
64+
("haddock-keep-temp-files:", constantCompleter ["False", "True"]),
65+
("http-transport:", constantCompleter ["curl", "wget", "powershell", "plain-http"]),
66+
("ignore-expiry:", constantCompleter ["False", "True"]),
6067
("remote-repo-cache:", noopCompleter),
6168
("logs-dir:", noopCompleter),
6269
-- projectConfigSharedFieldGrammar
6370
("builddir:", noopCompleter),
6471
("project-dir:", noopCompleter),
6572
("project-file:", noopCompleter),
6673
("ignore-project:", noopCompleter),
67-
("compiler:", noopCompleter),
74+
("compiler:", constantCompleter ["ghc", "ghcjs", "jhc", "lhc", "uhc", "haskell-suite"]),
6875
("with-compiler:", noopCompleter),
6976
("with-hc-pkg:", noopCompleter),
7077
("doc-index-file:", noopCompleter),
@@ -75,73 +82,76 @@ cabalProjectKeywords =
7582
("constraints:", noopCompleter),
7683
("preferences:", noopCompleter),
7784
("cabal-lib-version:", noopCompleter),
78-
("solver:", noopCompleter),
85+
("solver:", constantCompleter ["modular"]),
7986
("allow-older:", noopCompleter),
8087
("allow-newer:", noopCompleter),
81-
("write-ghc-environment-files:", noopCompleter),
88+
("write-ghc-environment-files:", constantCompleter ["never", "always", "ghc8.4.4+"]),
8289
("max-backjumps:", noopCompleter),
83-
("reorder-goals:", noopCompleter),
84-
("count-conflicts:", noopCompleter),
85-
("fine-grained-conflicts:", noopCompleter),
86-
("minimize-conflict-set:", noopCompleter),
87-
("strong-flags:", noopCompleter),
88-
("allow-boot-library-installs:", noopCompleter),
90+
("reorder-goals:", constantCompleter ["False", "True"]),
91+
("count-conflicts:", constantCompleter ["True", "False"]),
92+
("fine-grained-conflicts:", constantCompleter ["True", "False"]),
93+
("minimize-conflict-set:", constantCompleter ["False", "True"]),
94+
("strong-flags:", constantCompleter ["False", "True"]),
95+
("allow-boot-library-installs:", constantCompleter ["False", "True"]),
8996
("reject-unconstrained-dependencies:", noopCompleter),
9097
("per-component:", noopCompleter),
9198
("independent-goals:", noopCompleter),
9299
("prefer-oldest:", noopCompleter),
93100
("extra-prog-path-shared-only:", noopCompleter),
94-
("multi-repl:", noopCompleter)
101+
("multi-repl:", noopCompleter),
102+
-- extras
103+
("benchmarks:", constantCompleter ["False", "True"])
104+
95105
]
96106

97107
packageFields :: Map KeyWordName Completer
98108
packageFields =
99109
Map.fromList
100110
[ -- packageConfigFieldGrammar
101-
("haddock-all:", noopCompleter),
111+
("haddock-all:", constantCompleter ["False", "True"]),
102112
("extra-prog-path:", noopCompleter),
103113
("flags:", noopCompleter),
104-
("library-vanilla:", noopCompleter),
105-
("shared:", noopCompleter),
106-
("static:", noopCompleter),
107-
("exectable-dynamic:", noopCompleter),
108-
("executable-static:", noopCompleter),
109-
("profiling:", noopCompleter),
110-
("library-profiling:", noopCompleter),
114+
("library-vanilla:", constantCompleter ["True", "False"]),
115+
("shared:", constantCompleter ["False", "True"]),
116+
("static:", constantCompleter ["False", "True"]),
117+
("exectable-dynamic:", constantCompleter ["False", "True"]),
118+
("executable-static:", constantCompleter ["False", "True"]),
119+
("profiling:", constantCompleter ["False", "True"]),
120+
("library-profiling:", constantCompleter ["False", "True"]),
111121
("profiling-shared:", noopCompleter),
112-
("exectable-profiling:", noopCompleter),
113-
("profiling-detail:", noopCompleter),
114-
("library-profiling-detail:", noopCompleter),
122+
("exectable-profiling:", constantCompleter ["False", "True"]),
123+
("profiling-detail:", constantCompleter ["default", "none", "exported-functions", "toplevel-functions", "all-functions"]),
124+
("library-profiling-detail:", constantCompleter ["default", "none", "exported-functions", "toplevel-functions", "all-functions"]),
115125
("configure-options:", noopCompleter),
116-
("optimization:", noopCompleter),
126+
("optimization:", constantCompleter ["0", "1", "2", "True", "False"]),
117127
("program-prefix:", noopCompleter),
118128
("program-suffix:", noopCompleter),
119129
("extra-lib-dirs:", noopCompleter),
120130
("extra-lib-dirs-static:", noopCompleter),
121131
("extra-framework-dirs:", noopCompleter),
122132
("extra-include-dirs:", noopCompleter),
123-
("library-for-ghci:", noopCompleter),
124-
("split-sections:", noopCompleter),
125-
("split-objs:", noopCompleter),
126-
("executable-stripping:", noopCompleter),
127-
("library-stripping:", noopCompleter),
128-
("tests:", noopCompleter),
129-
("benchmarks:", noopCompleter),
130-
("relocatable:", noopCompleter),
133+
("library-for-ghci:", constantCompleter ["True", "False"]),
134+
("split-sections:", constantCompleter ["False", "True"]),
135+
("split-objs:", constantCompleter ["False", "True"]),
136+
("executable-stripping:", constantCompleter ["True", "False"]),
137+
("library-stripping:", constantCompleter ["False", "True"]),
138+
("tests:", constantCompleter ["False", "True"]),
139+
("benchmarks:", constantCompleter ["False", "True"]),
140+
("relocatable:", constantCompleter ["False", "True"]),
131141
("debug-info:", noopCompleter),
132142
("build-info:", noopCompleter),
133-
("run-tests:", noopCompleter),
134-
("documentation:", noopCompleter),
135-
("haddock-hoogle:", noopCompleter),
136-
("haddock-html:", noopCompleter),
143+
("run-tests:", constantCompleter ["False", "True"]),
144+
("documentation:", constantCompleter ["False", "True"]),
145+
("haddock-hoogle:", constantCompleter ["False", "True"]),
146+
("haddock-html:", constantCompleter ["True", "False"]),
137147
("haddock-html-location:", noopCompleter),
138148
("haddock-foreign-libraries:", noopCompleter),
139-
("haddock-executables:", noopCompleter),
140-
("haddock-tests:", noopCompleter),
141-
("haddock-benchmarks:", noopCompleter),
142-
("haddock-internal:", noopCompleter),
149+
("haddock-executables:", constantCompleter ["False", "True"]),
150+
("haddock-tests:", constantCompleter ["False", "True"]),
151+
("haddock-benchmarks:", constantCompleter ["False", "True"]),
152+
("haddock-internal:", constantCompleter ["False", "True"]),
143153
("haddock-css:", noopCompleter),
144-
("haddock-hyperlink-source:", noopCompleter),
154+
("haddock-hyperlink-source:", constantCompleter ["False", "True"]),
145155
("haddock-quickjump:", noopCompleter),
146156
("haddock-hscolour-css:", noopCompleter),
147157
("haddock-contents-location:", noopCompleter),
@@ -160,13 +170,42 @@ packageFields =
160170
("test-options:", noopCompleter),
161171
("benchmark-options:", noopCompleter),
162172
-- packageConfigCoverageGrammar
163-
("coverage:", noopCompleter)
173+
("coverage:", constantCompleter ["False", "True"]),
174+
-- other
175+
("ghc-options:", noopCompleter)
176+
]
177+
178+
-- just for testing right now, to be filled in later
179+
programOptionsFields :: Map KeyWordName Completer
180+
programOptionsFields = Map.fromList
181+
[ ("ghc-options:", noopCompleter)
182+
]
183+
184+
sourceRepoFields :: Map KeyWordName Completer
185+
sourceRepoFields = Map.fromList
186+
[ ("type:", constantCompleter
187+
[ "darcs",
188+
"git",
189+
"svn",
190+
"cvs",
191+
"mercurial",
192+
"hg",
193+
"bazaar",
194+
"bzr",
195+
"arch",
196+
"monotone"
197+
]), -- just used the one from cabal
198+
("location:", noopCompleter),
199+
("tag:", noopCompleter),
200+
("subdir:", noopCompleter)
164201
]
165202

166203
-- | Map, containing all stanzas in a cabal file as keys,
167204
-- and lists of their possible nested keywords as values.
168205
stanzaKeywordMap :: Map StanzaType (Map KeyWordName Completer)
169206
stanzaKeywordMap =
170207
Map.fromList
171-
[ ("package", packageFields)
208+
[ ("package", packageFields),
209+
("program-options", programOptionsFields),
210+
("source-repository-package", sourceRepoFields)
172211
]

0 commit comments

Comments
 (0)