@@ -69,6 +69,7 @@ import Development.IDE hiding (line)
6969import Development.IDE.Spans.AtPoint (pointCommand )
7070
7171
72+ import qualified Development.IDE.Plugin.Completions.Types as C
7273import GHC.Plugins (Depth (AllTheWay ),
7374mkUserStyle ,
7475neverQualify ,
@@ -202,7 +203,7 @@ mkCompl
202203 _preselect= Nothing ,
203204 _sortText= Nothing ,
204205 _filterText= Nothing ,
205- _insertText= Just insertText,
206+ _insertText= Just $ snippetToText insertText,
206207 _insertTextFormat= Just InsertTextFormat_Snippet ,
207208 _insertTextMode= Nothing ,
208209 _textEdit= Nothing ,
@@ -242,10 +243,9 @@ mkNameCompItem doc thingParent origName provenance isInfix !imp mod = CI {..}
242243 isTypeCompl= isTcOcc origName
243244 typeText= Nothing
244245 label= stripOccNamePrefix$ printOutputable origName
245- insertText= case isInfixof
246+ insertText= snippetText $ case isInfixof
246247Nothing -> label
247248Just LeftSide -> label<> " `"
248-
249249Just Surrounded -> label
250250 additionalTextEdits=
251251 imp<&> \ x->
@@ -294,7 +294,7 @@ defaultCompletionItemWithLabel label =
294294fromIdentInfo :: Uri -> IdentInfo -> Maybe T. Text-> CompItem
295295fromIdentInfo doc identInfo@ IdentInfo {.. } q= CI
296296 { compKind= occNameToComKind name
297- , insertText= rend
297+ , insertText= snippetText rend
298298 , provenance= DefinedIn mod
299299 , label= rend
300300 , typeText= Nothing
@@ -458,10 +458,11 @@ localCompletionsForParsedModule uri pm@ParsedModule{pm_parsed_source = L _ HsMod
458458 ]
459459
460460 mkLocalComp pos n ctyp ty=
461- CI ctyppn (Local pos) pn tyNothing (ctyp`elem` [CompletionItemKind_Struct ,CompletionItemKind_Interface ])Nothing (Just $ NameDetails (ms_mod$ pm_mod_summary pm) occ)True
461+ CI ctypsn (Local pos) pn tyNothing (ctyp`elem` [CompletionItemKind_Struct ,CompletionItemKind_Interface ])Nothing (Just $ NameDetails (ms_mod$ pm_mod_summary pm) occ)True
462462where
463463 occ= rdrNameOcc$ unLoc n
464464 pn= showForSnippet n
465+ sn= snippetText pn
465466
466467findRecordCompl :: Uri -> Provenance -> TyClDecl GhcPs -> [CompItem ]
467468findRecordCompl uri mnDataDecl {tcdLName, tcdDataDefn}= result
@@ -638,7 +639,7 @@ getCompletions
638639dotFieldSelectorToCompl :: T. Text-> T. Text-> (Bool ,CompItem )
639640 dotFieldSelectorToCompl recname label= (True ,CI
640641 { compKind= CompletionItemKind_Field
641- , insertText= label
642+ , insertText= snippetText label
642643 , provenance= DefinedIn recname
643644 , label= label
644645 , typeText= Nothing
@@ -667,7 +668,7 @@ getCompletions
667668 endLoc= upperRange oldPos
668669 localCompls= map (uncurry localBindsToCompItem)$ getFuzzyScope localBindings startLoc endLoc
669670localBindsToCompItem :: Name -> Maybe Type -> CompItem
670- localBindsToCompItem name typ= CI ctyppn thisModName pn tyNothing (not $ isValOcc occ)Nothing detsTrue
671+ localBindsToCompItem name typ= CI ctyp(snippetText pn) thisModName pn tyNothing (not $ isValOcc occ)Nothing detsTrue
671672where
672673 occ= nameOccName name
673674 ctyp= occNameToComKind occ
@@ -736,7 +737,8 @@ uniqueCompl candidate unique =
736737-- filter global completions when we already have a local one
737738|| not (isLocalCompletion candidate)&& isLocalCompletion unique
738739then EQ
739- else compare (importedFrom candidate, insertText candidate) (importedFrom unique, insertText unique)
740+ else compare (importedFrom candidate) (importedFrom unique)<>
741+ snippetLexOrd (insertText candidate) (insertText unique)
740742 other-> other
741743where
742744importedFrom :: CompItem -> T. Text
@@ -805,9 +807,10 @@ mkRecordSnippetCompItem uri parent ctxStr compl importedFrom imp = r
805807 }
806808
807809 placeholder_pairs= zip compl ([1 .. ]:: [Int ])
808- snippet_parts= map (\ (x, i)-> x<> " =${" <> T. pack (show i)<> " :_" <> x<> " }" ) placeholder_pairs
809- snippet= T. intercalate (T. pack" ," ) snippet_parts
810- buildSnippet= ctxStr<> " {" <> snippet<> " }"
810+ snippet_parts= placeholder_pairs<&> \ (x, i)->
811+ snippetText x<> " =" <> snippetVariableDefault (T. pack$ show i) (C. SText$ " _" <> x)
812+ snippet= mconcat $ intersperse" ," snippet_parts
813+ buildSnippet= snippetText ctxStr<> " {" <> snippet<> " }"
811814
812815getImportQual :: LImportDecl GhcPs -> Maybe T. Text
813816getImportQual (L _ imp)