Skip to content

Conversation

@Saga4
Copy link
Contributor

@Saga4 Saga4 commented Jul 1, 2025

fix(lsp):

  • Isolates the LSP server from the main CLI argument parser by creating a new, dedicated entry point.
    Previously, the VS Code extension launched the LSP server using the main application's module (codeflash.lsp.beta). This caused the server to crash on startup because it was incorrectly processing the main CLI's argument parser, which expected a subcommand to start like init.

    1. Creating a new codeflash.lsp.server_entry module.
    2. This new entry point starts the pygls server directly, bypassing the main CLI's argument parser entirely.
    3. Configuring the server's root logger to direct all logs to stderr, allowing the VS Code client to capture and display them in the output channel without corrupting the stdout
      communication stream.

    These change basically ensures the LSP server starts reliably and that all its logs are correctly forwarded to the client for a better debugging experience.

PR Type

Bug fix, Enhancement


Description

  • Add show_message_log to LSP server

  • Create dedicated server_entry script

  • Configure stderr logging for VS Code

  • Silence console output and start server


Changes diagram

flowchart LR
  A["setup_logging()"] --> B["Configure stderr logging"]
  B --> C["Start LSP server via server.start_io()"]
  C --> D["show_message_log"]
  D -- "window/logMessage" --> E["VS Code output channel"]
Loading

Changes walkthrough 📝

Relevant files
Enhancement
server.py
Implement show_message_log in server                                         

codeflash/lsp/server.py

  • Import MessageType and LogMessageParams
  • Add show_message_log method for client logging
  • +22/-1   
    Configuration changes
    server_entry.py
    Add server_entry script and logging setup                               

    codeflash/lsp/server_entry.py

  • New entry point script for LSP server
  • Setup logging to stderr with custom formatter
  • Silence console output and start server
  • +42/-0   

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • @github-actions
    Copy link

    github-actions bot commented Jul 1, 2025

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Incorrect import path

    The entry point imports server from codeflash.lsp.beta, but the main server module is in codeflash.lsp.server. Verify that you import the correct module and that server refers to the LanguageServer instance.

    from codeflash.lsp.beta import server

    @github-actions
    Copy link

    github-actions bot commented Jul 1, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Use built-in notify method

    Switch to the server’s built-in notify method and ensure you're calling it on the
    server instance rather than on a non-existent lsp attribute. This aligns with the
    pygls API and avoids attribute errors.

    codeflash/lsp/server.py [74-78]

     lsp_message_type = type_mapping.get(message_type, MessageType.Info)
     # Send log message to client (appears in output channel)
     log_params = LogMessageParams(type=lsp_message_type, message=message)
    -self.lsp.notify("window/logMessage", log_params)
    +self.notify("window/logMessage", log_params)
    Suggestion importance[1-10]: 9

    __

    Why: This corrects the incorrect self.lsp.notify call by using the class’s notify method, avoiding an AttributeError and ensuring messages are properly sent.

    High
    Fix server import path

    Import the server module from its actual path to match the filename (server.py),
    preventing import errors at runtime.

    codeflash/lsp/server_entry.py [12]

    -from codeflash.lsp.beta import server
    +from codeflash.lsp.server import server
    Suggestion importance[1-10]: 9

    __

    Why: The original from codeflash.lsp.beta import server import will fail since the module resides in codeflash.lsp.server, so updating the path prevents a runtime ModuleNotFoundError.

    High
    General
    Normalize message_type casing

    Normalize the incoming message_type to a consistent case (e.g. lowercase) and use
    lowercase keys in the mapping to avoid mismatches. This ensures values like "info"
    or "INFO" still map correctly.

    codeflash/lsp/server.py [59-74]

    -def show_message_log(self, message: str, message_type: str) -> None:
    -    ...
    -    type_mapping = {
    -        "Info": MessageType.Info,
    -        "Warning": MessageType.Warning, 
    -        "Error": MessageType.Error,
    -        "Log": MessageType.Log
    -    }
    -    
    -    lsp_message_type = type_mapping.get(message_type, MessageType.Info)
    +normalized = message_type.lower()
    +type_mapping = {
    +    "info": MessageType.Info,
    +    "warning": MessageType.Warning,
    +    "error": MessageType.Error,
    +    "log": MessageType.Log
    +}
     
    +lsp_message_type = type_mapping.get(normalized, MessageType.Info)
    +
    Suggestion importance[1-10]: 6

    __

    Why: Normalizing message_type input ensures that different casing variants still map correctly, improving robustness without altering core functionality.

    Low

    @Saga4 Saga4 requested a review from mohammedahmed18 July 1, 2025 21:37
    @Saga4 Saga4 requested a review from KRRT7 July 1, 2025 22:19
    @Saga4 Saga4 merged commit 67a9e79 into main Jul 1, 2025
    15 of 16 checks passed
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    3 participants