Giter Site home page Giter Site logo

Add SymbolDisplayGenericsOptions.IncludeArity as an alternative to SymbolDisplayGenericsOptions.IncludeTypeParameters about roslyn HOT 14 CLOSED

ericstj avatar ericstj commented on June 20, 2024
Add SymbolDisplayGenericsOptions.IncludeArity as an alternative to SymbolDisplayGenericsOptions.IncludeTypeParameters

from roslyn.

Comments (14)

CyrusNajmabadi avatar CyrusNajmabadi commented on June 20, 2024 1

I bring it up because compiler has UseArityForGenericTypes as an internal option currently.

from roslyn.

CyrusNajmabadi avatar CyrusNajmabadi commented on June 20, 2024 1

in cases like this, where you're making a domain-specific key, our recommendation usually becomes: figure out what your domain needs, and extract out of the symbols. We're unlikely to add a feature (like for methods) that nothing else uses. We end up just chasing how the feature works, as opposed to some facility intrinsic to what the language is modeling.

from roslyn.

ericstj avatar ericstj commented on June 20, 2024 1

Exactly, that's what I'm doing. 👍 I'll close this as I think I have what I need.

from roslyn.

CyrusNajmabadi avatar CyrusNajmabadi commented on June 20, 2024

@ericstj I'm not quite getting the use case. CAn you flesh out the example more, including where generics are used today, and why the actual type argument values are a problem?

from roslyn.

ericstj avatar ericstj commented on June 20, 2024

Here are two cases:
https://github.com/dotnet/sdk/blob/26854d4fe75c45af1c17e696d98ca4c8b509f170/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompatibility/Comparing/SymbolEqualityComparer.cs#L40
https://github.com/dotnet/roslyn-analyzers/blob/b07c100bfc66013a8444172d00cfa04c9ceb5a97/src/PublicApiAnalyzers/Core/Analyzers/DeclarePublicApiAnalyzer.cs#L74

It's actually non-breaking to change the name of a type parameter, however we'd like to make that an optional rule that folks can enable. To do this we'd like to have a symbol representation that omits the generic parameter names, but still represents the arity. That way we can create a key that represents the API without including non-essential information (parameter names). It's a similar scenario to the format of typeof and the docID syntax - which both omit the generic parameter names. If there's an existing API we should be using here I can also investigate changing how we produce the key string.

from roslyn.

CyrusNajmabadi avatar CyrusNajmabadi commented on June 20, 2024

I'd probably prefer emitting as List`1. So something about wanting emitting the rarity instead.

from roslyn.

ericstj avatar ericstj commented on June 20, 2024

I'm not picky on the precise format here. It just needs to represent the number of generic parameters and not their names.

from roslyn.

ericstj avatar ericstj commented on June 20, 2024

Maybe we can just use GetDocumentationCommentId. That does format like we'd want. I might give it a try and see if its' reasonable.

from roslyn.

ericstj avatar ericstj commented on June 20, 2024

One downside I see for swapping to different methods for this is that we call it a lot. So much that I've been thinking about adding a cache for these strings. It would be nice if ISymbol would cache some of these. Maybe we should wrap all the ISymbol interfaces and add caching for the methods/properties we call the most.

from roslyn.

ericstj avatar ericstj commented on June 20, 2024

Looks like GetDocumentationCommentId isn't sufficient as this omits return value. I think exposing UseArityForGenericTypes would work for us.

from roslyn.

ericstj avatar ericstj commented on June 20, 2024

Ok I tested out using UseArityForGenericTypes by setting through reflection. This worked well for classes, but not methods. I would also like a similar setting for methods.

from roslyn.

ericstj avatar ericstj commented on June 20, 2024

I was able to make this work by combining the DocId with the DocID of the type/return-value for members. This gives me what I need.

from roslyn.

ericstj avatar ericstj commented on June 20, 2024

Actually, I see there's a SymbolDisplayParts API, that might be a better way to handle this. I'll experiment with that.

from roslyn.

CyrusNajmabadi avatar CyrusNajmabadi commented on June 20, 2024

And with the SymbolDisplayParts, you can see which are TypeParameter symbols. And you could elide those or transform them into anything you want.

from roslyn.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.