Event.cs 1.5 KB
Newer Older
1 2 3
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
4 5 6

using System;

7
namespace Microsoft.CodeAnalysis.LanguageServerIndexFormat.Generator.Graph
8 9
{
    /// <summary>
10
    /// Represents an event vertex for serialization. See https://github.com/Microsoft/language-server-protocol/blob/master/indexFormat/specification.md#events for further details.
11 12 13 14 15 16 17
    /// </summary>
    internal sealed class Event : Vertex
    {
        public string Kind { get; }
        public string Scope { get; }
        public Id<Element> Data { get; }

18 19
        private Event(EventKind kind, string scope, Id<Element> data, IdFactory idFactory)
            : base(label: "$event", idFactory)
20 21 22 23 24 25
        {
            this.Kind = kind switch { EventKind.Begin => "begin", EventKind.End => "end", _ => throw new ArgumentException(nameof(kind)) };
            this.Scope = scope;
            this.Data = data;
        }

26 27
        public Event(EventKind kind, Id<LsifProject> data, IdFactory idFactory)
            : this(kind, "project", data.As<LsifProject, Element>(), idFactory)
28 29 30
        {
        }

31 32
        public Event(EventKind kind, Id<LsifDocument> data, IdFactory idFactory)
            : this(kind, "document", data.As<LsifDocument, Element>(), idFactory)
33 34 35
        {
        }

36 37 38 39 40 41 42
        public enum EventKind
        {
            Begin,
            End
        }
    }
}