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

Handle Rename and OpenDocument responses from Omnisharp #1854

Merged
merged 11 commits into from
Jan 24, 2018

Conversation

rchande
Copy link

@rchande rchande commented Nov 10, 2017

Also adds an integration test that validates the behavior of the "rename
file to match type" refactoring:

  • File is renamed on disk
  • Old buffer is closed
  • New buffer is opened

Also adds an integration test that validates the behavior of the "rename
file to match type" refactoring:
* File is renamed on disk
* Old buffer is closed
* New buffer is opened
@rchande
Copy link
Author

rchande commented Nov 10, 2017

Omnisharp side: OmniSharp/omnisharp-roslyn#1023

@rchande
Copy link
Author

rchande commented Nov 10, 2017

cc @akshita31

Copy link
Member

@DustinCampbell DustinCampbell left a comment

Choose a reason for hiding this comment

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

Looks good, though I'm betting you'll have further updates to react to changes on the omnisharp-roslyn side.

edit.set(uri, edits);
if (change.ModificationType == FileModificationType.Modified)
{
let uri = vscode.Uri.file(change.FileName);
Copy link
Member

Choose a reason for hiding this comment

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

Based on your comment when FileModificationType.Renamed is true, should we check to see if this file is included in renamedFiles? And if so, does that change the order in which we loop through the changes?

Copy link
Author

Choose a reason for hiding this comment

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

Right. We should probably collect all the renames first, so we don't try to edit files that got renamed.

// Unfortunately, the textEditor.Close() API has been deprecated
// and replaced with a command that can only close the active editor.
// If files were renamed that weren't the active editor, their tabs will
// be left open and marked as "deleted" by VS Code
Copy link
Member

Choose a reason for hiding this comment

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

Do we have a bug on VS Code about this?

Copy link
Author

Choose a reason for hiding this comment

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

@@ -0,0 +1,12 @@
import { should } from 'chai';
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 file? Did it get added accidentally?

@DustinCampbell
Copy link
Member

OK. CI should properly fail for this now, since this PR requires a changes in omnisharp-roslyn

await csharpExtension.activate();
}

testAssetWorkspace.deleteBuildArtifacts();

Choose a reason for hiding this comment

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

do you need to delete build artifacts?

Copy link
Author

Choose a reason for hiding this comment

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

Copypasta, will remove.


testAssetWorkspace.deleteBuildArtifacts();

await fs.rimraf(testAssetWorkspace.vsCodeDirectoryPath);

Choose a reason for hiding this comment

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

do you need to delete the .vscode directory?

Copy link
Author

Choose a reason for hiding this comment

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

Copypasta, will remove.

@rchande
Copy link
Author

rchande commented Nov 15, 2017

@DustinCampbell Do these tests automatically consume the latest bits from omnisharp?

});

test("Code actions can remame and open files", async () => {
let fileUri = await testAssetWorkspace.projects[0].addFileWithContents("test.cs", "class C {}");

Choose a reason for hiding this comment

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

running this test more than once will give us false positives. The first execution will put C.cs in the workspace, the second will simply find it.

My first thought was to add a line that deletes both test.cs and C.cs... but this feels like we will have lots of this sort of cleanup code running around. What if we added a method on e.g. testAssetWorkspace that performed a git clean -xfd? This would allow tests to easily put the asset back into a known state [we could eliminate the custom methods for deleting bin/obj, as well as for .vscode]. Thoughts?

Copy link
Author

Choose a reason for hiding this comment

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

I somewhat dislike having the projects manipulated by tests under the repo because they show up in my git status, so it would be nice if we could do something to get them out of there.

Relatedly, Omnisharp-roslyn has a pretty nice system where you can request a real on-disk project from a test helper, and one is created for you under a random folder under %temp%. If we implemented that, we wouldn't have to worry about cleaning up test projects after we're done testing because a test would never see the same instance of a project.

O#r's build knows about the test projects so it can build/restore them as part of the solution build. That means deploying a project for test simply copies all the files into a temp directory.

I think that might be a good solution for these tests. 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.

Agreed 100%. This is why the tests in omnisharp-roslyn that operate on test projects go to an effort to copy test projects to a temporary folder and delete them when the test is finished.

Choose a reason for hiding this comment

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

CLI does the same, @DustinCampbell. However, in this scenario we have a non-trivial startup cost for opening a new folder in VS Code. We also don't have a known model for plugging in an outer loop test orchestrator. Such a thing would need to enumerate all the tests, understand which test asset is needed by which test, make a copy of the asset & launch VS Code in that copy's folder, and then get vscode to execute just that test. I agree that this would be cool to have [if we can make it fast] but it feels like a considerable amount of work...

@TheRealPiotrP
Copy link

@rchande the Code version gets pinned in a few places:
https://github.com/OmniSharp/omnisharp-vscode/search?utf8=%E2%9C%93&q=1.17.2&type=

We pinned it because 1.18 broke our integration tests. In general, I'd prefer we stick to this model so that we can deal with updates to VSCode separately from other feature work. @DustinCampbell got blocked on a feature recently, for example, because 1.18 happened to ship while he was working on his PR.

let fileUri = await testAssetWorkspace.projects[0].addFileWithContents("test.cs", "class C {}");
await vscode.commands.executeCommand("vscode.open", fileUri);
let c = await vscode.commands.executeCommand("vscode.executeCodeActionProvider", fileUri, new vscode.Range(0, 7, 0, 7)) as {command: string, arguments: string[]}[];
expect(c.length).to.equal(3);

Choose a reason for hiding this comment

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

3 seems like a magic number. Can we provide some text [expect should take a second parameter that is used to create the failure output string] that tells us why 3 is the right answer?

let c = await vscode.commands.executeCommand("vscode.executeCodeActionProvider", fileUri, new vscode.Range(0, 7, 0, 7)) as {command: string, arguments: string[]}[];
expect(c.length).to.equal(3);
await vscode.commands.executeCommand(c[1].command, ...c[1].arguments)
expect(vscode.window.activeTextEditor.document.fileName).contains("C.cs");

Choose a reason for hiding this comment

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

here as well... this might not be obvious... "Because the active file was renamed and its new name should be reflected" or something?

@TheRealPiotrP
Copy link

I suspect tests are failing because 3 is the right magic context but not in the other [sln vs. csproj]. Do we need to run this test in both contexts? Perhaps we should just limit it to the csproj context?

@DustinCampbell
Copy link
Member

DustinCampbell commented Nov 16, 2017

@rchande:

@DustinCampbell Do these tests automatically consume the latest bits from omnisharp?

Only once C# for VS Code is updated with new bits from OmniSharp. A release from omnisharp-roslyn has not yet been built with your changes. Once that happens, C# for VS Code will need to be updated with them (after using the tool you were building for uploading them to the CDNs).

@rchande
Copy link
Author

rchande commented Nov 16, 2017

@TheRealPiotrP I think tests are failing because as, @DustinCampbell mentioned, we haven't consumed the new omnisharp bits that would provide the behavior being tested. That said, I will incorporate the changes to the test that you suggested.

@DustinCampbell
Copy link
Member

FWIW, I did state that very fact above:

OK. CI should properly fail for this now, since this PR requires a changes in omnisharp-roslyn

@david-driscoll
Copy link
Contributor

We could deploy the latest omnisharp bits to a cdn / azure storage / myget / and have it act as a beta feed.

@ghost ghost removed the cla-already-signed label Dec 7, 2017
@rchande rchande merged commit 3633e82 into dotnet:master Jan 24, 2018
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.

5 participants