Skip to content

Commit

Permalink
(#515) Automatically enable Omnisharp usage
Browse files Browse the repository at this point in the history
Once downloaded, the Cake.Bakery.exe can be added to the Omnisharp
configuration file, so that Omnisharp knows where to find the binary,
and then once the file is updated, force a restart of the Omnisharp
Server so that everything just "works".

Here we are relying on the fact that any VSCode extension can call a
registered command from another extension, as long as the name is
known.  In this case, the `o.restart` command, which the Omnisharp
Extension registers.
  • Loading branch information
gep13 committed Dec 6, 2021
1 parent 9bb431d commit d296d11
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/cakeMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,21 @@ async function _registerCakeBakery(context: vscode.ExtensionContext) {
fs.mkdirSync(getOmnisharpUserFolderPath());
}

if (fs.existsSync(getOmnisharpCakeConfigFile())) {
// Read in file
//import omnisharpCakeConfig from getOmnisharpCakeConfigFile();
var omnisharpCakeConfig = JSON.parse(fs.readFileSync(getOmnisharpCakeConfigFile(), 'utf-8'))
console.log(omnisharpCakeConfig.cake.bakeryPath);
omnisharpCakeConfig.cake.bakeryPath = targetPath;
fs.writeFileSync(getOmnisharpCakeConfigFile(), JSON.stringify(omnisharpCakeConfig));

// lets force a restart of the Omnisharp server to use new config
vscode.commands.executeCommand('o.restart');
} else {
// create file
var newOmnisharpCakeConfig = { cake: { bakeryPath: targetPath }};
fs.writeFileSync(getOmnisharpCakeConfigFile(), JSON.stringify(newOmnisharpCakeConfig));
}
} else {
logger.logToOutput("Cake.Bakery has already been installed, skipping automated download and extraction.");
}
Expand Down Expand Up @@ -219,8 +234,8 @@ async function _getCakeScriptsAsTasks(context: vscode.ExtensionContext): Promise
`Run ${taskNamePrefix}${taskName}`,
'Cake',
new vscode.CustomExecution(getCakeToolExecution({
command: buildCommandBase,
script: file.fsPath,
command: buildCommandBase,
script: file.fsPath,
taskName,
verbosity: config.verbosity
}, config, context)),
Expand Down Expand Up @@ -315,7 +330,7 @@ export function deactivate() {
function getCakeToolExecution(
cfg: ICakeTaskRunnerConfig,
settings: ITaskRunnerSettings,
context: vscode.ExtensionContext)
context: vscode.ExtensionContext)
: (resolvedDefinition: vscode.TaskDefinition) => Thenable<vscode.Pseudoterminal> {

return (_: vscode.TaskDefinition) => {
Expand All @@ -330,8 +345,8 @@ class CakeTaskWrapper implements vscode.Pseudoterminal {
private readonly closeEmitter = new vscode.EventEmitter<number>();
public onDidClose: vscode.Event<number> = this.closeEmitter.event;
private isCanceled = false;
constructor(private cfg: ICakeTaskRunnerConfig,

constructor(private cfg: ICakeTaskRunnerConfig,
private settings: ITaskRunnerSettings,
private context: vscode.ExtensionContext) {
}
Expand Down Expand Up @@ -361,7 +376,7 @@ class CakeTaskWrapper implements vscode.Pseudoterminal {
});
this.writeEmitter.fire(`started command: ${proc.spawnargs.join(" ")}${os.EOL}`);
let exit = 0;

proc.on('error', (error) => {
this.setColorRed();
this.writeEmitter.fire(`ERROR: ${error.name}${os.EOL}${error.message}${os.EOL}`);
Expand All @@ -376,7 +391,7 @@ class CakeTaskWrapper implements vscode.Pseudoterminal {
const txt = data.toString();
this.writeEmitter.fire(txt);
});
proc.stderr.on('data', (data: Buffer) => {
proc.stderr.on('data', (data: Buffer) => {
const txt = data.toString();
this.setColorRed();
this.writeEmitter.fire(txt);
Expand All @@ -399,7 +414,7 @@ class CakeTaskWrapper implements vscode.Pseudoterminal {
}

interface ICakeTaskRunnerConfig{
command: string;
command: string;
script: string;
taskName: string;
verbosity: string;
Expand Down

0 comments on commit d296d11

Please sign in to comment.