Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Добавлена возможность запуска адаптера в режиме TCP сервера #1454

Merged
merged 2 commits into from
Oct 1, 2024

Conversation

akpaevj
Copy link
Contributor

@akpaevj akpaevj commented Sep 28, 2024

VSC позволяет подключаться к адаптеру по TCP, что позволяет отлаживать весь код адаптера, а не подключаться из IDE к процессу уже после инициализации. Для запуска адаптера в tcp режиме, необходимо передать аргумент --debug, порт отладки - 4711

Summary by CodeRabbit

  • New Features

    • Introduced a debug mode that activates when the --debug argument is provided, allowing for enhanced debugging capabilities.
    • Added a new configuration profile for debugging in the launchSettings.json file.
  • Bug Fixes

    • No specific bug fixes were noted in this release.
  • Refactor

    • Updated the project to use a newer version of C# (from 7.3 to 11.0) for improved language features and performance.

Copy link

coderabbitai bot commented Sep 28, 2024

Walkthrough

The changes introduce a mechanism to enable debugging for the VSCode Debug Adapter by adding a command-line argument that allows the application to listen for TCP connections. A new configuration file is created to facilitate this debugging mode. Additionally, the project file is updated to use a newer version of C#, ensuring compatibility with modern language features.

Changes

File Change Summary
src/VSCode.DebugAdapter/Program.cs Added conditional debug mode in Main method; listens for TCP connections if --debug is provided.
src/VSCode.DebugAdapter/Properties/launchSettings.json Introduced launchSettings.json with a profile for debugging, specifying --debug as command-line argument.
src/VSCode.DebugAdapter/VSCode.DebugAdapter.csproj Updated <LangVersion> from 7.3 to 11.0 in project file.

Possibly related PRs

  • Фикс #1418 #1436: The changes in VSCode.DebugAdapter.csproj regarding the addition of <GenerateRuntimeConfigDevFile> are related to the main PR, as both involve modifications to the same project file, impacting the debugging experience.

Poem

🐇 In the land of code where rabbits play,
A debug path was paved today.
With TCP listening, oh what a sight,
New language features make coding bright!
Hops of joy in every line,
Debugging bliss, how divine! 🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 61b0ef1 and b7f3d0d.

📒 Files selected for processing (1)
  • src/VSCode.DebugAdapter/Program.cs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/VSCode.DebugAdapter/Program.cs

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (4)
src/VSCode.DebugAdapter/Properties/launchSettings.json (1)

5-5: Consider adding the debugging port to the command-line arguments.

The PR objectives mention that the debugging port is set to 4711. However, this port number is not specified in the launch settings. Consider adding it to the commandLineArgs for completeness and to ensure the correct port is used.

You might want to update the commandLineArgs as follows:

-      "commandLineArgs": "--debug"
+      "commandLineArgs": "--debug --port 4711"

This change would explicitly set the debugging port as mentioned in the PR objectives.

src/VSCode.DebugAdapter/VSCode.DebugAdapter.csproj (1)

Line range hint 1-48: Suggestions for future improvements

While not directly related to the current change, here are some suggestions for future improvements:

  1. Consider migrating to .NET Core or .NET 5+ for better cross-platform support and performance improvements. This aligns well with the LinuxDebug configuration and could enhance the overall debugging experience.

  2. Some package versions might be outdated. For example, Newtonsoft.Json is at version 13.0.2. Consider updating to the latest stable versions of all packages for bug fixes and performance improvements.

  3. The presence of a LinuxDebug configuration is great for cross-platform development. Ensure that the new TCP server mode works correctly on both Windows and Linux environments.

To check for outdated packages and consider updating them, you can run the following command:

dotnet list src/VSCode.DebugAdapter/VSCode.DebugAdapter.csproj package --outdated

This will list all outdated packages in the project, allowing you to make informed decisions about updates in the future.

src/VSCode.DebugAdapter/Program.cs (2)

20-31: Approved with suggestions for improvement.

The implementation of the TCP server mode for debugging aligns well with the PR objectives. However, consider the following improvements for increased robustness and flexibility:

  1. Use a more structured approach for parsing command-line arguments, such as Microsoft.Extensions.Configuration.CommandLine or a similar library. This will be more maintainable as the number of potential arguments grows.

  2. Consider making the debug port configurable, either through an environment variable or an additional command-line argument. This would provide more flexibility for different development environments.

  3. Add error handling for potential issues when creating the TCP listener or accepting connections. This will make the application more resilient and easier to troubleshoot.

Example of how you might implement these suggestions:

var config = new ConfigurationBuilder()
    .AddCommandLine(args)
    .AddEnvironmentVariables()
    .Build();

var debugMode = config.GetValue<bool>("debug");
var debugPort = config.GetValue<int>("debugPort", 4711);

if (debugMode)
{
    try
    {
        var listener = TcpListener.Create(debugPort);
        listener.Start();
        Console.WriteLine($"Listening for debug connections on port {debugPort}");

        using var client = listener.AcceptTcpClient();
        using var stream = client.GetStream();

        StartSession(stream, stream);
    }
    catch (Exception ex)
    {
        Console.Error.WriteLine($"Error setting up debug listener: {ex.Message}");
        return;
    }
}
else
{
    StartSession(Console.OpenStandardInput(), Console.OpenStandardOutput());
}

20-31: Summary: Implementation meets objectives, with room for improvement.

The changes successfully implement the TCP server mode for debugging, allowing VSCode to connect to the adapter via TCP as described in the PR objectives. The implementation is straightforward and maintains existing functionality for non-debug mode.

While the basic requirements are met, consider the following improvements to enhance the robustness and flexibility of the implementation:

  1. Implement structured command-line argument parsing for better maintainability.
  2. Make the debug port configurable to accommodate different environments.
  3. Add error handling for the TCP listener setup and connection acceptance.
  4. Consider adding logging for the debug mode to aid in troubleshooting.

These enhancements would make the feature more resilient and adaptable to various development scenarios.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e091463 and 61b0ef1.

📒 Files selected for processing (3)
  • src/VSCode.DebugAdapter/Program.cs (2 hunks)
  • src/VSCode.DebugAdapter/Properties/launchSettings.json (1 hunks)
  • src/VSCode.DebugAdapter/VSCode.DebugAdapter.csproj (1 hunks)
🔇 Additional comments (5)
src/VSCode.DebugAdapter/Properties/launchSettings.json (2)

1-8: LGTM! The launch settings file is correctly structured.

The launchSettings.json file is well-formed and aligns with the PR objectives. It correctly defines a profile for the VSCode.DebugAdapter project with the "--debug" command-line argument, which enables the new TCP server mode as described in the PR summary.


1-8: Verify VSCode integration and consider additional configuration.

While this launchSettings.json file is correctly structured for Visual Studio, the PR objectives mention enabling VSCode to connect to the adapter. Please verify that this configuration is sufficient for VSCode integration. You might need to consider the following:

  1. Ensure that VSCode can read and use this launchSettings.json file.
  2. Check if an additional launch.json file in the .vscode folder is needed for VSCode-specific configuration.
  3. Confirm that the TCP server mode works as expected when launched from both Visual Studio and VSCode.

To help verify the VSCode integration, you can run the following script:

This script will help identify if there are any VSCode-specific configurations present and if the TCP server mode is properly configured across different configuration files.

src/VSCode.DebugAdapter/VSCode.DebugAdapter.csproj (1)

Line range hint 1-48: Discrepancy between PR objectives and file changes

The PR objectives mention adding TCP server mode functionality, but there are no direct changes in this file related to that feature. The language version update could be a preparatory step for implementing the TCP server mode using newer C# features in other files.

To verify the implementation of the TCP server mode, please run the following script:

This script will search for TCP-related code changes and check for new files that might contain the TCP server implementation. The results will help verify if the TCP server mode has been implemented in other files not included in this review.

src/VSCode.DebugAdapter/Program.cs (2)

9-9: LGTM: Added necessary namespace.

The addition of using System.Linq; is appropriate for the new functionality that uses the Contains method on the args array.


28-31: LGTM: Flexible use of StartSession method.

The StartSession method is appropriately used with different input/output streams based on the execution mode. This design allows for seamless integration of the new TCP debug mode while maintaining compatibility with the existing standard I/O mode.

@@ -9,7 +9,7 @@
<Configurations>Debug;Release;LinuxDebug</Configurations>
<AssemblyTitle>VSC debug adapter for 1Script</AssemblyTitle>
<Platforms>AnyCPU</Platforms>
<LangVersion>7.3</LangVersion>
<LangVersion>11.0</LangVersion>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Build Environment Missing .NET SDK

The build process failed because the dotnet command is not available in the environment. Additionally, the codebase is utilizing C# 11.0 features, which require the updated language version.

  • Ensure the build environment has the appropriate .NET SDK installed to support C# 11.0.
  • Verify that all dependencies are compatible with C# 11.0.
🔗 Analysis chain

Significant update to C# language version

The language version has been updated from 7.3 to 11.0, which is a substantial change. While this update allows for the use of newer C# features, it also has several implications:

  1. Ensure all developers have IDEs that support C# 11.0.
  2. Verify that the build environment and CI/CD pipelines are compatible with C# 11.0.
  3. Check for any potential compatibility issues with existing dependencies or .NET Framework versions.
  4. Consider documenting any new C# 11.0 features that will be utilized in the codebase.

To ensure compatibility and proper setup, please run the following verification script:

This script will help verify the .NET SDK version, ensure the project builds successfully with the new language version, and check for any usage of C# 11.0 specific features in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify C# version compatibility and setup

# Test: Check .NET SDK version
dotnet --version

# Test: Verify successful build with new language version
dotnet build src/VSCode.DebugAdapter/VSCode.DebugAdapter.csproj

# Test: Check for any C# 11.0 specific features in the codebase
rg --type csharp "required|record struct|file scoped namespace|raw string literal|utf8 string literal|pattern matching|list patterns" src/

Length of output: 688

@@ -9,7 +9,7 @@
<Configurations>Debug;Release;LinuxDebug</Configurations>
<AssemblyTitle>VSC debug adapter for 1Script</AssemblyTitle>
<Platforms>AnyCPU</Platforms>
<LangVersion>7.3</LangVersion>
<LangVersion>11.0</LangVersion>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а перехода на более старший рантайм не потребует?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Надо проверить

@EvilBeaver EvilBeaver merged commit 5597092 into EvilBeaver:develop Oct 1, 2024
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants