Esempio n. 1
0
            public DocumentId?Deserialize(
                ref MessagePackReader reader,
                MessagePackSerializerOptions options
                )
            {
                try
                {
                    if (reader.TryReadNil())
                    {
                        return(null);
                    }

                    Contract.ThrowIfFalse(reader.ReadArrayHeader() == 3);

                    var projectId = ProjectIdFormatter.Instance.Deserialize(ref reader, options);
                    Contract.ThrowIfNull(projectId);

                    var id        = GuidFormatter.Instance.Deserialize(ref reader, options);
                    var debugName = reader.ReadString();

                    return(DocumentId.CreateFromSerialized(projectId, id, debugName));
                }
                catch (Exception e) when(e is not MessagePackSerializationException)
                {
                    throw new MessagePackSerializationException(e.Message, e);
                }
            }
Esempio n. 2
0
        public async Task <LSP.CompletionItem> HandleRequestAsync(LSP.CompletionItem completionItem, RequestContext context, CancellationToken cancellationToken)
        {
            if (!(completionItem.Data is CompletionResolveData data))
            {
                data = ((JToken)completionItem.Data).ToObject <CompletionResolveData>();
            }

            var documentId = DocumentId.CreateFromSerialized(ProjectId.CreateFromSerialized(data.ProjectGuid), data.DocumentGuid);
            var document   = context.Solution.GetAdditionalDocument(documentId);

            if (document == null)
            {
                return(completionItem);
            }

            int offset = await document.GetPositionFromLinePositionAsync(ProtocolConversions.PositionToLinePosition(data.Position), cancellationToken).ConfigureAwait(false);

            var completionService = document.Project.LanguageServices.GetRequiredService <IXamlCompletionService>();
            var symbol            = await completionService.GetSymbolAsync(new XamlCompletionContext(document, offset), completionItem.Label, cancellationToken : cancellationToken).ConfigureAwait(false);

            if (symbol == null)
            {
                return(completionItem);
            }

            var description = await symbol.GetDescriptionAsync(document, offset, cancellationToken).ConfigureAwait(false);

            var vsCompletionItem = CloneVSCompletionItem(completionItem);

            vsCompletionItem.Description = new ClassifiedTextElement(description.Select(tp => new ClassifiedTextRun(tp.Tag.ToClassificationTypeName(), tp.Text)));
            return(vsCompletionItem);
        }
Esempio n. 3
0
            public async Task TrackChangesAsync(CancellationToken cancellationToken)
            {
                var guids = await _callbackService.InvokeAsync <List <Guid> >(
                    _owner,
                    nameof(ICodeLensContext.GetDocumentId),
                    new object[] { Descriptor.ProjectGuid, Descriptor.FilePath },
                    cancellationToken).ConfigureAwait(false);

                if (guids == null)
                {
                    return;
                }

                var documentId = DocumentId.CreateFromSerialized(
                    ProjectId.CreateFromSerialized(guids[0], Descriptor.ProjectGuid.ToString()),
                    guids[1],
                    Descriptor.FilePath);

                if (documentId == null)
                {
                    return;
                }

                // this asks Roslyn OOP to start track workspace changes and call back Invalidate on this type when there is one.
                // each data point owns 1 connection which is alive while data point is alive. and all communication is done through
                // that connection
                await _endPoint.InvokeAsync(
                    nameof(IRemoteCodeLensReferencesService.TrackCodeLensAsync),
                    new object[] { documentId },
                    cancellationToken).ConfigureAwait(false);
            }
Esempio n. 4
0
        public static DocumentId DeserializeDocumentId(ObjectReader reader, CancellationToken cancellationToken)
        {
            var projectId = DeserializeProjectId(reader, cancellationToken);

            var guid      = new Guid(reader.ReadArray <byte>());
            var debugName = reader.ReadString();

            return(DocumentId.CreateFromSerialized(projectId, guid, debugName));
        }
            public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
            {
                Contract.ThrowIfFalse(reader.TokenType == JsonToken.StartObject);

                var projectId = ReadProperty <ProjectId>(serializer, reader);

                var(id, debugName) = ReadIdAndName(reader);

                Contract.ThrowIfFalse(reader.Read());
                Contract.ThrowIfFalse(reader.TokenType == JsonToken.EndObject);

                return(DocumentId.CreateFromSerialized(projectId, id, debugName));
            }
Esempio n. 6
0
        internal static DocumentId?CreateDocIdFromEquivalenceKey(this FixAllContext fixAllContext)
        {
            var split = fixAllContext.CodeActionEquivalenceKey.Split(SemicolonSplit, StringSplitOptions.RemoveEmptyEntries);

            if (split.Length == 3 &&
                string.Equals(split[0], ApiDocEquivalenceKeyPrefix, StringComparison.Ordinal) &&
                Guid.TryParse(split[1], out var projectGuid) && projectGuid != Guid.Empty &&
                Guid.TryParse(split[2], out var docGuid) && docGuid != Guid.Empty)
            {
                var projectId = ProjectId.CreateFromSerialized(projectGuid);
                return(DocumentId.CreateFromSerialized(projectId, docGuid));
            }

            return(null);
        }
Esempio n. 7
0
        public async Task <LSP.CompletionItem> HandleRequestAsync(LSP.CompletionItem completionItem, RequestContext context, CancellationToken cancellationToken)
        {
            Contract.ThrowIfNull(context.Solution);

            if (completionItem is not VSInternalCompletionItem vsCompletionItem)
            {
                return(completionItem);
            }

            CompletionResolveData?data;

            if (completionItem.Data is JToken token)
            {
                data = token.ToObject <CompletionResolveData>();
                Assumes.Present(data);
            }
            else
            {
                return(completionItem);
            }

            var documentId = DocumentId.CreateFromSerialized(ProjectId.CreateFromSerialized(data.ProjectGuid), data.DocumentGuid);
            var document   = context.Solution.GetDocument(documentId) ?? context.Solution.GetAdditionalDocument(documentId);

            if (document == null)
            {
                return(completionItem);
            }

            var offset = await document.GetPositionFromLinePositionAsync(ProtocolConversions.PositionToLinePosition(data.Position), cancellationToken).ConfigureAwait(false);

            var completionService = document.Project.LanguageServices.GetRequiredService <IXamlCompletionService>();
            var symbol            = await completionService.GetSymbolAsync(new XamlCompletionContext(document, offset), completionItem.Label, cancellationToken : cancellationToken).ConfigureAwait(false);

            if (symbol == null)
            {
                return(completionItem);
            }

            var options     = _globalOptions.GetSymbolDescriptionOptions(document.Project.Language);
            var description = await symbol.GetDescriptionAsync(document, options, cancellationToken).ConfigureAwait(false);

            vsCompletionItem.Description = new ClassifiedTextElement(description.Select(tp => new ClassifiedTextRun(tp.Tag.ToClassificationTypeName(), tp.Text)));
            return(vsCompletionItem);
        }
Esempio n. 8
0
 public DocumentId Rehydrate()
 {
     return(DocumentId.CreateFromSerialized(
                ProjectId.Rehydrate(), Id, DebugName));
 }
Esempio n. 9
0
        private static async Task <IEnumerable <ReferenceLocationDescriptor> > FixUpDescriptors(
            Solution solution, IEnumerable <ReferenceLocationDescriptor> descriptors, CancellationToken cancellationToken)
        {
            var list = new List <ReferenceLocationDescriptor>();

            foreach (var descriptor in descriptors)
            {
                var referencedDocumentId = DocumentId.CreateFromSerialized(
                    ProjectId.CreateFromSerialized(descriptor.ProjectGuid), descriptor.DocumentGuid);

                var document = solution.GetDocument(referencedDocumentId);

                var spanMapper = document?.Services.GetService <ISpanMappingService>();
                if (spanMapper == null)
                {
                    // for normal document, just add one as they are
                    list.Add(descriptor);
                    continue;
                }

                var span    = new TextSpan(descriptor.SpanStart, descriptor.SpanLength);
                var results = await spanMapper.MapSpansAsync(document, SpecializedCollections.SingletonEnumerable(span), cancellationToken).ConfigureAwait(false);

                // external component violated contracts. the mapper should preserve input order/count.
                // since we gave in 1 span, it should return 1 span back
                Contract.ThrowIfTrue(results.IsDefaultOrEmpty);

                var result = results[0];
                if (result.IsDefault)
                {
                    // it is allowed for mapper to return default
                    // if it can't map the given span to any usable span
                    continue;
                }

                var excerpter        = document.Services.GetService <IDocumentExcerptService>();
                var referenceExcerpt = await excerpter.TryExcerptAsync(document, span, ExcerptMode.SingleLine, cancellationToken).ConfigureAwait(false);

                var tooltipExcerpt = await excerpter.TryExcerptAsync(document, span, ExcerptMode.Tooltip, cancellationToken).ConfigureAwait(false);

                var reference      = GetReferenceInfo(referenceExcerpt, descriptor);
                var referenceTexts = GetReferenceTexts(referenceExcerpt, tooltipExcerpt, descriptor);

                list.Add(new ReferenceLocationDescriptor(
                             descriptor.LongDescription,
                             descriptor.Language,
                             descriptor.Glyph,
                             result.Span.Start,
                             result.Span.Length,
                             result.LinePositionSpan.Start.Line,
                             result.LinePositionSpan.Start.Character,
                             descriptor.ProjectGuid,
                             descriptor.DocumentGuid,
                             result.FilePath,
                             reference.text,
                             reference.start,
                             reference.length,
                             referenceTexts.before1,
                             referenceTexts.before2,
                             referenceTexts.after1,
                             referenceTexts.after2));
            }

            return(list);
        }
Esempio n. 10
0
 public DocumentId GetDocumentId()
 =>
 DocumentId.CreateFromSerialized(ProjectId.CreateFromSerialized(ProjectIdGuid, ProjectIdDebugName),
                                 DocumentIdGuid, DocumentIdDebugName);
Esempio n. 11
0
 public static DocumentId ToDocumentId(this CodeCellId codeCellId)
 => DocumentId.CreateFromSerialized(
     ProjectId.CreateFromSerialized(codeCellId.ProjectId),
     codeCellId.Id);