-
Notifications
You must be signed in to change notification settings - Fork 485
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cwl): "clear screen", "stop session" actions #5958
## Problem Users may want to clear their screen during a tailing session. The liveTail document is read only. Users may want to stop their session without closing the document. ## Solution Provide a codeLens to clear the screen (make document empty) Provide a codeLens to stop the session without closing the document. Moves Interval Timer for updating the StatusBar to the LiveTailSession object so `stopLiveTailSession()` can interrupt it, and be guaranteed to be cleaned up. The TextDocument's URI and Session URI seem to not be equal. Looking up in the LiveTailSessionRegistry with a document URI causes a session to not be found. Converting with `toString` allows these URIs to match and the registry to work as intended. Improves Exception handling on-stream. Previously, stopping the session in an expected fashion (codeLens, Closing editors) would cause an exception to bubble up and appear to the User. New change recognizes when the Abort Controller triggers, signifying an error has not occured, and logs the event as opposed to surfacing an error. Exposing only `isAborted` so that a caller has to use `stopLiveTailSession` to trigger the abortController and guarantee that other clean up actions have taken place.
- Loading branch information
1 parent
21b4e7c
commit e6645d4
Showing
6 changed files
with
118 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
packages/core/src/awsService/cloudWatchLogs/document/liveTailCodeLensProvider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/*! | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import * as vscode from 'vscode' | ||
import { cloudwatchLogsLiveTailScheme } from '../../../shared/constants' | ||
|
||
export class LiveTailCodeLensProvider implements vscode.CodeLensProvider { | ||
onDidChangeCodeLenses?: vscode.Event<void> | undefined | ||
|
||
provideCodeLenses( | ||
document: vscode.TextDocument, | ||
token: vscode.CancellationToken | ||
): vscode.ProviderResult<vscode.CodeLens[]> { | ||
const uri = document.uri | ||
if (uri.scheme !== cloudwatchLogsLiveTailScheme) { | ||
return [] | ||
} | ||
const codeLenses: vscode.CodeLens[] = [] | ||
codeLenses.push(this.buildClearDocumentCodeLens(document)) | ||
codeLenses.push(this.buildStopTailingCodeLens(document)) | ||
return codeLenses | ||
} | ||
|
||
private buildClearDocumentCodeLens(document: vscode.TextDocument): vscode.CodeLens { | ||
const range = this.getBottomOfDocumentRange(document) | ||
const command: vscode.Command = { | ||
title: 'Clear document', | ||
command: 'aws.cwl.clearDocument', | ||
arguments: [document], | ||
} | ||
return new vscode.CodeLens(range, command) | ||
} | ||
|
||
private buildStopTailingCodeLens(document: vscode.TextDocument): vscode.CodeLens { | ||
const range = this.getBottomOfDocumentRange(document) | ||
const command: vscode.Command = { | ||
title: 'Stop tailing', | ||
command: 'aws.cwl.stopTailingLogGroup', | ||
arguments: [document], | ||
} | ||
return new vscode.CodeLens(range, command) | ||
} | ||
|
||
private getBottomOfDocumentRange(document: vscode.TextDocument): vscode.Range { | ||
return new vscode.Range( | ||
new vscode.Position(document.lineCount - 1, 0), | ||
new vscode.Position(document.lineCount - 1, 0) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters