Skip to content

Commit

Permalink
[Haxe 3.3] Adds Support of -D display-stdin. closes #1311 (#1318)
Browse files Browse the repository at this point in the history
Using SemVer right now, in the future we will also have a setting.
  • Loading branch information
SlavaRa authored and Neverbirth committed Oct 11, 2016
1 parent 258b37f commit 14a385f
Show file tree
Hide file tree
Showing 15 changed files with 301 additions and 33 deletions.
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 && sdkVersion.IsGreaterThanOrEquals(new SemVer("3.3.0")))
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;
}
}
}
15 changes: 14 additions & 1 deletion FlashDevelop.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25123.0
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlashDevelop", "FlashDevelop\FlashDevelop.csproj", "{EFD07485-9A64-4EEC-94E7-ACBD4DA5CA93}"
ProjectSection(ProjectDependencies) = postProject
Expand Down Expand Up @@ -83,6 +83,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ASCompletion.Tests", "Tests
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CodeRefactor.Tests", "Tests\External\Plugins\CodeRefactor.Tests\CodeRefactor.Tests.csproj", "{19C1FEE5-CEC3-442B-99B2-3F3FC955CAB4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PluginCore.Tests", "Tests\PluginCore\PluginCore.Tests\PluginCore.Tests.csproj", "{F44D3125-12E8-4143-B250-84C5D89D253C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -493,6 +495,17 @@ Global
{19C1FEE5-CEC3-442B-99B2-3F3FC955CAB4}.Release+Tests|Any CPU.Build.0 = Release|Any CPU
{19C1FEE5-CEC3-442B-99B2-3F3FC955CAB4}.Release+Tests|x86.ActiveCfg = Release|x86
{19C1FEE5-CEC3-442B-99B2-3F3FC955CAB4}.Release+Tests|x86.Build.0 = Release|x86
{F44D3125-12E8-4143-B250-84C5D89D253C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F44D3125-12E8-4143-B250-84C5D89D253C}.Debug|x86.ActiveCfg = Debug|Any CPU
{F44D3125-12E8-4143-B250-84C5D89D253C}.Debug|x86.Build.0 = Debug|Any CPU
{F44D3125-12E8-4143-B250-84C5D89D253C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F44D3125-12E8-4143-B250-84C5D89D253C}.Release|Any CPU.Build.0 = Release|Any CPU
{F44D3125-12E8-4143-B250-84C5D89D253C}.Release|x86.ActiveCfg = Release|Any CPU
{F44D3125-12E8-4143-B250-84C5D89D253C}.Release|x86.Build.0 = Release|Any CPU
{F44D3125-12E8-4143-B250-84C5D89D253C}.Release+Tests|Any CPU.ActiveCfg = Release|Any CPU
{F44D3125-12E8-4143-B250-84C5D89D253C}.Release+Tests|Any CPU.Build.0 = Release|Any CPU
{F44D3125-12E8-4143-B250-84C5D89D253C}.Release+Tests|x86.ActiveCfg = Release|Any CPU
{F44D3125-12E8-4143-B250-84C5D89D253C}.Release+Tests|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
39 changes: 24 additions & 15 deletions PluginCore/PluginCore/Utilities/SemVer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,13 @@ public SemVer(string version)
{
// ignore the pre-release denotation if present
int hyphenIndex = version.IndexOf('-');
if (hyphenIndex >= 0)
version = version.Substring(0, hyphenIndex);
if (hyphenIndex >= 0) version = version.Substring(0, hyphenIndex);

string[] numbers = version.Split('.');

if (numbers.Length >= 1)
int.TryParse(numbers[0], out Major);
if (numbers.Length >= 2)
int.TryParse(numbers[1], out Minor);
if (numbers.Length >= 3)
int.TryParse(numbers[2], out Patch);
if (numbers.Length >= 1) int.TryParse(numbers[0], out Major);
if (numbers.Length >= 2) int.TryParse(numbers[1], out Minor);
if (numbers.Length >= 3) int.TryParse(numbers[2], out Patch);
}

public override string ToString()
Expand All @@ -39,13 +35,26 @@ public override string ToString()

public bool IsOlderThan(SemVer semVer)
{
if (semVer.Major > Major)
return true;
if (semVer.Major == Major && semVer.Minor > Minor)
return true;
if (semVer.Major == Major && semVer.Minor == Minor && semVer.Patch > Patch)
return true;
return false;
return (semVer.Major > Major)
|| (semVer.Major == Major && semVer.Minor > Minor)
|| (semVer.Major == Major && semVer.Minor == Minor && semVer.Patch > Patch);
}

public bool Equals(SemVer semVer)
{
return semVer.Major == Major && semVer.Minor == Minor && semVer.Patch == Patch;
}

public bool IsGreaterThan(SemVer semVer)
{
return (semVer.Major < Major)
|| (semVer.Major == Major && semVer.Minor < Minor)
|| (semVer.Major == Major && semVer.Minor == Minor && semVer.Patch < Patch);
}

public bool IsGreaterThanOrEquals(SemVer semVer)
{
return Equals(semVer) || IsGreaterThan(semVer);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("CodeRefactor.Tests")]
[assembly: AssemblyDescription("DistroConfig.DISTRIBUTION_COMPANY")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyCompany("DistroConfig.DISTRIBUTION_COMPANY")]
[assembly: AssemblyProduct("CodeRefactor.Tests")]
[assembly: AssemblyCopyright("DistroConfig.DISTRIBUTION_COPYRIGHT")]
[assembly: AssemblyTrademark("")]
Expand Down
70 changes: 70 additions & 0 deletions Tests/PluginCore/PluginCore.Tests/PluginCore.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{F44D3125-12E8-4143-B250-84C5D89D253C}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PluginCore</RootNamespace>
<AssemblyName>PluginCore.Tests</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\..\Bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\..\Bin\Debug\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework">
<HintPath>..\..\..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="PluginCore\Utilities\SemVerTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Settings.Designer.cs">
<DependentUpon>Settings.settings</DependentUpon>
<AutoGen>True</AutoGen>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\PluginCore\PluginCore.csproj">
<Project>{61885F70-B4DC-4B44-852D-5D6D03F2A734}</Project>
<Name>PluginCore</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Loading

0 comments on commit 14a385f

Please sign in to comment.