public IEnumerable <Internal.ISymbolReference> ProvideDocumentSymbols(ScriptFile scriptFile)
 {
     foreach (SymbolReference symbolReference in _symbolProvider.ProvideDocumentSymbols(new EditorScriptFile(scriptFile)))
     {
         yield return(new ExternalSymbolReferenceAdapter(symbolReference));
     }
 }
        /// <summary>
        /// Get all Pester CodeLenses for a given script file.
        /// </summary>
        /// <param name="scriptFile">The script file to get Pester CodeLenses for.</param>
        /// <returns>All Pester CodeLenses for the given script file.</returns>
        public CodeLens[] ProvideCodeLenses(ScriptFile scriptFile)
        {
            // Don't return anything if codelens setting is disabled
            if (!_configurationService.CurrentSettings.Pester.CodeLens)
            {
                return(Array.Empty <CodeLens>());
            }

            List <CodeLens> lenses = new();

            foreach (SymbolReference symbol in _symbolProvider.ProvideDocumentSymbols(scriptFile))
            {
                if (symbol is not PesterSymbolReference pesterSymbol)
                {
                    continue;
                }

                if (_configurationService.CurrentSettings.Pester.UseLegacyCodeLens &&
                    pesterSymbol.Command != PesterCommandType.Describe)
                {
                    continue;
                }

                lenses.AddRange(GetPesterLens(pesterSymbol, scriptFile));
            }

            return(lenses.ToArray());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get all reference code lenses for a given script file.
        /// </summary>
        /// <param name="scriptFile">The PowerShell script file to get code lenses for.</param>
        /// <returns>An array of CodeLenses describing all functions in the given script file.</returns>
        public CodeLens[] ProvideCodeLenses(ScriptFile scriptFile)
        {
            var acc = new List <CodeLens>();

            foreach (SymbolReference sym in _symbolProvider.ProvideDocumentSymbols(scriptFile))
            {
                if (sym.SymbolType == SymbolType.Function)
                {
                    acc.Add(new CodeLens(this, scriptFile, sym.ScriptRegion));
                }
            }

            return(acc.ToArray());
        }
Exemplo n.º 4
0
        /// <summary>
        /// Get all Pester CodeLenses for a given script file.
        /// </summary>
        /// <param name="scriptFile">The script file to get Pester CodeLenses for.</param>
        /// <returns>All Pester CodeLenses for the given script file.</returns>
        public CodeLens[] ProvideCodeLenses(ScriptFile scriptFile)
        {
            var lenses = new List <CodeLens>();

            foreach (SymbolReference symbol in _symbolProvider.ProvideDocumentSymbols(scriptFile))
            {
                if (symbol is PesterSymbolReference pesterSymbol)
                {
                    if (pesterSymbol.Command != PesterCommandType.Describe)
                    {
                        continue;
                    }

                    lenses.AddRange(GetPesterLens(pesterSymbol, scriptFile));
                }
            }

            return(lenses.ToArray());
        }
Exemplo n.º 5
0
        /// <summary>
        /// Get all reference code lenses for a given script file.
        /// </summary>
        /// <param name="scriptFile">The PowerShell script file to get code lenses for.</param>
        /// <returns>An array of CodeLenses describing all functions in the given script file.</returns>
        public CodeLens[] ProvideCodeLenses(ScriptFile scriptFile)
        {
            var acc = new List <CodeLens>();

            foreach (SymbolReference sym in _symbolProvider.ProvideDocumentSymbols(scriptFile))
            {
                if (sym.SymbolType == SymbolType.Function)
                {
                    acc.Add(new CodeLens
                    {
                        Data = JToken.FromObject(new
                        {
                            Uri        = scriptFile.DocumentUri,
                            ProviderId = nameof(ReferencesCodeLensProvider)
                        }, LspSerializer.Instance.JsonSerializer),
                        Range = sym.ScriptRegion.ToRange()
                    });
                }
            }

            return(acc.ToArray());
        }
        /// <summary>
        /// Get all Pester CodeLenses for a given script file.
        /// </summary>
        /// <param name="scriptFile">The script file to get Pester CodeLenses for.</param>
        /// <returns>All Pester CodeLenses for the given script file.</returns>
        public CodeLens[] ProvideCodeLenses(ScriptFile scriptFile)
        {
            var lenses = new List <CodeLens>();

            foreach (SymbolReference symbol in _symbolProvider.ProvideDocumentSymbols(scriptFile))
            {
                if (!(symbol is PesterSymbolReference pesterSymbol))
                {
                    continue;
                }

                if (_configurationService.CurrentSettings.Pester.UseLegacyCodeLens &&
                    pesterSymbol.Command != PesterCommandType.Describe)
                {
                    continue;
                }

                lenses.AddRange(GetPesterLens(pesterSymbol, scriptFile));
            }

            return(lenses.ToArray());
        }