Skip to content

fix open file not working - revert #36

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions src/actions/setupActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ const commandErrorMessageFilter: ErrorMessageFilter = {
}
}

const runCommands = async (commands: string[], language: string) => {

// TODO: pass command and command name down for filtering. Eg. JAVASCRIPT, 'npm install'
const runCommands = async (commands: string[], language: string = 'JAVASCRIPT') => {
for (const command of commands) {
const {stdout, stderr} = await node.exec(command)
if (stderr) {
Expand All @@ -43,13 +45,28 @@ const setupActions = async (workspaceRoot: vscode.WorkspaceFolder, {commands, co
}

// run command

await runCommands(commands)

// open files
for (const filePath of files) {
console.log(`OPEN_FILE ${filePath}`)
try {
const absoluteFilePath = join(workspaceRoot.uri.path, filePath)
// TODO: figure out why this does not work
// try {
// const absoluteFilePath = join(workspaceRoot.uri.path, filePath)
// const doc = await vscode.workspace.openTextDocument(absoluteFilePath)
// await vscode.window.showTextDocument(doc, vscode.ViewColumn.One)
// // there are times when initialization leave the panel behind any files opened
// // ensure the panel is redrawn on the right side first
// // webview.createOrShow(vscode.ViewColumn.Two)
// } catch (error) {
// console.log(`Failed to open file ${filePath}`, error)
// }
const wr = vscode.workspace.rootPath
if (!wr) {
throw new Error('No workspace root path')
}
const absoluteFilePath = join(wr, filePath)
const doc = await vscode.workspace.openTextDocument(absoluteFilePath)
await vscode.window.showTextDocument(doc, vscode.ViewColumn.One)
// there are times when initialization leave the panel behind any files opened
Expand All @@ -61,4 +78,6 @@ const setupActions = async (workspaceRoot: vscode.WorkspaceFolder, {commands, co
}
}

export default setupActions
export default setupActions


17 changes: 17 additions & 0 deletions src/services/git/gitAction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import node from '../node'

interface GitAction {
command: string
onError?(stderr: string): any
onSuccess?(stdout: string): any
}

// handle common node.exec logic
export const gitAction = async ({command, onError, onSuccess}: GitAction) => {
const {stdout, stderr} = await node.exec(command)
if (onError && stderr) {
return onError(stderr)
} else if (onSuccess && stdout) {
return onSuccess(stdout)
}
}