Skip to content
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

(#733) use existing properties inside omnisharp.json #734

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@
"watch": "npm run ensureCi && tsc -watch -p ./",
"test": "npm run compile && node ./out/test/runTest.js",
"depcheck": "depcheck",
"ensureCi": "node -e \"const fs=require('fs'); if (fs.existsSync('./node_modules/')) { process.exit(123); }\" && npm ci"
"ensureCi": "(node -e \"const fs=require('fs'); if (fs.existsSync('./node_modules/')) { process.exit(123); }\" && npm ci) & echo 'ensured.'"
},
"dependencies": {
"adm-zip": "^0.5.9",
Expand Down
48 changes: 37 additions & 11 deletions src/bakery/cakeBakery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,36 @@ export class CakeBakery {

const targetPath = this.getTargetPath();
const omnisharpCakeConfigFile = this.getOmnisharpCakeConfigFile();
let omnisharpCakeConfig = {};
if (fs.existsSync(omnisharpCakeConfigFile)) {
// Read in file
//import omnisharpCakeConfig from omnisharpCakeConfigFile;
var omnisharpCakeConfig = JSON.parse(fs.readFileSync(omnisharpCakeConfigFile, 'utf-8'))
logger.logInfo(`existing bakery-path: ${omnisharpCakeConfig.cake.bakeryPath}`);
omnisharpCakeConfig.cake.bakeryPath = targetPath;
logger.logInfo(`new bakery-path: ${omnisharpCakeConfig.cake.bakeryPath}`);
fs.writeFileSync(omnisharpCakeConfigFile, JSON.stringify(omnisharpCakeConfig, null, 2));

// lets force a restart of the Omnisharp server to use new config
vscode.commands.executeCommand('o.restart');
omnisharpCakeConfig = JSON.parse(fs.readFileSync(omnisharpCakeConfigFile, 'utf-8'))
} else {
// create file
var newOmnisharpCakeConfig = { cake: { bakeryPath: targetPath }};
fs.writeFileSync(omnisharpCakeConfigFile, JSON.stringify(newOmnisharpCakeConfig));
logger.logInfo(`${omnisharpCakeConfigFile} will be created.`);
}

let cakePropName = this.getPropertyNameCaseInsensitive(omnisharpCakeConfig, "cake");
if(!cakePropName) {
cakePropName = "cake"
omnisharpCakeConfig[cakePropName] = {};
}

let bakeryPathPropName = this.getPropertyNameCaseInsensitive(omnisharpCakeConfig[cakePropName], "bakeryPath");
if(!bakeryPathPropName) {
bakeryPathPropName = "bakeryPath"
omnisharpCakeConfig[cakePropName][bakeryPathPropName] = "";
}

logger.logInfo(`existing bakery-path: ${omnisharpCakeConfig[cakePropName][bakeryPathPropName]}`);
omnisharpCakeConfig[cakePropName][bakeryPathPropName] = targetPath;
logger.logInfo(`new bakery-path: ${omnisharpCakeConfig[cakePropName][bakeryPathPropName]}`);


fs.writeFileSync(omnisharpCakeConfigFile, JSON.stringify(omnisharpCakeConfig, null, 2));

// lets force a restart of the Omnisharp server to use new config
vscode.commands.executeCommand('o.restart');
logger.logInfo("Omnisharp setting successfully updated.")
resolve();
} catch (e) {
Expand All @@ -124,4 +138,16 @@ export class CakeBakery {
private getOmnisharpCakeConfigFile() : string {
return path.join(this.getOmnisharpUserFolderPath(), "omnisharp.json");
}

private getPropertyNameCaseInsensitive(obj: any, propName: string) : string|null {
for (const key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
if(propName.toLowerCase() == key.toLowerCase()) {
return key;
}
}
}

return null;
}
}
24 changes: 14 additions & 10 deletions src/bakery/cakeBakeryCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ import { logger } from '../shared'

export async function updateCakeBakeryCommand(extensionPath: string) {
// Install Cake Bakery
var result = await forceInstallBakery(extensionPath);
if (result) {
commands.executeCommand('o.restart');
window.showInformationMessage(
'Intellisense support (Cake.Bakery) for Cake files was installed.'
);
} else {
window.showErrorMessage(
'Error downloading intellisense support (Cake.Bakery) for Cake files.'
);
try {
var result = await forceInstallBakery(extensionPath);
if (result) {
commands.executeCommand('o.restart');
window.showInformationMessage(
'Intellisense support (Cake.Bakery) for Cake files was installed.'
);
} else {
window.showErrorMessage(
'Error downloading intellisense support (Cake.Bakery) for Cake files.'
);
}
} catch (e: unknown) {
logger.logError("Intellisense support (Cake.Bakery) for Cake files NOT installed!\r\n> "+e, false)
}
}

Expand Down