Exemple #1
0
 /// <summary>
 /// Construct a new ReferencesCodeLensProvider for a given EditorSession.
 /// </summary>
 /// <param name="workspaceService"></param>
 /// <param name="symbolsService"></param>
 public ReferencesCodeLensProvider(WorkspaceService workspaceService, SymbolsService symbolsService)
 {
     _workspaceService = workspaceService;
     _symbolsService   = symbolsService;
     // TODO: Pull this from components
     _symbolProvider = new ScriptDocumentSymbolProvider();
 }
        public override async Task <LocationOrLocationLinks> Handle(DefinitionParams request, CancellationToken cancellationToken)
        {
            ScriptFile scriptFile = _workspaceService.GetFile(request.TextDocument.Uri);

            SymbolReference foundSymbol =
                SymbolsService.FindSymbolAtLocation(
                    scriptFile,
                    request.Position.Line + 1,
                    request.Position.Character + 1);

            List <LocationOrLocationLink> definitionLocations = new List <LocationOrLocationLink>();

            if (foundSymbol != null)
            {
                SymbolReference foundDefinition = await _symbolsService.GetDefinitionOfSymbolAsync(
                    scriptFile,
                    foundSymbol).ConfigureAwait(false);

                if (foundDefinition != null)
                {
                    definitionLocations.Add(
                        new LocationOrLocationLink(
                            new Location
                    {
                        Uri   = DocumentUri.From(foundDefinition.FilePath),
                        Range = GetRangeFromScriptRegion(foundDefinition.ScriptRegion)
                    }));
                }
            }

            return(new LocationOrLocationLinks(definitionLocations));
        }
 public TradeService(SymbolsService symbolsService, HttpClient httpClient)
 {
     _symbolsService = symbolsService;
     _httpClient     = httpClient;
     Init();
     SetTimer();
 }
 public KlineService(HttpClient httpClient, SymbolsService symbolsService)
 {
     _httpClient     = httpClient;
     _symbolsService = symbolsService;
     Init();
     SetTimer();
 }
 private IReadOnlyList <SymbolReference> GetOccurrences(ScriptRegion scriptRegion)
 {
     return(SymbolsService.FindOccurrencesInFile(
                GetScriptFile(scriptRegion),
                scriptRegion.StartLineNumber,
                scriptRegion.StartColumnNumber));
 }
Exemple #6
0
 public PsesDefinitionHandler(
     SymbolsService symbolsService,
     WorkspaceService workspaceService)
 {
     _symbolsService   = symbolsService;
     _workspaceService = workspaceService;
 }
Exemple #7
0
        public override Task <LocationContainer> Handle(ReferenceParams request, CancellationToken cancellationToken)
        {
            ScriptFile scriptFile = _workspaceService.GetFile(request.TextDocument.Uri);

            SymbolReference foundSymbol =
                SymbolsService.FindSymbolAtLocation(
                    scriptFile,
                    request.Position.Line + 1,
                    request.Position.Character + 1);

            List <SymbolReference> referencesResult =
                _symbolsService.FindReferencesOfSymbol(
                    foundSymbol,
                    _workspaceService.ExpandScriptReferences(scriptFile),
                    _workspaceService);

            var locations = new List <Location>();

            if (referencesResult != null)
            {
                foreach (SymbolReference foundReference in referencesResult)
                {
                    locations.Add(new Location
                    {
                        Uri   = DocumentUri.From(foundReference.FilePath),
                        Range = GetRangeFromScriptRegion(foundReference.ScriptRegion)
                    });
                }
            }

            return(Task.FromResult(new LocationContainer(locations)));
        }
Exemple #8
0
        public override Task <DocumentHighlightContainer> Handle(
            DocumentHighlightParams request,
            CancellationToken cancellationToken)
        {
            ScriptFile scriptFile = _workspaceService.GetFile(request.TextDocument.Uri);

            IReadOnlyList <SymbolReference> symbolOccurrences = SymbolsService.FindOccurrencesInFile(
                scriptFile,
                request.Position.Line + 1,
                request.Position.Character + 1);

            if (symbolOccurrences == null)
            {
                return(Task.FromResult(s_emptyHighlightContainer));
            }

            var highlights = new DocumentHighlight[symbolOccurrences.Count];

            for (int i = 0; i < symbolOccurrences.Count; i++)
            {
                highlights[i] = new DocumentHighlight
                {
                    Kind  = DocumentHighlightKind.Write, // TODO: Which symbol types are writable?
                    Range = symbolOccurrences[i].ScriptRegion.ToRange()
                };
            }

            return(Task.FromResult(new DocumentHighlightContainer(highlights)));
        }
 public PsesDefinitionHandler(
     ILoggerFactory factory,
     SymbolsService symbolsService,
     WorkspaceService workspaceService)
 {
     _logger           = factory.CreateLogger <PsesDefinitionHandler>();
     _symbolsService   = symbolsService;
     _workspaceService = workspaceService;
 }
Exemple #10
0
 public PsesSignatureHelpHandler(
     ILoggerFactory factory,
     SymbolsService symbolsService,
     WorkspaceService workspaceService)
 {
     _logger           = factory.CreateLogger <PsesHoverHandler>();
     _symbolsService   = symbolsService;
     _workspaceService = workspaceService;
 }
        public LanguageServiceTests()
        {
            var logger = NullLogger.Instance;

            powerShellContext = PowerShellContextFactory.Create(logger);
            workspace         = new WorkspaceService(NullLoggerFactory.Instance);
            symbolsService    = new SymbolsService(NullLoggerFactory.Instance, powerShellContext, workspace, new ConfigurationService());
            completionHandler = new PsesCompletionHandler(NullLoggerFactory.Instance, powerShellContext, workspace);
        }
 public HoverHandler(
     ILoggerFactory factory,
     SymbolsService symbolsService,
     WorkspaceService workspaceService)
 {
     _logger           = factory.CreateLogger <HoverHandler>();
     _symbolsService   = symbolsService;
     _workspaceService = workspaceService;
 }
Exemple #13
0
 public DocumentHighlightHandler(
     ILoggerFactory loggerFactory,
     WorkspaceService workspaceService,
     SymbolsService symbolService)
 {
     _logger           = loggerFactory.CreateLogger <DocumentHighlightHandler>();
     _workspaceService = workspaceService;
     _symbolsService   = symbolService;
     _logger.LogInformation("highlight handler loaded");
 }
Exemple #14
0
 public PsesSignatureHelpHandler(
     ILoggerFactory factory,
     SymbolsService symbolsService,
     WorkspaceService workspaceService,
     IInternalPowerShellExecutionService executionService)
 {
     _logger           = factory.CreateLogger <PsesHoverHandler>();
     _symbolsService   = symbolsService;
     _workspaceService = workspaceService;
     _executionService = executionService;
 }
Exemple #15
0
 public GetCommentHelpHandler(
     ILoggerFactory factory,
     WorkspaceService workspaceService,
     AnalysisService analysisService,
     SymbolsService symbolsService)
 {
     _logger           = factory.CreateLogger <GetCommentHelpHandler>();
     _workspaceService = workspaceService;
     _analysisService  = analysisService;
     _symbolsService   = symbolsService;
 }
Exemple #16
0
 public CodeLensHandlers(ILoggerFactory factory, SymbolsService symbolsService, WorkspaceService workspaceService)
 {
     _logger           = factory.CreateLogger <FoldingRangeHandler>();
     _workspaceService = workspaceService;
     _symbolsService   = symbolsService;
     _providers        = new ICodeLensProvider[]
     {
         new ReferencesCodeLensProvider(_workspaceService, _symbolsService),
         new PesterCodeLensProvider()
     };
 }
 public SymbolsServiceTests()
 {
     psesHost       = PsesHostFactory.Create(NullLoggerFactory.Instance);
     workspace      = new WorkspaceService(NullLoggerFactory.Instance);
     symbolsService = new SymbolsService(
         NullLoggerFactory.Instance,
         psesHost,
         psesHost,
         workspace,
         new ConfigurationService());
 }
 public SignatureHelpHandler(
     ILoggerFactory factory,
     SymbolsService symbolsService,
     WorkspaceService workspaceService,
     PowerShellContextService powerShellContextService)
 {
     _logger                   = factory.CreateLogger <HoverHandler>();
     _symbolsService           = symbolsService;
     _workspaceService         = workspaceService;
     _powerShellContextService = powerShellContextService;
 }
        private Task <SymbolReference> GetDefinition(ScriptRegion scriptRegion)
        {
            ScriptFile scriptFile = GetScriptFile(scriptRegion);

            SymbolReference symbolReference = SymbolsService.FindSymbolAtLocation(
                scriptFile,
                scriptRegion.StartLineNumber,
                scriptRegion.StartColumnNumber);

            Assert.NotNull(symbolReference);

            return(symbolsService.GetDefinitionOfSymbolAsync(scriptFile, symbolReference));
        }
Exemple #20
0
 public DocumentHighlightHandler(
     ILoggerFactory loggerFactory,
     WorkspaceService workspaceService,
     SymbolsService symbolService)
 {
     _logger              = loggerFactory.CreateLogger <OmniSharp.Extensions.LanguageServer.Protocol.Server.DocumentHighlightHandler>();
     _workspaceService    = workspaceService;
     _symbolsService      = symbolService;
     _registrationOptions = new TextDocumentRegistrationOptions()
     {
         DocumentSelector = LspUtils.PowerShellDocumentSelector
     };
     _logger.LogInformation("highlight handler loaded");
 }
        private Task <List <SymbolReference> > GetReferences(ScriptRegion scriptRegion)
        {
            ScriptFile scriptFile = GetScriptFile(scriptRegion);

            SymbolReference symbolReference = SymbolsService.FindSymbolAtLocation(
                scriptFile,
                scriptRegion.StartLineNumber,
                scriptRegion.StartColumnNumber);

            Assert.NotNull(symbolReference);

            return(symbolsService.FindReferencesOfSymbol(
                       symbolReference,
                       workspace.ExpandScriptReferences(scriptFile),
                       workspace));
        }
Exemple #22
0
        public async Task <CommentHelpRequestResult> Handle(CommentHelpRequestParams request, CancellationToken cancellationToken)
        {
            CommentHelpRequestResult result = new();

            if (!_workspaceService.TryGetFile(request.DocumentUri, out ScriptFile scriptFile))
            {
                return(result);
            }

            int triggerLine = request.TriggerPosition.Line + 1;

            FunctionDefinitionAst functionDefinitionAst = SymbolsService.GetFunctionDefinitionForHelpComment(
                scriptFile,
                triggerLine,
                out string helpLocation);

            if (functionDefinitionAst == null)
            {
                return(result);
            }

            IScriptExtent funcExtent = functionDefinitionAst.Extent;
            string        funcText   = funcExtent.Text;

            if (helpLocation.Equals("begin"))
            {
                // check if the previous character is `<` because it invalidates
                // the param block the follows it.
                IList <string> lines = ScriptFile.GetLinesInternal(funcText);
                int            relativeTriggerLine0b = triggerLine - funcExtent.StartLineNumber;
                if (relativeTriggerLine0b > 0 && lines[relativeTriggerLine0b].IndexOf("<", StringComparison.OrdinalIgnoreCase) > -1)
                {
                    lines[relativeTriggerLine0b] = string.Empty;
                }

                funcText = string.Join("\n", lines);
            }

            string helpText = await _analysisService.GetCommentHelpText(funcText, helpLocation, forBlockComment : request.BlockComment).ConfigureAwait(false);

            if (helpText == null)
            {
                return(result);
            }

            List <string> helpLines = ScriptFile.GetLinesInternal(helpText);

            if (helpLocation != null &&
                !helpLocation.Equals("before", StringComparison.OrdinalIgnoreCase))
            {
                // we need to trim the leading `{` and newline when helpLocation=="begin"
                helpLines.RemoveAt(helpLines.Count - 1);

                // we also need to trim the leading newline when helpLocation=="end"
                helpLines.RemoveAt(0);
            }

            // Trim trailing newline from help text.
            if (string.IsNullOrEmpty(helpLines[helpLines.Count - 1]))
            {
                helpLines.RemoveAt(helpLines.Count - 1);
            }

            result.Content = helpLines.ToArray();
            return(result);
        }
Exemple #23
0
 public CodeLensHandlers(ILoggerFactory factory, SymbolsService symbolsService, WorkspaceService workspaceService)
 {
     _logger           = factory.CreateLogger <FoldingRangeHandler>();
     _workspaceService = workspaceService;
     _symbolsService   = symbolsService;
 }
Exemple #24
0
 public DepthService(SymbolsService symbolsService)
 {
     _symbolsService = symbolsService;
     Init();
     SetTimer();
 }
        /// <summary>
        /// Take a codelens and create a new codelens object with updated references.
        /// </summary>
        /// <param name="codeLens">The old code lens to get updated references for.</param>
        /// <returns>A new code lens object describing the same data as the old one but with updated references.</returns>
        public CodeLens ResolveCodeLens(CodeLens codeLens, ScriptFile scriptFile)
        {
            ScriptFile[] references = _workspaceService.ExpandScriptReferences(
                scriptFile);

            SymbolReference foundSymbol = SymbolsService.FindFunctionDefinitionAtLocation(
                scriptFile,
                codeLens.Range.Start.Line + 1,
                codeLens.Range.Start.Character + 1);

            List <SymbolReference> referencesResult = _symbolsService.FindReferencesOfSymbol(
                foundSymbol,
                references,
                _workspaceService);

            Location[] referenceLocations;
            if (referencesResult == null)
            {
                referenceLocations = s_emptyLocationArray;
            }
            else
            {
                var acc = new List <Location>();
                foreach (SymbolReference foundReference in referencesResult)
                {
                    if (IsReferenceDefinition(foundSymbol, foundReference))
                    {
                        continue;
                    }

                    DocumentUri uri = DocumentUri.From(foundReference.FilePath);
                    // For any vscode-notebook-cell, we need to ignore the backing file on disk.
                    if (uri.Scheme == "file" &&
                        scriptFile.DocumentUri.Scheme == "vscode-notebook-cell" &&
                        uri.Path == scriptFile.DocumentUri.Path)
                    {
                        continue;
                    }

                    acc.Add(new Location
                    {
                        Uri   = uri,
                        Range = foundReference.ScriptRegion.ToRange()
                    });
                }
                referenceLocations = acc.ToArray();
            }

            return(new CodeLens
            {
                Data = codeLens.Data,
                Range = codeLens.Range,
                Command = new Command
                {
                    Name = "editor.action.showReferences",
                    Title = GetReferenceCountHeader(referenceLocations.Length),
                    Arguments = JArray.FromObject(new object[]
                    {
                        scriptFile.DocumentUri,
                        codeLens.Range.Start,
                        referenceLocations
                    },
                                                  LspSerializer.Instance.JsonSerializer)
                }
            });
        }
 public PsesReferencesHandler(SymbolsService symbolsService, WorkspaceService workspaceService)
 {
     _symbolsService   = symbolsService;
     _workspaceService = workspaceService;
 }
 internal DocumentSymbolService(SymbolsService symbolsService)
 {
     _symbolsService = symbolsService;
 }
 public PsesCodeLensHandlers(ILoggerFactory factory, SymbolsService symbolsService, WorkspaceService workspaceService, ConfigurationService configurationService)
 {
     _logger           = factory.CreateLogger <PsesCodeLensHandlers>();
     _workspaceService = workspaceService;
     _symbolsService   = symbolsService;
 }
 public WorkspaceSymbolsHandler(ILoggerFactory loggerFactory, SymbolsService symbols, WorkspaceService workspace)
 {
     _logger           = loggerFactory.CreateLogger <WorkspaceSymbolsHandler>();
     _symbolsService   = symbols;
     _workspaceService = workspace;
 }