Beispiel #1
0
        private static async void OpenWithGameStudioMenuCommand_Callback(object sender, EventArgs e)
        {
            var dte = (DTE2)ServiceProvider.GetService(typeof(SDTE));

            var solutionFile = dte.Solution?.FileName;

            // Is there any active solution?
            if (solutionFile == null)
            {
                return;
            }

            // Locate GameStudio
            var packageInfo = await XenkoCommandsProxy.FindXenkoSdkDir(solutionFile, "Xenko.GameStudio");

            if (packageInfo.LoadedVersion == null || packageInfo.SdkPaths.Count == 0)
            {
                return;
            }

            var mainExecutable = packageInfo.SdkPaths.First(x => Path.GetFileName(x) == "Xenko.GameStudio.exe");

            if (mainExecutable == null)
            {
                throw new InvalidOperationException("Could not locate GameStudio process");
            }
            if (Process.Start(mainExecutable, $"\"{solutionFile}\"") == null)
            {
                throw new InvalidOperationException("Could not start GameStudio process");
            }
        }
Beispiel #2
0
        public RawShaderNavigationResult AnalyzeAndGoToDefinition(string text, RawSourceSpan span)
        {
            // Try to locate containing project
            var    dte         = (DTE)GetService(typeof(DTE));
            var    projectItem = dte.Solution.FindProjectItem(span.File);
            string projectFile = null;

            if (projectItem != null && projectItem.ContainingProject != null && !string.IsNullOrEmpty(projectItem.ContainingProject.FileName))
            {
                projectFile = projectItem.ContainingProject.FileName;
            }
            return(XenkoCommandsProxy.GetProxy()?.AnalyzeAndGoToDefinition(projectFile, text, span) ?? new RawShaderNavigationResult());
        }
Beispiel #3
0
        protected override byte[] GenerateCode(string inputFileName, string inputFileContent)
        {
            try
            {
                var remoteCommands = XenkoCommandsProxy.GetProxy();
                return(remoteCommands.GenerateShaderKeys(inputFileName, inputFileContent));
            }
            catch (Exception ex)
            {
                GeneratorError(4, ex.ToString(), 0, 0);

                return(new byte[0]);
            }
        }
Beispiel #4
0
        protected override byte[] GenerateCode(string inputFileName, string inputFileContent)
        {
            try
            {
                return(System.Threading.Tasks.Task.Run(() =>
                {
                    var remoteCommands = XenkoCommandsProxy.GetProxy();
                    return remoteCommands.GenerateShaderKeys(inputFileName, inputFileContent);
                }).Result);
            }
            catch (Exception ex)
            {
                GeneratorError(4, ex.ToString(), 0, 0);

                return(new byte[0]);
            }
        }
Beispiel #5
0
        public override void OnIdle(bool periodic)
        {
            var source = GetCurrentNShaderSource();

            if (source != null)
            {
                if (lastChangeCount != source.ChangeCount)
                {
                    clock.Restart();
                    lastChangeCount = source.ChangeCount;
                }

                if (clock.IsRunning)
                {
                    if (clock.ElapsedMilliseconds > TriggerParsingDelayInMs)
                    {
                        clock.Stop();
                        clock.Reset();

                        var text       = source.GetText();
                        var sourcePath = source.GetFilePath();

                        Trace.WriteLine(string.Format("Parsing Change: {0} Time: {1}", source.ChangeCount, DateTime.Now));
                        var thread = new System.Threading.Thread(
                            () =>
                        {
                            try
                            {
                                var result = XenkoCommandsProxy.GetProxy().AnalyzeAndGoToDefinition(text, new RawSourceSpan(sourcePath, 1, 1));
                                OutputAnalysisMessages(result, source);
                            }
                            catch (Exception ex)
                            {
                                lock (errorListProvider)
                                {
                                    errorListProvider.Tasks.Add(new ErrorTask(ex.InnerException ?? ex));
                                }
                            }
                        });
                        thread.Start();
                    }
                }
            }

            base.OnIdle(periodic);
        }
Beispiel #6
0
        private void AnalyzeAndGoToDefinition()
        {
            int line;
            int column;

            TextView.GetCaretPos(out line, out column);

            IVsTextLines buffer;

            TextView.GetBuffer(out buffer);

            var span = new TextSpan();

            buffer.GetLastLineIndex(out span.iEndLine, out span.iEndIndex);

            string text;

            buffer.GetLineText(span.iStartLine, span.iStartIndex, span.iEndLine, span.iEndIndex, out text);

            try
            {
                var remoteCommands = XenkoCommandsProxy.GetProxy();
                if (remoteCommands == null)
                {
                    return;
                }
                var location = new RawSourceSpan()
                {
                    File   = this.Source.GetFilePath(),
                    Column = column + 1,
                    Line   = line + 1
                };
                var projectFile = langService.LocateProject(location.File);
                var result      = langService.AnalyzeAndGoToDefinition(projectFile, text, location);
                langService.OutputAnalysisAndGotoLocation(result, TextView);
            }
            catch (Exception)
            {
                // TODO handle errors
            }
        }
Beispiel #7
0
        private async System.Threading.Tasks.Task InitializeCommandProxy()
        {
            // Initialize the command proxy from the current solution's package
            var dte          = (DTE)GetService(typeof(DTE));
            var solutionPath = dte.Solution.FullName;

            var xenkoPackageInfo = await XenkoCommandsProxy.FindXenkoSdkDir(solutionPath);

            if (xenkoPackageInfo.LoadedVersion == null)
            {
                return;
            }
            XenkoCommandsProxy.InitializeFromSolution(solutionPath, xenkoPackageInfo);

            // Get General Output pane (for error logging)
            var generalOutputPane = GetGeneralOutputPane();

            // Enable UIContext depending on wheter it is a Xenko project. This will show or hide Xenko menus.
            var isXenkoSolution = xenkoPackageInfo.LoadedVersion != null;

            UpdateCommandVisibilityContext(isXenkoSolution);

            // If a package is associated with the solution, check if the correct version was found
            if (xenkoPackageInfo.ExpectedVersion != null && xenkoPackageInfo.ExpectedVersion != xenkoPackageInfo.LoadedVersion)
            {
                if (xenkoPackageInfo.ExpectedVersion < XenkoCommandsProxy.MinimumVersion)
                {
                    // The package version is deprecated
                    generalOutputPane.OutputStringThreadSafe($"Could not initialize Xenko extension for package with version {xenkoPackageInfo.ExpectedVersion}. Versions earlier than {XenkoCommandsProxy.MinimumVersion} are not supported. Loading latest version {xenkoPackageInfo.LoadedVersion} instead.\r\n");
                    generalOutputPane.Activate();
                }
                else if (xenkoPackageInfo.LoadedVersion == null)
                {
                    // No version found
                    generalOutputPane.OutputStringThreadSafe("Could not find Xenko SDK directory.");
                    generalOutputPane.Activate();

                    // Don't try to create any services
                    return;
                }
                else
                {
                    // The package version was not found
                    generalOutputPane.OutputStringThreadSafe($"Could not find SDK directory for Xenko version {xenkoPackageInfo.ExpectedVersion}. Loading latest version {xenkoPackageInfo.LoadedVersion} instead.\r\n");
                    generalOutputPane.Activate();
                }
            }

            // Initialize the build monitor, that will display BuildEngine results in the Build Output pane.
            buildLogPipeGenerator = new BuildLogPipeGenerator(this);

            try
            {
                // Start PackageBuildMonitorRemote in a separate app domain
                if (buildMonitorDomain != null)
                {
                    AppDomain.Unload(buildMonitorDomain);
                }

                buildMonitorDomain = XenkoCommandsProxy.CreateXenkoDomain();
                XenkoCommandsProxy.InitializeFromSolution(solutionPath, xenkoPackageInfo, buildMonitorDomain);
                var remoteCommands = XenkoCommandsProxy.CreateProxy(buildMonitorDomain);
                remoteCommands.StartRemoteBuildLogServer(new BuildMonitorCallback(), buildLogPipeGenerator.LogPipeUrl);
            }
            catch (Exception e)
            {
                generalOutputPane.OutputStringThreadSafe($"Error loading Xenko SDK: {e}\r\n");
                generalOutputPane.Activate();

                // Unload domain right away
                AppDomain.Unload(buildMonitorDomain);
                buildMonitorDomain = null;
            }

            // Preinitialize the parser in a separate thread
            var thread = new System.Threading.Thread(
                () =>
            {
                try
                {
                    XenkoCommandsProxy.GetProxy();
                }
                catch (Exception ex)
                {
                    generalOutputPane.OutputStringThreadSafe($"Error Initializing Xenko Language Service: {ex.InnerException ?? ex}\r\n");
                    generalOutputPane.Activate();
                    errorListProvider.Tasks.Add(new ErrorTask(ex.InnerException ?? ex));
                }
            });

            thread.Start();
        }
Beispiel #8
0
        private void InitializeCommandProxy()
        {
            // Initialize the command proxy from the current solution's package
            var dte          = (DTE)GetService(typeof(DTE));
            var solutionPath = dte.Solution.FullName;

            XenkoCommandsProxy.InitialzeFromSolution(solutionPath);

            // Get General Output pane (for error logging)
            var generalOutputPane = GetGeneralOutputPane();

            // If a package is associated with the solution, check if the correct version was found
            var xenkoPackageInfo = XenkoCommandsProxy.CurrentPackageInfo;

            if (xenkoPackageInfo.ExpectedVersion != null && xenkoPackageInfo.ExpectedVersion != xenkoPackageInfo.LoadedVersion)
            {
                if (xenkoPackageInfo.ExpectedVersion < XenkoCommandsProxy.MinimumVersion)
                {
                    // The package version is deprecated
                    generalOutputPane.OutputStringThreadSafe(string.Format("Could not initialize Xenko extension for package with version {0}. Versions earlier than {1} are not supported. Loading latest version {2} instead.\r\n", xenkoPackageInfo.ExpectedVersion, XenkoCommandsProxy.MinimumVersion, xenkoPackageInfo.LoadedVersion));
                    generalOutputPane.Activate();
                }
                else if (xenkoPackageInfo.LoadedVersion == null)
                {
                    // No version found
                    generalOutputPane.OutputStringThreadSafe("Could not find Xenko SDK directory.");
                    generalOutputPane.Activate();
                }
                else
                {
                    // The package version was not found
                    generalOutputPane.OutputStringThreadSafe(string.Format("Could not find SDK directory for Xenko version {0}. Loading latest version {1} instead.\r\n", xenkoPackageInfo.ExpectedVersion, xenkoPackageInfo.LoadedVersion));
                    generalOutputPane.Activate();
                }
            }

            // Initialize the build monitor, that will display BuildEngine results in the Build Output pane.
            // Seems like VS2015 display <Exec> output directly without waiting end of execution, so no need for all this anymore!
            // TODO: Need to find a better way to detect VS version?
            int visualStudioVersion;

            if (!int.TryParse(dte2.Version.Split('.')[0], out visualStudioVersion))
            {
                visualStudioVersion = 12;
            }

            if (visualStudioVersion < 14)
            {
                buildLogPipeGenerator = new BuildLogPipeGenerator(this);

                try
                {
                    // Start PackageBuildMonitorRemote in a separate app domain
                    if (buildMonitorDomain != null)
                    {
                        AppDomain.Unload(buildMonitorDomain);
                    }

                    buildMonitorDomain = XenkoCommandsProxy.CreateXenkoDomain();
                    XenkoCommandsProxy.InitialzeFromSolution(solutionPath, buildMonitorDomain);
                    var remoteCommands = XenkoCommandsProxy.CreateProxy(buildMonitorDomain);
                    remoteCommands.StartRemoteBuildLogServer(new BuildMonitorCallback(), buildLogPipeGenerator.LogPipeUrl);
                }
                catch (Exception e)
                {
                    generalOutputPane.OutputStringThreadSafe(string.Format("Error loading Xenko SDK: {0}\r\n", e));
                    generalOutputPane.Activate();

                    // Unload domain right away
                    AppDomain.Unload(buildMonitorDomain);
                    buildMonitorDomain = null;
                }
            }

            // Preinitialize the parser in a separate thread
            var thread = new System.Threading.Thread(
                () =>
            {
                try
                {
                    XenkoCommandsProxy.GetProxy();
                }
                catch (Exception ex)
                {
                    generalOutputPane.OutputStringThreadSafe(string.Format("Error Initializing Xenko Language Service: {0}\r\n", ex.InnerException ?? ex));
                    generalOutputPane.Activate();
                    errorListProvider.Tasks.Add(new ErrorTask(ex.InnerException ?? ex));
                }
            });

            thread.Start();
        }
 public RawShaderNavigationResult AnalyzeAndGoToDefinition(string projectFile, string text, RawSourceSpan span)
 {
     return(XenkoCommandsProxy.GetProxy()?.AnalyzeAndGoToDefinition(projectFile, text, span) ?? new RawShaderNavigationResult());
 }