public SuggestedHandlerCompletionData (MonoDevelop.Projects.Project project, CodeMemberMethod methodInfo, INamedTypeSymbol codeBehindClass, Location codeBehindClassLocation)
		{
			this.project = project;
			this.methodInfo = methodInfo;
			this.codeBehindClass = codeBehindClass;
			this.codeBehindClassLocation = codeBehindClassLocation;
		}
            private SimpleDiagnostic(
                DiagnosticDescriptor descriptor,
                DiagnosticSeverity severity,
                int warningLevel,
                Location location,
                IEnumerable<Location> additionalLocations,
                object[] messageArgs,
                ImmutableDictionary<string, string> properties,
                bool isSuppressed)
            {
                if ((warningLevel == 0 && severity != DiagnosticSeverity.Error) ||
                    (warningLevel != 0 && severity == DiagnosticSeverity.Error))
                {
                    throw new ArgumentException(nameof(warningLevel));
                }

                if (descriptor == null)
                {
                    throw new ArgumentNullException(nameof(descriptor));
                }

                _descriptor = descriptor;
                _severity = severity;
                _warningLevel = warningLevel;
                _location = location ?? Location.None;
                _additionalLocations = additionalLocations?.ToImmutableArray() ?? SpecializedCollections.EmptyReadOnlyList<Location>();
                _messageArgs = messageArgs ?? Array.Empty<object>();
                _properties = properties ?? ImmutableDictionary<string, string>.Empty;
                _isSuppressed = isSuppressed;
            }
Пример #3
0
            internal SimpleDiagnostic(string id, string category, string message, DiagnosticSeverity severity, bool isEnabledByDefault,
                                      int warningLevel, bool isWarningAsError, Location location,
                                      IEnumerable<Location> additionalLocations)
            {
                if (isWarningAsError && severity != DiagnosticSeverity.Warning)
                {
                    throw new ArgumentException("isWarningAsError");
                }

                if ((warningLevel == 0 && severity == DiagnosticSeverity.Warning) ||
                    (warningLevel != 0 && severity != DiagnosticSeverity.Warning))
                {
                    throw new ArgumentException("warningLevel");
                }

                this.id = id;
                this.category = category;
                this.message = message;
                this.severity = severity;
                this.isEnabledByDefault = isEnabledByDefault;
                this.warningLevel = warningLevel;
                this.isWarningAsError = isWarningAsError;
                this.location = location;
                this.additionalLocations = additionalLocations == null ? SpecializedCollections.EmptyReadOnlyList<Location>() : additionalLocations.ToImmutableArray();
            }
Пример #4
0
        private static StatementRange MapBlockSyntax(TextSpan span, SyntaxNode node)
        {
            var  block = (BlockSyntax)node;
            bool start = Math.Abs(block.SpanStart - span.Start) < Math.Abs(block.Span.End - span.Start);

            Location             location = block.GetLocation();
            FileLinePositionSpan mapped   = location.GetMappedLineSpan();

            if (start)
            {
                return(new StatementRange
                {
                    StartLine = mapped.StartLinePosition.Line,
                    StartColumn = mapped.StartLinePosition.Character,
                    EndLine = mapped.StartLinePosition.Line,
                    EndColumn = mapped.StartLinePosition.Character + 1,
                });
            }
            return(new StatementRange
            {
                StartLine = mapped.EndLinePosition.Line,
                StartColumn = mapped.EndLinePosition.Character - 1,
                EndLine = mapped.EndLinePosition.Line,
                EndColumn = mapped.EndLinePosition.Character,
            });
        }
        private QuickFix ConvertSymbol(ISymbol symbol, Location location)
        {
            var lineSpan = location.GetLineSpan();
            var path = lineSpan.Path;
            var documents = _workspace.GetDocuments(path);

            var format = SymbolDisplayFormat.MinimallyQualifiedFormat;
            format = format.WithMemberOptions(format.MemberOptions
                                              ^ SymbolDisplayMemberOptions.IncludeContainingType
                                              ^ SymbolDisplayMemberOptions.IncludeType);

            format = format.WithKindOptions(SymbolDisplayKindOptions.None);

            return new SymbolLocation
            {
                Text = symbol.ToDisplayString(format),
                Kind = symbol.GetKind(),
                FileName = path,
                Line = lineSpan.StartLinePosition.Line + 1,
                Column = lineSpan.StartLinePosition.Character + 1,
                EndLine = lineSpan.EndLinePosition.Line + 1,
                EndColumn = lineSpan.EndLinePosition.Character + 1,
                Projects = documents.Select(document => document.Project.Name).ToArray()
            };
        }
        private static async Task<Document> GetTransformedDocumentAsync(Document document, Location location, CancellationToken cancellationToken)
        {
            var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
            var sourceSpan = location.SourceSpan;

            return document.WithText(text.WithChanges(GetTextChange(text, sourceSpan)));
        }
Пример #7
0
            public Session(
                RenameLocations renameLocationSet,
                Location renameSymbolDeclarationLocation,
                string originalText,
                string replacementText,
                OptionSet optionSet,
                Func<IEnumerable<ISymbol>, bool?> newSymbolsAreValid,
                CancellationToken cancellationToken)
            {
                _renameLocationSet = renameLocationSet;
                _renameSymbolDeclarationLocation = renameSymbolDeclarationLocation;
                _originalText = originalText;
                _replacementText = replacementText;
                _optionSet = optionSet;
                _hasConflictCallback = newSymbolsAreValid;
                _cancellationToken = cancellationToken;

                _renamedSymbolDeclarationAnnotation = new RenameAnnotation();

                _conflictLocations = SpecializedCollections.EmptySet<ConflictLocationInfo>();
                _replacementTextValid = true;
                _possibleNameConflicts = new List<string>();

                // only process documents which possibly contain the identifiers.
                _documentsIdsToBeCheckedForConflict = new HashSet<DocumentId>();
                _documentIdOfRenameSymbolDeclaration = renameLocationSet.Solution.GetDocument(renameSymbolDeclarationLocation.SourceTree).Id;

                _renameAnnotations = new AnnotationTable<RenameAnnotation>(RenameAnnotation.Kind);
            }
        /// <inheritdoc/>
        protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, DocumentationCommentTriviaSyntax documentation, XmlNodeSyntax syntax, XElement completeDocumentation, Location[] diagnosticLocations)
        {
            if (syntax == null)
            {
                return;
            }

            if (completeDocumentation != null)
            {
                XElement summaryNode = completeDocumentation.Nodes().OfType<XElement>().FirstOrDefault(element => element.Name == XmlCommentHelper.SummaryXmlTag);
                if (summaryNode == null)
                {
                    // Handled by SA1604
                    return;
                }

                if (!XmlCommentHelper.IsConsideredEmpty(summaryNode))
                {
                    return;
                }
            }
            else
            {
                if (!XmlCommentHelper.IsConsideredEmpty(syntax))
                {
                    return;
                }
            }

            foreach (var location in diagnosticLocations)
            {
                context.ReportDiagnostic(Diagnostic.Create(Descriptor, location));
            }
        }
 /// <inheritdoc/>
 protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, XmlNodeSyntax syntax, Location diagnosticLocation)
 {
     if (syntax != null && XmlCommentHelper.IsConsideredEmpty(syntax))
     {
         context.ReportDiagnostic(Diagnostic.Create(Descriptor, diagnosticLocation));
     }
 }
		public CodeGenerationOptions(
			Location contextLocation = null,
			Location afterThisLocation = null,
			Location beforeThisLocation = null,
			bool addImports = true,
			bool placeSystemNamespaceFirst = true,
			IEnumerable<INamespaceSymbol> additionalImports = null,
			bool generateMembers = true,
			bool mergeNestedNamespaces = true,
			bool mergeAttributes = true,
			bool generateDefaultAccessibility = true,
			bool generateMethodBodies = true,
			bool generateDocumentationComments = false,
			bool autoInsertionLocation = true,
			bool reuseSyntax = false)
		{
			instance = Activator.CreateInstance (typeInfo, new object[] {
				contextLocation,
				afterThisLocation,
				beforeThisLocation,
				addImports,
				placeSystemNamespaceFirst,
				additionalImports,
				generateMembers,
				mergeNestedNamespaces,
				mergeAttributes,
				generateDefaultAccessibility,
				generateMethodBodies,
				generateDocumentationComments,
				autoInsertionLocation,
				reuseSyntax
			});
		}
        /// <inheritdoc/>
        protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, DocumentationCommentTriviaSyntax documentation, XmlNodeSyntax syntax, XElement completeDocumentation, Location[] diagnosticLocations)
        {
            if (completeDocumentation != null)
            {
                // We are working with an <include> element
                if (completeDocumentation.Nodes().OfType<XElement>().Any(element => element.Name == XmlCommentHelper.SummaryXmlTag))
                {
                    return;
                }

                if (completeDocumentation.Nodes().OfType<XElement>().Any(element => element.Name == XmlCommentHelper.InheritdocXmlTag))
                {
                    // Ignore nodes with an <inheritdoc/> tag in the included XML.
                    return;
                }
            }
            else
            {
                if (syntax != null)
                {
                    return;
                }

                if (documentation?.Content.GetFirstXmlElement(XmlCommentHelper.InheritdocXmlTag) != null)
                {
                    // Ignore nodes with an <inheritdoc/> tag.
                    return;
                }
            }

            foreach (var location in diagnosticLocations)
            {
                context.ReportDiagnostic(Diagnostic.Create(Descriptor, location));
            }
        }
Пример #12
0
        private static MITextPosition MapBlockSyntax(TextSpan span, SyntaxNode node, string fileName)
        {
            var  block = (BlockSyntax)node;
            bool start = Math.Abs(block.SpanStart - span.Start) < Math.Abs(block.Span.End - span.Start);

            Location             location = block.GetLocation();
            FileLinePositionSpan mapped   = location.GetMappedLineSpan();

            if (start)
            {
                return(new MITextPosition(fileName,
                                          new TEXT_POSITION()
                {
                    dwLine = (uint)mapped.StartLinePosition.Line, dwColumn = (uint)mapped.StartLinePosition.Character
                },
                                          new TEXT_POSITION()
                {
                    dwLine = (uint)mapped.StartLinePosition.Line, dwColumn = (uint)mapped.StartLinePosition.Character + 1
                }));
            }

            return(new MITextPosition(fileName,
                                      new TEXT_POSITION()
            {
                dwLine = (uint)mapped.EndLinePosition.Line, dwColumn = (uint)mapped.EndLinePosition.Character - 1
            },
                                      new TEXT_POSITION()
            {
                dwLine = (uint)mapped.EndLinePosition.Line, dwColumn = (uint)mapped.EndLinePosition.Character
            }));
        }
            private SimpleDiagnostic(
                DiagnosticDescriptor descriptor,
                DiagnosticSeverity severity,
                int warningLevel,
                Location location,
                IEnumerable<Location> additionalLocations,
                object[] messageArgs)
            {
                if ((warningLevel == 0 && severity != DiagnosticSeverity.Error) ||
                    (warningLevel != 0 && severity == DiagnosticSeverity.Error))
                {
                    throw new ArgumentException(nameof(warningLevel));
                }

                if(descriptor == null)
                {
                    throw new ArgumentNullException(nameof(descriptor));
                }

                _descriptor = descriptor;
                _severity = severity;
                _warningLevel = warningLevel;
                _location = location ?? Location.None;
                _additionalLocations = additionalLocations == null ? SpecializedCollections.EmptyReadOnlyList<Location>() : additionalLocations.ToImmutableArray();
                _messageArgs = messageArgs ?? SpecializedCollections.EmptyArray<object>();
            }
 /// <inheritdoc/>
 protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, XmlNodeSyntax syntax, Location diagnosticLocation)
 {
     if (syntax == null)
     {
         context.ReportDiagnostic(Diagnostic.Create(Descriptor, diagnosticLocation));
     }
 }
        public void GetAdjustedDiagnosticSpan(
            DocumentId documentId, Location location,
            out TextSpan sourceSpan, out FileLinePositionSpan originalLineInfo, out FileLinePositionSpan mappedLineInfo)
        {
            sourceSpan = location.SourceSpan;
            originalLineInfo = location.GetLineSpan();
            mappedLineInfo = location.GetMappedLineSpan();

            // check quick bail out case.
            if (location == Location.None)
            {
                return;
            }
            // Update the original source span, if required.
            if (!TryAdjustSpanIfNeededForVenus(documentId, originalLineInfo, mappedLineInfo, out var originalSpan, out var mappedSpan))
            {
                return;
            }

            if (originalSpan.Start != originalLineInfo.StartLinePosition || originalSpan.End != originalLineInfo.EndLinePosition)
            {
                originalLineInfo = new FileLinePositionSpan(originalLineInfo.Path, originalSpan.Start, originalSpan.End);

                var textLines = location.SourceTree.GetText().Lines;
                var startPos = textLines.GetPosition(originalSpan.Start);
                var endPos = textLines.GetPosition(originalSpan.End);

                sourceSpan = TextSpan.FromBounds(startPos, Math.Max(startPos, endPos));
            }

            if (mappedSpan.Start != mappedLineInfo.StartLinePosition || mappedSpan.End != mappedLineInfo.EndLinePosition)
            {
                mappedLineInfo = new FileLinePositionSpan(mappedLineInfo.Path, mappedSpan.Start, mappedSpan.End);
            }
        }
Пример #16
0
 internal DiagnosticWithInfo(DiagnosticInfo info, Location location)
 {
     Debug.Assert(info != null);
     Debug.Assert(location != null);
     _info = info;
     _location = location;
 }
        public void GetAdjustedDiagnosticSpan(
            DocumentId documentId, Location location,
            out TextSpan sourceSpan, out FileLinePositionSpan originalLineInfo, out FileLinePositionSpan mappedLineInfo)
        {
            sourceSpan = location.SourceSpan;
            originalLineInfo = location.GetLineSpan();
            mappedLineInfo = location.GetMappedLineSpan();

            // Update the original source span, if required.
            LinePositionSpan originalSpan;
            LinePositionSpan mappedSpan;
            if (!TryAdjustSpanIfNeededForVenus(documentId, originalLineInfo, mappedLineInfo, out originalSpan, out mappedSpan))
            {
                return;
            }

            if (originalSpan.Start != originalLineInfo.StartLinePosition || originalSpan.End != originalLineInfo.EndLinePosition)
            {
                originalLineInfo = new FileLinePositionSpan(originalLineInfo.Path, originalSpan.Start, originalSpan.End);

                var textLines = location.SourceTree.GetText().Lines;
                var startPos = textLines.GetPosition(originalSpan.Start);
                var endPos = textLines.GetPosition(originalSpan.End);
                sourceSpan = new TextSpan(startPos, endPos - startPos);
            }

            if (mappedSpan.Start != mappedLineInfo.StartLinePosition || mappedSpan.End != mappedLineInfo.EndLinePosition)
            {
                mappedLineInfo = new FileLinePositionSpan(mappedLineInfo.Path, mappedSpan.Start, mappedSpan.End);
            }
        }
 public InsertionResult(CodeRefactoringContext context, SyntaxNode node, INamedTypeSymbol type, Location location)
 {
     this.Context = context;
     this.Node = node;
     this.Type = type;
     this.Location = location;
 }
 private async Task AddQuickFix(ICollection<QuickFix> quickFixes, Location location)
 {
     if (location.IsInSource)
     {
         var quickFix = await GetQuickFix(location);
         quickFixes.Add(quickFix);
     }
 }
Пример #20
0
        public ReferenceDirective(string file, Location location)
        {
            Debug.Assert(file != null);
            Debug.Assert(location != null);

            File = file;
            Location = location;
        }
Пример #21
0
        protected void setLocation(Location location)
        {
            var line = location.GetMappedLineSpan().StartLinePosition;

            File = location.FilePath;
            Line = line.Line + 1;
            Character = line.Character + 1;
        }
Пример #22
0
 public static async Task AddQuickFix(ICollection<QuickFix> quickFixes, OmnisharpWorkspace workspace, Location location)
 {
     if (location.IsInSource)
     {
         var quickFix = await GetQuickFix(workspace, location);
         quickFixes.Add(quickFix);
     }
 }
 internal static NRefactoryDiagnosticDiagnostic Create(string id, LocalizableString title, string category, LocalizableString message, LocalizableString description, string helpLink,
     DiagnosticSeverity severity, DiagnosticSeverity defaultSeverity,
     bool isEnabledByDefault, int warningLevel, Location location,
     IEnumerable<Location> additionalLocations, string[] customTags)
 {
     var descriptor = new DiagnosticDescriptor(id, title, message,
         category, defaultSeverity, isEnabledByDefault, description, helpLink);
     return new NRefactoryDiagnosticDiagnostic(descriptor, severity, warningLevel, location, additionalLocations, messageArgs: null, customTags: customTags);
 }
Пример #24
0
 internal static SimpleDiagnostic Create(string id, LocalizableString title, string category, LocalizableString message, LocalizableString description, string helpLink,
                           DiagnosticSeverity severity, DiagnosticSeverity defaultSeverity,
                           bool isEnabledByDefault, int warningLevel, Location location,
                           IEnumerable<Location> additionalLocations, IEnumerable<string> customTags)
 {
     var descriptor = new DiagnosticDescriptor(id, title, message,
          category, defaultSeverity, isEnabledByDefault, description, helpLink, customTags.ToImmutableArrayOrEmpty());
     return new SimpleDiagnostic(descriptor, severity, warningLevel, location, additionalLocations, messageArgs: null);
 }
Пример #25
0
        private bool IsValidSourceLocation(Location location, Solution solution)
        {
            if (!location.IsInSource)
            {
                return false;
            }

            var document = solution.GetDocument(location.SourceTree);
            return IsValidSourceLocation(document, location.SourceSpan);
        }
Пример #26
0
 internal static SimpleDiagnostic Create(
     DiagnosticDescriptor descriptor,
     DiagnosticSeverity severity,
     int warningLevel,
     Location location,
     IEnumerable<Location> additionalLocations,
     object[] messageArgs)
 {
     return new SimpleDiagnostic(descriptor, severity, warningLevel, location, additionalLocations, messageArgs);
 }
Пример #27
0
 private SimpleDiagnostic(SerializationInfo info, StreamingContext context)
 {
     this.id = info.GetString("id");
     this.category = info.GetString("category");
     this.message = info.GetString("message");
     this.severity = (DiagnosticSeverity)info.GetInt32("severity");
     this.warningLevel = info.GetInt32("warningLevel");
     this.isWarningAsError = info.GetBoolean("isWarningAsError");
     this.location = (Location)info.GetValue("location", typeof(Location));
     this.additionalLocations = ((Location[])info.GetValue("additionalLocations", typeof(Location[]))).ToImmutableListOrEmpty();
 }
        internal bool TryBind(Dictionary <string, TypeSummary> types, out MonoBreakpointLocation breakpointLocation)
        {
            try
            {
                using (var stream = File.OpenRead(DocumentName))
                {
                    SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(SourceText.From(stream), path: DocumentName);
                    TextLine   textLine   = syntaxTree.GetText().Lines[StartLine];
                    Location   location   = syntaxTree.GetLocation(textLine.Span);
                    SyntaxTree sourceTree = location.SourceTree;
                    SyntaxNode node       = location.SourceTree.GetRoot().FindNode(location.SourceSpan, true, true);

                    // Find the method which contains the breakpoint
                    bool isAnonymousFunctionExpression = false;
                    var  method = GetParentNode <MethodDeclarationSyntax, AnonymousFunctionExpressionSyntax>(node.Parent, ref isAnonymousFunctionExpression);

                    if (method == null)
                    {
                        breakpointLocation = null;
                        return(false);
                    }

                    string methodName = method.Identifier.Text;

                    // Find the class which contains the method
                    var    cl        = GetParentNode <ClassDeclarationSyntax>(method);
                    string className = cl.Identifier.Text;

                    // Find the namespace which contains the class
                    var    ns     = GetParentNode <NamespaceDeclarationSyntax>(method);
                    string nsname = ns.Name.ToString();

                    // Find the loaded type with name "namespace.className"
                    string      name = string.Format("{0}.{1}", nsname, className);
                    TypeSummary summary;
                    if (types.TryGetValue(name, out summary))
                    {
                        breakpointLocation = FindNearestBreakpointLocation(isAnonymousFunctionExpression, methodName, summary);
                        if (breakpointLocation != null)
                        {
                            return(true);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Trace($"Exception : {ex}");
            }

            breakpointLocation = null;
            return(false);
        }
 internal static SimpleDiagnostic Create(
     DiagnosticDescriptor descriptor,
     DiagnosticSeverity severity,
     int warningLevel,
     Location location,
     IEnumerable<Location> additionalLocations,
     object[] messageArgs,
     ImmutableDictionary<string, string> properties,
     bool isSuppressed = false)
 {
     return new SimpleDiagnostic(descriptor, severity, warningLevel, location, additionalLocations, messageArgs, properties, isSuppressed);
 }
Пример #30
0
        public static DomRegion ToDomRegion(this Microsoft.CodeAnalysis.Location location, int injectedHeaderLines = 0)
        {
            //DomRegion is 1-based Editor friendly struct

            var linePosition = location.GetLineSpan().StartLinePosition;

            return(new DomRegion
            {
                FileName = location.SourceTree.FilePath,
                BeginLine = linePosition.Line + 1 - injectedHeaderLines,
                EndLine = linePosition.Line + 1 - injectedHeaderLines,
                BeginColumn = linePosition.Character + 1,
            });
        }
Пример #31
0
        internal static MITextPosition GetStatementRange(string fileName, int startLine, int startColumn)
        {
            try
            {
                logger.Trace("Line: {0} Column: {1} Source: {2}", startLine, startColumn, fileName);

                if (!File.Exists(fileName))
                {
                    return(null);
                }

                using (var stream = File.OpenRead(fileName))
                {
                    SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(SourceText.From(stream), path: fileName);
                    SourceText text       = syntaxTree.GetText();
                    var        root       = (CompilationUnitSyntax)syntaxTree.GetRoot();

                    var        span = new TextSpan(text.Lines[startLine - 1].Start + startColumn, 1);
                    SyntaxNode node = root.FindNode(span, false, false);

                    if (node is BlockSyntax)
                    {
                        return(MapBlockSyntax(span, node, fileName));
                    }
                    while (node is TypeSyntax || node is MemberAccessExpressionSyntax)
                    {
                        node = node.Parent;
                    }

                    Location             location = node.GetLocation();
                    FileLinePositionSpan mapped   = location.GetMappedLineSpan();

                    return(new MITextPosition(fileName,
                                              new TEXT_POSITION()
                    {
                        dwLine = (uint)mapped.StartLinePosition.Line, dwColumn = (uint)mapped.StartLinePosition.Character
                    },
                                              new TEXT_POSITION()
                    {
                        dwLine = (uint)mapped.EndLinePosition.Line, dwColumn = (uint)mapped.EndLinePosition.Character
                    }));
                }
            }
            catch (Exception ex)
            {
                logger.Trace($"Exception : {ex}");
                return(null);
            }
        }
Пример #32
0
        internal bool TryBind(Dictionary <string, TypeSummary> types, out MonoBreakpointLocation breakpointLocation)
        {
            try
            {
                using (var stream = File.OpenRead(DocumentName))
                {
                    SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(SourceText.From(stream), path: DocumentName);
                    TextLine   textLine   = syntaxTree.GetText().Lines[StartLine];
                    Location   location   = syntaxTree.GetLocation(textLine.Span);
                    SyntaxTree sourceTree = location.SourceTree;
                    SyntaxNode node       = location.SourceTree.GetRoot().FindNode(location.SourceSpan, true, true);

                    var    method     = GetParentMethod <MethodDeclarationSyntax>(node.Parent);
                    string methodName = method.Identifier.Text;

                    var    cl        = GetParentMethod <ClassDeclarationSyntax>(method);
                    string className = cl.Identifier.Text;

                    var    ns     = GetParentMethod <NamespaceDeclarationSyntax>(method);
                    string nsname = ns.Name.ToString();

                    string      name = string.Format("{0}.{1}", nsname, className);
                    TypeSummary summary;
                    if (types.TryGetValue(name, out summary))
                    {
                        MethodMirror methodMirror = summary.Methods.FirstOrDefault(x => x.Name == methodName);

                        if (methodMirror != null)
                        {
                            breakpointLocation = new MonoBreakpointLocation
                            {
                                Method = methodMirror,
                                Offset = 0,
                            };
                            return(true);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log($"Exception : {ex}");
            }

            breakpointLocation = null;
            return(false);
        }
Пример #33
0
 Assembly(Context cx, Microsoft.CodeAnalysis.Location init)
     : base(cx, init)
 {
     if (init == null)
     {
         // This is the output assembly
         assemblyPath = cx.Extractor.OutputPath;
         assembly     = cx.Compilation.Assembly;
     }
     else
     {
         assembly = symbol.MetadataModule.ContainingAssembly;
         var identity = assembly.Identity;
         var idString = identity.Name + " " + identity.Version;
         assemblyPath = cx.Extractor.GetAssemblyFile(idString);
     }
 }
Пример #34
0
        internal GraphNode GetLocationNode(ISymbol symbol, Location location, IGraphContext context, ProjectId projectId, CancellationToken cancellationToken)
        {
            var span = location.GetLineSpan();
            var lineText = location.SourceTree.GetText(cancellationToken).Lines[span.StartLinePosition.Line].ToString();
            var filePath = location.SourceTree.FilePath;
            var sourceLocation = new SourceLocation(filePath,
                                        new Position(span.StartLinePosition.Line, span.StartLinePosition.Character),
                                        new Position(span.EndLinePosition.Line, span.EndLinePosition.Character));
            var label = string.Format("{0} ({1}, {2}): {3}",
                                        System.IO.Path.GetFileName(filePath),
                                        span.StartLinePosition.Line + 1,
                                        span.StartLinePosition.Character + 1,
                                        lineText.TrimStart());
            var locationNode = context.Graph.Nodes.GetOrCreate(sourceLocation.CreateGraphNodeId(), label, CodeNodeCategories.SourceLocation);
            locationNode[CodeNodeProperties.SourceLocation] = sourceLocation;
            locationNode[RoslynGraphProperties.ContextProjectId] = projectId;
            locationNode[DgmlNodeProperties.Icon] = IconHelper.GetIconName("Reference", Accessibility.NotApplicable);

            return locationNode;
        }
Пример #35
0
            public Session(RenameLocationSet renameLocationSet, Location renameSymbolDeclarationLocation, string originalText, string replacementText, OptionSet optionSet, CancellationToken cancellationToken)
            {
                this.renameLocationSet = renameLocationSet;
                this.renameSymbolDeclarationLocation = renameSymbolDeclarationLocation;
                this.originalText = originalText;
                this.replacementText = replacementText;
                this.optionSet = optionSet;
                this.cancellationToken = cancellationToken;

                this.renamedSymbolDeclarationAnnotation = new RenameAnnotation();

                this.conflictLocations = SpecializedCollections.EmptySet<ConflictLocationInfo>();
                this.replacementTextValid = true;
                this.possibleNameConflicts = new List<string>();

                // only process documents which possibly contain the identifiers.
                this.documentsIdsToBeCheckedForConflict = new HashSet<DocumentId>();
                this.documentIdOfRenameSymbolDeclaration = renameLocationSet.Solution.GetDocument(renameSymbolDeclarationLocation.SourceTree).Id;

                this.renameAnnotations = new AnnotationTable<RenameAnnotation>(RenameAnnotation.Kind);
            }
Пример #36
0
        internal static StatementRange GetStatementRange(string fileName, int startLine, int startColumn)
        {
            try
            {
                logger.Trace("Line: {0} Column: {1} Source: {2}", startLine, startColumn, fileName);


                SyntaxTree syntaxTree = CSharpSyntaxTree.ParseFile(fileName);
                SourceText text       = syntaxTree.GetText();
                var        root       = (CompilationUnitSyntax)syntaxTree.GetRoot();

                var        span = new TextSpan(text.Lines[startLine - 1].Start + startColumn, 1);
                SyntaxNode node = root.FindNode(span, false, false);

                if (node is BlockSyntax)
                {
                    return(MapBlockSyntax(span, node));
                }
                while (node is TypeSyntax || node is MemberAccessExpressionSyntax)
                {
                    node = node.Parent;
                }

                Location             location = node.GetLocation();
                FileLinePositionSpan mapped   = location.GetMappedLineSpan();

                return(new StatementRange
                {
                    StartLine = mapped.StartLinePosition.Line,
                    StartColumn = mapped.StartLinePosition.Character,
                    EndLine = mapped.EndLinePosition.Line,
                    EndColumn = mapped.EndLinePosition.Character,
                });
            }
            catch
            {
                return(null);
            }
        }
Пример #37
0
 public Issue(
     string id, string message, string description,
     string title, string category, string helpLink, bool isEnabledByDefault,
     DiagnosticSeverity defaultSeverity, DiagnosticSeverity severity, int warningLevel,
     Location location, IReadOnlyList<Location> additionalLocations,
     IReadOnlyList<string> customTags, ImmutableDictionary<string, string> customProperties)
 {
     Id = id;
     Message = message;
     Description = description;
     Title = title;
     Category = category;
     HelpLink = helpLink;
     IsEnabledByDefault = isEnabledByDefault;
     DefaultSeverity = defaultSeverity;
     Severity = severity;
     WarningLevel = warningLevel;
     Location = location;
     AdditionalLocations = additionalLocations;
     CustomTags = customTags;
     CustomProperties = customProperties.OrderBy(kvp => kvp.Key).ToImmutableArray();
 }
        private async Task<QuickFix> GetQuickFix(Location location)
        {
            if (!location.IsInSource)
                throw new Exception("Location is not in the source tree");

            var lineSpan = location.GetLineSpan();
            var path = lineSpan.Path;
            var documents = _workspace.GetDocuments(path);
            var line = lineSpan.StartLinePosition.Line;
            var syntaxTree = await documents.First().GetSyntaxTreeAsync();
            var text = syntaxTree.GetText().Lines[line].ToString();

            return new QuickFix
            {
                Text = text.Trim(),
                FileName = path,
                Line = line + 1,
                Column = lineSpan.StartLinePosition.Character + 1,
                EndLine = lineSpan.EndLinePosition.Line + 1,
                EndColumn = lineSpan.EndLinePosition.Character + 1,
                Projects = documents.Select(document => document.Project.Name).ToArray()
            };
        }
Пример #39
0
 public static Protocol.Range AsRange(this Microsoft.CodeAnalysis.Location location) => AsRange(location.GetLineSpan());
Пример #40
0
 protected SourceLocation(Context cx, Microsoft.CodeAnalysis.Location init)
     : base(cx, init)
 {
 }
Пример #41
0
 public static ILocation WrapLocation(Microsoft.CodeAnalysis.Location roslynLocation)
 {
     return(new SourceLocationWrapper(roslynLocation.SourceTree, roslynLocation.SourceSpan));
 }
Пример #42
0
 public static Location Create(Context cx, Microsoft.CodeAnalysis.Location loc) => SourceLocationFactory.Instance.CreateEntity(cx, loc, loc);
Пример #43
0
 protected NonGeneratedSourceLocation(Context cx, Microsoft.CodeAnalysis.Location init)
     : base(cx, init)
 {
     Position   = init.GetLineSpan();
     FileEntity = File.Create(Context, Position.Path);
 }
Пример #44
0
 /// <summary>
 /// Create a new instance of this diagnostic with the Location property changed.
 /// </summary>
 internal abstract Diagnostic WithLocation(Location location);
Пример #45
0
 public static Location Create(Microsoft.CodeAnalysis.Location location)
 {
     return(new Location(location));
 }
Пример #46
0
 public Location(Microsoft.CodeAnalysis.Location location)
 {
     this.location             = location;
     this.fileLinePositionSpan = location.GetLineSpan();
 }
Пример #47
0
 public new static Location Create(Context cx, Microsoft.CodeAnalysis.Location loc) => AssemblyConstructorFactory.Instance.CreateEntity(cx, loc);
Пример #48
0
        /// <summary>
        /// Register a program entity which can be bound to comments.
        /// </summary>
        /// <param name="cx">Extractor context.</param>
        /// <param name="entity">Program entity.</param>
        /// <param name="l">Location of the entity.</param>
        public void BindComments(IEntity entity, Microsoft.CodeAnalysis.Location l)
        {
            var duplicationGuardKey = tagStack.Count > 0 ? tagStack.Peek() : null;

            CommentGenerator.RegisterElementLocation(entity.Label, duplicationGuardKey, l);
        }
Пример #49
0
        internal static MonoDevelop.Ide.FindInFiles.SearchResult GetJumpTypePartSearchResult(Microsoft.CodeAnalysis.ISymbol part, Microsoft.CodeAnalysis.Location location)
        {
            var provider = new MonoDevelop.Ide.FindInFiles.FileProvider(location.SourceTree.FilePath);
            var doc      = TextEditorFactory.CreateNewDocument();

            doc.Text = provider.ReadString().ReadToEnd();
            int position = location.SourceSpan.Start;

            while (position + part.Name.Length < doc.Length)
            {
                if (doc.GetTextAt(position, part.Name.Length) == part.Name)
                {
                    break;
                }
                position++;
            }
            return(new MonoDevelop.Ide.FindInFiles.SearchResult(provider, position, part.Name.Length));
        }