static public string GetActiveConfigurationName()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            string solutionPath = EditorUtils.GetSolutionPath();

            if (solutionPath == null || solutionPath.Length == 0)
            {
                return(null);
            }

            string activeConfigFilename = solutionPath + @".vs\ProjectSettings.json";

            if (File.Exists(activeConfigFilename))
            {
                var activeConfig = new CMakeActiveConfiguration();

                try
                {
                    string jsonString = File.ReadAllText(activeConfigFilename);
                    activeConfig = JsonConvert.DeserializeObject <CMakeActiveConfiguration>(jsonString);
                }
                catch (Exception e)
                {
                    OutputLog.Error(e.Message);
                }

                if (activeConfig != null)
                {
                    return(activeConfig.CurrentProjectSetting);
                }
            }

            return(null);
        }
        public async System.Threading.Tasks.Task ParseAtCurrentLocationAsync()
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            OutputLog.Clear();

            EditorUtils.SaveActiveDocument();

            DocumentLocation location = GetCurrentLocation();

            if (location == null)
            {
                string msg = "Unable to retrieve current document position.";
                OutputLog.Error(msg);
                ParseMessageWindow.Display(new ParseMessageContent(msg));
            }

            ProjectProperties properties = GetProjectData();

            if (properties == null)
            {
                string msg = "Unable to retrieve the project configuration";
                OutputLog.Error(msg);
                ParseMessageWindow.Display(new ParseMessageContent(msg));
                return;
            }

            GeneralSettingsPageGrid settings = EditorUtils.GetGeneralSettings();

            parser.PrintCommandLine = settings.OptionParserShowCommandLine;

            //TODO ~ ramonv ~ add parsing queue to avoid multiple queries at the same time

            LayoutWindow prewin = EditorUtils.GetLayoutWindow(false);

            if (prewin != null)
            {
                prewin.SetProcessing();
            }

            ParseResult result = await parser.ParseAsync(properties, location);

            //Only create or focus the window if we have a valid result
            LayoutWindow win = EditorUtils.GetLayoutWindow(result.Status == ParseResult.StatusCode.Found);

            if (win != null)
            {
                win.SetResult(result);

                if (result.Status == ParseResult.StatusCode.Found)
                {
                    EditorUtils.FocusWindow(win);
                }
            }

            DisplayResult(result);
        }
        private void Load()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (Filename != null && File.Exists(Filename))
            {
                try
                {
                    string jsonString = File.ReadAllText(Filename);
                    Settings = JsonConvert.DeserializeObject <SolutionSettings>(jsonString);
                }
                catch (Exception e)
                {
                    OutputLog.Error(e.Message);
                }
            }
        }
        public void Save()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            TryRefreshFilename();

            if (Filename != null && Settings != null)
            {
                try
                {
                    string jsonString = JsonConvert.SerializeObject(Settings, Formatting.Indented);
                    File.WriteAllText(Filename, jsonString);
                }
                catch (Exception e)
                {
                    OutputLog.Error(e.Message);
                }
            }
        }
        private CMakeConfiguration GetActiveConfiguration()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            string solutionPath = EditorUtils.GetSolutionPath();

            if (solutionPath == null || solutionPath.Length == 0)
            {
                return(null);
            }

            string settingsFilename = solutionPath + "CMakeSettings.json";

            if (File.Exists(settingsFilename))
            {
                CMakeSettings settings = null;

                try
                {
                    string jsonString = File.ReadAllText(settingsFilename);
                    settings = JsonConvert.DeserializeObject <CMakeSettings>(jsonString);
                }
                catch (Exception e)
                {
                    OutputLog.Error(e.Message);
                }

                string activeConfigName = GetActiveConfigurationName();
                if (activeConfigName != null && activeConfigName.Length > 0 && settings != null && settings.configurations != null)
                {
                    foreach (CMakeConfiguration config in settings.configurations)
                    {
                        if (config.name == activeConfigName)
                        {
                            return(config);
                        }
                    }
                }
            }

            return(null);
        }
        private ProjectProperties CaptureCMakeCommands(string commandsFile, string documentName)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var ret = new ProjectProperties();

            if (commandsFile == null || commandsFile.Length == 0)
            {
                OutputLog.Log("Unable to retrieve a CMake commands file.\nMake sure the cmake flag -DCMAKE_EXPORT_COMPILE_COMMANDS=1 is set and the options are pointing to the proper file.");
            }
            else
            {
                if (File.Exists(commandsFile))
                {
                    OutputLog.Log("Capturing commands from CMake commands file: " + commandsFile);

                    List <CMakeCommandEntry> allCommands = null;
                    try
                    {
                        string jsonString = File.ReadAllText(commandsFile);
                        allCommands = JsonConvert.DeserializeObject <List <CMakeCommandEntry> >(jsonString);
                    }
                    catch (Exception e)
                    {
                        OutputLog.Error(e.Message);
                    }

                    ExtractCMakeProjectProperties(ret, FindBestCMakeEntry(allCommands, documentName));
                }
                else
                {
                    OutputLog.Log("Unable to find CMake commands file at " + commandsFile + ".\nMake sure the cmake flag -DCMAKE_EXPORT_COMPILE_COMMANDS=1 is set and the options are pointing to the proper file.");
                }
            }

            return(ret);
        }
示例#7
0
        public async Task <ParseResult> ParseAsync(ProjectProperties projProperties, DocumentLocation location)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            ParseResult ret = new ParseResult();

            if (location.Filename == null || location.Filename.Length == 0)
            {
                OutputLog.Error("No file provided for parsing");
                ret.Status = ParseResult.StatusCode.InvalidInput;
                return(ret);
            }

            AdjustPaths(projProperties.IncludeDirectories);
            AdjustPaths(projProperties.ForceIncludes);

            string includes = GenerateCommandStr("-I", projProperties.IncludeDirectories);
            string forceInc = GenerateCommandStr("-include", projProperties.ForceIncludes);
            string defines  = GenerateCommandStr("-D", projProperties.PrepocessorDefinitions);
            string workDir  = projProperties.WorkingDirectory.Length == 0 ? "" : " -working-directory=" + AdjustPath(projProperties.WorkingDirectory);
            string flags    = projProperties.ShowWarnings? "" : " -w";
            string extra    = projProperties.ExtraArguments.Length == 0? "" : " " + projProperties.ExtraArguments;

            string standard = GetStandardFlag(projProperties.Standard);
            string archStr  = projProperties != null && projProperties.Target == ProjectProperties.TargetType.x86 ? "-m32" : "-m64";

            string toolCmd = AdjustPath(location.Filename) + " -- -x c++ " + archStr + standard + flags + defines + includes + forceInc + workDir + extra;

            OutputLog.Focus();
            OutputLog.Log("Looking for structures at " + location.Filename + ":" + location.Line + ":" + location.Column + "...");

            if (PrintCommandLine)
            {
                OutputLog.Log("COMMAND LINE: " + toolCmd);
            }

            Log = "";

            var watch = System.Diagnostics.Stopwatch.StartNew();

            var valid = false;

            valid = await System.Threading.Tasks.Task.Run(() => LayoutParser_ParseLocation(toolCmd, location.Filename, location.Line, location.Column));

            watch.Stop();
            const long TicksPerMicrosecond = (TimeSpan.TicksPerMillisecond / 1000);
            string     timeStr             = " (" + GetTimeStr((ulong)(watch.ElapsedTicks / TicksPerMicrosecond)) + ")";

            if (Log.Length > 0)
            {
                OutputLog.Log("Execution Log:\n" + Log);
                ret.ParserLog = Log;
                Log           = "";
            }

            if (valid)
            {
                //capture data
                uint   size   = 0;
                IntPtr result = LayoutParser_GetData(ref size);

                if (size > 0)
                {
                    byte[] managedArray = new byte[size];
                    Marshal.Copy(result, managedArray, 0, (int)size);

                    using (BinaryReader reader = new BinaryReader(new MemoryStream(managedArray)))
                    {
                        ret.Layout = ReadNode(reader);
                        FinalizeNode(ret.Layout);
                    }

                    OutputLog.Log("Found structure " + ret.Layout.Type + "." + timeStr);
                    ret.Status = ParseResult.StatusCode.Found;
                }
                else
                {
                    OutputLog.Log("No structure found at the given location." + timeStr);
                    ret.Status = ParseResult.StatusCode.NotFound;
                }
            }
            else
            {
                OutputLog.Error("Unable to scan the given location." + timeStr);
                ret.Status = ParseResult.StatusCode.ParseFailed;
            }

            LayoutParser_Clear();

            return(ret);
        }