Public API for "file-local types" #62254
Labels
api-approved
API was approved in API review, it can be implemented
Area-Compilers
Concept-API
This issue involves adding, removing, clarification, or modification of an API.
Feature - File-Local Types
File-local types (file types)
Feature Request
Milestone
Background and Motivation
The file-local types feature (#60819) introduces public APIs.
[update:] API is named
IsFileLocal
Proposed API
Usage Examples
INamedTypeSymbol.IsFile
is needed to implement SymbolKey for file types.roslyn/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/SymbolKey/SymbolKey.NamedTypeSymbolKey.cs
Lines 12 to 22 in b547e91
roslyn/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/SymbolKey/SymbolKey.NamedTypeSymbolKey.cs
Lines 76 to 96 in b547e91
The IDE may also have other places where they want to handle a file type specially. For example, when it is displayed in the navbar or member list.
Whenever the IDE gets the members of a namespace symbol, they may need to filter out file types which aren't available in the current file, for example. LookupSymbols does this automatically when it is given a
INamespaceOrTypeSymbol? container
butINamespaceSymbol.GetMembers()
won't be able to do this automatically.Alternative Designs
We're not proposing any alternative designs here. We think it's not viable to proceed with IDE tooling for the feature without the
INamedTypeSymbol.IsFile
API. It might be possible to go to source for some cases, since file types is a source-only concept, but it is expensive and would break layering for symbol-oriented components to do so. This is something the IDE team strongly wants to avoid.Earlier on we considered having an API
SyntaxTree? INamedTypeSymbol.AssociatedSyntaxTree
, where a non-null return value means the symbol is a file type, and a null return value means it is not a file type. However, it was felt that exposing justbool INamedTypeSymbol.IsFile
is simpler here. Users who want to actually know which file the symbol is declared in can checkDeclaringSyntaxReferences
.Risks
Not aware of any risks from the current design.
SymbolDisplay
We've added internal symbol display options to make it easier to distinguish file types declared in different files with the same name.
This raises a few questions:
@
symbol?The text was updated successfully, but these errors were encountered: