@@ -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 ),
7374 mkUserStyle ,
7475 neverQualify ,
@@ -202,7 +203,7 @@ mkCompl
202203 _preselect = Nothing ,
203204 _sortText = Nothing ,
204205 _filterText = Nothing ,
205- _insertText = Just $ sanitize insertText,
206+ _insertText = Just $ snippetToText insertText,
206207 _insertTextFormat = Just InsertTextFormat_Snippet ,
207208 _insertTextMode = Nothing ,
208209 _textEdit = Nothing ,
@@ -227,7 +228,6 @@ mkCompl
227228 pprLineCol (UnhelpfulLoc fs) = T. pack $ unpackFS fs
228229 pprLineCol (RealSrcLoc loc _) =
229230 " line " <> printOutputable (srcLocLine loc) <> " , column " <> printOutputable (srcLocCol loc)
230- sanitize = T. replace " $" " \\ $"
231231
232232
233233mkAdditionalEditsCommand :: Maybe PluginId -> ExtendImport -> Maybe Command
@@ -243,10 +243,9 @@ mkNameCompItem doc thingParent origName provenance isInfix !imp mod = CI {..}
243243 isTypeCompl = isTcOcc origName
244244 typeText = Nothing
245245 label = stripOccNamePrefix $ printOutputable origName
246- insertText = case isInfix of
246+ insertText = snippetText $ case isInfix of
247247 Nothing -> label
248248 Just LeftSide -> label <> " `"
249-
250249 Just Surrounded -> label
251250 additionalTextEdits =
252251 imp <&> \ x ->
@@ -295,7 +294,7 @@ defaultCompletionItemWithLabel label =
295294fromIdentInfo :: Uri -> IdentInfo -> Maybe T. Text -> CompItem
296295fromIdentInfo doc identInfo@ IdentInfo {.. } q = CI
297296 { compKind= occNameToComKind name
298- , insertText= rend
297+ , insertText= snippetText rend
299298 , provenance = DefinedIn mod
300299 , label= rend
301300 , typeText = Nothing
@@ -459,10 +458,11 @@ localCompletionsForParsedModule uri pm@ParsedModule{pm_parsed_source = L _ HsMod
459458 ]
460459
461460 mkLocalComp pos n ctyp ty =
462- CI ctyp pn (Local pos) pn ty Nothing (ctyp `elem` [CompletionItemKind_Struct , CompletionItemKind_Interface ]) Nothing (Just $ NameDetails (ms_mod $ pm_mod_summary pm) occ) True
461+ CI ctyp sn (Local pos) pn ty Nothing (ctyp `elem` [CompletionItemKind_Struct , CompletionItemKind_Interface ]) Nothing (Just $ NameDetails (ms_mod $ pm_mod_summary pm) occ) True
463462 where
464463 occ = rdrNameOcc $ unLoc n
465464 pn = showForSnippet n
465+ sn = snippetText pn
466466
467467findRecordCompl :: Uri -> Provenance -> TyClDecl GhcPs -> [CompItem ]
468468findRecordCompl uri mn DataDecl {tcdLName, tcdDataDefn} = result
@@ -639,7 +639,7 @@ getCompletions
639639 dotFieldSelectorToCompl :: T. Text -> T. Text -> (Bool , CompItem )
640640 dotFieldSelectorToCompl recname label = (True , CI
641641 { compKind = CompletionItemKind_Field
642- , insertText = label
642+ , insertText = snippetText label
643643 , provenance = DefinedIn recname
644644 , label = label
645645 , typeText = Nothing
@@ -668,7 +668,7 @@ getCompletions
668668 endLoc = upperRange oldPos
669669 localCompls = map (uncurry localBindsToCompItem) $ getFuzzyScope localBindings startLoc endLoc
670670 localBindsToCompItem :: Name -> Maybe Type -> CompItem
671- localBindsToCompItem name typ = CI ctyp pn thisModName pn ty Nothing (not $ isValOcc occ) Nothing dets True
671+ localBindsToCompItem name typ = CI ctyp (snippetText pn) thisModName pn ty Nothing (not $ isValOcc occ) Nothing dets True
672672 where
673673 occ = nameOccName name
674674 ctyp = occNameToComKind occ
@@ -737,7 +737,8 @@ uniqueCompl candidate unique =
737737 -- filter global completions when we already have a local one
738738 || not (isLocalCompletion candidate) && isLocalCompletion unique
739739 then EQ
740- else compare (importedFrom candidate, insertText candidate) (importedFrom unique, insertText unique)
740+ else compare (importedFrom candidate) (importedFrom unique) <>
741+ snippetLexOrd (insertText candidate) (insertText unique)
741742 other -> other
742743 where
743744 importedFrom :: CompItem -> T. Text
@@ -806,9 +807,10 @@ mkRecordSnippetCompItem uri parent ctxStr compl importedFrom imp = r
806807 }
807808
808809 placeholder_pairs = zip compl ([1 .. ]:: [Int ])
809- snippet_parts = map (\ (x, i) -> x <> " =${" <> T. pack (show i) <> " :_" <> x <> " }" ) placeholder_pairs
810- snippet = T. intercalate (T. pack " , " ) snippet_parts
811- 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 <> " }"
812814
813815getImportQual :: LImportDecl GhcPs -> Maybe T. Text
814816getImportQual (L _ imp)
0 commit comments