bmd-extension 1.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/launch.json +14 -0
- package/.vscode/settings.json +1 -0
- package/CHANGELOG.md +9 -0
- package/DEPLOY.md +4 -0
- package/README.md +17 -0
- package/README_PRIVATE.md +1 -0
- package/build.sh +5 -0
- package/logo.png +0 -0
- package/media/dark/add.svg +40 -0
- package/media/dark/block.svg +1 -0
- package/media/dark/checklist-1.svg +1 -0
- package/media/dark/checklist.svg +1 -0
- package/media/dark/control.svg +1 -0
- package/media/dark/create.svg +1 -0
- package/media/dark/delete-1.svg +1 -0
- package/media/dark/delete.svg +1 -0
- package/media/dark/deploy-1.svg +2 -0
- package/media/dark/deploy.svg +2 -0
- package/media/dark/documents.svg +66 -0
- package/media/dark/earth.svg +68 -0
- package/media/dark/exe.svg +15 -0
- package/media/dark/export.svg +1 -0
- package/media/dark/function.svg +1 -0
- package/media/dark/game-controller.svg +77 -0
- package/media/dark/get.svg +1 -0
- package/media/dark/id-card.svg +59 -0
- package/media/dark/identity.svg +81 -0
- package/media/dark/import.svg +1 -0
- package/media/dark/information.svg +1 -0
- package/media/dark/interface.svg +1 -0
- package/media/dark/layout.svg +41 -0
- package/media/dark/leaf.svg +54 -0
- package/media/dark/list.svg +13 -0
- package/media/dark/logo.svg +249 -0
- package/media/dark/mockup.svg +1 -0
- package/media/dark/needle.svg +1 -0
- package/media/dark/pass.svg +46 -0
- package/media/dark/plus.svg +1 -0
- package/media/dark/post.svg +1 -0
- package/media/dark/quit.svg +1 -0
- package/media/dark/rocket.svg +28 -0
- package/media/dark/service.svg +1 -0
- package/media/dark/settings.svg +98 -0
- package/media/dark/social.svg +1 -0
- package/media/dark/spaceship-1.svg +1 -0
- package/media/dark/spaceship-2.svg +1 -0
- package/media/dark/spaceship.svg +1 -0
- package/media/dark/support.svg +88 -0
- package/media/dark/transfer.svg +1 -0
- package/media/dark/transform.svg +92 -0
- package/media/dark/update.svg +45 -0
- package/media/dark/upload-1.svg +1 -0
- package/media/dark/upload.svg +41 -0
- package/media/dark/vaccine.svg +1 -0
- package/media/dark/vr-gaming.svg +1 -0
- package/media/light/add.svg +40 -0
- package/media/light/block.svg +1 -0
- package/media/light/checklist-1.svg +1 -0
- package/media/light/checklist.svg +1 -0
- package/media/light/control.svg +1 -0
- package/media/light/create.svg +1 -0
- package/media/light/delete-1.svg +1 -0
- package/media/light/delete.svg +1 -0
- package/media/light/deploy-1.svg +2 -0
- package/media/light/deploy.svg +2 -0
- package/media/light/documents.svg +66 -0
- package/media/light/earth.svg +68 -0
- package/media/light/exe.svg +15 -0
- package/media/light/export.svg +1 -0
- package/media/light/function.svg +1 -0
- package/media/light/game-controller.svg +77 -0
- package/media/light/get.svg +1 -0
- package/media/light/id-card.svg +59 -0
- package/media/light/identity.svg +81 -0
- package/media/light/import.svg +1 -0
- package/media/light/information.svg +1 -0
- package/media/light/interface.svg +1 -0
- package/media/light/layout.svg +41 -0
- package/media/light/leaf.svg +54 -0
- package/media/light/list.svg +13 -0
- package/media/light/logo.svg +249 -0
- package/media/light/mockup.svg +1 -0
- package/media/light/needle.svg +1 -0
- package/media/light/pass.svg +46 -0
- package/media/light/plus.svg +1 -0
- package/media/light/post.svg +1 -0
- package/media/light/quit.svg +1 -0
- package/media/light/rocket.svg +28 -0
- package/media/light/service.svg +1 -0
- package/media/light/settings.svg +98 -0
- package/media/light/social.svg +1 -0
- package/media/light/spaceship-1.svg +1 -0
- package/media/light/spaceship-2.svg +1 -0
- package/media/light/spaceship.svg +1 -0
- package/media/light/support.svg +88 -0
- package/media/light/transfer.svg +1 -0
- package/media/light/transform.svg +92 -0
- package/media/light/update.svg +45 -0
- package/media/light/upload-1.svg +1 -0
- package/media/light/upload.svg +41 -0
- package/media/light/vaccine.svg +1 -0
- package/media/light/vr-gaming.svg +1 -0
- package/package-lock.json +6430 -0
- package/package.json +540 -0
- package/snippets-tsr.json +512 -0
- package/snippets.json +761 -0
- package/src/API.ts +14 -0
- package/src/FsProvider.ts +105 -0
- package/src/Request.ts +24 -0
- package/src/assets/api/api.txt +27 -0
- package/src/assets/configuration/AdminConfigurationController.ts.txt +72 -0
- package/src/assets/configuration/Configuration.ts.txt +37 -0
- package/src/assets/configuration/ConfigurationService.ts.txt +26 -0
- package/src/assets/contentDefine/AdminContentDefineController.ts.txt +91 -0
- package/src/assets/contentDefine/ContentDefine.ts.txt +45 -0
- package/src/assets/contentDefine/ContentDefineService.ts.txt +19 -0
- package/src/assets/contentDefine/CustomerContentDefineController.ts.txt +34 -0
- package/src/assets/controller/controller.txt +46 -0
- package/src/assets/controller/controllerResource.txt +103 -0
- package/src/assets/entity/entity.txt +22 -0
- package/src/assets/entity-request/entity-request.txt +18 -0
- package/src/assets/init/.env.example.txt +37 -0
- package/src/assets/init/.env.production.txt +37 -0
- package/src/assets/init/.gitignore.txt +8 -0
- package/src/assets/init/config.ts.txt +55 -0
- package/src/assets/init/deploy.sh.txt +46 -0
- package/src/assets/init/package-lock.json.txt +4184 -0
- package/src/assets/init/package.json.txt +79 -0
- package/src/assets/init/src/Server.ts.txt +167 -0
- package/src/assets/init/src/controllers/admin/AuthController.ts.txt +96 -0
- package/src/assets/init/src/controllers/admin/CustomerController.ts.txt +107 -0
- package/src/assets/init/src/controllers/admin/RoleController.ts.txt +143 -0
- package/src/assets/init/src/controllers/admin/StaffController.ts.txt +192 -0
- package/src/assets/init/src/controllers/customer/AuthController.ts.txt +170 -0
- package/src/assets/init/src/controllers/customer/CustomerController.ts.txt +32 -0
- package/src/assets/init/src/core/entity/CoreEntity.ts.txt +70 -0
- package/src/assets/init/src/core/services/CoreService.ts.txt +21 -0
- package/src/assets/init/src/entity/Customer.ts.txt +68 -0
- package/src/assets/init/src/entity/Permission.ts.txt +29 -0
- package/src/assets/init/src/entity/Role.ts.txt +36 -0
- package/src/assets/init/src/entity/Staff.ts.txt +54 -0
- package/src/assets/init/src/entity-request/CustomerInsert.ts.txt +42 -0
- package/src/assets/init/src/entity-request/CustomerUpdate.ts.txt +40 -0
- package/src/assets/init/src/entity-request/PermissionImport.ts.txt +12 -0
- package/src/assets/init/src/entity-request/StaffUpdate.ts.txt +33 -0
- package/src/assets/init/src/index.ts.txt +13 -0
- package/src/assets/init/src/middleware/auth/Verification.ts.txt +16 -0
- package/src/assets/init/src/middleware/auth/VerificationJWT.ts.txt +16 -0
- package/src/assets/init/src/middleware/auth/strategy/AuthStrategy.ts.txt +5 -0
- package/src/assets/init/src/middleware/auth/strategy/JWT.ts.txt +147 -0
- package/src/assets/init/src/middleware/error/handleError.ts.txt +22 -0
- package/src/assets/init/src/middleware/error/handleNotFound.ts.txt +7 -0
- package/src/assets/init/src/middleware/response/CustomSendResponse.ts.txt +35 -0
- package/src/assets/init/src/middleware/response/responseAPI.ts.txt +76 -0
- package/src/assets/init/src/middleware/validator/Validator.ts.txt +103 -0
- package/src/assets/init/src/services/CustomerService.ts.txt +79 -0
- package/src/assets/init/src/services/InitService.ts.txt +11 -0
- package/src/assets/init/src/services/MailService.ts.txt +271 -0
- package/src/assets/init/src/services/RoleService.ts.txt +66 -0
- package/src/assets/init/src/services/StaffService.ts.txt +104 -0
- package/src/assets/init/src/ssl/certificate-ca.crt +0 -0
- package/src/assets/init/src/ssl/certificate.crt +0 -0
- package/src/assets/init/src/ssl/private.key +0 -0
- package/src/assets/init/src/types/express.d.ts.txt +97 -0
- package/src/assets/init/src/util/expo.ts.txt +53 -0
- package/src/assets/init/src/util/helper.ts.txt +321 -0
- package/src/assets/init/src/util/language.ts.txt +8 -0
- package/src/assets/init/src/util/logger.ts.txt +47 -0
- package/src/assets/init/src/util/mailer.ts.txt +32 -0
- package/src/assets/init/src/util/password.ts.txt +13 -0
- package/src/assets/init/tsconfig.json.txt +26 -0
- package/src/assets/service/service.txt +34 -0
- package/src/constant.ts +83 -0
- package/src/extension.ts +459 -0
- package/src/provider/codeAction/controller/addPathParams.ts +65 -0
- package/src/provider/codeAction/controller/addTokenParam.ts +43 -0
- package/src/provider/codeAction/controller/addValidation.ts +47 -0
- package/src/provider/codeAction/controller/codeAction.ts +34 -0
- package/src/provider/codeAction/controller/util.ts +48 -0
- package/src/provider/codeAction/entity/codeAction.ts +48 -0
- package/src/provider/codeAction/entity/handleBuilder.ts +87 -0
- package/src/provider/codeAction/entity/handleFunction.ts +487 -0
- package/src/provider/codeAction/entity/handleProperty.ts +32 -0
- package/src/provider/codeAction/entity/handleRelation.ts +72 -0
- package/src/provider/codeAction/entity/helper.ts +132 -0
- package/src/provider/codeAction/entity-request/codeAction.ts +178 -0
- package/src/provider/codeAction/enum/codeAction.ts +95 -0
- package/src/provider/codeAction/service/codeAction.ts +232 -0
- package/src/provider/completion/CompletionProvider.ts +108 -0
- package/src/provider/errorChecking/checkHeaderToken.ts +60 -0
- package/src/provider/errorChecking/checkPathParam.ts +64 -0
- package/src/provider/errorChecking/checkRequired.ts +56 -0
- package/src/provider/errorChecking/errorChecking.ts +35 -0
- package/src/provider/errorChecking/util.ts +56 -0
- package/src/provider/treeDataProvider/Dependency.ts +26 -0
- package/src/provider/treeDataProvider/TreeProviderCommand.ts +60 -0
- package/src/provider/treeDataProvider/TreeProviderProject.ts +65 -0
- package/src/provider/treeDataProvider/api/createApi.ts +106 -0
- package/src/provider/treeDataProvider/controller/command/createController.ts +99 -0
- package/src/provider/treeDataProvider/controller/command/handleMethod.ts +363 -0
- package/src/provider/treeDataProvider/controller/treeData.ts +81 -0
- package/src/provider/treeDataProvider/deploy/command/handleDeploy.ts +70 -0
- package/src/provider/treeDataProvider/deploy/treeData.ts +21 -0
- package/src/provider/treeDataProvider/entity/command/addProperty.ts +144 -0
- package/src/provider/treeDataProvider/entity/command/addRelation.ts +125 -0
- package/src/provider/treeDataProvider/entity/command/createEntity.ts +53 -0
- package/src/provider/treeDataProvider/entity/command/createEntityRequest.ts +65 -0
- package/src/provider/treeDataProvider/entity/command/exportInterface.ts +130 -0
- package/src/provider/treeDataProvider/entity/treeData.ts +49 -0
- package/src/provider/treeDataProvider/module/command/configuration.ts +34 -0
- package/src/provider/treeDataProvider/module/command/contentDefine.ts +36 -0
- package/src/provider/treeDataProvider/module/command/initProject.ts +155 -0
- package/src/provider/treeDataProvider/module/treeData.ts +28 -0
- package/src/provider/treeDataProvider/project/command/addEnum.ts +0 -0
- package/src/provider/treeDataProvider/project/command/addProjectName.ts +23 -0
- package/src/provider/treeDataProvider/project/command/getProjectDetails.ts +284 -0
- package/src/provider/treeDataProvider/project/treeData.ts +28 -0
- package/src/provider/treeDataProvider/service/command/createService.ts +70 -0
- package/src/provider/treeDataProvider/service/command/handleConstructor.ts +134 -0
- package/src/provider/treeDataProvider/service/treeData.ts +25 -0
- package/src/types/project.d.ts +7 -0
- package/src/util.ts +145 -0
- package/src/utils/Password.ts +19 -0
- package/tsconfig.json +18 -0
- package/tslint.json +15 -0
- package/vsc-extension-quickstart.md +42 -0
@@ -0,0 +1,72 @@
|
|
1
|
+
import * as vscode from 'vscode';
|
2
|
+
import { EntityAction, PropertyType } from '../../../constant';
|
3
|
+
import { getFullTextType } from '../../../util';
|
4
|
+
import { FSProvider } from '../../../FsProvider';
|
5
|
+
|
6
|
+
export function createRelationAction(document: vscode.TextDocument, range: vscode.Range) {
|
7
|
+
if (isEntityRelations(document, range)) {
|
8
|
+
const insertOneToMany = createAddRelationAction(document, range, EntityAction.OneToMany);
|
9
|
+
const insertManyToOne = createAddRelationAction(document, range, EntityAction.ManyToOne);
|
10
|
+
const insertManyToMany = createAddRelationAction(document, range, EntityAction.ManyToMany);
|
11
|
+
const insertOneToOne = createAddRelationAction(document, range, EntityAction.OneToOne);
|
12
|
+
|
13
|
+
return [
|
14
|
+
insertOneToMany,
|
15
|
+
insertManyToOne,
|
16
|
+
insertManyToMany,
|
17
|
+
insertOneToOne
|
18
|
+
];
|
19
|
+
}
|
20
|
+
|
21
|
+
return []
|
22
|
+
}
|
23
|
+
|
24
|
+
function isEntityRelations(document: vscode.TextDocument, range: vscode.Range) {
|
25
|
+
const start = range.start;
|
26
|
+
const line = document.lineAt(start.line);
|
27
|
+
return line.text.includes('RELATIONS')
|
28
|
+
}
|
29
|
+
|
30
|
+
function createAddRelationAction(document: vscode.TextDocument, range: vscode.Range, typeFunc: EntityAction): vscode.CodeAction {
|
31
|
+
const entity = new vscode.CodeAction(typeFunc, vscode.CodeActionKind.QuickFix);
|
32
|
+
switch (typeFunc) {
|
33
|
+
case EntityAction.OneToMany:
|
34
|
+
entity.command = {
|
35
|
+
command: typeFunc,
|
36
|
+
title: 'OneToMany with:',
|
37
|
+
tooltip: 'OneToMany with:',
|
38
|
+
arguments: [document]
|
39
|
+
};
|
40
|
+
break
|
41
|
+
|
42
|
+
case EntityAction.ManyToOne:
|
43
|
+
entity.command = {
|
44
|
+
command: typeFunc,
|
45
|
+
title: 'ManyToOne with:',
|
46
|
+
tooltip: 'ManyToOne with:',
|
47
|
+
arguments: [document]
|
48
|
+
};
|
49
|
+
break
|
50
|
+
|
51
|
+
case EntityAction.ManyToMany:
|
52
|
+
entity.command = {
|
53
|
+
command: typeFunc,
|
54
|
+
title: 'ManyToMany with:',
|
55
|
+
tooltip: 'ManyToMany with:',
|
56
|
+
arguments: [document]
|
57
|
+
};
|
58
|
+
break
|
59
|
+
|
60
|
+
case EntityAction.OneToOne:
|
61
|
+
entity.command = {
|
62
|
+
command: typeFunc,
|
63
|
+
title: 'OneToOne with:',
|
64
|
+
tooltip: 'OneToOne with:',
|
65
|
+
arguments: [document]
|
66
|
+
};
|
67
|
+
break
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
return entity;
|
72
|
+
}
|
@@ -0,0 +1,132 @@
|
|
1
|
+
import * as vscode from 'vscode';
|
2
|
+
import { FSProvider } from '../../../FsProvider';
|
3
|
+
import { getWordBetweenSpace, getFullTextType } from '../../../util';
|
4
|
+
|
5
|
+
export function getEntityFromFunction(document: vscode.TextDocument, range: vscode.Range, isQuery: boolean = false) {
|
6
|
+
const start = range.start;
|
7
|
+
const line = document.lineAt(start.line);
|
8
|
+
|
9
|
+
if (!isQuery) {
|
10
|
+
const entities = line.text.match(/\s[A-Z][A-z]+/)
|
11
|
+
if (entities && entities.length) {
|
12
|
+
const entity = entities[0].replace(' ', '').replace('.', '')
|
13
|
+
return { text: entity, lastIndex: 0 }
|
14
|
+
}
|
15
|
+
return { text: "", lastIndex: 0 }
|
16
|
+
} else {
|
17
|
+
const { text, lastIndex } = getWordBetweenSpace(line.text, range.start.character)
|
18
|
+
if (!text) return { text: "", lastIndex: 0 }
|
19
|
+
|
20
|
+
const entityFullText = getFullTextType(text)
|
21
|
+
return { text: entityFullText.classifyCase, lastIndex }
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
|
26
|
+
export function getPropertiesEntity(name: string): any[] {
|
27
|
+
const lines = FSProvider.getLinesDocumentInFile(`src/entity/${name}.ts`)
|
28
|
+
if (!lines.length) return []
|
29
|
+
const properties = []
|
30
|
+
for (let index = 0; index < lines.length; index++) {
|
31
|
+
const line = lines[index];
|
32
|
+
if (line.includes('@Column') || line.includes('@PrimaryGeneratedColumn')) {
|
33
|
+
let lineProperty = lines[index + 1]
|
34
|
+
if (lineProperty.includes('JsonProperty') || lineProperty.includes('Property')) {
|
35
|
+
lineProperty = lines[index + 2]
|
36
|
+
}
|
37
|
+
lineProperty = lineProperty.replace(':', '').replace(';', '')
|
38
|
+
const words = lineProperty.split(' ').filter(Boolean)
|
39
|
+
if (words.length > 1) {
|
40
|
+
properties.push({ name: words[0], type: words[1] })
|
41
|
+
}
|
42
|
+
else continue
|
43
|
+
}
|
44
|
+
}
|
45
|
+
const propertyInCore = getPropertyInCore()
|
46
|
+
properties.push(...propertyInCore)
|
47
|
+
|
48
|
+
return properties
|
49
|
+
}
|
50
|
+
|
51
|
+
function getPropertyInCore() {
|
52
|
+
const lines = FSProvider.getLinesDocumentInFile(`src/core/entity/CoreEntity.ts`)
|
53
|
+
if (!lines.length) return []
|
54
|
+
const properties = []
|
55
|
+
for (let index = 0; index < lines.length; index++) {
|
56
|
+
const line = lines[index];
|
57
|
+
if (line.includes('@Column') || line.includes('@PrimaryGeneratedColumn')) {
|
58
|
+
let lineProperty = lines[index + 1]
|
59
|
+
if (lineProperty.includes('JsonProperty') || lineProperty.includes('Property')) {
|
60
|
+
lineProperty = lines[index + 2]
|
61
|
+
}
|
62
|
+
lineProperty = lineProperty.replace(':', '').replace(';', '')
|
63
|
+
const words = lineProperty.split(' ').filter(Boolean)
|
64
|
+
if (words.length > 1) { properties.push({ name: words[0], type: words[1] }) }
|
65
|
+
else continue
|
66
|
+
}
|
67
|
+
}
|
68
|
+
return properties
|
69
|
+
}
|
70
|
+
|
71
|
+
|
72
|
+
export function getRelationsEntityDeeper(name: string, nameExcept: string = ''): { relations: any[], entities: any[] } {
|
73
|
+
const lines = FSProvider.getLinesDocumentInFile(`src/entity/${name}.ts`)
|
74
|
+
if (!lines.length) return { relations: [], entities: [] }
|
75
|
+
const relations = []
|
76
|
+
const nextEntity = []
|
77
|
+
for (let index = 0; index < lines.length; index++) {
|
78
|
+
const line = lines[index];
|
79
|
+
if (line.includes('@ManyToMany') ||
|
80
|
+
line.includes('@OneToMany') ||
|
81
|
+
line.includes('@ManyToOne') ||
|
82
|
+
line.includes('@OneToOne')) {
|
83
|
+
let lineProperty = lines[index + 1]
|
84
|
+
if (lineProperty.includes('@')) {
|
85
|
+
lineProperty = lines[index + 2]
|
86
|
+
}
|
87
|
+
if (lineProperty.includes('@')) {
|
88
|
+
lineProperty = lines[index + 3]
|
89
|
+
}
|
90
|
+
lineProperty = lineProperty.replace(':', '').replace(';', '').replace('[]', '')
|
91
|
+
|
92
|
+
if (nameExcept && lineProperty == nameExcept) continue
|
93
|
+
|
94
|
+
const words = lineProperty.split(' ').filter(Boolean)
|
95
|
+
if (words.length > 1) {
|
96
|
+
relations.push(words[0])
|
97
|
+
nextEntity.push(words[1])
|
98
|
+
}
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
return { relations, entities: nextEntity }
|
103
|
+
}
|
104
|
+
|
105
|
+
export function getRelationsEntity(name: string): any[] {
|
106
|
+
const finalRelation: any[] = []
|
107
|
+
const { relations, entities } = getRelationsEntityDeeper(name)
|
108
|
+
if (!relations || !relations.length) return []
|
109
|
+
|
110
|
+
relations.map((r: any, i: number) => {
|
111
|
+
finalRelation.push(r)
|
112
|
+
const nextRelations = getRelationsEntityDeeper(entities[i], name)
|
113
|
+
|
114
|
+
if (relations && relations.length) {
|
115
|
+
finalRelation.push(...nextRelations.relations.map((n: any) => `${r}.${n}`))
|
116
|
+
}
|
117
|
+
})
|
118
|
+
return finalRelation
|
119
|
+
}
|
120
|
+
|
121
|
+
export function findLastLineRelation(document: vscode.TextDocument, currentLine: vscode.TextLine) {
|
122
|
+
let start = true
|
123
|
+
let currentLineNumber = currentLine.lineNumber
|
124
|
+
while (start) {
|
125
|
+
currentLineNumber += 1
|
126
|
+
let newLine = document.lineAt(currentLineNumber)
|
127
|
+
if (!newLine.text.includes('Join')) {
|
128
|
+
start = false
|
129
|
+
}
|
130
|
+
}
|
131
|
+
return currentLineNumber
|
132
|
+
}
|
@@ -0,0 +1,178 @@
|
|
1
|
+
import { FSProvider } from '../../../FsProvider';
|
2
|
+
import * as vscode from 'vscode';
|
3
|
+
import { getFullTextType, toLowerCaseFirstLetter } from '../../../util';
|
4
|
+
|
5
|
+
export enum EntityRequestAction {
|
6
|
+
AddProperty = 'BMD: Add property entity-request',
|
7
|
+
}
|
8
|
+
|
9
|
+
|
10
|
+
export class EntityRequestActionProvider implements vscode.CodeActionProvider {
|
11
|
+
|
12
|
+
public static readonly providedCodeActionKinds = [
|
13
|
+
vscode.CodeActionKind.QuickFix
|
14
|
+
];
|
15
|
+
|
16
|
+
public provideCodeActions(
|
17
|
+
document: vscode.TextDocument,
|
18
|
+
range: vscode.Range | vscode.Selection,
|
19
|
+
context: vscode.CodeActionContext
|
20
|
+
): vscode.CodeAction[] | undefined {
|
21
|
+
|
22
|
+
if (this.isEntityRequestProperties(document, range)) {
|
23
|
+
const addProperty = this.createEntityFunc(document, range, EntityRequestAction.AddProperty);
|
24
|
+
|
25
|
+
return [
|
26
|
+
addProperty
|
27
|
+
];
|
28
|
+
}
|
29
|
+
|
30
|
+
}
|
31
|
+
|
32
|
+
private isEntityRequestProperties(document: vscode.TextDocument, range: vscode.Range) {
|
33
|
+
const start = range.start;
|
34
|
+
const line = document.lineAt(start.line);
|
35
|
+
return line.text.includes('PROPERTIES') && document.fileName.includes('entity-request/')
|
36
|
+
}
|
37
|
+
|
38
|
+
|
39
|
+
private createEntityFunc(document: vscode.TextDocument, range: vscode.Range, typeFunc: EntityRequestAction): vscode.CodeAction {
|
40
|
+
const entity = new vscode.CodeAction(typeFunc, vscode.CodeActionKind.QuickFix);
|
41
|
+
switch (typeFunc) {
|
42
|
+
case EntityRequestAction.AddProperty:
|
43
|
+
entity.command = {
|
44
|
+
command: typeFunc,
|
45
|
+
title: 'Add property: ',
|
46
|
+
tooltip: 'Add property: ',
|
47
|
+
arguments: [document]
|
48
|
+
};
|
49
|
+
break
|
50
|
+
|
51
|
+
default:
|
52
|
+
break;
|
53
|
+
|
54
|
+
}
|
55
|
+
|
56
|
+
return entity;
|
57
|
+
}
|
58
|
+
|
59
|
+
public async addProperty(document: vscode.TextDocument) {
|
60
|
+
let entity = this.getEntityFromEntityRequest(document)
|
61
|
+
if (!entity)
|
62
|
+
return vscode.window.showInformationMessage('Find not found entity')
|
63
|
+
|
64
|
+
const propertiesInEntity = this.getPropertiesEntity(entity)
|
65
|
+
if (!propertiesInEntity.length)
|
66
|
+
return vscode.window.showInformationMessage('Find not found properties in entity')
|
67
|
+
|
68
|
+
const propertiesInEntityRequest = this.getPropertiesEntityRequest(document)
|
69
|
+
|
70
|
+
const propertiesNotInEntityRequest = propertiesInEntity.filter(property => {
|
71
|
+
if (propertiesInEntityRequest.indexOf(property) == -1)
|
72
|
+
return property
|
73
|
+
})
|
74
|
+
|
75
|
+
if (!propertiesNotInEntityRequest.length)
|
76
|
+
return vscode.window.showInformationMessage('All property were selected')
|
77
|
+
|
78
|
+
const property = await vscode.window.showQuickPick(
|
79
|
+
[...propertiesNotInEntityRequest],
|
80
|
+
{ ignoreFocusOut: true }
|
81
|
+
)
|
82
|
+
if (!property)
|
83
|
+
return vscode.window.showInformationMessage('No property was selected')
|
84
|
+
|
85
|
+
const edit = new vscode.WorkspaceEdit();
|
86
|
+
|
87
|
+
let template = this.getTemplatePropertyEntity(entity, property)
|
88
|
+
if (!template)
|
89
|
+
return vscode.window.showInformationMessage('Can not generate template')
|
90
|
+
|
91
|
+
for (let index = 0; index < document.lineCount; index++) {
|
92
|
+
const line = document.lineAt(index)
|
93
|
+
if (line.text.includes('PROPERTIES')) {
|
94
|
+
edit.insert(document.uri, new vscode.Position(index + 1, 0), template);
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
const entityCamel = getFullTextType(entity).camelCase
|
99
|
+
for (let index = 0; index < document.lineCount; index++) {
|
100
|
+
const line = document.lineAt(index)
|
101
|
+
if (line.text.includes(`return ${entityCamel}`)) {
|
102
|
+
let templateTo = `${toLowerCaseFirstLetter(entity)}.${property} = this.${property} \n`
|
103
|
+
edit.insert(document.uri, new vscode.Position(index - 1, 0), templateTo);
|
104
|
+
}
|
105
|
+
}
|
106
|
+
|
107
|
+
vscode.workspace.applyEdit(edit)
|
108
|
+
}
|
109
|
+
|
110
|
+
private getEntityFromEntityRequest(document: vscode.TextDocument) {
|
111
|
+
let entity = ''
|
112
|
+
for (let index = 0; index < document.lineCount; index++) {
|
113
|
+
let lineText = document.lineAt(index).text
|
114
|
+
if (lineText.includes('new')) {
|
115
|
+
lineText = lineText.replace('()', '')
|
116
|
+
const words = lineText.split(' ')
|
117
|
+
entity = words[words.length - 1]
|
118
|
+
break;
|
119
|
+
}
|
120
|
+
}
|
121
|
+
return entity
|
122
|
+
}
|
123
|
+
|
124
|
+
|
125
|
+
private getPropertiesEntity(name: string): any[] {
|
126
|
+
const lines = FSProvider.getLinesDocumentInFile(`src/entity/${name}.ts`)
|
127
|
+
if (!lines.length) return []
|
128
|
+
const properties = []
|
129
|
+
for (let index = 0; index < lines.length; index++) {
|
130
|
+
const line = lines[index];
|
131
|
+
if (line.includes('@Column')) {
|
132
|
+
let lineProperty = lines[index + 2]
|
133
|
+
lineProperty = lineProperty.replace(':', '').replace(';', '')
|
134
|
+
const words = lineProperty.split(' ').filter(Boolean)
|
135
|
+
if (words.length > 1) properties.push(words[0])
|
136
|
+
else continue
|
137
|
+
}
|
138
|
+
}
|
139
|
+
return properties
|
140
|
+
}
|
141
|
+
|
142
|
+
private getPropertiesEntityRequest(document: vscode.TextDocument): any {
|
143
|
+
const properties: any = []
|
144
|
+
for (let index = 0; index < document.lineCount; index++) {
|
145
|
+
let lineText = document.lineAt(index).text
|
146
|
+
if (lineText.includes('@JsonProperty') || lineText.includes('Property')) {
|
147
|
+
let lineProperty = document.lineAt(index + 1).text
|
148
|
+
lineProperty = lineProperty.replace(':', '').replace(';', '')
|
149
|
+
const words = lineProperty.split(' ').filter(Boolean)
|
150
|
+
if (words.length > 1) properties.push(words[0])
|
151
|
+
else continue
|
152
|
+
}
|
153
|
+
}
|
154
|
+
return properties
|
155
|
+
}
|
156
|
+
|
157
|
+
private getTemplatePropertyEntity(name: string, property: string): any {
|
158
|
+
|
159
|
+
const lines = FSProvider.getLinesDocumentInFile(`src/entity/${name}.ts`)
|
160
|
+
if (!lines.length) return vscode.window.showInformationMessage('Can not read file or file is empty')
|
161
|
+
|
162
|
+
let template = ''
|
163
|
+
for (let index = 0; index < lines.length; index++) {
|
164
|
+
const line = lines[index];
|
165
|
+
const lineDecorator = lines[index + 1];
|
166
|
+
const lineProperty = lines[index + 2]
|
167
|
+
if (line.includes('@Column') && lineProperty.includes(property + ':')) {
|
168
|
+
return template = `
|
169
|
+
${lineDecorator}
|
170
|
+
${lineProperty}
|
171
|
+
`
|
172
|
+
}
|
173
|
+
}
|
174
|
+
|
175
|
+
return template
|
176
|
+
}
|
177
|
+
|
178
|
+
}
|
@@ -0,0 +1,95 @@
|
|
1
|
+
import * as vscode from 'vscode';
|
2
|
+
import { API } from '../../../API';
|
3
|
+
import { BMDCommand } from '../../../constant';
|
4
|
+
import { Request } from '../../../Request';
|
5
|
+
|
6
|
+
export class EnumActionProvider implements vscode.CodeActionProvider {
|
7
|
+
|
8
|
+
public static readonly providedCodeActionKinds = [
|
9
|
+
vscode.CodeActionKind.QuickFix
|
10
|
+
];
|
11
|
+
|
12
|
+
public provideCodeActions(
|
13
|
+
document: vscode.TextDocument,
|
14
|
+
range: any
|
15
|
+
): vscode.CodeAction[] | undefined | any {
|
16
|
+
if (isEnumLine(document, range)) {
|
17
|
+
const action = new vscode.CodeAction(BMDCommand.AddEnum, vscode.CodeActionKind.QuickFix);
|
18
|
+
|
19
|
+
action.command = {
|
20
|
+
command: BMDCommand.AddEnum,
|
21
|
+
title: 'Add enum',
|
22
|
+
tooltip: 'Add enum',
|
23
|
+
arguments: [document, range]
|
24
|
+
};
|
25
|
+
return [action];
|
26
|
+
}
|
27
|
+
|
28
|
+
return []
|
29
|
+
}
|
30
|
+
|
31
|
+
}
|
32
|
+
|
33
|
+
function isEnumLine(document: vscode.TextDocument, range: vscode.Range) {
|
34
|
+
const start = range.start;
|
35
|
+
const line = document.lineAt(start.line);
|
36
|
+
return line.text.includes('enum')
|
37
|
+
}
|
38
|
+
|
39
|
+
export async function addEnum(document: vscode.TextDocument, range: vscode.Range) {
|
40
|
+
const start = range.start;
|
41
|
+
const line = document.lineAt(start.line);
|
42
|
+
|
43
|
+
const enumName = getEnumNameInLine(line.text)
|
44
|
+
const enumBody = getEnumBody(document, range)
|
45
|
+
|
46
|
+
const folders = vscode.workspace.workspaceFolders
|
47
|
+
if (!folders?.length) return
|
48
|
+
|
49
|
+
const projectName = folders[0].name
|
50
|
+
|
51
|
+
const data = await Request.post(API.Enum.post, {
|
52
|
+
name: enumName,
|
53
|
+
project: projectName,
|
54
|
+
body: enumBody
|
55
|
+
})
|
56
|
+
|
57
|
+
if (data) {
|
58
|
+
vscode.window.showInformationMessage(`Upload successfully!`);
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
function getEnumNameInLine(line: string) {
|
63
|
+
const words = line.split(' ')
|
64
|
+
|
65
|
+
for (let index = 0; index < words.length; index++) {
|
66
|
+
const word = words[index];
|
67
|
+
if (word == 'enum') {
|
68
|
+
return words[index + 1]
|
69
|
+
}
|
70
|
+
}
|
71
|
+
return ``
|
72
|
+
}
|
73
|
+
|
74
|
+
function getEnumBody(document: vscode.TextDocument, range: vscode.Range) {
|
75
|
+
let start = range.start.line
|
76
|
+
|
77
|
+
const lines = []
|
78
|
+
|
79
|
+
const line = document.lineAt(start);
|
80
|
+
lines.push(line.text) // Add select line
|
81
|
+
|
82
|
+
let isLineOpenEnum = !line.text.includes('}')
|
83
|
+
while (isLineOpenEnum) {
|
84
|
+
start += 1
|
85
|
+
const nextLine = document.lineAt(start)
|
86
|
+
lines.push(nextLine.text)
|
87
|
+
isLineOpenEnum = !nextLine.text.includes('}')
|
88
|
+
}
|
89
|
+
|
90
|
+
const body = `
|
91
|
+
${lines.join('\n')}
|
92
|
+
`
|
93
|
+
|
94
|
+
return body
|
95
|
+
}
|