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

Override code generation not working #4600

Closed
SubtleMetaphor opened this issue Jun 6, 2021 · 9 comments · Fixed by OmniSharp/omnisharp-roslyn#2319
Closed

Override code generation not working #4600

SubtleMetaphor opened this issue Jun 6, 2021 · 9 comments · Fixed by OmniSharp/omnisharp-roslyn#2319

Comments

@SubtleMetaphor
Copy link

Issue Type: Bug

If there is a trailing white space ANYWHERE in a class, the override code generation will not work.

https://gyazo.com/be89e3cb0b6ffe9a86697ba1f5d0406e

Extension version: 1.23.12
VS Code version: Code 1.56.2 (054a9295330880ed74ceaedda236253b4f39a335, 2021-05-12T17:13:13.157Z)
OS version: Windows_NT x64 10.0.19042

@333fred
Copy link
Member

333fred commented Jul 11, 2021

I'm unable to reproduce this issue:
Demo

Can you give a more precise set of instructions? Do you have other extensions installed that could be interfering with the completion list?

@SubtleMetaphor
Copy link
Author

I'm unable to reproduce this issue:
Demo

Can you give a more precise set of instructions? Do you have other extensions installed that could be interfering with the completion list?

Maybe it's a spaces vs tab issue? (I was using tabs.)

@333fred
Copy link
Member

333fred commented Aug 21, 2021

Maybe it's a spaces vs tab issue? (I was using tabs.)

I could try, but a precise set of instructions for reproducing the issue and your omnisharp logs are likely going to be the only way to make progress here.

@DArkHekRoMaNT
Copy link

Same problem. Override sometimes stops working. Moreover, it can work now, stop working in two minutes, and start working again in three minutes, some kind of madness. Previously, everything worked fine, but lately I see this more and more often.

@DArkHekRoMaNT
Copy link

Your conversation about spaces and tabs helped me find the reason. Override unexpectedly requires proper indentation o.O

I often do three enter and up arrow for a new method. As a result, the up arrow takes me not to the class level, unlike enter, but to the beginning of the line, I immediately write override (since I see no reason to add indentation, which will be fixed anyway) and it does not work.

@333fred
Copy link
Member

333fred commented Dec 20, 2021

@DArkHekRoMaNT I'm still looking for a way to reproduce this. If you have info, please let me know.

@SirIntruder
Copy link

I've noticed this mysterious behaviour too - after some trial and error I realised it's not triggered by just any trailing whitespace anywhere, but for some reason it really hates trailing tab on class-scope opening brace. Tried this in omnisharp-roslyn repo

2021-12-26_18-27-15
2021-12-26_18-27-02

it goes together with these logs:

[warn]: OmniSharp.Roslyn.CSharp.Services.Navigation.FindUsagesService
        No symbol found. File: c:\Git\omnisharp\omnisharp-roslyn\src\OmniSharp.Cake\CakeContextModel.cs, Line: 4, Column: 15.
Received response for /v2/getcodeactions but could not find request.

@ddavisso4
Copy link

Seems to work for me as long as I start typing public override at the very end of the class or the very beginning. Anywhere in between gives the error below. It also seems to dislike improper indentation (e.g. if I start at the very beginning of a line it doesn't work even at the beginning or end of the class).

  "Request_seq": 390,
  "Command": "/completion",
  "Running": true,
  "Success": false,
  "Message": "\"System.ArgumentOutOfRangeException: Length cannot be less than zero.\\nParameter name: length\\n  at System.String.Substring (System.Int32 startIndex, System.Int32 length) [0x00031] in <9f0df102fe6e4cfea29d2e46f585d8a5>:0 \\n  at OmniSharp.Roslyn.CSharp.Services.Completion.CompletionListBuilder.<GetCompletionInfo>g__getPossiblySnippetizedInsertText|16_0 (Microsoft.CodeAnalysis.Text.TextChange change, System.Nullable`1[T] adjustedNewPosition) [0x00060] in <dbd4c42c78874a71919856b53db6870e>:0 \\n  at OmniSharp.Roslyn.CSharp.Services.Completion.CompletionListBuilder.GetCompletionInfo (Microsoft.CodeAnalysis.Text.SourceText sourceText, System.Int32 position, Microsoft.CodeAnalysis.Completion.CompletionItem completion, Microsoft.CodeAnalysis.Completion.CompletionChange change, Microsoft.CodeAnalysis.Text.TextSpan typedSpan, System.String labelText, System.Boolean expectingImportedItems, System.String& insertText, System.String& filterText, System.String& sortText, OmniSharp.Models.v1.Completion.InsertTextFormat& insertTextFormat, Microsoft.CodeAnalysis.Text.TextSpan& changeSpan, System.Collections.Generic.List`1[OmniSharp.Models.LinePositionSpanTextChange]& additionalTextEdits) [0x000d6] in <dbd4c42c78874a71919856b53db6870e>:0 \\n  at OmniSharp.Roslyn.CSharp.Services.Completion.CompletionListBuilder.BuildCompletionItemsSync (Microsoft.CodeAnalysis.Document document, Microsoft.CodeAnalysis.Text.SourceText sourceText, System.Int64 cacheId, System.Int32 position, Microsoft.CodeAnalysis.Completion.CompletionService completionService, Microsoft.CodeAnalysis.Completion.CompletionList completions, Microsoft.CodeAnalysis.Text.TextSpan typedSpan, System.Boolean expectingImportedItems, System.Boolean isSuggestionMode) [0x0021b] in <dbd4c42c78874a71919856b53db6870e>:0 \\n  at OmniSharp.Roslyn.CSharp.Services.Completion.CompletionListBuilder.BuildCompletionItems (Microsoft.CodeAnalysis.Document document, Microsoft.CodeAnalysis.Text.SourceText sourceText, System.Int64 cacheId, System.Int32 position, Microsoft.CodeAnalysis.Completion.CompletionService completionService, Microsoft.CodeAnalysis.Completion.CompletionList completions, Microsoft.CodeAnalysis.Text.TextSpan typedSpan, System.Boolean expectingImportedItems, System.Boolean isSuggestionMode, System.Boolean enableAsyncCompletion) [0x00138] in <dbd4c42c78874a71919856b53db6870e>:0 \\n  at OmniSharp.Roslyn.CSharp.Services.Completion.CompletionService.Handle (OmniSharp.Models.v1.Completion.CompletionRequest request) [0x005bb] in <dbd4c42c78874a71919856b53db6870e>:0 \\n  at OmniSharp.Endpoint.EndpointHandler`2[TRequest,TResponse].GetFirstNotEmptyResponseFromHandlers (OmniSharp.Endpoint.Exports.ExportHandler`2[TRequest,TResponse][] handlers, TRequest request) [0x00099] in <7c5a61c964114ca68a62c9da132f5af2>:0 \\n  at OmniSharp.Endpoint.EndpointHandler`2[TRequest,TResponse].HandleRequestForLanguage (System.String language, TRequest request, OmniSharp.Protocol.RequestPacket packet) [0x00163] in <7c5a61c964114ca68a62c9da132f5af2>:0 \\n  at OmniSharp.Endpoint.EndpointHandler`2[TRequest,TResponse].Process (OmniSharp.Protocol.RequestPacket packet, OmniSharp.Endpoint.LanguageModel model, Newtonsoft.Json.Linq.JToken requestObject) [0x0024b] in <7c5a61c964114ca68a62c9da132f5af2>:0 \\n  at OmniSharp.Stdio.Host.HandleRequest (System.String json, Microsoft.Extensions.Logging.ILogger logger) [0x000f3] in <a50105da3f9c45b299f1e289aba046fa>:0 \"",
  "Body": null,
  "Seq": 1047,
  "Type": "response"
}

333fred added a commit to 333fred/omnisharp-roslyn that referenced this issue Dec 31, 2021
LSP filters expect that the range of the main text edit is going to start on the same line as the cursor. However, when trailing whitespace preceeds the override marker, Roslyn will return a single text edit for the whole range that trims that whitespace. This confuses the vscode intellisense engine, which then unhelpfully displays no completions with no user feedback that this filtering is happening. To avoid this, we now detect when this case occurs, and split up the change into non-overlapping edits from before the current line. Fixes dotnet/vscode-csharp#4600.
@333fred
Copy link
Member

333fred commented Dec 31, 2021

Thanks for the help @SirIntruder, I was able to reproduce from your pictures, and have a bug fix in OmniSharp/omnisharp-roslyn#2319. @ddavisso4, I don't think this addresses the issue you mentioned: I didn't see anything about an ArgumentOutOfRange exception in the repro for this bug. If you encounter that again, please file a separate issue with a set of instructions on how to reproduce 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 a pull request may close this issue.

5 participants