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

Remaining fallback options #60888

Merged
merged 59 commits into from
May 18, 2022
Merged

Remaining fallback options #60888

merged 59 commits into from
May 18, 2022

Conversation

tmat
Copy link
Member

@tmat tmat commented Apr 21, 2022

Threads through fallback options to all remaining call sites that do not have them yet.
Obsoletes Document.GetDocumentOptions and DocumentOptionsSet internally (banned API).

Cleans up option types to use uniform patterns

  • Use init-only properties instead of constructors, unless the option type has non-optional properties in which case these are passed to the constructor.
  • Extension methods GetXyzOptionsAsync(this Document, XyzOptions fallbackOptions) and GetXyzOptionsAsync(this Document, XyzOptionsProvider fallbackOptionsProvider) are defined that read options from document. The former is used when fallbackOptions are readily available, the latter then we need to call a provider to retrieve them.

Language agnostic options

  • Use records.
  • Option type has Default static property that holds on the default values of all options.
  • Extensions method are defined for each option type that reads the options from AnalyzerConfigOptions and IGlobalOptionsService:
    • GetXyzOptions(this AnalyzerConfigOptions, XyzOptions? fallbackOptions)
    • GetXyzOptions(this IGlobalOptionsService)

Language specific options

  • Do not use records. VB doesn't support inheriting from a record and therefore we can't use records neither for the base class nor the C# subtype.
  • XyzOptions is an abstract class and CSharpXyzOptions and VisualBasicXyzOptions are sealed derived classes.
  • Options common to C# and VB are stored in the abstract base class. To avoid repetition when constructing options (via object initializers that assign to init-only properties) the common options are not stored directly on the abstract class but in a nested class CommonOptions. If C# language supported extension constructors we could remove this indirection.
  • CommonOptions has Default static property that holds on the default values of the options.
  • Language specific derived types have Default property that holds on the default values of all options.
  • XyzOptions has GetDefault(HostLanguageServices language) static method that returns language specific instance with default values.

Accessing options from a feature implementation

In general, a feature that is configurable to produce different outputs should take the set of options it depends on as a parameter (of type {FeatureName}Options). Sometimes a feature A calls to feature B and feature B is parameterized by BOptions. Then AOptions type should contain a field/property of type BOptions, since the outcome of A depends on B's options. These options will be serialized as the feature is invoked from the client (if the feature runs OOP) like any other parameters. The granularity of these option types varies. E.g. if a feature X uses mostly the same options as feature Y then it might make more sense to use the same type for both features rather then to define multiple option types.

If a feature depends on options that may vary on per-document basis (e.g. editorconfig options) it is better to retrieve these options from the solution snapshot as the feature traverses the documents it operates on. editorconfig options are part of the solution snapshot and can be retrieved from Document instances via call to AnalyzerConfigOptions Document.GetAnalyzerConfigOptionsAsync(). Then use an extension GetXyzOptions method of AnalyzerConfigOptions to fetch the specific options type. Note that this method takes fallbackOptions. These are values of the corresponding options used when the value of the option is not specified in any editorconfig file that affects the document. Fallback options are global options passed to each feature that might read editorconfig options. Fallback options are generally passed lazily - via a provider interface that allows reading fetching the option set asynchronously and only for a specific language. This is important especially for features that may operate on documents from different projects/languages as we do not want to load options for all languages eagerly.

Accessing options from an analyzer or a code fix (unified across Code Style & Features layers)

Helper types are provided to avoid repetitive code used to access options (usually this code also varies between Code Style layer and other layers):

  • AnalyzerOptionsProvider
  • CSharpAnalyzerOptionsProvider
  • VisualBasicAnalyzerOptionsProvider

The types are structs providing cheap and convenient façades making accessing options from code that executes within various analyzer contexts (SemanticModelAnalysisContext, SyntaxNodeAnalysisContext, SyntaxTreeAnalysisContext, etc.) straightforward and concise. The providers are returned by Get(CSharp|VisualBasic)AnalyzerOptions extension methods defined on the context types.

The types contain properties to read options on as needed basis, they do not have property for every single option.

Similarly CodeFixOptionsProvider, CSharpCodeFixOptionsProvider, VisualBasicCodeFixOptionsProvider are façades that provide options for Code Fixes and are available from extension methods GetCodeFixOptionsAsync defined on Document.

Review

I'd recommend looking at option types like SyntaxFormattingOptions, SimplifierOptions, CodeGenerationOptions, CodeActionOptions, AnalyzerOptionsProvider etc. first in their final form. I iterated quite a bit on shape of these options. Then commit by commit is probably best for rest of the changes.

@tmat tmat force-pushed the RemainingFallbackOptions branch 3 times, most recently from 8a9fe7c to 9f72144 Compare April 25, 2022 04:49
@tmat tmat force-pushed the RemainingFallbackOptions branch 5 times, most recently from 859be5d to a9110fb Compare May 5, 2022 16:19
@tmat tmat force-pushed the RemainingFallbackOptions branch 5 times, most recently from 068d8d8 to 48bc0ae Compare May 16, 2022 03:07
@tmat
Copy link
Member Author

tmat commented May 16, 2022

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 4 pipeline(s).

@tmat tmat marked this pull request as ready for review May 16, 2022 16:11
@tmat tmat requested review from 333fred, JoeRobich and a team as code owners May 16, 2022 16:11
@tmat tmat force-pushed the RemainingFallbackOptions branch 2 times, most recently from 0b52b72 to 08f4137 Compare May 17, 2022 05:53
Copy link
Member

@dibarbet dibarbet left a comment

Choose a reason for hiding this comment

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

that was a long one!

@tmat tmat enabled auto-merge (squash) May 18, 2022 18:05
@tmat tmat disabled auto-merge May 18, 2022 18:06
@tmat tmat enabled auto-merge (squash) May 18, 2022 18:06
@tmat tmat merged commit bb11cf4 into dotnet:main May 18, 2022
@ghost ghost added this to the Next milestone May 18, 2022
@tmat tmat deleted the RemainingFallbackOptions branch May 18, 2022 20:18
@Cosifne Cosifne modified the milestones: Next, 17.3 P2 May 31, 2022
Cosifne added a commit that referenced this pull request Jun 1, 2022
* Avoid caching RelativeIndentationData.effectiveBaseToken

* Relax assertion in SyntheticBoundNodeFactory.Convert (#61287)

* Add missing node state transition

It's valid for an input to be modified causing a downstream input to be removed (for example a syntax tree can change what is in it, leading to the downstream node not generating something). 

//cc @jkoritzinsky in case I'm missing something obvious.

* Simplify logic, more tests, rework tests

* Fix several LSP completion kind mappings (#61243)

* Fix several LSP completion kind mappings

* Extension method

* Fix issue where we were getting a raw-string in a skipped token, causing a crash

* Add test

* Add an UWP OptProf test for IDE

* Disable smart copy/paste when line-copy is involved.

* Update src/EditorFeatures/CSharp/StringCopyPaste/StringCopyPasteCommandHandler.cs

* Add additional sanity check

* Fix

* Add pointer for `AnalysisLevel` to warning waves doc (#61196)

* Remove parameter null-checking from the Language Feature Status list (#61302)

* Switch to GetRequiredService

* Simpler approach

* [EE] Implement IDkmClrFullNameProvider2 in Roslyn's ResultProvider Formatter. (#60522)

* Implement IDkmClrFullNameProvider2 in Roslyn's ResultProvider Formatter.

Issue:
- Debugger added IDkmClrFullNameProvider2 API with https://devdiv.visualstudio.com/DevDiv/_git/Concord/pullrequest/301518
- It is currently temporarily implement in Concord, needs to be implemented in Roslyn so implementation can be removed from Concord.

Changes:
1. Formatter:
- Implement IDkmClrFullNameProvider2. It has 2 methods, one to format local names and the other given field metadata.
- Currently only implemented for C#. I'm not that familiar with VB and the GeneratedNames stuff in VB needs some splitting and moving around to get working.

2. Unit tests:
- Add unit tests for the common cases of hoisted locals, synthesized locals, etc.

3. Versions.props:
Update MicrosoftVSSDKVSDConfigToolVersion to a newer version which recognizes IDkmClrFullNameProvider2.

* PR feedback - fix casing of MetadataImport

* PR feedback - move GetOriginalLocalVariableName, GetOriginalFieldName back to CSharpFormatter

Co-authored-by: Ramkumar Ramesh <ramram@microsoft.com>

* PR feedback

* Fix and/or completion after parenthesized pattern

* [LSP] Disable GoToDef/GoToImpl integration tests  (#61190)

* Added syntax context flag

* Keywords c#

* Keep leadin trivia inside Main method if it is more likely to be a statement comment rather than a file header when converting to 'Program.Main' style program

* Symbols

* Snippets C#

* Remove set accessor of new SyntaxContext property

* Remove PROTOTYPE comments (#61322)

* Added assertions, comments, and refactored for clarity

* Change VB language version Roslyn.sln uses to "latest" (#61313)

To allow us to use the latest VB features, such as setting init-only properties.

* PR feedback

* Remove document options provider (#61228)

* Remove IDocumentOptionsProvider

* Fold DocumentSpecificOptionSet into DocumentOptionSet

* Use an explicit option to control frozen-partial semantics in inheritance margin

* Break into separate methods

* Fix null ref (#61342)

* Simplify internal types search

* Removed unintentional WorkItem's

* Make static

* PR feedback

* [LSP] Support LSP services associated with LSP server instances (with lifetimes that match). (#61266)

* Add support for exporting services that are created for each server
instance.

* Use the correct span to rename after invoking extract-method manually.

* Move Spellcheck capabilities to be activated in all scenarios (#61366)

* move spellcheck capability to always activated server

* Rename type

* rename fields

* [LSP] Add JSON semantic token classifications (#61231)

* Make async

* Test fallout

* Unify nint and IntPtr (#60913)

* restore file

* Minor simplification to rename code

* Remaining fallback options (#60888)

* Add missing fallbacks

* Fallback options from ILegacyGlobalOptionsWorkspaceService

* Pass options to CodeCleaner APIs.

* Fallback options from ILegacyGlobalOptionsWorkspaceService 2

* Fallback in tests

* CodeModel

* Remove CodeActionOptions.Default

* Remove dependency on IGlobalOptionService from inline hints service

* Remove obsolete VS UnitTesting APIs.

* Remote dependency on IGlobalOption service from RemoteProcessTelemetryService

* Remove ExportGlobalOptionProviderAttribute

* Remove PythiaOptions

* Remove DiagnosticOptions from solution snapshot

* Access options via AnalyzerOptionsProvider

* Split ISyntaxFormatting.cs

* Simplify initializers

* Fix

* Move AddImportPlacementOptions to a separate file in compiler extensions

* Move option providers to workspace extensions

* Move CodeCleanupOptions and IdeAnalyzerOptions to workspace extensions

* Layering

* Replace legacy GetOptions with AnalyzerOptionsProvider; add missing options

* Parameter rename, comment

* Add LineFormattingOptionsProviders

* CodeFixOptionsProvider, include CodeStyleOptions in CodeActionOptions, include LineFormattingOptions in ExtractMethodGenerationOptions

* DocumentFormattingOptions

* Move a couple of options from IdeCodeStyle to SyntaxFormatting to make them available to new document formatter

* Generalize using placement option in AddImportPlacementOptions

* Move PreferParameterNullChecking and AllowEmbeddedStatementsOnSameLine to CSharpSimplifierOptions

* Move CodeGen options to compiler extensions

* UseExpressionBody

* Eliminate more calls to Document.GetOptionsAsync

* Cleanup DocumentationCommentOptions

* Line formatting options

* DefaultConditionalExpressionWrappingLength

* insert_final_newline

* Add PreferThrowExpression to simplifier options

* Add AddNullChecksToConstructorsGeneratedFromMembers to CodeGenOptions

* GenerateEqualsAndGetHashCodeFromMembersOptions

* IImplementInterfaceService

* AddParameterCheckCodeRefactoringProvider

* ReplaceMethodWithPropertyService

* NamingStylePreferences

* Eliminate legacy option helpers

* Fix up ExtractMethod options

* Remove SyntaxFormattingOptions ctors

* Replace extra helpers with CodeFixOptionsProvider

* PreferUtf8StringLiterals

* RazorLineFormattingOptionsStorage

* Remove usage of Document.GetOptionsAsync - 1

* Remove internal usage of DocumentOptionSet and Document.GetOptionsAsync

* Simplify and unify option definition patterns

* Fixes and pattern unification

* Serialization and equality

* Simplify

* Rename

* Fixes

* CompletionOption fixes

* Feedback

* Single switch

* Add frozen delegate tests

* Add extract method test

* Add workitem

* Fix

* Add support for CompilerFeatureRequiredAttribute (#61113)

Adds support for decoding and reporting errors when `CompilerFeatureRequiredAttribute` is encountered on metadata type symbols. We also block applying the attribute by hand in both C# and VB.

* Delegate keyword tests

* Verifying interpolation escaping of curlies in content (#61387)

* Verify classification on var pattern (#61376)

* Add lambda parameters in scope in nameof using proper binder (#61382)

* Parse `unchecked` gracefully in operators (#61309)

* Update src/Features/Core/Portable/InheritanceMargin/AbstractInheritanceMarginService_Helpers.cs

* Update src/Features/Core/Portable/InheritanceMargin/AbstractInheritanceMarginService_Helpers.cs

* Use AspNetCoreKey to external access assembly

* Fix typo (#61380)

* Add new collapsing option for metadata files that contain source (#61205)

* More correctly respect background analysis scope (#61392)

* Fix function id (#61400)

* Wait for async operations to complete before proceeding

* Update SDK to .NET 7 Preview 4

* Avoid logging work when no logger is specified

* Emit CompilerFeatureRequired for ref structs when present.

* Support emitting CompilerFeatureRequiredAttribute for contructors of types with required members.

* [LSP] Small cleanup for pull diagnostics logging (#61417)

* Small logging cleanup on pull diagnostics code

* Update tests to account for lsp diagnostics throwing when mismatch in diagnostic mode

* Address feedback from numeric IntPtr feature review (#61418)

* Fix binding for checkbox text in rename dialogs (#61430)

Previously text was bound to properties on the control type using x:Name. This restores that

* Fix build

* Restrict IsGenericConstraintContext for C#

* More instrumentation for ReferenceCachingCS (#61402)

* Do not filter snippets

* Reverted delegate completion

* Allow source link, embedded or decompiled source in Peek Definition (#61427)

* Update status for DIM and numeric IntPtr (#61464)

* Lazily produce semantic models in source generators

* Remove unnecessary finalizer state handling from MethodToStateMachineRewriter (#61409)

* Update src/Tools/IdeCoreBenchmarks/IncrementalSourceGeneratorBenchmarks.cs

* Update src/Tools/IdeCoreBenchmarks/IncrementalSourceGeneratorBenchmarks.cs

* Update src/Tools/IdeCoreBenchmarks/IncrementalSourceGeneratorBenchmarks.cs

* lint

* Address prototype comments (#61436)

* Give a warning when obsolete is applied to a required member and the containing context is not obsolete, or all constructors are not obsolete/setsrequiredmembers.

* Restore nullable constructor warnings for constructors with `SetsRequiredMembersAttribute`.

* Remove prototype comments.

* Add tests and extra state

* Extract checking for generic constraint context to extension method & minor refactoring

* Update test comment

* Generate single OptProf config for compiler vsix

Currently OptProf can't support profiling for multiple flavors of vsix, and Optprof test only runs on X64. Multiple configs with same profiling binary are causing the tests to fail.

* Reduce release/64 limit for EndToEndTests.Constraints (#61480)

* Reduce release/64 limit for EndToEndTests.Constraints

* Lower bar more

* Lower bar more

* Remove parameter nullchecking feature (#61397)

* Fix null ref for JS files (#61472)

* Add file paths to interactive buffers and documents to support LSP requests (#61441)

* Add file paths to interactive buffers and documents to support LSP requests

* Switch to false returning predicate

* more feedback

* mroe feedback

* Reword comment

* Log additional information from CopyRefAssembly (#61384)

* update versioning to use languageserver.client.implementation

* Require VS 17.0 in signed build.

* Bump LSP protocol version (#61494)

* Bump protocol version

* React to breaking changes in foldingrangekind

* Disable inheritance margin for interactive documents (#61476)

* fix

* Improvements to the background compiler component

* add docs

* Simplify

* docs

* Check token

* Simplify

* Simplify

* Rename enum field

* Lifted relational operator implies operands non-null when true (#61403)

* Use ImmutableArray instead of IEnumerable parameters

* Use assignabiilty instead of subclass test in extension loader

* Fix test

* Fix test

* Simplify rename implementation

* Rename

* Unify all end operations that rename performs

* restore code

* Remove unnecessary code'

* Unify error handling in rename

* Add comment

* message severities

* Restore

* Simplify

* Bring main-vs-deps back (#61514)

* Add main-vs-deps back

* Update eng/config/PublishData.json

Co-authored-by: Joey Robichaud <joseph.robichaud@microsoft.com>

Co-authored-by: Joey Robichaud <joseph.robichaud@microsoft.com>

* Simplify LSP reference update

* Adjust conversion from nuint to float/double (#61345)

* Add embedded classification for field initializers

* Add support for properties

* Update src/EditorFeatures/Core/InlineRename/InlineRenameSession.cs

* Update src/EditorFeatures/Core/RenameTracking/RenameTrackingTaggerProvider.RenameTrackingCommitter.cs

* Update src/EditorFeatures/Core/RenameTracking/RenameTrackingTaggerProvider.RenameTrackingCommitter.cs

* Fix setup authoring bug (#61508)

* Expose VirtualChars to asp.net (through EA) to facilitate route classification

* add docs

* Add member

* NRT

* Make async

* Make async

* Pull token out

* Use feature attribute

* Remove Utf8StringLiteral conversion (#61481)

https://github.com/dotnet/csharplang/blob/main/meetings/2022/LDM-2022-04-18.md#target-typing-a-regular-string-literal-to-utf8-types

* Fix AbstractLanguageService constructor (#61513)

* Fix AbstractLanguageService constructor

* Fix formatting

* Don't throw in logging when the document path contains curly braces (#61524)

* Update unit tests

* Improve normalization to match idiomatic patterns for nested usings and fixed statements. (#61533)

* Better syntax normalization for fixed/using statements

* Add tests

* Prepare VB iterators for EnC support (#61488)

* Remove unused parameters

* Separate iterator finalizer states from resumable states.

* Remove unused

* Skip timing test (#61222)

* Skip test

* Add some APIs on AspNetCoreVirtualCharSequence

* Add IsDefault

* Final prototype comments and top level statements local adjustments (#61551)

Clean up the last of the prototype comments and adjust the parsing of locals named required in top level statements.

* IDE Support for Required Members (#61440)

* Add required keyword recommender.

* Add SyntaxNormalizer test.

* Code generation support.

* Add SymbolDisplay

* F1 help service and test fix.

* Add order modifier tests and update.

* Change natural type of UTF-8 string literals to `ReadOnlySpan<byte>` and null terminate the underlying blob. (#61532)

https://github.com/dotnet/csharplang/blob/main/meetings/2022/LDM-2022-04-18.md#natural-type-of-utf8-literals
https://github.com/dotnet/csharplang/blob/main/meetings/2022/LDM-2022-04-18.md#should-utf8-literals-be-null-terminated

Related to #61517
Closes #60644

* fix assumption of length

* Bind native integers in cref (#61431)

* Use VS2022 for PR Validation builds

* PR feedback

* Add unit test project IVT to ExternalAccess.AspNetCore

* Fix generation location when generating across files

* Add test

* Relax check

* EnC: Allow adding/removing await expressions and yield statements (#61356)

* Implements support for adding and removing await/yield return in C# async, iterator and async iterator methods.

* Fix syntax node associated with BoundTryStatement created from using syntax

* Update required members status (#61602)

* Implements support for adding and removing await/yield return in C# in the IDE (#61521)

Co-authored-by: Sam Harwell <Sam.Harwell@microsoft.com>
Co-authored-by: Julien Couvreur <jcouv@users.noreply.github.com>
Co-authored-by: Chris Sienkiewicz <chsienki@microsoft.com>
Co-authored-by: DoctorKrolic <mapmyp03@gmail.com>
Co-authored-by: Gen Lu <genlu@users.noreply.github.com>
Co-authored-by: DoctorKrolic <70431552+DoctorKrolic@users.noreply.github.com>
Co-authored-by: Cyrus Najmabadi <cyrusn@microsoft.com>
Co-authored-by: gel@microsoft.com <gel@microsoft.com>
Co-authored-by: CyrusNajmabadi <cyrus.najmabadi@gmail.com>
Co-authored-by: dotnet bot <dotnet-bot@dotnetfoundation.org>
Co-authored-by: AlFas <AlFasGD@users.noreply.github.com>
Co-authored-by: Ramkumar Ramesh <ramkumar.ramesh.8@live.com>
Co-authored-by: Ramkumar Ramesh <ramram@microsoft.com>
Co-authored-by: AlekseyTs <AlekseyTs@users.noreply.github.com>
Co-authored-by: Allison Chou <allichou@microsoft.com>
Co-authored-by: Tomáš Matoušek <tmat@users.noreply.github.com>
Co-authored-by: David Wengier <david.wengier@microsoft.com>
Co-authored-by: David Barbet <dabarbet@microsoft.com>
Co-authored-by: Fred Silberberg <frsilb@microsoft.com>
Co-authored-by: James Newton-King <james@newtonking.com>
Co-authored-by: Weihan Li <weihanli@outlook.com>
Co-authored-by: Joey Robichaud <joseph.robichaud@microsoft.com>
Co-authored-by: Julien Couvreur <julien.couvreur@gmail.com>
Co-authored-by: Andrew Hall <ryzngard@live.com>
Co-authored-by: Manish Vasani <mavasani@microsoft.com>
Co-authored-by: Jared Parsons <jaredpparsons@gmail.com>
Co-authored-by: Joey Robichaud <jorobich@microsoft.com>
Co-authored-by: Rikki Gibson <rigibson@microsoft.com>
Co-authored-by: akhera99 <ankitakhera@microsoft.com>
Co-authored-by: Ankita Khera <40616383+akhera99@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants