Skip to content

Commit 42afaf0

Browse files
committed
add helper function to remove code dupe
1 parent af63618 commit 42afaf0

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

packages/core/src/awsService/cloudWatchLogs/commands/searchLogGroup.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { createBackButton, createExitButton, createHelpButton } from '../../../s
2929
import { PromptResult } from '../../../shared/ui/prompter'
3030
import { ToolkitError } from '../../../shared/errors'
3131
import { Messages } from '../../../shared/utilities/messages'
32+
import { showFile } from '../../../shared/utilities/textDocumentUtilities'
3233

3334
const localize = nls.loadMessageBundle()
3435

@@ -65,9 +66,7 @@ export async function prepareDocument(uri: vscode.Uri, logData: CloudWatchLogsDa
6566
try {
6667
// Gets the data: calls filterLogEventsFromUri().
6768
await registry.fetchNextLogEvents(uri)
68-
const doc = await vscode.workspace.openTextDocument(uri)
69-
await vscode.window.showTextDocument(doc, { preview: false })
70-
await vscode.languages.setTextDocumentLanguage(doc, 'log')
69+
await showFile(uri)
7170
} catch (err) {
7271
if (CancellationError.isUserCancelled(err)) {
7372
throw err

packages/core/src/awsService/ec2/commands.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
5-
import * as vscode from 'vscode'
65
import { Ec2InstanceNode } from './explorer/ec2InstanceNode'
76
import { Ec2Node } from './explorer/ec2ParentNode'
87
import { Ec2ConnectionManager } from './model'
@@ -14,6 +13,7 @@ import { ec2LogSchema } from './ec2LogDocumentProvider'
1413
import { getAwsConsoleUrl } from '../../shared/awsConsole'
1514
import { showRegionPrompter } from '../../auth/utils'
1615
import { openUrl } from '../../shared/utilities/vsCodeUtils'
16+
import { showFile } from '../../shared/utilities/textDocumentUtilities'
1717

1818
export function refreshExplorer(node?: Ec2Node) {
1919
if (node) {
@@ -74,8 +74,5 @@ export async function copyInstanceId(instanceId: string): Promise<void> {
7474
}
7575

7676
export async function openLogDocument(node?: Ec2InstanceNode): Promise<void> {
77-
const uri = ec2LogSchema.form(await getSelection(node))
78-
const doc = await vscode.workspace.openTextDocument(uri)
79-
await vscode.window.showTextDocument(doc, { preview: false })
80-
await vscode.languages.setTextDocumentLanguage(doc, 'log')
77+
return await showFile(ec2LogSchema.form(await getSelection(node)))
8178
}

packages/core/src/shared/utilities/textDocumentUtilities.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,9 @@ export function getIndentedCode(message: any, doc: vscode.TextDocument, selectio
184184

185185
return indent(message.code, indentation.length)
186186
}
187+
188+
export async function showFile(uri: vscode.Uri) {
189+
const doc = await vscode.workspace.openTextDocument(uri)
190+
await vscode.window.showTextDocument(doc, { preview: false })
191+
await vscode.languages.setTextDocumentLanguage(doc, 'log')
192+
}

0 commit comments

Comments
 (0)