-
Notifications
You must be signed in to change notification settings - Fork 420
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 generate file #1143
Merged
Merged
Fix generate file #1143
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
92afdca
Fix generate type in file
bc6487c
Make code simplesr
3d09d7a
Add semicolon
35eceb2
Merge branch 'master' into fixGenerateFile
29012d7
Fix test cross platform?
7b6ecd8
Merge branch 'fixGenerateFile' of https://github.com/rchande/omnishar…
572d2a2
Add project to build.json
9a99612
Make test assets with errors allowed
7ae76c4
Validate file contents better
9818e23
Merge branch 'master' into fixGenerateFile
DustinCampbell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
test-assets/test-projects/ProjectWithMissingType/HelloWorld.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp1.0</TargetFramework> | ||
<EnableDefaultCompileItems>false</EnableDefaultCompileItems> | ||
<LangVersion>7.1</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="**\*.cs" /> | ||
<EmbeddedResource Include="**\*.resx" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NETCore.App"> | ||
<Version>1.0.1</Version> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
</Project> |
12 changes: 12 additions & 0 deletions
12
test-assets/test-projects/ProjectWithMissingType/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
|
||
namespace ConsoleApplication | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
Z x = null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,7 +139,6 @@ public void Whatever() | |
[|Console.Write(""should be using System;"");|] | ||
} | ||
}"; | ||
|
||
const string expected = | ||
@"public class Class1 | ||
{ | ||
|
@@ -153,11 +152,40 @@ private static void NewMethod() | |
Console.Write(""should be using System;""); | ||
} | ||
}"; | ||
|
||
var response = await RunRefactoringAsync(code, "Extract Method"); | ||
AssertIgnoringIndent(expected, ((ModifiedFileResponse)response.Changes.First()).Buffer); | ||
} | ||
|
||
[Fact] | ||
public async Task Can_generate_type_and_return_name_of_new_file() | ||
{ | ||
using (var testProject = await TestAssets.Instance.GetTestProjectAsync("ProjectWithMissingType")) | ||
using (var host = CreateOmniSharpHost(testProject.Directory)) | ||
{ | ||
var requestHandler = host.GetRequestHandler<RunCodeActionService>(OmniSharpEndpoints.V2.RunCodeAction); | ||
var document = host.Workspace.CurrentSolution.Projects.First().Documents.First(); | ||
var buffer = await document.GetTextAsync(); | ||
var path = document.FilePath; | ||
|
||
var request = new RunCodeActionRequest | ||
{ | ||
Line = 8, | ||
Column = 12, | ||
FileName = path, | ||
Buffer = buffer.ToString(), | ||
Identifier = "Generate class 'Z' in new file", | ||
WantsTextChanges = true, | ||
WantsAllCodeActionOperations = true | ||
}; | ||
|
||
var response = await requestHandler.Handle(request); | ||
var changes = response.Changes.ToArray(); | ||
Assert.Equal(2, changes.Length); | ||
Assert.NotNull(changes[0].FileName); | ||
Assert.NotNull(changes[1].FileName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should you also assert that the file was generated on disk? |
||
} | ||
} | ||
|
||
[Fact] | ||
public async Task Can_send_rename_and_fileOpen_responses_when_codeAction_renames_file() | ||
{ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll probably want to add this to build.json so it gets restored and built before the test runs: https://github.com/OmniSharp/omnisharp-roslyn/blob/master/build.json#L40.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do. Thanks!