Ejemplo n.º 1
0
        private HighlightingInfo[] GetHighlightings()
        {
#if RESHARPER_60_OR_NEWER
            var projectFile = DaemonProcess.SourceFile.ToProjectFile();
            if (projectFile == null || !projectFile.IsValid())
#else
            IProjectFile projectFile = DaemonProcess.ProjectFile;
            if (!projectFile.IsValid)
#endif
            { return(EmptyArray <HighlightingInfo> .Instance); }

            var state = ProjectFileState.GetFileState(projectFile);
            if (state == null)
            {
                return(EmptyArray <HighlightingInfo> .Instance);
            }

            var highlightings = new List <HighlightingInfo>();

            foreach (AnnotationState annotation in state.Annotations)
            {
                IDeclaredElement declaredElement = annotation.GetDeclaredElement();
                if (declaredElement != null && declaredElement.IsValid())
                {
#if RESHARPER_60_OR_NEWER
                    foreach (IDeclaration declaration in declaredElement.GetDeclarationsIn(DaemonProcess.SourceFile))
#else
                    foreach (IDeclaration declaration in declaredElement.GetDeclarationsIn(projectFile))
#endif
                    {
                        if (declaration.IsValid())
                        {
                            ReSharperDocumentRange range = declaration.GetNameDocumentRange();
#if RESHARPER_31 || RESHARPER_40 || RESHARPER_41
                            if (range.IsValid)
#else
                            if (range.IsValid())
#endif
                            {
                                var annotationHighlighting = AnnotationHighlighting.CreateHighlighting(annotation);
#if RESHARPER_60_OR_NEWER
                                var highlightingInfo = new HighlightingInfo(range, annotationHighlighting, null, null);
#else
                                var highlightingInfo = new HighlightingInfo(range, annotationHighlighting);
#endif
                                highlightings.Add(highlightingInfo);
                            }
                        }
                    }
                }
            }

            return(highlightings.ToArray());
        }
        /// <summary>
        /// Gets the location associated with a declared element.
        /// </summary>
        /// <param name="declaredElement">The declared element.</param>
        /// <returns>The resulting code location.</returns>
        protected static CodeLocation GetDeclaredElementSourceLocation(IDeclaredElement declaredElement)
        {
            IList <IDeclaration> decl = declaredElement.GetDeclarations();

            if (decl.Count == 0)
            {
                return(CodeLocation.Unknown);
            }

            ReSharperDocumentRange range = decl[0].GetDocumentRange();

#if RESHARPER_31 || RESHARPER_40 || RESHARPER_41
            bool isValid = range.IsValid;
#else
            bool isValid = range.IsValid();
#endif
            if (isValid)
            {
                return(CodeLocation.Unknown);
            }

#if RESHARPER_60_OR_NEWER
            var projectFile = decl[0].GetSourceFile().ToProjectFile();
#else
            var projectFile = decl[0].GetProjectFile();
#endif
            if (projectFile == null)
            {
                return(CodeLocation.Unknown);
            }

            string         filename = projectFile.Location.FullPath;
            DocumentCoords start    = range.Document.GetCoordsByOffset(range.TextRange.StartOffset);

#if !RESHARPER_50_OR_NEWER
            return(new CodeLocation(filename, start.Line, start.Column));
#else
            return(new CodeLocation(filename, (int)start.Line.Plus1(), (int)start.Column.Plus1()));
#endif
        }