Exemplo n.º 1
0
        protected override async Task <(int ExitCode, string Value, int HasDefaultValue)> GetDefaultValueAsync(CancellationToken cancellationToken)
        {
            var hasDefaultValue = 0;
            var value           = string.Empty;

            if (!TryGetDocument(out var document))
            {
                return(VSConstants.E_FAIL, value, hasDefaultValue);
            }

            var surfaceBufferFieldSpan = new VsTextSpan[1];

            if (snippetExpansionClient.ExpansionSession.GetFieldSpan(FieldName, surfaceBufferFieldSpan) != VSConstants.S_OK)
            {
                return(VSConstants.E_FAIL, value, hasDefaultValue);
            }

            if (!snippetExpansionClient.TryGetSubjectBufferSpan(surfaceBufferFieldSpan[0], out var subjectBufferFieldSpan))
            {
                return(VSConstants.E_FAIL, value, hasDefaultValue);
            }

            var snippetFunctionService = document.Project.GetRequiredLanguageService <SnippetFunctionService>();

            value = await snippetFunctionService.GetContainingClassNameAsync(document, subjectBufferFieldSpan.Start.Position, cancellationToken).ConfigureAwait(false);

            if (!string.IsNullOrWhiteSpace(value))
            {
                hasDefaultValue = 1;
            }

            return(VSConstants.S_OK, value, hasDefaultValue);
        }
Exemplo n.º 2
0
        public static bool TryMapSpanFromSecondaryBufferToPrimaryBuffer(this VsTextSpan spanInSecondaryBuffer, Microsoft.CodeAnalysis.Workspace workspace, DocumentId documentId, out VsTextSpan spanInPrimaryBuffer)
        {
            spanInPrimaryBuffer = default;

            if (!(workspace is VisualStudioWorkspaceImpl visualStudioWorkspace))
            {
                return(false);
            }

            var containedDocument = visualStudioWorkspace.TryGetContainedDocument(documentId);

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

            var bufferCoordinator = containedDocument.BufferCoordinator;

            var primary = new VsTextSpan[1];
            var hresult = bufferCoordinator.MapSecondaryToPrimarySpan(spanInSecondaryBuffer, primary);

            spanInPrimaryBuffer = primary[0];

            return(ErrorHandler.Succeeded(hresult));
        }
        private bool TryGetSimplifiedTypeName(string fullyQualifiedTypeName, string firstEnumMemberName, CancellationToken cancellationToken, out string simplifiedTypeName)
        {
            simplifiedTypeName = string.Empty;

            Document document;

            if (!TryGetDocument(out document))
            {
                return(false);
            }

            // Add the first switch case using the fully qualified type name, then simplify it in
            // that context
            var surfaceBufferFieldSpan = new VsTextSpan[1];

            if (snippetExpansionClient.ExpansionSession.GetFieldSpan(CaseGenerationLocationField, surfaceBufferFieldSpan) != VSConstants.S_OK)
            {
                return(false);
            }

            SnapshotSpan subjectBufferFieldSpan;

            if (!snippetExpansionClient.TryGetSubjectBufferSpan(surfaceBufferFieldSpan[0], out subjectBufferFieldSpan))
            {
                return(false);
            }

            return(TryGetSimplifiedTypeNameInCaseContext(document, fullyQualifiedTypeName, firstEnumMemberName, subjectBufferFieldSpan.Start.Position, subjectBufferFieldSpan.End.Position, cancellationToken, out simplifiedTypeName));
        }
Exemplo n.º 4
0
        public void Bind(JavaDebugProgram program, JavaDebugThread thread, IReferenceType type, IEnumerable <string> sourcePaths)
        {
            IVirtualMachine virtualMachine = program.VirtualMachine;

            IEnumerable <string> validPaths = sourcePaths.Where(i => string.Equals(Path.GetFileName(RequestLocation.DocumentPosition.GetFileName()), Path.GetFileName(i), StringComparison.OrdinalIgnoreCase));

            List <JavaDebugBoundBreakpoint> boundBreakpoints = new List <JavaDebugBoundBreakpoint>();
            List <IDebugErrorBreakpoint2>   errorBreakpoints = new List <IDebugErrorBreakpoint2>();

            foreach (var path in validPaths)
            {
                TextSpan range = RequestLocation.DocumentPosition.GetRange();
                try
                {
                    ReadOnlyCollection <ILocation> locations = type.GetLocationsOfLine(range.iStartLine + 1);
                    ILocation bindLocation = locations.OrderBy(i => i.GetCodeIndex()).FirstOrDefault();
                    if (bindLocation != null && IsFirstOnLine())
                    {
                        IEventRequestManager eventRequestManager = virtualMachine.GetEventRequestManager();

                        IBreakpointRequest eventRequest = eventRequestManager.CreateBreakpointRequest(bindLocation);
                        eventRequest.SuspendPolicy = SuspendPolicy.All;

                        JavaDebugCodeContext             codeContext     = new JavaDebugCodeContext(program, bindLocation);
                        BreakpointResolutionLocationCode location        = new BreakpointResolutionLocationCode(codeContext);
                        DebugBreakpointResolution        resolution      = new DebugBreakpointResolution(program, thread, enum_BP_TYPE.BPT_CODE, location);
                        JavaDebugBoundBreakpoint         boundBreakpoint = new JavaDebugBoundBreakpoint(this, program, eventRequest, resolution);
                        if (!_disabled)
                        {
                            boundBreakpoint.Enable(1);
                        }

                        boundBreakpoints.Add(boundBreakpoint);
                    }
                }
                catch (MissingInformationException)
                {
                }
            }

            _boundBreakpoints.AddRange(boundBreakpoints);
            if (boundBreakpoints.Count > 0)
            {
                _errorBreakpoints.Clear();
            }

            _errorBreakpoints.AddRange(errorBreakpoints);

            if (boundBreakpoints.Count > 0)
            {
                DebugEvent debugEvent = new DebugBreakpointBoundEvent(enum_EVENTATTRIBUTES.EVENT_SYNCHRONOUS, this, new EnumDebugBoundBreakpoints(boundBreakpoints));
                program.Callback.Event(DebugEngine, program.Process, program, null, debugEvent);
            }

            foreach (var errorBreakpoint in errorBreakpoints)
            {
                DebugEvent debugEvent = new DebugBreakpointErrorEvent(enum_EVENTATTRIBUTES.EVENT_ASYNCHRONOUS, errorBreakpoint);
                program.Callback.Event(DebugEngine, program.Process, program, null, debugEvent);
            }
        }
Exemplo n.º 5
0
        protected override int GetDefaultValue(CancellationToken cancellationToken, out string value, out int hasDefaultValue)
        {
            hasDefaultValue = 0;
            value           = string.Empty;

            Document document;

            if (!TryGetDocument(out document))
            {
                return(VSConstants.E_FAIL);
            }

            var surfaceBufferFieldSpan = new VsTextSpan[1];

            if (snippetExpansionClient.ExpansionSession.GetFieldSpan(FieldName, surfaceBufferFieldSpan) != VSConstants.S_OK)
            {
                return(VSConstants.E_FAIL);
            }

            SnapshotSpan subjectBufferFieldSpan;

            if (!snippetExpansionClient.TryGetSubjectBufferSpan(surfaceBufferFieldSpan[0], out subjectBufferFieldSpan))
            {
                return(VSConstants.E_FAIL);
            }

            return(GetContainingClassName(document, subjectBufferFieldSpan, cancellationToken, ref value, ref hasDefaultValue));
        }
        private bool TryGetDocumentWithFullyQualifiedTypeName(Document document, out TextSpan updatedTextSpan, out Document documentWithFullyQualifiedTypeName)
        {
            documentWithFullyQualifiedTypeName = null;
            updatedTextSpan = default(TextSpan);

            var surfaceBufferFieldSpan = new VsTextSpan[1];
            if (snippetExpansionClient.ExpansionSession.GetFieldSpan(_fieldName, surfaceBufferFieldSpan) != VSConstants.S_OK)
            {
                return false;
            }

            if (!snippetExpansionClient.TryGetSubjectBufferSpan(surfaceBufferFieldSpan[0], out var subjectBufferFieldSpan))
            {
                return false;
            }

            var originalTextSpan = new TextSpan(subjectBufferFieldSpan.Start, subjectBufferFieldSpan.Length);
            updatedTextSpan = new TextSpan(subjectBufferFieldSpan.Start, _fullyQualifiedName.Length);

            var textChange = new TextChange(originalTextSpan, _fullyQualifiedName);
            var newText = document.GetTextAsync(CancellationToken.None).WaitAndGetResult(CancellationToken.None).WithChanges(textChange);

            documentWithFullyQualifiedTypeName = document.WithText(newText);
            return true;
        }
        protected override bool TryGetEnumTypeSymbol(CancellationToken cancellationToken, out ITypeSymbol typeSymbol)
        {
            typeSymbol = null;
            if (!TryGetDocument(out var document))
            {
                return false;
            }

            var surfaceBufferFieldSpan = new VsTextSpan[1];
            if (snippetExpansionClient.ExpansionSession.GetFieldSpan(SwitchExpressionField, surfaceBufferFieldSpan) != VSConstants.S_OK)
            {
                return false;
            }

            if (!snippetExpansionClient.TryGetSubjectBufferSpan(surfaceBufferFieldSpan[0], out var subjectBufferFieldSpan))
            {
                return false;
            }

            var expressionSpan = subjectBufferFieldSpan.Span.ToTextSpan();

            var syntaxTree = document.GetSyntaxTreeSynchronously(cancellationToken);
            var token = syntaxTree.FindTokenOnRightOfPosition(expressionSpan.Start, cancellationToken);
            var expressionNode = token.GetAncestor(n => n.Span == expressionSpan);

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

            SemanticModel model = document.GetSemanticModelAsync(cancellationToken).WaitAndGetResult(cancellationToken);
            typeSymbol = model.GetTypeInfo(expressionNode, cancellationToken).Type;

            return typeSymbol != null;
        }
        public static async Task <VsTextSpan?> MapSpanFromSecondaryBufferToPrimaryBufferAsync(
            this VsTextSpan spanInSecondaryBuffer,
            IThreadingContext threadingContext,
            Workspace workspace,
            DocumentId documentId,
            CancellationToken cancellationToken)
        {
            if (workspace is not VisualStudioWorkspaceImpl visualStudioWorkspace)
            {
                return(null);
            }

            var containedDocument = visualStudioWorkspace.TryGetContainedDocument(documentId);

            if (containedDocument == null)
            {
                return(null);
            }

            await threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            var bufferCoordinator = containedDocument.BufferCoordinator;

            var primary = new VsTextSpan[1];
            var hresult = bufferCoordinator.MapSecondaryToPrimarySpan(spanInSecondaryBuffer, primary);

            var result = primary[0];

            return(ErrorHandler.Succeeded(hresult) ? result : null);
        }
Exemplo n.º 9
0
 public static SnapshotSpan?TryGetSpan(this ITextSnapshot snapshot, VsTextSpan textSpan) =>
 snapshot.TryGetSpan(
     textSpan.iStartLine,
     textSpan.iStartIndex,
     textSpan.iEndLine,
     textSpan.iEndIndex
     );
Exemplo n.º 10
0
        public static bool TryMapSpanFromSecondaryBufferToPrimaryBuffer(this VsTextSpan spanInSecondaryBuffer, Workspace workspace, DocumentId documentId, out VsTextSpan spanInPrimaryBuffer)
        {
            spanInPrimaryBuffer = default(VsTextSpan);
            return(false);

            // TODO

            //var visualStudioWorkspace = workspace as VisualStudioWorkspaceImpl;
            //if (visualStudioWorkspace == null)
            //{
            //    return false;
            //}

            //var containedDocument = visualStudioWorkspace.GetHostDocument(documentId) as ContainedDocument;
            //if (containedDocument == null)
            //{
            //    return false;
            //}

            //var bufferCoordinator = containedDocument.ContainedLanguage.BufferCoordinator;

            //var primary = new VsTextSpan[1];
            //var hresult = bufferCoordinator.MapSecondaryToPrimarySpan(spanInSecondaryBuffer, primary);

            //spanInPrimaryBuffer = primary[0];

            //return ErrorHandler.Succeeded(hresult);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Gets the display location of the tasklist item. This is the same as the navigation
        /// location except for Venus which must have their original
        /// unmapped line numbers mapped through its buffer coordinator.
        /// </summary>
        protected VsTextSpan GetDisplayLocation()
        {
            var containedDocument = GetContainedDocumentFromWorkspace();

            if (containedDocument != null)
            {
                var displayLocation = new VsTextSpan()
                {
                    iStartLine  = this.Info.OriginalLine,
                    iStartIndex = this.Info.OriginalColumn,
                    iEndLine    = this.Info.OriginalLine,
                    iEndIndex   = this.Info.OriginalColumn
                };

                var containedLanguage     = containedDocument.ContainedLanguage;
                var bufferCoordinator     = containedLanguage.BufferCoordinator;
                var containedLanguageHost = containedLanguage.ContainedLanguageHost;

                var mappedLocation = new VsTextSpan[1];

                if (VSConstants.S_OK == bufferCoordinator.MapSecondaryToPrimarySpan(displayLocation, mappedLocation))
                {
                    return(mappedLocation[0]);
                }
                else if (VSConstants.S_OK == containedLanguageHost.GetNearestVisibleToken(displayLocation, mappedLocation))
                {
                    return(mappedLocation[0]);
                }
            }

            return(GetMappedLocation());
        }
        protected override int GetDefaultValue(CancellationToken cancellationToken, out string value, out int hasDefaultValue)
        {
            hasDefaultValue = 0;
            value = string.Empty;

            Document document;
            if (!TryGetDocument(out document))
            {
                return VSConstants.E_FAIL;
            }

            var surfaceBufferFieldSpan = new VsTextSpan[1];
            if (snippetExpansionClient.ExpansionSession.GetFieldSpan(FieldName, surfaceBufferFieldSpan) != VSConstants.S_OK)
            {
                return VSConstants.E_FAIL;
            }

            SnapshotSpan subjectBufferFieldSpan;
            if (!snippetExpansionClient.TryGetSubjectBufferSpan(surfaceBufferFieldSpan[0], out subjectBufferFieldSpan))
            {
                return VSConstants.E_FAIL;
            }

            return GetContainingClassName(document, subjectBufferFieldSpan, cancellationToken, ref value, ref hasDefaultValue);
        }
        private bool TryGetDocumentWithFullyQualifiedTypeName(Document document, out TextSpan updatedTextSpan, out Document documentWithFullyQualifiedTypeName)
        {
            documentWithFullyQualifiedTypeName = null;
            updatedTextSpan = default(TextSpan);

            var surfaceBufferFieldSpan = new VsTextSpan[1];

            if (snippetExpansionClient.ExpansionSession.GetFieldSpan(_fieldName, surfaceBufferFieldSpan) != VSConstants.S_OK)
            {
                return(false);
            }

            SnapshotSpan subjectBufferFieldSpan;

            if (!snippetExpansionClient.TryGetSubjectBufferSpan(surfaceBufferFieldSpan[0], out subjectBufferFieldSpan))
            {
                return(false);
            }

            var originalTextSpan = new TextSpan(subjectBufferFieldSpan.Start, subjectBufferFieldSpan.Length);

            updatedTextSpan = new TextSpan(subjectBufferFieldSpan.Start, _fullyQualifiedName.Length);

            var textChange = new TextChange(originalTextSpan, _fullyQualifiedName);
            var newText    = document.GetTextAsync(CancellationToken.None).WaitAndGetResult(CancellationToken.None).WithChanges(textChange);

            documentWithFullyQualifiedTypeName = document.WithText(newText);
            return(true);
        }
Exemplo n.º 14
0
        public static bool TryMapSpanFromSecondaryBufferToPrimaryBuffer(this VsTextSpan spanInSecondaryBuffer, Workspace workspace, DocumentId documentId, out VsTextSpan spanInPrimaryBuffer)
        {
            spanInPrimaryBuffer = default(VsTextSpan);

            var visualStudioWorkspace = workspace as VisualStudioWorkspaceImpl;
            if (visualStudioWorkspace == null)
            {
                return false;
            }

            var containedDocument = visualStudioWorkspace.GetHostDocument(documentId) as ContainedDocument;
            if (containedDocument == null)
            {
                return false;
            }

            var bufferCoordinator = containedDocument.ContainedLanguage.BufferCoordinator;

            var primary = new VsTextSpan[1];
            var hresult = bufferCoordinator.MapSecondaryToPrimarySpan(spanInSecondaryBuffer, primary);

            spanInPrimaryBuffer = primary[0];

            return ErrorHandler.Succeeded(hresult);
        }
Exemplo n.º 15
0
 public int GetLocationOfName(
     string pszName,
     out string?pbstrMkDoc,
     out VsTextSpan pspanLocation
     )
 {
     pbstrMkDoc    = null;
     pspanLocation = default;
     return(VSConstants.E_NOTIMPL);
 }
        protected override bool TryGetEnumTypeSymbol(
            CancellationToken cancellationToken,
            out ITypeSymbol typeSymbol
            )
        {
            typeSymbol = null;
            if (!TryGetDocument(out var document))
            {
                return(false);
            }

            var surfaceBufferFieldSpan = new VsTextSpan[1];

            if (
                snippetExpansionClient.ExpansionSession.GetFieldSpan(
                    SwitchExpressionField,
                    surfaceBufferFieldSpan
                    ) != VSConstants.S_OK
                )
            {
                return(false);
            }

            if (
                !snippetExpansionClient.TryGetSubjectBufferSpan(
                    surfaceBufferFieldSpan[0],
                    out var subjectBufferFieldSpan
                    )
                )
            {
                return(false);
            }

            var expressionSpan = subjectBufferFieldSpan.Span.ToTextSpan();

            var syntaxTree = document.GetSyntaxTreeSynchronously(cancellationToken);
            var token      = syntaxTree.FindTokenOnRightOfPosition(
                expressionSpan.Start,
                cancellationToken
                );
            var expressionNode = token.GetAncestor(n => n.Span == expressionSpan);

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

            var model = document
                        .GetSemanticModelAsync(cancellationToken)
                        .WaitAndGetResult(cancellationToken);

            typeSymbol = model.GetTypeInfo(expressionNode, cancellationToken).Type;

            return(typeSymbol != null);
        }
Exemplo n.º 17
0
        /// <summary>
        ///     This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.
        /// </summary>
        /// <param name="textSpan">This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.</param>
        /// <returns>This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.</returns>
        public static XmlDesignerBaseTextSpan ConvertFromVSTextSpan(VSTextSpan textSpan)
        {
            var ret = new XmlDesignerBaseTextSpan();

            ret.iStartIndex = textSpan.iStartIndex;
            ret.iStartLine  = textSpan.iStartLine;
            ret.iEndIndex   = textSpan.iEndIndex;
            ret.iEndLine    = textSpan.iEndLine;

            return(ret);
        }
Exemplo n.º 18
0
        public override string GetDataTipText(int line, int col, out Microsoft.VisualStudio.TextManager.Interop.TextSpan span)
        {
            span = new Microsoft.VisualStudio.TextManager.Interop.TextSpan();
            // can set a span here where the tool tip would be displayed

            /*span.iStartLine = 0;
             * span.iStartIndex = 1;
             * span.iEndLine = 0;
             * span.iEndIndex = 4;*/
            return("");
        }
Exemplo n.º 19
0
        // Internal for testing purposes
        internal static int GetPairExtentsWorker(ITextView textView, Workspace workspace, IBraceMatchingService braceMatcher, int iLine, int iIndex, TextSpan[] pSpan, CancellationToken cancellationToken)
        {
            pSpan[0].iStartLine = pSpan[0].iEndLine = iLine;
            pSpan[0].iStartIndex = pSpan[0].iEndIndex = iIndex;

            var pointInViewBuffer = textView.TextSnapshot.GetLineFromLineNumber(iLine).Start + iIndex;

            var subjectBuffer = textView.GetBufferContainingCaret();
            if (subjectBuffer != null)
            {
                // PointTrackingMode and PositionAffinity chosen arbitrarily.
                var positionInSubjectBuffer = textView.BufferGraph.MapDownToBuffer(pointInViewBuffer, PointTrackingMode.Positive, subjectBuffer, PositionAffinity.Successor);
                if (!positionInSubjectBuffer.HasValue)
                {
                    positionInSubjectBuffer = textView.BufferGraph.MapDownToBuffer(pointInViewBuffer, PointTrackingMode.Positive, subjectBuffer, PositionAffinity.Predecessor);
                }

                if (positionInSubjectBuffer.HasValue)
                {
                    var position = positionInSubjectBuffer.Value;

                    var document = subjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();
                    if (document != null)
                    {
                        var matchingSpan = braceMatcher.FindMatchingSpanAsync(document, position, cancellationToken).WaitAndGetResult(cancellationToken);

                        if (matchingSpan.HasValue)
                        {
                            var resultsInView = textView.GetSpanInView(matchingSpan.Value.ToSnapshotSpan(subjectBuffer.CurrentSnapshot)).ToList();
                            if (resultsInView.Count == 1)
                            {
                                var vsTextSpan = resultsInView[0].ToVsTextSpan();

                                if (matchingSpan.Value.Start < position)
                                {
                                    pSpan[0].iStartLine = vsTextSpan.iStartLine;
                                    pSpan[0].iStartIndex = vsTextSpan.iStartIndex;
                                }
                                else if (matchingSpan.Value.End > position)
                                {
                                    pSpan[0].iEndLine = vsTextSpan.iEndLine;
                                    pSpan[0].iEndIndex = vsTextSpan.iEndIndex;
                                }
                            }
                        }
                    }
                }
            }

            return VSConstants.S_OK;
        }
Exemplo n.º 20
0
        public override int ValidateBreakpointLocation(IVsTextBuffer buffer, int line, int col, TextSpan[] pCodeSpan)
        {
            var componentModel = ServiceProvider.GetComponentModel();
            var adapterFactoryService = componentModel.DefaultExportProvider.GetExport<IVsEditorAdaptersFactoryService>();
            ITextBuffer textBuffer = adapterFactoryService.Value.GetDataBuffer(buffer);

            ITextSnapshot snapshot = textBuffer.CurrentSnapshot;
            ITextSnapshotLine snapshotLine = snapshot.GetLineFromLineNumber(line);
            string lineText = snapshotLine.GetText();

            IList<IParseTree> statementTrees;
            IList<IToken> tokens;
            if (!LineStatementAnalyzer.TryGetLineStatements(textBuffer, line, out statementTrees, out tokens))
                return VSConstants.E_FAIL;

            IParseTree tree = null;
            for (int i = statementTrees.Count - 1; i >= 0; i--)
            {
                // want the last tree ending at or after col
                IParseTree current = statementTrees[i];
                if (current.SourceInterval.Length == 0)
                    continue;

                IToken token = tokens[current.SourceInterval.b];
                if (token.Line - 1 < line)
                    break;

                if (token.Line - 1 == line && (token.Column + token.StopIndex - token.StartIndex + 1) < col)
                    break;

                tree = current;
            }

            if (tree == null)
                return VSConstants.E_FAIL;

            IToken startToken = tokens[tree.SourceInterval.a];
            IToken stopToken = tokens[tree.SourceInterval.b];

            pCodeSpan[0].iStartLine = startToken.Line - 1;
            pCodeSpan[0].iStartIndex = startToken.Column;
            pCodeSpan[0].iEndLine = stopToken.Line - 1;
            pCodeSpan[0].iEndIndex = stopToken.Column + stopToken.StopIndex - stopToken.StartIndex + 1;
            return VSConstants.S_OK;
        }
Exemplo n.º 21
0
        private bool TryGetSpan(string fieldName, [NotNullWhen(true)] out TextSpan?switchExpressionSpan)
        {
            switchExpressionSpan = null;
            var surfaceBufferFieldSpan = new VsTextSpan[1];

            if (snippetExpansionClient.ExpansionSession?.GetFieldSpan(fieldName, surfaceBufferFieldSpan) != VSConstants.S_OK)
            {
                return(false);
            }

            if (!snippetExpansionClient.TryGetSubjectBufferSpan(surfaceBufferFieldSpan[0], out var subjectBufferFieldSpan))
            {
                return(false);
            }

            switchExpressionSpan = subjectBufferFieldSpan.Span.ToTextSpan();
            return(true);
        }
 int IVsLanguageDebugInfo.GetLocationOfName(
     string pszName,
     out string pbstrMkDoc,
     out TextSpan pspanLocation
     )
 {
     try
     {
         return(LanguageDebugInfo.GetLocationOfName(
                    pszName,
                    out pbstrMkDoc,
                    out pspanLocation
                    ));
     }
     catch (Exception e) when(FatalError.ReportAndCatch(e) && false)
     {
         throw ExceptionUtilities.Unreachable;
     }
 }
        private bool TryGetSimplifiedTypeName(string fullyQualifiedTypeName, string firstEnumMemberName, CancellationToken cancellationToken, out string simplifiedTypeName)
        {
            simplifiedTypeName = string.Empty;
            if (!TryGetDocument(out var document))
            {
                return false;
            }

            // Add the first switch case using the fully qualified type name, then simplify it in
            // that context
            var surfaceBufferFieldSpan = new VsTextSpan[1];
            if (snippetExpansionClient.ExpansionSession.GetFieldSpan(CaseGenerationLocationField, surfaceBufferFieldSpan) != VSConstants.S_OK)
            {
                return false;
            }

            if (!snippetExpansionClient.TryGetSubjectBufferSpan(surfaceBufferFieldSpan[0], out var subjectBufferFieldSpan))
            {
                return false;
            }

            return TryGetSimplifiedTypeNameInCaseContext(document, fullyQualifiedTypeName, firstEnumMemberName, subjectBufferFieldSpan.Start.Position, subjectBufferFieldSpan.End.Position, cancellationToken, out simplifiedTypeName);
        }
Exemplo n.º 24
0
        private bool TryGetFieldSpan([NotNullWhen(true)] out TextSpan?fieldSpan)
        {
            fieldSpan = null;
            var surfaceBufferFieldSpan = new VsTextSpan[1];

            if (snippetExpansionClient.ExpansionSession == null)
            {
                return(false);
            }

            if (snippetExpansionClient.ExpansionSession.GetFieldSpan(_fieldName, surfaceBufferFieldSpan) != VSConstants.S_OK)
            {
                return(false);
            }

            if (!snippetExpansionClient.TryGetSubjectBufferSpan(surfaceBufferFieldSpan[0], out var subjectBufferFieldSpan))
            {
                return(false);
            }

            fieldSpan = new TextSpan(subjectBufferFieldSpan.Start, subjectBufferFieldSpan.Length);
            return(true);
        }
        protected override void OnNavigate(EventArgs e)
        {
            ////base.OnNavigate(e);

            if (string.IsNullOrEmpty(this.Document))
            {
                return;
            }

            // We know the document is open, don't we?  This just forces it to the foreground/activates it...
            // Sadly, we get the old IVsTextView interface instead of the new ITextView one...
            IVsUIHierarchy hierarchy;
            uint           item;
            IVsWindowFrame frame;

            Microsoft.VisualStudio.TextManager.Interop.IVsTextView legacyTextView;

            VsShellUtilities.OpenDocument(
                this.serviceProvider,
                this.Document,
                VSConstants.LOGVIEWID.Any_guid,
                out hierarchy,
                out item,
                out frame,
                out legacyTextView);

            var legacySpan = new Microsoft.VisualStudio.TextManager.Interop.TextSpan();

            legacySpan.iStartLine  = this.Range.Start.Line;
            legacySpan.iStartIndex = this.Range.Start.Column;
            legacySpan.iEndLine    = this.Range.End.Line;
            legacySpan.iEndIndex   = this.Range.End.Column;

            legacyTextView.SetCaretPos(legacySpan.iEndLine, legacySpan.iEndIndex);
            legacyTextView.SetSelection(legacySpan.iStartLine, legacySpan.iStartIndex, legacySpan.iEndLine, legacySpan.iEndIndex);
            legacyTextView.EnsureSpanVisible(legacySpan);
        }
Exemplo n.º 26
0
 public int GetLocationOfName(string pszName, out string pbstrMkDoc, TextSpan[] pspanLocation)
 {
     pbstrMkDoc = null;
     return VSConstants.E_NOTIMPL;
 }
Exemplo n.º 27
0
        /// <summary>
        ///     This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.
        /// </summary>
        /// <param name="textSpan">This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.</param>
        /// <returns>This API supports the Entity Framework infrastructure and is not intended to be used directly from your code.</returns>
        public static XmlDesignerBaseTextSpan ConvertFromVSTextSpan(VSTextSpan textSpan)
        {
            var ret = new XmlDesignerBaseTextSpan();
            ret.iStartIndex = textSpan.iStartIndex;
            ret.iStartLine = textSpan.iStartLine;
            ret.iEndIndex = textSpan.iEndIndex;
            ret.iEndLine = textSpan.iEndLine;

            return ret;
        }
        /// <summary>
        /// Called by the debugger whenever it needs to determine a position of an active statement.
        /// E.g. the user clicks on a frame in a call stack.
        /// </summary>
        /// <remarks>
        /// Called when applying change, when setting current IP, a notification is received from 
        /// <see cref="IDebugEncNotify.NotifyEncUpdateCurrentStatement"/>, etc.
        /// In addition this API is exposed on IDebugENC2 COM interface so it can be used anytime by other components.
        /// </remarks>
        public int GetCurrentActiveStatementPosition(uint vsId, VsTextSpan[] ptsNewPosition)
        {
            try
            {
                using (NonReentrantContext)
                {
                    Debug.Assert(IsDebuggable);

                    var session = _encService.EditSession;
                    var ids = _activeStatementIds;

                    // Can be called anytime, even outside of an edit/debug session.
                    // We might not have an active statement available if PDB got out of sync with the source.
                    ActiveStatementId id;
                    if (session == null || ids == null || !ids.TryGetValue(vsId, out id))
                    {
                        log.Write("GetCurrentActiveStatementPosition failed for AS {0}.", vsId);
                        return VSConstants.E_FAIL;
                    }

                    Document document = _vsProject.VisualStudioWorkspace.CurrentSolution.GetDocument(id.DocumentId);
                    SourceText text = document.GetTextAsync(default(CancellationToken)).Result;

                    // Try to get spans from the tracking service first.
                    // We might get an imprecise result if the document analysis hasn't been finished yet and 
                    // the active statement has structurally changed, but that's ok. The user won't see an updated tag
                    // for the statement until the analysis finishes anyways.
                    TextSpan span;
                    LinePositionSpan lineSpan;
                    if (_trackingService.TryGetSpan(id, text, out span) && span.Length > 0)
                    {
                        lineSpan = text.Lines.GetLinePositionSpan(span);
                    }
                    else
                    {
                        var activeSpans = session.GetDocumentAnalysis(document).GetValue(default(CancellationToken)).ActiveStatements;
                        if (activeSpans.IsDefault)
                        {
                            // The document has syntax errors and the tracking span is gone.
                            log.Write("Position not available for AS {0} due to syntax errors", vsId);
                            return VSConstants.E_FAIL;
                        }

                        lineSpan = activeSpans[id.Ordinal];
                    }

                    ptsNewPosition[0] = lineSpan.ToVsTextSpan();
                    log.DebugWrite("AS position: {0} {1} {2}", vsId, lineSpan,
                        session.BaseActiveStatements[id.DocumentId][id.Ordinal].Flags);

                    return VSConstants.S_OK;
                }
            }
            catch (Exception e) when (FatalError.ReportWithoutCrash(e))
            {
                return VSConstants.E_FAIL;
            }
        }
        /// <summary>
        /// Called when changes are being applied.
        /// </summary>
        /// <param name="exceptionRegionId">
        /// The value of <see cref="ShellInterop.ENC_EXCEPTION_SPAN.id"/>. 
        /// Set by <see cref="GetExceptionSpans(uint, ShellInterop.ENC_EXCEPTION_SPAN[], ref uint)"/> to the index into <see cref="_exceptionRegions"/>. 
        /// </param>
        /// <param name="ptsNewPosition">Output value holder.</param>
        public int GetCurrentExceptionSpanPosition(uint exceptionRegionId, VsTextSpan[] ptsNewPosition)
        {
            try
            {
                using (NonReentrantContext)
                {
                    Debug.Assert(IsDebuggable);
                    Debug.Assert(_encService.EditSession != null);
                    Debug.Assert(!_encService.EditSession.StoppedAtException);
                    Debug.Assert(ptsNewPosition.Length == 1);

                    var exceptionRegion = _exceptionRegions[(int)exceptionRegionId];

                    var session = _encService.EditSession;
                    var asid = _activeStatementIds[exceptionRegion.ActiveStatementId];

                    var document = _projectBeingEmitted.GetDocument(asid.DocumentId);
                    var analysis = session.GetDocumentAnalysis(document).GetValue(default(CancellationToken));
                    var regions = analysis.ExceptionRegions;

                    // the method shouldn't be called in presence of errors:
                    Debug.Assert(!analysis.HasChangesAndErrors);
                    Debug.Assert(!regions.IsDefault);

                    // Absence of rude edits guarantees that the exception regions around AS haven't semantically changed.
                    // Only their spans might have changed.
                    ptsNewPosition[0] = regions[asid.Ordinal][exceptionRegion.Ordinal].ToVsTextSpan();
                }

                return VSConstants.S_OK;
            }
            catch (Exception e) when (FatalError.ReportWithoutCrash(e))
            {
                return VSConstants.E_FAIL;
            }
        }
Exemplo n.º 30
0
        public override string Goto(Microsoft.VisualStudio.VSConstants.VSStd97CmdID cmd, Microsoft.VisualStudio.TextManager.Interop.IVsTextView textView, int line, int col, out Microsoft.VisualStudio.TextManager.Interop.TextSpan span)
        {
            span = new Microsoft.VisualStudio.TextManager.Interop.TextSpan();

            return(null);
        }
Exemplo n.º 31
0
 internal static LinePositionSpan ToLinePositionSpan(this VsTextSpan span)
 => new LinePositionSpan(new LinePosition(span.iStartLine, span.iStartIndex), new LinePosition(span.iEndLine, span.iEndIndex));
 public int GetCurrentActiveStatementPosition(uint id, VsTextSpan[] ptsNewPosition)
 {
     return EditAndContinueImplOpt.GetCurrentActiveStatementPosition(id, ptsNewPosition);
 }
Exemplo n.º 33
0
 public static SnapshotSpan GetSpan(this ITextSnapshot snapshot, VsTextSpan textSpan)
 => TryGetSpan(snapshot, textSpan).Value;
 public int GetCurrentExceptionSpanPosition(uint id, VsTextSpan[] ptsNewPosition)
 {
     return EditAndContinueImplOpt.GetCurrentExceptionSpanPosition(id, ptsNewPosition);
 }
Exemplo n.º 35
0
        public override string Goto(Microsoft.VisualStudio.VSConstants.VSStd97CmdID cmd, Microsoft.VisualStudio.TextManager.Interop.IVsTextView textView, int line, int col, out Microsoft.VisualStudio.TextManager.Interop.TextSpan span)
        {
            span = new Microsoft.VisualStudio.TextManager.Interop.TextSpan();

            return null;
        }
Exemplo n.º 36
0
 public override string GetDataTipText(int line, int col, out Microsoft.VisualStudio.TextManager.Interop.TextSpan span)
 {
     span = new Microsoft.VisualStudio.TextManager.Interop.TextSpan();
     return null;
 }
Exemplo n.º 37
0
 public static SnapshotSpan GetSpan(this ITextSnapshot snapshot, VsTextSpan textSpan)
 {
     return TryGetSpan(snapshot, textSpan).Value;
 }
Exemplo n.º 38
0
 public static SnapshotSpan? TryGetSpan(this ITextSnapshot snapshot, VsTextSpan textSpan)
 {
     return snapshot.TryGetSpan(textSpan.iStartLine, textSpan.iStartIndex, textSpan.iEndLine, textSpan.iEndIndex);
 }
Exemplo n.º 39
0
        // Internal for testing purposes
        internal static int GetPairExtentsWorker(ITextView textView, Workspace workspace, IBraceMatchingService braceMatcher, int iLine, int iIndex, TextSpan[] pSpan, bool extendSelection, CancellationToken cancellationToken)
        {
            pSpan[0].iStartLine = pSpan[0].iEndLine = iLine;
            pSpan[0].iStartIndex = pSpan[0].iEndIndex = iIndex;

            var pointInViewBuffer = textView.TextSnapshot.GetLineFromLineNumber(iLine).Start + iIndex;

            var subjectBuffer = textView.GetBufferContainingCaret();
            if (subjectBuffer != null)
            {
                // PointTrackingMode and PositionAffinity chosen arbitrarily.
                var positionInSubjectBuffer = textView.BufferGraph.MapDownToBuffer(pointInViewBuffer, PointTrackingMode.Positive, subjectBuffer, PositionAffinity.Successor);
                if (!positionInSubjectBuffer.HasValue)
                {
                    positionInSubjectBuffer = textView.BufferGraph.MapDownToBuffer(pointInViewBuffer, PointTrackingMode.Positive, subjectBuffer, PositionAffinity.Predecessor);
                }

                if (positionInSubjectBuffer.HasValue)
                {
                    var position = positionInSubjectBuffer.Value;

                    var document = subjectBuffer.CurrentSnapshot.GetOpenDocumentInCurrentContextWithChanges();
                    if (document != null)
                    {
                        var matchingSpan = braceMatcher.FindMatchingSpanAsync(document, position, cancellationToken).WaitAndGetResult(cancellationToken);

                        if (matchingSpan.HasValue)
                        {
                            var resultsInView = textView.GetSpanInView(matchingSpan.Value.ToSnapshotSpan(subjectBuffer.CurrentSnapshot)).ToList();
                            if (resultsInView.Count == 1)
                            {
                                var vsTextSpan = resultsInView[0].ToVsTextSpan();

                                // caret is at close parenthesis
                                if (matchingSpan.Value.Start < position)
                                {
                                    pSpan[0].iStartLine = vsTextSpan.iStartLine;
                                    pSpan[0].iStartIndex = vsTextSpan.iStartIndex;

                                    // For text selection using goto matching brace, tweak spans to suit the VS editor's behavior.
                                    // The vs editor sets selection for GotoBraceExt (Ctrl + Shift + ]) like so :
                                    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                    // if (fExtendSelection)
                                    // {
                                    //      textSpan.iEndIndex++;
                                    //      this.SetSelection(textSpan.iStartLine, textSpan.iStartIndex, textSpan.iEndLine, textSpan.iEndIndex);
                                    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                    // Notice a couple of things: it arbitrarily increments EndIndex by 1 and does nothing similar for StartIndex.
                                    // So, if we're extending selection: 
                                    //    case a: set EndIndex to left of closing parenthesis -- ^}
                                    //            this adjustment is for any of the four cases where caret could be. left or right of open or close parenthesis -- ^{^ ^}^
                                    //    case b: set StartIndex to left of opening parenthesis -- ^{
                                    //            this adjustment is for cases where caret was originally to the right of the open parenthesis -- {^ }

                                    // if selecting, adjust end position by using the matching opening span that we just computed.
                                    if (extendSelection)
                                    {
                                        // case a.
                                        var closingSpans = braceMatcher.FindMatchingSpanAsync(document, matchingSpan.Value.Start, cancellationToken).WaitAndGetResult(cancellationToken);
                                        var vsClosingSpans = textView.GetSpanInView(closingSpans.Value.ToSnapshotSpan(subjectBuffer.CurrentSnapshot)).ToList().First().ToVsTextSpan();
                                        pSpan[0].iEndIndex = vsClosingSpans.iStartIndex;
                                    }
                                }
                                else if (matchingSpan.Value.End > position) // caret is at open parenthesis
                                {
                                    pSpan[0].iEndLine = vsTextSpan.iEndLine;
                                    pSpan[0].iEndIndex = vsTextSpan.iEndIndex;

                                    // if selecting, adjust start position by using the matching closing span that we computed
                                    if (extendSelection)
                                    {
                                        // case a.
                                        pSpan[0].iEndIndex = vsTextSpan.iStartIndex;

                                        // case b.
                                        var openingSpans = braceMatcher.FindMatchingSpanAsync(document, matchingSpan.Value.End, cancellationToken).WaitAndGetResult(cancellationToken);
                                        var vsOpeningSpans = textView.GetSpanInView(openingSpans.Value.ToSnapshotSpan(subjectBuffer.CurrentSnapshot)).ToList().First().ToVsTextSpan();
                                        pSpan[0].iStartIndex = vsOpeningSpans.iStartIndex;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return VSConstants.S_OK;
        }
 public int GetCurrentActiveStatementPosition(uint id, VsTextSpan[] ptsNewPosition)
 {
     return EditAndContinueImplOpt?.GetCurrentActiveStatementPosition(id, ptsNewPosition) ?? VSConstants.E_FAIL;
 }
Exemplo n.º 41
0
 public int GetLocationOfName(string pszName, out string pbstrMkDoc, out TextSpan pspanLocation)
 {
     return(this.LanguageDebugInfo.GetLocationOfName(pszName, out pbstrMkDoc, out pspanLocation));
 }
Exemplo n.º 42
0
 public int ValidateBreakpointLocation(IVsTextBuffer pBuffer, int iLine, int iCol, TextSpan[] pCodeSpan)
 {
     return VSConstants.E_NOTIMPL;
 }
Exemplo n.º 43
0
 public override string GetDataTipText(int line, int col, out Microsoft.VisualStudio.TextManager.Interop.TextSpan span)
 {
     span = new Microsoft.VisualStudio.TextManager.Interop.TextSpan();
     return(null);
 }
Exemplo n.º 44
0
 public static SnapshotSpan GetSpan(this ITextSnapshot snapshot, VsTextSpan textSpan)
 {
     return(TryGetSpan(snapshot, textSpan).Value);
 }