提交 262141e4 编写于 作者: C Cyrus Najmabadi

Merge remote-tracking branch 'tmat/FixRefMgrSharing' into allowSymbolOOp3

......@@ -37,6 +37,10 @@ indent_size = 2
# Dotnet code style settings:
[*.{cs,vb}]
# IDE0055: Fix formatting
dotnet_diagnostic.IDE0055.severity = warning
# Sort using and Import directives with System.* appearing first
dotnet_sort_system_directives_first = true
dotnet_separate_import_directive_groups = false
......
......@@ -11,22 +11,23 @@ efforts behind them.
| Feature | Branch | State | Developers | Reviewer | LDM Champ |
|----------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------|------------------------------------------------------------------------------|------------------------------------------------------------------------------------|-----------------------------------------|
| [Caller expression attribute](https://github.com/dotnet/csharplang/issues/287) | [caller-expression](https://github.com/dotnet/roslyn/tree/features/caller-expression) | Prototype | [alrz](https://github.com/alrz) | [jcouv](https://github.com/jcouv) | [jcouv](https://github.com/jcouv) |
| [Target-typed new](https://github.com/dotnet/csharplang/issues/100) | [target-typed-new](https://github.com/dotnet/roslyn/tree/features/target-typed-new) | [Merged into 16.7p1](https://github.com/dotnet/roslyn/issues/28489) | [alrz](https://github.com/alrz) | [jcouv](https://github.com/jcouv) | [jcouv](https://github.com/jcouv) |
| [Target-typed new](https://github.com/dotnet/csharplang/issues/100) | [target-typed-new](https://github.com/dotnet/roslyn/tree/features/target-typed-new) | [Merged into 16.7p1](https://github.com/dotnet/roslyn/issues/28489) | [alrz](https://github.com/alrz) | [jcouv](https://github.com/jcouv) | [jcouv](https://github.com/jcouv) |
| [Generic attributes](https://github.com/dotnet/csharplang/issues/124) | [generic-attributes](https://github.com/dotnet/roslyn/tree/features/generic-attributes) | [In Progress](https://github.com/dotnet/roslyn/issues/36285) | [AviAvni](https://github.com/AviAvni) | [agocke](https://github.com/agocke) | [mattwar](https://github.com/mattwar) |
| [Default in deconstruction](https://github.com/dotnet/roslyn/pull/25562) | [decon-default](https://github.com/dotnet/roslyn/tree/features/decon-default) | [Implemented](https://github.com/dotnet/roslyn/issues/25559) | [jcouv](https://github.com/jcouv) | [gafter](https://github.com/gafter) | [jcouv](https://github.com/jcouv) |
| [Relax ordering of `ref` and `partial` modifiers](https://github.com/dotnet/csharplang/issues/946) | [ref-partial](https://github.com/dotnet/roslyn/tree/features/ref-partial) | In Progress | [alrz](https://github.com/alrz) | [gafter](https://github.com/gafter) | [jcouv](https://github.com/jcouv) |
| [Parameter null-checking](https://github.com/dotnet/csharplang/issues/2145) | [param-nullchecking](https://github.com/dotnet/roslyn/tree/features/param-nullchecking) | [In Progress](https://github.com/dotnet/roslyn/issues/36024) | [fayrose](https://github.com/fayrose) | [agocke](https://github.com/agocke) | [jaredpar](https://github.com/jaredpar) |
| [Skip locals init](https://github.com/dotnet/csharplang/issues/1738) | [localsinit](https://github.com/dotnet/roslyn/tree/features/localsinit) | [Merged](https://github.com/dotnet/roslyn/issues/25780) | [t-camaia](https://github.com/t-camaia), [agocke](https://github.com/agocke) | [jaredpar](https://github.com/jaredpar) | [agocke](https://github.com/agocke) |
| [Skip locals init](https://github.com/dotnet/csharplang/issues/1738) | [localsinit](https://github.com/dotnet/roslyn/tree/features/localsinit) | [Merged](https://github.com/dotnet/roslyn/issues/25780) | [t-camaia](https://github.com/t-camaia), [agocke](https://github.com/agocke) | [jaredpar](https://github.com/jaredpar) | [agocke](https://github.com/agocke) |
| [Lambda discard parameters](https://github.com/dotnet/csharplang/issues/111) | master | [Merged](https://github.com/dotnet/roslyn/issues/38820) | [jcouv](https://github.com/jcouv) | [AlekseyTs](https://github.com/AlekseyTs), [chsienki](https://github.com/chsienki) | [jcouv](https://github.com/jcouv) |
| [Native ints](https://github.com/dotnet/csharplang/issues/435) | [features/NativeInt](https://github.com/dotnet/roslyn/tree/features/NativeInt) | [Merged into 16.7p1](https://github.com/dotnet/roslyn/issues/38821) | [cston](https://github.com/cston) | [333fred](https://github.com/333fred), [gafter](https://github.com/gafter) | [jaredpar](https://github.com/jaredpar) |
| [Attributes on local functions](https://github.com/dotnet/csharplang/issues/1888) | [features/local-function-attributes](https://github.com/dotnet/roslyn/tree/features/local-function-attributes) | [Merged](https://github.com/dotnet/roslyn/issues/38801) | [RikkiGibson](https://github.com/RikkiGibson) | [agocke](https://github.com/agocke) | [agocke](https://github.com/agocke) |
| [Native ints](https://github.com/dotnet/csharplang/issues/435) | [features/NativeInt](https://github.com/dotnet/roslyn/tree/features/NativeInt) | [Merged into 16.7p1](https://github.com/dotnet/roslyn/issues/38821) | [cston](https://github.com/cston) | [333fred](https://github.com/333fred), [gafter](https://github.com/gafter) | [jaredpar](https://github.com/jaredpar) |
| [Attributes on local functions](https://github.com/dotnet/csharplang/issues/1888) | [features/local-function-attributes](https://github.com/dotnet/roslyn/tree/features/local-function-attributes) | [Merged](https://github.com/dotnet/roslyn/issues/38801) | [RikkiGibson](https://github.com/RikkiGibson) | [agocke](https://github.com/agocke) | [agocke](https://github.com/agocke) |
| [Function pointers](https://github.com/dotnet/csharplang/issues/191) | [function-pointers](https://github.com/dotnet/roslyn/tree/features/function-pointers) | [In Progress](https://github.com/dotnet/roslyn/issues/38830) | [333fred](https://github.com/333fred) | [AlekseyTs](https://github.com/AlekseyTs) | [jaredpar](https://github.com/jaredpar) |
| [Pattern matching improvements](https://github.com/dotnet/csharplang/issues/2850) | [features/patterns3](https://github.com/dotnet/roslyn/tree/features/patterns3) | [In progress](https://github.com/dotnet/roslyn/issues/41502) ([test](https://github.com/dotnet/roslyn/issues/40727)) | [gafter](https://github.com/gafter) | [RikkiGibson](https://github.com/RikkiGibson),[agocke](https://github.com/agocke) | [gafter](https://github.com/gafter) |
| [Pattern matching improvements](https://github.com/dotnet/csharplang/issues/2850) | [features/patterns3](https://github.com/dotnet/roslyn/tree/features/patterns3) | [In progress](https://github.com/dotnet/roslyn/issues/41502) ([test](https://github.com/dotnet/roslyn/issues/40727)) | [gafter](https://github.com/gafter) | [RikkiGibson](https://github.com/RikkiGibson),[agocke](https://github.com/agocke) | [gafter](https://github.com/gafter) |
| [Static lambdas](https://github.com/dotnet/csharplang/issues/275) | [features/static-lambdas](https://github.com/dotnet/roslyn/tree/features/static-lambdas) | [In progress](https://github.com/dotnet/roslyn/issues/39606) | [CyrusNajmabadi](https://github.com/CyrusNajmabadi) | [jcouv](https://github.com/jcouv) | [jcouv](https://github.com/jcouv) |
| [Records](https://github.com/dotnet/csharplang/issues/39) | [features/records](https://github.com/dotnet/roslyn/tree/features/records) | [In progress](https://github.com/dotnet/roslyn/issues/40726) | [agocke](https://github.com/agocke) | [gafter](https://github.com/gafter), [333fred](https://github.com/333fred) | [agocke](https://github.com/agocke) |
| [Target-typed conditional](https://github.com/dotnet/csharplang/issues/2460) | [features/target-typing](https://github.com/dotnet/roslyn/tree/features/target-typing) | [In Progress](https://github.com/dotnet/roslyn/issues/43186) | [gafter](https://github.com/gafter) | TBD,TBD | [gafter](https://github.com/gafter) |
| [Covariant](https://github.com/dotnet/csharplang/issues/49) [Returns](https://github.com/dotnet/csharplang/issues/2844) | [features/covariant-returns](https://github.com/dotnet/roslyn/tree/features/covariant-returns) | [In Progress](https://github.com/dotnet/roslyn/issues/43188) | [gafter](https://github.com/gafter) | TBD,TBD | [gafter](https://github.com/gafter) |
| [Extension GetEnumerator](https://github.com/dotnet/csharplang/issues/3194) | [features/extension-foreach](https://github.com/dotnet/roslyn/tree/features/extension-foreach) | [In Progress](https://github.com/dotnet/roslyn/issues/43184) | [YairHalberstadt](https://github.com/YairHalberstadt) | [333fred](https://github.com/333fred),TBD | [333fred](https://github.com/333fred) |
| [Records](https://github.com/dotnet/csharplang/issues/39) | [features/records](https://github.com/dotnet/roslyn/tree/features/records) | [In progress](https://github.com/dotnet/roslyn/issues/40726) | [agocke](https://github.com/agocke) | [gafter](https://github.com/gafter), [333fred](https://github.com/333fred) | [agocke](https://github.com/agocke) |
| [Target-typed conditional](https://github.com/dotnet/csharplang/issues/2460) | [features/target-typing](https://github.com/dotnet/roslyn/tree/features/target-typing) | [In Progress](https://github.com/dotnet/roslyn/issues/43186) | [gafter](https://github.com/gafter) | [agocke](https://github.com/agocke), [RikkiGibson](https://github.com/RikkiGibson) | [gafter](https://github.com/gafter) |
| [Covariant](https://github.com/dotnet/csharplang/issues/49) [Returns](https://github.com/dotnet/csharplang/issues/2844) | [features/covariant-returns](https://github.com/dotnet/roslyn/tree/features/covariant-returns) | [In Progress](https://github.com/dotnet/roslyn/issues/43188) | [gafter](https://github.com/gafter) | TBD,TBD | [gafter](https://github.com/gafter) |
| [Extension GetEnumerator](https://github.com/dotnet/csharplang/issues/3194) | [features/extension-foreach](https://github.com/dotnet/roslyn/tree/features/extension-foreach) | [In Progress](https://github.com/dotnet/roslyn/issues/43184) | [YairHalberstadt](https://github.com/YairHalberstadt) | [333fred](https://github.com/333fred) | [333fred](https://github.com/333fred) |
| [Module initializers](https://github.com/RikkiGibson/csharplang/blob/module-initializers/proposals/module-initializers.md) | TBD | [In progress / design](https://github.com/dotnet/roslyn/issues/40500) | [RikkiGibson](https://github.com/RikkiGibson) [jnm2](https://github.com/jnm2)| [AlekseyTs](https://github.com/AlekseyTs) | [gafter](https://github.com/gafter) |
# C# 8.0
......
Source Generators
=================
Summary
-------
Source generators provide a mechanism through which source code can be generated at compile time
and added to the compilation. The additional source can be based on the content of the compilation,
enabling some meta-programming scenarios.
Deprecation notice
----------
Like all pre-release features, code generators will need to be specially enabled, either by passing
`/features:replace` directly to `csc` or by setting the `<Features>replace</Features>` flag in the project file.
Scenarios
---------
* Generate `BoundNode` classes from record definitions.
* Implement `System.ComponentModel.INotifyPropertyChanged`.
* Support code contracts defined through attributes.
* Generate types from structured data similar to F# Type Providers.
* Serialization/deserialization (see https://github.com/agocke/json-serializer)
General
-------
Source generators are implementations of `Microsoft.CodeAnalysis.SourceGenerator`.
```csharp
public abstract class SourceGenerator
{
public abstract void Execute(SourceGeneratorContext context);
}
```
`SourceGenerator` implementations are defined in external assemblies passed to the compiler
using the same `-analyzer:` option used for diagnostic analyzers. Valid source generators
must:
1. Implement `Microsoft.CodeAnalysis.SourceGenerator`
1. Be decorated with the `Microsoft.CodeAnalysis.SourceGeneratorAttribute` to indicate
supported languages.
An assembly can contain a mix of diagnostic analyzers and source generators.
Since generators are loaded from external assemblies, a generator cannot be used to build
the assembly in which it is defined.
`SourceGenerator` has a single `Execute` method that is called by the host -- either the IDE
or the command-line compiler. `Execute` provides
access to the `Compilation` and allows adding source and reporting diagnostics.
```csharp
public abstract class SourceGeneratorContext
{
public abstract Compilation Compilation { get; }
public abstract void ReportDiagnostic(Diagnostic diagnostic);
public abstract void AddCompilationUnit(string name, SyntaxTree tree);
}
```
Generators add source to the compilation using `context.AddCompilationUnit()`.
Source can be added to the compilation but not replaced or rewritten. The `replace` keyword allows redefining methods.
The command-line compiler persists the generated source to support scenarios that require
files on disk (e.g.: navigating to error locations; debugging and setting breakpoints in generated code).
Generated source is persisted to a `GeneratedFiles/{GeneratorAssemblyName}` subfolder within the
`CommandLineArguments.OutputDirectory` using the `name` argument to `AddCompilationUnit`, and an extension based on the language.
For instance, on Windows a call to ```AddCompilationUnit("MyCode", ...);```
from `MyGenerator.dll` for a C# project would be persisted as `obj/debug/GeneratedFiles/MyGenerator.dll/MyCode.cs`.
The `name` must be a valid file name, must be unique across all files produced by the generator for the compilation,
and should be deterministic. (The content of the generated source should be deterministic as well. Both requirements
are necessary to ensure builds are deterministic.) By convention, `name` should be the namespace-qualified
type name of the type modified or generated.
`build clean` should be modified to delete the `GeneratedFiles/` directory.
Execution
---------
Source generators are executed by the command-line compilers and the IDE. The generators
are obtained from the `AnalyzerReference.GetSourceGenerators` for each analyzer reference
specified on the command-line or in the project. `GetSourceGenerators` uses reflection to find types that
inherit from `SourceGenerator` and instantiates those types.
```csharp
public abstract class AnalyzerReference
{
...
public abstract ImmutableArray<SourceGenerator> GetSourceGenerators(string language);
}
```
A public `GeneratedSource` extension method on `Compilation` executes each generator in a collection of generators
and returns the collection of `SyntaxTrees` and `Diagnostics`.
(`GenerateSource` is called by the command-line compilers and IDE.)
If `writeToDisk` is true, the generated source is persisted to `outputPath`. Regardless of whether the tree is persisted
to disk, `SyntaxTree.FilePath` is set.
```csharp
public static class SourceGeneratorExtensions
{
public static ImmutableArray<SyntaxTree> GenerateSource(
this Compilation compilation,
ImmutableArray<SourceGenerator> generators,
string outputPath,
bool writeToDisk,
out ImmutableArray<Diagnostic> diagnostics,
CancellationToken cancellationToken);
}
```
The compilers and IDE add `SyntaxTrees` returned by `GenerateSource` to the `Compilation` to
generate a new `Compilation` that is compiled and passed to any diagnostic analyzers.
Diagnostics from `GenerateSource` are reported to the user.
In the command-line compilers, the compile will be aborted if the diagnostics include errors.
In the IDE, diagnostics are included in the Errors list and errors do not prevent subsequent binding or analysis.
Exceptions thrown from generators are caught by the `GenerateSource` and reported as errors.
Generators may be executed in parallel by `GenerateSource` using the same policy that is used for
concurrent execution of `DiagnosticAnalyzers`.
Modifying Types
---------------
To add members to an existing class, the generated source will define a `partial class`.
In C# this means the original class definition must be defined as `partial`.
To redefine members in generated source, there are new language keywords: `replace` and `original`.
`replace` is a declaration modifier applied to the redefined method, property, or event.
`original` is a reference to the member that is replaced in a `replace` member.
`replace` and `original` are contextual keywords: `replace` is a keyword only when used as a member modifier;
`original` is a keyword only when used within a `replace` method (similar to parser handling of `async` and `await`).
```csharp
// original.cs:
partial class C
{
void F() { }
int P { get; set; }
object this[int index] { get { return null; } }
event EventHandler E;
}
// replace.cs:
partial class C
{
replace void F() { original(); }
replace int P
{
get { return original; }
set { original += value; } // P.get and P.set
}
replace object this[int index]
{
get { return original[index]; }
}
replace event EventHandler E
{
add { original += value; }
remove { original -= value; }
}
}
```
The following `class` and `struct` members can be replaced:
1. Static and instance methods, properties, and events
1. Explicit interface implementations of members
1. User defined operators
1. Static constructors
1. Instance constructors
1. Instance destructors
1. Extension methods
The default constructor can be added by a generator but not replaced.
The following must match when replacing a member:
1. Signature: name, accessibility, arity, return type, parameter number, parameter types and ref-ness
1. Parameter names and default values (to prevent changing the interpretation of call-sites)
1. Type parameters and constraints
1. Attributes on the member, parameters, and return type (including `this` for extension methods)
1. Set of accessors in properties and events
1. Explicit implementation of the member
1. Modifiers: `sealed`, `static`, `virtual`, `new`, and `override`.
If type parameter constraints are specified in the original method but absent in the `replace` method,
the original constraints are used (similar to constraints in overrides).
`abstract` and `extern` members cannot be replaced.
`partial` methods can be replaced although the `partial` modifier is not allowed on the `replace` method.
`async` need not match.
If there are multiple `replace` definitions for the same member, the compiler will report an error
that there are multiple definitions for the member.
_To support scenarios where multiple generators may replace the same method, it will
be necessary to determine an order for the chain of replacements. One possibility is
to use the order of the assemblies containing the generators in the `Compilation`. Another possibility is
to require the ambiguous `replace` members to have explicit ```[Order(...)]``` attributes that indicate the
relative order._
Code Generation
---------------
The replacing methods will have the signature in metadata of the original method,
including the `virtual` and `final` metadata attributes and `override` clause.
The original methods will be emitted with mangled names to avoid multiple definitions with the same
name and signature when the containing type is loaded from metadata.
The mangled name is `<M>v__I` where M is the original method name, qualified by namespace and
type name if an explicit interface implementation, and where I is an index since there may be multiple
overloads that are replaced. (Since the compiler disallows methods and property or event accessors
with the same signatures, the same name mangling can be used for methods and accessors.)
To ensure the mangled names are deterministic, the index is from the original overloads sorted by syntax location.
Since the original methods will have mangled names, the methods are not callable
from source and are therefore emitted as `private`.
In the EE and REPL, which evaluate expressions in the context of methods loaded from metadata (even for projects from source),
the `Binder` implementations for those scenarios will bind `original` to the method with the mangled name.
Since there may be several methods named `<M>v__I` for a given M, with distinct signatures,
the Binder compares method signatures to find the actual original method.
The original methods in metadata will not override any base class or interface members so original
methods will be emitted without `virtual` and with no `override` clause.
If the replacing method does not call the original method (in scenarios where methods are rewritten
completely), the original method will be unused. And since it has a mangled name, the method is not
callable. To avoid bloating the assembly, the compiler should drop those unused
uncallable methods in optimized builds.
Original property and events will be dropped from metadata although the original accessors will be emitted.
The EE and REPL will need to recognize that certain mangled names map to accessors rather than oridinary methods.
CodeAnalysis API
----------------
`SyntaxKind` includes `ReplaceKeyword` and `OriginalKeyword`.
`DeclarationModifiers` includes a `Replace` member.
`IMethodSymbol`, `IPopertySymbol`, `IEventSymbol` include `Replaced` and `ReplacedBy` properties.
Member lookup in expressions in the `SemanticModel` returns the replacing definition.
The semantic model for `original` will return the replaced symbol.
IDE
---
The IDE deals with `Workspace`, `Solution`, `Project`, and `Document`.
Generated source is exposed as `Documents` added to the `Project`.
The generated source is updated in the `Project` on load and on explicit build. At other times, the generated source is potentially stale.
The generated source are files on disk although the IDE does not persist the generated source, only the command-line compiler does.
On load and on build, the IDE will invoke `GenerateSource()` with a `Compilation` from the original source and use
the `FilePath` from each generated `SyntaxTree` to update the `Solution` in the `Workspace` to point to the new set of source files.
`Document.IsGenerated` indicates whether the source was generated. Generated source will be readonly in the IDE
and certain tools such as Rename treat generated source specially.
This proposal has been deprecated in favor of the newer [Source Generators](source-generators.md) proposal.
## Checklist of work for Source Generators:
- [ ] GenerateSource
- [ ] Return errors to caller
- [ ] Catch exceptions and return to caller as errors
- [ ] Execute generators in parallel using same concurrent policy as analyzers (P2)
- [ ] `AddCompilationUnit`
- [ ] Create `GeneratedSource` directory (on demand) in `$OutputPath`
- [ ] Create separate directories for each generator (on demand), using generator assembly file name. e.g.: `$OutputPath/GeneratedSource/MyGenerator.dll/MySource.cs`
- [ ] `AddCompilation` should take `SourceText` and `ParseOptions` rather than `SyntaxTree`: ```AddCompilation(string name, SourceText text, ParseOptions options)```
- [ ] Add `IsGenerated` property to `SyntaxTree`. See `DocumentInfo.IsGenerated` and ```AnalyzerDriver.IsGeneratedCode(SyntaxTree tree)```.
- [ ] Incremental parsing when adding/removing `replace`. See `src/Compilers/CSharp/Test/Syntax/IncrementalParsing/ReplaceOriginalTests.cs`
- [ ] Match signature on replace/original
- [ ] Compare parameter names
- [ ] Compare default values
- [ ] Compare type parameter names and constraints
- [ ] Inherit type parameter constraints from original definition if absent in `replace`
- [ ] Compare set of property/event accessors
- [ ] Compare modifiers: `sealed`, `static`, `virtual`, `new`, and `override`
- [ ] `replace` members
- [ ] `replace` for explicit implementation
- [ ] `replace` for user-defined operators
- [ ] `replace` for static and instance constructors
- [ ] Allow calling `base` constructor in original constructor
- [ ] Allow writing to `readonly` fields in original constructor
- [ ] `replace` for destructors
- [ ] `replace` for field-like events
- [ ] `replace` for extension methods
- [ ] `replace` partial methods
- [ ] `replace` external method
- [ ] Add `Replaced` and `ReplacedBy` to `ISymbol`
- [ ] Report diagnostics
- [ ] Report error for multiple `replace`
- [ ] Report error for signature mismatch
- [ ] Report error for `replace` with no original
- [ ] Report error for a `replace` member with `extern` or `abstract`
- [ ] Allow a member to be replaced multiple times (P2)
- [ ] Use ```[Order]``` attributes to determine chain
- [ ] Emit metadata
- [ ] Include namespace and type name in mangled name of original explicit interface implementation
- [ ] Include (deterministic) unique id in mangled name of original overloaded methods: ```<M>v__0```, ```<M>v__1```, ...
- [ ] Drop original methods that are not called in optimized builds (P2)
- [ ] IDE
- [ ] Include diagnostics from `SourceGenerator.Execute` in Errors list (P2)
- [ ] EnC
- [ ] Changes that add/remove `replace` are considered rude edits
- [ ] EE
- [ ] Bind `original` to mangled method or accessor
- [ ] VB
- [ ] `Replace` keyword in parser and syntax
- [ ] Implement `Replaced` and `ReplacedBy` on `Symbol`
......@@ -10,7 +10,7 @@ The _task type_ may be non-generic, for async methods that do not return a value
To support `await`, the _task type_ must have a corresponding, accessible `GetAwaiter()` method
that returns an instance of an _awaiter type_ (see _C# 7.7.7.1 Awaitable expressions_).
```
```cs
[AsyncMethodBuilder(typeof(MyTaskMethodBuilder<>))]
class MyTask<T>
{
......@@ -28,7 +28,7 @@ class Awaiter<T> : INotifyCompletion
The _builder type_ is a `class` or `struct` that corresponds to the specific _task type_.
The _builder type_ has the following `public` methods.
For non-generic _builder types_, `SetResult()` has no parameters.
```
```cs
class MyTaskMethodBuilder<T>
{
public static MyTaskMethodBuilder<T> Create();
......
......@@ -29,8 +29,8 @@
<!-- Versions used by several individual references below -->
<RoslynDiagnosticsNugetPackageVersion>3.0.0-beta2.20169.3</RoslynDiagnosticsNugetPackageVersion>
<CodeStyleLayerCodeAnalysisVersion>3.3.1</CodeStyleLayerCodeAnalysisVersion>
<MicrosoftCodeAnalysisTestingVersion>1.0.1-beta1.20206.1</MicrosoftCodeAnalysisTestingVersion>
<CodeStyleAnalyzerVersion>3.6.0-2.20157.5</CodeStyleAnalyzerVersion>
<MicrosoftCodeAnalysisTestingVersion>1.0.1-beta1.20210.2</MicrosoftCodeAnalysisTestingVersion>
<CodeStyleAnalyzerVersion>3.7.0-1.20210.7</CodeStyleAnalyzerVersion>
<VisualStudioEditorPackagesVersion>16.4.248</VisualStudioEditorPackagesVersion>
<ILToolsPackageVersion>5.0.0-alpha1.19409.1</ILToolsPackageVersion>
<MicrosoftVisualStudioLanguageServerPackagesVersion>16.3.27-develop-gdd55e997</MicrosoftVisualStudioLanguageServerPackagesVersion>
......@@ -51,7 +51,7 @@
<ICSharpCodeDecompilerVersion>5.0.2.5153</ICSharpCodeDecompilerVersion>
<MicrosoftBuildVersion>15.3.409</MicrosoftBuildVersion>
<MicrosoftBuildFrameworkVersion>15.3.409</MicrosoftBuildFrameworkVersion>
<MicrosoftBuildLocatorVersion>1.2.2</MicrosoftBuildLocatorVersion>
<MicrosoftBuildLocatorVersion>1.2.6</MicrosoftBuildLocatorVersion>
<MicrosoftBuildRuntimeVersion>15.3.409</MicrosoftBuildRuntimeVersion>
<MicrosoftBuildTasksCoreVersion>15.3.409</MicrosoftBuildTasksCoreVersion>
<!--
......@@ -214,7 +214,7 @@
<xunitVersion>2.4.1-pre.build.4059</xunitVersion>
<xunitanalyzersVersion>0.10.0</xunitanalyzersVersion>
<xunitassertVersion>$(xunitVersion)</xunitassertVersion>
<XunitCombinatorialVersion>1.2.7</XunitCombinatorialVersion>
<XunitCombinatorialVersion>1.3.2</XunitCombinatorialVersion>
<xunitextensibilitycoreVersion>$(xunitVersion)</xunitextensibilitycoreVersion>
<xunitrunnerconsoleVersion>2.4.1-pre.build.4059</xunitrunnerconsoleVersion>
<xunitrunnerwpfVersion>1.0.51</xunitrunnerwpfVersion>
......@@ -245,75 +245,7 @@
<MicrosoftVisualStudioStaticReviewsEmbeddableVersion>0.1.102-alpha</MicrosoftVisualStudioStaticReviewsEmbeddableVersion>
<MicrosoftBclAsyncInterfacesVersion>1.1.0</MicrosoftBclAsyncInterfacesVersion>
</PropertyGroup>
<!--
The following packages are considered implementation details and will not be included
in the list of dependencies of Roslyn packages. They won't flow as package references
to the projects that reference Roslyn packages.
-->
<ItemGroup>
<PrivateVisualStudioPackage Include="EnvDTE" />
<PrivateVisualStudioPackage Include="EnvDTE80" />
<PrivateVisualStudioPackage Include="Microsoft.Internal.Performance.CodeMarkers.DesignTime" />
<PrivateVisualStudioPackage Include="Microsoft.Internal.VisualStudio.Shell.Interop.14.0.DesignTime" />
<PrivateVisualStudioPackage Include="Microsoft.MSXML" />
<PrivateVisualStudioPackage Include="Microsoft.ServiceHub.Client" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.CallHierarchy.Package.Definitions" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.ComponentModelHost" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.CodingConventions" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.CoreUtility" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Debugger.Engine-implementation" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Debugger.Metadata-implementation" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Debugger.UI.Interfaces" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Designer.Interfaces" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Editor" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.GraphModel" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.ImageCatalog" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Imaging" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Language.CallHierarchy" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Language.Intellisense" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Language.NavigateTo.Interfaces" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Language.StandardClassification" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.LanguageServer.Client" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.LiveShare.LanguageServices.Guest" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.LiveShare.WebEditors" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.OLE.Interop" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Progression.CodeSchema" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Progression.Common" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Progression.Interfaces" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.RemoteControl" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.SDK.EmbedInteropTypes" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Shell.15.0" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Shell.Design" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Shell.Framework" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Shell.Immutable.10.0" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Shell.Interop.9.0" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Shell.Interop.10.0" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Shell.Interop.11.0" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Shell.Interop.12.1.DesignTime" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Shell.Interop.14.0.DesignTime" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Shell.Interop.15.0.DesignTime" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Shell.Interop.15.3.DesignTime" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Shell.Interop.15.7.DesignTime" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Telemetry" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Text.Data" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Text.Logic" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Text.UI" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Text.UI.Wpf" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.TextManager.Interop.10.0" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.TextManager.Interop.12.0" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.TextManager.Interop.12.1.DesignTime" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.TextManager.Interop.16.0.DesignTime" />
<PrivateVisualStudioPackage Include="Microsoft.VisualStudio.Utilities" />
<PrivateVisualStudioPackage Include="Microsoft.VSSDK.BuildTools" />
<PrivateVisualStudioPackage Include="Newtonsoft.Json" />
<PrivateVisualStudioPackage Include="NuGet.VisualStudio" />
<PrivateVisualStudioPackage Include="StreamJsonRpc" />
<PrivateVisualStudioPackage Include="VSLangProj" />
<PrivateVisualStudioPackage Include="VSLangProj2" />
<PrivateVisualStudioPackage Include="VSLangProj80" />
<PrivateVisualStudioPackage Include="VSLangProj140" />
<PrivateVisualStudioPackage Include="VsWebsite.Interop" />
</ItemGroup>
<PropertyGroup>
<UsingToolPdbConverter>true</UsingToolPdbConverter>
<UsingToolSymbolUploader>true</UsingToolSymbolUploader>
......
......@@ -351,6 +351,12 @@ function TestUsingOptimizedRunner() {
# Minimize all windows to avoid interference during integration test runs
$shell = New-Object -ComObject "Shell.Application"
$shell.MinimizeAll()
# Set registry to take dump automatically when test process crashes
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" /f
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" /f /v DumpType /t REG_DWORD /d 2
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" /f /v DumpCount /t REG_DWORD /d 2
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps" /f /v DumpFolder /t REG_SZ /d "$LogDir"
}
}
......
......@@ -30,6 +30,12 @@
<PropertyGroup Condition="'$(DisableNullableWarnings)' == 'true'">
<NoWarn>$(NoWarn);Nullable</NoWarn>
</PropertyGroup>
<!-- Workaround for https://github.com/dotnet/roslyn/issues/42166 -->
<!-- PERF: This property group prevents the analyzers from CodeStyle NuGet package from being executed by default in all explicit builds (i.e. csc/vbc invocations both inside Visual Studio and from command line prompt) -->
<PropertyGroup Condition="'$(DesignTimeBuild)' != 'true'">
<NoWarn>$(NoWarn);IDE0004;IDE0004WithoutSuggestion;IDE0005;IDE0007;IDE0007WithoutSuggestion;IDE0008;IDE0008WithoutSuggestion;IDE0009;IDE0009WithoutSuggestion;IDE0010;IDE0010WithoutSuggestion;IDE0011;IDE0011WithoutSuggestion;IDE0016;IDE0016WithoutSuggestion;IDE0017;IDE0017WithoutSuggestion;IDE0018;IDE0018WithoutSuggestion;IDE0019;IDE0019WithoutSuggestion;IDE0020;IDE0020WithoutSuggestion;IDE0021;IDE0022;IDE0023;IDE0024;IDE0025;IDE0026;IDE0027;IDE0028;IDE0028WithoutSuggestion;IDE0029;IDE0029WithoutSuggestion;IDE0030;IDE0030WithoutSuggestion;IDE0031;IDE0031WithoutSuggestion;IDE0032;IDE0032WithoutSuggestion;IDE0033;IDE0033WithoutSuggestion;IDE0034;IDE0034WithoutSuggestion;IDE0035;IDE0035WithoutSuggestion;IDE0036;IDE0036WithoutSuggestion;IDE0037;IDE0037WithoutSuggestion;IDE0040;IDE0040WithoutSuggestion;IDE0041;IDE0041WithoutSuggestion;IDE0042;IDE0042WithoutSuggestion;IDE0043;IDE0044;IDE0044WithoutSuggestion;IDE0045;IDE0045WithoutSuggestion;IDE0046;IDE0046WithoutSuggestion;IDE0047;IDE0048;IDE0048WithoutSuggestion;IDE0050;IDE0050WithoutSuggestion;IDE0051;IDE0052;IDE0054;IDE0054WithoutSuggestion;IDE0055;IDE0056;IDE0056WithoutSuggestion;IDE0057;IDE0057WithoutSuggestion;IDE0058;IDE0059;IDE0060;IDE0061;IDE0062;IDE0062WithoutSuggestion;IDE0063;IDE0063WithoutSuggestion;IDE0064;IDE0065;IDE0066;IDE0066WithoutSuggestion;IDE0070;IDE0070WithoutSuggestion;IDE0071;IDE0071WithoutSuggestion;IDE0072;IDE0072WithoutSuggestion;IDE0073;IDE0073WithoutSuggestion;IDE0074;IDE0074WithoutSuggestion;IDE0075;IDE0075WithoutSuggestion;IDE1005;IDE1005WithoutSuggestion;IDE1006;IDE1006WithoutSuggestion</NoWarn>
</PropertyGroup>
<ItemGroup Condition="'$(Language)' == 'CSharp' and '$(TargetFramework)' == 'net20'">
<_ExplicitReference Include="$(FrameworkPathOverride)\mscorlib.dll" />
......@@ -195,13 +201,6 @@
</PropertyGroup>
</Target>
<!--
Exclude private Visual Studio packages from dependencies of Roslyn packages.
-->
<ItemGroup Condition="'$(IsPackable)' == 'true'">
<PackageReference Update="@(PrivateVisualStudioPackage)" PrivateAssets="all"/>
</ItemGroup>
<!-- Make sure additional files show up in Solution Explorer -->
<ItemGroup>
<!--
......
......@@ -173,7 +173,7 @@ public bool TryAddHashedSymbol(IOperation value, bool seenHash)
return false;
}
private static bool TryGetFieldOrProperty(IOperation operation, [NotNullWhen(true)]out ISymbol? symbol)
private static bool TryGetFieldOrProperty(IOperation operation, [NotNullWhen(true)] out ISymbol? symbol)
{
operation = Unwrap(operation);
......
......@@ -338,6 +338,7 @@ protected override INamespaceSymbol CommonCreateErrorNamespaceSymbol(INamespaceS
//
// TODO: Consider reusing some results of the assembly binding to improve perf
// since most of the binding work is similar.
// https://github.com/dotnet/roslyn/issues/43397
var compilation = new CSharpCompilation(
assemblyName,
......@@ -609,7 +610,13 @@ public CSharpCompilation WithScriptCompilationInfo(CSharpScriptCompilationInfo?
return this;
}
// Reference binding doesn't depend on previous submission so we can reuse it.
// Metadata references are inherited from the previous submission,
// so we can only reuse the manager if we can guarantee that these references are the same.
// Check if the previous script compilation doesn't change.
// TODO: Consider comparing the metadata references if they have been bound already.
// https://github.com/dotnet/roslyn/issues/43397
bool reuseReferenceManager = ReferenceEquals(ScriptCompilationInfo?.PreviousScriptCompilation, info?.PreviousScriptCompilation);
return new CSharpCompilation(
this.AssemblyName,
......@@ -618,9 +625,9 @@ public CSharpCompilation WithScriptCompilationInfo(CSharpScriptCompilationInfo?
info?.PreviousScriptCompilation,
info?.ReturnTypeOpt,
info?.GlobalsType,
info != null,
isSubmission: info != null,
_referenceManager,
reuseReferenceManager: true,
reuseReferenceManager,
syntaxAndDeclarations: _syntaxAndDeclarations);
}
......@@ -912,6 +919,7 @@ public new CSharpCompilation ReplaceSyntaxTree(SyntaxTree oldTree, SyntaxTree? n
// TODO(tomat): Consider comparing #r's of the old and the new tree. If they are exactly the same we could still reuse.
// This could be a perf win when editing a script file in the IDE. The services create a new compilation every keystroke
// that replaces the tree with a new one.
// https://github.com/dotnet/roslyn/issues/43397
var reuseReferenceManager = !oldTree.HasReferenceOrLoadDirectives() && !newTree.HasReferenceOrLoadDirectives();
syntaxAndDeclarations = syntaxAndDeclarations.ReplaceSyntaxTree(oldTree, newTree);
......
......@@ -521,8 +521,8 @@ public void CloseMethod(BoundStatement body)
SynthesizedLocalKind kind = SynthesizedLocalKind.LoweringTemp
#if DEBUG
,
[CallerLineNumber]int createdAtLineNumber = 0,
[CallerFilePath]string? createdAtFilePath = null
[CallerLineNumber] int createdAtLineNumber = 0,
[CallerFilePath] string? createdAtFilePath = null
#endif
)
{
......@@ -1368,8 +1368,8 @@ internal BoundExpression Not(BoundExpression expression)
SynthesizedLocalKind kind = SynthesizedLocalKind.LoweringTemp,
SyntaxNode? syntaxOpt = null
#if DEBUG
, [CallerLineNumber]int callerLineNumber = 0
, [CallerFilePath]string? callerFilePath = null
, [CallerLineNumber] int callerLineNumber = 0
, [CallerFilePath] string? callerFilePath = null
#endif
)
{
......
......@@ -38,8 +38,8 @@ internal sealed class SynthesizedLocal : LocalSymbol
RefKind refKind = RefKind.None
#if DEBUG
,
[CallerLineNumber]int createdAtLineNumber = 0,
[CallerFilePath]string createdAtFilePath = null
[CallerLineNumber] int createdAtLineNumber = 0,
[CallerFilePath] string createdAtFilePath = null
#endif
)
{
......
......@@ -28,8 +28,8 @@ public class CodeGen_DynamicTests : CSharpTestBase
string expectedUnoptimizedIL = null,
MetadataReference[] references = null,
bool allowUnsafe = false,
[CallerFilePath]string callerPath = null,
[CallerLineNumber]int callerLine = 0,
[CallerFilePath] string callerPath = null,
[CallerLineNumber] int callerLine = 0,
CSharpParseOptions parseOptions = null,
Verification verify = Verification.Passes)
{
......
......@@ -2076,6 +2076,44 @@ class C { }", options: TestOptions.Script);
Assert.False(arc.ReferenceManagerEquals(ars));
}
[Fact]
public void ReferenceManagerReuse_WithScriptCompilationInfo()
{
// Note: The following results would change if we optimized sharing more: https://github.com/dotnet/roslyn/issues/43397
var c1 = CSharpCompilation.CreateScriptCompilation("c1");
Assert.NotNull(c1.ScriptCompilationInfo);
Assert.Null(c1.ScriptCompilationInfo.PreviousScriptCompilation);
var c2 = c1.WithScriptCompilationInfo(null);
Assert.Null(c2.ScriptCompilationInfo);
Assert.True(c2.ReferenceManagerEquals(c1));
var c3 = c2.WithScriptCompilationInfo(new CSharpScriptCompilationInfo(previousCompilationOpt: null, returnType: typeof(int), globalsType: null));
Assert.NotNull(c3.ScriptCompilationInfo);
Assert.Null(c3.ScriptCompilationInfo.PreviousScriptCompilation);
Assert.True(c3.ReferenceManagerEquals(c2));
var c4 = c3.WithScriptCompilationInfo(null);
Assert.Null(c4.ScriptCompilationInfo);
Assert.True(c4.ReferenceManagerEquals(c3));
var c5 = c4.WithScriptCompilationInfo(new CSharpScriptCompilationInfo(previousCompilationOpt: c1, returnType: typeof(int), globalsType: null));
Assert.False(c5.ReferenceManagerEquals(c4));
var c6 = c5.WithScriptCompilationInfo(new CSharpScriptCompilationInfo(previousCompilationOpt: c1, returnType: typeof(bool), globalsType: null));
Assert.True(c6.ReferenceManagerEquals(c5));
var c7 = c6.WithScriptCompilationInfo(new CSharpScriptCompilationInfo(previousCompilationOpt: c2, returnType: typeof(bool), globalsType: null));
Assert.False(c7.ReferenceManagerEquals(c6));
var c8 = c7.WithScriptCompilationInfo(new CSharpScriptCompilationInfo(previousCompilationOpt: null, returnType: typeof(bool), globalsType: null));
Assert.False(c8.ReferenceManagerEquals(c7));
var c9 = c8.WithScriptCompilationInfo(null);
Assert.True(c9.ReferenceManagerEquals(c8));
}
private sealed class EvolvingTestReference : PortableExecutableReference
{
private readonly IEnumerator<Metadata> _metadataSequence;
......
......@@ -74,7 +74,7 @@ internal static class NativeMethods
internal static extern bool CreateProcess
(
string? lpApplicationName,
[In, Out]StringBuilder lpCommandLine,
[In, Out] StringBuilder lpCommandLine,
IntPtr lpProcessAttributes,
IntPtr lpThreadAttributes,
[In, MarshalAs(UnmanagedType.Bool)]
......
......@@ -391,7 +391,7 @@ protected internal override void AddResponseFileCommands(CommandLineBuilderExten
/// Then we look at the resulting list of strings, and remove any that are
/// illegal identifiers, and pass the remaining ones through to the compiler.
///
/// Note that CSharp does support assigning a value to the constants ... in
/// Note that CSharp doesn't support assigning a value to the constants ... in
/// other words, a constant is either defined or not defined ... it can't have
/// an actual value.
/// </summary>
......
......@@ -15,25 +15,25 @@ public virtual int GetTokenFromSig(byte* voidPointerSig, int byteCountSig)
public virtual int GetSigFromToken(
int standaloneSignature,
[Out]byte** signature,
[Out]int* signatureLength)
[Out] byte** signature,
[Out] int* signatureLength)
=> throw new NotImplementedException();
public virtual int GetTypeDefProps(
int typeDef,
[Out]char* qualifiedName,
[Out] char* qualifiedName,
int qualifiedNameBufferLength,
[Out]int* qualifiedNameLength,
[Out]TypeAttributes* attributes,
[Out]int* baseType)
[Out] int* qualifiedNameLength,
[Out] TypeAttributes* attributes,
[Out] int* baseType)
=> throw new NotImplementedException();
public virtual int GetTypeRefProps(
int typeRef,
[Out]int* resolutionScope, // ModuleRef or AssemblyRef
[Out]char* qualifiedName,
[Out] int* resolutionScope, // ModuleRef or AssemblyRef
[Out] char* qualifiedName,
int qualifiedNameBufferLength,
[Out]int* qualifiedNameLength)
[Out] int* qualifiedNameLength)
=> throw new NotImplementedException();
public virtual int GetNestedClassProps(int nestedClass, out int enclosingClass)
......
......@@ -32,11 +32,11 @@ public override int GetTokenFromSig(byte* voidPointerSig, int byteCountSig)
public override int GetTypeDefProps(
int typeDef,
[Out]char* qualifiedName,
[Out] char* qualifiedName,
int qualifiedNameBufferLength,
[Out]int* qualifiedNameLength,
[Out]TypeAttributes* attributes,
[Out]int* baseType)
[Out] int* qualifiedNameLength,
[Out] TypeAttributes* attributes,
[Out] int* baseType)
{
Debug.Assert(baseType == null);
......@@ -65,10 +65,10 @@ public override int GetTokenFromSig(byte* voidPointerSig, int byteCountSig)
public override int GetTypeRefProps(
int typeRef,
[Out]int* resolutionScope, // ModuleRef or AssemblyRef
[Out]char* qualifiedName,
[Out] int* resolutionScope, // ModuleRef or AssemblyRef
[Out] char* qualifiedName,
int qualifiedNameBufferLength,
[Out]int* qualifiedNameLength)
[Out] int* qualifiedNameLength)
=> throw new NotImplementedException();
public override int GetNestedClassProps(int nestedClass, out int enclosingClass)
......
......@@ -33,19 +33,19 @@ internal static string DiaSymReaderModuleName
[DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory | DllImportSearchPath.SafeDirectories)]
[DllImport(DiaSymReaderModuleName32, EntryPoint = CreateSymReaderFactoryName)]
private extern static void CreateSymReader32(ref Guid id, [MarshalAs(UnmanagedType.IUnknown)]out object symReader);
private extern static void CreateSymReader32(ref Guid id, [MarshalAs(UnmanagedType.IUnknown)] out object symReader);
[DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory | DllImportSearchPath.SafeDirectories)]
[DllImport(DiaSymReaderModuleName64, EntryPoint = CreateSymReaderFactoryName)]
private extern static void CreateSymReader64(ref Guid id, [MarshalAs(UnmanagedType.IUnknown)]out object symReader);
private extern static void CreateSymReader64(ref Guid id, [MarshalAs(UnmanagedType.IUnknown)] out object symReader);
[DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory | DllImportSearchPath.SafeDirectories)]
[DllImport(DiaSymReaderModuleName32, EntryPoint = CreateSymWriterFactoryName)]
private extern static void CreateSymWriter32(ref Guid id, [MarshalAs(UnmanagedType.IUnknown)]out object symWriter);
private extern static void CreateSymWriter32(ref Guid id, [MarshalAs(UnmanagedType.IUnknown)] out object symWriter);
[DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory | DllImportSearchPath.SafeDirectories)]
[DllImport(DiaSymReaderModuleName64, EntryPoint = CreateSymWriterFactoryName)]
private extern static void CreateSymWriter64(ref Guid id, [MarshalAs(UnmanagedType.IUnknown)]out object symWriter);
private extern static void CreateSymWriter64(ref Guid id, [MarshalAs(UnmanagedType.IUnknown)] out object symWriter);
[DllImport("kernel32")]
private static extern IntPtr LoadLibrary(string path);
......@@ -56,7 +56,7 @@ internal static string DiaSymReaderModuleName
[DllImport("kernel32")]
private static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);
private delegate void NativeFactory(ref Guid id, [MarshalAs(UnmanagedType.IUnknown)]out object instance);
private delegate void NativeFactory(ref Guid id, [MarshalAs(UnmanagedType.IUnknown)] out object instance);
#if !NET20
private static Lazy<Func<string, string>> s_lazyGetEnvironmentVariable = new Lazy<Func<string, string>>(() =>
......
......@@ -125,12 +125,12 @@ internal interface ISymUnmanagedWriter8 : ISymUnmanagedWriter5
void InitializeDeterministic([MarshalAs(UnmanagedType.IUnknown)] object emitter, [MarshalAs(UnmanagedType.IUnknown)] object stream);
// ISymUnmanagedWriter7
unsafe void UpdateSignatureByHashingContent([In]byte* buffer, int size);
unsafe void UpdateSignatureByHashingContent([In] byte* buffer, int size);
// ISymUnmanagedWriter8
void UpdateSignature(Guid pdbId, uint stamp, int age);
unsafe void SetSourceServerData([In]byte* data, int size);
unsafe void SetSourceLinkData([In]byte* data, int size);
unsafe void SetSourceServerData([In] byte* data, int size);
unsafe void SetSourceLinkData([In] byte* data, int size);
}
/// <summary>
......
......@@ -40,7 +40,7 @@ private WrappedValue ComputeValue(TKey key)
return new WrappedValue { Value = value };
}
internal bool TryGetValue(TKey key, [MaybeNull] [NotNullWhen(true)] out TValue value)
internal bool TryGetValue(TKey key, [MaybeNull][NotNullWhen(true)] out TValue value)
{
// Catch any exceptions from the computeValue callback, which calls into user code.
try
......
......@@ -23,7 +23,7 @@ public CompilationAnalysisValueProvider(AnalysisValueProvider<TKey, TValue> anal
_valueMap = new Dictionary<TKey, TValue>(analysisValueProvider.KeyComparer);
}
internal bool TryGetValue(TKey key, [MaybeNull] [NotNullWhen(true)] out TValue value)
internal bool TryGetValue(TKey key, [MaybeNull][NotNullWhen(true)] out TValue value)
{
// First try to get the cached value for this compilation.
lock (_valueMap)
......
......@@ -223,12 +223,12 @@ public virtual void ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags an
/// <param name="valueProvider">Provider that computes the underlying value.</param>
/// <param name="value">Value associated with the key.</param>
/// <returns>Returns true on success, false otherwise.</returns>
public bool TryGetValue<TValue>(SourceText text, SourceTextValueProvider<TValue> valueProvider, [MaybeNull] [NotNullWhen(true)] out TValue value)
public bool TryGetValue<TValue>(SourceText text, SourceTextValueProvider<TValue> valueProvider, [MaybeNull][NotNullWhen(true)] out TValue value)
{
return TryGetValue(text, valueProvider.CoreValueProvider, out value);
}
private bool TryGetValue<TKey, TValue>(TKey key, AnalysisValueProvider<TKey, TValue> valueProvider, [MaybeNull] [NotNullWhen(true)] out TValue value)
private bool TryGetValue<TKey, TValue>(TKey key, AnalysisValueProvider<TKey, TValue> valueProvider, [MaybeNull][NotNullWhen(true)] out TValue value)
where TKey : class
{
DiagnosticAnalysisContextHelpers.VerifyArguments(key, valueProvider);
......@@ -462,7 +462,7 @@ public virtual void RegisterOperationAction(Action<OperationAnalysisContext> act
/// <param name="valueProvider">Provider that computes the underlying value.</param>
/// <param name="value">Value associated with the key.</param>
/// <returns>Returns true on success, false otherwise.</returns>
public bool TryGetValue<TValue>(SourceText text, SourceTextValueProvider<TValue> valueProvider, [MaybeNull] [NotNullWhen(true)] out TValue value)
public bool TryGetValue<TValue>(SourceText text, SourceTextValueProvider<TValue> valueProvider, [MaybeNull][NotNullWhen(true)] out TValue value)
{
return TryGetValue(text, valueProvider.CoreValueProvider, out value);
}
......@@ -477,19 +477,19 @@ public bool TryGetValue<TValue>(SourceText text, SourceTextValueProvider<TValue>
/// <param name="valueProvider">Provider that computes the underlying value.</param>
/// <param name="value">Value associated with the key.</param>
/// <returns>Returns true on success, false otherwise.</returns>
public bool TryGetValue<TValue>(SyntaxTree tree, SyntaxTreeValueProvider<TValue> valueProvider, [MaybeNull] [NotNullWhen(true)] out TValue value)
public bool TryGetValue<TValue>(SyntaxTree tree, SyntaxTreeValueProvider<TValue> valueProvider, [MaybeNull][NotNullWhen(true)] out TValue value)
{
return TryGetValue(tree, valueProvider.CoreValueProvider, out value);
}
private bool TryGetValue<TKey, TValue>(TKey key, AnalysisValueProvider<TKey, TValue> valueProvider, [MaybeNull] [NotNullWhen(true)] out TValue value)
private bool TryGetValue<TKey, TValue>(TKey key, AnalysisValueProvider<TKey, TValue> valueProvider, [MaybeNull][NotNullWhen(true)] out TValue value)
where TKey : class
{
DiagnosticAnalysisContextHelpers.VerifyArguments(key, valueProvider);
return TryGetValueCore(key, valueProvider, out value);
}
internal virtual bool TryGetValueCore<TKey, TValue>(TKey key, AnalysisValueProvider<TKey, TValue> valueProvider, [MaybeNull] [NotNullWhen(true)] out TValue value)
internal virtual bool TryGetValueCore<TKey, TValue>(TKey key, AnalysisValueProvider<TKey, TValue> valueProvider, [MaybeNull][NotNullWhen(true)] out TValue value)
where TKey : class
{
throw new NotImplementedException();
......@@ -568,7 +568,7 @@ public void ReportDiagnostic(Diagnostic diagnostic)
/// <param name="valueProvider">Provider that computes the underlying value.</param>
/// <param name="value">Value associated with the key.</param>
/// <returns>Returns true on success, false otherwise.</returns>
public bool TryGetValue<TValue>(SourceText text, SourceTextValueProvider<TValue> valueProvider, [MaybeNull] [NotNullWhen(true)] out TValue value)
public bool TryGetValue<TValue>(SourceText text, SourceTextValueProvider<TValue> valueProvider, [MaybeNull][NotNullWhen(true)] out TValue value)
{
return TryGetValue(text, valueProvider.CoreValueProvider, out value);
}
......@@ -583,12 +583,12 @@ public bool TryGetValue<TValue>(SourceText text, SourceTextValueProvider<TValue>
/// <param name="valueProvider">Provider that computes the underlying value.</param>
/// <param name="value">Value associated with the key.</param>
/// <returns>Returns true on success, false otherwise.</returns>
public bool TryGetValue<TValue>(SyntaxTree tree, SyntaxTreeValueProvider<TValue> valueProvider, [MaybeNull] [NotNullWhen(true)] out TValue value)
public bool TryGetValue<TValue>(SyntaxTree tree, SyntaxTreeValueProvider<TValue> valueProvider, [MaybeNull][NotNullWhen(true)] out TValue value)
{
return TryGetValue(tree, valueProvider.CoreValueProvider, out value);
}
private bool TryGetValue<TKey, TValue>(TKey key, AnalysisValueProvider<TKey, TValue> valueProvider, [MaybeNull] [NotNullWhen(true)] out TValue value)
private bool TryGetValue<TKey, TValue>(TKey key, AnalysisValueProvider<TKey, TValue> valueProvider, [MaybeNull][NotNullWhen(true)] out TValue value)
where TKey : class
{
DiagnosticAnalysisContextHelpers.VerifyArguments(key, valueProvider);
......
......@@ -202,7 +202,7 @@ public override void RegisterOperationAction(Action<OperationAnalysisContext> ac
// Issue with enforcing nullability attributes in OHI https://github.com/dotnet/roslyn/issues/42169
#pragma warning disable CS8765 // Type of parameter doesn't match overridden member because of nullability attributes.
internal override bool TryGetValueCore<TKey, TValue>(TKey key, AnalysisValueProvider<TKey, TValue> valueProvider, [MaybeNull] [NotNullWhen(true)] out TValue value)
internal override bool TryGetValueCore<TKey, TValue>(TKey key, AnalysisValueProvider<TKey, TValue> valueProvider, [MaybeNull][NotNullWhen(true)] out TValue value)
#pragma warning restore CS8765
{
var compilationAnalysisValueProvider = _compilationAnalysisValueProviderFactory.GetValueProvider(valueProvider);
......
......@@ -65,11 +65,10 @@ internal static void DumpStackTrace(Exception? exception = null, string? message
if (exception is object)
{
Console.WriteLine("Exception info");
for (Exception? current = exception; current is object; current = current!.InnerException)
for (Exception? current = exception; current is object; current = current.InnerException)
{
Console.WriteLine(current.Message);
Console.WriteLine(current.StackTrace);
current = current.InnerException;
}
}
......
......@@ -112,7 +112,7 @@ internal interface IClrStrongName
[In, MarshalAs(UnmanagedType.LPWStr)] string pwzKeyContainer,
[In] IntPtr pbKeyBlob,
[In, MarshalAs(UnmanagedType.U4)] int cbKeyBlob,
[Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 5)]byte[] ppbSignatureBlob,
[Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 5)] byte[] ppbSignatureBlob,
[MarshalAs(UnmanagedType.U4)] out int pcbSignatureBlob);
void StrongNameSignatureGenerationEx(
......
......@@ -364,7 +364,7 @@ internal partial class CommonReferenceManager<TCompilation, TAssemblySymbol>
ImmutableArray<ResolvedReference> explicitReferenceMap,
ArrayBuilder<AssemblyReferenceBinding[]> referenceBindings,
int totalReferencedAssemblyCount,
[Out]ArrayBuilder<(MetadataReference, ArraySegment<AssemblyReferenceBinding>)> result)
[Out] ArrayBuilder<(MetadataReference, ArraySegment<AssemblyReferenceBinding>)> result)
{
Debug.Assert(result.Count == 0);
......
......@@ -131,7 +131,7 @@ internal T DecodeValue<T>(SpecialType specialType)
return value;
}
internal bool TryDecodeValue<T>(SpecialType specialType, [MaybeNull] [NotNullWhen(returnValue: true)] out T value)
internal bool TryDecodeValue<T>(SpecialType specialType, [MaybeNull][NotNullWhen(returnValue: true)] out T value)
{
if (_kind == TypedConstantKind.Error)
{
......
......@@ -119,7 +119,7 @@ private static int CreateAssemblyNameObject(out IAssemblyName ppEnum, string szA
}
[DllImport("clr", EntryPoint = "CreateAssemblyNameObject", CharSet = CharSet.Unicode, PreserveSig = true)]
private static extern int RealCreateAssemblyNameObject(out IAssemblyName ppEnum, [MarshalAs(UnmanagedType.LPWStr)]string szAssemblyName, uint dwFlags, IntPtr pvReserved);
private static extern int RealCreateAssemblyNameObject(out IAssemblyName ppEnum, [MarshalAs(UnmanagedType.LPWStr)] string szAssemblyName, uint dwFlags, IntPtr pvReserved);
private const int ERROR_INSUFFICIENT_BUFFER = unchecked((int)0x8007007A);
private const int FUSION_E_INVALID_NAME = unchecked((int)0x80131047);
......
......@@ -661,7 +661,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Return Me
End If
' Reference binding doesn't depend on previous submission so we can reuse it.
' Metadata references are inherited from the previous submission,
' so we can only reuse the manager if we can guarantee that these references are the same.
' Check if the previous script compilation doesn't change.
' TODO Consider comparing the metadata references if they have been bound already.
' https://github.com/dotnet/roslyn/issues/43397
Dim reuseReferenceManager = ScriptCompilationInfo?.PreviousScriptCompilation Is info?.PreviousScriptCompilation
Return New VisualBasicCompilation(
Me.AssemblyName,
......@@ -677,7 +683,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
info?.GlobalsType,
info IsNot Nothing,
_referenceManager,
reuseReferenceManager:=True)
reuseReferenceManager)
End Function
''' <summary>
......
......@@ -2049,15 +2049,6 @@ End Class
Assert.False(c1.ReferenceManagerEquals(c2))
End Sub
<Fact>
Public Sub ReferenceManagerReuse_WithPreviousSubmission()
Dim s1 = VisualBasicCompilation.CreateScriptCompilation("s1")
Dim s2 = VisualBasicCompilation.CreateScriptCompilation("s2")
Dim s3 = s2.WithScriptCompilationInfo(s2.ScriptCompilationInfo.WithPreviousScriptCompilation(s1))
Assert.True(s2.ReferenceManagerEquals(s3))
End Sub
<Fact>
Public Sub ReferenceManagerReuse_WithXmlFileResolver()
Dim c1 = VisualBasicCompilation.Create("c", options:=TestOptions.ReleaseDll)
......@@ -2176,6 +2167,43 @@ End Class
Assert.False(arc.ReferenceManagerEquals(ars))
End Sub
<Fact>
Public Sub ReferenceManagerReuse_WithScriptCompilationInfo()
' Note The following results would change if we optimized sharing more: https://github.com/dotnet/roslyn/issues/43397
Dim c1 = VisualBasicCompilation.CreateScriptCompilation("c1")
Assert.NotNull(c1.ScriptCompilationInfo)
Assert.Null(c1.ScriptCompilationInfo.PreviousScriptCompilation)
Dim c2 = c1.WithScriptCompilationInfo(Nothing)
Assert.Null(c2.ScriptCompilationInfo)
Assert.True(c2.ReferenceManagerEquals(c1))
Dim c3 = c2.WithScriptCompilationInfo(New VisualBasicScriptCompilationInfo(previousCompilationOpt:=Nothing, returnType:=GetType(Integer), globalsType:=Nothing))
Assert.NotNull(c3.ScriptCompilationInfo)
Assert.Null(c3.ScriptCompilationInfo.PreviousScriptCompilation)
Assert.True(c3.ReferenceManagerEquals(c2))
Dim c4 = c3.WithScriptCompilationInfo(Nothing)
Assert.Null(c4.ScriptCompilationInfo)
Assert.True(c4.ReferenceManagerEquals(c3))
Dim c5 = c4.WithScriptCompilationInfo(New VisualBasicScriptCompilationInfo(previousCompilationOpt:=c1, returnType:=GetType(Integer), globalsType:=Nothing))
Assert.False(c5.ReferenceManagerEquals(c4))
Dim c6 = c5.WithScriptCompilationInfo(New VisualBasicScriptCompilationInfo(previousCompilationOpt:=c1, returnType:=GetType(Boolean), globalsType:=Nothing))
Assert.True(c6.ReferenceManagerEquals(c5))
Dim c7 = c6.WithScriptCompilationInfo(New VisualBasicScriptCompilationInfo(previousCompilationOpt:=c2, returnType:=GetType(Boolean), globalsType:=Nothing))
Assert.False(c7.ReferenceManagerEquals(c6))
Dim c8 = c7.WithScriptCompilationInfo(New VisualBasicScriptCompilationInfo(previousCompilationOpt:=Nothing, returnType:=GetType(Boolean), globalsType:=Nothing))
Assert.False(c8.ReferenceManagerEquals(c7))
Dim c9 = c8.WithScriptCompilationInfo(Nothing)
Assert.True(c9.ReferenceManagerEquals(c8))
End Sub
Private Class EvolvingTestReference
Inherits PortableExecutableReference
......
......@@ -19,7 +19,7 @@ private CSharpDecompiledSourceFormattingRule()
{
}
public override AdjustNewLinesOperation GetAdjustNewLinesOperation(
public override AdjustNewLinesOperation? GetAdjustNewLinesOperation(
SyntaxToken previousToken, SyntaxToken currentToken, AnalyzerConfigOptions options, in NextGetAdjustNewLinesOperation nextOperation)
{
var operation = GetAdjustNewLinesOperation(previousToken, currentToken);
......
......@@ -37,7 +37,7 @@ private SyntaxToken GetStringToken(string text)
}
private void Test(string stringText, string expected, RegexOptions options,
bool runSubTreeTests = true, [CallerMemberName]string name = "",
bool runSubTreeTests = true, [CallerMemberName] string name = "",
bool allowIndexOutOfRange = false,
bool allowNullReference = false,
bool allowOutOfMemory = false,
......
......@@ -970,7 +970,7 @@ public void ReferenceTest15()
<EndOfFile />
</CompilationUnit>
<Diagnostics>
<Diagnostic Message=""{WorkspacesResources.Not_enough_close_parens}"" Span=""[25..25)"" Text="""" />
<Diagnostic Message=""{FeaturesResources.Not_enough_close_parens}"" Span=""[25..25)"" Text="""" />
</Diagnostics>
<Captures>
<Capture Name=""0"" Span=""[10..25)"" Text=""((\w+(\s?)){{2,}}"" />
......@@ -1209,7 +1209,7 @@ public void ReferenceTest18()
<EndOfFile />
</CompilationUnit>
<Diagnostics>
<Diagnostic Message=""{string.Format(WorkspacesResources.Reference_to_undefined_group_name_0, "Open")}"" Span=""[20..24)"" Text=""Open"" />
<Diagnostic Message=""{string.Format(FeaturesResources.Reference_to_undefined_group_name_0, "Open")}"" Span=""[20..24)"" Text=""Open"" />
</Diagnostics>
<Captures>
<Capture Name=""0"" Span=""[10..35)"" Text=""((?'Close-Open'&gt;)[^&lt;&gt;]*)+"" />
......@@ -1847,7 +1847,7 @@ public void ReferenceTest31()
<EndOfFile />
</CompilationUnit>
<Diagnostics>
<Diagnostic Message=""{string.Format(WorkspacesResources.Reference_to_undefined_group_name_0, "Open")}"" Span=""[19..23)"" Text=""Open"" />
<Diagnostic Message=""{string.Format(FeaturesResources.Reference_to_undefined_group_name_0, "Open")}"" Span=""[19..23)"" Text=""Open"" />
</Diagnostics>
<Captures>
<Capture Name=""0"" Span=""[10..26)"" Text=""(?'Close-Open'&gt;)"" />
......
......@@ -44,7 +44,7 @@ void Main()
options: OptionOn(),
diagnosticId: AbstractRegexDiagnosticAnalyzer.DiagnosticId,
diagnosticSeverity: DiagnosticSeverity.Warning,
diagnosticMessage: string.Format(WorkspacesResources.Regex_issue_0, WorkspacesResources.Too_many_close_parens));
diagnosticMessage: string.Format(FeaturesResources.Regex_issue_0, FeaturesResources.Too_many_close_parens));
}
[Fact, Trait(Traits.Feature, Traits.Features.ValidateRegexString)]
......@@ -63,7 +63,7 @@ void Main()
options: OptionOn(),
diagnosticId: AbstractRegexDiagnosticAnalyzer.DiagnosticId,
diagnosticSeverity: DiagnosticSeverity.Warning,
diagnosticMessage: string.Format(WorkspacesResources.Regex_issue_0, WorkspacesResources.Too_many_close_parens));
diagnosticMessage: string.Format(FeaturesResources.Regex_issue_0, FeaturesResources.Too_many_close_parens));
}
[Fact, Trait(Traits.Feature, Traits.Features.ValidateRegexString)]
......
......@@ -7,7 +7,6 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Structure;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Text;
using Xunit;
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Structure.MetadataAsSource
......@@ -25,9 +24,9 @@ class C
{
public string Text
{
$${|hint:get{|textspan:
$${|#0:get{|textspan:
{
}|}
}|#0}
|}
set
{
......@@ -36,13 +35,7 @@ public string Text
}";
await VerifyBlockSpansAsync(code,
new BlockSpan(
isCollapsible: true,
textSpan: TextSpan.FromBounds(56, 80),
hintSpan: TextSpan.FromBounds(53, 78),
type: BlockTypes.Nonstructural,
bannerText: CSharpStructureHelpers.Ellipsis,
autoCollapse: true));
Region("textspan", "#0", CSharpStructureHelpers.Ellipsis, autoCollapse: true));
}
[Fact, Trait(Traits.Feature, Traits.Features.Outlining)]
......@@ -55,9 +48,9 @@ public string Text
{
{|span1:// My
// Getter|}
$${|hint2:get{|textspan2:
$${|#0:get{|textspan2:
{
}|}
}|#0}
|}
set
{
......@@ -68,13 +61,7 @@ public string Text
await VerifyBlockSpansAsync(code,
Region("span1", "// My ...", autoCollapse: true),
new BlockSpan(
isCollapsible: true,
textSpan: TextSpan.FromBounds(90, 114),
hintSpan: TextSpan.FromBounds(87, 112),
type: BlockTypes.Nonstructural,
bannerText: CSharpStructureHelpers.Ellipsis,
autoCollapse: true));
Region("textspan2", "#0", CSharpStructureHelpers.Ellipsis, autoCollapse: true));
}
[Fact, Trait(Traits.Feature, Traits.Features.Outlining)]
......@@ -87,9 +74,9 @@ public string Text
{
{|span1:/* My
Getter */|}
$${|hint2:get{|textspan2:
$${|#0:get{|textspan2:
{
}|}
}|#0}
|}
set
{
......@@ -100,13 +87,7 @@ public string Text
await VerifyBlockSpansAsync(code,
Region("span1", "/* My ...", autoCollapse: true),
new BlockSpan(
isCollapsible: true,
textSpan: TextSpan.FromBounds(93, 117),
hintSpan: TextSpan.FromBounds(90, 115),
type: BlockTypes.Nonstructural,
bannerText: CSharpStructureHelpers.Ellipsis,
autoCollapse: true));
Region("textspan2", "#0", CSharpStructureHelpers.Ellipsis, autoCollapse: true));
}
}
}
......@@ -7,7 +7,6 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Structure;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Text;
using Xunit;
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Structure.MetadataAsSource
......@@ -81,23 +80,17 @@ public async Task TestConstructor10()
const string code = @"
class C
{
$$public C()
$${|#0:public C(){|textspan:
{
}
}|#0}
|}
public C(int x)
{
}
}";
await VerifyBlockSpansAsync(code,
new BlockSpan(
isCollapsible: true,
textSpan: TextSpan.FromBounds(28, 44),
hintSpan: TextSpan.FromBounds(18, 42),
type: BlockTypes.Nonstructural,
bannerText: CSharpStructureHelpers.Ellipsis,
autoCollapse: true));
Region("textspan", "#0", CSharpStructureHelpers.Ellipsis, autoCollapse: true));
}
}
}
......@@ -7,7 +7,6 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Structure;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Text;
using Xunit;
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Structure.MetadataAsSource
......@@ -65,23 +64,17 @@ public async Task TestOperator3()
const string code = @"
class C
{
$$public static explicit operator C(byte i)
$${|#0:public static explicit operator C(byte i){|textspan:
{
}
}|#0}
|}
public static explicit operator C(short i)
{
}
}";
await VerifyBlockSpansAsync(code,
new BlockSpan(
isCollapsible: true,
textSpan: TextSpan.FromBounds(59, 75),
hintSpan: TextSpan.FromBounds(18, 73),
type: BlockTypes.Nonstructural,
bannerText: CSharpStructureHelpers.Ellipsis,
autoCollapse: true));
Region("textspan", "#0", CSharpStructureHelpers.Ellipsis, autoCollapse: true));
}
}
}
......@@ -7,7 +7,6 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Structure;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Text;
using Xunit;
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Structure.MetadataAsSource
......@@ -36,21 +35,15 @@ public async Task WithAttributes()
{
const string code = @"
{|hint:{|textspan:[Bar]
|}enum $$E|}
|}{|#0:enum $$E|}{|textspan2:
{
A,
B
}";
}|}|#0}";
await VerifyBlockSpansAsync(code,
Region("textspan", "hint", CSharpStructureHelpers.Ellipsis, autoCollapse: true),
new BlockSpan(
isCollapsible: true,
textSpan: TextSpan.FromBounds(15, 36),
hintSpan: TextSpan.FromBounds(9, 36),
type: BlockTypes.Nonstructural,
bannerText: CSharpStructureHelpers.Ellipsis,
autoCollapse: false));
Region("textspan2", "#0", CSharpStructureHelpers.Ellipsis, autoCollapse: false));
}
[Fact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)]
......@@ -60,21 +53,15 @@ public async Task WithCommentsAndAttributes()
{|hint:{|textspan:// Summary:
// This is a summary.
[Bar]
|}enum $$E|}
|}{|#0:enum $$E|}{|textspan2:
{
A,
B
}";
}|}|#0}";
await VerifyBlockSpansAsync(code,
Region("textspan", "hint", CSharpStructureHelpers.Ellipsis, autoCollapse: true),
new BlockSpan(
isCollapsible: true,
textSpan: TextSpan.FromBounds(55, 76),
hintSpan: TextSpan.FromBounds(49, 76),
type: BlockTypes.Nonstructural,
bannerText: CSharpStructureHelpers.Ellipsis,
autoCollapse: false));
Region("textspan2", "#0", CSharpStructureHelpers.Ellipsis, autoCollapse: false));
}
[Fact, Trait(Traits.Feature, Traits.Features.MetadataAsSource)]
......@@ -84,21 +71,15 @@ public async Task WithCommentsAttributesAndModifiers()
{|hint:{|textspan:// Summary:
// This is a summary.
[Bar]
|}public enum $$E|}
|}{|#0:public enum $$E|}{|textspan2:
{
A,
B
}";
}|}|#0}";
await VerifyBlockSpansAsync(code,
Region("textspan", "hint", CSharpStructureHelpers.Ellipsis, autoCollapse: true),
new BlockSpan(
isCollapsible: true,
textSpan: TextSpan.FromBounds(62, 83),
hintSpan: TextSpan.FromBounds(49, 83),
type: BlockTypes.Nonstructural,
bannerText: CSharpStructureHelpers.Ellipsis,
autoCollapse: false));
Region("textspan2", "#0", CSharpStructureHelpers.Ellipsis, autoCollapse: false));
}
[Theory, Trait(Traits.Feature, Traits.Features.Outlining)]
......@@ -109,22 +90,16 @@ public async Task WithCommentsAttributesAndModifiers()
public async Task TestEnum3(string typeKind)
{
var code = $@"
$$enum E
{{|#0:$$enum E{{|textspan:
{{
}}
}}|#0}}
|}}
{typeKind} Following
{{
}}";
await VerifyBlockSpansAsync(code,
new BlockSpan(
isCollapsible: true,
textSpan: TextSpan.FromBounds(8, 16),
hintSpan: TextSpan.FromBounds(2, 14),
type: BlockTypes.Nonstructural,
bannerText: CSharpStructureHelpers.Ellipsis,
autoCollapse: false));
Region("textspan", "#0", CSharpStructureHelpers.Ellipsis, autoCollapse: false));
}
}
}
......@@ -7,7 +7,6 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Structure;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Text;
using Xunit;
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Structure.MetadataAsSource
......@@ -85,12 +84,12 @@ public async Task TestEvent3()
const string code = @"
class C
{
$$event EventHandler E
$${|#0:event EventHandler E{|textspan:
{
add { }
remove { }
}
}|#0}
|}
event EventHandler E2
{
add { }
......@@ -99,13 +98,7 @@ class C
}";
await VerifyBlockSpansAsync(code,
new BlockSpan(
isCollapsible: true,
textSpan: TextSpan.FromBounds(38, 91),
hintSpan: TextSpan.FromBounds(18, 89),
type: BlockTypes.Nonstructural,
bannerText: CSharpStructureHelpers.Ellipsis,
autoCollapse: true));
Region("textspan", "#0", CSharpStructureHelpers.Ellipsis, autoCollapse: true));
}
}
}
......@@ -7,7 +7,6 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Structure;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Text;
using Xunit;
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Structure.MetadataAsSource
......@@ -85,22 +84,16 @@ public async Task TestIndexer3()
const string code = @"
class C
{
$$public string this[int index]
$${|#0:public string this[int index]{|textspan:
{
get { }
}
}|#0}
|}
int Value => 0;
}";
await VerifyBlockSpansAsync(code,
new BlockSpan(
isCollapsible: true,
textSpan: TextSpan.FromBounds(47, 80),
hintSpan: TextSpan.FromBounds(18, 78),
type: BlockTypes.Nonstructural,
bannerText: CSharpStructureHelpers.Ellipsis,
autoCollapse: true));
Region("textspan", "#0", CSharpStructureHelpers.Ellipsis, autoCollapse: true));
}
}
}
......@@ -3,13 +3,13 @@
// See the LICENSE file in the project root for more information.
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp.Structure;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Structure;
using Microsoft.CodeAnalysis.Structure;
using Microsoft.CodeAnalysis.Test.Utilities;
using Xunit;
namespace Microsoft.CodeAnalysis.CSharp.Structure.Outlining
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Structure
{
public class NamespaceDeclarationStructureTests : AbstractCSharpSyntaxNodeStructureTests<NamespaceDeclarationSyntax>
{
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册