Skip to content

Commit

Permalink
Merge pull request #34 from rafaeelaudibert/33-extension-fails-with-t…
Browse files Browse the repository at this point in the history
…erminal-failed-to-launch

Handle absolute path when creating terminal
  • Loading branch information
thadeu authored Feb 2, 2024
2 parents 6247401 + 2430afb commit b6661cc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/Utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as vscode from 'vscode'
import get from 'lodash.get'
import nodePath from 'path'

import {
SettingsType,
Expand Down Expand Up @@ -33,6 +34,12 @@ export function getWorkspace() {
}
}

export function createTerminal(name: string, path: string) {
let cwd = nodePath.isAbsolute(path) ? path : `/${path}`

return vscode.window.createTerminal({ name, cwd })
}

export function getByKeyOrAll(object, key) {
if (key) {
return object[key]
Expand Down
13 changes: 10 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ import get from 'lodash.get'

import FileObject from './FileObject'

import { getWorkspace, factorySettings, isMultipleWorkSpaces, getActiveLine, clearTerminal } from './Utils'
import {
getWorkspace,
factorySettings,
isMultipleWorkSpaces,
getActiveLine,
clearTerminal,
createTerminal,
} from './Utils'

let terminals = {}
let lastExecuted = ''
Expand All @@ -19,14 +26,14 @@ function getTerminal(): vscode.Terminal {
return opened
}

return vscode.window.createTerminal({ name, cwd: workspace.path })
return createTerminal(name, workspace.path)
}

if (get(terminals, name)) {
return get(terminals, name)
}

terminals[name] = vscode.window.createTerminal({ name, cwd: workspace.path })
terminals[name] = createTerminal(name, workspace.path)
return get(terminals, name)
}

Expand Down

0 comments on commit b6661cc

Please sign in to comment.