Skip to content

Commit

Permalink
feat: default config (#6)
Browse files Browse the repository at this point in the history
- add configuration for default configs
- expand all kubernetes object tree view by default
- sort the YAML result by default
  • Loading branch information
sunggun-yu authored Dec 26, 2023
1 parent 7336443 commit 0c545ee
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@
"activationEvents": [],
"main": "./out/extension.js",
"contributes": {
"configuration": [
{
"id": "kubemani-diff-configuration",
"title": "KubeMani Diff",
"properties": {
"kubemaniTreeView.expandAll": {
"type": "boolean",
"default": true,
"description": "Expand all the Kubernetes Objects in a tree view by default",
"scope": "resource"
},
"editor.sortYaml": {
"type": "boolean",
"default": true,
"description": "Sort the Kubernetes Object YAML in the Editor",
"scope": "resource"
}
}
}
],
"viewsContainers": {
"activitybar": [
{
Expand Down
10 changes: 7 additions & 3 deletions src/kubeItemView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ export class KubeItem extends vscode.TreeItem implements IKubeItem {
public uriB?: vscode.Uri | undefined
) {

// TODO: create config to set Collapsed or Expanded by default;
var collapsibleState = vscode.TreeItemCollapsibleState.Collapsed;
let collapsibleState = vscode.TreeItemCollapsibleState.Collapsed;
const sortYaml = vscode.workspace.getConfiguration().get('kubemaniTreeView.expandAll');
if (sortYaml) {
collapsibleState = vscode.TreeItemCollapsibleState.Expanded;
}
if (type === KubeItemType.Item) {
collapsibleState = vscode.TreeItemCollapsibleState.None;
}
Expand Down Expand Up @@ -314,7 +317,8 @@ function createTempFileFromKubernetesObject(content: KubernetesObject, dir: vsco

const filePath = path.join(dir.fsPath, `${appears}.yaml`);
try {
fs.writeFileSync(filePath, yaml.dump(content));
const sortYaml = vscode.workspace.getConfiguration().get('editor.sortYaml');
fs.writeFileSync(filePath, yaml.dump(content, {sortKeys: sortYaml ? true : false}));
const fileUri = vscode.Uri.file(filePath);
return fileUri;
} catch (err) {
Expand Down

0 comments on commit 0c545ee

Please sign in to comment.