예제 #1
0
        public static ClassificationSpan ToClassification(CodexSemanticStore store, CodexSpan span)
        {
            if (!span.Classification.IsValid && !span.Symbol.IsValid)
            {
                return(null);
            }

            return(new ClassificationSpan()
            {
                Start = span.Start,
                Length = span.Length,
                LocalGroupId = span.LocalId.IsValid ? span.LocalId.Id + 1 : 0,
                Classification = span.Classification.IsValid ? store.Classifications[span.Classification].Name : "text"
            });
        }
예제 #2
0
        public static CodexSpan Read(string line)
        {
            string[] parts = line.Split(',');

            var span = new CodexSpan()
            {
                Start  = int.Parse(parts[0]),
                Length = int.Parse(parts[1]),
            };

            span.Classification.Read(parts[2]);
            span.Symbol.Read(parts[3]);
            span.ReferenceKind.Read(parts[4]);
            span.LocalId.Read(parts[5]);

            return(span);
        }
예제 #3
0
        public void Read(StreamReader reader)
        {
            string line = null;

            while ((line = reader.ReadLine()) != null)
            {
                if (line.StartsWith("#"))
                {
                    continue;
                }

                var span = CodexSpan.Read(line);
                Debug.Assert(span.Length > 0, "Must have some length..");
                Debug.Assert(span.Start + span.Length < Length, "Span must fit in file...");

                Spans.Add(span);
            }
        }
예제 #4
0
        public static DefinitionSpan ToDefinition(CodexSemanticStore store, BoundSourceFileBuilder builder, CodexSpan span)
        {
            if ((span.ReferenceKind.IsValid && !string.Equals(nameof(ReferenceKind.Definition), store.ReferenceKinds[span.ReferenceKind].Name,
                                                              StringComparison.OrdinalIgnoreCase)) || !span.Symbol.IsValid)
            {
                return(null);
            }

            var      symbol   = store.Symbols[span.Symbol];
            SymbolId symbolId = GetSpanSymbolId(symbol);

            var projectId = symbol.Project.IsValid ? store.Projects.Get(symbol.Project).Name : builder.ProjectId;

            return(new DefinitionSpan()
            {
                Start = span.Start,
                Length = span.Length,
                Definition = new DefinitionSymbol()
                {
                    Id = symbolId,
                    ShortName = symbol.ShortName,
                    DisplayName = symbol.DisplayName,
                    ContainerQualifiedName = symbol.ContainerQualifiedName,
                    SymbolDepth = symbol.SymbolDepth,
                    ReferenceKind = nameof(ReferenceKind.Definition),
                    Kind = symbol.Kind,
                    ProjectId = projectId,
                },
            });
        }
예제 #5
0
        public static ReferenceSpan ToReference(CodexSemanticStore store, BoundSourceFileBuilder builder, CodexSpan span)
        {
            if (!span.ReferenceKind.IsValid || !span.Symbol.IsValid)
            {
                return(null);
            }

            var      symbol   = store.Symbols[span.Symbol];
            SymbolId symbolId = GetSpanSymbolId(symbol);

            var projectId = symbol.Project.IsValid ? store.Projects.Get(symbol.Project).Name : builder.ProjectId;

            return(new ReferenceSpan()
            {
                Start = span.Start,
                Length = span.Length,
                Reference = new ReferenceSymbol()
                {
                    Id = symbolId,
                    ReferenceKind = store.ReferenceKinds[span.ReferenceKind].Name,
                    Kind = "symbol",
                    ProjectId = projectId,
                },
            });
        }