Skip to content

Commit 0071f14

Browse files
Fix completion for record dot syntax when record isn't known
1 parent 32f7800 commit 0071f14

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

ghcide-test/exe/CompletionTests.hs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,36 @@ localCompletionTests = [
211211

212212
compls <- getCompletions doc (Position 0 15)
213213
liftIO $ filter ("AAA" `T.isPrefixOf`) (mapMaybe _insertText compls) @?= ["AAAAA"]
214-
pure ()
214+
pure (),
215+
completionTest
216+
"polymorphic record dot completion"
217+
[ "{-# LANGUAGE OverloadedRecordDot #-}"
218+
, "module A () where"
219+
, "data Record = Record"
220+
, " { field1 :: Int"
221+
, " , field2 :: Int"
222+
, " }"
223+
, "foo record = record.f"
224+
]
225+
(Position 6 21)
226+
[("field1", CompletionItemKind_Function, "field1", True, False, Nothing)
227+
,("field2", CompletionItemKind_Function, "field2", True, False, Nothing)
228+
],
229+
completionTest
230+
"qualified polymorphic record dot completion"
231+
[ "{-# LANGUAGE OverloadedRecordDot #-}"
232+
, "module A () where"
233+
, "data Record = Record"
234+
, " { field1 :: Int"
235+
, " , field2 :: Int"
236+
, " }"
237+
, "someValue = undefined"
238+
, "foo = A.someValue.f"
239+
]
240+
(Position 7 19)
241+
[("field1", CompletionItemKind_Function, "field1", True, False, Nothing)
242+
,("field2", CompletionItemKind_Function, "field2", True, False, Nothing)
243+
]
215244
]
216245

217246
nonLocalCompletionTests :: [TestTree]

ghcide/src/Development/IDE/Plugin/Completions/Logic.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ getCompletionPrefixFromRope pos@(Position l c) ropetext =
912912
[] -> Nothing
913913
(x:xs) -> do
914914
let modParts = reverse $ filter (not .T.null) xs
915-
modName = T.intercalate "." modParts
915+
modName = if all (isUpper . T.head) modParts then T.intercalate "." modParts else ""
916916
return $ PosPrefixInfo { fullLine = curLine, prefixScope = modName, prefixText = x, cursorPos = pos }
917917

918918
completionPrefixPos :: PosPrefixInfo -> Position

0 commit comments

Comments
 (0)