public override Task Initialize(Properties status) { var controller = (FileDocumentController)Controller; var filePath = controller.FilePath.ToString(); var textBuffer = controller.GetContent <ITextBuffer>(); if (!_workspaceAccessor.TryGetWorkspace(textBuffer, out var workspace)) { return(Task.CompletedTask); } _editorDocumentManager = workspace.Services.GetRequiredService <EditorDocumentManager>() as VisualStudioMacEditorDocumentManager; Debug.Assert(_editorDocumentManager != null); _editorDocumentManager.HandleDocumentOpened(filePath, textBuffer); return(Task.CompletedTask); }
public override async Task <Range> TryResolveBreakpointRangeAsync(ITextBuffer textBuffer, int lineIndex, int characterIndex, CancellationToken cancellationToken) { if (textBuffer is null) { throw new ArgumentNullException(nameof(textBuffer)); } if (!_fileUriProvider.TryGet(textBuffer, out var documentUri)) { // Not an addressable Razor document. Do not allow a breakpoint here. In practice this shouldn't happen, just being defensive. return(null); } if (!_documentManager.TryGetDocument(documentUri, out var documentSnapshot)) { // No associated Razor document. Do not allow a breakpoint here. In practice this shouldn't happen, just being defensive. return(null); } var cacheKey = new CacheKey(documentSnapshot.Uri, documentSnapshot.Version, lineIndex, characterIndex); if (_cache.TryGetValue(cacheKey, out var cachedRange)) { // We've seen this request before, no need to go async. return(cachedRange); } var lspPosition = new Position(lineIndex, characterIndex); var projectionResult = await _projectionProvider.GetProjectionAsync(documentSnapshot, lspPosition, cancellationToken).ConfigureAwait(false); if (projectionResult == null) { // Can't map the position, invalid breakpoint location. return(null); } cancellationToken.ThrowIfCancellationRequested(); if (projectionResult.LanguageKind != RazorLanguageKind.CSharp) { // We only allow breakpoints in C# return(null); } if (!documentSnapshot.TryGetVirtualDocument <CSharpVirtualDocumentSnapshot>(out var virtualDocument)) { Debug.Fail($"Some how there's no C# document associated with the host Razor document {documentUri.OriginalString} when validating breakpoint locations."); return(null); } _workspaceAccessor.TryGetWorkspace(textBuffer, out var workspace); var syntaxTree = await virtualDocument.GetCSharpSyntaxTreeAsync(workspace, cancellationToken).ConfigureAwait(false); if (!RazorBreakpointSpans.TryGetBreakpointSpan(syntaxTree, projectionResult.PositionIndex, cancellationToken, out var csharpBreakpointSpan)) { return(null); } virtualDocument.Snapshot.GetLineAndCharacter(csharpBreakpointSpan.Start, out var startLineIndex, out var startCharacterIndex); virtualDocument.Snapshot.GetLineAndCharacter(csharpBreakpointSpan.End, out var endLineIndex, out var endCharacterIndex); var projectedRange = new[] { new Range() { Start = new Position(startLineIndex, startCharacterIndex), End = new Position(endLineIndex, endCharacterIndex), }, }; var hostDocumentMapping = await _documentMappingProvider.MapToDocumentRangesAsync(RazorLanguageKind.CSharp, documentUri, projectedRange, cancellationToken).ConfigureAwait(false); if (hostDocumentMapping == null) { return(null); } cancellationToken.ThrowIfCancellationRequested(); var hostDocumentRange = hostDocumentMapping.Ranges.FirstOrDefault(); // Cache range so if we're asked again for this document/line/character we don't have to go async. _cache.Set(cacheKey, hostDocumentRange); return(hostDocumentRange); }
public override async Task <IReadOnlyList <string> > TryResolveProximityExpressionsAsync(ITextBuffer textBuffer, int lineIndex, int characterIndex, CancellationToken cancellationToken) { if (textBuffer is null) { throw new ArgumentNullException(nameof(textBuffer)); } if (!_fileUriProvider.TryGet(textBuffer, out var documentUri)) { // Not an addressable Razor document. Do not allow expression resolution here. In practice this shouldn't happen, just being defensive. return(null); } if (!_documentManager.TryGetDocument(documentUri, out var documentSnapshot)) { // No associated Razor document. Do not resolve expressions here. In practice this shouldn't happen, just being defensive. return(null); } var cacheKey = new CacheKey(documentSnapshot.Uri, documentSnapshot.Version, lineIndex, characterIndex); if (_cache.TryGetValue(cacheKey, out var cachedExpressions)) { // We've seen this request before, no need to go async. return(cachedExpressions); } var lspPosition = new Position(lineIndex, characterIndex); var projectionResult = await _projectionProvider.GetProjectionAsync(documentSnapshot, lspPosition, cancellationToken).ConfigureAwait(false); if (projectionResult == null) { // Can't map the position, invalid breakpoint location. return(null); } cancellationToken.ThrowIfCancellationRequested(); if (projectionResult.LanguageKind != RazorLanguageKind.CSharp) { // We only allow proximity expressions in C# return(null); } if (!documentSnapshot.TryGetVirtualDocument <CSharpVirtualDocumentSnapshot>(out var virtualDocument)) { Debug.Fail($"Somehow there's no C# document associated with the host Razor document {documentUri.OriginalString} when retrieving proximity expressions."); return(null); } _workspaceAccessor.TryGetWorkspace(textBuffer, out var workspace); var syntaxTree = await virtualDocument.GetCSharpSyntaxTreeAsync(workspace, cancellationToken).ConfigureAwait(false); var proximityExpressions = RazorCSharpProximityExpressionResolverService.GetProximityExpressions(syntaxTree, projectionResult.PositionIndex, cancellationToken)?.ToList(); // Cache range so if we're asked again for this document/line/character we don't have to go async. _cache.Set(cacheKey, proximityExpressions); return(proximityExpressions); }