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

Request textDocument/documentHighlight failed error in vscode when displaying Bicep files from Remote Repositories extension and from a non-default branch #11467

Closed
Aymope opened this issue Aug 8, 2023 · 22 comments · Fixed by #12259
Assignees
Labels
bug Something isn't working devdiv Related to Bicep tooling efforts in DevDiv
Milestone

Comments

@Aymope
Copy link

Aymope commented Aug 8, 2023

edit: see repro steps below: #11467 (comment)

Bicep version
Latest version

VScode: Latest version

I have been getting this error below on vscode, I cant do anything with the bicep code and i dont know why this problem cant go away

[Error - 12:12:13 PM] Request textDocument/documentHighlight failed.
Message: Internal Error
Code: -32603
[Error - 12:12:13 PM] Request textDocument/codeAction failed.
Message: Internal Error
Code: -32603
[Error - 12:12:14 PM] Request textDocument/hover failed.
Message: Internal Error
Code: -32603

@anthony-c-martin
Copy link
Member

Please could you copy+paste the text from the first few lines of the "Bicep" output pane? For me, this looks like:
image

Please also copy+paste the contents of the "about" window (Help -> About). For me, this looks like:
image

@Aymope
Copy link
Author

Aymope commented Aug 9, 2023

2023-08-07T21:45:30.142Z info: Current log level: debug.
2023-08-07T21:45:30.147Z info: Acquiring dotnet runtime...
2023-08-07T21:45:30.156Z debug: Found dotnet command at 'c:\Users\AppData\Roaming\Code\User\globalStorage\ms-dotnettools.vscode-dotnet-runtime.dotnet\7.0.9\dotnet.exe'.
2023-08-07T21:45:30.156Z info: Launching Bicep language service...
2023-08-07T21:45:30.156Z debug: Found language server at 'c:\Users.vscode\extensions\ms-azuretools.vscode-bicep-0.20.4\bicepLanguageServer\Bicep.LangServer.dll'.
2023-08-07T21:45:30.758Z info: Bicep language service started.
[Info - 4:45:30 PM] Running on processId 21276
[Error - 4:45:30 PM] Request textDocument/codeAction failed.

@Aymope
Copy link
Author

Aymope commented Aug 9, 2023

Version: 1.81.0 (user setup)
Commit: 6445d93c81ebe42c4cbd7a60712e0b17d9463e97
Date: 2023-08-02T12:37:13.485Z
Electron: 22.3.18
ElectronBuildId: 22689846
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Windows_NT x64 10.0.19045

@anthony-c-martin
Copy link
Member

anthony-c-martin commented Aug 9, 2023

@Aymope thanks for sharing. Is there any additional logging in the VSCode output window if you enable this VSCode setting?
image

Is there anything otherwise unusual about your Windows install? (security policies, firewall config etc)

@Aymope
Copy link
Author

Aymope commented Aug 9, 2023

I just made the server update to verbose. The error still pops up, maybe its a security policy or firewall config, let me check and update the issue.

@Aymope
Copy link
Author

Aymope commented Aug 15, 2023

So the extension works now but the problem is that the extension works only on the default branch in the repo of the application. Anytime i create a new branch or use a different branch from the default branch the bicep extension doesn't work. Any idea why this problem?

@StephenWeatherford
Copy link
Contributor

@Aymope Sorry you're having troubles with bicep. Having trouble thinking of why a different branch might be an issue. Could you try a few things and let us know how each turns out? Thanks!

  1. Disable all extensions except Bicep and .NET Install Tool for Extension Authors. Easiest way is to run "Disable all installed extensions" in the command palette, then re-enable Bicep. Does the issue still occur?
  2. Create and save an empty .bicep file (try both within your app repo and also outside of it). Restart vscode and open the file. Can you view/edit the file without issues?
  3. Uninstall the Bicep and .NET Install Tool for Extension Authors extensions, and delete their folders on disk:
c:\Users\AppData\Roaming\Code\User\globalStorage\ms-dotnettools.vscode-dotnet-runtime.dotnet
c:\Users.vscode\extensions\ms-azuretools.vscode-bicep-0.20.4

Then restart vscode and reinstall the Bicep extension. Does that fix it?
4) Try installing previous versions of the Bicep extension and see if the issue still occurs
If it still occurs after those, could you provide us with more specifics about your setup with git and your app repo from your last comment?

Thanks!

@majastrz
Copy link
Member

@Aymope are you able to try out the steps that @StephenWeatherford shared?

@Aymope
Copy link
Author

Aymope commented Aug 23, 2023

Yes, I tried those. But the issue was that the pipeline deployment process was set in a way that only the default branch can make code changes direct to ADO,I just got to find that out today. So another issue is when i changed the variables in the code so another branch can be able to make deployments, the variable change couldn't override the set up so another branch can make deployments and then, I wonder what all this has got to do with making the bicep extension fail on the other branches.

@StephenWeatherford
Copy link
Contributor

@Aymope Sorry for the delay. I'm confused about your previous response. I asked you to run some steps on your local machine where I assume the problem is, to try and narrow it down, make sure it's not caused by another extension, and make sure the extension hasn't been corrupted. You've been able to verify all the above? You didn't answer any of the questions. I'm not sure what the rest of your response has to do with this, either. Thx.

Also:

I just made the server update to verbose. The error still pops up, maybe its a security policy or firewall config, let me check and update the issue.

You didn't answer Marcin's question... He was hoping there might be something in the additional output before the error occurred that could give us a clue. Anything there look suspicious? Maybe you can share it if it's not sensitive? Thanks.

Trying to figure out how to narrow this down.

@Aymope
Copy link
Author

Aymope commented Sep 11, 2023

@StephenWeatherford I did run the steps and let me answer properly now.

Disable all extensions except Bicep and .NET Install Tool for Extension Authors. Easiest way is to run "Disable all installed extensions" in the command palette, then re-enable Bicep. Does the issue still occur?

Ans: Yes, the issue still occur

Create and save an empty .bicep file (try both within your app repo and also outside of it). Restart vscode and open the file. Can you view/edit the file without issues?

Ans: Yes the issue still exist in my app repo

I carried out step 3 and 4 and the issue still occurred.

To answer Marcin's question, there isn't any security policy or firewall config that makes this issue occur.

To discuss how the repo is set up, I cloned the repo directly from ADO into VScode, For ease, I am able to access the repo using Azure repo extension.

So to narrow this down, currently, the bicep extension works perfectly for only the default branch for the application and some months before now, all other branches were working. So now I am having this issue even after trying the 4 steps you had me go through.

@alex-frankel
Copy link
Collaborator

@Aymope - we are having trouble reproducing the issue. Would you be up for joining a call with us to watch the error occur live? That will help us do more troubleshooting in real time.

@Aymope
Copy link
Author

Aymope commented Sep 20, 2023

That would be great, how do get the call rolling?

@Aymope
Copy link
Author

Aymope commented Sep 21, 2023

My company uses Webex for calls, can we use this?
I just have to send you an invite to join for a meet

@alex-frankel
Copy link
Collaborator

Sure that's fine - can you send an email to alfran@microsoft.com and we can set it up?

@Aymope
Copy link
Author

Aymope commented Sep 22, 2023

@alex-frankel I sent you an email, did you receive it?
Because of company restrictions that might have not gotten to you, please confirm it did, if now, please skype me 469-444-0117 and we set up a meeting

@alex-frankel
Copy link
Collaborator

Received - we will coordinate offline and update this thread if we have any meaningful updates on the issue.

@StephenWeatherford
Copy link
Contributor

StephenWeatherford commented Oct 3, 2023

REPRO STEPS

  1. start up vscode
  2. install extension "Azure Repos" (https://github.com/microsoft/vscode-remote-repositories-github)
  3. Close current folder
  4. View -> Explorer
image
  1. click Open Remote Repository
  2. enter "https://github.com/StephenWeatherford/template-examples"
  3. In lower-right corner of vscode, click on "Restricted Mode" if you see it, and choose to trust the folder
  4. in explorer, select TEMPLATE EXAMPLES [GITHUB] -> bicep -> main.bicep
image
  1. this should correctly open the file in the editor in remote mode, with language Bicep, with no problems
  2. In lower-right corner of vscode, click on "master"
image
  1. Create New Branch, enter a branch name, Switch to Branch
  2. repeat: in explorer, select TEMPLATE EXAMPLES [GITHUB] -> bicep -> main.bicep
    !)
image

@stephaniezyen stephaniezyen added bug Something isn't working devdiv Related to Bicep tooling efforts in DevDiv and removed Needs: Attention 👋 labels Oct 3, 2023
@stephaniezyen stephaniezyen added this to the v0.23 milestone Oct 3, 2023
@StephenWeatherford
Copy link
Contributor

StephenWeatherford commented Oct 3, 2023

image

BicepTextDocumentSyncHandler.GetTextDocumentAttributes() receives this uri:
"vscode-vfs://github%2B7b2276223a312c22726566223a7b2274797065223a342c226964223a225374657068656e57656174686572666f72642d70617463682d31227d7d/StephenWeatherford/template-examples/bicep/templatespec/client.bicep"

Trying to call DocumentUri.ToUri() or ToEncodedUri() gives this:
System.UriFormatException: "Invalid URI: The hostname could not be parsed."
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions)\n at System.Uri..ctor(String uriString)\n at System.UriBuilder.get_Uri()\n at OmniSharp.Extensions.LanguageServer.Protocol.DocumentUri.ToUri()\n at Bicep.LanguageServer.Handlers.BicepTextDocumentSyncHandler.GetTextDocumentAttributes(DocumentUri uri) in /Users/stephenweatherford/repos/bicep/src/Bicep.LangServer/Handlers/BicepTextDocumentSyncHandler.cs:39

With the default branch, the URI we get looks like this:
vscode-vfs://github/StephenWeatherford/template-examples/bicep/hoverTest/hoverTest.bicep

example language server log:

[Trace - 12:47:22 PM] Sending request 'textDocument/codeAction - (8)'.
Params: {
"textDocument": {
"uri": "vscode-vfs://github%2B7b2276223a312c22726566223a7b2274797065223a342c226964223a2261646673686c6b61646773227d7d/StephenWeatherford/template-examples/bicep/main.bicep"
},
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 0,
"character": 0
}
},
"context": {
"diagnostics": [],
"triggerKind": 2
}
}

[Trace - 12:47:22 PM] Received response 'textDocument/codeAction - (8)' in 2ms. Request failed: Internal Error (-32603).
[Error - 12:47:22 PM] Request textDocument/codeAction failed.
Message: Internal Error
Code: -32603

From debugging inside the extension, it appears that this truly is the URI that is being used by vscode for the document:
vscode-vfs://github%2B7b2276223a312c22726566223a7b2274797065223a342c226964223a225374657068656e57656174686572666f72642d70617463682d31227d7d/StephenWeatherford/template-examples/bicep/templatespec/client.bicep
So the problem is not that OmniSharp is transferring it to us incorrectly.
image

But neither System.Uri, nor OmniSharp.Extensions.LanguageServer.Protocol.DocumentUri will parse this URI. vscode's Uri.parse handles it, but new vscode.Uri doesn't (why?).

Example: System.Uri failing (whether the "+" is encoded or not):
new System.Uri("vscode-vfs://github+7b2276223a312c22726566223a7b2274797065223a342c226964223a225374657068656e57656174686572666f72642d70617463682d31227d7d/StephenWeatherford/template-examples/bicep/templatespec/client.bicep", System.UriKind.Absolute)
'new System.Uri("vscode-vfs://github+7b2276223a312c22726566223a7b2274797065223a342c226964223a225374657068656e57656174686572666f72642d70617463682d31227d7d/StephenWeatherford/template-examples/bicep/templatespec/client.bicep", System.UriKind.Absolute)' threw an exception of type 'System.UriFormatException'

System.Uri.IsWellFormedUriString() returns false.

By contrast, on the default branch the URI has this format:
github://github/StephenWeatherford/template-examples/bicep/main.bicep

@StephenWeatherford
Copy link
Contributor

StephenWeatherford commented Oct 23, 2023

Recommendation: Disable use of Bicep language server in Remote Repositories extension as suggested here.
PR: #12259

Repro steps: #11467 (comment)

Summary:

The vscode Remote Repositories extension produces some weird but technically valid URIs for documents when displaying files in a different branch than the default branch. They're valid URIs but have a unusual (invalid?) hostname and dotnet's System.Uri throws an error if you try to create a Uri with that format (try here and here). Given that URIs are passed to extension via a string (or if using OmniSharp via a DocumentUri), and the first thing they generally do is to create and store a Uri from the string/DocumentUri, that means that the extension immediately fails in the handler. This affects our extension and probably many others.

The dotnet bug relating to this is dotnet/runtime#64707. An opt-in argument to allow such URIs has been suggested as a possible fix here.

Even if the dotnet bug is fixed, I'm not sure if it solves all the problems (see #12041), but in my opinion is a good first step for dotnet.

It appears though that the Remote Repositories isn't the only extension producing such URIs, see gitkraken/vscode-gitlens#2978.

microsoft/vscode#163225 talks about using "." instead of "+" in the domain name as a possible fix from the source of the URIs. Don't know what came of that, though.

The bug I entered against Remote Repositories extension: microsoft/vscode-remote-repositories-github#375

@StephenWeatherford
Copy link
Contributor

StephenWeatherford commented Oct 23, 2023

NOTE: C# also disables virtual workspaces (https://github.com/dotnet/vscode-csharp/blob/e336406b01c0824af748931c8e0ca5434d0363a2/package.json#L34C32-L34C32). But they still seem to get intellisense, I think vscode must have that built in because I see that even if I uninstall the C# extensions.

For Bicep, with this fix, looks exactly like it does for restricted mode:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working devdiv Related to Bicep tooling efforts in DevDiv
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

7 participants