Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Haxe 3.3] Adds Support of -D display-stdin. closes #1311 #1318

Merged
merged 17 commits into from
Oct 11, 2016
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public CompilerCompletionHandler(Process haxeProcess)
}

public string GetCompletion(string[] args)
{
return GetCompletion(args, null);
}
public string GetCompletion(string[] args, string fileContent)
{
if (args == null || haxeProcess == null)
return string.Empty;
Expand All @@ -33,7 +37,6 @@ public string GetCompletion(string[] args)

public void Stop()
{

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public bool IsRunning()
}

public string GetCompletion(string[] args)
{
return GetCompletion(args, null);
}
public string GetCompletion(string[] args, string fileContent)
{
if (args == null || haxeProcess == null)
return string.Empty;
Expand All @@ -50,6 +54,11 @@ public string GetCompletion(string[] args)
writer.WriteLine("--cwd " + (PluginBase.CurrentProject as HaxeProject).Directory);
foreach (var arg in args)
writer.WriteLine(arg);
if (fileContent != null)
{
writer.Write("\x01");
writer.Write(fileContent);
}
writer.Write("\0");
writer.Flush();
var reader = new StreamReader(client.GetStream());
Expand Down
27 changes: 17 additions & 10 deletions External/Plugins/HaXeContext/Completion/HaxeComplete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,19 @@ public void GetUsages(HaxeCompleteResultHandler<List<HaxePositionResult>> callba

private void StartThread<T>(HaxeCompleteResultHandler<T> callback, Func<T> resultFunc)
{
PluginBase.MainForm.CallCommand("Save", null);

SaveFile();
ThreadPool.QueueUserWorkItem(_ =>
{
Status = ParseLines(handler.GetCompletion(BuildHxmlArgs()));
Status = ParseLines(handler.GetCompletion(BuildHxmlArgs(), GetFileContent()));
Notify(callback, resultFunc());
});
}

protected virtual void SaveFile()
{
PluginBase.MainForm.CallCommand("Save", null);
}

void Notify<T>(HaxeCompleteResultHandler<T> callback, T result)
{
if (Sci.InvokeRequired)
Expand All @@ -103,7 +107,7 @@ void Notify<T>(HaxeCompleteResultHandler<T> callback, T result)

/* HAXE COMPILER ARGS */

string[] BuildHxmlArgs()
protected virtual string[] BuildHxmlArgs()
{
// check haxe project & context
if (PluginBase.CurrentProject == null || !(PluginBase.CurrentProject is HaxeProject)
Expand All @@ -120,15 +124,18 @@ string[] BuildHxmlArgs()
QuotePath(hxmlArgs);
EscapeMacros(hxmlArgs);

hxmlArgs.Insert(0, String.Format("--display \"{0}\"@{1}{2}", FileName, pos, GetMode()));
hxmlArgs.Insert(1, "-D use_rtti_doc");
hxmlArgs.Insert(2, "-D display-details");

if (hxproj.TraceEnabled) hxmlArgs.Insert(2, "-debug");

hxmlArgs.Add(String.Format("--display \"{0}\"@{1}{2}", FileName, pos, GetMode()));
hxmlArgs.Add("-D use_rtti_doc");
hxmlArgs.Add("-D display-details");
if (hxproj.TraceEnabled) hxmlArgs.Add("-debug");
return hxmlArgs.ToArray();
}

protected virtual string GetFileContent()
{
return null;
}

private string GetMode()
{
switch (CompilerService)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
interface IHaxeCompletionHandler
{
string GetCompletion(string[] args);
string GetCompletion(string[] args, string fileContent);
void Stop();
}
}
16 changes: 12 additions & 4 deletions External/Plugins/HaXeContext/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,7 @@ public override MemberList ResolveDotContext(ScintillaNet.ScintillaControl sci,
if (expression.Value != "")
{
// async processing
var hc = new HaxeComplete(sci, expression, autoHide, completionModeHandler, HaxeCompilerService.COMPLETION, GetCurrentSDKVersion());
var hc = GetHaxeComplete(sci, expression, autoHide, HaxeCompilerService.COMPLETION);
hc.GetList(OnDotCompletionResult);
resolvingDot = true;
}
Expand All @@ -1209,6 +1209,14 @@ public override MemberList ResolveDotContext(ScintillaNet.ScintillaControl sci,
return null;
}

HaxeComplete GetHaxeComplete(ScintillaControl sci, ASExpr expression, bool autoHide, HaxeCompilerService compilerService)
{
var sdkVersion = GetCurrentSDKVersion();
if (hxsettings.CompletionMode == HaxeCompletionModeEnum.CompletionServer && new SemVer("3.2.1").IsOlderThan(sdkVersion))
Copy link
Member

@elsassph elsassph Oct 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe do a semver greater-than-or-equal 3.3.0 if it's possible; who knows, a 3.2.2 fix release could happen.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed 7c68005

return new HaxeComplete330(sci, expression, autoHide, completionModeHandler, compilerService, sdkVersion);
return new HaxeComplete(sci, expression, autoHide, completionModeHandler, compilerService, sdkVersion);
}

internal void OnDotCompletionResult(HaxeComplete hc, HaxeCompleteResult result, HaxeCompleteStatus status)
{
resolvingDot = false;
Expand Down Expand Up @@ -1378,7 +1386,7 @@ public override MemberModel ResolveFunctionContext(ScintillaNet.ScintillaControl
return null;

expression.Position++;
var hc = new HaxeComplete(sci, expression, autoHide, completionModeHandler, HaxeCompilerService.COMPLETION, GetCurrentSDKVersion());
var hc = GetHaxeComplete(sci, expression, autoHide, HaxeCompilerService.COMPLETION);
hc.GetList(OnFunctionCompletionResult);

resolvingFunction = true;
Expand Down Expand Up @@ -1407,7 +1415,7 @@ public override bool HandleGotoDeclaration(ScintillaControl sci, ASExpr expressi
if (hxsettings.CompletionMode == HaxeCompletionModeEnum.FlashDevelop || GetCurrentSDKVersion().IsOlderThan(new SemVer("3.2.0")))
return false;

var hc = new HaxeComplete(sci, expression, false, completionModeHandler, HaxeCompilerService.POSITION, GetCurrentSDKVersion());
var hc = GetHaxeComplete(sci, expression, false, HaxeCompilerService.POSITION);
hc.GetPosition(OnPositionResult);
return true;
}
Expand Down Expand Up @@ -1467,7 +1475,7 @@ public override void CheckSyntax()
if (hxsettings.CompletionMode == HaxeCompletionModeEnum.FlashDevelop || PluginBase.MainForm.CurrentDocument.IsUntitled) return;

EventManager.DispatchEvent(this, new NotifyEvent(EventType.ProcessStart));
var hc = new HaxeComplete(ASContext.CurSciControl, new ASExpr(), false, completionModeHandler, HaxeCompilerService.COMPLETION, GetCurrentSDKVersion());
var hc = GetHaxeComplete(ASContext.CurSciControl, new ASExpr(), false, HaxeCompilerService.COMPLETION);
hc.GetList(OnCheckSyntaxResult);
}

Expand Down
1 change: 1 addition & 0 deletions External/Plugins/HaXeContext/HaXeContext.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
<Compile Include="Completion\IHaxeCompletionHandler.cs" />
<Compile Include="Completion\CompilerCompletionHandler.cs" />
<Compile Include="Completion\CompletionServerCompletionHandler.cs" />
<Compile Include="HaxeComplete330.cs" />
<Compile Include="HaXeSettings.cs" />
<Compile Include="ExternalToolchain.cs" />
<Compile Include="PluginMain.cs" />
Expand Down
37 changes: 37 additions & 0 deletions External/Plugins/HaXeContext/HaxeComplete330.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Collections.Generic;
using ASCompletion.Completion;
using PluginCore;
using PluginCore.Utilities;
using ScintillaNet;

namespace HaXeContext
{
class HaxeComplete330 : HaxeComplete
{
public HaxeComplete330(ScintillaControl sci, ASExpr expr, bool autoHide, IHaxeCompletionHandler completionHandler, HaxeCompilerService compilerService, SemVer haxeVersion) : base(sci, expr, autoHide, completionHandler, compilerService, haxeVersion)
{
}

protected override void SaveFile()
{
foreach (var document in PluginBase.MainForm.Documents)
{
if(document.FileName != Sci.FileName && document.IsModified) document.Save();
}
}

protected override string[] BuildHxmlArgs()
{
var args = base.BuildHxmlArgs();
if (args == null) return null;
var list = new List<string>(args) {"-D display-stdin"};
var result = list.ToArray();
return result;
}

protected override string GetFileContent()
{
return Sci.Text;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any possible filesize concern here? What about if you're editing a very large file?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My test file contains more than 20,000 lines of text and all ok)

}
}
}