generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpsa.ts
98 lines (88 loc) · 2.43 KB
/
psa.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import * as fs from 'fs';
import * as process from 'process';
import { generateMyAwesomeTemplate } from './templates/tsClass.template'
const completions = [];
const notifications: any[] = [];
const type = process.env.PSA_TYPE;
if (type === 'Info') {
console.log(JSON.stringify({
supported_languages: ["TypeScript"],
goto_element_filter: ["JS:STRING_LITERAL"],
templates: [
{
type: "single_file",
name: "my_awesome_template",
title: "My Awesome Template",
path_regex: "^\/src\/[^\/]+\/$",
fields: [
{
name: "className",
title: "Class Name",
type: "Text",
options: []
},
{
name: "abstract",
title: "Is Abstract",
type: "Checkbox",
options: []
},
{
name: "comment",
title: "Comment",
type: "Select",
options: ["OptionA", "OptionB", "OptionC"]
},
{
name: "richText",
title: "Rich Text with Completion",
type: "RichText",
options: ['Completion A', 'Completion B', 'Completion C']
},
{
name: "collection",
title: "Collection of text fields",
type: "Collection",
options: []
}
]
}
]
}));
process.exit(0)
}
const contextString = fs.readFileSync(process.env.PSA_CONTEXT as string).toString();
const context = JSON.parse(contextString);
if (type === 'GenerateFileFromTemplate') {
console.log(JSON.stringify({
'file_name': context['formFields']['className'] + '.class.ts',
'content': generateMyAwesomeTemplate(context['formFields']),
'form_fields': {
richText: {
options: ['Completion A', 'Completion B', 'Completion C']
}
}
}));
process.exit(0)
}
const language = process.env.PSA_LANGUAGE;
if (language === 'TypeScript') {
if (type === 'Completion') {
if (context['elementType'] === 'JS:STRING_LITERAL') {
completions.push({
text: 'My Completion',
bold: false,
priority: 123,
type: 'MyType',
});
}
}
if (type === 'GoTo') {
if (context['elementType'] === 'JS:STRING_LITERAL') {
completions.push({
link: '/examples/ts/psa.ts:0:0',
});
}
}
}
console.log(JSON.stringify({completions, notifications}));