Skip to content

Commit d02cf8e

Browse files
hopehadfieldrgrunber
authored andcommitted
Support movement of snippets to JDT-LS
Signed-off-by: Hope Hadfield <hhadfiel@redhat.com>
1 parent 4eadce1 commit d02cf8e

4 files changed

Lines changed: 82 additions & 86 deletions

File tree

package.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,6 @@
188188
"path": "./language-support/properties/JavaProperties.tmLanguage.json"
189189
}
190190
],
191-
"snippets": [
192-
{
193-
"language": "java",
194-
"path": "./snippets/java.json"
195-
}
196-
],
197191
"jsonValidation": [
198192
{
199193
"fileMatch": "package.json",

snippets/java.json

Lines changed: 0 additions & 79 deletions
This file was deleted.

snippets/server.json

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,82 @@
8686
"} while (${1:condition});"
8787
],
8888
"description": "Do-While Statement"
89+
},
90+
"Switch Statement": {
91+
"prefix": "switch",
92+
"body": [
93+
"switch (${1:key}) {",
94+
"\tcase ${2:value}:",
95+
"\t\t$0",
96+
"\t\tbreak;",
97+
"",
98+
"\tdefault:",
99+
"\t\tbreak;",
100+
"}"
101+
],
102+
"description": "Switch Statement"
103+
},
104+
"trycatch": {
105+
"prefix": "try_catch",
106+
"body": [
107+
"try {",
108+
"\t${TM_SELECTED_TEXT:$1}",
109+
"} catch (${2:Exception} ${3:e}) {",
110+
"\t$0// TODO: handle exception",
111+
"}"
112+
],
113+
"description": "try/catch block"
114+
},
115+
"tryresources": {
116+
"prefix": "try_resources",
117+
"body": [
118+
"try ($1) {",
119+
"\t$2",
120+
"} catch (${3:Exception} ${4:e}) {",
121+
"\t$0// TODO: handle exception",
122+
"}"
123+
]
124+
},
125+
"main": {
126+
"prefix": ["main", "psvm"],
127+
"body": [
128+
"public static void main(String[] args) {",
129+
"\t$0",
130+
"}"
131+
],
132+
"description": "Public static main method"
133+
},
134+
"Constructor": {
135+
"prefix": "ctor",
136+
"body": [
137+
"${1|public,protected,private|} ${2:${TM_FILENAME_BASE}}($3) {",
138+
"\t${4:super();}$0",
139+
"}"
140+
],
141+
"description": "Constructor"
142+
},
143+
"method": {
144+
"prefix": "method",
145+
"body": [
146+
"${1|public,protected,private|}${2| , static |}${3:void} ${4:name}($5) {",
147+
"\t$0",
148+
"}"
149+
],
150+
"description": "Method"
151+
},
152+
"newObject": {
153+
"prefix": "new",
154+
"body": [
155+
"${1:Object} ${2:foo} = new ${1}($3);",
156+
"$0"
157+
],
158+
"description": "Create new Object"
159+
},
160+
"Field": {
161+
"prefix": "field",
162+
"body": [
163+
"${1|public,protected,private|} ${2:String} ${3:name};"
164+
],
165+
"description": "Field"
89166
}
90167
}

src/snippetCompletionProvider.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ class SnippetCompletionProviderImpl implements CompletionItemProvider {
5656
}
5757

5858
export function beautifyDocument(raw: string): MarkdownString {
59-
const escapedString = raw.replace(/\$\{\d:?(.*?)\}/gm, '$1').replace(/\$\d/gm, '');
59+
const escapedString = raw.replace(/\$\{\d\|(.*?),.*?\}/gm, '$1')
60+
.replace(/\$\{\d:?(.*?)\}/gm, '$1')
61+
.replace(/\$\d/gm, '')
62+
.replace(/\${TM_SELECTED_TEXT:}/gm, '')
63+
.replace(/\${TM_FILENAME_BASE}/gm, '');
6064
return new MarkdownString().appendCodeblock(escapedString, "java");
6165
}
6266

0 commit comments

Comments
 (0)