XSharpPublic icon indicating copy to clipboard operation
XSharpPublic copied to clipboard

Windows Forms Designer : Crashes when editing a VFPXPorter generated Form - 2nd Sample... Crashes without errors

Open fforay opened this issue 1 year ago • 3 comments

Describe the bug Same as #1595, but with a more complex VFP Application. I'm using X# 2.21

To Reproduce It reproduces with my full app ;)

I've tried to track it in VSIntegration solution and the VS Experimental instance, but as it is using the registered CodeDomProvider...It's hard to check.

Anyway, I was able to get this error log : Exception thrown: 'System.ArgumentOutOfRangeException' in mscorlib.dll Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) at System.Collections.Generic.List1.get_Item(Int32 index) at XSharp.CodeDom.ParseHelpers.GetLeadingTrivia(ParserRuleContext context, IList1 tokens) in C:\XSharp\DevPublic\src\VisualStudio\CodeDomProvider\XSharpTreeDiscoverClass.cs:line 768 at XSharp.CodeDom.XSharpBaseDiscover.writeTrivia(CodeObject o, XSharpParserRuleContext context, Boolean end) in C:\XSharp\DevPublic\src\VisualStudio\CodeDomProvider\XSharpTreeDiscoverBase.cs:line 1920 at XSharp.CodeDom.XSharpBaseDiscover.EnterUsing_(Using_Context context) in C:\XSharp\DevPublic\src\VisualStudio\CodeDomProvider\XSharpTreeDiscoverBase.cs:line 1906 at LanguageService.CodeAnalysis.XSharp.SyntaxParser.XSharpParser.Using_Context.EnterRule(IParseTreeListener listener) at LanguageService.SyntaxTree.Tree.ParseTreeWalker.Walk(IParseTreeListener listener, IParseTree t) at XSharp.CodeDom.XSharpCodeParser.Parse(String source) in C:\XSharp\DevPublic\src\VisualStudio\CodeDomProvider\XSharpCodeParser.cs:line 126

fforay avatar Oct 09 '24 14:10 fforay

I'll look into this asap. Btw: you can simply delete the CodeDomprovider from the GAC to debug it. The version in the GAC is only needed to generate code behind for WPF projects, which is done from a build task.

RobertvanderHulst avatar Oct 09 '24 15:10 RobertvanderHulst

After running the experimental VS instance, I was able to reproduce the error. In XSharpTreeDiscoverBase, line 1920, it calls GetLeadingTrivia(). Then it goes into XSharpTreeDiscoverClass, line 763. There OriginalTokenIndex returns 18, where the length of the tokens if 17, and the max pos is 16...so the crash. There is something wrong in the Context.

I attach a zip with the offending solution.

Open the SLN, try to open the file toolbar_navig.prg in the ClassLibraries project, folder Libs/toolbar. MyDemo.zip

FabForay avatar Oct 13 '24 19:10 FabForay

Fabrice, I'll try to look into this in Munich on Tuesday or Wednesday, so you will have a fix for your session.

RobertvanderHulst avatar Oct 13 '24 20:10 RobertvanderHulst

The problem seems to be that it is looking in the tokens of the imported file VFPXPorter.xh and not the tokens of the form.

RobertvanderHulst avatar Oct 15 '24 10:10 RobertvanderHulst

Ok, found it. The problem is the USING toolbar in the header file. This becomes the first entity in the parsetree. When trying to load the tokens of the tree, we fetch the tokens based on the start token of the parsetree. The first element in the parsetree is this USING toolbar that is from the header file. I will change the logic to exclude entities from header files when determining the first token. That should fix this.

RobertvanderHulst avatar Oct 15 '24 10:10 RobertvanderHulst

Many thanks, it solves my trouble. You always guide and inspire 😁

I can now close both tickets

fforay avatar Oct 17 '24 20:10 fforay

Keep the music alive !

RobertvanderHulst avatar Oct 17 '24 23:10 RobertvanderHulst

Confirmed fixed

cpyrgas avatar Nov 05 '24 00:11 cpyrgas