Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue diagnostic for a templated model with a template parameter that is not used. #5494

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

chunyu3
Copy link
Contributor

@chunyu3 chunyu3 commented Jan 6, 2025

Fix #181
Fix #5488

  • check all the usage of the template parameter, if a template parameter is not used, issue diagnostic and dim the template parameter.
  • implement codeFix for unused-template-parameter diagnostic: remove the unused template parameter.

@microsoft-github-policy-service microsoft-github-policy-service bot added the compiler:core Issues for @typespec/compiler label Jan 6, 2025
@azure-sdk
Copy link
Collaborator

azure-sdk commented Jan 6, 2025

All changed packages have been documented.

  • @typespec/compiler
  • @typespec/protobuf
Show changes

@typespec/compiler - feature ✏️

Support diagnostics for unused template parameter in model template

@typespec/protobuf - internal ✏️

Suppress unused-template-parameter diagnostic for Map model

@chunyu3 chunyu3 added ide Issues for VS, VSCode, Monaco, etc. and removed compiler:core Issues for @typespec/compiler labels Jan 6, 2025
@azure-sdk
Copy link
Collaborator

You can try these changes here

🛝 Playground 🌐 Website 📚 Next docs 🛝 VSCode Extension

@markcowl markcowl self-assigned this Jan 9, 2025
Copy link
Contributor

@markcowl markcowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure that we want to do this

"unused-template-parameter": {
severity: "hint",
messages: {
default: paramMessage`Template may only specify used parameter, and '${"parameterName"}' does not exist in type '${"type"}'.`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
default: paramMessage`Template may only specify used parameter, and '${"parameterName"}' does not exist in type '${"type"}'.`,
default: paramMessage`Templates should use all specified parameters, and parameter '${"parameterName"}' does not exist in type '${"type"}'. Consider removing this parameter.`,

@@ -135,6 +135,7 @@ alias integral = int32 | int64 | uint32 | uint64 | boolean;
* @template Key the key type (any integral type or string)
* @template Value the value type (any type other than another map)
*/
#suppress "unused-template-parameter"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a suppression here if this is not a warning? What is the impact of an unsuppressed hint diagnostic on compilation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ide Issues for VS, VSCode, Monaco, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unused template parameter in model template Unused template parameter silently ignored
3 participants