Exemple #1
0
        public RawShaderNavigationResult AnalyzeAndGoToDefinition(string sourceCode, RawSourceSpan span)
        {
            var rawResult = new RawShaderNavigationResult();

            var navigation = new ShaderNavigation();

            var shaderDirectories = CollectShadersDirectories(null);

            if (span.File != null)
            {
                var dirName = Path.GetDirectoryName(span.File);
                if (dirName != null)
                {
                    shaderDirectories.Add(dirName);
                }
            }

            var resultAnalysis = navigation.AnalyzeAndGoToDefinition(sourceCode, new SiliconStudio.Shaders.Ast.SourceLocation(span.File, 0, span.Line, span.Column), shaderDirectories);

            if (resultAnalysis.DefinitionLocation.Location.FileSource != null)
            {
                rawResult.DefinitionSpan = ConvertToRawLocation(resultAnalysis.DefinitionLocation);
            }

            foreach (var message in resultAnalysis.Messages.Messages)
            {
                rawResult.Messages.Add(ConvertToRawMessage(message));
            }

            return rawResult;
        }
Exemple #2
0
 private static TextSpan ConvertToTextSpan(RawSourceSpan span)
 {
     return(new TextSpan()
     {
         iStartIndex = Math.Max(0, span.Column - 1),
         iStartLine = Math.Max(0, span.Line - 1),
         iEndIndex = Math.Max(0, span.EndColumn - 1),
         iEndLine = Math.Max(0, span.EndLine - 1)
     });
 }
Exemple #3
0
        private void GoToLocation(RawSourceSpan loc, string caption, bool asReadonly)
        {
            // Code taken from Nemerle https://github.com/rsdn/nemerle/blob/master/snippets/VS2010/Nemerle.VisualStudio/LanguageService/NemerleLanguageService.cs#L565
            // TODO: Add licensing
            if (loc == null || loc.File == null)
            {
                return;
            }

            // Opens the document
            var span = new TextSpan {
                iStartLine = loc.Line - 1, iStartIndex = loc.Column - 1, iEndLine = loc.EndLine - 1, iEndIndex = loc.EndColumn - 1
            };
            uint           itemID;
            IVsUIHierarchy hierarchy;
            IVsWindowFrame docFrame;
            IVsTextView    textView;

            VsShell.OpenDocument(Site, loc.File, VSConstants.LOGVIEWID_Code, out hierarchy, out itemID, out docFrame, out textView);

            // If we need readonly, set the buffer to read-only
            if (asReadonly)
            {
                IVsTextLines buffer;
                ErrorHandler.ThrowOnFailure(textView.GetBuffer(out buffer));
                var stream = (IVsTextStream)buffer;
                stream.SetStateFlags((uint)BUFFERSTATEFLAGS.BSF_USER_READONLY);
            }

            // Need to use a different caption?
            if (caption != null)
            {
                ErrorHandler.ThrowOnFailure(docFrame.SetProperty((int)__VSFPROPID.VSFPROPID_OwnerCaption, caption));
            }

            // Show the frame
            ErrorHandler.ThrowOnFailure(docFrame.Show());

            // Go to the specific location
            if (textView != null && loc.Line != 0)
            {
                try
                {
                    ErrorHandler.ThrowOnFailure(textView.SetCaretPos(span.iStartLine, span.iStartIndex));
                    TextSpanHelper.MakePositive(ref span);
                    //ErrorHandler.ThrowOnFailure(textView.SetSelection(span.iStartLine, span.iStartIndex, span.iEndLine, span.iEndIndex));
                    ErrorHandler.ThrowOnFailure(textView.EnsureSpanVisible(span));
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(ex.Message);
                }
            }
        }
Exemple #4
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());
        }
Exemple #5
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 = StrideCommandsProxy.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
            }
        }
 public RawShaderNavigationResult AnalyzeAndGoToDefinition(string sourceCode, RawSourceSpan span)
 {
     // TODO: We need to know which package is currently selected in order to query all valid shaders
     return remote.AnalyzeAndGoToDefinition(sourceCode, span);
 }
        private void GoToLocation(RawSourceSpan loc, string caption, bool asReadonly)
        {
            // Code taken from Nemerle https://github.com/rsdn/nemerle/blob/master/snippets/VS2010/Nemerle.VisualStudio/LanguageService/NemerleLanguageService.cs#L565
            // TODO: Add licensing
            if (loc == null || loc.File == null)
                return;

            // Opens the document
            var span = new TextSpan { iStartLine = loc.Line - 1, iStartIndex = loc.Column - 1, iEndLine = loc.EndLine - 1, iEndIndex = loc.EndColumn - 1 };
            uint itemID;
            IVsUIHierarchy hierarchy;
            IVsWindowFrame docFrame;
            IVsTextView textView;
            VsShell.OpenDocument(Site, loc.File, VSConstants.LOGVIEWID_Code, out hierarchy, out itemID, out docFrame, out textView);

            // If we need readonly, set the buffer to read-only
            if (asReadonly)
            {
                IVsTextLines buffer;
                ErrorHandler.ThrowOnFailure(textView.GetBuffer(out buffer));
                var stream = (IVsTextStream)buffer;
                stream.SetStateFlags((uint)BUFFERSTATEFLAGS.BSF_USER_READONLY);
            }

            // Need to use a different caption?
            if (caption != null)
            {
                ErrorHandler.ThrowOnFailure(docFrame.SetProperty((int)__VSFPROPID.VSFPROPID_OwnerCaption, caption));
            }

            // Show the frame
            ErrorHandler.ThrowOnFailure(docFrame.Show());

            // Go to the specific location
            if (textView != null && loc.Line != 0)
            {
                try
                {
                    ErrorHandler.ThrowOnFailure(textView.SetCaretPos(span.iStartLine, span.iStartIndex));
                    TextSpanHelper.MakePositive(ref span);
                    //ErrorHandler.ThrowOnFailure(textView.SetSelection(span.iStartLine, span.iStartIndex, span.iEndLine, span.iEndIndex));
                    ErrorHandler.ThrowOnFailure(textView.EnsureSpanVisible(span));
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(ex.Message);
                }
            }
        }
 private static TextSpan ConvertToTextSpan(RawSourceSpan span)
 {
     return new TextSpan()
     {
         iStartIndex = Math.Max(0, span.Column-1),
         iStartLine = Math.Max(0, span.Line-1),
         iEndIndex = Math.Max(0, span.EndColumn-1),
         iEndLine = Math.Max(0, span.EndLine-1)
     };
 }
        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();
                var location = new RawSourceSpan()
                {
                    File = this.Source.GetFilePath(),
                    Column = column + 1,
                    Line = line + 1
                };
                var result = remoteCommands.AnalyzeAndGoToDefinition(text, location);

                langService.OutputAnalysisAndGotoLocation(result, TextView);
            }
            catch (Exception)
            {
                // TODO handle errors
            }
        }
 public RawShaderNavigationResult AnalyzeAndGoToDefinition(string projectFile, string text, RawSourceSpan span)
 {
     return(StrideCommandsProxy.GetProxy()?.AnalyzeAndGoToDefinition(projectFile, text, span) ?? new RawShaderNavigationResult());
 }