예제 #1
0
        public async Task <ActionResult> Index(string projectId, string filename, bool partial = false)
        {
            try
            {
                Requests.LogRequest(this);

                if (string.IsNullOrEmpty(filename))
                {
                    return(this.HttpNotFound());
                }

                var boundSourceFile = await Storage.GetBoundSourceFileAsync(this.GetSearchRepos(), projectId, filename);

                if (boundSourceFile == null)
                {
                    return(PartialView("~/Views/Source/Index.cshtml", new EditorModel {
                        Error = $"Bound source file for {filename} in {projectId} not found."
                    }));
                }

                var renderer = new SourceFileRenderer(boundSourceFile, projectId);

                Responses.PrepareResponse(Response);

                var model = await renderer.RenderAsync();

                foreach (var editEntry in m_edits)
                {
                    if (model.WebLink?.StartsWith(editEntry.Key, StringComparison.OrdinalIgnoreCase) == true)
                    {
                        var truncateLength = editEntry.Value.TruncateLength;
                        if (editEntry.Value.ReplacePrefix)
                        {
                            truncateLength = editEntry.Key.Length;
                        }

                        var start = model.WebLink.Substring(0, editEntry.Key.Length - truncateLength);
                        var end   = model.WebLink.Substring(editEntry.Key.Length + editEntry.Value.Offset);

                        model.WebLink = start + editEntry.Value.Inserted + end;
                    }
                }

                if (partial)
                {
                    return(PartialView("~/Views/Source/Index.cshtml", (object)model));
                }
                else
                {
                    return(View((object)model));
                }
            }
            catch (Exception ex)
            {
                return(Responses.Exception(ex));
            }
        }
예제 #2
0
        public async Task Populate(BoundSourceFile boundSourceFile)
        {
            contents = await boundSourceFile.SourceFile.GetContentsAsync();

            repoRelativePath = boundSourceFile.SourceFile.Info.RepoRelativePath;
            webLink          = boundSourceFile.SourceFile.Info.WebAddress;

            segmentLength = contents.Length;
            var segment = new SegmentModel();

            segments.Add(segment);

            classifications.AddRange(boundSourceFile.ClassificationSpans.Select(classification =>
            {
                return(new ClassificationSpan()
                {
                    name = SourceFileRenderer.MapClassificationToCssClass(classification.Classification),
                    position = classification.Start,
                    length = classification.Length
                });
            }).Where(span => !string.IsNullOrEmpty(span.name)));

            documentSymbols.AddRange(boundSourceFile.Definitions.Select(definition =>
            {
                return(new SymbolInformation()
                {
                    name = definition.Definition.ShortName,
                    containerName = definition.Definition.ContainerQualifiedName,
                    symbolKind = definition.Definition.Kind,
                    span = new Span()
                    {
                        position = definition.Start,
                        length = definition.Length
                    }
                });
            }));

            foreach (var reference in boundSourceFile.References)
            {
                if (reference.Reference.IsImplicitlyDeclared)
                {
                    continue;
                }

                var symbolSpan = new SymbolSpan()
                {
                    symbol    = reference.Reference.Id.Value,
                    projectId = reference.Reference.ProjectId,
                    span      = new Span()
                    {
                        position = reference.Start,
                        length   = reference.Length
                    }
                };

                if (reference.Reference.ReferenceKind == nameof(ReferenceKind.Definition))
                {
                    segment.definitions.Add(symbolSpan);
                }
                else
                {
                    segment.references.Add(symbolSpan);
                }
            }
        }