rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.2k stars 1.59k forks source link

Unexpected Activation of rust-analyzer in a Swift Project #17018

Open mole828 opened 6 months ago

mole828 commented 6 months ago

Hello,

I am currently working on a Swift project in Visual Studio Code and have encountered an unexpected behavior with the rust-analyzer extension.

When I press the F5 key to debug my Swift project, the rust-analyzer extension is being triggered. This is unexpected as the rust-analyzer extension should ideally only respond to Rust projects.

Here are the steps to reproduce the issue:

Minimum Reproduction Code: https://github.com/mole828/SwiftLearning/tree/02435b6a83b9c09d936cae252cd5821a74ffcd4c Clone the Swift project from this repository. Open the project in Visual Studio Code. Press F5 to start debugging. Expected Behavior: The Swift debugger should start.

Actual Behavior: The rust-analyzer extension is triggered.

I have checked my workspace settings and confirmed that they are correctly set up for a Swift project. I have also verified that the launch.json file in the .vscode directory is correctly configured for Swift debugging.

I would appreciate any guidance on how to prevent rust-analyzer from being activated when working on a Swift project.

Thank you for your time and assistance.

Veykril commented 6 months ago

Can you check the extension host logs? It should tell you what the activation event is that triggered rust-analyzer. Also please check if this also happens with only rust-analyzer and your swift extension enabled and nothing else. There are certain VSCode APIs that some extensions use that activate all extensions registering task providers iirc (something we cant do anything about)

mole828 commented 6 months ago

I tried on Windows (an environment that has detached from the Swift language) and removed all extensions. The complete Extension Host Log is as follows:

2024-04-06 00:48:17.768 [info] Extension host with pid 21424 started
2024-04-06 00:48:17.768 [info] Skipping acquiring lock for c:\Users\mrx80\AppData\Roaming\Code\User\workspaceStorage\f1b118e238b3ec25b6cb80abf3574418.
2024-04-06 00:48:17.782 [info] ExtensionService#_doActivateExtension vscode.emmet, startup: false, activationEvent: 'onLanguage'
2024-04-06 00:48:17.813 [info] ExtensionService#_doActivateExtension vscode.git-base, startup: true, activationEvent: '*', root cause: vscode.git
2024-04-06 00:48:17.828 [info] ExtensionService#_doActivateExtension vscode.git, startup: true, activationEvent: '*'
2024-04-06 00:48:17.879 [info] ExtensionService#_doActivateExtension vscode.github, startup: true, activationEvent: '*'
2024-04-06 00:48:17.945 [info] Eager extensions activated
2024-04-06 00:48:18.002 [info] ExtensionService#_doActivateExtension vscode.debug-auto-launch, startup: false, activationEvent: 'onStartupFinished'
2024-04-06 00:48:18.005 [info] ExtensionService#_doActivateExtension vscode.merge-conflict, startup: false, activationEvent: 'onStartupFinished'
2024-04-06 00:48:18.189 [info] ExtensionService#_doActivateExtension vscode.github-authentication, startup: false, activationEvent: 'onAuthenticationRequest:github'
2024-04-06 00:48:33.741 [info] ExtensionService#_doActivateExtension vscode.debug-server-ready, startup: false, activationEvent: 'onDebugResolve'
2024-04-06 00:48:33.746 [info] ExtensionService#_doActivateExtension vscode.grunt, startup: false, activationEvent: 'onTaskType:grunt'
2024-04-06 00:48:33.749 [info] ExtensionService#_doActivateExtension vscode.gulp, startup: false, activationEvent: 'onTaskType:gulp'
2024-04-06 00:48:33.751 [info] ExtensionService#_doActivateExtension vscode.jake, startup: false, activationEvent: 'onTaskType:jake'
2024-04-06 00:48:33.753 [info] ExtensionService#_doActivateExtension vscode.npm, startup: false, activationEvent: 'onTaskType:npm'
2024-04-06 00:48:33.772 [info] ExtensionService#_doActivateExtension vscode.typescript-language-features, startup: false, activationEvent: 'onTaskType:typescript'
2024-04-06 00:48:33.817 [info] ExtensionService#_doActivateExtension rust-lang.rust-analyzer, startup: false, activationEvent: 'onTaskType:cargo'
roife commented 6 months ago

It seems to be working fine for me on macOS. Could you create a new project for testing? What debugging extension are you using (CodeLLDB or others)? Could you share your configuration?

Veykril commented 6 months ago

Something in your setup is kicking off all onTaskType events starting every extension that has such an activation event (including rust-analyzer).

lnicola commented 6 months ago

CC https://github.com/rust-lang/rust-analyzer/issues/14231

mole828 commented 6 months ago
{
    "configurations": [
        {
            "type": "lldb",
            "request": "launch",
            "sourceLanguages": [
                "swift"
            ],
            "args": [],
            "cwd": "${workspaceFolder:SwiftLearning}",
            "name": "Debug SwiftLearning",
            "program": "${workspaceFolder:SwiftLearning}/.build/debug/SwiftLearning",
            "preLaunchTask": "swift: Build Debug SwiftLearning"
        },
        {
            "type": "lldb",
            "request": "launch",
            "sourceLanguages": [
                "swift"
            ],
            "args": [],
            "cwd": "${workspaceFolder:SwiftLearning}",
            "name": "Release SwiftLearning",
            "program": "${workspaceFolder:SwiftLearning}/.build/release/SwiftLearning",
            "preLaunchTask": "swift: Build Release SwiftLearning"
        }
    ]
}

This is the launch.json, it seems the problem lies with the "preLaunchTask". If this parameter is removed, the problem does not occur. If it is changed to “${defaultBuildTask}”, in the part that is entirely handled by vscode before selecting tasks, it starts rust-analyzer. This seems to have been confirmed as an issue in vscode.