Skip to content

use DiagnosticTag.Unnecessary for validations that point out unnecessary things #1345

Closed

Description

@martinlippert

We have diagnostics in place that point out unnecessary things:

  • Unnecessary @Autowired annotation on constructors
  • Unnecessary @PathVariable annotation when the name matches the parameter name
    (maybe more?)

We should include the DiagnosticTag.Unnecessary in the resulting diagnostic marker. It allows the client to render the part in the editor faded out.

https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#diagnosticTag

(Whether this works in Eclipse would be an additional thing to verify)

Activity

  1. added this to the 4.26.0.RELEASE milestone on Sep 5, 2024
  2. manueljordan commented on Sep 5, 2024

    @manueljordan

    About

    Unnecessary @PathVariable annotation when the name matches the parameter name
    (maybe more?)

    Do you mean about:

    From

    @GetMapping(path={"/ciencias/{id}","/ciencias/{id}.html"})
    String findOneById(Model model, @PathVariable(name="id") Integer id) {
    	model.addAttribute("ciencia", cienciaService.findById(id));
    	return "ciencia/findOne";
    }

    To

    @GetMapping(path={"/ciencias/{id}","/ciencias/{id}.html"})
    String findOneById(Model model, @PathVariable Integer id) {
    	model.addAttribute("ciencia", cienciaService.findById(id));
    	return "ciencia/findOne";
    }

    Therefore from @PathVariable(name="id") to @PathVariable. It thanks to:

    • "/ciencias/{id}"
    • "/ciencias/{id}.html"

    If yes, it applies for @RequestParam too such as:

    From

    @GetMapping(path={"/ciencia","/ciencia.html"})
    String findOneById(Model model, @RequestParam(name="id") Integer id) {
    	model.addAttribute("ciencia", cienciaService.findById(id));
    	return "ciencia/findOne";
    }

    To

    @GetMapping(path={"/ciencia","/ciencia.html"})
    String findOneById(Model model, @RequestParam Integer id) {
    	model.addAttribute("ciencia", cienciaService.findById(id));
    	return "ciencia/findOne";
    }

    But here is tricky because the URL is unknown until runtime

  3. added a commit that references this issue on Nov 18, 2024
  4. martinlippert commented on Nov 18, 2024

    @martinlippert
    MemberAuthor

    @manueljordan This issue is purely about adopting the DiagnosticTag capability of the language server protocol to mark diagnostics as deprecated or unnecessary, so that the client can render those diagnostics accordingly. The two mentioned annotations were just examples.

    The validation that you mentioned for @RequestParam already shipped a few releases ago.

  5. martinlippert commented on Nov 18, 2024

    @martinlippert
    MemberAuthor

    Fixed with e285e3a

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: vscodetheme: validationtype: enhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions