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

Another way to correct generate Uri for new Document when resolve code action #68995

Merged
merged 22 commits into from
Aug 21, 2023

Conversation

Cosifne
Copy link
Member

@Cosifne Cosifne commented Jul 12, 2023

A different path to fix #68550
The reason is we don't provide folders in document in LSP server, so when https://sourceroslyn.io/#Microsoft.CodeAnalysis.Features/CodeRefactorings/MoveType/AbstractMoveTypeService.MoveTypeEditor.cs,148 is called, no folder is given, and we fall back to add the document under the project root.

@Cosifne Cosifne requested a review from a team as a code owner July 12, 2023 01:22
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Jul 12, 2023
@Cosifne
Copy link
Member Author

Cosifne commented Jul 12, 2023

cc @jasonmalinowski

@@ -206,8 +206,11 @@ private DocumentFileInfo MakeDocumentFileInfo(MSB.Framework.ITaskItem documentIt
var isLinked = IsDocumentLinked(documentItem);
var isGenerated = IsDocumentGenerated(documentItem);
var sourceCodeKind = GetSourceCodeKind(filePath);
var relativePath = PathUtilities.GetDirectoryName(
PathUtilities.GetRelativePath(_projectDirectory, filePath));
Copy link
Member

Choose a reason for hiding this comment

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

What is this going to do if the file path is outside the project directory cone?

Copy link
Member Author

Choose a reason for hiding this comment

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

🤔If it is not in the project directory, we might support things like .. so it could be ..\..\projectB\cool\folder.
Or we should just assume the document lives in the project directory and use null/ImmutableArray.Empty in all other cases?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh cool I found PathUtilites.GetRelativePath could give .. as the parent folder, so I guess I just need to add some tests to verify that.

Copy link
Member

Choose a reason for hiding this comment

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

I guess my question isn't "what does the method return" but "do we expect .. entries to appear in the folders list in the first place?"

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 feel it should be allowed in the legacy project, I have added a test for that case.

Copy link
Member Author

Choose a reason for hiding this comment

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

See MSBuildWorkspaceWithDocumentInParentFolders test, its referencing a document in ../MyDir

</Compile>
<Compile Include="CSharpClass.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="..\MyDir\MyClass.cs" />
Copy link
Member Author

@Cosifne Cosifne Jul 25, 2023

Choose a reason for hiding this comment

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

This is the core test scenario in MSBuildWorkspaceWithDocumentInParentFolders

using var workspace = CreateMSBuildWorkspace();
var project = await workspace.OpenProjectAsync(GetSolutionFileName(@"CSharpProject\CSharpProject.csproj"));
var linkedDocument = project.Documents.Single(d => d.Name == "Foo.cs");
Assert.Equal(new[] { "Blah" }, linkedDocument.Folders);
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the linked location in our resources file. See here

@Cosifne Cosifne requested a review from jasonmalinowski July 25, 2023 23:08
@Cosifne
Copy link
Member Author

Cosifne commented Jul 25, 2023

@jasonmalinowski It's ready to be reviewed second time

Copy link
Member

@jasonmalinowski jasonmalinowski left a comment

Choose a reason for hiding this comment

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

Overall looks good. I have a few questions just to double check a few behaviors, but assuming everything is matching up, let's :shipit:.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Move type to" code action using C# Dev Kit incorrectly moves the type to the root folder.
3 participants