Пример #1
0
        public int GetMemberNavigationPoint(string pszClassName, string pszUniqueMemberID, TextSpan[] pSpanNavPoint, out uint pItemID)
        {
            uint     itemId    = 0;
            TextSpan textSpan  = default(TextSpan);
            var      succeeded = false;

            var waitIndicator = this.ComponentModel.GetService <IWaitIndicator>();

            waitIndicator.Wait(
                "Intellisense",
                allowCancel: false,
                action: c =>
            {
                Document targetDocument;
                if (ContainedLanguageCodeSupport.TryGetMemberNavigationPoint(GetThisDocument(), pszClassName, pszUniqueMemberID, out textSpan, out targetDocument, c.CancellationToken))
                {
                    succeeded = true;
                    itemId    = this.ContainedDocument.FindItemIdOfDocument(targetDocument);
                }
            });

            pItemID          = itemId;
            pSpanNavPoint[0] = textSpan;
            return(succeeded ? VSConstants.S_OK : VSConstants.E_FAIL);
        }
Пример #2
0
        private DiagnosticData CreateDocumentDiagnosticItem(ExternalError error)
        {
            var hostProject = _workspace.GetHostProject(_projectId);

            if (!hostProject.ContainsFile(error.bstrFileName))
            {
                return(null);
            }

            var hostDocument = hostProject.GetCurrentDocumentFromPath(error.bstrFileName);

            var line   = error.iLine;
            var column = error.iCol;

            if (hostDocument is ContainedDocument containedDocument)
            {
                var span = new VsTextSpan
                {
                    iStartLine  = line,
                    iStartIndex = column,
                    iEndLine    = line,
                    iEndIndex   = column,
                };

                var spans = new VsTextSpan[1];
                Marshal.ThrowExceptionForHR(containedDocument.ContainedLanguage.BufferCoordinator.MapPrimaryToSecondarySpan(
                                                span,
                                                spans));

                line   = spans[0].iStartLine;
                column = spans[0].iStartIndex;
            }

            return(GetDiagnosticData(error, hostDocument.Id, line, column));
        }
        private bool NavigateTo(ITextBuffer textBuffer, VsTextSpan vsTextSpan)
        {
            using (Logger.LogBlock(FunctionId.NavigationService_VSDocumentNavigationService_NavigateTo, CancellationToken.None))
            {
                var vsTextBuffer = _editorAdaptersFactoryService.GetBufferAdapter(textBuffer);
                if (vsTextBuffer == null)
                {
                    Debug.Fail("Could not get IVsTextBuffer for document!");
                    return false;
                }

                var textManager = (IVsTextManager2)_serviceProvider.GetService(typeof(SVsTextManager));
                if (textManager == null)
                {
                    Debug.Fail("Could not get IVsTextManager service!");
                    return false;
                }

                return ErrorHandler.Succeeded(
                    textManager.NavigateToLineAndColumn2(
                        vsTextBuffer,
                        VSConstants.LOGVIEWID.TextView_guid,
                        vsTextSpan.iStartLine,
                        vsTextSpan.iStartIndex,
                        vsTextSpan.iEndLine,
                        vsTextSpan.iEndIndex,
                        (uint)_VIEWFRAMETYPE.vftCodeWindow));
            }
        }
Пример #4
0
        /// <returns>The tracking span of the inserted "/**/" if there is an $end$ location, null
        /// otherwise.</returns>
        protected override ITrackingSpan InsertEmptyCommentAndGetEndPositionTrackingSpan()
        {
            VsTextSpan[] endSpanInSurfaceBuffer = new VsTextSpan[1];
            if (ExpansionSession.GetEndSpan(endSpanInSurfaceBuffer) != VSConstants.S_OK)
            {
                return(null);
            }

            SnapshotSpan subjectBufferEndSpan;

            if (!TryGetSubjectBufferSpan(endSpanInSurfaceBuffer[0], out subjectBufferEndSpan))
            {
                return(null);
            }

            var endPosition = subjectBufferEndSpan.Start.Position;

            string commentString = "/**/";

            SubjectBuffer.Insert(endPosition, commentString);

            var commentSpan = new Span(endPosition, commentString.Length);

            return(SubjectBuffer.CurrentSnapshot.CreateTrackingSpan(commentSpan, SpanTrackingMode.EdgeExclusive));
        }
        public virtual bool TryInsertExpansion(int startPositionInSubjectBuffer, int endPositionInSubjectBuffer)
        {
            int startLine  = 0;
            int startIndex = 0;
            int endLine    = 0;
            int endIndex   = 0;

            // The expansion itself needs to be created in the surface buffer, so map everything up
            var startPointInSubjectBuffer = SubjectBuffer.CurrentSnapshot.GetPoint(startPositionInSubjectBuffer);
            var endPointInSubjectBuffer   = SubjectBuffer.CurrentSnapshot.GetPoint(endPositionInSubjectBuffer);

            SnapshotSpan surfaceBufferSpan;

            if (!TryGetSurfaceBufferSpan(SubjectBuffer.CurrentSnapshot.GetSpan(startPositionInSubjectBuffer, endPositionInSubjectBuffer - startPositionInSubjectBuffer), out surfaceBufferSpan))
            {
                return(false);
            }

            var buffer = EditorAdaptersFactoryService.GetBufferAdapter(TextView.TextBuffer);

            buffer.GetLineIndexOfPosition(surfaceBufferSpan.Start.Position, out startLine, out startIndex);
            buffer.GetLineIndexOfPosition(surfaceBufferSpan.End.Position, out endLine, out endIndex);

            var textSpan = new VsTextSpan
            {
                iStartLine  = startLine,
                iStartIndex = startIndex,
                iEndLine    = endLine,
                iEndIndex   = endIndex
            };

            var expansion = buffer as IVsExpansion;

            return(expansion.InsertExpansion(textSpan, textSpan, this, LanguageServiceGuid, out ExpansionSession) == VSConstants.S_OK);
        }
        public static bool TryGetMemberNavigationPoint(
            Document thisDocument,
            string className,
            string uniqueMemberID,
            out VsTextSpan textSpan,
            out Document targetDocument,
            CancellationToken cancellationToken)
        {
            targetDocument = null;
            textSpan       = default(VsTextSpan);

            var type   = thisDocument.Project.GetCompilationAsync(cancellationToken).WaitAndGetResult_Venus(cancellationToken).GetTypeByMetadataName(className);
            var member = LookupMemberId(type, uniqueMemberID);

            if (member == null)
            {
                return(false);
            }

            var codeModel  = thisDocument.Project.LanguageServices.GetService <ICodeModelNavigationPointService>();
            var memberNode = member.DeclaringSyntaxReferences.Select(r => r.GetSyntax(cancellationToken)).FirstOrDefault();

            if (memberNode != null)
            {
                var navigationPoint = codeModel.GetStartPoint(memberNode, EnvDTE.vsCMPart.vsCMPartNavigate);
                if (navigationPoint != null)
                {
                    targetDocument = thisDocument.Project.Solution.GetDocument(memberNode.SyntaxTree);
                    textSpan       = navigationPoint.Value.ToVsTextSpan();
                    return(true);
                }
            }

            return(false);
        }
Пример #7
0
        public bool WouldNotifyToSpecificSymbol(ISymbol symbol, Solution solution, out string filePath, out int lineNumber, out int charOffset)
        {
            AssertIsForeground();

            filePath   = null;
            lineNumber = 0;
            charOffset = 0;
            if (!TryGetNavigationAPIRequiredArguments(symbol, solution, out var hierarchy, out var itemID, out var navigationNotify, out var rqname))
            {
                return(false);
            }

            var navigateToTextSpan = new Microsoft.VisualStudio.TextManager.Interop.TextSpan[1];

            int queryNavigateStatusCode = navigationNotify.QueryNavigateToSymbol(
                hierarchy,
                itemID,
                rqname,
                out var navigateToHierarchy,
                out var navigateToItem,
                navigateToTextSpan,
                out var wouldNavigate);

            if (queryNavigateStatusCode == VSConstants.S_OK && wouldNavigate == 1)
            {
                navigateToHierarchy.GetCanonicalName(navigateToItem, out filePath);
                lineNumber = navigateToTextSpan[0].iStartLine;
                charOffset = navigateToTextSpan[0].iStartIndex;
                return(true);
            }

            return(false);
        }
        public bool WouldNotifyToSpecificSymbol(
            DefinitionItem definitionItem,
            string?rqName,
            CancellationToken cancellationToken,
            [NotNullWhen(true)] out string?filePath,
            out int lineNumber,
            out int charOffset
            )
        {
            AssertIsForeground();

            filePath   = null;
            lineNumber = 0;
            charOffset = 0;

            if (rqName == null)
            {
                return(false);
            }

            if (
                !TryGetNavigationAPIRequiredArguments(
                    definitionItem,
                    rqName,
                    cancellationToken,
                    out var hierarchy,
                    out var itemID,
                    out var navigationNotify
                    )
                )
            {
                return(false);
            }

            var navigateToTextSpan = new Microsoft.VisualStudio.TextManager.Interop.TextSpan[1];

            var queryNavigateStatusCode = navigationNotify.QueryNavigateToSymbol(
                hierarchy,
                itemID,
                rqName,
                out var navigateToHierarchy,
                out var navigateToItem,
                navigateToTextSpan,
                out var wouldNavigate
                );

            if (queryNavigateStatusCode == VSConstants.S_OK && wouldNavigate == 1)
            {
                navigateToHierarchy.GetCanonicalName(navigateToItem, out filePath);
                lineNumber = navigateToTextSpan[0].iStartLine;
                charOffset = navigateToTextSpan[0].iStartIndex;
                return(true);
            }

            return(false);
        }
        public int ValidateBreakpointLocation(IVsTextBuffer pBuffer, int iLine, int iCol, TextSpan[] pCodeSpan)
        {
            var textBuffer = _editorAdaptersFactory.GetDataBuffer(pBuffer);

            if (textBuffer == null)
            {
                // Can't resolve the text buffer, let someone else deal with this breakpoint.
                return(VSConstants.E_NOTIMPL);
            }

            var snapshot = textBuffer.CurrentSnapshot;

            if (!ValidBreakpointLocation(snapshot, iLine, iCol))
            {
                // The point disappeared between sessions. Do not allow a breakpoint here.
                return(VSConstants.E_FAIL);
            }

            var dialogResult = _waitDialogFactory.TryCreateWaitDialog(
                title: "Determining breakpoint location...",
                message: "Razor Debugger",
                async(context) =>
            {
                var breakpointRange = await _breakpointResolver.TryResolveBreakpointRangeAsync(textBuffer, iLine, iCol, context.CancellationToken);
                if (breakpointRange == null)
                {
                    // No applicable breakpoint location.
                    return(VSConstants.E_FAIL);
                }

                pCodeSpan[0] = new TextSpan()
                {
                    iStartIndex = breakpointRange.Start.Character,
                    iStartLine  = breakpointRange.Start.Line,
                    iEndIndex   = breakpointRange.End.Character,
                    iEndLine    = breakpointRange.End.Line,
                };
                return(VSConstants.S_OK);
            });

            if (dialogResult == null)
            {
                // Failed to create the dialog at all.
                return(VSConstants.E_FAIL);
            }

            if (dialogResult.Cancelled)
            {
                return(VSConstants.E_FAIL);
            }

            return(dialogResult.Result);
        }
 // Test constructor
 internal CSharpDebuggerIntelliSenseContext(
     IWpfTextView view,
     ITextBuffer contextBuffer,
     TextSpan[] currentStatementSpan,
     IComponentModel componentModel,
     bool immediateWindow)
     : base(view,
         contextBuffer,
         currentStatementSpan,
         componentModel,
         componentModel.GetService<IContentTypeRegistryService>().GetContentType(ContentTypeNames.CSharpContentType),
         immediateWindow)
 {
 }
Пример #11
0
        public virtual bool TryInsertExpansion(int startPositionInSubjectBuffer, int endPositionInSubjectBuffer)
        {
            var textViewModel = TextView.TextViewModel;

            if (textViewModel == null)
            {
                Debug.Assert(TextView.IsClosed);
                return(false);
            }

            int startLine  = 0;
            int startIndex = 0;
            int endLine    = 0;
            int endIndex   = 0;

            // The expansion itself needs to be created in the data buffer, so map everything up
            var startPointInSubjectBuffer = SubjectBuffer.CurrentSnapshot.GetPoint(startPositionInSubjectBuffer);
            var endPointInSubjectBuffer   = SubjectBuffer.CurrentSnapshot.GetPoint(endPositionInSubjectBuffer);

            SnapshotSpan dataBufferSpan;

            if (!TryGetSpanOnHigherBuffer(
                    SubjectBuffer.CurrentSnapshot.GetSpan(startPositionInSubjectBuffer, endPositionInSubjectBuffer - startPositionInSubjectBuffer),
                    textViewModel.DataBuffer,
                    out dataBufferSpan))
            {
                return(false);
            }

            var buffer    = EditorAdaptersFactoryService.GetBufferAdapter(textViewModel.DataBuffer);
            var expansion = buffer as IVsExpansion;

            if (buffer == null || expansion == null)
            {
                return(false);
            }

            buffer.GetLineIndexOfPosition(dataBufferSpan.Start.Position, out startLine, out startIndex);
            buffer.GetLineIndexOfPosition(dataBufferSpan.End.Position, out endLine, out endIndex);

            var textSpan = new VsTextSpan
            {
                iStartLine  = startLine,
                iStartIndex = startIndex,
                iEndLine    = endLine,
                iEndIndex   = endIndex
            };

            return(expansion.InsertExpansion(textSpan, textSpan, this, LanguageServiceGuid, out ExpansionSession) == VSConstants.S_OK);
        }
 // Constructor for testing
 protected AbstractDebuggerIntelliSenseContext(IWpfTextView wpfTextView,
                                               ITextBuffer contextBuffer,
                                               Microsoft.VisualStudio.TextManager.Interop.TextSpan[] currentStatementSpan,
                                               IComponentModel componentModel,
                                               IContentType contentType,
                                               bool isImmediateWindow)
 {
     _textView                           = wpfTextView;
     this.ContextBuffer                  = contextBuffer;
     this.CurrentStatementSpan           = currentStatementSpan[0];
     _contentType                        = contentType;
     this.ProjectionBufferFactoryService = componentModel.GetService <IProjectionBufferFactoryService>();
     _bufferGraphFactoryService          = componentModel.GetService <IBufferGraphFactoryService>();
     _isImmediateWindow                  = isImmediateWindow;
 }
 // Constructor for testing
 protected AbstractDebuggerIntelliSenseContext(IWpfTextView wpfTextView,
     ITextBuffer contextBuffer,
     Microsoft.VisualStudio.TextManager.Interop.TextSpan[] currentStatementSpan,
     IComponentModel componentModel,
     IContentType contentType,
     bool isImmediateWindow)
 {
     _textView = wpfTextView;
     this.ContextBuffer = contextBuffer;
     this.CurrentStatementSpan = currentStatementSpan[0];
     _contentType = contentType;
     this.ProjectionBufferFactoryService = componentModel.GetService<IProjectionBufferFactoryService>();
     _bufferGraphFactoryService = componentModel.GetService<IBufferGraphFactoryService>();
     _isImmediateWindow = isImmediateWindow;
 }
Пример #14
0
        internal bool TryGetSubjectBufferSpan(VsTextSpan surfaceBufferTextSpan, out SnapshotSpan subjectBufferSpan)
        {
            var snapshotSpan = TextView.TextSnapshot.GetSpan(surfaceBufferTextSpan);
            var subjectBufferSpanCollection = TextView.BufferGraph.MapDownToBuffer(snapshotSpan, SpanTrackingMode.EdgeExclusive, SubjectBuffer);

            // Bail if a snippet span does not map down to exactly one subject buffer span.
            if (subjectBufferSpanCollection.Count == 1)
            {
                subjectBufferSpan = subjectBufferSpanCollection.Single();
                return(true);
            }

            subjectBufferSpan = default;
            return(false);
        }
 public CSharpDebuggerIntelliSenseContext(
     IWpfTextView view,
     IVsTextView vsTextView,
     IVsTextLines debuggerBuffer,
     ITextBuffer contextBuffer,
     TextSpan[] currentStatementSpan,
     IComponentModel componentModel,
     IServiceProvider serviceProvider)
     : base(view,
         vsTextView,
         debuggerBuffer,
         contextBuffer,
         currentStatementSpan,
         componentModel,
         serviceProvider,
         componentModel.GetService<IContentTypeRegistryService>().GetContentType(ContentTypeNames.CSharpContentType))
 {
 }
Пример #16
0
        /// <summary>
        /// If there was no $end$ token, place it at the end of the snippet code. Otherwise, it
        /// defaults to the beginning of the snippet code.
        /// </summary>
        private static bool SetEndPositionIfNoneSpecified(IVsExpansionSession pSession)
        {
            XElement snippetNode;

            if (!TryGetSnippetNode(pSession, out snippetNode))
            {
                return(false);
            }

            var ns       = snippetNode.Name.NamespaceName;
            var codeNode = snippetNode.Element(XName.Get("Code", ns));

            if (codeNode == null)
            {
                return(false);
            }

            var delimiterAttribute = codeNode.Attribute("Delimiter");
            var delimiter          = delimiterAttribute != null ? delimiterAttribute.Value : "$";

            if (codeNode.Value.IndexOf(string.Format("{0}end{0}", delimiter), StringComparison.OrdinalIgnoreCase) != -1)
            {
                return(false);
            }

            var snippetSpan = new VsTextSpan[1];

            if (pSession.GetSnippetSpan(snippetSpan) != VSConstants.S_OK)
            {
                return(false);
            }

            var newEndSpan = new VsTextSpan
            {
                iStartLine  = snippetSpan[0].iEndLine,
                iStartIndex = snippetSpan[0].iEndIndex,
                iEndLine    = snippetSpan[0].iEndLine,
                iEndIndex   = snippetSpan[0].iEndIndex
            };

            pSession.SetEndSpan(newEndSpan);
            return(true);
        }
        public int ValidateBreakpointLocation(IVsTextBuffer pBuffer, int iLine, int iCol, TextSpan[] pCodeSpan)
        {
            var textBuffer = _editorAdaptersFactory.GetDataBuffer(pBuffer);

            if (textBuffer is null)
            {
                // Can't resolve the text buffer, let someone else deal with this breakpoint.
                return(VSConstants.E_NOTIMPL);
            }

            var snapshot = textBuffer.CurrentSnapshot;

            if (!ValidateLocation(snapshot, iLine, iCol))
            {
                // The point disappeared between sessions. Do not allow a breakpoint here.
                return(VSConstants.E_FAIL);
            }

            var breakpointRange = _uiThreadOperationExecutor.Execute(
                title: "Determining breakpoint location...",
                description: "Razor Debugger",
                allowCancellation: true,
                showProgress: true,
                (cancellationToken) => _breakpointResolver.TryResolveBreakpointRangeAsync(textBuffer, iLine, iCol, cancellationToken), _joinableTaskFactory);

            if (breakpointRange is null)
            {
                // Failed to create the dialog at all or no applicable breakpoint location.
                return(VSConstants.E_FAIL);
            }

            pCodeSpan[0] = new TextSpan()
            {
                iStartIndex = breakpointRange.Start.Character,
                iStartLine  = breakpointRange.Start.Line,
                iEndIndex   = breakpointRange.End.Character,
                iEndLine    = breakpointRange.End.Line,
            };

            return(VSConstants.S_OK);
        }
        public int GetMemberNavigationPoint(string pszClassName, string pszUniqueMemberID, TextSpan[] pSpanNavPoint, out uint pItemID)
        {
            uint     itemId    = 0;
            TextSpan textSpan  = default;
            var      succeeded = false;

            var uiThreadOperationExecutor = ComponentModel.GetService <IUIThreadOperationExecutor>();

            uiThreadOperationExecutor.Execute(
                "Intellisense",
                defaultDescription: "",
                allowCancellation: false,
                showProgress: false,
                action: c =>
            {
                if (ContainedLanguageCodeSupport.TryGetMemberNavigationPoint(GetThisDocument(), GlobalOptions, pszClassName, pszUniqueMemberID, out textSpan, out var targetDocument, c.UserCancellationToken))
                {
                    succeeded = true;
                    itemId    = this.ContainedDocument.FindItemIdOfDocument(targetDocument);
                }
            });
Пример #19
0
        /// <returns>The tracking span of the inserted "/**/" if there is an $end$ location, null
        /// otherwise.</returns>
        protected override ITrackingSpan InsertEmptyCommentAndGetEndPositionTrackingSpan()
        {
            VsTextSpan[] endSpanInSurfaceBuffer = new VsTextSpan[1];
            if (ExpansionSession.GetEndSpan(endSpanInSurfaceBuffer) != VSConstants.S_OK)
            {
                return null;
            }

            if (!TryGetSubjectBufferSpan(endSpanInSurfaceBuffer[0], out var subjectBufferEndSpan))
            {
                return null;
            }

            var endPosition = subjectBufferEndSpan.Start.Position;

            string commentString = "/**/";
            SubjectBuffer.Insert(endPosition, commentString);

            var commentSpan = new Span(endPosition, commentString.Length);
            return SubjectBuffer.CurrentSnapshot.CreateTrackingSpan(commentSpan, SpanTrackingMode.EdgeExclusive);
        }
Пример #20
0
        public async Task <(string filePath, int lineNumber, int charOffset)?> WouldNotifyToSpecificSymbolAsync(
            DefinitionItem definitionItem, string?rqName, CancellationToken cancellationToken)
        {
            if (rqName == null)
            {
                return(null);
            }

            var values = await TryGetNavigationAPIRequiredArgumentsAsync(
                definitionItem, rqName, cancellationToken).ConfigureAwait(false);

            if (values is not var(hierarchy, itemID, navigationNotify))
            {
                return(null);
            }

            var navigateToTextSpan = new Microsoft.VisualStudio.TextManager.Interop.TextSpan[1];

            await this.ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            var queryNavigateStatusCode = navigationNotify.QueryNavigateToSymbol(
                hierarchy,
                itemID,
                rqName,
                out var navigateToHierarchy,
                out var navigateToItem,
                navigateToTextSpan,
                out var wouldNavigate);

            if (queryNavigateStatusCode != VSConstants.S_OK || wouldNavigate != 1)
            {
                return(null);
            }

            navigateToHierarchy.GetCanonicalName(navigateToItem, out var filePath);
            var lineNumber = navigateToTextSpan[0].iStartLine;
            var charOffset = navigateToTextSpan[0].iStartIndex;

            return(filePath, lineNumber, charOffset);
        }
        public bool WouldNotifyToSpecificSymbol(ISymbol symbol, Solution solution, out string filePath, out int lineNumber, out int charOffset)
        {
            filePath   = null;
            lineNumber = 0;
            charOffset = 0;

            IVsHierarchy hierarchy;
            IVsSymbolicNavigationNotify navigationNotify;
            string rqname;

            if (!TryGetNavigationAPIRequiredArguments(symbol, solution, out hierarchy, out navigationNotify, out rqname))
            {
                return(false);
            }

            IVsHierarchy navigateToHierarchy;
            uint         navigateToItem;
            int          wouldNavigate;
            var          navigateToTextSpan = new Microsoft.VisualStudio.TextManager.Interop.TextSpan[1];

            int queryNavigateStatusCode = navigationNotify.QueryNavigateToSymbol(
                hierarchy,
                (uint)VSConstants.VSITEMID.Nil,
                rqname,
                out navigateToHierarchy,
                out navigateToItem,
                navigateToTextSpan,
                out wouldNavigate);

            if (queryNavigateStatusCode == VSConstants.S_OK && wouldNavigate == 1)
            {
                navigateToHierarchy.GetCanonicalName(navigateToItem, out filePath);
                lineNumber = navigateToTextSpan[0].iStartLine;
                charOffset = navigateToTextSpan[0].iStartIndex;
                return(true);
            }

            return(false);
        }
        protected AbstractDebuggerIntelliSenseContext(
            IWpfTextView wpfTextView,
            IVsTextView vsTextView,
            IVsTextLines vsDebuggerTextLines,
            ITextBuffer contextBuffer,
            Microsoft.VisualStudio.TextManager.Interop.TextSpan[] currentStatementSpan,
            IComponentModel componentModel,
            IServiceProvider serviceProvider,
            IContentType contentType)
        {
            _textView = wpfTextView;
            _debuggerTextLines = vsDebuggerTextLines;
            this.ContextBuffer = contextBuffer;
            this.CurrentStatementSpan = currentStatementSpan[0];
            _contentType = contentType;
            this.ProjectionBufferFactoryService = componentModel.GetService<IProjectionBufferFactoryService>();
            _bufferGraphFactoryService = componentModel.GetService<IBufferGraphFactoryService>();
            var _editorAdaptersFactoryService = componentModel.GetService<IVsEditorAdaptersFactoryService>();

            _isImmediateWindow = vsTextView.IsImmediateWindow(
                (IVsUIShell)serviceProvider.GetService(typeof(SVsUIShell)),
                _editorAdaptersFactoryService);
        }
        protected AbstractDebuggerIntelliSenseContext(
            IWpfTextView wpfTextView,
            IVsTextView vsTextView,
            IVsTextLines vsDebuggerTextLines,
            ITextBuffer contextBuffer,
            Microsoft.VisualStudio.TextManager.Interop.TextSpan[] currentStatementSpan,
            IComponentModel componentModel,
            IServiceProvider serviceProvider,
            IContentType contentType)
        {
            _textView                           = wpfTextView;
            _debuggerTextLines                  = vsDebuggerTextLines;
            this.ContextBuffer                  = contextBuffer;
            this.CurrentStatementSpan           = currentStatementSpan[0];
            _contentType                        = contentType;
            this.ProjectionBufferFactoryService = componentModel.GetService <IProjectionBufferFactoryService>();
            _bufferGraphFactoryService          = componentModel.GetService <IBufferGraphFactoryService>();
            var _editorAdaptersFactoryService = componentModel.GetService <IVsEditorAdaptersFactoryService>();

            _isImmediateWindow = vsTextView.IsImmediateWindow(
                (IVsUIShell)serviceProvider.GetService(typeof(SVsUIShell)),
                _editorAdaptersFactoryService);
        }
Пример #24
0
 public override string GetDataTipText(int line, int col, out MVTI.TextSpan span)
 {
     span = new MVTI.TextSpan();
     return null;
 }
        public static bool TryGetMemberNavigationPoint(
            Document thisDocument,
            string className,
            string uniqueMemberID,
            out VsTextSpan textSpan,
            out Document targetDocument,
            CancellationToken cancellationToken)
        {
            targetDocument = null;
            textSpan = default(VsTextSpan);

            var type = thisDocument.Project.GetCompilationAsync(cancellationToken).WaitAndGetResult(cancellationToken).GetTypeByMetadataName(className);
            var member = LookupMemberId(type, uniqueMemberID);

            if (member == null)
            {
                return false;
            }

            var codeModel = thisDocument.Project.LanguageServices.GetService<ICodeModelNavigationPointService>();
            var memberNode = member.DeclaringSyntaxReferences.Select(r => r.GetSyntax(cancellationToken)).FirstOrDefault();
            if (memberNode != null)
            {
                var navigationPoint = codeModel.GetStartPoint(memberNode, EnvDTE.vsCMPart.vsCMPartNavigate);
                if (navigationPoint != null)
                {
                    targetDocument = thisDocument.Project.Solution.GetDocument(memberNode.SyntaxTree);
                    textSpan = navigationPoint.Value.ToVsTextSpan();
                    return true;
                }
            }

            return false;
        }
Пример #26
0
 public override string Goto(VSConstants.VSStd97CmdID cmd, MVTI.IVsTextView textView, int line, int col, out MVTI.TextSpan span)
 {
     span = new MVTI.TextSpan();
     return null;
 }
Пример #27
0
 public override string GetDataTipText(int line, int col, out TextSpan span)
 {
     span = new Microsoft.VisualStudio.TextManager.Interop.TextSpan();
     return(null);
 }
Пример #28
0
 public override string Goto(VSConstants.VSStd97CmdID cmd, MVTI.IVsTextView textView, int line, int col, out MVTI.TextSpan span)
 {
     span = new MVTI.TextSpan();
     return(null);
 }
        public bool WouldNotifyToSpecificSymbol(ISymbol symbol, Solution solution, out string filePath, out int lineNumber, out int charOffset)
        {
            AssertIsForeground();

            filePath = null;
            lineNumber = 0;
            charOffset = 0;

            IVsHierarchy hierarchy;
            IVsSymbolicNavigationNotify navigationNotify;
            string rqname;
            uint itemID;
            if (!TryGetNavigationAPIRequiredArguments(symbol, solution, out hierarchy, out itemID, out navigationNotify, out rqname))
            {
                return false;
            }

            IVsHierarchy navigateToHierarchy;
            uint navigateToItem;
            int wouldNavigate;
            var navigateToTextSpan = new Microsoft.VisualStudio.TextManager.Interop.TextSpan[1];

            int queryNavigateStatusCode = navigationNotify.QueryNavigateToSymbol(
                hierarchy,
                itemID,
                rqname,
                out navigateToHierarchy,
                out navigateToItem,
                navigateToTextSpan,
                out wouldNavigate);

            if (queryNavigateStatusCode == VSConstants.S_OK && wouldNavigate == 1)
            {
                navigateToHierarchy.GetCanonicalName(navigateToItem, out filePath);
                lineNumber = navigateToTextSpan[0].iStartLine;
                charOffset = navigateToTextSpan[0].iStartIndex;
                return true;
            }

            return false;
        }
Пример #30
0
        public virtual bool TryInsertExpansion(int startPositionInSubjectBuffer, int endPositionInSubjectBuffer)
        {
            var textViewModel = TextView.TextViewModel;
            if (textViewModel == null)
            {
                Debug.Assert(TextView.IsClosed);
                return false;
            }

            int startLine = 0;
            int startIndex = 0;
            int endLine = 0;
            int endIndex = 0;

            // The expansion itself needs to be created in the data buffer, so map everything up
            var startPointInSubjectBuffer = SubjectBuffer.CurrentSnapshot.GetPoint(startPositionInSubjectBuffer);
            var endPointInSubjectBuffer = SubjectBuffer.CurrentSnapshot.GetPoint(endPositionInSubjectBuffer);

            SnapshotSpan dataBufferSpan;
            if (!TryGetSpanOnHigherBuffer(
                SubjectBuffer.CurrentSnapshot.GetSpan(startPositionInSubjectBuffer, endPositionInSubjectBuffer - startPositionInSubjectBuffer),
                textViewModel.DataBuffer,
                out dataBufferSpan))
            {
                return false;
            }

            var buffer = EditorAdaptersFactoryService.GetBufferAdapter(textViewModel.DataBuffer);
            var expansion = buffer as IVsExpansion;
            if (buffer == null || expansion == null)
            {
                return false;
            }

            buffer.GetLineIndexOfPosition(dataBufferSpan.Start.Position, out startLine, out startIndex);
            buffer.GetLineIndexOfPosition(dataBufferSpan.End.Position, out endLine, out endIndex);

            var textSpan = new VsTextSpan
            {
                iStartLine = startLine,
                iStartIndex = startIndex,
                iEndLine = endLine,
                iEndIndex = endIndex
            };

            return expansion.InsertExpansion(textSpan, textSpan, this, LanguageServiceGuid, out ExpansionSession) == VSConstants.S_OK;
        }
Пример #31
0
 public override int GetFullDataTipText(string textValue, Microsoft.VisualStudio.TextManager.Interop.TextSpan ts, out string fullTipText)
 {
     return(base.GetFullDataTipText(textValue, ts, out fullTipText));
 }
        private DiagnosticData CreateDocumentDiagnosticItem(ExternalError error)
        {
            var hostProject = _workspace.GetHostProject(_projectId);
            if (!hostProject.ContainsFile(error.bstrFileName))
            {
                return null;
            }

            var hostDocument = hostProject.GetCurrentDocumentFromPath(error.bstrFileName);

            var line = error.iLine;
            var column = error.iCol;
            var containedDocument = hostDocument as ContainedDocument;
            if (containedDocument != null)
            {
                var span = new VsTextSpan
                {
                    iStartLine = line,
                    iStartIndex = column,
                    iEndLine = line,
                    iEndIndex = column,
                };

                var spans = new VsTextSpan[1];
                Marshal.ThrowExceptionForHR(containedDocument.ContainedLanguage.BufferCoordinator.MapPrimaryToSecondarySpan(
                    span,
                    spans));

                line = spans[0].iStartLine;
                column = spans[0].iStartIndex;
            }

            return GetDiagnosticData(error, hostDocument.Id, line, column);
        }
        /// <summary>
        /// If there was no $end$ token, place it at the end of the snippet code. Otherwise, it
        /// defaults to the beginning of the snippet code.
        /// </summary>
        private static bool SetEndPositionIfNoneSpecified(IVsExpansionSession pSession)
        {
            XElement snippetNode;
            if (!TryGetSnippetNode(pSession, out snippetNode))
            {
                return false;
            }

            var ns = snippetNode.Name.NamespaceName;
            var codeNode = snippetNode.Element(XName.Get("Code", ns));
            if (codeNode == null)
            {
                return false;
            }

            var delimiterAttribute = codeNode.Attribute("Delimiter");
            var delimiter = delimiterAttribute != null ? delimiterAttribute.Value : "$";
            if (codeNode.Value.IndexOf(string.Format("{0}end{0}", delimiter), StringComparison.OrdinalIgnoreCase) != -1)
            {
                return false;
            }

            var snippetSpan = new VsTextSpan[1];
            if (pSession.GetSnippetSpan(snippetSpan) != VSConstants.S_OK)
            {
                return false;
            }

            var newEndSpan = new VsTextSpan
            {
                iStartLine = snippetSpan[0].iEndLine,
                iStartIndex = snippetSpan[0].iEndIndex,
                iEndLine = snippetSpan[0].iEndLine,
                iEndIndex = snippetSpan[0].iEndIndex
            };

            pSession.SetEndSpan(newEndSpan);
            return true;
        }
Пример #34
0
 public override string GetDataTipText(int line, int col, out MVTI.TextSpan span)
 {
     span = new MVTI.TextSpan();
     return(null);
 }
Пример #35
0
 private bool CanMapFromSecondaryBufferToPrimaryBuffer(Workspace workspace, DocumentId documentId, VsTextSpan spanInSecondaryBuffer)
 => spanInSecondaryBuffer.TryMapSpanFromSecondaryBufferToPrimaryBuffer(workspace, documentId, out var spanInPrimaryBuffer);
Пример #36
0
        public int FormatSpan(IVsTextLines pBuffer, VsTextSpan[] tsInSurfaceBuffer)
        {
            // Formatting a snippet isn't cancellable.
            var cancellationToken = CancellationToken.None;

            // At this point, the $selection$ token has been replaced with the selected text and
            // declarations have been replaced with their default text. We need to format the
            // inserted snippet text while carefully handling $end$ position (where the caret goes
            // after Return is pressed). The IVsExpansionSession keeps a tracking point for this
            // position but we do the tracking ourselves to properly deal with virtual space. To
            // ensure the end location is correct, we take three extra steps:
            // 1. Insert an empty comment ("/**/" or "'") at the current $end$ position (prior
            //    to formatting), and keep a tracking span for the comment.
            // 2. After formatting the new snippet text, find and delete the empty multiline
            //    comment (via the tracking span) and notify the IVsExpansionSession of the new
            //    $end$ location. If the line then contains only whitespace (due to the formatter
            //    putting the empty comment on its own line), then delete the white space and
            //    remember the indentation depth for that line.
            // 3. When the snippet is finally completed (via Return), and PositionCaretForEditing()
            //    is called, check to see if the end location was on a line containing only white
            //    space in the previous step. If so, and if that line is still empty, then position
            //    the caret in virtual space.
            // This technique ensures that a snippet like "if($condition$) { $end$ }" will end up
            // as:
            //     if ($condition$)
            //     {
            //         $end$
            //     }
            if (!TryGetSubjectBufferSpan(tsInSurfaceBuffer[0], out var snippetSpan))
            {
                return(VSConstants.S_OK);
            }

            // Insert empty comment and track end position
            var snippetTrackingSpan = snippetSpan.CreateTrackingSpan(SpanTrackingMode.EdgeInclusive);

            var fullSnippetSpan = new VsTextSpan[1];

            ExpansionSession.GetSnippetSpan(fullSnippetSpan);

            var isFullSnippetFormat =
                fullSnippetSpan[0].iStartLine == tsInSurfaceBuffer[0].iStartLine &&
                fullSnippetSpan[0].iStartIndex == tsInSurfaceBuffer[0].iStartIndex &&
                fullSnippetSpan[0].iEndLine == tsInSurfaceBuffer[0].iEndLine &&
                fullSnippetSpan[0].iEndIndex == tsInSurfaceBuffer[0].iEndIndex;
            var endPositionTrackingSpan = isFullSnippetFormat ? InsertEmptyCommentAndGetEndPositionTrackingSpan() : null;

            var formattingSpan = CommonFormattingHelpers.GetFormattingSpan(SubjectBuffer.CurrentSnapshot, snippetTrackingSpan.GetSpan(SubjectBuffer.CurrentSnapshot));

            SubjectBuffer.CurrentSnapshot.FormatAndApplyToBuffer(formattingSpan, CancellationToken.None);

            if (isFullSnippetFormat)
            {
                CleanUpEndLocation(endPositionTrackingSpan);

                // Unfortunately, this is the only place we can safely add references and imports
                // specified in the snippet xml. In OnBeforeInsertion we have no guarantee that the
                // snippet xml will be available, and changing the buffer during OnAfterInsertion can
                // cause the underlying tracking spans to get out of sync.
                var currentStartPosition = snippetTrackingSpan.GetStartPoint(SubjectBuffer.CurrentSnapshot).Position;
                AddReferencesAndImports(
                    ExpansionSession, currentStartPosition, cancellationToken);

                SetNewEndPosition(endPositionTrackingSpan);
            }

            return(VSConstants.S_OK);
        }
        private bool NavigateTo(ITextBuffer textBuffer, VsTextSpan vsTextSpan)
        {
            using (Logger.LogBlock(FunctionId.NavigationService_VSDocumentNavigationService_NavigateTo, CancellationToken.None))
            {
                var vsTextBuffer = _editorAdaptersFactoryService.GetBufferAdapter(textBuffer);
                if (vsTextBuffer == null)
                {
                    Debug.Fail("Could not get IVsTextBuffer for document!");
                    return false;
                }

                var textManager = (IVsTextManager2)_serviceProvider.GetService(typeof(SVsTextManager));
                if (textManager == null)
                {
                    Debug.Fail("Could not get IVsTextManager service!");
                    return false;
                }

                return ErrorHandler.Succeeded(
                    textManager.NavigateToLineAndColumn2(
                        vsTextBuffer, VSConstants.LOGVIEWID.TextView_guid, vsTextSpan.iStartLine, vsTextSpan.iStartIndex, vsTextSpan.iEndLine, vsTextSpan.iEndIndex, (uint)_VIEWFRAMETYPE.vftCodeWindow));
            }
        }
 private bool CanMapFromSecondaryBufferToPrimaryBuffer(Workspace workspace, DocumentId documentId, VsTextSpan spanInSecondaryBuffer)
 {
     return spanInSecondaryBuffer.TryMapSpanFromSecondaryBufferToPrimaryBuffer(workspace, documentId, out var spanInPrimaryBuffer);
 }
        public override string Goto(VSConstants.VSStd97CmdID cmd, IVsTextView textView, int line, int col, out TextSpan span)
        {
            span = new Microsoft.VisualStudio.TextManager.Interop.TextSpan();

            return null;
        }
        public int FormatSpan(IVsTextLines pBuffer, VsTextSpan[] tsInSurfaceBuffer)
        {
            // Formatting a snippet isn't cancellable.
            var cancellationToken = CancellationToken.None;

            // At this point, the $selection$ token has been replaced with the selected text and
            // declarations have been replaced with their default text. We need to format the 
            // inserted snippet text while carefully handling $end$ position (where the caret goes
            // after Return is pressed). The IVsExpansionSession keeps a tracking point for this
            // position but we do the tracking ourselves to properly deal with virtual space. To 
            // ensure the end location is correct, we take three extra steps:
            // 1. Insert an empty comment ("/**/" or "'") at the current $end$ position (prior 
            //    to formatting), and keep a tracking span for the comment.
            // 2. After formatting the new snippet text, find and delete the empty multiline 
            //    comment (via the tracking span) and notify the IVsExpansionSession of the new 
            //    $end$ location. If the line then contains only whitespace (due to the formatter
            //    putting the empty comment on its own line), then delete the white space and 
            //    remember the indentation depth for that line.
            // 3. When the snippet is finally completed (via Return), and PositionCaretForEditing()
            //    is called, check to see if the end location was on a line containing only white
            //    space in the previous step. If so, and if that line is still empty, then position
            //    the caret in virtual space.
            // This technique ensures that a snippet like "if($condition$) { $end$ }" will end up 
            // as:
            //     if ($condition$)
            //     {
            //         $end$
            //     }

            SnapshotSpan snippetSpan;
            if (!TryGetSubjectBufferSpan(tsInSurfaceBuffer[0], out snippetSpan))
            {
                return VSConstants.S_OK;
            }

            // Insert empty comment and track end position
            var snippetTrackingSpan = snippetSpan.CreateTrackingSpan(SpanTrackingMode.EdgeInclusive);

            var fullSnippetSpan = new VsTextSpan[1];
            ExpansionSession.GetSnippetSpan(fullSnippetSpan);

            var isFullSnippetFormat =
                fullSnippetSpan[0].iStartLine == tsInSurfaceBuffer[0].iStartLine &&
                fullSnippetSpan[0].iStartIndex == tsInSurfaceBuffer[0].iStartIndex &&
                fullSnippetSpan[0].iEndLine == tsInSurfaceBuffer[0].iEndLine &&
                fullSnippetSpan[0].iEndIndex == tsInSurfaceBuffer[0].iEndIndex;
            var endPositionTrackingSpan = isFullSnippetFormat ? InsertEmptyCommentAndGetEndPositionTrackingSpan() : null;

            var formattingSpan = CommonFormattingHelpers.GetFormattingSpan(SubjectBuffer.CurrentSnapshot, snippetTrackingSpan.GetSpan(SubjectBuffer.CurrentSnapshot));
            SubjectBuffer.CurrentSnapshot.FormatAndApplyToBuffer(formattingSpan, CancellationToken.None);

            if (isFullSnippetFormat)
            {
                CleanUpEndLocation(endPositionTrackingSpan);

                // Unfortunately, this is the only place we can safely add references and imports
                // specified in the snippet xml. In OnBeforeInsertion we have no guarantee that the
                // snippet xml will be available, and changing the buffer during OnAfterInsertion can
                // cause the underlying tracking spans to get out of sync.
                AddReferencesAndImports(ExpansionSession, cancellationToken);

                SetNewEndPosition(endPositionTrackingSpan);
            }

            return VSConstants.S_OK;
        }
        internal bool TryGetSubjectBufferSpan(VsTextSpan surfaceBufferTextSpan, out SnapshotSpan subjectBufferSpan)
        {
            var snapshotSpan = TextView.TextSnapshot.GetSpan(surfaceBufferTextSpan);
            var subjectBufferSpanCollection = TextView.BufferGraph.MapDownToBuffer(snapshotSpan, SpanTrackingMode.EdgeExclusive, SubjectBuffer);

            // Bail if a snippet span does not map down to exactly one subject buffer span.
            if (subjectBufferSpanCollection.Count == 1)
            {
                subjectBufferSpan = subjectBufferSpanCollection.Single();
                return true;
            }

            subjectBufferSpan = default(SnapshotSpan);
            return false;
        }
        public virtual bool TryInsertExpansion(int startPositionInSubjectBuffer, int endPositionInSubjectBuffer)
        {
            int startLine = 0;
            int startIndex = 0;
            int endLine = 0;
            int endIndex = 0;

            // The expansion itself needs to be created in the surface buffer, so map everything up
            var startPointInSubjectBuffer = SubjectBuffer.CurrentSnapshot.GetPoint(startPositionInSubjectBuffer);
            var endPointInSubjectBuffer = SubjectBuffer.CurrentSnapshot.GetPoint(endPositionInSubjectBuffer);

            SnapshotSpan surfaceBufferSpan;
            if (!TryGetSurfaceBufferSpan(SubjectBuffer.CurrentSnapshot.GetSpan(startPositionInSubjectBuffer, endPositionInSubjectBuffer - startPositionInSubjectBuffer), out surfaceBufferSpan))
            {
                return false;
            }

            var buffer = EditorAdaptersFactoryService.GetBufferAdapter(TextView.TextBuffer);
            buffer.GetLineIndexOfPosition(surfaceBufferSpan.Start.Position, out startLine, out startIndex);
            buffer.GetLineIndexOfPosition(surfaceBufferSpan.End.Position, out endLine, out endIndex);

            var textSpan = new VsTextSpan
            {
                iStartLine = startLine,
                iStartIndex = startIndex,
                iEndLine = endLine,
                iEndIndex = endIndex
            };

            var expansion = buffer as IVsExpansion;
            return expansion.InsertExpansion(textSpan, textSpan, this, LanguageServiceGuid, out ExpansionSession) == VSConstants.S_OK;
        }
Пример #43
0
        public override string Goto(VSConstants.VSStd97CmdID cmd, IVsTextView textView, int line, int col, out TextSpan span)
        {
            span = new Microsoft.VisualStudio.TextManager.Interop.TextSpan();

            return(null);
        }
 public int IsValidKind(IVsTextLines pBuffer, VsTextSpan[] ts, string bstrKind, out int pfIsValidKind)
 {
     pfIsValidKind = 1;
     return VSConstants.S_OK;
 }
 public int IsValidType(IVsTextLines pBuffer, VsTextSpan[] ts, string[] rgTypes, int iCountTypes, out int pfIsValidType)
 {
     pfIsValidType = 1;
     return VSConstants.S_OK;
 }
        private bool CanMapFromSecondaryBufferToPrimaryBuffer(Workspace workspace, DocumentId documentId, VsTextSpan spanInSecondaryBuffer)
        {
            VsTextSpan spanInPrimaryBuffer;

            return(spanInSecondaryBuffer.TryMapSpanFromSecondaryBufferToPrimaryBuffer(workspace, documentId, out spanInPrimaryBuffer));
        }
 public override string GetDataTipText(int line, int col, out TextSpan span)
 {
     span = new Microsoft.VisualStudio.TextManager.Interop.TextSpan();
     return null;
 }