You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Assigning message_tags.message_id = LSPMessageId(...).value assumes all ids after the 'id:' prefix map to enum values; unexpected ids will raise ValueError during enum construction. Consider defensive handling (try/except or validating membership) to avoid crashing logging.
LspMessage.message_id is typed as Optional[str] while callers pass LSPMessageId.value in some places and LSPMessageId is also imported elsewhere. Consider standardizing on Optional[LSPMessageId] or consistently using str to avoid confusion and accidental enum leaks.
# allow the client to know which message it is receivingclassLSPMessageId(enum.Enum):
BEST_CANDIDATE="best_candidate"CANDIDATE="candidate"@dataclassclassLspMessage:
# to show a loading indicator if the operation is taking time like generating candidates or teststakes_time: bool=Falsemessage_id: Optional[str] =Nonedef_loop_through(self, obj: Any) ->Any: # noqa: ANN401
New parameter lsp_message_id was added to code_print; verify all internal callers are updated or have defaults. Also ensure non-LSP path ignores the param safely and that static typing (if any) is updated.
Guard against invalid or unknown message_id values to avoid ValueError when constructing LSPMessageId. Fall back to treating the tag content as a raw string if it doesn't match the enum. This keeps logging resilient to unexpected tags.
for tag in tags:
if tag.startswith(message_id_prefix):
- message_tags.message_id = LSPMessageId(tag[len(message_id_prefix) :]).value+ raw_id = tag[len(message_id_prefix) :]+ try:+ message_tags.message_id = LSPMessageId(raw_id).value+ except ValueError:+ # accept arbitrary IDs without failing enum conversion+ message_tags.message_id = raw_id
elif tag == "lsp":
message_tags.lsp = True
elif tag == "!lsp":
message_tags.not_lsp = True
elif tag == "force_lsp":
message_tags.force_lsp = True
elif tag == "loading":
message_tags.loading = True
elif tag == "highlight":
message_tags.highlight = True
elif tag == "h1":
message_tags.h1 = True
elif tag == "h2":
message_tags.h2 = True
elif tag == "h3":
message_tags.h3 = True
elif tag == "h4":
message_tags.h4 = True
Suggestion importance[1-10]: 7
__
Why: This guards enum construction against invalid message_id values, preventing a potential ValueError at runtime. It's directly applicable to the new loop and improves robustness without altering behavior for valid IDs.
Medium
General
Sanitize optional message ID
Validate or normalize lsp_message_id before forwarding to the logger to avoid emitting empty or whitespace-only IDs. Only attach message_id when a meaningful value is provided. This prevents ambiguous client-side routing.
Why: Trimming and omitting empty message_id avoids emitting meaningless identifiers and is a safe, low-risk improvement aligned with the new parameter usage.
Low
Ensure non-empty task context
If task_id is required by execution_context, passing None may break tracing or cause collisions. Provide a stable fallback (e.g., derive from params) to ensure context is always populated. This prevents missing-context issues in logs and cancellations.
-with execution_context(task_id=getattr(params, "task_id", None)):+task_id = getattr(params, "task_id", None) or getattr(params, "functionName", None) or getattr(params, "textDocument", None) and getattr(getattr(params, "textDocument", None), "uri", None)+with execution_context(task_id=task_id):
Suggestion importance[1-10]: 5
__
Why: Providing a fallback for task_id may help maintain tracing when it's missing, but correctness depends on execution_context requirements and the suitability of fallbacks; impact is moderate and somewhat speculative.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
send a message id with the lsp logs for the client to know when it will receive a specific type of message
currently only telling the client when it start testing a candidate, and when it finds the best candidate, later we can add more to it.
this can be used in the future to implement steps or timeline of the optimization which we discussed before
PR Type
Enhancement
Description
Add LSP message IDs to logs
Propagate IDs through code and text messages
Make task_id optional in execution context
Parse and serialize message_id in LSP messages
Diagram Walkthrough
File Walkthrough
console.py
code_print supports LSP message IDscodeflash/cli_cmds/console.py
lsp_message_idparam tocode_print.message_idtoLspCodeMessage.beta.py
Optional task_id in execution context usagecodeflash/lsp/beta.py
getattr(params, "task_id", None)in two handlers.execution_contextrobust to missing task_id.lsp_logger.py
Logger parses and forwards LSP message IDscodeflash/lsp/lsp_logger.py
message_idtoLspMessageTags.id:tags intoLSPMessageId.message_idwhen serializingLspTextMessage.lsp_message.py
LSP message model gains message_id enumcodeflash/lsp/lsp_message.py
LSPMessageIdenum.message_idtoLspMessagebase.function_optimizer.py
Emit message IDs for candidates and bestcodeflash/optimization/function_optimizer.py
LSPMessageId.CANDIDATEID to candidate code prints.BEST_CANDIDATEID to best candidate print.