Skip to content

Fix unable to open files in problems/peek windows issue #872

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

Merged
merged 11 commits into from
Mar 11, 2019

Conversation

rkeithhill
Copy link
Contributor

@rkeithhill rkeithhill commented Feb 28, 2019

This is due to PSES not properly storing a language client path in the
ClientFilePath property of ScriptFile. This change ensures that a
ClientFilePath is always stored in the text document Uri that a LSP
client expects. This code has mostly been provided by
@SeeminglyScience. Thanks for the reference to your code.
This fixes issue 1732 in the vscode-powershell repo.

BTW I've also verified that there are issues when you use the reference code lens where refs to other files that you haven't loaded, will not load when you click on the file in the peek window.

@rkeithhill
Copy link
Contributor Author

Well, looks like that bombs a lot of tests. I'll take a look at the tests tomorrow and see if this is a case where we can "fix" the tests.

@rkeithhill
Copy link
Contributor Author

rkeithhill commented Mar 3, 2019

OK, the latest update leaves only one (non-test) use of ClientFilePath and that happens starting here:

context?.CurrentFile.InsertText(Encoding.UTF8.GetString(fileContent, 0, fileContent.Length));

which calls (and uses ClientPath):

.InsertTextAsync(this.scriptFile.ClientFilePath, textToInsert, insertRange)

which sends this insert test request to the LSP client:

Not sure if we could have a latent bug here where we pass a path that hasn't been converted to a DocumentUri. So I've left this one alone. I think it is used when you edit a remote file. @TylerLeonhardt ?

@rkeithhill
Copy link
Contributor Author

OK, I think this is ready for review again.

Copy link
Collaborator

@SeeminglyScience SeeminglyScience left a comment

Choose a reason for hiding this comment

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

LGTM! Just a couple suggestions

@TylerLeonhardt
Copy link
Member

This is great @rkeithhill! A couple things...

Can you resolve the merge conflict?

Is it possible to add tests for this change? (I only ask because I think this part of the code is very testable)

This is due to PSES not properly storing a language client path in the
ClientFilePath property of ScriptFile.  This change ensures that a
ClientFilePath is always stored in the text document Uri that a LSP
client expects.  This code has mostly been provided by
@SeeminglyScience. Thanks for the reference to your code.
This fixes issue 1732 in the vscode-powershell repo.
@rkeithhill rkeithhill force-pushed the rkeithhill/fix-vscode-1732-bad-client-path branch from ce692b2 to b4be9ba Compare March 5, 2019 18:52
@rkeithhill
Copy link
Contributor Author

Resovled the merge conflicts and addresses other PR comments. I'll look into tests next.

@rkeithhill
Copy link
Contributor Author

BTW it would be nice if running tests locally was more convenient and more reliable. For instance, when I run the tests from the Visual Studio Test Explorer window, I get 55 failures, yet I get zero failures fom the command line. That is, when the tests don't hang. Often when running from the command line, the tests hang. :-(

@rjmholt
Copy link
Contributor

rjmholt commented Mar 5, 2019

BTW it would be nice if running tests locally was more convenient and more reliable. For instance, when I run the tests from the Visual Studio Test Explorer window, I get 55 failures, yet I get zero failures fom the command line. That is, when the tests don't hang. Often when running from the command line, the tests hang. :-(

Yeah testing is what I want to focus on when I next get the chance. Once we have better testing we can make the changes we so badly need to make without breaking everything else

@rkeithhill
Copy link
Contributor Author

@TylerLeonhardt Good call on adding tests. I think I've found an issue but I need to spin up my Ubuntu VM to verify.

@TylerLeonhardt
Copy link
Member

Let me know if there's anything I can do to help!

@TylerLeonhardt
Copy link
Member

Commit: Try to fix tests for Linux ✔️

Nice! Do you think this is ready for review now?

@rkeithhill
Copy link
Contributor Author

Yes. It is ready for review. Also could you test this on macOS or Linux? In the released version of the extension, open the examples folder. Insert a few lines of script into StopTest.ps1 that will generate PSSA warnings (use iex or unused variable). The save & close the file. Now reload VSCode and open Stop-Process2.ps1. After PS initializes, click on the references on the Stop-Process2 function. While the reference is being displayed in the peek window, you should see a problem appear in the Problems window for the script you added. Double click on the problem to navigate to it. That is when you should see this:

image

Now build VSCode with this PR pulled down in PSES and try the above experiment again and it should work this time.

BTW sometimes I've seen references fail before when you try to navigate to a file. Still trying to find a repro for that one.

@TylerLeonhardt
Copy link
Member

Before:
image

After 😊
image

And when I click on them, they navigate successfully!

Awesome work!

@rkeithhill
Copy link
Contributor Author

Thanks. So you are seeing the extension dev host use the ISE color theme as well. Hmm... I wonder what is up with that.

@rkeithhill
Copy link
Contributor Author

rkeithhill commented Mar 9, 2019

@SeeminglyScience Would you mind taking a peek at this again? I changed some of the logic and would like to get you to review it. The main thing I found is that Linux allows file names like foo:bar:baz.txt. That and foo\bar:baz.txt which VSCode chokes on.

Copy link
Collaborator

@SeeminglyScience SeeminglyScience left a comment

Choose a reason for hiding this comment

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

LGTM! One nit and some possible optimization. The string allocs are nbd though, shouldn't block if they're an issue.

@rkeithhill
Copy link
Contributor Author

To quote Lego Batman - "What the heck!?"

Build started
2
git clone -q --depth=10 https://github.com/PowerShell/PowerShellEditorServices.git C:\projects\powershelleditorservices
3
fatal: unable to access 'https://github.com/PowerShell/PowerShellEditorServices.git/': Could not resolve host: github.com
4
Command exited with code 128

How do you go about kicking a new build without having to push an unnecessary commit?

@rkeithhill
Copy link
Contributor Author

OK, just about ready to merge this. @TylerLeonhardt could you run that test one more time since we changed the Linux/macOS code path a bit (based on @SeeminglyScience feedback)? Thanks.

@rkeithhill
Copy link
Contributor Author

Can someone rekick the build?

Copy link
Member

@TylerLeonhardt TylerLeonhardt left a comment

Choose a reason for hiding this comment

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

LGTM with a not important nit. 😄

@TylerLeonhardt
Copy link
Member

those flaky tests are so frustrating but I haven't had time to fix/mitigate them... I'm thinking about implementing 5x retry logic.

@TylerLeonhardt
Copy link
Member

@SeeminglyScience @rjmholt if you guys wanna give this one more look after my comments... otherwise I think this is good to go in

@TylerLeonhardt
Copy link
Member

p.s. this PR still works on macOS 😄

@SeeminglyScience
Copy link
Collaborator

Perfection

@TylerLeonhardt
Copy link
Member

@rjmholt is OOF, merging this in. I marked it for backport. @rkeithhill we should cherry pick this back and test it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants