Example #1
0
        public async Task <HoverModel> Handle(HoverParams request, CancellationToken cancellationToken)
        {
            if (request is null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var document = await Task.Factory.StartNew(() =>
            {
                _documentResolver.TryResolveDocument(request.TextDocument.Uri.AbsolutePath, out var documentSnapshot);

                return(documentSnapshot);
            }, cancellationToken, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler);

            if (document is null)
            {
                return(null);
            }

            var codeDocument = await document.GetGeneratedOutputAsync();

            if (codeDocument.IsUnsupported())
            {
                return(null);
            }

            var tagHelperDocumentContext = codeDocument.GetTagHelperContext();

            var sourceText = await document.GetTextAsync();

            var linePosition      = new LinePosition((int)request.Position.Line, (int)request.Position.Character);
            var hostDocumentIndex = sourceText.Lines.GetPosition(linePosition);
            var location          = new SourceSpan(hostDocumentIndex, (int)request.Position.Line, (int)request.Position.Character, 0);

            var hoverItem = _hoverInfoService.GetHoverInfo(codeDocument, location);

            _logger.LogTrace($"Found hover info items.");

            return(hoverItem);
        }
Example #2
0
        public async Task <HoverModel> Handle(HoverParams request, CancellationToken cancellationToken)
        {
            if (request is null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var document = await _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() =>
            {
                _documentResolver.TryResolveDocument(request.TextDocument.Uri.GetAbsoluteOrUNCPath(), out var documentSnapshot);

                return(documentSnapshot);
            }, cancellationToken).ConfigureAwait(false);

            if (document is null)
            {
                return(null);
            }

            var codeDocument = await document.GetGeneratedOutputAsync();

            if (codeDocument.IsUnsupported())
            {
                return(null);
            }

            var sourceText = await document.GetTextAsync();

            var linePosition       = new LinePosition((int)request.Position.Line, (int)request.Position.Character);
            var hostDocumentIndex  = sourceText.Lines.GetPosition(linePosition);
            var location           = new SourceLocation(hostDocumentIndex, (int)request.Position.Line, (int)request.Position.Character);
            var clientCapabilities = _languageServer.ClientSettings.Capabilities;

            var hoverItem = _hoverInfoService.GetHoverInfo(codeDocument, location, clientCapabilities);

            _logger.LogTrace($"Found hover info items.");

            return(hoverItem);
        }