@@ -939,66 +939,51 @@ def format_diagnostic_for_html(
939
939
return "" .join (formatted )
940
940
941
941
942
- def _is_completion_item_deprecated (item : CompletionItem ) -> bool :
943
- if item .get ("deprecated" , False ):
944
- return True
945
- tags = item .get ("tags" )
946
- if isinstance (tags , list ):
947
- return CompletionItemTag .Deprecated in tags
948
- return False
949
-
950
-
951
- def _wrap_in_tags (tag : str , item : str ) -> str :
952
- return "<{0}>{1}</{0}>" .format (tag , html .escape (item ))
953
-
954
-
955
942
def format_completion (
956
943
item : CompletionItem , index : int , can_resolve_completion_items : bool , session_name : str
957
944
) -> sublime .CompletionItem :
958
945
# This is a hot function. Don't do heavy computations or IO in this function.
959
- item_kind = item .get ("kind" )
960
- kind = COMPLETION_KINDS .get (item_kind , KIND_UNSPECIFIED ) if item_kind else KIND_UNSPECIFIED
961
-
962
- if _is_completion_item_deprecated (item ):
963
- kind = (kind [0 ], '!' , "⚠ {} - Deprecated" .format (kind [2 ]))
964
-
965
- lsp_label = item ["label" ]
966
- lsp_label_details = item .get ("labelDetails" )
967
- lsp_filter_text = item .get ("filterText" )
968
- st_annotation = (item .get ("detail" ) or "" ).replace ('\n ' , ' ' )
969
-
970
- st_details = ""
971
- if can_resolve_completion_items or item .get ("documentation" ):
972
- st_details += make_command_link ("lsp_resolve_docs" , "More" , {"index" : index , "session_name" : session_name })
973
- if lsp_label_details :
974
- if st_details :
975
- st_details += " | "
976
- lsp_label_detail = lsp_label_details .get ("detail" )
977
- lsp_label_description = lsp_label_details .get ("description" )
978
- st_details += "<p>"
979
- # `label` should be rendered most prominent.
980
- st_details += _wrap_in_tags ("b" , lsp_label )
981
- if isinstance (lsp_label_detail , str ):
982
- # `detail` should be rendered less prominent than `label`.
983
- # The string is appended directly after `label`, with no additional white space applied.
984
- st_details += html .escape (lsp_label_detail )
985
- if isinstance (lsp_label_description , str ):
986
- # `description` should be rendered less prominent than `detail`.
987
- # Additional separation is added.
988
- st_details += " - {}" .format (_wrap_in_tags ("i" , lsp_label_description ))
989
- st_details += "</p>"
990
- elif lsp_filter_text and lsp_filter_text != lsp_label :
991
- if st_details :
992
- st_details += " | "
993
- st_details += _wrap_in_tags ("p" , lsp_label )
946
+
947
+ lsp_label = item ['label' ]
948
+ lsp_label_details = item .get ('labelDetails' ) or {}
949
+ lsp_label_detail = lsp_label_details .get ('detail' ) or ""
950
+ lsp_label_description = lsp_label_details .get ('description' ) or ""
951
+ lsp_filter_text = item .get ('filterText' ) or ""
952
+ lsp_detail = (item .get ('detail' ) or "" ).replace ("\n " , " " )
953
+
954
+ kind = COMPLETION_KINDS .get (item .get ('kind' , - 1 ), KIND_UNSPECIFIED )
955
+
956
+ details = [] # type: List[str]
957
+ if can_resolve_completion_items or item .get ('documentation' ):
958
+ details .append (make_command_link ('lsp_resolve_docs' , "More" , {'index' : index , 'session_name' : session_name }))
959
+
960
+ if lsp_label_detail and (lsp_label + lsp_label_detail ).startswith (lsp_filter_text ):
961
+ trigger = lsp_label + lsp_label_detail
962
+ annotation = lsp_label_description or lsp_detail
963
+ elif lsp_label .startswith (lsp_filter_text ):
964
+ trigger = lsp_label
965
+ annotation = lsp_detail
966
+ if lsp_label_detail :
967
+ details .append (html .escape (lsp_label + lsp_label_detail ))
968
+ if lsp_label_description :
969
+ details .append (html .escape (lsp_label_description ))
970
+ else :
971
+ trigger = lsp_filter_text
972
+ annotation = lsp_detail
973
+ details .append (html .escape (lsp_label + lsp_label_detail ))
974
+ if lsp_label_description :
975
+ details .append (html .escape (lsp_label_description ))
976
+
977
+ if item .get ('deprecated' ) or CompletionItemTag .Deprecated in item .get ('tags' , []):
978
+ annotation = "DEPRECATED - " + annotation if annotation else "DEPRECATED"
994
979
995
980
completion = sublime .CompletionItem .command_completion (
996
- trigger = lsp_filter_text or lsp_label ,
997
- command = " lsp_select_completion_item" ,
981
+ trigger = trigger ,
982
+ command = ' lsp_select_completion_item' ,
998
983
args = {"item" : item , "session_name" : session_name },
999
- annotation = st_annotation ,
984
+ annotation = annotation ,
1000
985
kind = kind ,
1001
- details = st_details )
1002
- if item .get (" textEdit" ):
986
+ details = " | " . join ( details ) )
987
+ if item .get (' textEdit' ):
1003
988
completion .flags = sublime .COMPLETION_FLAG_KEEP_PREFIX
1004
989
return completion
0 commit comments