Skip to content

Filter out run and debug contextual menu when the file doesn't contain a Main #937

Open

Description

Run and debug contextual menu are available on files that cannot be run or debug. it would be better to not provide the menu. it will allow having a lighter contextual menu, do nto give false hope to end-users and avoid an error notifications when clicking on it

Environment
  • Operating System:
  • JDK version:
  • Visual Studio Code version:
  • Java extension version:
  • Java Debugger extension version:
Steps To Reproduce
  1. create a java file which does not contain a Main class
  2. right-click on it

[attach a sample project reproducing the error]
attach logs

Current Result
Expected Result
Additional Informations

Activity

  1. testforstephen commented on Jan 20, 2021

    @testforstephen
    Contributor

    The contextual menu is added statically. To support filter out those files without a main method, we have to watch the file changes to dynamically calculate the main method info of the current file and update the menu registry.

  2. github-actions commented on Nov 11, 2025

    @github-actions

    Hi Aurélien Pupier (@apupier), I'm an AI Support assistant here to help with your issue. While the team reviews your request, I wanted to provide some possible tips and documentation that might help you in the meantime.

    • Currently, the Java Debug extension registers Run/Debug on all *.java files regardless of containing a main method. There is no user-facing setting to hide these commands when no entry point exists.
    • A related discussion is in vscode-java-debug issue #1037, where it’s noted that menus are contributed on every Java file and then the debugger searches the workspace for main classes if none are in the current file.
    • To track or request filtering based on presence of a main method, please upvote or comment on that issue.

    labels:

    • enhancement

    duplicateUrls: []

    The team will respond to your issue shortly. I hope these suggestions are helpful in the meantime. If this comment helped you, please give it a 👍. If the suggestion was not helpful or incorrect, please give it a 👎. Your feedback helps us improve!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions