redhat-developer / redhat-developer/vscode-java

"Add throws declaration" formats entire file

Open
#1,095 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

code action
Dominant language
TypeScript
Stars
2.3k
Forks
546
Avg merge
20h 1m
Merged PRs (30d)
11

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Add throws declaration suggestion in a Java file with non-default formatting and a call such as CompletableFuture.get. Trace the suggestion and formatter paths to determine why formatting is triggered; done means only the current function gains its throws declaration and the rest of the file remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, typescript
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.