


How to configure vscode to show unnecessary (over-specified) generics in go?
php editor Baicao introduces you how to configure VSCode to display unnecessary generics in Go. With the development of the Go language, generics have become the focus of developers. However, during coding, sometimes we over-specify generics, resulting in code that is verbose and difficult to maintain. To solve this problem, VSCode provides some configuration options that can help us display unnecessary generics in the editor, making the code more concise and readable. The following will introduce you in detail how to configure VSCode to display unnecessary generics, making your Go development more efficient and convenient.
Question content
In the code below
package main import "fmt" func test[A, B any](a A, b B) { fmt.Printf("a: %v, b: %v", a, b) } func main() { test[string, int]("test", 1) }
Explicit type specification when calling test methods is unnecessary and over-specification. Calling test("test", 1")
is sufficient because the type can be inferred from the parameters.
Is it possible to configure VSCode to indicate this? Or is there a linter that can report this issue? I somehow remember seeing VSCode displaying unnecessary type specifications as gray text, but either I messed up my configuration or this functionality is gone.
This is very helpful for more advanced cases, especially since type inference in go is steadily improving and code written for older go versions may be simplified.
Set according to documentation
"gopls": { "ui.diagnostic.analyses": { "infertypeargs": true } }
Should result in a visual indication of unused types. But that didn't come up for me.
Workaround
Currently, this analyzer can only be used via code manipulation within unnecessary type parameters:
x/tools/gopls: infertypeargs no longer generates diagnostic messages #63821 Tracking lack of diagnostic messages. After this issue is resolved, the diagnostic messages should reappear in VS Code.
infertypeargs
Enabled by default, so no configuration is required.
The above is the detailed content of How to configure vscode to show unnecessary (over-specified) generics in go?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The library used for floating-point number operation in Go language introduces how to ensure the accuracy is...

Queue threading problem in Go crawler Colly explores the problem of using the Colly crawler library in Go language, developers often encounter problems with threads and request queues. �...

The difference between string printing in Go language: The difference in the effect of using Println and string() functions is in Go...

The problem of using RedisStream to implement message queues in Go language is using Go language and Redis...

Two ways to define structures in Go language: the difference between var and type keywords. When defining structures, Go language often sees two different ways of writing: First...

What should I do if the custom structure labels in GoLand are not displayed? When using GoLand for Go language development, many developers will encounter custom structure tags...

Which libraries in Go are developed by large companies or well-known open source projects? When programming in Go, developers often encounter some common needs, ...

When using sql.Open, why doesn’t the DSN report an error? In Go language, sql.Open...
