View unanswered posts | View active topics



Reply to topic  [ 5 posts ] 
Autocomplete and autoformat patches for Haxe and AS3 
Author Message
Member

Joined: Tue Aug 27, 2013 10:09 am
Posts: 2
Reply with quote
Hi! I've just started with FD to learn Haxe and I love it!
I've fiddled with the source so I could add a few things I've feel it was missing for me. (Should I make separated threads for each feature?)
This is for beta version 4.4.3 revision 2753.

First, I noticed the code formatter (default shortcut: Ctrl+Shift+2) doesn't work for Haxe. It seems there was a plugin, but it doesn't work with FD last versions.
Then, as Haxe is so similar to AS3, I thought a quick hack to make the AS3 code formatter work for Haxe would be useful for now.
Of course, Haxe isn't 100% equals AS3, so the syntax checker that runs before the code formatter will probably say there's some syntax error when you try to format the whole code at once. Then I added some come so you can format only the selected text. Also, if there's nothing selected, it'll follow the original behavior of formatting everything. All this is working for the AS3 code formatter too (format selection).

Code:
Index: FD4/External/Plugins/CodeFormatter/PluginMain.cs
===================================================================
--- FD4/External/Plugins/CodeFormatter/PluginMain.cs   (revision 2753)
+++ FD4/External/Plugins/CodeFormatter/PluginMain.cs   (working copy)
@@ -240,6 +240,7 @@
       private const int TYPE_MXML = 1;
       private const int TYPE_XML = 2;
       private const int TYPE_UNKNOWN = 3;
+        private const int TYPE_HAXE = 4;
       
       /// <summary>
       ///
@@ -251,20 +252,30 @@
          {
             doc.SciControl.BeginUndoAction();
             Int32 oldPos = CurrentPos;
-            String source = doc.SciControl.Text;
+            Boolean isSelection = doc.SciControl.SelTextSize > 0;
+            String source = isSelection ? doc.SciControl.SelText : doc.SciControl.Text;
+            int currentLine = doc.SciControl.LineFromPosition(doc.SciControl.SelectionStart);
+            int identation = isSelection ? doc.SciControl.GetLineIndentation(currentLine) : 0;
+
                 try
                 {
                     switch (DocumentType)
                     {
                         case TYPE_AS3PURE:
+                        case TYPE_HAXE:
                             ASPrettyPrinter asPrinter = new ASPrettyPrinter(true, source);
                             FormatUtility.ConfigureASPrinter(asPrinter, this.settingObject, PluginBase.Settings.TabWidth);
-                            String asResultData = asPrinter.Print(0);
+                            String asResultData = asPrinter.Print(identation).TrimEnd(' ', '\t', '\n', '\r');
                             if (asResultData == null)
                             {
                                 TraceManager.Add(TextHelper.GetString("Info.CouldNotFormat"), -3);
                                 PluginBase.MainForm.CallCommand("PluginCommand", "ResultsPanel.ShowResults");
                             }
+                            else if (isSelection)
+                            {
+                                doc.SciControl.ReplaceSel(asResultData);
+                                doc.SciControl.SetLineIndentation(currentLine, identation);
+                            }
                             else doc.SciControl.Text = asResultData;
                             break;
 
@@ -287,7 +298,7 @@
                     TraceManager.Add(TextHelper.GetString("Info.CouldNotFormat"), -3);
                     PluginBase.MainForm.CallCommand("PluginCommand", "ResultsPanel.ShowResults");
                 }
-            CurrentPos = oldPos;
+            if (!isSelection) CurrentPos = oldPos;
             doc.SciControl.EndUndoAction();
          }
       }
@@ -346,6 +357,7 @@
                     else if (ext.Equals(".mxml")) return TYPE_MXML;
             }
                 if (ext.Equals(".xml")) return TYPE_XML;
+                if (ext.Equals(".hx")) return TYPE_HAXE;
             return TYPE_UNKNOWN;
          }
       }



This is the second problem to me. You can use the selected item at the autocompletion suggestion list by pressing Enter and some other keys like: . + - = ,
The problem was that the respective numpad keys don't work for this. Numpad add, subtract, divide, dot, etc, don't trigger the autocompletion selected item, it just cancel the suggestions list and add the pressed key to the text. Well, I don't really know if this was the right/best file to edit (UIToold.cs), but it worked to me.
"Decimal", "RButton, Oemtilde", "Add", "Subtract" and "Multiply" are just the numpad keys names. Also, I noticed "\" and "/" didn't work too, wherever they were at the keyboard, not only the keypad one, so I added them too, using: "LButton, Oemtilde", "OemBackslash" and "Divide". I don't know if they're all correct for other language keyboards, though.

Code:
Index: FD4/PluginCore/PluginCore/Controls/UITools.cs
===================================================================
--- FD4/PluginCore/PluginCore/Controls/UITools.cs   (revision 2762)
+++ FD4/PluginCore/PluginCore/Controls/UITools.cs   (working copy)
@@ -408,7 +408,9 @@
          }
          
          // switches
-         else if ((key & Keys.ShiftKey) == Keys.ShiftKey || (key & Keys.ControlKey) == Keys.ControlKey || (key & Keys.Menu) == Keys.Menu)
+         else if ((key & Keys.ShiftKey) == Keys.ShiftKey || (key & Keys.ControlKey) == Keys.ControlKey || (key & Keys.Menu) == Keys.Menu
+            || ks == "Decimal" || ks == "RButton, Oemtilde" || ks == "Add" || ks == "Subtract" || ks == "Multiply"
+            || ks == "LButton, Oemtilde" || ks == "OemBackslash" || ks == "Divide")
          {
             return false;
          }


The third problem... it'll be easier to show with gifs:
How it should be:

Image

How it is:

Image

If you just want to use the first selected item with any key besides Enter, but don't press Up or Down before that, it's just cancelled. The patch below forces it to actually use the selected item.

Code:
Index: FD4/PluginCore/PluginCore/Controls/UITools.cs
===================================================================
--- FD4/PluginCore/PluginCore/Controls/UITools.cs   (revision 2762)
+++ FD4/PluginCore/PluginCore/Controls/UITools.cs   (working copy)
@@ -410,6 +410,8 @@
          // switches
          else if ((key & Keys.ShiftKey) == Keys.ShiftKey || (key & Keys.ControlKey) == Keys.ControlKey || (key & Keys.Menu) == Keys.Menu)
          {
+            if(!String.IsNullOrEmpty(CompletionList.SelectedLabel))
+               CompletionList.SelectItem(CompletionList.SelectedLabel);
             return false;
          }


Those are all for AS3 and Haxe. Thank you guys for this awesome IDE, and for reading this!


Last edited by NeoZeroo on Mon Sep 02, 2013 10:59 pm, edited 1 time in total.



Sun Sep 01, 2013 2:54 pm
Profile
Admin

Joined: Wed Aug 31, 2005 7:27 am
Posts: 12172
Location: London
Reply with quote
Thanks for looking into FD source code to fix things - code contributions are very appreciated.

- I'm cool with the CodeFormatter patch - I guess it won't break anything...
- 2nd fix certainly doesn't look right, but I accept the issue; I need to find my USB keyboard to look into that,
- I'm not ok with the 3rd fix: this behaviour is a feature.


Sun Sep 01, 2013 8:29 pm
Profile WWW
Member

Joined: Tue Aug 27, 2013 10:09 am
Posts: 2
Reply with quote
I knew the second patch was too hacky to be accepted, thank you for looking into it though!
About the third one, I thought that was not the intended behavior, as Visual Studio behaves just like the first gif, and I got used to that.
So, is the following also intended? If I've previously selected the first option using enter, the next time I try to just press period to select it, it works, like the first gif, just pressing ". . .". If it's the first time in this session that I'm trying to do it like that, it won't work, as seen in the second gif.
Thanks!


Sun Sep 01, 2013 9:32 pm
Profile
Admin

Joined: Wed Aug 31, 2005 7:27 am
Posts: 12172
Location: London
Reply with quote
There may be edge cases where it works but that was historically the intended behaviour (less aggressive insertion; actually needed for Haxe).


Sun Sep 01, 2013 9:58 pm
Profile WWW
Member

Joined: Thu Feb 09, 2006 10:58 am
Posts: 1095
Location: Israel
Reply with quote
.<Enter>.<Enter>.<Enter>.<Enter>

_________________
MovieClipCommander


Mon Sep 02, 2013 12:58 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.