From 71c92d0638b73f7116a936e744411e1949c5ab4f Mon Sep 17 00:00:00 2001 From: Vusal Orujov Date: Sat, 5 Jun 2021 22:33:36 +0400 Subject: [PATCH 1/6] Add auto-completion tags for Doctrine ORM Annotations --- package.json | 7 +- src/completions.ts | 10 +++ src/extra/doctrine.ts | 150 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 src/extra/doctrine.ts diff --git a/package.json b/package.json index 1a0ba3b..052f064 100644 --- a/package.json +++ b/package.json @@ -93,6 +93,11 @@ "email": "email@email.com" }, "description": "Default author tag" + }, + "php-docblocker.enableDoctrineCompletions": { + "type": "boolean", + "default": false, + "description": "Whether you want to enable auto completaion for Doctrine ORM Annonations." } } } @@ -117,4 +122,4 @@ "dependencies": { "coveralls": "^3.0.7" } -} +} \ No newline at end of file diff --git a/src/completions.ts b/src/completions.ts index c8d2b14..01f41c3 100644 --- a/src/completions.ts +++ b/src/completions.ts @@ -1,6 +1,7 @@ import {workspace, TextDocument, Position, CancellationToken, ProviderResult, CompletionItem, CompletionItemProvider, Range, SnippetString, CompletionItemKind, window} from "vscode"; import Documenter from "./documenter"; import Config from "./util/config"; +import {doctrineTags} from './extra/doctrine' /** * Completions provider that can be registered to the language @@ -315,6 +316,8 @@ export default class Completions implements CompletionItemProvider protected getTags():Array<{tag:string, snippet:string}> { if (!this.formatted) { + this.addDoctrineTags(); + this.tags.forEach((tag, index) => { if (tag.tag == '@author') { tag.snippet = tag.snippet.replace("{{name}}", Config.instance.get('author').name); @@ -328,4 +331,11 @@ export default class Completions implements CompletionItemProvider return this.tags; } + + protected addDoctrineTags() + { + if (Config.instance.get('enableDoctrineCompletions')) { + this.tags = this.tags.concat(doctrineTags) + } + } } diff --git a/src/extra/doctrine.ts b/src/extra/doctrine.ts new file mode 100644 index 0000000..6b1bc09 --- /dev/null +++ b/src/extra/doctrine.ts @@ -0,0 +1,150 @@ +export let doctrineTags = [ + { + "tag": "@ORM\\Column", + "snippet": "@ORM\\Column(type=\"${1|smallint,integer,bigint,decimal,float,string,ascii_string,text,guid,binary,blob,boolean,date,date_immutable,datetime,datetime_immutable,datetimetz,datetimetz_immutable,time,time_immutable,dateinterval,array,simple_array,json,object|}\",${2: name=\"${3:column_name}\",}${4: length=${5:255},}${6: precision=${7:2},}${8: scale=${9:2},}${10: unique=${11|true,false|},}${12: nullable=${13|true,false|},}${14: options=${15|default,unsigned,fixed,comment,collation,check|},}${16: columnDefinition=${17:\"DDL SQL snippet\"}})" + }, + { + "tag": "@ORM\\ColumnResult", + "snippet": "@ORM\\ColumnResult(name=\"${1:The name of a column in the SELECT clause of a SQL query}\"})" + }, + { + "tag": "@ORM\\Cache", + "snippet": "@ORM\\Cache${1:(${2:name=\"${3|READ_ONLY,READ_WRITE,NONSTRICT_READ_WRITE|}\",}${4: region=\"${5:A specific region name}\"})}" + }, + { + "tag": "@ORM\\ChangeTrackingPolicy", + "snippet": "@ORM\\ChangeTrackingPolicy(\"${1|DEFERRED_IMPLICIT,DEFERRED_EXPLICIT,NOTIFY|}\")" + }, + { + "tag": "@ORM\\CustomIdGenerator", + "snippet": "@ORM\\CustomIdGenerator(class=\"${1:Custom\\Namespace\\IdGenerator}\")" + }, + { + "tag": "@ORM\\DiscriminatorColumn", + "snippet": "@ORM\\DiscriminatorColumn(name=\"${1:discr}\"${2:, type=\"${3:string}\"}${4:, length=${5:255}})" + }, + { + "tag": "@ORM\\DiscriminatorMap", + "snippet": "@ORM\\DiscriminatorMap({\"base\" = \"Base\\BaseEntity\", \"concrete\" = \"Concrete\\ConcreteEntity\"})" + }, + { + "tag": "@ORM\\Embeddable", + "snippet": "@ORM\\Embeddable" + }, + { + "tag": "@ORM\\Embedded", + "snippet": "@ORM\\Embedded(class=\"${1:Namespace\\ClassName}\")" + }, + { + "tag": "@ORM\\Entity", + "snippet": "@ORM\\Entity${1:(${2:repositoryClass=\"${3:Namespace\\RepositoryClassName}\", }${4:readOnly=${5|true,false|}})}" + }, + { + "tag": "@ORM\\EntityResult", + "snippet": "@ORM\\EntityResult(entityClass=\"${1:Namespace\\ClassName}\"${2:, fields={${3}\\}}${4:, discriminatorColumn=\"${5:discr}\"})" + }, + { + "tag": "@ORM\\FieldResult", + "snippet": "@ORM\\FieldResult(name=\"${1:Name of the persistent field or property of the class.}\"${2:, column=\"${5:Name of the column in the SELECT clause.}\"})" + }, + { + "tag": "@ORM\\GeneratedValue", + "snippet": "@ORM\\GeneratedValue${1:(strategy=\"${2|AUTO,SEQUENCE,TABLE,IDENTITY,UUID,CUSTOM,NONE|}\")}" + }, + { + "tag": "@ORM\\HasLifecycleCallbacks", + "snippet": "@ORM\\HasLifecycleCallbacks" + }, + { + "tag": "@ORM\\Index", + "snippet": "@ORM\\Index(name=\"${1:index_name_idx}\", columns={\"${2:column_1}\"${3:, \"${4:column_2}\"}})${5:, options=\"{${6}\\}\"}" + }, + { + "tag": "@ORM\\Id", + "snippet": "@ORM\\Id" + }, + { + "tag": "@ORM\\InheritanceType", + "snippet": "@ORM\\InheritanceType(\"${1|SINGLE_TABLE,JOINED|}\")" + }, + { + "tag": "@ORM\\JoinColumn", + "snippet": "@ORM\\JoinColumn${1:(${2:name=\"${3:Column name that holds the foreign key identifier for this relation}\", }${4:referencedColumnName=\"${5:id}\", }${6:unique=\"${7|false,true|}\", }${8:nullable=\"${9|true,false|}\", }${10:onDelete=\"${11:CASCADE}\", }${12:columnDefinition=\"${13:DDL SQL snippet}\"})}" + }, + { + "tag": "@ORM\\JoinColumns", + "snippet": "@ORM\\JoinColumns" + }, + { + "tag": "@ORM\\JoinTable", + "snippet": "@ORM\\JoinTable${1:(${2:name=\"${3:Database name of the join-table}\", }${4:joinColumns=\"${5}\", }${6:inverseJoinColumns=\"${7}\"})}" + }, + { + "tag": "@ORM\\ManyToOne", + "snippet": "@ORM\\ManyToOne(targetEntity=\"${1:Namespace\\EntityClass}\"${2:, cascade={${3:\"persist\", }${4:\"remove\", }${5:\"merge\", }${6:\"detach\", }${7:\"refresh\", }${8:\"all\"}\\}}${9:, fetch=\"${10|LAZY,EAGER|}\"})" + }, + { + "tag": "@ORM\\ManyToMany", + "snippet": "@ORM\\ManyToMany(targetEntity=\"${1:Namespace\\EntityClass}\"${2:, mappedBy=\"${3}\"}${4:, inversedBy=\"${5}\"}${6:, cascade={${7:\"persist\", }${8:\"remove\", }${9:\"merge\", }${10:\"detach\", }${11:\"refresh\", }${12:\"all\"}\\}}${13:, fetch=\"${14|LAZY,EXTRA_LAZY,EAGER|}\"}${15:, indexBy=\"${16}\"})" + }, + { + "tag": "@ORM\\MappedSuperclass", + "snippet": "@ORM\\MappedSuperclass${1:(repositoryClass=\"${2:Namespace\\RepositoryClassName}\")}" + }, + { + "tag": "@ORM\\NamedNativeQuery", + "snippet": "@ORM\\NamedNativeQuery(name=\"${1}\", query=\"${2:SQL query string}\"${3:, resultClass=\"${4}\"}${5:, resultSetMapping=\"${6}\"})" + }, + { + "tag": "@ORM\\OneToOne", + "snippet": "@ORM\\OneToOne(targetEntity=\"${1:Namespace\\EntityClass}\"${2:, cascade={${3:\"persist\", }${4:\"remove\", }${5:\"merge\", }${6:\"detach\", }${7:\"refresh\", }${8:\"all\"}\\}}${9:, fetch=\"${10|LAZY,EAGER|}\"}${11:, orphanRemoval=${12|true,false|}}${13:, inversedBy=\"${14}\"})" + }, + { + "tag": "@ORM\\OneToMany", + "snippet": "@ORM\\OneToMany(targetEntity=\"${1:Namespace\\EntityClass}\"${2:, cascade={${3:\"persist\", }${4:\"remove\", }${5:\"merge\", }${6:\"detach\", }${7:\"refresh\", }${8:\"all\"}\\}}${9:, orphanRemoval=${10|true,false|}}${11:, mappedBy=\"${12}\"}${13:, fetch=\"${14|LAZY,EXTRA_LAZY,EAGER|}\"}${15:, indexBy=\"${16}\"})" + }, + { + "tag": "@ORM\\OrderBy", + "snippet": "@ORM\\OrderBy({\"${1:name}\"=\"${2|ASC,DESC|}\"})" + }, + { + "tag": "@ORM\\PostLoad", + "snippet": "@ORM\\PostLoad" + }, + { + "tag": "@ORM\\PostPersist", + "snippet": "@ORM\\PostPersist" + }, + { + "tag": "@ORM\\PostRemove", + "snippet": "@ORM\\PostRemove" + }, + { + "tag": "@ORM\\PostUpdate", + "snippet": "@ORM\\PostUpdate" + }, + { + "tag": "@ORM\\PrePersist", + "snippet": "@ORM\\PrePersist" + }, + { + "tag": "@ORM\\PreRemove", + "snippet": "@ORM\\PreRemove" + }, + { + "tag": "@ORM\\PreUpdate", + "snippet": "@ORM\\PreUpdate" + }, + { + "tag": "@ORM\\SequenceGenerator", + "snippet": "@ORM\\SequenceGenerator(sequenceName=\"${1:tablename_seq}\"${2:, allocationSize=${3:10}}${4:, initialValue=${5:1}})" + }, + { + "tag": "@ORM\\SqlResultSetMapping", + "snippet": "@ORM\\SqlResultSetMapping(name=\"${1}\"${2:, entities={${3}\\}}${4:, columns={${5}\\}})" + }, + { + "tag": "@ORM\\Table", + "snippet": "@ORM\\Table(name=\"${1:table_name}\"${2:, indexes={${3}\\}}${4:, uniqueConstraints={${5}\\}}${6:, schema=\"${7:schema_name}\"})" + } +]; \ No newline at end of file From 376bf40e0fc6a8e1abb578ccbd83758396b759a1 Mon Sep 17 00:00:00 2001 From: Vusal Orujov Date: Sat, 5 Jun 2021 23:03:38 +0400 Subject: [PATCH 2/6] Fix typo --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 052f064..44bc0a5 100644 --- a/package.json +++ b/package.json @@ -94,10 +94,10 @@ }, "description": "Default author tag" }, - "php-docblocker.enableDoctrineCompletions": { + "php-docblocker.enableDoctrineCompilation": { "type": "boolean", "default": false, - "description": "Whether you want to enable auto completaion for Doctrine ORM Annonations." + "description": "Whether you want to enable auto compilation for Doctrine ORM Annonations." } } } From 26a0bc30fa64fcdba996ffe4f3a0696ef6acc50a Mon Sep 17 00:00:00 2001 From: Vusal Orujov Date: Sat, 5 Jun 2021 23:10:06 +0400 Subject: [PATCH 3/6] Fix typo --- src/completions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/completions.ts b/src/completions.ts index 01f41c3..22699f2 100644 --- a/src/completions.ts +++ b/src/completions.ts @@ -334,7 +334,7 @@ export default class Completions implements CompletionItemProvider protected addDoctrineTags() { - if (Config.instance.get('enableDoctrineCompletions')) { + if (Config.instance.get('enableDoctrineCompilation')) { this.tags = this.tags.concat(doctrineTags) } } From bf56b407590a596039dfacd49ded38b766c73ff9 Mon Sep 17 00:00:00 2001 From: Vusal Orujov Date: Sat, 5 Jun 2021 23:52:31 +0400 Subject: [PATCH 4/6] Set default settings as first option --- src/extra/doctrine.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extra/doctrine.ts b/src/extra/doctrine.ts index 6b1bc09..63fdcc1 100644 --- a/src/extra/doctrine.ts +++ b/src/extra/doctrine.ts @@ -1,7 +1,7 @@ export let doctrineTags = [ { "tag": "@ORM\\Column", - "snippet": "@ORM\\Column(type=\"${1|smallint,integer,bigint,decimal,float,string,ascii_string,text,guid,binary,blob,boolean,date,date_immutable,datetime,datetime_immutable,datetimetz,datetimetz_immutable,time,time_immutable,dateinterval,array,simple_array,json,object|}\",${2: name=\"${3:column_name}\",}${4: length=${5:255},}${6: precision=${7:2},}${8: scale=${9:2},}${10: unique=${11|true,false|},}${12: nullable=${13|true,false|},}${14: options=${15|default,unsigned,fixed,comment,collation,check|},}${16: columnDefinition=${17:\"DDL SQL snippet\"}})" + "snippet": "@ORM\\Column(type=\"${1|smallint,integer,bigint,decimal,float,string,ascii_string,text,guid,binary,blob,boolean,date,date_immutable,datetime,datetime_immutable,datetimetz,datetimetz_immutable,time,time_immutable,dateinterval,array,simple_array,json,object|}\",${2: name=\"${3:column_name}\",}${4: length=${5:255},}${6: precision=${7:2},}${8: scale=${9:2},}${10: unique=${11|false,true|},}${12: nullable=${13|false,true|},}${14: options=${15|default,unsigned,fixed,comment,collation,check|},}${16: columnDefinition=${17:\"DDL SQL snippet\"}})" }, { "tag": "@ORM\\ColumnResult", From 1bbc19ead438205ff5b5082b5be7297e9d7a7e11 Mon Sep 17 00:00:00 2001 From: Vusal Orujov Date: Thu, 1 Sep 2022 11:41:23 +0400 Subject: [PATCH 5/6] Update package.json --- package.json | 5 ----- 1 file changed, 5 deletions(-) diff --git a/package.json b/package.json index cbc8715..8b2c1e0 100644 --- a/package.json +++ b/package.json @@ -142,11 +142,6 @@ "email": "email@email.com" }, "description": "Default author tag" - }, - "php-docblocker.enableDoctrineCompilation": { - "type": "boolean", - "default": false, - "description": "Whether you want to enable auto compilation for Doctrine ORM Annonations." } } } From a0009ebca9d3f1f54eee61076a3dcbd321264d87 Mon Sep 17 00:00:00 2001 From: Vusal Orujov Date: Thu, 1 Sep 2022 11:43:13 +0400 Subject: [PATCH 6/6] Update completions.ts --- src/completions.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/completions.ts b/src/completions.ts index 21794b6..7aaafeb 100644 --- a/src/completions.ts +++ b/src/completions.ts @@ -87,8 +87,6 @@ export default class Completions implements CompletionItemProvider protected addDoctrineTags() { - if (Config.instance.get('enableDoctrineCompilation')) { - this.tags = this.tags.concat(doctrineTags) - } + this.tags = this.tags.concat(doctrineTags); } }