Example #1
0
        private static int?FallbackAttributeCompletionHandler(XmlInfo info, ITextDocument textDoc, ITextView textView, IWorkspaceManager workspaceManager)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            if ((info.AttributeName == "Include" || info.AttributeName == "Update" || info.AttributeName == "Exclude" || info.AttributeName == "Remove"))
            {
                string            relativePath = info.AttributeValue;
                IWorkspace        workspace    = workspaceManager.GetWorkspace(textDoc.FilePath);
                List <Definition> matchedItems = workspace.GetItemProvenance(relativePath);

                if (matchedItems.Count == 1)
                {
                    string   absolutePath = Path.Combine(Path.GetDirectoryName(textDoc.FilePath), matchedItems[0].File);
                    FileInfo fileInfo     = new FileInfo(absolutePath);

                    if (fileInfo.Exists)
                    {
                        ServiceUtil.DTE.ItemOperations.OpenFile(fileInfo.FullName);
                        return(VSConstants.S_OK);
                    }
                }

                //Don't return the result of show in find all references, the caret may also be in a symbol,
                //  where we'd also want to go to that definition
                ShowInFar("Item Provenance", matchedItems);
            }

            return(null);
        }
Example #2
0
        private static int?HandleGoToDefinitionOnProjectReference(XmlInfo info, ITextDocument textDoc, ITextView textView, IWorkspaceManager workspaceManager)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (info.AttributeName == "Include")
            {
                string            relativePath = info.AttributeValue;
                IWorkspace        workspace    = workspaceManager.GetWorkspace(textDoc.FilePath);
                List <Definition> matchedItems = workspace.GetItems(relativePath);

                if (matchedItems.Count == 1)
                {
                    string   absolutePath = Path.Combine(Path.GetDirectoryName(textDoc.FilePath), matchedItems[0].File);
                    FileInfo fileInfo     = new FileInfo(absolutePath);
                    if (fileInfo.Exists)
                    {
                        ServiceUtil.DTE.ItemOperations.OpenFile(fileInfo.FullName);
                        return(VSConstants.S_OK);
                        //ServiceUtil.DTE.Commands.Raise(VSConstants.CMDSETID.StandardCommandSet2K_string, (int)EditProjectFileCommandId, ref unusedArgs, ref unusedArgs);
                    }
                }
            }

            return(null);
        }
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            if (pguidCmdGroup == _vSStd97CmdIDGuid && nCmdID == (uint)VSConstants.VSStd97CmdID.GotoDefn)
            {
                TextView.TextBuffer.Properties.TryGetProperty <ITextDocument>(typeof(ITextDocument), out ITextDocument textDoc);

                if (PackageCompletionSource.IsInRangeForPackageCompletion(TextView.TextSnapshot, TextView.Caret.Position.BufferPosition.Position, out Span targetSpan, out string packageName, out string packageVersion, out string completionType))
                {
                    if (PackageExistsOnNuGet(packageName, packageVersion, out string url))
                    {
                        System.Diagnostics.Process.Start(url);
                        return(VSConstants.S_OK);
                    }
                }

                IWorkspace        workspace   = _workspaceManager.GetWorkspace(textDoc.FilePath);
                List <Definition> definitions = workspace.ResolveDefinition(textDoc.FilePath, TextView.TextSnapshot.GetText(), TextView.Caret.Position.BufferPosition.Position);

                if (definitions.Count == 1)
                {
                    DTE dte = ServiceProvider.GlobalProvider.GetService(typeof(DTE)) as DTE;
                    dte.MainWindow.Activate();

                    using (var state = new NewDocumentStateScope(Microsoft.VisualStudio.Shell.Interop.__VSNEWDOCUMENTSTATE.NDS_Provisional, Guid.Parse(ProjectFileToolsPackage.PackageGuidString)))
                    {
                        EnvDTE.Window w = dte.ItemOperations.OpenFile(definitions[0].File, EnvDTE.Constants.vsViewKindTextView);

                        if (definitions[0].Line.HasValue)
                        {
                            ((EnvDTE.TextSelection)dte.ActiveDocument.Selection).GotoLine(definitions[0].Line.Value, true);
                        }
                    }

                    return(VSConstants.S_OK);
                }

                else if (definitions.Count > 1)
                {
                    IFindAllReferencesService farService = (IFindAllReferencesService)Package.GetGlobalService(typeof(SVsFindAllReferences));
                    FarDataSource             dataSource = new FarDataSource(1);
                    dataSource.Snapshots[0] = new FarDataSnapshot(definitions);

                    IFindAllReferencesWindow farWindow   = farService.StartSearch(definitions[0].Type);
                    ITableManager            _farManager = farWindow.Manager;
                    _farManager.AddSource(dataSource);

                    dataSource.Sink.IsStable = false;
                    dataSource.Sink.AddSnapshot(dataSource.Snapshots[0]);
                    dataSource.Sink.IsStable = true;

                    return(VSConstants.S_OK);
                }
            }

            return(Next?.Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut) ?? (int)Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED);
        }
Example #4
0
        public async Task <QuickInfoItem> GetQuickInfoItemAsync(IAsyncQuickInfoSession session, CancellationToken cancellationToken)
        {
            if (!session.TextView.TextBuffer.Properties.TryGetProperty(typeof(ITextDocument), out ITextDocument textDoc))
            {
                return(null);
            }

            SnapshotPoint?triggerPoint = session.GetTriggerPoint(session.TextView.TextSnapshot);

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

            int pos = triggerPoint.Value.Position;

            if (!PackageCompletionSource.IsInRangeForPackageCompletion(session.TextView.TextSnapshot, pos, out Span s, out string packageId, out string packageVersion, out string type))
            {
                XmlInfo info = XmlTools.GetXmlInfo(session.TextView.TextSnapshot, pos);

                if (info != null)
                {
                    IWorkspace    workspace      = workspace = _workspaceManager.GetWorkspace(textDoc.FilePath);
                    string        evaluatedValue = workspace.GetEvaluatedPropertyValue(info.AttributeValue);
                    ITrackingSpan target         = session.TextView.TextSnapshot.CreateTrackingSpan(new Span(info.AttributeValueStart, info.AttributeValueLength), SpanTrackingMode.EdgeNegative);

                    if (info.AttributeName == "Condition")
                    {
                        try
                        {
                            bool isTrue = workspace.EvaluateCondition(info.AttributeValue);
                            evaluatedValue = $"Expanded value: {evaluatedValue}\nEvaluation result: {isTrue}";
                            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                            return(new QuickInfoItem(target, evaluatedValue));
                        }
                        catch (Exception ex)
                        {
                            Debug.Fail(ex.ToString());
                        }
                    }
                    else
                    {
                        evaluatedValue = $"Value(s):\n    {string.Join("\n    ", evaluatedValue.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))}";
                        await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                        return(new QuickInfoItem(target, evaluatedValue));
                    }
                }
            }
Example #5
0
        private int?HandleFindAllReferences()
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            if (!TextView.TextBuffer.Properties.TryGetProperty(typeof(ITextDocument), out ITextDocument textDoc))
            {
                return(null);
            }

            XmlInfo info = XmlTools.GetXmlInfo(TextView.TextSnapshot, TextView.Caret.Position.BufferPosition.Position);

            if (info != null)
            {
                if (info.AttributeName == "Include" || info.AttributeName == "Update" || info.AttributeName == "Exclude" || info.AttributeName == "Remove")
                {
                    string            relativePath = info.AttributeValue;
                    IWorkspace        workspace    = _workspaceManager.GetWorkspace(textDoc.FilePath);
                    List <Definition> matchedItems = workspace.GetItems(relativePath);

                    if (matchedItems.Count == 1)
                    {
                        string   absolutePath = Path.Combine(Path.GetDirectoryName(textDoc.FilePath), matchedItems[0].File);
                        FileInfo fileInfo     = new FileInfo(absolutePath);

                        if (fileInfo.Exists)
                        {
                            ServiceUtil.DTE.ItemOperations.OpenFile(fileInfo.FullName);
                            return(VSConstants.S_OK);
                        }
                    }

                    return(ShowInFar("Files Matching Glob", matchedItems));
                }
            }

            return(null);
        }