Esempio n. 1
0
 public AliasedSymbol(string name, SymbolKinds kind, PapyrusSymbol aliasedSymbol, PapyrusSymbol parent)
     : base(aliasedSymbol.Definition, aliasedSymbol.Identifier, parent)
 {
     _name          = name;
     _kind          = kind;
     _aliasedSymbol = aliasedSymbol;
 }
        public static Task <IEnumerable <SyntaxNode> > FindReferences(this PapyrusSymbol symbol, CancellationToken cancellationToken)
        {
            return(Task.Run(() =>
            {
                try
                {
                    var symbolScriptId = symbol.Script.Id;

                    Dictionary <ObjectIdentifier, ScriptFile> scriptFiles;
                    lock (symbol.File.Program.ScriptFiles)
                    {
                        scriptFiles = symbol.File.Program.ScriptFiles.ToDictionary();
                    }

                    return scriptFiles.Values.AsParallel().WithCancellation(cancellationToken).
                    Where(file =>
                    {
                        lock (file.Text)
                        {
                            return file.Text.Text.Contains(symbol.Name);
                        }
                    }).
                    Where(file => file.CompilerNode != null && file.CompilerNode.GetDescendants().AsParallel().WithCancellation(cancellationToken).
                          Any(node => node.Text.CaseInsensitiveEquals(symbol.Name))).
                    SelectMany(file => file.Node.GetDescendants().OfType <IdentifierNode>().Where(n => n.GetDeclaredOrReferencedSymbol() == symbol)).
                    ToArray();
                }
                catch (OperationCanceledException)
                {
                    return Enumerable.Empty <SyntaxNode>();
                }
            }));
        }
        // TODO: Move this elsewhere?
        public static string GetDocumentationMarkdown(this PapyrusSymbol symbol)
        {
            var docs = symbol.Documentation.
                       Where(doc => !string.IsNullOrEmpty(doc.Trim())).
                       Select(doc =>
                              doc.Split('\n').Select(d => d.TrimEnd() + "  ").Join("\r\n")).
                       Join("\r\n___\r\n");

            if (string.IsNullOrWhiteSpace(docs))
            {
                return(null);
            }

            return(docs);
        }
Esempio n. 4
0
        private static void ToDocumentSymbol(Uri fileUri, IReadOnlyScriptText text, PapyrusSymbol symbol, List <DocumentSymbolInformation> symbolInformationContainer, string containerName = null)
        {
            var symbolInformation = new DocumentSymbolInformation()
            {
                Name     = symbol.Name,
                Kind     = GetSymbolKind(symbol),
                Location = new Location()
                {
                    Uri   = fileUri,
                    Range = symbol.Definition.Range.ToRange()
                },
                ContainerName = containerName
            };

            foreach (var childSymbol in symbol.Children)
            {
                ToDocumentSymbol(fileUri, text, childSymbol, symbolInformationContainer, symbolInformation.Name);
            }

            symbolInformationContainer.Add(symbolInformation);
        }
        public static CompletionItemKind GetCompletionItemKind(PapyrusSymbol symbol)
        {
            switch (symbol.Kind)
            {
            case SymbolKinds.CustomEvent:
            case SymbolKinds.Event:
                return(CompletionItemKind.Event);

            case SymbolKinds.Function:
                return(CompletionItemKind.Method);

            case SymbolKinds.Variable:
                if (symbol.Parent == null ||
                    symbol.Parent.Kind == SymbolKinds.Script ||
                    symbol.Parent.Kind == SymbolKinds.Struct)
                {
                    return(CompletionItemKind.Field);
                }

                return(CompletionItemKind.Variable);

            case SymbolKinds.Property:
                return(CompletionItemKind.Property);

            case SymbolKinds.Struct:
                return(CompletionItemKind.Struct);

            case SymbolKinds.Import:
            case SymbolKinds.Script:
                return(CompletionItemKind.Class);

            case SymbolKinds.State:
                return(CompletionItemKind.Module);

            default:
                return(CompletionItemKind.Text);
            }
        }
Esempio n. 6
0
        public static SymbolKind GetSymbolKind(PapyrusSymbol symbol)
        {
            switch (symbol.Kind)
            {
            case SymbolKinds.CustomEvent:
            case SymbolKinds.Event:
                return(SymbolKind.Event);

            case SymbolKinds.Function:
                return(SymbolKind.Method);

            case SymbolKinds.State:
            case SymbolKinds.Group:
                return(SymbolKind.Namespace);

            case SymbolKinds.Variable:
                if (symbol.Parent.Kind == SymbolKinds.Script)
                {
                    return(SymbolKind.Field);
                }

                return(SymbolKind.Variable);

            case SymbolKinds.Property:
                return(SymbolKind.Property);

            case SymbolKinds.Struct:
                return(SymbolKind.Struct);

            case SymbolKinds.Import:
            case SymbolKinds.Script:
                return(SymbolKind.Class);

            default:
                return(SymbolKind.Object);
            }
        }
        public static PapyrusType GetPapyrusType(this PapyrusSymbol symbol)
        {
            if (symbol is AliasedSymbol asAliased)
            {
                return(asAliased.Aliased.GetPapyrusType());
            }

            if (symbol is ScriptSymbol asScript)
            {
                return((ComplexType)asScript.File?.Type ?? asScript.SyntheticArrayType);
            }

#if FALLOUT4
            if (symbol is StructSymbol asStruct)
            {
                return(asStruct.Definition.Header.Identifier.GetReferencedType());
            }
#endif

            if (symbol is FunctionSymbol asFunction)
            {
                return(asFunction.Definition.Header.TypeIdentifier?.GetReferencedType());
            }

            if (symbol is PropertySymbol asProperty)
            {
                return(asProperty.Definition.Header.TypeIdentifier?.GetReferencedType());
            }

            if (symbol.Definition is ITypeIdentifiable asTypeIdentifiable)
            {
                return(asTypeIdentifiable.TypeIdentifier?.GetReferencedType());
            }

            return(null);
        }
 // TODO: Move these elsewhere?
 public static Task <IEnumerable <SyntaxNode> > FindReferences(this PapyrusSymbol symbol)
 {
     return(symbol.FindReferences(CancellationToken.None));
 }