irongit

A simpler way to view django projects

have the app stuff ready for tree

huncholanehuncholaneauthored
parent 5eed920commit 94d06f7a17802c4c6eddb31d840ad03093be85b9Browse files

5 files changed, +25 -156

+0-68resources/models.svg
@@ -1,68 +0,0 @@
1-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
3-
4-<svg
5- width="24"
6- height="24"
7- viewBox="0 0 0.72 0.72"
8- fill="none"
9- version="1.1"
10- id="svg12"
11- sodipodi:docname="models.svg"
12- inkscape:version="1.1.2 (0a00cf5339, 2022-02-04)"
13- xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
14- xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
15- xmlns="http://www.w3.org/2000/svg"
16- xmlns:svg="http://www.w3.org/2000/svg">
17- <defs
18- id="defs16" />
19- <sodipodi:namedview
20- id="namedview14"
21- pagecolor="#ffffff"
22- bordercolor="#666666"
23- borderopacity="1.0"
24- inkscape:pageshadow="2"
25- inkscape:pageopacity="0.0"
26- inkscape:pagecheckerboard="0"
27- showgrid="false"
28- inkscape:zoom="1.0125"
29- inkscape:cx="400"
30- inkscape:cy="320.98765"
31- inkscape:window-width="1920"
32- inkscape:window-height="988"
33- inkscape:window-x="0"
34- inkscape:window-y="24"
35- inkscape:window-maximized="1"
36- inkscape:current-layer="svg12" />
37- <g
38- id="g31"
39- transform="matrix(0.03348837,0,0,0.03348837,-0.04186044,-0.04186044)">
40- <path
41- d="M 4,18 V 6"
42- stroke="#1c274c"
43- stroke-width="1.5"
44- stroke-linecap="round"
45- id="path2" />
46- <path
47- d="M 20,6 V 18"
48- stroke="#1c274c"
49- stroke-width="1.5"
50- stroke-linecap="round"
51- id="path4" />
52- <path
53- d="M 12,10 C 16.4183,10 20,8.20914 20,6 20,3.79086 16.4183,2 12,2 7.58172,2 4,3.79086 4,6 c 0,2.20914 3.58172,4 8,4 z"
54- stroke="#1c274c"
55- stroke-width="1.5"
56- id="path6" />
57- <path
58- d="m 20,12 c 0,2.2091 -3.5817,4 -8,4 -4.41828,0 -8,-1.7909 -8,-4"
59- stroke="#1c274c"
60- stroke-width="1.5"
61- id="path8" />
62- <path
63- d="m 20,18 c 0,2.2091 -3.5817,4 -8,4 -4.41828,0 -8,-1.7909 -8,-4"
64- stroke="#1c274c"
65- stroke-width="1.5"
66- id="path10" />
67- </g>
68-</svg>
+0-46resources/settings.svg
@@ -1,46 +0,0 @@
1-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
3-
4-<svg
5- fill="#000000"
6- height="24"
7- width="24"
8- version="1.1"
9- id="Capa_1"
10- viewBox="0 0 1.62 1.62"
11- xml:space="preserve"
12- sodipodi:docname="settings.svg"
13- inkscape:version="1.1.2 (0a00cf5339, 2022-02-04)"
14- xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
15- xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
16- xmlns="http://www.w3.org/2000/svg"
17- xmlns:svg="http://www.w3.org/2000/svg"><defs
18- id="defs11" /><sodipodi:namedview
19- id="namedview9"
20- pagecolor="#ffffff"
21- bordercolor="#666666"
22- borderopacity="1.0"
23- inkscape:pageshadow="2"
24- inkscape:pageopacity="0.0"
25- inkscape:pagecheckerboard="0"
26- showgrid="false"
27- inkscape:zoom="32.416667"
28- inkscape:cx="12"
29- inkscape:cy="12"
30- inkscape:window-width="1920"
31- inkscape:window-height="988"
32- inkscape:window-x="0"
33- inkscape:window-y="24"
34- inkscape:window-maximized="1"
35- inkscape:current-layer="Capa_1" />
36-<g
37- id="g6"
38- transform="scale(0.03)">
39- <path
40- d="m 51.22,21 h -5.052 c -0.812,0 -1.481,-0.447 -1.792,-1.197 -0.311,-0.75 -0.153,-1.54 0.42,-2.114 l 3.572,-3.571 c 0.525,-0.525 0.814,-1.224 0.814,-1.966 0,-0.743 -0.289,-1.441 -0.814,-1.967 L 43.815,5.632 c -1.05,-1.05 -2.881,-1.052 -3.933,0 L 36.311,9.203 C 35.737,9.776 34.945,9.936 34.197,9.624 33.447,9.313 33,8.644 33,7.832 V 2.78 C 33,1.247 31.753,0 30.22,0 H 23.78 C 22.247,0 21,1.247 21,2.78 v 5.052 c 0,0.812 -0.447,1.481 -1.197,1.792 -0.748,0.313 -1.54,0.152 -2.114,-0.421 L 14.118,5.632 c -1.052,-1.052 -2.883,-1.05 -3.933,0 l -4.553,4.553 c -0.525,0.525 -0.814,1.224 -0.814,1.967 0,0.742 0.289,1.44 0.814,1.966 l 3.572,3.571 c 0.573,0.574 0.73,1.364 0.42,2.114 C 9.314,20.553 8.644,21 7.832,21 H 2.78 C 1.247,21 0,22.247 0,23.78 v 6.439 C 0,31.753 1.247,33 2.78,33 h 5.052 c 0.812,0 1.481,0.447 1.792,1.197 0.311,0.75 0.153,1.54 -0.42,2.114 l -3.572,3.571 c -0.525,0.525 -0.814,1.224 -0.814,1.966 0,0.743 0.289,1.441 0.814,1.967 l 4.553,4.553 c 1.051,1.051 2.881,1.053 3.933,0 l 3.571,-3.572 c 0.574,-0.573 1.363,-0.731 2.114,-0.42 0.75,0.311 1.197,0.98 1.197,1.792 v 5.052 c 0,1.533 1.247,2.78 2.78,2.78 h 6.439 c 1.533,0 2.78,-1.247 2.78,-2.78 v -5.052 c 0,-0.812 0.447,-1.481 1.197,-1.792 0.751,-0.312 1.54,-0.153 2.114,0.42 l 3.571,3.572 c 1.052,1.052 2.883,1.05 3.933,0 l 4.553,-4.553 c 0.525,-0.525 0.814,-1.224 0.814,-1.967 0,-0.742 -0.289,-1.44 -0.814,-1.966 L 44.795,36.311 C 44.222,35.737 44.065,34.947 44.375,34.197 44.685,33.447 45.356,33 46.168,33 H 51.22 C 52.753,33 54,31.753 54,30.22 V 23.78 C 54,22.247 52.753,21 51.22,21 Z M 52,30.22 C 52,30.65 51.65,31 51.22,31 h -5.052 c -1.624,0 -3.019,0.932 -3.64,2.432 -0.622,1.5 -0.295,3.146 0.854,4.294 l 3.572,3.571 c 0.305,0.305 0.305,0.8 0,1.104 l -4.553,4.553 c -0.304,0.304 -0.799,0.306 -1.104,0 L 37.726,43.382 C 36.577,42.233 34.932,41.908 33.432,42.528 31.932,43.149 31,44.544 31,46.168 V 51.22 C 31,51.65 30.65,52 30.22,52 H 23.78 C 23.35,52 23,51.65 23,51.22 v -5.052 c 0,-1.624 -0.932,-3.019 -2.432,-3.64 -0.503,-0.209 -1.021,-0.311 -1.533,-0.311 -1.014,0 -1.997,0.4 -2.761,1.164 l -3.571,3.572 c -0.306,0.306 -0.801,0.304 -1.104,0 L 7.046,42.4 c -0.305,-0.305 -0.305,-0.8 0,-1.104 l 3.572,-3.571 c 1.148,-1.148 1.476,-2.794 0.854,-4.294 C 10.851,31.932 9.456,31 7.832,31 H 2.78 C 2.35,31 2,30.65 2,30.22 V 23.78 C 2,23.35 2.35,23 2.78,23 h 5.052 c 1.624,0 3.019,-0.932 3.64,-2.432 0.622,-1.5 0.295,-3.146 -0.854,-4.294 L 7.046,12.703 c -0.305,-0.305 -0.305,-0.8 0,-1.104 l 4.553,-4.553 c 0.304,-0.305 0.799,-0.305 1.104,0 l 3.571,3.571 c 1.147,1.147 2.792,1.476 4.294,0.854 C 22.068,10.851 23,9.456 23,7.832 V 2.78 C 23,2.35 23.35,2 23.78,2 h 6.439 C 30.65,2 31,2.35 31,2.78 v 5.052 c 0,1.624 0.932,3.019 2.432,3.64 1.502,0.622 3.146,0.294 4.294,-0.854 l 3.571,-3.571 c 0.306,-0.305 0.801,-0.305 1.104,0 l 4.553,4.553 c 0.305,0.305 0.305,0.8 0,1.104 l -3.572,3.571 c -1.148,1.148 -1.476,2.794 -0.854,4.294 0.621,1.5 2.016,2.432 3.64,2.432 H 51.22 C 51.65,23 52,23.35 52,23.78 Z"
41- id="path2" />
42- <path
43- d="m 27,18 c -4.963,0 -9,4.037 -9,9 0,4.963 4.037,9 9,9 4.963,0 9,-4.037 9,-9 0,-4.963 -4.037,-9 -9,-9 z m 0,16 c -3.859,0 -7,-3.141 -7,-7 0,-3.859 3.141,-7 7,-7 3.859,0 7,3.141 7,7 0,3.859 -3.141,7 -7,7 z"
44- id="path4" />
45-</g>
46-</svg>
+15-5src/context.ts
@@ -1,15 +1,16 @@
11 import * as vscode from "vscode";
22 import * as path from "path";
33 import * as fs from "fs";
4+import DjangoProject from "./project";
45
56 export const setDjangoContext = async () => {
67 const workspaceFolders = vscode.workspace.workspaceFolders;
7- if (vscode.workspace.getConfiguration("django-overview").get("projectDir")) {
8- return;
9- }
10- if (workspaceFolders) {
8+ let dir = vscode.workspace
9+ .getConfiguration("django-overview")
10+ .get("projectDir") as string;
11+ if (workspaceFolders && !dir) {
1112 for (const folder of workspaceFolders) {
12- const dir = folder.uri.fsPath;
13+ dir = folder.uri.fsPath;
1314 const isDjango = await isDjangoProject(dir);
1415 const inDjango = isDjango || (await isInDjangoProject(path.dirname(dir)));
1516 if (isDjango || inDjango) {
@@ -27,6 +28,15 @@ export const setDjangoContext = async () => {
2728 null
2829 );
2930 }
31+ if (dir) {
32+ const project = new DjangoProject(dir);
33+ await project.read();
34+ vscode.commands.executeCommand(
35+ "setContext",
36+ "django-overview.project",
37+ project
38+ );
39+ }
3040 };
3141
3242 const isDjangoProject = async (dir: string): Promise<boolean> => {
+6-13src/project.ts
@@ -12,6 +12,7 @@ type Field = {
1212 name: string;
1313 type: string;
1414 index: number;
15+ raw: string;
1516 };
1617
1718 type Model = {
@@ -48,14 +49,12 @@ if spec is not None and spec.origin is not None:
4849 `;
4950 try {
5051 const result = childProcess
51- .execSync(`${pythonPath} -c "${pythonScript}"`)
52+ .execSync(`${pythonPath} -c "${pythonScript}" 2>/dev/null`)
5253 .toString();
5354 this.path = result.trim();
5455 } catch (error) {
55- console.error(error);
5656 throw new Error(`Error getting path for app ${this.name}`);
5757 }
58- console.log(`Reading models.py for app ${this.name}`);
5958 try {
6059 const data = fs.readFileSync(`${this.path}/models.py`, "utf-8");
6160 const models = data.matchAll(regex.model);
@@ -71,14 +70,13 @@ if spec is not None and spec.origin is not None:
7170 name: fieldMatch[1],
7271 type: fieldMatch[2],
7372 index: fieldMatch.index || 0,
73+ raw: fieldMatch[0],
7474 };
7575 model.fields.push(field);
7676 }
7777 this.models.push(model);
7878 }
79- console.log(models);
8079 } catch (err) {
81- console.error(`Error reading models.py for app ${this.name}`);
8280 // throw new Error(`Error reading models.py for app ${this.name}`);
8381 }
8482 }
@@ -119,14 +117,9 @@ export default class DjangoProject {
119117 const appContainer = appContainerMatch ? appContainerMatch[1] : "";
120118 const apps = appContainer.matchAll(regex.module);
121119 for (const app of apps ? apps : []) {
122- this.apps.push(new App(app[1]));
120+ try {
121+ this.apps.push(new App(app[1]));
122+ } catch {}
123123 }
124- console.log(apps);
125124 }
126125 }
127-
128-export const getProject = async () => {};
129-
130-export const getAvailableApps = async () => {
131- const projectDir = getDjangoProjectDir();
132-};
+4-24src/providers/project.ts
@@ -10,39 +10,19 @@ export default class ProjectDataProvider
1010 getChildren(element?: vscode.TreeItem): Thenable<vscode.TreeItem[]> {
1111 if (element === undefined) {
1212 // Return the root items
13- return Promise.resolve([
14- new vscode.TreeItem(
15- "Item 1",
16- vscode.TreeItemCollapsibleState.Collapsed
17- ),
18- new vscode.TreeItem(
19- "Item 2",
20- vscode.TreeItemCollapsibleState.Collapsed
21- ),
22- new vscode.TreeItem(
23- "Item 3",
24- vscode.TreeItemCollapsibleState.Collapsed
25- ),
26- ]);
13+ return Promise.resolve([this.createModelsTreeItem()]);
2714 } else {
2815 // Return the child items for the given parent item
2916 return Promise.resolve([
30- this.createSettingsTreeItem(),
3117 new vscode.TreeItem("Subitem 2"),
3218 new vscode.TreeItem("Subitem 3"),
3319 ]);
3420 }
3521 }
3622
37- private createSettingsTreeItem(): vscode.TreeItem {
38- const treeItem = new vscode.TreeItem("Settings");
39- treeItem.checkboxState = {
40- state: vscode.TreeItemCheckboxState.Checked,
41- };
42- treeItem.command = {
43- command: "django-overview.openSettings",
44- title: "Open Settings",
45- };
23+ private createModelsTreeItem(): vscode.TreeItem {
24+ const treeItem = new vscode.TreeItem("Models");
25+ treeItem.collapsibleState = vscode.TreeItemCollapsibleState.Collapsed;
4626 return treeItem;
4727 }
4828 }