Skip to content

Commit

Permalink
Merge pull request #27 from isfopo:issue/Show-no-env-message-if-no-en…
Browse files Browse the repository at this point in the history
…v-file-were-found

Issue/Show-no-env-message-if-no-env-file-were-found
  • Loading branch information
isfopo authored Jul 14, 2024
2 parents da653ae + 6249a7c commit 42d7552
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 29 deletions.
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,12 @@
},
"viewsWelcome": [
{
"view": "environments-sidebar-view",
"contents": "No .env files found."
"view": "environments-sidebar",
"contents": "No environment files found. \n[Create file](command:environments.create)"
},
{
"view": "environments-explorer",
"contents": "No environment files found. \n[Create file](command:environments.create)"
}
],
"viewsContainers": {
Expand Down Expand Up @@ -143,4 +147,4 @@
"webpack": "^5.92.1",
"webpack-cli": "^5.1.4"
}
}
}
59 changes: 33 additions & 26 deletions src/EnvironmentTreeviewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,44 @@ export class EnvironmentTreeviewProvider
{
context: vscode.ExtensionContext;

private _onDidChangeTreeData: vscode.EventEmitter<
vscode.TreeItem | undefined | void
> = new vscode.EventEmitter<vscode.TreeItem | undefined | void>();

readonly onDidChangeTreeData: vscode.Event<
vscode.TreeItem | undefined | void
> = this._onDidChangeTreeData.event;

constructor(context: vscode.ExtensionContext) {
this.context = context;
}

register() {
vscode.window.createTreeView("environments-sidebar", {
treeDataProvider: this,
});

const tree = vscode.window.createTreeView("environments-explorer", {
treeDataProvider: this,
});

tree.onDidChangeSelection(async (e) => {
const selected = e.selection[0];
if (selected instanceof EnvironmentKeyValueTreeItem) {
await vscode.window.showTextDocument(
await vscode.workspace.openTextDocument(selected.parent.uri)
);
}
});
const trees = [
vscode.window.createTreeView("environments-sidebar", {
treeDataProvider: this,
}),
vscode.window.createTreeView("environments-explorer", {
treeDataProvider: this,
}),
];

for (const tree of trees) {
tree.onDidChangeSelection(async (e): Promise<void> => {
const selected = e.selection[0];
if (selected instanceof EnvironmentKeyValueTreeItem) {
await vscode.window.showTextDocument(
await vscode.workspace.openTextDocument(selected.parent.uri)
);
}
});
}

return this;
}

create(workspace: string, fileName: string) {
vscode.workspace.fs.writeFile(
async create(workspace: string, fileName: string) {
await vscode.workspace.fs.writeFile(
vscode.Uri.joinPath(
vscode.Uri.from({
path: workspace,
Expand All @@ -53,21 +64,17 @@ export class EnvironmentTreeviewProvider

content += `${key}="${value}"\n`;

vscode.workspace.fs.writeFile(
await vscode.workspace.fs.writeFile(
element.uri,
new TextEncoder().encode(content)
);

this.refresh();
}

flip(element: EnvironmentKeyValueTreeItem) {
this.edit(element, element.value.value === "true" ? "false" : "true");
}
private _onDidChangeTreeData: vscode.EventEmitter<
vscode.TreeItem | undefined | void
> = new vscode.EventEmitter<vscode.TreeItem | undefined | void>();
readonly onDidChangeTreeData: vscode.Event<
vscode.TreeItem | undefined | void
> = this._onDidChangeTreeData.event;

refresh() {
this._onDidChangeTreeData?.fire();
Expand All @@ -78,7 +85,7 @@ export class EnvironmentTreeviewProvider
await vscode.workspace.fs.readFile(element.parent.uri)
);

vscode.workspace.fs.writeFile(
await vscode.workspace.fs.writeFile(
element.parent.uri,
new TextEncoder().encode(replace(content, element.key, input))
);
Expand Down

0 comments on commit 42d7552

Please sign in to comment.