Skip to content

[vscode-extension] Fixed tab size for extension #1701

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
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
44 changes: 22 additions & 22 deletions vscode-extension/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/naming-convention": "warn",
"@typescript-eslint/semi": "warn",
"curly": "warn",
"eqeqeq": "warn",
"no-throw-literal": "warn",
"semi": "off"
},
"ignorePatterns": [
"out",
"dist",
"**/*.d.ts"
]
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/naming-convention": "warn",
"@typescript-eslint/semi": "warn",
"curly": "warn",
"eqeqeq": "warn",
"no-throw-literal": "warn",
"semi": "off"
},
"ignorePatterns": [
"out",
"dist",
"**/*.d.ts"
]
}
219 changes: 108 additions & 111 deletions vscode-extension/src/devbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,127 +7,124 @@ interface Message {
}

export async function devboxReopen() {

if (process.platform === 'win32') {
const seeDocs = 'See Devbox docs';
const result = await window.showErrorMessage(
'This feature is not supported on your platform. \
Please open VSCode from inside devbox shell in WSL using the CLI.', seeDocs
);
if (result === seeDocs) {
env.openExternal(Uri.parse('https://www.jetpack.io/devbox/docs/ide_configuration/vscode/#windows-setup'));
return;
}
if (process.platform === 'win32') {
const seeDocs = 'See Devbox docs';
const result = await window.showErrorMessage(
'This feature is not supported on your platform. \
Please open VSCode from inside devbox shell in WSL using the CLI.', seeDocs
);
if (result === seeDocs) {
env.openExternal(Uri.parse('https://www.jetpack.io/devbox/docs/ide_configuration/vscode/#windows-setup'));
return;
}
await window.withProgress({
location: ProgressLocation.Notification,
title: "Setting up your Devbox environment. Please don't close vscode.",
cancellable: true
},
async (progress, token) => {
token.onCancellationRequested(() => {
console.log("User canceled the long running operation");
});

const p = new Promise<void>(async (resolve, reject) => {
}
await window.withProgress({
location: ProgressLocation.Notification,
title: "Setting up your Devbox environment. Please don't close vscode.",
cancellable: true
},
async (progress, token) => {
token.onCancellationRequested(() => {
console.log("User canceled the long running operation");
});

if (workspace.workspaceFolders) {
const workingDir = workspace.workspaceFolders[0].uri;
const dotdevbox = Uri.joinPath(workingDir, '/.devbox');
progress.report({ message: 'Installing devbox packages...', increment: 25 });
await setupDotDevbox(workingDir, dotdevbox);
const p = new Promise<void>(async (resolve, reject) => {
if (workspace.workspaceFolders) {
const workingDir = workspace.workspaceFolders[0].uri;
const dotdevbox = Uri.joinPath(workingDir, '/.devbox');
progress.report({ message: 'Installing devbox packages...', increment: 25 });
await setupDotDevbox(workingDir, dotdevbox);

// setup required vscode settings
progress.report({ message: 'Updating configurations...', increment: 50 });
updateVSCodeConf();
// setup required vscode settings
progress.report({ message: 'Updating configurations...', increment: 50 });
updateVSCodeConf();

// Calling CLI to compute devbox env
progress.report({ message: 'Calling Devbox to setup environment...', increment: 80 });
// To use a custom compiled devbox when testing, change this to an absolute path.
const devbox = 'devbox';
// run devbox integrate and then close this window
let child = spawn(devbox, ['integrate', 'vscode'], {
cwd: workingDir.path,
stdio: [0, 1, 2, 'ipc']
});
// if CLI closes before sending "finished" message
child.on('close', (code: number) => {
console.log("child process closed with exit code:", code);
window.showErrorMessage("Failed to setup devbox environment.");
reject();
});
// send config path to CLI
child.send({ configDir: workingDir.path });
// handle CLI finishing the env and sending "finished"
child.on('message', function (msg: Message, handle) {
if (msg.status === "finished") {
progress.report({ message: 'Finished setting up! Reloading the window...', increment: 100 });
resolve();
commands.executeCommand("workbench.action.closeWindow");
}
else {
console.log(msg);
window.showErrorMessage("Failed to setup devbox environment.");
reject();
}
});
}
});
return p;
// Calling CLI to compute devbox env
progress.report({ message: 'Calling Devbox to setup environment...', increment: 80 });
// To use a custom compiled devbox when testing, change this to an absolute path.
const devbox = 'devbox';
// run devbox integrate and then close this window
let child = spawn(devbox, ['integrate', 'vscode'], {
cwd: workingDir.path,
stdio: [0, 1, 2, 'ipc']
});
// if CLI closes before sending "finished" message
child.on('close', (code: number) => {
console.log("child process closed with exit code:", code);
window.showErrorMessage("Failed to setup devbox environment.");
reject();
});
// send config path to CLI
child.send({ configDir: workingDir.path });
// handle CLI finishing the env and sending "finished"
child.on('message', function (msg: Message, handle) {
if (msg.status === "finished") {
progress.report({ message: 'Finished setting up! Reloading the window...', increment: 100 });
resolve();
commands.executeCommand("workbench.action.closeWindow");
}
else {
console.log(msg);
window.showErrorMessage("Failed to setup devbox environment.");
reject();
}
});
}
);


});
return p;
}
);
}

async function setupDotDevbox(workingDir: Uri, dotdevbox: Uri) {
try {
// check if .devbox exists
await workspace.fs.stat(dotdevbox);
} catch (error) {
//.devbox doesn't exist
// running devbox shellenv to create it
spawnSync('devbox', ['shellenv'], {
cwd: workingDir.path
});
}
try {
// check if .devbox exists
await workspace.fs.stat(dotdevbox);
} catch (error) {
//.devbox doesn't exist
// running devbox shellenv to create it
spawnSync('devbox', ['shellenv'], {
cwd: workingDir.path
});
}
}

function updateVSCodeConf() {
if (process.platform === 'darwin') {
const shell = process.env["SHELL"] ?? "/bin/zsh";
const shellArgsMap = (shellType: string) => {
switch (shellType) {
case "fish":
// We special case fish here because fish's `fish_add_path` function
// tends to prepend to PATH by default, hence sourcing the fish config after
// vscode reopens in devbox environment, overwrites devbox packages and
// might cause confusion for users as to why their system installed packages
// show up when they type for example `which go` as opposed to the packages
// installed by devbox.
return ["--no-config"];
default:
return [];
}
};
const shellTypeSlices = shell.split("/");
const shellType = shellTypeSlices[shellTypeSlices.length - 1];
shellArgsMap(shellType);
const devboxCompatibleShell = {
"devboxCompatibleShell": {
"path": shell,
"args": shellArgsMap(shellType)
}
};
if (process.platform === 'darwin') {
const shell = process.env["SHELL"] ?? "/bin/zsh";
const shellArgsMap = (shellType: string) => {
switch (shellType) {
case "fish":
// We special case fish here because fish's `fish_add_path` function
// tends to prepend to PATH by default, hence sourcing the fish config after
// vscode reopens in devbox environment, overwrites devbox packages and
// might cause confusion for users as to why their system installed packages
// show up when they type for example `which go` as opposed to the packages
// installed by devbox.
return ["--no-config"];
default:
return [];
}
};
const shellTypeSlices = shell.split("/");
const shellType = shellTypeSlices[shellTypeSlices.length - 1];
shellArgsMap(shellType);
const devboxCompatibleShell = {
"devboxCompatibleShell": {
"path": shell,
"args": shellArgsMap(shellType)
}
};

workspace.getConfiguration().update(
'terminal.integrated.profiles.osx',
devboxCompatibleShell,
ConfigurationTarget.Workspace
);
workspace.getConfiguration().update(
'terminal.integrated.defaultProfile.osx',
'devboxCompatibleShell',
ConfigurationTarget.Workspace);
}
workspace.getConfiguration().update(
'terminal.integrated.profiles.osx',
devboxCompatibleShell,
ConfigurationTarget.Workspace
);
workspace.getConfiguration().update(
'terminal.integrated.defaultProfile.osx',
'devboxCompatibleShell',
ConfigurationTarget.Workspace
);
}
}
3 changes: 0 additions & 3 deletions vscode-extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ async function initialCheckDevboxJSON(context: ExtensionContext) {
// devbox.json exists setcontext for devbox commands to be available
commands.executeCommand('setContext', 'devbox.configFileExists', true);
context.workspaceState.update("configFileExists", true);

} catch (err) {
console.log(err);
// devbox.json does not exist
Expand All @@ -153,7 +152,6 @@ async function runInTerminal(cmd: string, showTerminal: boolean) {
'text': `${cmd}\r\n`
});
}

}

async function getDevboxScripts(): Promise<string[]> {
Expand Down Expand Up @@ -192,7 +190,6 @@ async function readDevboxJson(workspaceUri: Uri) {
const readStr = Buffer.from(readData).toString('utf8');
const devboxJsonData = JSON.parse(readStr);
return devboxJsonData;

}

// This method is called when your extension is deactivated
Expand Down
Loading