Skip to content

use latest language version for Miscellaneous Files workspace#25802

Merged
JieCarolHu merged 4 commits intodotnet:dev15.7.xfrom
JieCarolHu:vs575761
Apr 5, 2018
Merged

use latest language version for Miscellaneous Files workspace#25802
JieCarolHu merged 4 commits intodotnet:dev15.7.xfrom
JieCarolHu:vs575761

Conversation

@JieCarolHu
Copy link
Copy Markdown
Contributor

@JieCarolHu JieCarolHu commented Mar 29, 2018

use latest language version for Miscellaneous Files workspace

Customer scenario

Diff window uses the default language version instead of the project language version. So when a code file contains a new feature which does not exist in the default language version, the diff window shows error which is confusing to customers.

Bugs this fixes

https://devdiv.visualstudio.com/DevDiv/_workitems/edit/575761

Workarounds, if any

No

Risk

Low, only uses the latest language version instead of the default language version for ParserOptions when opening a historical version of code file

Performance impact

Low, no extra allocations/no complexity changes

Is this a regression from a previous update?

Not sure

Root cause analysis

NA

How was the bug found?

Customer reported on vs feedback

Test documentation updated?

No

@JieCarolHu JieCarolHu requested a review from a team as a code owner March 29, 2018 01:43
@sharwell
Copy link
Copy Markdown
Contributor

sharwell commented Mar 29, 2018

... no extra allocations ...

This is not correct. A previously non-allocating path is now always-allocating here:

https://github.com/dotnet/roslyn/blob/abb91c56bf7a133241062aedb7460fe303f0460b/src/Workspaces/CSharp/Portable/LanguageServices/CSharpSyntaxTreeFactoryService.cs#L31

Copy link
Copy Markdown
Contributor

@sharwell sharwell Mar 29, 2018

Choose a reason for hiding this comment

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

❗️ I would prefer to not change the behavior of GetDefaultParseOptions() (see comment in MiscellaneousFilesWorkspace)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

❗️ I would prefer to add the following method to ParseOptions:

internal abstract ParseOptions WithLatestLanguageVersion();

You could then use the following:

var parseOptionsOpt = languageServices.GetService<ISyntaxTreeFactoryService>()?.GetDefaultParseOptions()
    .WithLatestLanguageVersion();

@JieCarolHu JieCarolHu requested a review from a team as a code owner March 29, 2018 21:44
Copy link
Copy Markdown
Member

@jcouv jcouv Mar 29, 2018

Choose a reason for hiding this comment

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

Tagging @jaredpar @gafter for public API change.

It feels like this new public API is unnecessary.
The consumer can do the job with existing language-specific APIs, so an abstract (language-agnostic) API could be added in IDE layer if you need.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is wrong (losing other information inside the parse options you start with). See WithFeatures above for contrast.
Assuming we end adding such a compiler API, it needs corresponding API-level compiler tests.

Copy link
Copy Markdown
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

Done with review pass (iteration 4).
Let's do this without compiler change.

@jcouv jcouv added this to the 15.7 milestone Mar 29, 2018
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@dotnet/roslyn-compiler I intended for this to be internal. Please let us know how to define such a method for use in the VS layer without a new public API.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not implement this API in one of the language services? (ISyntaxTreeFactoryService seems reasonable place)

If that doesn't work for some reason, you can try making this internal, but I'm not sure there is InternalsVisibleTo from the compiler to this part of the IDE code.
If there is no IVT, there is probably a reason why it's not there, and so I would suspect it shouldn't be added.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Originally, we couldn't even have IVT between compiler and IDE for legal reasons. Today, we simply don't want it because the compiler API should be sufficient for consumer's needs.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If there is concern about a new API why not just make it an extension method? That doesn't need any change in the compiler.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added to the ISyntaxTreeFactoryService.
I am not sure how to add the override extension method for ParseOptions, VisualBasicParseOptions and CSharpParseOptions, so ISyntaxTreeFactoryService looks like a good place

@jcouv
Copy link
Copy Markdown
Member

jcouv commented Apr 4, 2018

There is no longer any compiler change in this PR, so I removed the Compiler label. This can be reviewed by IDE team. Thanks

[ExportLanguageServiceFactory(typeof(ISyntaxTreeFactoryService), LanguageNames.CSharp), Shared]
internal partial class CSharpSyntaxTreeFactoryServiceFactory : ILanguageServiceFactory
{
private static CSharpParseOptions _parseOptionWithLatestLanguageVersion = CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Latest);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

readonly

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

var compilationOptionsOpt = languageServices.GetService<ICompilationFactoryService>()?.GetDefaultCompilationOptions();
var parseOptionsOpt = languageServices.GetService<ISyntaxTreeFactoryService>()?.GetDefaultParseOptions();

// We only have one code file without project file here, so we cannot find out language version of the project
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment seems out of place since that's the fact of life for this entire type. 😄

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated the comment

@jasonmalinowski
Copy link
Copy Markdown
Member

@JieCarolHu Have we tested TypeScript and F# with this? I'm assuming they don't have an implementation of the ISyntaxTreeFactoryService (I don't know how they could...) but if they do this is a breaking change.


Private Shared ReadOnly _parseOptionsWithLatestLanguageVersion As VisualBasicParseOptions = VisualBasicParseOptions.Default.WithLanguageVersion(LanguageVersion.Latest)


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: double blank line

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed

@JieCarolHu
Copy link
Copy Markdown
Contributor Author

@jasonmalinowski tested on typescript and F#, none of them creates project for miscellaneous files. So they are not affected by this change

@jasonmalinowski
Copy link
Copy Markdown
Member

@JieCarolHu Do they have implementations of this interface, even if they don't use Miscellaneous Files? Adding new members to interfaces is breaking unless we are careful.

@JieCarolHu
Copy link
Copy Markdown
Contributor Author

@jasonmalinowski Actually I was searching for the wrong interface. Just searched for "ISyntaxTreeFactoryService" again and they did not implement this interface

@JieCarolHu
Copy link
Copy Markdown
Contributor Author

@jaredpar @sharwell Could you guys please finish review? Thanks

@jaredpar
Copy link
Copy Markdown
Member

jaredpar commented Apr 4, 2018

@JieCarolHu sorry didn't realize you were waiting for my sign off since you removed the compiler change. The changes looked good to me.

@jinujoseph
Copy link
Copy Markdown
Contributor

@Pilchie for ask mode approval

@JieCarolHu
Copy link
Copy Markdown
Contributor Author

@Pilchie for ask mode approval, thanks!

@Pilchie
Copy link
Copy Markdown
Member

Pilchie commented Apr 5, 2018

Approved for 15.7 Preview 4.

@JieCarolHu JieCarolHu merged commit 902e902 into dotnet:dev15.7.x Apr 5, 2018
@JieCarolHu JieCarolHu deleted the vs575761 branch April 5, 2018 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants