Skip to content

Commit

Permalink
Handle absolute path when creating terminal
Browse files Browse the repository at this point in the history
On WSL (Ubuntu 22.04, more specifically) the terminal would fail to launch with a "The terminal process failed to launch". This is happening because the workspace path is being returned as a relative path, but `vscode.window.createTerminal` expects an absolute `cwd` parameter.

We solved that by simply appending a `/` at the front of the path in case it doesn't have one yet.

Closes #33
  • Loading branch information
rafaeelaudibert committed Oct 18, 2023
1 parent 825550f commit 2430afb
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 2430afb

Please sign in to comment.