From: Jean-Philippe Bruyère Date: Sat, 4 Dec 2021 19:44:17 +0000 (+0100) Subject: save commit X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=2e268d4b87ca746443e3e8a10ce31922917d41fd;p=jp%2Fcrowedit.git save commit --- diff --git a/CrowEditBase/CrowEditBase.csproj b/CrowEditBase/CrowEditBase.csproj index c19e01a..26dd958 100644 --- a/CrowEditBase/CrowEditBase.csproj +++ b/CrowEditBase/CrowEditBase.csproj @@ -16,6 +16,6 @@ - + diff --git a/CrowEditBase/src/Editor.cs b/CrowEditBase/src/Editor.cs index 7e5abce..b1ca568 100644 --- a/CrowEditBase/src/Editor.cs +++ b/CrowEditBase/src/Editor.cs @@ -59,11 +59,9 @@ namespace Crow public event EventHandler 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 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); diff --git a/CrowEditBase/src/SourceEditor.cs b/CrowEditBase/src/SourceEditor.cs index 9169cb1..281a7cd 100644 --- a/CrowEditBase/src/SourceEditor.cs +++ b/CrowEditBase/src/SourceEditor.cs @@ -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 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(); diff --git a/plugins/CECrowPlugin/default.conf b/plugins/CECrowPlugin/default.conf index f557a31..87b623e 100644 --- a/plugins/CECrowPlugin/default.conf +++ b/plugins/CECrowPlugin/default.conf @@ -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 diff --git a/plugins/CECrowPlugin/src/CrowService.cs b/plugins/CECrowPlugin/src/CrowService.cs index 5866a7b..3d93ee3 100644 --- a/plugins/CECrowPlugin/src/CrowService.cs +++ b/plugins/CECrowPlugin/src/CrowService.cs @@ -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); } } diff --git a/plugins/CECrowPlugin/src/DebugInterface.cs b/plugins/CECrowPlugin/src/DebugInterface.cs index f179d25..b5c78f4 100644 --- a/plugins/CECrowPlugin/src/DebugInterface.cs +++ b/plugins/CECrowPlugin/src/DebugInterface.cs @@ -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; diff --git a/plugins/CECrowPlugin/src/ImlDocument.cs b/plugins/CECrowPlugin/src/ImlDocument.cs index 5dde2dc..49a4f99 100644 --- a/plugins/CECrowPlugin/src/ImlDocument.cs +++ b/plugins/CECrowPlugin/src/ImlDocument.cs @@ -15,7 +15,6 @@ using CrowEditBase; using static CrowEditBase.CrowEditBase; using CrowEdit.Xml; -using CERoslynPlugin; using AttributeSyntax = CrowEdit.Xml.AttributeSyntax; diff --git a/plugins/CECrowPlugin/src/Parsing/Styling/StyleTokenType.cs b/plugins/CECrowPlugin/src/Parsing/Styling/StyleTokenType.cs index e6609f5..8267f1b 100644 --- a/plugins/CECrowPlugin/src/Parsing/Styling/StyleTokenType.cs +++ b/plugins/CECrowPlugin/src/Parsing/Styling/StyleTokenType.cs @@ -4,7 +4,7 @@ using System; -namespace CECrowPlugin +namespace CECrowPlugin.Style { [Flags] public enum StyleTokenType { diff --git a/plugins/CECrowPlugin/src/Parsing/Styling/StyleTokenizer.cs b/plugins/CECrowPlugin/src/Parsing/Styling/StyleTokenizer.cs index 33fa2f2..a49628b 100644 --- a/plugins/CECrowPlugin/src/Parsing/Styling/StyleTokenizer.cs +++ b/plugins/CECrowPlugin/src/Parsing/Styling/StyleTokenizer.cs @@ -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; diff --git a/plugins/CECrowPlugin/src/Parsing/Styling/SyntaxAnalyser.cs b/plugins/CECrowPlugin/src/Parsing/Styling/SyntaxAnalyser.cs index d3cf493..dfcb8b8 100644 --- a/plugins/CECrowPlugin/src/Parsing/Styling/SyntaxAnalyser.cs +++ b/plugins/CECrowPlugin/src/Parsing/Styling/SyntaxAnalyser.cs @@ -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 iter; - int currentLine; public override void Process () { StyleDocument doc = source as StyleDocument; Exceptions = new List (); - CurrentNode = new StyleRootSyntax (doc); - previousTok = default; - iter = doc.Tokens.AsEnumerable().GetEnumerator (); + currentNode = new StyleRootSyntax (doc); currentLine = 0; + Span 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) diff --git a/plugins/CECrowPlugin/src/Parsing/Styling/SyntaxNodes.cs b/plugins/CECrowPlugin/src/Parsing/Styling/SyntaxNodes.cs index 1f2f33e..c740e90 100644 --- a/plugins/CECrowPlugin/src/Parsing/Styling/SyntaxNodes.cs +++ b/plugins/CECrowPlugin/src/Parsing/Styling/SyntaxNodes.cs @@ -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; } diff --git a/plugins/CECrowPlugin/src/StyleDocument.cs b/plugins/CECrowPlugin/src/StyleDocument.cs index 31e1337..d6e751a 100644 --- a/plugins/CECrowPlugin/src/StyleDocument.cs +++ b/plugins/CECrowPlugin/src/StyleDocument.cs @@ -1,14 +1,14 @@ // Copyright (c) 2013-2021 Bruyère Jean-Philippe // // 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) diff --git a/plugins/CERoslynPlugin/src/RoslynService.cs b/plugins/CERoslynPlugin/src/RoslynService.cs index 3652ec8..f2a6728 100644 --- a/plugins/CERoslynPlugin/src/RoslynService.cs +++ b/plugins/CERoslynPlugin/src/RoslynService.cs @@ -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 diff --git a/plugins/CEXmlPlugin/CEXmlPlugin.csproj b/plugins/CEXmlPlugin/CEXmlPlugin.csproj index 5329767..bf08eac 100644 --- a/plugins/CEXmlPlugin/CEXmlPlugin.csproj +++ b/plugins/CEXmlPlugin/CEXmlPlugin.csproj @@ -4,7 +4,7 @@ netcoreapp3.1 false - + diff --git a/src/CrowEdit.cs b/src/CrowEdit.cs index a1ae00c..17556c7 100644 --- a/src/CrowEdit.cs +++ b/src/CrowEdit.cs @@ -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; diff --git a/ui/windows/winPlugins.crow b/ui/windows/winPlugins.crow index d9354b2..b4e5877 100644 --- a/ui/windows/winPlugins.crow +++ b/ui/windows/winPlugins.crow @@ -22,13 +22,13 @@ - + - diff --git a/ui/windows/winProjects.crow b/ui/windows/winProjects.crow index d1ec6ef..2b86351 100644 --- a/ui/windows/winProjects.crow +++ b/ui/windows/winProjects.crow @@ -13,7 +13,6 @@ --> -