private void mxmlcRunner_Output(object sender, string line) { PluginBase.RunAsync((MethodInvoker) delegate { if (!notificationSent && line.StartsWith("Done(")) { running = false; TraceManager.Add(line, -2); notificationSent = true; ASContext.SetStatusText(TextHelper.GetString("Info.MxmlcDone")); EventManager.DispatchEvent(this, new TextEvent(EventType.ProcessEnd, line)); if (Regex.IsMatch(line, "Done\\([1-9]")) { EventManager.DispatchEvent(this, new DataEvent(EventType.Command, "ResultsPanel.ShowResults", null)); } else { RunAfterBuild(); } } else { TraceManager.Add(line, 0); } }); }
/// <summary> /// Checks if files is related to the project /// TODO support SWCs -> refactor test as IProject method /// </summary> public static Boolean IsProjectRelatedFile(IProject project, String file) { IASContext context = ASContext.GetLanguageContext(project.Language); if (context == null) { return(false); } foreach (PathModel pathModel in context.Classpath) { string absolute = project.GetAbsolutePath(pathModel.Path); if (file.StartsWith(absolute)) { return(true); } } // If no source paths are defined, is it under the project? if (project.SourcePaths.Length == 0) { String projRoot = Path.GetDirectoryName(project.ProjectPath); if (file.StartsWith(projRoot)) { return(true); } } return(false); }
private void ascRunner_OutputError(object sender, string line) { if (line == null) { return; } PluginBase.RunAsync((MethodInvoker) delegate { if (line.StartsWith("Exception ")) { TraceManager.AddAsync(line, -3); return; } if (silentChecking) { if (SyntaxError != null) { SyntaxError(line); } return; } TraceManager.Add(line, -3); if (!notificationSent) { notificationSent = true; TraceManager.Add("Done(1)", -2); EventManager.DispatchEvent(this, new TextEvent(EventType.ProcessEnd, "Done(1)")); ASContext.SetStatusText(TextHelper.GetString("Info.AscDone")); EventManager.DispatchEvent(this, new DataEvent(EventType.Command, "ResultsPanel.ShowResults", null)); } }); }
/// <summary> /// Gets all files related to the project /// </summary> private static List <String> GetAllProjectRelatedFiles(IProject project) { List <String> files = new List <String>(); string filter = GetSearchPatternFromLang(project.Language.ToLower()); if (string.IsNullOrEmpty(filter)) { return(files); } IASContext context = ASContext.GetLanguageContext(project.Language); if (context == null) { return(files); } foreach (PathModel pathModel in context.Classpath) { string path = pathModel.Path; String absolute = project.GetAbsolutePath(path); if (Directory.Exists(path)) { files.AddRange(Directory.GetFiles(absolute, filter, SearchOption.AllDirectories)); } } // If no source paths are defined, get files directly from project path if (project.SourcePaths.Length == 0) { String projRoot = Path.GetDirectoryName(project.ProjectPath); files.AddRange(Directory.GetFiles(projRoot, filter, SearchOption.AllDirectories)); } return(files); }
internal HashSet <ClassModel> ResolveInterfaces(ClassModel cls) { if (cls == null || cls.IsVoid()) { return(new HashSet <ClassModel>()); } if (cls.Implements == null) { return(ResolveInterfaces(cls.Extends)); } var context = ASContext.GetLanguageContext(PluginBase.CurrentProject.Language); return(cls.Implements .Select(impl => context.ResolveType(impl, cls.InFile)) .Where(interf => interf != null && !interf.IsVoid()) .SelectMany(interf => //take the interfaces we found already and add all interfaces they extend { interf.ResolveExtends(); var set = ResolveExtends(interf); set.Add(interf); return set; }) .Union(ResolveInterfaces(cls.Extends)).ToHashSet()); }
void InitializeClasspaths() { IASContext context = ASContext.GetLanguageContext(PluginBase.CurrentProject.Language); if (context == null) { return; } string projectDir = Path.GetDirectoryName(PluginBase.CurrentProject.ProjectPath); foreach (PathModel classpath in context.Classpath) { if (classpath.IsVirtual) { continue; } string path = classpath.Path; string fullPath = path; if (!Path.IsPathRooted(path)) { fullPath = Path.GetFullPath(path); } if (fullPath.StartsWith(projectDir)) { projectClasspaths.AddRange(GetClasspaths(path, projectDir)); } else { externalClasspaths.AddRange(GetClasspaths(path)); } } }
public void SimpleTest() { //TODO: Improve this test with more checks! var pluginMain = Substitute.For <PluginMain>(); var pluginUiMock = new PluginUIMock(pluginMain); pluginMain.MenuItems.Returns(new List <System.Windows.Forms.ToolStripItem>()); pluginMain.Settings.Returns(new GeneralSettings()); pluginMain.Panel.Returns(pluginUiMock); ASContext.GlobalInit(pluginMain); ASContext.Context = Substitute.For <IASContext>(); ASContext.Context.CurrentLine = 9; var asContext = new AS3Context.Context(new AS3Settings()); ASContext.Context.Features.Returns(asContext.Features); ASContext.Context.GetCodeModel(null).ReturnsForAnyArgs(x => asContext.GetCodeModel(x.ArgAt <string>(0))); // Maybe we want to get the filemodel from ASFileParser even if we won't get a controlled environment? var member = new MemberModel("test1", "void", FlagType.Function, Visibility.Public) { LineFrom = 4, LineTo = 10, Parameters = new List <MemberModel> { new MemberModel("arg1", "String", FlagType.ParameterVar, Visibility.Default), new MemberModel("arg2", "Boolean", FlagType.ParameterVar, Visibility.Default) { Value = "false" } } }; var classModel = new ClassModel(); classModel.Name = "ASCompleteTest"; classModel.Members.Add(member); var fileModel = new FileModel(); fileModel.Classes.Add(classModel); classModel.InFile = fileModel; ASContext.Context.CurrentModel.Returns(fileModel); ASContext.Context.CurrentClass.Returns(classModel); ASContext.Context.CurrentMember.Returns(member); var sci = GetBaseScintillaControl(); sci.Text = TestFile.ReadAllText("ASCompletion.Test_Files.completion.as3.SimpleTest.as"); sci.ConfigurationLanguage = "as3"; sci.Colourise(0, -1); var result = ASComplete.GetExpressionType(sci, 185); Assert.True(result.Context != null && result.Context.LocalVars != null); Assert.AreEqual(4, result.Context.LocalVars.Count); }
public void LintAsync(string[] files, LintCallback callback) { var context = ASContext.GetLanguageContext("haxe") as Context; if (context == null || !CanContinue(context)) { return; } var total = files.Length; var list = new List <LintingResult>(); foreach (var file in files) { ITabbedDocument document; if (!File.Exists(file) || (document = DocumentManager.FindDocument(file)) != null && document.IsUntitled) { total--; continue; } var sciCreated = false; var sci = document?.SciControl; if (sci == null) { sci = GetStubSci(file); sciCreated = true; } var hc = context.GetHaxeComplete(sci, new ASExpr { Position = 0 }, true, HaxeCompilerService.DIAGNOSTICS); fileQueue.Run(finished => { hc.GetDiagnostics((complete, results, status) => { total--; if (sciCreated) { sci.Dispose(); } AddDiagnosticsResults(list, status, results, hc); if (total == 0) { callback(list); } finished(); }); }); } }
static ClassModel GetClassModel(MemberModel cls) { var pos = cls.Type.LastIndexOf('.'); var package = pos == -1 ? "" : cls.Type.Substring(0, pos); var name = cls.Type.Substring(pos + 1); var context = ASContext.GetLanguageContext(PluginBase.CurrentProject.Language); return(context.GetModel(package, name, "")); }
private ProcessingInstruction GenerateFirstCADIndexInstruction(ASContext asContext) { MSProcessorInstruction pi = new MSProcessorInstruction(); pi.DocumentProcessorName = DocumentProcessorName; pi.DocumentProcessorGuid = DocumentProcessorGuid.ToString(); pi.Step = Constants.Steps.KeyInStep; pi.MicroStationMessage = GenerateMicroStationInstructions(asContext); return(pi); }
public void DisambiguateComaSetUp() { var pluginMain = Substitute.For <PluginMain>(); var pluginUiMock = new PluginUIMock(pluginMain); pluginMain.MenuItems.Returns(new List <System.Windows.Forms.ToolStripItem>()); pluginMain.Settings.Returns(new GeneralSettings()); pluginMain.Panel.Returns(pluginUiMock); ASContext.GlobalInit(pluginMain); }
/// <summary> /// Handles the incoming events /// </summary> public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority priority) { switch (e.Type) { case EventType.UIStarted: contextInstance = new Context(settingObject); // Associate this context with a file type ASContext.RegisterLanguage(contextInstance, associatedSyntax); break; } }
public static void SetHaxeFeatures(this IASContext mock) { var context = new HaXeContext.Context(new HaXeContext.HaXeSettings()); ASContext.RegisterLanguage(context, "haxe"); BuildClassPath(context); context.CurrentModel = new FileModel { Context = mock, Version = 4, haXe = true }; SetFeatures(mock, context); }
public static void SetAs3Features(this IASContext mock) { var context = new AS3Context.Context(new AS3Context.AS3Settings()); ASContext.RegisterLanguage(context, "as3"); BuildClassPath(context); context.CurrentModel = new FileModel { Context = mock, Version = 3 }; SetFeatures(mock, context); }
/// <summary> /// Gives the smart dispatcher the sequence of steps needed to index widgets. /// </summary> /// <param name="asContext">Automation Services context object</param> /// <param name="previousPi">The previous step</param> /// <param name="isFirstRequestForProcessingInstructions">First step?</param> /// <returns>The next processing instruction to execute</returns> public override ProcessingInstruction GenerateProcessingInstructions ( ASContext asContext, ProcessingInstruction previousPi, bool isFirstRequestForProcessingInstructions ) { ProcessingInstruction nextPi = GenerateCADProcessingInstructions(asContext, previousPi, isFirstRequestForProcessingInstructions); return(nextPi); }
/// <summary> /// Handles the incoming events /// </summary> public void HandleEvent(Object sender, NotifyEvent e, HandlingPriority priority) { switch (e.Type) { case EventType.UIStarted: contextInstance = new Context(settingObject); ValidateSettings(); // Associate this context with AS2 language ASContext.RegisterLanguage(contextInstance, "as2"); break; } }
public void Setup() { var pluginMain = Substitute.For <ASCompletion.PluginMain>(); var pluginUiMock = new PluginUIMock(pluginMain); pluginMain.MenuItems.Returns(new List <System.Windows.Forms.ToolStripItem>()); pluginMain.Settings.Returns(new GeneralSettings()); pluginMain.Panel.Returns(pluginUiMock); ASContext.GlobalInit(pluginMain); ASContext.Context = Substitute.For <IASContext>(); Sci = GetBaseScintillaControl(); doc.SciControl.Returns(Sci); }
/// <summary> /// Run the Flash IDE with the additional parameters provided /// </summary> /// <param name="parameters"></param> /// <returns>Operation successful</returns> static public bool Run(string pathToIDE, string cmdData) { if (pathToIDE != null && Path.GetExtension(pathToIDE).Length < 3) { pathToIDE = Path.Combine(pathToIDE, "Flash.exe"); } if (pathToIDE == null || !System.IO.File.Exists(pathToIDE)) { string msg = TextHelper.GetString("Info.ConfigureFlashPath"); string title = TextHelper.GetString("Info.ConfigurationRequired"); DialogResult result = MessageBox.Show(msg, title, MessageBoxButtons.OKCancel); if (result == DialogResult.OK) { PluginBase.MainForm.ShowSettingsDialog("ASCompletion", "Flash"); } return(false); } TimeSpan diff = DateTime.Now.Subtract(lastRun); if (diff.Seconds < 1) { return(false); } lastRun = DateTime.Now; string args = null; if (cmdData != null) { args = PluginBase.MainForm.ProcessArgString(cmdData); if (args.IndexOf('"') < 0) { args = '"' + args + '"'; } } // execution ASContext.SetStatusText(TextHelper.GetString("Info.CallingFlashIDE")); PluginBase.MainForm.CallCommand("SaveAllModified", null); EventManager.DispatchEvent(null, new NotifyEvent(EventType.ProcessStart)); if (args != null) { ProcessHelper.StartAsync(pathToIDE, args); } else { ProcessHelper.StartAsync(pathToIDE); } return(true); }
void CreateItemsList() { closedTypes.Clear(); openedTypes.Clear(); TypeToClassModel.Clear(); var context = ASContext.GetLanguageContext(PluginBase.CurrentProject.Language); if (context == null) { return; } var projectFolder = Path.GetDirectoryName(PluginBase.CurrentProject.ProjectPath); var onlyProjectTypes = !searchingInExternalClasspaths.Checked; foreach (var classpath in context.Classpath) { if (onlyProjectTypes) { var path = classpath.Path; if (!Path.IsPathRooted(classpath.Path)) { path = Path.GetFullPath(Path.Combine(projectFolder, classpath.Path)); } if (!path.StartsWith(projectFolder)) { continue; } } classpath.ForeachFile(model => { foreach (var aClass in model.Classes) { var type = aClass.Type; if (TypeToClassModel.ContainsKey(type)) { continue; } if (FormHelper.IsFileOpened(aClass.InFile.FileName)) { openedTypes.Add(type); } else { closedTypes.Add(type); } TypeToClassModel.Add(type, aClass); } return(true); }); } }
/// <summary> /// Checks if the class extends / implements something that does not exist (yet). /// </summary> /// <returns>True if nothing is found, false if there are non-existing parents</returns> /// <param name="cls"></param> bool IsCompletelyResolvable(ClassModel cls) { if (cls == null || cls.IsVoid()) { return(true); } var context = ASContext.GetLanguageContext(PluginBase.CurrentProject.Language); var missingExtends = cls.ExtendsType != "Dynamic" && cls.ExtendsType != "Void" && cls.ExtendsType != null && cls.Extends.IsVoid(); //Dynamic means the class extends nothing var missingInterfaces = cls.Implements != null && cls.Implements.Any(i => GetCachedModel(context.ResolveType(i, cls.InFile)) == null); //also check parent interfaces and extends return(!missingInterfaces && !missingExtends && (cls.Implements == null || ResolveInterfaces(cls).All(IsCompletelyResolvable)) && IsCompletelyResolvable(cls.Extends)); }
public void LintAsync(IEnumerable <string> files, LintCallback callback) { var context = ASContext.GetLanguageContext("haxe") as Context; if (context == null || !(PluginBase.CurrentProject is ProjectManager.Projects.Haxe.HaxeProject) || !CanContinue(context)) { return; } var total = files.Count(); var list = new List <LintingResult>(); String untitledFileStart = TextHelper.GetString("FlashDevelop.Info.UntitledFileStart"); foreach (var file in files) { if (!File.Exists(file) || file.StartsWithOrdinal(untitledFileStart)) { total--; continue; } var sci = GetStubSci(file); var hc = context.GetHaxeComplete(sci, new ASExpr { Position = 0 }, true, HaxeCompilerService.DIAGNOSTICS); fileQueue.Run(finished => { hc.GetDiagnostics((complete, results, status) => { total--; sci.Dispose(); AddDiagnosticsResults(list, status, results, hc); if (total == 0) { callback(list); } finished(); }); }); } }
private void create_Click(object sender, EventArgs e) { string authorizationHeader = null; try { authorizationHeader = this.DetermineAuthorizationHeader(); } catch (OperationCanceledException) { ASContext.SetStatusText(ResourceHelper.GetString("CreateGist.LoginFailedOrCanceled")); return; } var fileName = Path.GetFileName(ASContext.Context.CurrentFile); var content = ASContext.CurSciControl.SelTextSize <= 0 ? ASContext.CurSciControl.Text : ASContext.CurSciControl.SelText; var gist = new Gist { Description = this.description.Text, Public = !this.isPrivate.Checked }.AddFile(fileName, content); try { var location = HttpHelper.Post(PostGistUri, gist, authorizationHeader); if (this.shouldOpen.Checked) { Process.Start(location); } var format = ResourceHelper.GetString("CreateGist.GistSuccessFormat"); ASContext.SetStatusText((string.Format(format, location))); } catch (Exception ex) { ASContext.SetStatusText(ResourceHelper.GetString("CreateGist.GistErrorString")); Debug.WriteLine(ex); } this.SaveSettings(); this.Close(); }
private void CreateItemsList() { projectTypes.Clear(); openedTypes.Clear(); dictionary.Clear(); IASContext context = ASContext.GetLanguageContext(PluginBase.CurrentProject.Language); if (context == null) { return; } foreach (PathModel path in context.Classpath) { path.ForeachFile(FileModelDelegate); } }
public override Command CreateFindAllReferencesCommand(ASResult target, bool output, bool ignoreDeclarations, bool onlySourceFiles) { var context = (Context)ASContext.GetLanguageContext("haxe"); var settings = (HaXeSettings)context.Settings; if ((settings.EnabledFeatures & CompletionFeatures.EnableForFindAllReferences) == CompletionFeatures.EnableForFindAllReferences && settings.CompletionMode != HaxeCompletionModeEnum.FlashDevelop && target.Member != null && ((target.Member.Flags & FlagType.LocalVar) > 0 || (target.Member.Flags & FlagType.ParameterVar) > 0) && context.GetCurrentSDKVersion() >= "3.2.0") { return(new Commands.HaxeFindAllReferences(target, output, ignoreDeclarations) { OnlySourceFiles = onlySourceFiles }); } return(base.CreateFindAllReferencesCommand(target, output, ignoreDeclarations, onlySourceFiles)); }
void OnTimerTick(object sender, EventArgs e) { var context = ASContext.GetLanguageContext(PluginBase.CurrentProject.Language); if (context == null || SelectedNode != null || context.Classpath.Count == openedTypes.Count + closedTypes.Count) { return; } var filesCount = context.Classpath.Sum(it => it.FilesCount); if (filesCount == this.filesCount) { return; } this.filesCount = filesCount; CreateItemsList(); RefreshTree(); }
private void baseBrowse_Click(object sender, EventArgs e) { ClassBrowser browser = new ClassBrowser(); IASContext context = ASContext.GetLanguageContext(PluginBase.CurrentProject.Language); try { browser.ClassList = context.GetAllProjectClasses(); } catch { } browser.ExcludeFlag = FlagType.Interface; browser.IncludeFlag = FlagType.Class; if (browser.ShowDialog(this) == DialogResult.OK) { this.baseBox.Text = browser.SelectedClass; } this.okButton.Focus(); }
/// <summary> /// Update the cache for the whole project /// </summary> public void UpdateCompleteCache() { var action = new Action(() => { try { var context = ASContext.GetLanguageContext(PluginBase.CurrentProject.Language); if (context == null || context.Classpath == null || PathExplorer.IsWorking) { if (FinishedUpdate != null) { PluginBase.RunAsync(new MethodInvoker(FinishedUpdate)); } return; } var c = new Dictionary <ClassModel, CachedClassModel>(cache.Comparer); foreach (MemberModel memberModel in context.GetAllProjectClasses()) { if (PluginBase.MainForm.ClosingEntirely) { return; //make sure we leave if the form is closing, so we do not block it } var cls = GetClassModel(memberModel); UpdateClass(cls, c); } lock (cache) cache = c; if (FinishedUpdate != null) { PluginBase.RunAsync(new MethodInvoker(FinishedUpdate)); } } catch (Exception) { } }); action.BeginInvoke(null, null); }
private void onTimedDelete(object source, ElapsedEventArgs e) { Control ctrl = mainForm.CurDocument as Control; if (ctrl != null && ctrl.InvokeRequired) { ctrl.BeginInvoke(new ElapsedEventHandler(onTimedDelete), new object[] { source, e }); } else { if (File.Exists(fullWatchedPath)) { File.Delete(fullWatchedPath); mainForm.AddTraceLogEntry("Done(0)", -2); mainForm.DispatchEvent(new NotifyEvent(EventType.ProcessEnd)); ASContext.SetStatusText("Asc Done"); } } }
public void CheckAS3(string filename) { if (flex2Shell == null) { UpdateSettings(); } if (!sdkOk) { ErrorHandler.ShowInfo("Set the path to the Flex 2 SDK in the program settings."); return; } if (!File.Exists(filename)) { return; } mainForm.CallCommand("Save", null); try { mainForm.DispatchEvent(new NotifyEvent(EventType.ProcessStart)); if (ascRunner == null || !ascRunner.isRunning) { StartAscRunner(); } mainForm.AddTraceLogEntry("AscShell command: " + filename, -1); StringBuilder sb = new StringBuilder(filename.Length); GetShortPathName(filename, sb, (uint)filename.Length); string shortname = sb.ToString().Replace(".AS", ".as"); WatchFile(shortname); //filename); ASContext.SetStatusText("Asc Running"); notificationSent = false; ascRunner.process.StandardInput.WriteLine("clear"); ascRunner.process.StandardInput.WriteLine("asc -p " + shortname); } catch (Exception ex) { ErrorHandler.ShowError("Error while running the AS3 syntax checking.", ex); } }
private void onTimedDelete(object source, ElapsedEventArgs e) { Control ctrl = PluginBase.MainForm.CurrentDocument as Control; if (ctrl != null && ctrl.InvokeRequired) { ctrl.BeginInvoke(new ElapsedEventHandler(onTimedDelete), new object[] { source, e }); } else { if (File.Exists(fullWatchedPath)) { File.Delete(fullWatchedPath); TraceManager.Add("Done(0)", -2); EventManager.DispatchEvent(this, new TextEvent(EventType.ProcessEnd, "Done(0)")); ASContext.SetStatusText("Asc Done"); } } }