]> O.S.I.I.S - jp/crowedit.git/commitdiff
save commit
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sat, 4 Dec 2021 19:44:17 +0000 (20:44 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sat, 4 Dec 2021 19:44:17 +0000 (20:44 +0100)
17 files changed:
CrowEditBase/CrowEditBase.csproj
CrowEditBase/src/Editor.cs
CrowEditBase/src/SourceEditor.cs
plugins/CECrowPlugin/default.conf
plugins/CECrowPlugin/src/CrowService.cs
plugins/CECrowPlugin/src/DebugInterface.cs
plugins/CECrowPlugin/src/ImlDocument.cs
plugins/CECrowPlugin/src/Parsing/Styling/StyleTokenType.cs
plugins/CECrowPlugin/src/Parsing/Styling/StyleTokenizer.cs
plugins/CECrowPlugin/src/Parsing/Styling/SyntaxAnalyser.cs
plugins/CECrowPlugin/src/Parsing/Styling/SyntaxNodes.cs
plugins/CECrowPlugin/src/StyleDocument.cs
plugins/CERoslynPlugin/src/RoslynService.cs
plugins/CEXmlPlugin/CEXmlPlugin.csproj
src/CrowEdit.cs
ui/windows/winPlugins.crow
ui/windows/winProjects.crow

index c19e01a653388c8fc1766d26565fcaef36fcd6d6..26dd95805fb360cb21fef4947350d4bf0cd21c5c 100644 (file)
@@ -16,6 +16,6 @@
        </ItemGroup>
        <ItemGroup>
                <ProjectReference Include="/mnt/devel/crow/Crow/Crow.csproj" />
-               <!--<PackageReference Include="Crow" Version="0.9.7-beta" />-->
+               <!--<PackageReference Include="Crow" Version="0.9.8" />-->
        </ItemGroup>
 </Project>
index 7e5abce4922d025aad20c44e8ae38bd88f8d7ee7..b1ca5680e1c4978c65bd4555f14d91a2d086948a 100644 (file)
@@ -59,11 +59,9 @@ namespace Crow
                public event EventHandler<TextChangeEventArgs> TextChanged;
                public void OnTextChanged(object sender, TextChangeEventArgs e)
                {
-                       if (disableTextChangedEvent)
-                               return;
                        TextChanged.Raise (this, e);
                }
-               protected void backgroundThreadFunc () {
+               protected virtual void backgroundThreadFunc () {
                        while (true) {
                                if (Document != null && document.TryGetState (this, out List<TextChange> changes)) {
                                        disableTextChangedEvent = true;
@@ -881,7 +879,8 @@ namespace Crow
 
                protected virtual void update (TextChange change) {
 
-                       OnTextChanged (this, new TextChangeEventArgs (change));
+                       if (!disableTextChangedEvent)
+                               OnTextChanged (this, new TextChangeEventArgs (change));
 
                        selectionStart = null;
                        CurrentLoc = document.GetLocation (change.Start + change.ChangedText.Length);
index 9169cb182551eb6482ea35c487a73c653d12adca..281a7cd72c53317dcc968c3dbe13002c951a8a83 100644 (file)
@@ -16,6 +16,20 @@ namespace Crow
 {
        public class SourceEditor : Editor {
                object TokenMutex = new object();
+               /*protected override void backgroundThreadFunc () {
+                       while (true) {
+                               if (Document != null && Document.TryGetState (this, out List<TextChange> changes)) {
+                                       disableTextChangedEvent = true;
+                                       disableSuggestions = true;
+                                       foreach (TextChange tc in changes)
+                                               update (tc);
+                                       disableTextChangedEvent = false;
+                                       disableSuggestions = false;
+                               }
+                               System.Threading.Thread.Sleep (200);
+                       }
+               }*/
+
                SyntaxNode currentNode;
 #if DEBUG_NODE
                SyntaxNode _hoverNode;
@@ -765,7 +779,7 @@ namespace Crow
                        if (Document is SourceDocument srcdoc)
                                srcdoc.updateCurrentTokAndNode (CurrentLoc.Value);
 
-                       if (!disableSuggestions && HasFocus)
+                       if (!disableSuggestions &&!disableTextChangedEvent && HasFocus)
                                tryGetSuggestions ();
 
                        RegisterForGraphicUpdate();
index f557a312f59864f9966366065c859af2e4501ded..87b623e4a18b206fc5118dfbb37c80be393d5303 100644 (file)
@@ -1 +1 @@
-FileAssociations = CECrowPlugin.ImlDocument:.crow,.iml,.itmp,.template,.tmp:#ui.sourceEditor.itmp;CECrowPlugin.StyleDocument:.style:#ui.sourceEditor.itmp
+FileAssociations = CECrowPlugin.ImlDocument:.crow,.iml,.itmp,.template,.tmp:#ui.sourceEditor.itmp;CECrowPlugin.Style.StyleDocument:.style:#ui.sourceEditor.itmp
index 5866a7beac6ec91a3b6b9ec53ebb9736cefd026b..3d93ee3bc6f1d7e62eafd6faf1883dde18a0074e 100644 (file)
@@ -38,7 +38,7 @@ namespace Crow
                        => App.TryGetPlugin ("CERoslynPlugin", out Plugin roslynPlugin) ?
                                roslynPlugin.Load (assemblyName) : null;*/
 
-               static IntPtr resolveUnmanaged(Assembly assembly, String libraryName)
+               /*static IntPtr resolveUnmanaged(Assembly assembly, String libraryName)
                {
 
                        switch (libraryName)
@@ -50,9 +50,9 @@ namespace Crow
                        }
                        Console.WriteLine($"[UNRESOLVE] {assembly} {libraryName}");
                        return IntPtr.Zero;
-               }
+               }*/
 
-               void updateCrowApp () {
+               /*void updateCrowApp () {
                        if (App.CurrentProject is CERoslynPlugin.SolutionProject sol) {
                                if (sol.StartupProject is CERoslynPlugin.MSBuildProject csprj) {
 
@@ -64,7 +64,7 @@ namespace Crow
                        }
 
 
-               }
+               }*/
                #region Commands
                public Command CMDStartRecording, CMDStopRecording, CMDRefresh;
                public Command CMDGotoParentEvent, CMDEventHistoryForward, CMDEventHistoryBackward;
@@ -293,8 +293,8 @@ namespace Crow
                        foreach (string assemblyPath in crowAssemblies)
                                additionalResolvePath.Add (System.IO.Path.GetDirectoryName(assemblyPath));
 
+                       crowLoadCtx?.Unload();
                        crowLoadCtx = new AssemblyLoadContext("CrowDebuggerLoadContext");
-                       crowLoadCtx.ResolvingUnmanagedDll += resolveUnmanaged;
                        crowLoadCtx.Resolving += (context, assemblyName) => {
                                foreach (string path in additionalResolvePath) {
                                        string assemblyPath = System.IO.Path.Combine (path, assemblyName.Name + ".dll");
@@ -304,7 +304,6 @@ namespace Crow
                                }
                                return null;
                        };
-                       //crowLoadCtx.Resolving += (ctx,name) => AssemblyLoadContext.Default.LoadFromAssemblyName (name);
 
                        //using (crowLoadCtx.EnterContextualReflection()) {
                                crowAssembly = crowLoadCtx.LoadFromAssemblyPath (CrowDbgAssemblyLocation);
@@ -394,10 +393,10 @@ namespace Crow
                public Project ActiveSolution {
                        get => activeSolution;
                        set {
-                               CERoslynPlugin.SolutionProject sol = value as CERoslynPlugin.SolutionProject;
-                               if (activeSolution == sol)
+                               //CERoslynPlugin.SolutionProject sol = value as CERoslynPlugin.SolutionProject;
+                               if (activeSolution == value)
                                        return;
-                               activeSolution = sol;
+                               activeSolution = value;
                                NotifyValueChanged (activeSolution);
                        }
                }
index f179d25d281a499915d687e6780569c302dd4d7b..b5c78f406d6e6f3a16aee38ec317de9305ec149e 100644 (file)
@@ -7,6 +7,7 @@ using System.Collections.Generic;
 using System.IO;
 using System.Reflection;
 using System.Threading;
+using System.Linq;
 using Crow;
 using Crow.Drawing;
 using IML = Crow.IML;
@@ -190,12 +191,18 @@ namespace CECrowPlugin
                public override Type GetWidgetTypeFromName (string typeName){
                        if (knownCrowWidgetTypes.ContainsKey (typeName))
                                return knownCrowWidgetTypes [typeName];
-                       foreach (Assembly a in System.Runtime.Loader.AssemblyLoadContext.GetLoadContext (Assembly.GetExecutingAssembly ()).Assemblies) {
-                               foreach (Type expT in a.GetExportedTypes ()) {
-                                       if (expT.Name != typeName)
-                                               continue;
-                                       knownCrowWidgetTypes.Add (typeName, expT);
-                                       return expT;
+                       System.Runtime.Loader.AssemblyLoadContext dbgLoadCtx =
+                               System.Runtime.Loader.AssemblyLoadContext.All.FirstOrDefault (ctx=>ctx.Name == "CrowDebuggerLoadContext");
+                       foreach (Assembly a in dbgLoadCtx.Assemblies) {
+                               try {
+                                       foreach (Type expT in a.GetExportedTypes ()) {
+                                               if (expT.Name != typeName)
+                                                       continue;
+                                               knownCrowWidgetTypes.Add (typeName, expT);
+                                               return expT;
+                                       }
+                               } catch (Exception ex) {
+                                       Console.WriteLine ($"[CECrowPlugin]Error: GetWidgetTypeFromName failed for {typeName} in {a}.\n{ex}");
                                }
                        }
                        return null;
index 5dde2dcee7e1d7b38fee27cf2e26391f5ed334ab..49a4f99d020ee52560e7cbbd0f9f760b9d13c5db 100644 (file)
@@ -15,7 +15,6 @@ using CrowEditBase;
 using static CrowEditBase.CrowEditBase;
 
 using CrowEdit.Xml;
-using CERoslynPlugin;
 
 using AttributeSyntax = CrowEdit.Xml.AttributeSyntax;
 
index e6609f59016b5ac417547b9afa329b1aebd1920b..8267f1b5cc26ce85ee48e47c62bcc41159e66242 100644 (file)
@@ -4,7 +4,7 @@
 
 using System;
 
-namespace CECrowPlugin
+namespace CECrowPlugin.Style
 {
        [Flags]
        public enum StyleTokenType {
index 33fa2f2a13aa0a306f202a7da0015341bc0911af..a49628b0aceb897a1814b0a547ba1fa88b8b64b3 100644 (file)
@@ -9,7 +9,7 @@ using CrowEditBase;
 using System.Globalization;
 using Crow.Coding;
 
-namespace CECrowPlugin {
+namespace CECrowPlugin.Style {
        public class StyleTokenizer : Tokenizer {
                enum States     {
                        classNames, members, value, endOfStatement
@@ -40,6 +40,20 @@ namespace CECrowPlugin {
                        }
                        return false;
                }
+               bool replacePreviousNonTriviaTokType (StyleTokenType expectedType, StyleTokenType newType) {
+                       int tk = Toks.Count - 2;
+                       if (tk < 0)
+                               return false;
+                       while (tk > 0 && Toks[tk].Type.HasFlag(StyleTokenType.Trivia))
+                               tk --;
+                       if ((StyleTokenType)Toks[tk].Type == expectedType) {
+                               Token tok = Toks[tk];
+                               tok.Type = (TokenType)newType;
+                               Toks[tk] = tok;
+                               return true;
+                       }
+                       return false;
+               }
 
                public override Token[] Tokenize (string source) {
                        SpanCharReader reader = initParsing (source);
@@ -64,10 +78,20 @@ namespace CECrowPlugin {
                                        } else if (reader.TryPeak ('*')) {
                                                reader.Advance ();
                                                addTok (ref reader, StyleTokenType.BlockCommentStart);
-                                               if (reader.TryReadUntil ("*/")) {
-                                                       addTok (ref reader, StyleTokenType.BlockComment);
-                                                       reader.Advance (2);
-                                                       addTok (ref reader, StyleTokenType.BlockCommentEnd);
+                                               while (!reader.EndOfSpan) {
+                                                       if (reader.Eol()) {
+                                                               addTok (ref reader, StyleTokenType.BlockComment);
+                                                               reader.ReadEol();
+                                                               addTok (ref reader, StyleTokenType.LineBreak);
+                                                               continue;
+                                                       }
+                                                       if (reader.TryPeak ("*/")) {
+                                                               addTok (ref reader, StyleTokenType.BlockComment);
+                                                               reader.Advance (2);
+                                                               addTok (ref reader, StyleTokenType.BlockCommentEnd);
+                                                               break;
+                                                       } else
+                                                               reader.Read ();
                                                }
                                        }
                                        break;
index d3cf4930da265f8653f822afb50178ebeece6d17..dfcb8b8dde46a852ff99175033518fb3c86e103b 100644 (file)
@@ -6,35 +6,50 @@ using System.Collections.Generic;
 using System.Linq;
 using CrowEditBase;
 
-namespace CECrowPlugin
+namespace CECrowPlugin.Style
 {
+       public static class Extensions {
+               public static StyleTokenType GetTokenType (this Token tok) {
+                       return (StyleTokenType)tok.Type;
+               }
+               public static void SetTokenType (this Token tok, StyleTokenType type) {
+                       tok.Type = (TokenType)type;
+               }
+       }
        public class StyleSyntaxAnalyser : SyntaxAnalyser {
-               public override SyntaxNode Root => CurrentNode;
+               public override SyntaxNode Root => currentNode;
                public StyleSyntaxAnalyser (StyleDocument source) : base (source) {
                        this.source = source;
                }
 
-               SyntaxNode CurrentNode;
-               Token previousTok;
-               IEnumerator<Token> iter;
-               int currentLine;
                public override void Process () {
                        StyleDocument doc = source as StyleDocument;
                        Exceptions = new List<SyntaxException> ();
-                       CurrentNode = new StyleRootSyntax (doc);
-                       previousTok = default;
-                       iter = doc.Tokens.AsEnumerable().GetEnumerator ();
+                       currentNode = new StyleRootSyntax (doc);
                        currentLine = 0;
+                       Span<Token> toks = source.Tokens;
+                       tokIdx = 0;
+
+                       int firstNameIdx = -1;
 
-                       bool notEndOfSource = iter.MoveNext ();
-                       while (notEndOfSource) {
-                               if (iter.Current.Type == TokenType.LineBreak)
+                       while (tokIdx < toks.Length) {
+                               Token curTok = toks[tokIdx];
+                               if (curTok.Type == TokenType.LineBreak)
                                        currentLine++;
-                               else if (!iter.Current.Type.HasFlag (TokenType.Trivia)) {
-                               }
+                               else if (!curTok.Type.HasFlag (TokenType.Trivia)) {
+                                       /*if (currentNode is StyleRootSyntax root) {
+                                               if (firstNameIdx < 0) {
+                                                       if (curTok.GetTokenType()  == StyleTokenType.Name) {
+                                                               firstNameIdx = tokIdx;
+                                                       } else {
+                                                               Exceptions.Add (new SyntaxException  ("Unexpected Token", curTok));
+                                                       }
+
+                                               }
 
-                               previousTok = iter.Current;
-                               notEndOfSource = iter.MoveNext ();
+                                       }*/
+                               }
+                               tokIdx++;
                        }
                        while (currentNode.Parent != null) {
                                if (!currentNode.LastTokenOffset.HasValue)
index 1f2f33e09fb9eebffd671bf37ddb9e3b65a2d479..c740e90b9fea54f5a14ab5c78376738cc3b557cd 100644 (file)
@@ -7,7 +7,7 @@ using System.Linq;
 
 using CrowEditBase;
 
-namespace CECrowPlugin
+namespace CECrowPlugin.Style
 {
 
        public class StyleRootSyntax : SyntaxRootNode {
@@ -15,7 +15,14 @@ namespace CECrowPlugin
                        : base (source) {
                }
        }
-
+       public class ConstantDefinitionSyntax : SyntaxNode {
+               internal int? name, equal, valueOpen, valueClose;
+               public override bool IsComplete => base.IsComplete & name.HasValue & equal.HasValue &
+                       valueOpen.HasValue & valueClose.HasValue;
+               public ConstantDefinitionSyntax (int startLine, int tokenBase)
+                       : base (startLine, tokenBase) {
+               }
+       }
        public class AttributeSyntax : SyntaxNode {
                public Token? NameToken { get; internal set; }
                public Token? EqualToken { get; internal set; }
index 31e1337c87e2f1d01c07a74de3240485f88404fe..d6e751a7c438406ae2b6a987c883e57f38a91528 100644 (file)
@@ -1,14 +1,14 @@
 // Copyright (c) 2013-2021  Bruyère Jean-Philippe <jp_bruyere@hotmail.com>
 //
 // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
-
+using System;
 using Crow.Text;
 using Crow;
 using System.Collections;
 using CrowEditBase;
 using static CrowEditBase.CrowEditBase;
 
-namespace CECrowPlugin
+namespace CECrowPlugin.Style
 {
        public class StyleDocument : SourceDocument {
 
@@ -25,8 +25,9 @@ namespace CECrowPlugin
                protected override SyntaxAnalyser CreateSyntaxAnalyser() => new StyleSyntaxAnalyser (this);
 
                public override IList GetSuggestions (CharLocation loc) {
-                       /*currentToken = FindTokenIncludingPosition (pos);
-                       currentNode = FindNodeIncludingPosition (pos);*/
+                       Console.ForegroundColor = ConsoleColor.DarkYellow;
+                       Console.WriteLine ($"Tok: {this.CurrentTokenString} {((StyleTokenType)CurrentToken.Type).ToString()}");
+                       Console.ResetColor();
                        return null;
                }
                public override bool TryGetCompletionForCurrentToken(object suggestion, out TextChange change, out TextSpan? newSelection)
index 3652ec80c50a2bb46557a5fd8ff87049b85ebf30..f2a67281215c42862e58d85112144ae59e6838a4 100644 (file)
@@ -209,5 +209,7 @@ namespace CERoslynPlugin
                        public long ToInt => major << 62 + minor << 60 + revision;
                        public override string ToString () => $"{major}.{minor}.{revision}";
                }
+
+
        }
 }
\ No newline at end of file
index 53297675473c46bb9504887a71c865152556c862..bf08eacaac64fb3af8806a01062883f661b96489 100644 (file)
@@ -4,7 +4,7 @@
                <TargetFrameworks>netcoreapp3.1</TargetFrameworks>
                <EnableDefaultItems>false</EnableDefaultItems>
        </PropertyGroup>
-       
+
        <ItemGroup>
                <Compile Include="src\**\*.cs" />
                <EmbeddedResource Include="default.conf" />
index a1ae00c6688b8de79f21f703f42d4c3069d94641..17556c71ba7f055be9c9ac544640de2b5b907aeb 100644 (file)
@@ -17,21 +17,6 @@ namespace CrowEdit
 {
        public class CrowEdit : CrowEditBase.CrowEditBase
        {
-#if NETCOREAPP
-               static IntPtr resolveUnmanaged(Assembly assembly, String libraryName)
-               {
-
-                       switch (libraryName)
-                       {
-                               case "glfw3":
-                                       return NativeLibrary.Load("glfw", assembly, null);
-                               case "rsvg-2.40":
-                                       return NativeLibrary.Load("rsvg-2", assembly, null);
-                       }
-                       Console.WriteLine($"[UNRESOLVE] {assembly} {libraryName}");
-                       return IntPtr.Zero;
-               }
-
                static Assembly last_chance_resolve (System.Runtime.Loader.AssemblyLoadContext context, AssemblyName assemblyName)
                {
                        foreach (Plugin plugin in App.Plugins) {
@@ -45,10 +30,9 @@ namespace CrowEdit
                }
                static CrowEdit()
                {
-                       System.Runtime.Loader.AssemblyLoadContext.GetLoadContext(Assembly.GetExecutingAssembly()).ResolvingUnmanagedDll += resolveUnmanaged;
                        System.Runtime.Loader.AssemblyLoadContext.GetLoadContext(Assembly.GetExecutingAssembly()).Resolving += last_chance_resolve;
                }
-#endif
+
                static void Main ()
                {
                        /*DbgLogger.IncludedEvents.AddRange ( new DbgEvtType[] {
@@ -203,7 +187,10 @@ namespace CrowEdit
                                OpenedDocuments.Add (doc);
                                CurrentDocument = doc;
                        } catch (Exception ex) {
-                               System.Diagnostics.Debug.WriteLine ($"[openOrCreateFile]{ex}");
+                               MessageBox.ShowModal (this, MessageBox.Type.Alert, $"Unable to open {filePath}.\n{ex.Message}");
+                               Console.ForegroundColor = ConsoleColor.Red;
+                               Console.WriteLine (ex);
+                               Console.ResetColor();
                        }
                        return doc;
                }
@@ -254,9 +241,9 @@ namespace CrowEdit
                                CurrentDocument = doc;
                }
                void tv_projects_SelectedItemChanged (object sender, SelectionChangeEventArgs e) {
-                       if (e.NewValue is Project prj) {
+                       /*if (e.NewValue is Project prj) {
                                CurrentProject = prj;
-                       }
+                       }*/
                        /*if (e.NewValue is IFileNode fi) {
                                if (string.IsNullOrEmpty (fi.FullPath) || ! File.Exists (fi.FullPath))
                                        return;
index d9354b2abe841499d888d0c5e10270ed84f4364e..b4e587751272059ad2829afd15413f5cf076546f 100644 (file)
                </ListBox>
                <Splitter/>
                <TreeView IsRoot="true" Name="lbCtxs"  Data="{AllLoadContexts}" UseLoadingThread = 'false' >
-                       <ItemTemplate DataType="System.Reflection">
+                       <ItemTemplate DataType="System.Reflection.Assembly">
                                <ListItem CornerRadius="2" Margin="0" Height="Fit" Width="Stretched"
                                                Selected="{Background=${ControlHighlight}}"
                                                Unselected="{Background=Transparent}">
                                        <HorizontalStack>
                                                <!--<Image Margin="1" Width="14" Height="14" Path="#Crow.Icons.file.svg"/>-->
-                                               <Label Text="{}" Width="Stretched"/>
+                                               <Label Text="{}" Width="Stretched" Tooltip="{Location}"/>
                                        </HorizontalStack>
                                </ListItem>
                        </ItemTemplate>
index d1ec6efd24ec5cf39a5d16bcda2c1e802bc3f6e7..2b86351a9726150ce17246850be1d9f34cfe19f6 100644 (file)
@@ -13,7 +13,6 @@
                        </HorizontalStack>
                </ItemTemplate>
        </ListBox>-->
-
        <TreeView Name="treeview" IsRoot="true" RootDataLevel="true" Data="{Projects}" Background="Onyx"
                                SelectedItemChanged="tv_projects_SelectedItemChanged" >
                <ItemTemplate DataType="default" >