jacobslusser / ScintillaNET

A Windows Forms control, wrapper, and bindings for the Scintilla text editor.
MIT License
964 stars 242 forks source link

Any chance to add .NET 5.0 support? #502

Closed huanlin closed 2 years ago

huanlin commented 3 years ago

I'm trying to add .NET 5.0 support in my fork and I wonder if any chance to add .NET 5.0 support "officially"? Currently I've done the following changes in my fork:

I'm still testing and solving issues, so it's not ready for anyone to use.

p.s. I'm also working on .NET 5.0 support for ScintillaNET.FindReplaceDialog.

VPKSoft commented 3 years ago

Hi, I'm not sure if you have noticed that there already are few forks of this project which are targeting a specific .NET version. The one I made is already targeting NET Core 3.1 and .NET Framework 4.0:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <ProjectGuid>{22AE2386-60F1-476E-9303-61CDB0AAC4CF}</ProjectGuid>
    <TargetFrameworks>netcoreapp3.1;net40</TargetFrameworks>

The change to add .NET 5.0 is not very complicated:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <ProjectGuid>{22AE2386-60F1-476E-9303-61CDB0AAC4CF}</ProjectGuid>
    <TargetFrameworks>netcoreapp3.1;net5.0-windows;net40</TargetFrameworks>
    <UseWindowsForms>true</UseWindowsForms>

I'm just hoping there aren't going to be a "million" different versions to choose from, not suggesting anything else...

huanlin commented 3 years ago

@VPKSoft , you're right, there so so many forks. Apparently I didn't do enough home work to find those forks. 🙂 During upgrade my .NET projects to .NET 5, I see ScintillaNET and I'm curious how much work to make it support .NET 5. So I just thought: why not? just try it.

Thank you for providing the code and letting me know it is pretty easy. What I did in my fork is creating a brand new .NET 5 .csproj, and add all files to it, so I can see if the new csproj file is more tidy.

Since adding .NET 5 support is as easy as you mentioned, hopefully it can be added officially soon, and I'll just keep my fork as experimental and might drop it eventually. Thanks!

p.s. After upgrade to .NET 5, I encounter runtime exception (as below) in ScintillaNET constructor, it must be my fault, I'm still debugging it.

Exception: "Index was outside the bounds of the array."

at System.Array.InternalGetReference(Void* elemRef, Int32 rank, Int32* pIndices)
at System.Array.GetValue(Int32 index)
at ScintillaNET.Scintilla.GetModulePath()   
at ScintillaNET.Scintilla.get_CreateParams()
ghost commented 3 years ago

I was about to open this thread because Yesterday I spent a couple of hours trying to use this component in a .Net5 WPF application using the nuget original library and then, when I found the New Version I tried also that, Unfortunately at the moment the Support for Windows Forms Hosted in .NET 5 is not there, so I'm Stuck I wanted to know if the Use of Windows forms instead of WPF was somehow a forced choice or just a preference choice, because if there is no problem in using WPF I can experiment with your code and see if I can create a WPF Wrapper, if I succeed in doing so I can share the code creating a fork or another project connected to this if you like. But if the use of Windows Forms is a Must I will just cry all my tears but avoid spending time and wait for the Windows Forms Hosting support in .net 5. By the way thanks this is really a great project. Sabrina

VPKSoft commented 3 years ago

It would be a good idea if we try to combine our effort to keep this project alive. I don't even care, who manages the "main" fork. I'm fine with contributing via PR's.

huanlin commented 3 years ago

@VPKSoft, Yes agreed. It would be great to combine efforts via PRs. I might create one when I see fit (at least pass some tests). @SabrinaCs, I only use Windows Forms and I don't know WPF. Hopefully I could learn something from your work in the future.

VPKSoft commented 3 years ago

I added NET 5 support to this fork and released a NuGet if it helps with the WPF Wrapper.

ghost commented 3 years ago

Thanks for the swift answer, The number of versions of this that I found on Nuget is confusing also for myself, so if we can combine the efforts and say which is the right version for each framework in the description appearing in Nuget it would be great. As for the WPF I use it for all desktop project of my company so I know it well. If there are some Notes on how you approached the Wrap of the component in windows forms besides the code it would be great just to shorten the time to learn what you did, I will start working on it in my spare time and let you know how it goes. Thanks again

ghost commented 3 years ago

I have one more Dumb question, sorry but what means contributing via PR's sadly some of the Acronyms used around are not immediate for a non native english speaker such as me.

Stumpii commented 3 years ago

PR is a pull request. If you fork the code and make a change, you can request the change be brought into the original code with a pull request.

svdHero commented 3 years ago

@VPKSoft Thanks for your with targeting .NET 5.0. I am so grateful for your fork. May I ask if there is any update on the PR?

svdHero commented 3 years ago

@VPKSoft I might have found a bug in your fork, though.

When I add this code to a simple .NET 4.0 Framework app using ScintillaNET, everything works fine and I get syntax highlighting of my JSON code in the Scintilla textbox component:

namespace ScintillaTest
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void InitScintilla()
        {
            ScintillaTextBox.WrapMode = WrapMode.None;
            ScintillaTextBox.IndentationGuides = IndentView.LookBoth;

            ScintillaTextBox.StyleResetDefault();
            ScintillaTextBox.Styles[Style.Default].Font = "Consolas";
            ScintillaTextBox.Styles[Style.Default].Size = 12;
            ScintillaTextBox.Styles[Style.Default].BackColor = Color.WhiteSmoke;
            ScintillaTextBox.Styles[Style.Default].ForeColor = Color.Black;
            ScintillaTextBox.StyleClearAll();

            ScintillaTextBox.Styles[Style.Json.Default].ForeColor = Color.Black;
            ScintillaTextBox.Styles[Style.Json.BlockComment].ForeColor = Color.DarkOliveGreen;
            ScintillaTextBox.Styles[Style.Json.LineComment].ForeColor = Color.DarkOliveGreen;
            ScintillaTextBox.Styles[Style.Json.Number].ForeColor = Color.CornflowerBlue;
            ScintillaTextBox.Styles[Style.Json.PropertyName].ForeColor = Color.MediumPurple;
            ScintillaTextBox.Styles[Style.Json.String].ForeColor = Color.DarkSalmon;
            ScintillaTextBox.Styles[Style.Json.StringEol].BackColor = Color.DarkSalmon;
            ScintillaTextBox.Styles[Style.Json.Operator].ForeColor = Color.Purple;
            ScintillaTextBox.Lexer = Lexer.Json;
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            InitScintilla();
        }
    }
}

However, if I write the exact same code in a .NET 5.0 Core app using your fork, there is no syntax highlighting in the Scintilla textbox component.

What's wrong here? Am I missing something?

VPKSoft commented 3 years ago

I'll look into this the next weekend. If you mean the PR for the fork I made to this original it has existed a long time (#486).

svdHero commented 3 years ago

Thank you for looking into the highlighting problem.

And it's a shame that your PR has not been merged, yet. I hope it will make it throught eventually.

VPKSoft commented 3 years ago

Hi, I seem to be getting nothing with both .NET Framework 4.7 and NET 5: image There is something wrong with the Json lexer though as the enum values seem to be wrong: This data comes from Notepad++ XML style definition file: image The numbers in red rectangles are the indices of the Json styles, in the code the Json number style for example seems to be different from the view point of Notepad++ which also uses Scintilla: image 4 != 1, the other indices are wrong as well. I'll check with some other lexer and see if there is a bug... probably this weekend as well.

VPKSoft commented 3 years ago

I found a bug here: image So the lexer property assignment seems to fail in the Lexer property without an exception:

  /// <summary>
  /// Gets or sets the current lexer.
  /// </summary>
  /// <returns>One of the <see cref="Lexer" /> enumeration values. The default is <see cref="ScintillaNET.Lexer.Container" />.</returns>
  [DefaultValue(Lexer.Container)]
  [Category("Lexing")]
  [Description("The current lexer.")]
  public Lexer Lexer
  {
      get
      {
          return (Lexer)DirectMessage(NativeMethods.SCI_GETLEXER);
      }
      set
      {
          var lexer = (int)value;
          DirectMessage(NativeMethods.SCI_SETLEXER, new IntPtr(lexer));
      }
  }
VPKSoft commented 3 years ago

All right, I need to build the SciLexer.dll with statically linked lexer definitions - anyone who can help me with this? The DLL compiles fine without this definition, which is required for the lexers to be included in the DLL: image

svdHero commented 3 years ago

Thank you so much for your help. Unfortunately I have no experience with this project whatsoever. I just need to integrate a JSON code editor component into a .NET Core app.

I hope someone more experienced than me is willing to assist you.

VPKSoft commented 3 years ago

Issue resolved with version 3.8.4. Thanks for reporting this 👍

svdHero commented 3 years ago

Thank you so much for the fix. I will test it on Monday first thing in the morning.

svdHero commented 3 years ago

Quick update: I have been busy with other stuff but will return to my Scintilla project next week. I'll let you know if everything works fine.

svdHero commented 3 years ago

@VPKSoft Thank you so much once again. With .NET 5, everything works perfectly now.

huanlin commented 2 years ago

Hey guys, FYI, I don't know if you guys has found the version you like. I come back to this issue because I've upgraded my fork to .NET 6, and then I found fernandreu/ScintillaNET has already done it. So I take a look at fernandreu's commits, and I like his changes. So I dropped my fork and use his build in my projects, that is version 4.2.0. In addition, he has a WPF wrapper. I don't write WPF application so I can't comment on this.

Fernandreu's build works well in my .NET 6 project, so I'll close this issue when I visit this thread next time. Cheers.