33import  logging 
44import  sys 
55from  dataclasses  import  dataclass 
6- from  typing  import  Any , Callable 
6+ from  typing  import  Any , Callable ,  Optional 
77
88from  codeflash .lsp .helpers  import  is_LSP_enabled 
9- from  codeflash .lsp .lsp_message  import  LspTextMessage , message_delimiter 
9+ from  codeflash .lsp .lsp_message  import  LSPMessageId ,  LspTextMessage , message_delimiter 
1010
1111root_logger  =  None 
1212
13+ message_id_prefix  =  "id:" 
14+ 
1315
1416@dataclass  
1517class  LspMessageTags :
@@ -18,6 +20,7 @@ class LspMessageTags:
1820    lsp : bool  =  False   # lsp                (lsp only) 
1921    force_lsp : bool  =  False   # force_lsp    (you can use this to force a message to be sent to the LSP even if the level is not supported) 
2022    loading : bool  =  False   # loading        (you can use this to indicate that the message is a loading message) 
23+     message_id : Optional [LSPMessageId ] =  None   # example: id:best_candidate 
2124    highlight : bool  =  False   # highlight    (you can use this to highlight the message by wrapping it in ``) 
2225    h1 : bool  =  False   # h1 
2326    h2 : bool  =  False   # h2 
@@ -52,24 +55,27 @@ def extract_tags(msg: str) -> tuple[LspMessageTags, str]:
5255        tags  =  {tag .strip () for  tag  in  tags_str .split ("," )}
5356        message_tags  =  LspMessageTags ()
5457        # manually check and set to avoid repeated membership tests 
55-         if  "lsp"  in  tags :
56-             message_tags .lsp  =  True 
57-         if  "!lsp"  in  tags :
58-             message_tags .not_lsp  =  True 
59-         if  "force_lsp"  in  tags :
60-             message_tags .force_lsp  =  True 
61-         if  "loading"  in  tags :
62-             message_tags .loading  =  True 
63-         if  "highlight"  in  tags :
64-             message_tags .highlight  =  True 
65-         if  "h1"  in  tags :
66-             message_tags .h1  =  True 
67-         if  "h2"  in  tags :
68-             message_tags .h2  =  True 
69-         if  "h3"  in  tags :
70-             message_tags .h3  =  True 
71-         if  "h4"  in  tags :
72-             message_tags .h4  =  True 
58+         for  tag  in  tags :
59+             if  tag .startswith (message_id_prefix ):
60+                 message_tags .message_id  =  LSPMessageId (tag [len (message_id_prefix ) :]).value 
61+             elif  tag  ==  "lsp" :
62+                 message_tags .lsp  =  True 
63+             elif  tag  ==  "!lsp" :
64+                 message_tags .not_lsp  =  True 
65+             elif  tag  ==  "force_lsp" :
66+                 message_tags .force_lsp  =  True 
67+             elif  tag  ==  "loading" :
68+                 message_tags .loading  =  True 
69+             elif  tag  ==  "highlight" :
70+                 message_tags .highlight  =  True 
71+             elif  tag  ==  "h1" :
72+                 message_tags .h1  =  True 
73+             elif  tag  ==  "h2" :
74+                 message_tags .h2  =  True 
75+             elif  tag  ==  "h3" :
76+                 message_tags .h3  =  True 
77+             elif  tag  ==  "h4" :
78+                 message_tags .h4  =  True 
7379        return  message_tags , content 
7480
7581    return  LspMessageTags (), msg 
@@ -114,7 +120,7 @@ def enhanced_log(
114120    if  is_normal_text_message :
115121        clean_msg  =  add_heading_tags (clean_msg , tags )
116122        clean_msg  =  add_highlight_tags (clean_msg , tags )
117-         clean_msg  =  LspTextMessage (text = clean_msg , takes_time = tags .loading ).serialize ()
123+         clean_msg  =  LspTextMessage (text = clean_msg , takes_time = tags .loading ,  message_id = tags . message_id ).serialize ()
118124
119125    actual_log_fn (clean_msg , * args , ** kwargs )
120126
0 commit comments