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

Fix razor completion #35225

Merged
merged 8 commits into from
May 2, 2019
Merged

Fix razor completion #35225

merged 8 commits into from
May 2, 2019

Conversation

genlu
Copy link
Member

@genlu genlu commented Apr 23, 2019

Fix #35172.

This also include a small change as an attempt to fix the feedback issue below. I still can't repro the crash so not able to verify the fix yet.
https://developercommunity.visualstudio.com/content/problem/514087/problem-in-namespace-refactor.html?childToView=546711#comment-546711

FYI @heejaechang

RazorCompletion

@jinujoseph @vatsalyaagrawal this needs approval.


Customer and scenario info
Who is impacted by this bug?
Razor users who turned on import completion.
What is the customer scenario and impact of the bug?
Use commit a import completion item
Expected
The type name has been committed
Actual
the document will be corrupted
What is the workaround?
User can't use import completion in Razor document, manually add imports first.
How was the bug found?
user feedback
If this fix is for a regression - what had regressed, when was the regression introduced, and why was the regression originally missed?
No. import completion is a new feature added in 16.1

@genlu genlu requested a review from a team as a code owner April 23, 2019 22:28
@genlu genlu added the Area-IDE label Apr 23, 2019
@jinujoseph jinujoseph modified the milestones: 16.1.P3, 16.1 Apr 23, 2019
internal sealed class InteractiveSupportsFeatureService
{
[ExportWorkspaceService(typeof(ITextBufferSupportsFeatureService), WorkspaceKind.Interactive), Shared]
internal class InteractiveTextBufferSupportsFeatureService : ITextBufferSupportsFeatureService
Copy link
Contributor

Choose a reason for hiding this comment

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

you can have 1 type with 2 interfaces with 2 ExportWorkspaceServices?

you can even share instance by exporting ExportWorkspaceServiceFactory with same service instance?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, you can't. Each export is a nested type itself.


return CompletionChange.Create(change);
// Certain types of workspace don't support document change, e.g. DebuggerIntellisense
if (!workspace.CanApplyChange(ApplyChangesKind.ChangeDocument))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can use feature service from debugger workspace to disable it rather than using CanApplyChange just for debugger workspace?

Copy link
Member Author

Choose a reason for hiding this comment

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

Let me try that

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, doesn't work. workspace.Services.GetService<IDocumentSupportsFeatureService>().SupportsRefactorings(document) returns true for DebuggerIntellisenseWorkspace

Copy link
Contributor

Choose a reason for hiding this comment

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

sure, you need to export one for DebuggerIntellisenseWorkspace that return false? IDocumentSupportsFeatureService is per workpsace service which supposed to return different value based on workspace? like we have one for interactive and etc?

}

// During an EnC session, adding import is not supported.
var encService = workspace.Services.GetService<IDebuggingWorkspaceService>()?.EditAndContinueServiceOpt;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should move to FeatureService ?

Copy link
Member Author

Choose a reason for hiding this comment

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

@tmat What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

What should?

Copy link
Member Author

Choose a reason for hiding this comment

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

Should we return "CodeFix and Refactorings not available" in the ITextBufferSupportsFeatureService during EnC?

}

// Certain documents, e.g. Razor document, don't support adding imports
var documentSupportsFeatureService = workspace.Services.GetService<IDocumentSupportsFeatureService>();
Copy link
Contributor

Choose a reason for hiding this comment

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

hmmm.. why not add one specific for type import?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the existing SupportRefactoring already does what I need, so I just used it. Do you prefer adding one specific to adding import? That feels too narrow to me.

[ExportWorkspaceService(typeof(IDocumentSupportsFeatureService), ServiceLayer.Default), Shared]
internal class DefaultDocumentSupportsFeatureService : IDocumentSupportsFeatureService
{
public bool SupportsCodeFixes(Document document)
Copy link
Contributor

Choose a reason for hiding this comment

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

do we actually need one that accept Document for these? I think @dibarbet actually removed one that accept document and explicitly changed to text buffer for these APIs?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't need those for my purpose, they were included just because I wanted to expose the same APIs in Feature layer. @dibarbet Any particular reason that those shouldn't be available for Document?

Copy link
Member

Choose a reason for hiding this comment

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

I don't see any reason for them not to be available - it was changed from document -> text buffer because we had the text buffer first in almost all the cases the interface was being used, so we were often just getting the document for no reason.

internal sealed class VisualStudioSupportsFeatureService
{
[ExportWorkspaceService(typeof(ITextBufferSupportsFeatureService), ServiceLayer.Host), Shared]
private class VisualStudioTextBufferSupportsFeatureService : ITextBufferSupportsFeatureService
Copy link
Contributor

Choose a reason for hiding this comment

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

these feels like could be shared as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure what do you mean. Each type can only ExportWorkspaceService once.

@genlu
Copy link
Member Author

genlu commented Apr 25, 2019

@heejaechang @rynowak this commit contains a change which I believe would fix this customer feedback . Could you please take a look?

Also @rynowak I couldn't figure out a repro for the crash, could you give me some help here? How can I generate a .g.cs Razor file that reference a type from source code?

@rynowak
Copy link
Member

rynowak commented Apr 25, 2019

Also @rynowak I couldn't figure out a repro for the crash, could you give me some help here? How can I generate a .g.cs Razor file that reference a type from source code?

The issue from the customer feedback is a case that needs to have a friendlier error message.

You can repro this by creating an ASP.NET Core application, and then doing a refactoring that tries to change code inside a .cshtml file.

@genlu
Copy link
Member Author

genlu commented Apr 25, 2019

@rynowak Hmm, still couldn't repro the crash. The refactoring attempts to change the namespace, which affects all the references to enclosed types. While there's some issue with cshtml, it doesn't crash. How can I have a .g.cs file that references the type Foo in the gif below?

RazorSyncNamespace

@rynowak
Copy link
Member

rynowak commented Apr 26, 2019

Try the same thing with Error.cshtml closed 😄

@genlu
Copy link
Member Author

genlu commented Apr 29, 2019

@rynowak With Error.cshtml closed, find all reference on type Foo finds no reference. So still no repro.

@dpoeschl dpoeschl changed the base branch from dev16.1 to release/dev16.1 May 1, 2019 20:04
@genlu
Copy link
Member Author

genlu commented May 1, 2019

@heejaechang Could you please take a look at this again?

@genlu
Copy link
Member Author

genlu commented May 2, 2019

Discussed with @heejaechang offline, I will merge this as is, and address his comment for 16.2

@jinujoseph
Copy link
Contributor

@ManishJayaswal for approval

@genlu genlu merged commit ee7c923 into dotnet:release/dev16.1 May 2, 2019
@genlu genlu deleted the FixRazorCompletion branch May 2, 2019 21:58
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.

8 participants