Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Feature/output channel#557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ShMcK merged 9 commits intomasterfromfeature/output-channel
Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletionsrc/actions/onOpenLogs.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
import * as T from 'typings'
import { showOutput } from '../services/testRunner/output'
import { showOutput } from '../services/logger/output'

export const onOpenLogs = async (action: T.Action): Promise<void> => {
const channel = action.payload.channel
Expand Down
3 changes: 2 additions & 1 deletionsrc/actions/onRunReset.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,7 @@ import Context from '../services/context/context'
import reset from '../services/reset'
import * as hooks from '../services/hooks'
import getCommitHashByPosition from '../services/reset/lastHash'
import logger from '../services/logger'

type ResetAction = {
type: 'LATEST' | 'POSITION'
Expand All@@ -22,7 +23,7 @@ const onRunReset = async (action: ResetAction, context: Context): Promise<void>
const branch = tutorial?.config.repo.branch

if (!branch) {
console.error('No repo branch found for tutorial')
logger('Error:No repo branch found for tutorial')
return
}

Expand Down
2 changes: 1 addition & 1 deletionsrc/actions/onTutorialConfigContinue.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,7 +8,7 @@ import logger from '../services/logger'
import { setupWebhook } from '../services/hooks/webhooks'

const onTutorialConfigContinue = async (action: T.Action, context: Context): Promise<void> => {
logger('onTutorialConfigContinue',action)
logger(`Continuing tutorial from progress: ${JSON.stringify(action.payload)}`)
try {
const tutorialToContinue: TT.Tutorial | null = context.tutorial.get()
if (!tutorialToContinue) {
Expand Down
9 changes: 8 additions & 1 deletionsrc/channel.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,7 +28,14 @@ class Channel implements Channel {
// action may be an object.type or plain string
const actionType: string = typeof action === 'string' ? action : action.type

logger(`EXT RECEIVED: "${actionType}"`)
if (actionType === 'CLIENT_LOG') {
// logs in web client are not easily visible
// it's simpler to log to the "CodeRoad (Logs)" channel
logger(action.payload)
return
}

logger(actionType)

switch (actionType) {
case 'EDITOR_STARTUP':
Expand Down
12 changes: 6 additions & 6 deletionssrc/commands.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,15 +21,15 @@ interface CreateCommandProps {
}

let sendToClient = (action: T.Action): void => {
// function is replaced whenwebclient loads
// function is replaced whenwebview mounts
}

// This makes it easier to pass the send
// function throughout the codebase
export const send = (action: T.Action): void => {
logger(`EXT TO CLIENT: "${typeof action === 'string' ? action : action.type}"`)

if (action)sendToClient(action)
// log send of event to client
logger(`${typeof action === 'string' ? action : action.type}`)
sendToClient(action)
}

export const createCommands = (commandProps: CreateCommandProps): { [key: string]: any } => {
Expand DownExpand Up@@ -75,7 +75,7 @@ export const createCommands = (commandProps: CreateCommandProps): { [key: string
}
testRunner = createTestRunner(data, {
onSuccess: (position: T.Position) => {
logger('test pass position',position)
logger(`Test pass position: ${JSON.stringify(position)}`)
// send test pass message back to client
channel.context.position.set({ ...position, complete: true })
send({ type: 'TEST_PASS', payload: { position: { ...position, complete: true } } })
Expand All@@ -91,7 +91,7 @@ export const createCommands = (commandProps: CreateCommandProps): { [key: string
},
onRun: (position: T.Position) => {
// send test run message back to client
send({ type: 'TEST_RUNNING', payload: { position } })
send({ type: 'START_TEST', payload: { position } })
},
onLoadSubtasks: ({ summary }) => {
send({ type: 'LOAD_SUBTASK_RESULTS', payload: { summary } })
Expand Down
3 changes: 0 additions & 3 deletionssrc/environment.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,9 +10,6 @@ export type Env = 'test' | 'local' | 'development' | 'production'
// @ts-ignore
export const NODE_ENV: Env = process.env.NODE_ENV || 'development'

// toggle logging
export const LOG = (process.env.CODEROAD_ENABLE_LOG || '').toLowerCase() === 'true'

// error logging tool
export const INSTRUMENTATION_KEY = '6ff37c76-72f3-48e3-a1b9-d5636f519b7b'

Expand Down
34 changes: 18 additions & 16 deletionssrc/services/git/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,14 +9,14 @@ const stashAllFiles = async (): Promise<never | void> => {
// stash files including untracked (eg. newly created file)
const { stderr } = await exec({ command: `git stash --include-untracked` })
if (stderr) {
console.error(stderr)
logger(`Error: ${stderr}`)
throw new Error('Error stashing files')
}
}

const cherryPickCommit = async (commit: string, count = 0): Promise<never | void> => {
if (count > 1) {
console.warn('cherry-pick failed')
logger('cherry-pick failed')
return
}
try {
Expand All@@ -26,8 +26,8 @@ const cherryPickCommit = async (commit: string, count = 0): Promise<never | void
if (!stdout) {
throw new Error('No cherry-pick output')
}
} catch (error) {
console.log('cherry-pick-commit failed')
} catch (error: any) {
logger(`cherry-pick-commit failed: ${error.message}`)
// stash all files if cherry-pick fails
await stashAllFiles()
return cherryPickCommit(commit, ++count)
Expand All@@ -50,10 +50,10 @@ export function loadCommit(commit: string): Promise<never | void> {
export async function saveCommit(message: string): Promise<never | void> {
const { stdout, stderr } = await exec({ command: `git commit -am '${message}'` })
if (stderr) {
console.error(stderr)
logger(`Error: ${stderr}`)
throw new Error('Error saving progress to Git')
}
logger(['save with commit & continuestdout', stdout])
logger(`Commit saved: ${stdout}`)
}

export async function clear(): Promise<Error | void> {
Expand All@@ -63,9 +63,9 @@ export async function clear(): Promise<Error | void> {
if (!stderr) {
return
}
console.error(stderr)
} catch (error) {
console.error(error)
logger(`Error: ${stderr}`)
} catch (error: any) {
logger(`Error: ${error.message}`)
}
throw new Error('Error cleaning up current unsaved work')
}
Expand DownExpand Up@@ -127,7 +127,7 @@ export async function addRemote(repo: string): Promise<never | void> {

// validate the response is acceptable
if (!alreadyExists && !successfulNewBranch) {
console.error(stderr)
logger(`Error: ${stderr}`)
throw new Error('Error adding git remote')
}
}
Expand All@@ -142,7 +142,8 @@ export async function checkRemoteExists(): Promise<boolean> {
// string match on remote output
// TODO improve the specificity of this regex
return !!stdout.match(gitOrigin)
} catch (error) {
} catch (error: any) {
logger(`Warn: ${error.message}`)
return false
}
}
Expand All@@ -168,8 +169,9 @@ export async function loadCommitHistory(): Promise<string[]> {
}
// string match on remote output
return stdout.split('\n')
} catch (error) {
} catch (error: any) {
// likely no git setup or no commits
logger(`Warn: ${error.message}`)
return []
}
}
Expand All@@ -189,8 +191,8 @@ export async function getCommitMessage(hash: string): Promise<string | null> {
}
// string match on remote output
return stdout
} catch (error) {
logger('error',error)
} catch (error: any) {
logger(`Error: ${error.message}`)
// likely no git commit message found
return null
}
Expand All@@ -204,8 +206,8 @@ export async function commitsExistsByMessage(message: string): Promise<boolean>
return false
}
return !!stdout.length
} catch (error) {
logger('error',error)
} catch (error: any) {
logger(`Error: ${error.message}`)
// likely no commit found
return false
}
Expand Down
3 changes: 2 additions & 1 deletionsrc/services/hooks/utils/openFiles.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
import { join } from 'path'
import * as vscode from 'vscode'
import logger from '../../logger'

const openFiles = async (files: string[] = []): Promise<void> => {
if (!files.length) {
Expand All@@ -16,7 +17,7 @@ const openFiles = async (files: string[] = []): Promise<void> => {
const doc = await vscode.workspace.openTextDocument(absoluteFilePath)
await vscode.window.showTextDocument(doc, vscode.ViewColumn.One)
} catch (error: any) {
console.log(`Failed to open file ${filePath}: ${error.message}`)
logger(`Failed to open file ${filePath}: ${error.message}`)
}
}
}
Expand Down
5 changes: 3 additions & 2 deletionssrc/services/hooks/utils/runCommands.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
import { exec } from '../../node'
import { send } from '../../../commands'
import logger from '../../logger'

const runCommands = async (commands: string[] = []): Promise<void> => {
if (!commands.length) {
Expand All@@ -14,9 +15,9 @@ const runCommands = async (commands: string[] = []): Promise<void> => {
let result: { stdout: string; stderr: string }
try {
result = await exec({ command })
console.log(result)
logger(`Command output: ${JSON.stringify(result)}`)
} catch (error: any) {
console.error(`Command failed: ${error.message}`)
logger(`Command failed: ${error.message}`)
send({ type: 'COMMAND_FAIL', payload: { process: { ...process, status: 'FAIL' } } })
return
}
Expand Down
13 changes: 5 additions & 8 deletionssrc/services/logger/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
import {LOG } from '../../environment'
import {getOutputChannel } from './output'

export type Log = any

const logChannel = getOutputChannel('CodeRoad (Logs)')

const logger = (...messages: Log[]): void => {
if (!LOG) {
return
}
// Inside vscode, you console.log does not allow more than 1 param
// to get around it, we can log with multiple log statements
for (const message of messages) {
if (typeof message === 'object') {
console.log(JSON.stringify(message))
logChannel.appendLine(message)
} else {
console.log(message)
logChannel.appendLine(message)
}
}
}
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,7 @@ const channels:
/* */
} = {}

const getOutputChannel = (name: string): vscode.OutputChannel => {
exportconst getOutputChannel = (name: string): vscode.OutputChannel => {
if (!channels[name]) {
channels[name] = vscode.window.createOutputChannel(name)
}
Expand Down
5 changes: 3 additions & 2 deletionssrc/services/node/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@ import * as fs from 'fs'
import { join } from 'path'
import { promisify } from 'util'
import { WORKSPACE_ROOT } from '../../environment'
import logger from '../logger'

const asyncExec = promisify(cpExec)
const asyncRemoveFile = promisify(fs.unlink)
Expand DownExpand Up@@ -35,13 +36,13 @@ export const removeFile = (...paths: string[]) => {
export const readFile = (...paths: string[]): Promise<string | void> => {
const filePath = getWorkspacePath(...paths)
return asyncReadFile(getWorkspacePath(...paths), 'utf8').catch((err) => {
console.warn(`Failed to read from ${filePath}: ${err.message}`)
logger(`Failed to read from ${filePath}: ${err.message}`)
})
}

export const writeFile = (data: any, ...paths: string[]): Promise<void> => {
const filePath = getWorkspacePath(...paths)
return asyncWriteFile(filePath, data).catch((err) => {
console.warn(`Failed to write to ${filePath}: ${err.message}`)
logger(`Failed to write to ${filePath}: ${err.message}`)
})
}
9 changes: 4 additions & 5 deletionssrc/services/reset/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
import { exec, removeFile } from '../node'

import logger from '../logger'
interface Input {
hash: string
branch: string
Expand All@@ -17,13 +17,13 @@ const reset = async ({ branch, hash }: Input): Promise<void> => {
try {
// if no git init, will initialize
// otherwise re-initializes git
await exec({ command: 'git init' }).catch(console.log)
await exec({ command: 'git init' }).catch(logger)

// capture current branch
const hasBranch = await exec({ command: 'git branch --show-current' })
const localBranch = hasBranch.stdout
// check if coderoad remote exists
const hasRemote = await exec({ command: 'git remote -v' }).catch(console.warn)
const hasRemote = await exec({ command: 'git remote -v' }).catch(logger)
if (!hasRemote || !hasRemote.stdout || !hasRemote.stdout.length) {
throw new Error('No remote found')
} else if (!hasRemote.stdout.match(new RegExp(remote))) {
Expand DownExpand Up@@ -64,8 +64,7 @@ const reset = async ({ branch, hash }: Input): Promise<void> => {
command: `git reset --hard ${hash}`,
})
} catch (error: any) {
console.error('Error resetting')
console.error(error.message)
logger(`Error resetting: ${error.message}`)
}
}

Expand Down
13 changes: 8 additions & 5 deletionssrc/services/storage/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
import * as vscode from 'vscode'
import { readFile, writeFile } from '../node'
import { SESSION_STORAGE_PATH } from '../../environment'
import logger from '../logger'

// NOTE: localStorage is not available on client
// and must be stored in editor
Expand DownExpand Up@@ -46,17 +47,17 @@ class Storage<T> {
return data
}
}
} catch (err) {
console.warn(`Failed to read or parse session file: ${SESSION_STORAGE_PATH}/${this.filePath}.json`)
} catch (err: any) {
logger(`Failed to read or parse session file: ${SESSION_STORAGE_PATH}/${this.filePath}.json: ${err.message}`)
}
}
const value: string | undefined = await this.storage.get(this.key)
if (value) {
// 2. read from local storage
try {
return JSON.parse(value)
} catch (err) {
console.warn(`Failed to parse session state from local storage: ${value}`)
} catch (err: any) {
logger(`Failed to parse session state from local storage: ${value}: ${err.message}`)
}
}
// 3. fallback to the default
Expand All@@ -83,7 +84,9 @@ class Storage<T> {
try {
writeFile(data, SESSION_STORAGE_PATH, `${this.filePath}.json`)
} catch (err: any) {
console.warn(`Failed to write coderoad session to path: ${SESSION_STORAGE_PATH}/${this.filePath}.json`)
logger(
`Failed to write coderoad session to path: ${SESSION_STORAGE_PATH}/${this.filePath}.json: ${err.message}`,
)
}
}
}
Expand Down
4 changes: 1 addition & 3 deletionssrc/services/telemetry/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,7 +19,7 @@ interface Measurements {
let reporter: any

export const activate = (subscribeFn: (reporter: any) => void): void => {
logger(EXTENSION_ID,VERSION, INSTRUMENTATION_KEY)
logger(`${EXTENSION_ID} v${VERSION}`)
reporter = new TelemetryReporter(EXTENSION_ID, VERSION, INSTRUMENTATION_KEY)
subscribeFn(reporter)
}
Expand All@@ -31,14 +31,12 @@ export const deactivate = (): void => {
}

export const onError = (error: Error, properties?: Properties, measurements?: Measurements): void => {
logger(error, properties, measurements)
if (reporter) {
reporter.sendTelemetryException(error, properties, measurements)
}
}

export const onEvent = (eventName: string, properties?: Properties, measurements?: Measurements): void => {
logger(eventName, properties, measurements)
if (reporter) {
reporter.sendTelemetryEvent(eventName, properties, measurements)
}
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp