@@ -166,7 +166,7 @@ mkCompl
166
166
{ compKind,
167
167
isInfix,
168
168
insertText,
169
- importedFrom ,
169
+ provenance ,
170
170
typeText,
171
171
label,
172
172
docs,
@@ -195,26 +195,28 @@ mkCompl
195
195
196
196
where kind = Just compKind
197
197
docs' = imported : spanDocToMarkdown docs
198
- isImported = isNothing additionalTextEdits
199
- definedOrImported = if isImported then " *Imported from '" else " *Defined in '"
200
- imported = case importedFrom of
201
- Left pos -> " *Defined at '" <> ppr pos <> " '*\n '"
202
- Right mod -> definedOrImported <> mod <> " '*\n "
198
+ imported = case provenance of
199
+ Local pos -> " *Defined at " <> pprLineCol (srcSpanStart pos) <> " in this module*\n '"
200
+ ImportedFrom mod -> " *Imported from '" <> mod <> " '*\n "
201
+ DefinedIn mod -> " *Defined in '" <> mod <> " '*\n "
203
202
colon = if optNewColonConvention then " : " else " :: "
204
203
documentation = Just $ CompletionDocMarkup $
205
204
MarkupContent MkMarkdown $
206
205
T. intercalate sectionSeparator docs'
206
+ pprLineCol :: SrcLoc -> T. Text
207
+ pprLineCol (UnhelpfulLoc fs) = T. pack $ unpackFS fs
208
+ pprLineCol (RealSrcLoc loc) =
209
+ " line " <> ppr(srcLocLine loc) <> " , column " <> ppr(srcLocCol loc)
207
210
208
211
209
212
mkAdditionalEditsCommand :: PluginId -> ExtendImport -> Command
210
213
mkAdditionalEditsCommand pId edits =
211
214
mkLspCommand pId (CommandId extendImportCommandId) " extend import" (Just [toJSON edits])
212
215
213
- mkNameCompItem :: Uri -> Maybe T. Text -> OccName -> ModuleName -> Maybe Type -> Maybe Backtick -> SpanDoc -> Maybe (LImportDecl GhcPs ) -> CompItem
214
- mkNameCompItem doc thingParent origName origMod thingType isInfix docs ! imp = CI {.. }
216
+ mkNameCompItem :: Uri -> Maybe T. Text -> OccName -> Provenance -> Maybe Type -> Maybe Backtick -> SpanDoc -> Maybe (LImportDecl GhcPs ) -> CompItem
217
+ mkNameCompItem doc thingParent origName provenance thingType isInfix docs ! imp = CI {.. }
215
218
where
216
219
compKind = occNameToComKind typeText origName
217
- importedFrom = Right $ showModName origMod
218
220
isTypeCompl = isTcOcc origName
219
221
label = stripPrefix $ showGhc origName
220
222
insertText = case isInfix of
@@ -309,7 +311,7 @@ fromIdentInfo :: Uri -> IdentInfo -> Maybe T.Text -> CompItem
309
311
fromIdentInfo doc IdentInfo {.. } q = CI
310
312
{ compKind= occNameToComKind Nothing name
311
313
, insertText= rendered
312
- , importedFrom = Right moduleNameText
314
+ , provenance = DefinedIn moduleNameText
313
315
, typeText= Nothing
314
316
, label= rendered
315
317
, isInfix= Nothing
@@ -330,6 +332,7 @@ cacheDataProducer uri env curMod globalEnv inScopeEnv limports = do
330
332
let
331
333
packageState = hscEnv env
332
334
curModName = moduleName curMod
335
+ curModNameText = ppr curModName
333
336
334
337
importMap = Map. fromList [ (l, imp) | imp@ (L (RealSrcSpan l _) _) <- limports ]
335
338
@@ -356,7 +359,7 @@ cacheDataProducer uri env curMod globalEnv inScopeEnv limports = do
356
359
357
360
getComplsForOne :: GlobalRdrElt -> IO ([CompItem ],QualCompls )
358
361
getComplsForOne (GRE n par True _) =
359
- (, mempty ) <$> toCompItem par curMod curModName n Nothing
362
+ (, mempty ) <$> toCompItem par curMod curModNameText n Nothing
360
363
getComplsForOne (GRE n par False prov) =
361
364
flip foldMapM (map is_decl prov) $ \ spec -> do
362
365
let originalImportDecl = do
@@ -365,7 +368,7 @@ cacheDataProducer uri env curMod globalEnv inScopeEnv limports = do
365
368
-- or if it doesn't have a real location
366
369
loc <- realSpan $ is_dloc spec
367
370
Map. lookup loc importMap
368
- compItem <- toCompItem par curMod (is_mod spec) n originalImportDecl
371
+ compItem <- toCompItem par curMod (ppr $ is_mod spec) n originalImportDecl
369
372
let unqual
370
373
| is_qual spec = []
371
374
| otherwise = compItem
@@ -376,7 +379,7 @@ cacheDataProducer uri env curMod globalEnv inScopeEnv limports = do
376
379
origMod = showModName (is_mod spec)
377
380
return (unqual,QualCompls qual)
378
381
379
- toCompItem :: Parent -> Module -> ModuleName -> Name -> Maybe (LImportDecl GhcPs ) -> IO [CompItem ]
382
+ toCompItem :: Parent -> Module -> T. Text -> Name -> Maybe (LImportDecl GhcPs ) -> IO [CompItem ]
380
383
toCompItem par m mn n imp' = do
381
384
docs <- getDocumentationTryGhc packageState curMod n
382
385
let (mbParent, originName) = case par of
@@ -392,10 +395,10 @@ cacheDataProducer uri env curMod globalEnv inScopeEnv limports = do
392
395
393
396
let recordCompls = case record_ty of
394
397
Just (ctxStr, flds) | not (null flds) ->
395
- [mkRecordSnippetCompItem uri mbParent ctxStr flds (ppr mn) docs imp']
398
+ [mkRecordSnippetCompItem uri mbParent ctxStr flds (ImportedFrom mn) docs imp']
396
399
_ -> []
397
400
398
- return $ mkNameCompItem uri mbParent originName mn ty Nothing docs imp'
401
+ return $ mkNameCompItem uri mbParent originName ( ImportedFrom mn) ty Nothing docs imp'
399
402
: recordCompls
400
403
401
404
(unquals,quals) <- getCompls rdrElts
@@ -413,7 +416,7 @@ cacheDataProducer uri env curMod globalEnv inScopeEnv limports = do
413
416
414
417
-- | Produces completions from the top level declarations of a module.
415
418
localCompletionsForParsedModule :: Uri -> ParsedModule -> CachedCompletions
416
- localCompletionsForParsedModule uri pm@ ParsedModule {pm_parsed_source = L _ HsModule {hsmodDecls, hsmodName }} =
419
+ localCompletionsForParsedModule uri pm@ ParsedModule {pm_parsed_source = L _ HsModule {hsmodDecls}} =
417
420
CC { allModNamesAsNS = mempty
418
421
, unqualCompls = compls
419
422
, qualCompls = mempty
@@ -449,7 +452,7 @@ localCompletionsForParsedModule uri pm@ParsedModule{pm_parsed_source = L _ HsMod
449
452
| id <- listify (\ (_ :: Located (IdP GhcPs )) -> True ) x
450
453
, let cl = occNameToComKind Nothing (rdrNameOcc $ unLoc id )]
451
454
-- here we only have to look at the outermost type
452
- recordCompls = findRecordCompl uri pm thisModName x
455
+ recordCompls = findRecordCompl uri pm ( Local pos) x
453
456
in
454
457
-- the constructors and snippets will be duplicated here giving the user 2 choices.
455
458
generalCompls ++ recordCompls
@@ -458,18 +461,17 @@ localCompletionsForParsedModule uri pm@ParsedModule{pm_parsed_source = L _ HsMod
458
461
ForD _ ForeignExport {fd_name,fd_sig_ty} ->
459
462
[mkComp fd_name CiVariable (Just $ ppr fd_sig_ty)]
460
463
_ -> []
461
- | L _ decl <- hsmodDecls
464
+ | L pos decl <- hsmodDecls,
465
+ let mkComp = mkLocalComp pos
462
466
]
463
467
464
- mkComp n ctyp ty =
465
- CI ctyp pn (Right thisModName ) ty pn Nothing doc (ctyp `elem` [CiStruct , CiInterface ]) Nothing
468
+ mkLocalComp pos n ctyp ty =
469
+ CI ctyp pn (Local pos ) ty pn Nothing doc (ctyp `elem` [CiStruct , CiInterface ]) Nothing
466
470
where
467
471
pn = ppr n
468
472
doc = SpanDocText (getDocumentation [pm] n) (SpanDocUris Nothing Nothing )
469
473
470
- thisModName = ppr hsmodName
471
-
472
- findRecordCompl :: Uri -> ParsedModule -> T. Text -> TyClDecl GhcPs -> [CompItem ]
474
+ findRecordCompl :: Uri -> ParsedModule -> Provenance -> TyClDecl GhcPs -> [CompItem ]
473
475
findRecordCompl uri pmod mn DataDecl {tcdLName, tcdDataDefn} = result
474
476
where
475
477
result = [mkRecordSnippetCompItem uri (Just $ showNameWithoutUniques $ unLoc tcdLName)
@@ -590,9 +592,7 @@ getCompletions plId ideOpts CC {allModNamesAsNS, anyQualCompls, unqualCompls, qu
590
592
ctyp = occNameToComKind Nothing occ
591
593
pn = ppr name
592
594
ty = ppr <$> typ
593
- thisModName = case nameModule_maybe name of
594
- Nothing -> Left $ nameSrcSpan name
595
- Just m -> Right $ ppr m
595
+ thisModName = Local $ nameSrcSpan name
596
596
597
597
compls = if T. null prefixModule
598
598
then localCompls ++ unqualCompls ++ (($ Nothing ) <$> anyQualCompls)
@@ -639,8 +639,8 @@ getCompletions plId ideOpts CC {allModNamesAsNS, anyQualCompls, unqualCompls, qu
639
639
640
640
uniqueCompl :: CompItem -> CompItem -> Ordering
641
641
uniqueCompl x y =
642
- case compare (label x, importedFrom x , compKind x)
643
- (label y, importedFrom y , compKind y) of
642
+ case compare (label x, importedFrom (provenance x) , compKind x)
643
+ (label y, importedFrom (provenance x) , compKind y) of
644
644
EQ ->
645
645
-- preserve completions for duplicate record fields where the only difference is in the type
646
646
-- remove redundant completions with less type info
@@ -650,6 +650,11 @@ uniqueCompl x y =
650
650
then EQ
651
651
else compare (insertText x) (insertText y)
652
652
other -> other
653
+ where
654
+ importedFrom :: Provenance -> T. Text
655
+ importedFrom (ImportedFrom m) = m
656
+ importedFrom (DefinedIn m) = m
657
+ importedFrom (Local _) = " local"
653
658
654
659
-- ---------------------------------------------------------------------
655
660
-- helper functions for infix backticks
@@ -755,13 +760,13 @@ safeTyThingForRecord (AConLike dc) =
755
760
Just (ctxStr, field_names)
756
761
safeTyThingForRecord _ = Nothing
757
762
758
- mkRecordSnippetCompItem :: Uri -> Maybe T. Text -> T. Text -> [T. Text ] -> T. Text -> SpanDoc -> Maybe (LImportDecl GhcPs ) -> CompItem
759
- mkRecordSnippetCompItem uri parent ctxStr compl mn docs imp = r
763
+ mkRecordSnippetCompItem :: Uri -> Maybe T. Text -> T. Text -> [T. Text ] -> Provenance -> SpanDoc -> Maybe (LImportDecl GhcPs ) -> CompItem
764
+ mkRecordSnippetCompItem uri parent ctxStr compl importedFrom docs imp = r
760
765
where
761
766
r = CI {
762
767
compKind = CiSnippet
763
768
, insertText = buildSnippet
764
- , importedFrom = importedFrom
769
+ , provenance = importedFrom
765
770
, typeText = Nothing
766
771
, label = ctxStr
767
772
, isInfix = Nothing
@@ -781,7 +786,6 @@ mkRecordSnippetCompItem uri parent ctxStr compl mn docs imp = r
781
786
snippet_parts = map (\ (x, i) -> x <> " =${" <> T. pack (show i) <> " :_" <> x <> " }" ) placeholder_pairs
782
787
snippet = T. intercalate (T. pack " , " ) snippet_parts
783
788
buildSnippet = ctxStr <> " {" <> snippet <> " }"
784
- importedFrom = Right mn
785
789
786
790
getImportQual :: LImportDecl GhcPs -> Maybe T. Text
787
791
getImportQual (L _ imp)
0 commit comments