Skip to content

"Add throws declaration" formats entire file #1095

Closed

Description

@gdoenlen

When you use the "Add throws declaration" it formats the entire file instead of just adding the throws clause to the current function.

Environment
  • Operating System: Windows 10
  • JDK version: openjdk 11.0.4 2019-07-16
  • Visual Studio Code version: 1.38.1
  • Java extension version: 0.50.0
Steps To Reproduce
  1. Create a java file start writing some code and have it not match the default formatter. (like indenting case under a switch)

  2. write a function that calls a function that throws a checked exception (like CompletableFuture.get)

  3. Use the suggestion to add throws declarations to the current function.

Current Result

Throws declarations are added but the entire file gets formatted

Expected Result

only the throws declarations should be added to the current function and the rest of the file is untouched.

Activity

  1. robstryker commented on Oct 29, 2026

    @robstryker
    Contributor

    Created file as such:

    public class Test3 {
    
        public void myMain() {
                     int j = 5;
            throwStuff();
        }
    
    
        private void throwStuff()         throws      Exception {
                   throw new Exception("BLAH");
        }
    }
    

    Note the horrific formatting, random spacing, etc.
    I then used ctrl+. on the call inside myMain() to throwStuff(), and only a throws Exception was added to the myMain signature.

    Seems to work as expected. The rest of my garbage formatting remained unchanged.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions