i-c-fn-head 0.0.5
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/.vscodeignore +15 -0
- package/CHANGELOG.md +9 -0
- package/LICENSE +1 -0
- package/README.md +78 -0
- package/dist/extension.js +1 -0
- package/dist/extension.js.map +1 -0
- package/empty +1 -0
- package/eslint.config.mjs +27 -0
- package/i-c-fn-head-0.0.1.use-for-Rust.vsix +0 -0
- package/i-c-fn-head-0.0.2.vsix +0 -0
- package/i-c-fn-head-0.0.3.vsix +0 -0
- package/i-c-fn-head-0.0.5.vsix +0 -0
- package/package.json +211 -0
- package/src/basic_funx.ts +120 -0
- package/src/colorful.ts +276 -0
- package/src/extension.ts +277 -0
- package/src/faav.ts +51 -0
- package/src/fancy_f12.ts +113 -0
- package/src/fn_body_n_head.ts +504 -0
- package/src/goto_impl.ts +62 -0
- package/src/init.ts +84 -0
- package/src/quick_pick.ts +43 -0
- package/src/show_doc_symbs.ts +66 -0
- package/src/test/extension.test.ts +15 -0
- package/tsconfig.json +23 -0
- package/tst.tst +0 -0
- package/vsc-extension-quickstart.md +48 -0
- package/webpack.config.js +48 -0
|
@@ -0,0 +1,504 @@
|
|
|
1
|
+
import * as vscode from 'vscode';
|
|
2
|
+
import { writeFileSync, readFileSync, copyFileSync, closeSync, existsSync, rmSync } from "fs";
|
|
3
|
+
import { _block_head} from './faav'
|
|
4
|
+
export function _c_fn_body(doc: string | string[], uri: vscode.Uri, symbols: & vscode.SymbolInformation[]) {
|
|
5
|
+
let c_like: lang_element = new lang_element();
|
|
6
|
+
c_like.exclude_strns = /(\"[\s\S]*?\")/gm
|
|
7
|
+
let tmp_doc: string = Array.isArray(doc) ? function (arr: string[]): string {
|
|
8
|
+
let ret: string = "";
|
|
9
|
+
arr.forEach(function (strn: string) {
|
|
10
|
+
ret += strn;
|
|
11
|
+
});
|
|
12
|
+
return ret;
|
|
13
|
+
}(doc) : doc;
|
|
14
|
+
let beeped_doc = bee_ep(tmp_doc, c_like.exclude_strns, "#");
|
|
15
|
+
let lines: string[] = beeped_doc.split("\n");
|
|
16
|
+
let orig_lines: string[] = typeof doc == "string" ? doc.split("\n") : doc;
|
|
17
|
+
for (let i = 0; i < lines.length; i++) {
|
|
18
|
+
lines[i] = lines[i].trim();
|
|
19
|
+
}
|
|
20
|
+
c_like.uri = uri;
|
|
21
|
+
if (!c_like.set_lines(lines, orig_lines)) { return; }
|
|
22
|
+
c_like.exclude_comments = /(\/\/.*)|(\/\*.*(\/)?)/g;//|([\"\'\`].*[\"\'\`])/g;
|
|
23
|
+
c_like.one_line_comment = /^[/]{2}/;
|
|
24
|
+
c_like.one_line_block = /.*\{.*\}.*/;
|
|
25
|
+
c_like.open_comment = /^\/\*/;
|
|
26
|
+
c_like.close_comment = /\*\/$/;
|
|
27
|
+
const butterfly = /\}.*\{/;
|
|
28
|
+
c_like.open_block = /\{/g;//(^\{([/]{2})?(\/\*)?)|(\{([/]{2})?(\/[\*]*)?$)/;
|
|
29
|
+
c_like.close_block = /\}/g;//(^\}([/]{2})?(\/\*)?)|(\}([/]{2})?(\/[\*]*)?$)/;
|
|
30
|
+
c_like.tst_class = /^(class|struct|enum)\s|\s(class|struct|enum)\s/i;
|
|
31
|
+
c_like.block_head.mark_fn_head = /.*/;
|
|
32
|
+
for (let i = 0; i < lines.length; i++) {
|
|
33
|
+
if (c_like.one_line_comment7(i)) { continue; }
|
|
34
|
+
if (c_like.within_comment7(i)) { continue; }
|
|
35
|
+
//if (skip.run(lines[i])) { continue; }
|
|
36
|
+
if (c_like.class_entry7(i)) { continue; }
|
|
37
|
+
c_like.head7(i);
|
|
38
|
+
if (c_like.one_line_block7(i)) { continue; }
|
|
39
|
+
c_like.block_entry7(i);
|
|
40
|
+
//if (c_like.block_entry7(i)) { continue; }
|
|
41
|
+
if (c_like.close_class7(i)) { continue; }
|
|
42
|
+
c_like.update_block_state(i);
|
|
43
|
+
if (c_like.close_block7(i)) { continue; }
|
|
44
|
+
//if (yea_class) { yea_class = false; continue; }
|
|
45
|
+
}
|
|
46
|
+
symbols.push(...c_like.symbols);
|
|
47
|
+
}
|
|
48
|
+
export function bee_ep(txt0: string, rgx: RegExp, symb: string): string {
|
|
49
|
+
//const alt_nl = "/<==>/";
|
|
50
|
+
let txt = txt0//.replaceAll ("\n", alt_nl);
|
|
51
|
+
let for_beep: RegExpMatchArray | null = txt0.match(rgx);
|
|
52
|
+
if (for_beep == null) { return txt; }
|
|
53
|
+
let len = 0;
|
|
54
|
+
for_beep.forEach(function (strn: string) {
|
|
55
|
+
len = strn.length;
|
|
56
|
+
let new_strn = "";
|
|
57
|
+
for (let x = 0; x < len; x++) {
|
|
58
|
+
if (strn[x] != "\n") { new_strn += symb }
|
|
59
|
+
else { new_strn += "\n"; }
|
|
60
|
+
}
|
|
61
|
+
txt = txt.replace(strn, new_strn);
|
|
62
|
+
});
|
|
63
|
+
if (mode.dbg) {
|
|
64
|
+
rmSync("/tmp/txt");
|
|
65
|
+
writeFileSync("/tmp/txt", txt);
|
|
66
|
+
}
|
|
67
|
+
return txt;
|
|
68
|
+
}
|
|
69
|
+
export function rust_fn_body(doc: string | string[], uri: vscode.Uri, symbols: & vscode.SymbolInformation[]) {
|
|
70
|
+
const exclude_strns: RegExp = /(\"[\s\S]*?\")/gm
|
|
71
|
+
let tmp_doc: string = Array.isArray(doc) ? function (arr: string[]): string {
|
|
72
|
+
let ret: string = "";
|
|
73
|
+
arr.forEach(function (strn: string) {
|
|
74
|
+
ret += strn;
|
|
75
|
+
});
|
|
76
|
+
return ret;
|
|
77
|
+
}(doc) : doc;
|
|
78
|
+
let beeped_doc = bee_ep(tmp_doc, exclude_strns, "#");
|
|
79
|
+
let lines: string[] = beeped_doc.split("\n");
|
|
80
|
+
let orig_lines: string[] = typeof doc == "string" ? doc.split("\n") : doc;
|
|
81
|
+
for (let i = 0; i < lines.length; i++) {
|
|
82
|
+
lines[i] = lines[i].trim();
|
|
83
|
+
}
|
|
84
|
+
const exclude_comments: RegExp = /(\/\/.*)|(\/\*.*(\/)?)/g;//|([\"\'\`].*[\"\'\`])/g;
|
|
85
|
+
const one_line_comment: RegExp = /^[/]{2}/;
|
|
86
|
+
const one_line_block: RegExp = /.*\{.*\}.*/;
|
|
87
|
+
const open_comment: RegExp = /^\/\*/;
|
|
88
|
+
const close_comment: RegExp = /\*\/$/;
|
|
89
|
+
const butterfly = /\}.*\{/;
|
|
90
|
+
const open_block: RegExp = /\{/g;//(^\{([/]{2})?(\/\*)?)|(\{([/]{2})?(\/[\*]*)?$)/;
|
|
91
|
+
const close_block: RegExp = /\}/g;//(^\}([/]{2})?(\/\*)?)|(\}([/]{2})?(\/[\*]*)?$)/;
|
|
92
|
+
const tst_class: RegExp = /.*(trait|struct|impl|enum)\s/i;
|
|
93
|
+
let opened_class = false;
|
|
94
|
+
let within_comment: boolean = false;
|
|
95
|
+
let within_quotes = false
|
|
96
|
+
let start_class: number | null = null;
|
|
97
|
+
let start_block: number | null = null;
|
|
98
|
+
let block_state: number = 0;
|
|
99
|
+
let sav_block_state = 0;
|
|
100
|
+
let fn_head: string = "";
|
|
101
|
+
let search_curlies: RegExpMatchArray | null = null;
|
|
102
|
+
let ln: string;
|
|
103
|
+
let no_comments = "";
|
|
104
|
+
let block_head = new _block_head;
|
|
105
|
+
let step_back = false;
|
|
106
|
+
let step_back_was_used: boolean = false;
|
|
107
|
+
for (let i = 0; i < lines.length; i++) {
|
|
108
|
+
/* if (step_back_was_used) {
|
|
109
|
+
step_back_was_used = false;
|
|
110
|
+
step_back = false;
|
|
111
|
+
}
|
|
112
|
+
if (step_back) { i--; step_back_was_used = true; step_back = false; }*/
|
|
113
|
+
ln = lines[i];
|
|
114
|
+
if (one_line_comment.test(ln)) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (!within_comment) { within_comment = open_comment.test(lines[i].trim()); }
|
|
118
|
+
if (within_comment) {
|
|
119
|
+
if (close_comment.test(ln.trim())) {
|
|
120
|
+
within_comment = false;
|
|
121
|
+
}
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
if (start_class == null && block_state == 0) {
|
|
125
|
+
if (tst_class.test(lines[i])) {
|
|
126
|
+
if (open_block.test(lines[i])) {
|
|
127
|
+
opened_class = true;
|
|
128
|
+
}
|
|
129
|
+
start_class = i;
|
|
130
|
+
sav_block_state = block_state;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
no_comments = lines[i].replaceAll(exclude_comments, "");
|
|
135
|
+
block_head.try_set_info(no_comments, i);
|
|
136
|
+
if (start_block == null && block_state == -1) {
|
|
137
|
+
fn_head = block_head.name;
|
|
138
|
+
start_block = i;
|
|
139
|
+
}
|
|
140
|
+
//if (one_line_block.test(ln) && block_state != 0) { continue; }
|
|
141
|
+
if (one_line_block.test(ln) && block_state == 0 && block_head.name.length > 0) {
|
|
142
|
+
add_symb(
|
|
143
|
+
block_head.lnum,
|
|
144
|
+
i,
|
|
145
|
+
orig_lines[i],
|
|
146
|
+
"Function",
|
|
147
|
+
uri,
|
|
148
|
+
symbols
|
|
149
|
+
);
|
|
150
|
+
block_head.name = "";
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
//step_back = butterfly.test(lines[i]);
|
|
154
|
+
if (start_class != null && block_state == 0 && close_block.test(lines[i])) {
|
|
155
|
+
add_symb(
|
|
156
|
+
start_class,
|
|
157
|
+
i,
|
|
158
|
+
orig_lines[start_class],
|
|
159
|
+
"Class",
|
|
160
|
+
uri,
|
|
161
|
+
symbols
|
|
162
|
+
);
|
|
163
|
+
start_class = null;
|
|
164
|
+
opened_class = false;
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
block_state -= (search_curlies = no_comments.match(open_block)) != null ? search_curlies.length : 0;
|
|
168
|
+
if (!opened_class && start_class != null && sav_block_state != block_state) {
|
|
169
|
+
block_state += 1;
|
|
170
|
+
opened_class = true;
|
|
171
|
+
}
|
|
172
|
+
block_state += (search_curlies = no_comments.match(close_block)) != null ? search_curlies.length : 0;
|
|
173
|
+
// block_head.set_info(lines[i], i);
|
|
174
|
+
if (start_block != null && block_state == 0 && block_head.name.length > 0) {
|
|
175
|
+
add_symb(
|
|
176
|
+
block_head.lnum,
|
|
177
|
+
i,
|
|
178
|
+
block_head.name,
|
|
179
|
+
"Function",
|
|
180
|
+
uri,
|
|
181
|
+
symbols
|
|
182
|
+
);
|
|
183
|
+
block_head.name = "";
|
|
184
|
+
start_block = null;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
export function _rust_fn_body(doc: string | string[], uri: vscode.Uri, symbols: & vscode.SymbolInformation[]) {
|
|
189
|
+
let rust: lang_element = new lang_element();
|
|
190
|
+
rust.exclude_strns = /(\"[\s\S]*?\")/gm
|
|
191
|
+
let tmp_doc: string = Array.isArray(doc) ? function (arr: string[]): string {
|
|
192
|
+
let ret: string = "";
|
|
193
|
+
arr.forEach(function (strn: string) {
|
|
194
|
+
ret += strn;
|
|
195
|
+
});
|
|
196
|
+
return ret;
|
|
197
|
+
}(doc) : doc;
|
|
198
|
+
let beeped_doc = bee_ep(tmp_doc, rust.exclude_strns, "#");
|
|
199
|
+
let lines: string[] = beeped_doc.split("\n");
|
|
200
|
+
let orig_lines: string[] = typeof doc == "string" ? doc.split("\n") : doc;
|
|
201
|
+
for (let i = 0; i < lines.length; i++) {
|
|
202
|
+
lines[i] = lines[i].trim();
|
|
203
|
+
}
|
|
204
|
+
rust.uri = uri;
|
|
205
|
+
if (!rust.set_lines(lines, orig_lines)) { return; }
|
|
206
|
+
rust.exclude_comments = /(\/\/.*)|(\/\*.*(\/)?)/g;//|([\"\'\`].*[\"\'\`])/g;
|
|
207
|
+
rust.one_line_comment = /^[/]{2}/;
|
|
208
|
+
rust.one_line_block = /.*\{.*\}.*/;
|
|
209
|
+
rust.open_comment = /^\/\*/;
|
|
210
|
+
rust.close_comment = /\*\/$/;
|
|
211
|
+
const butterfly = /\}.*\{/;
|
|
212
|
+
rust.open_block = /\{/g;//(^\{([/]{2})?(\/\*)?)|(\{([/]{2})?(\/[\*]*)?$)/;
|
|
213
|
+
rust.close_block = /\}/g;//(^\}([/]{2})?(\/\*)?)|(\}([/]{2})?(\/[\*]*)?$)/;
|
|
214
|
+
rust.tst_class = /^(trait(\<)?|struct(\<)?|(impl(\<)?)|enum(\<)?)|\s(trait(\<)?|struct(\<)?|(impl(\<)?)|enum(\<)?)/i;
|
|
215
|
+
//let skip: skip_ln = new skip_ln();
|
|
216
|
+
//skip.arr.push(/.*!/gi);
|
|
217
|
+
for (let i = 0; i < lines.length; i++) {
|
|
218
|
+
if (rust.one_line_comment7(i)) { continue; }
|
|
219
|
+
if (rust.within_comment7(i)) { continue; }
|
|
220
|
+
//if (skip.run(lines[i])) { continue; }
|
|
221
|
+
if (rust.class_entry7(i)) { continue; }
|
|
222
|
+
rust.head7(i);
|
|
223
|
+
if (rust.one_line_block7(i)) { continue; }
|
|
224
|
+
rust.block_entry7(i);
|
|
225
|
+
if (rust.close_class7(i)) { continue; }
|
|
226
|
+
//if (yea_class) { yea_class = false; continue; }
|
|
227
|
+
rust.update_block_state(i);
|
|
228
|
+
if (rust.close_block7(i)) { continue; }
|
|
229
|
+
}
|
|
230
|
+
symbols.push(...rust.symbols);
|
|
231
|
+
}
|
|
232
|
+
export function add_symb(
|
|
233
|
+
startLine: number,
|
|
234
|
+
endLine: number,
|
|
235
|
+
objName: string,
|
|
236
|
+
objType: string,
|
|
237
|
+
uri: vscode.Uri,
|
|
238
|
+
symbols: & vscode.SymbolInformation[]) {
|
|
239
|
+
|
|
240
|
+
let set_rng = new vscode.Range(startLine, 0, endLine, 0);
|
|
241
|
+
symbols.push(new vscode.SymbolInformation(
|
|
242
|
+
objName,
|
|
243
|
+
eval("vscode.SymbolKind." + objType),
|
|
244
|
+
'',
|
|
245
|
+
new vscode.Location(uri, set_rng)));
|
|
246
|
+
}
|
|
247
|
+
export class lang_element {
|
|
248
|
+
#privateVar: number = 0;
|
|
249
|
+
exclude_strns: RegExp = /(\"[\s\S]*?\")/gm;
|
|
250
|
+
exclude_comments: RegExp = /(\/\/.*)|(\/\*.*(\/)?)/g;//|([\"\'\`].*[\"\'\`])/g;
|
|
251
|
+
one_line_comment: RegExp = /^[/]{2}/;
|
|
252
|
+
one_line_block: RegExp = /.*\{.*\}.*/;
|
|
253
|
+
open_comment: RegExp = /^\/\*/;
|
|
254
|
+
close_comment: RegExp = /(\*\/)$/;
|
|
255
|
+
butterfly = /\}.*\{/;
|
|
256
|
+
open_block: RegExp = /\{/g;//(^\{([/]{2})?(\/\*)?)|(\{([/]{2})?(\/[\*]*)?$)/;
|
|
257
|
+
close_block: RegExp = /\}/g;//(^\}([/]{2})?(\/\*)?)|(\}([/]{2})?(\/[\*]*)?$)/;
|
|
258
|
+
tst_class: RegExp = /.*(trait|struct|impl|enum)\s/i;
|
|
259
|
+
#opened_class: number | null = null;
|
|
260
|
+
#within_comment: boolean = false;
|
|
261
|
+
#within_quotes = false
|
|
262
|
+
#start_class: number | null = null;
|
|
263
|
+
#start_block: number | null = null;
|
|
264
|
+
#block_state: number = 0;
|
|
265
|
+
#sav_block_state = 0;
|
|
266
|
+
#fn_head: string = "";
|
|
267
|
+
#search_curlies: RegExpMatchArray | null = null;
|
|
268
|
+
#no_comments = "";
|
|
269
|
+
#lines: string[] = [];
|
|
270
|
+
#orig_lines: string[] = [];
|
|
271
|
+
block_head: _block_head = new _block_head;
|
|
272
|
+
rloc: number = 0;
|
|
273
|
+
uri: vscode.Uri | null = vscode.window.activeTextEditor?.document.uri ?? null;
|
|
274
|
+
symbols: vscode.SymbolInformation[] = [];
|
|
275
|
+
class_symbols: vscode.SymbolInformation[] = [];
|
|
276
|
+
set_lines(arr: string[], orig: string[]): boolean {
|
|
277
|
+
if (this.uri == null) { return false; }
|
|
278
|
+
this.#lines = arr;
|
|
279
|
+
this.#orig_lines = orig;
|
|
280
|
+
this.rloc = orig.length;
|
|
281
|
+
return true;
|
|
282
|
+
}
|
|
283
|
+
one_line_comment7(lnum: number): boolean {
|
|
284
|
+
return this.one_line_comment.test(this.#lines[lnum]);
|
|
285
|
+
}
|
|
286
|
+
within_comment7(lnum: number): boolean {
|
|
287
|
+
if (!this.#within_comment) { this.#within_comment = this.open_comment.test(this.#lines[lnum].trim()); }
|
|
288
|
+
if (this.#within_comment) {
|
|
289
|
+
if (this.close_comment.test(this.#lines[lnum].trim())) {
|
|
290
|
+
this.#within_comment = false;
|
|
291
|
+
return true;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return this.#within_comment;
|
|
295
|
+
}
|
|
296
|
+
class_entry7(i: number): boolean {
|
|
297
|
+
if (this.#start_class != null && this.#opened_class == null && this.open_block.test(this.#lines[i])) {
|
|
298
|
+
this.#opened_class = i;
|
|
299
|
+
return true;
|
|
300
|
+
}
|
|
301
|
+
if (this.#start_class == null && this.#block_state == 0) {
|
|
302
|
+
//let res = this.#lines[i].match(this.tst_class);
|
|
303
|
+
//if (res != null) {
|
|
304
|
+
if (this.tst_class.test(this.#lines[i])) {
|
|
305
|
+
if (this.#lines[i].match(this.open_block) != null) {
|
|
306
|
+
//if (this.open_block.test(this.#lines[i])) {
|
|
307
|
+
this.#opened_class = i;
|
|
308
|
+
}
|
|
309
|
+
this.#start_class = i;
|
|
310
|
+
this.#sav_block_state = this.#block_state;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return this.#start_class === i || this.#opened_class === i;
|
|
314
|
+
}
|
|
315
|
+
block_entry7(i: number): boolean {
|
|
316
|
+
// this.head7(i);
|
|
317
|
+
if (this.#start_block == null && this.#block_state == -1) {
|
|
318
|
+
this.#fn_head = this.block_head.name;
|
|
319
|
+
this.#start_block = i;
|
|
320
|
+
}
|
|
321
|
+
return this.#start_block === i
|
|
322
|
+
}
|
|
323
|
+
one_line_block7(i: number): boolean | undefined {
|
|
324
|
+
if (this.uri == null) { return undefined }
|
|
325
|
+
if (this.one_line_block.test(this.#lines[i]) && this.#block_state == 0 && this.block_head.name.length > 0) {
|
|
326
|
+
add_symb(
|
|
327
|
+
this.block_head.lnum,
|
|
328
|
+
i,
|
|
329
|
+
this.#orig_lines[i],
|
|
330
|
+
"Function",
|
|
331
|
+
this.uri,
|
|
332
|
+
this.symbols
|
|
333
|
+
);
|
|
334
|
+
this.block_head.name = "";
|
|
335
|
+
return true;
|
|
336
|
+
}
|
|
337
|
+
return false
|
|
338
|
+
}
|
|
339
|
+
head7(i: number) {
|
|
340
|
+
this.#no_comments = this.#lines[i].replaceAll(this.exclude_comments, "");
|
|
341
|
+
if (this.#block_state != 0) { return; }
|
|
342
|
+
this.block_head.try_set_info(this.#no_comments, i);
|
|
343
|
+
}
|
|
344
|
+
close_block7(i: number): boolean | undefined {
|
|
345
|
+
if (this.uri == null) { return undefined }
|
|
346
|
+
if (this.#start_block != null && this.#block_state == 0 && this.block_head.name.length > 0) {
|
|
347
|
+
add_symb(
|
|
348
|
+
this.block_head.lnum,
|
|
349
|
+
i + 1,
|
|
350
|
+
this.#orig_lines[this.block_head.lnum],
|
|
351
|
+
"Function",
|
|
352
|
+
this.uri,
|
|
353
|
+
this.symbols
|
|
354
|
+
);
|
|
355
|
+
this.block_head.name = "";
|
|
356
|
+
this.#start_block = null;
|
|
357
|
+
return true;
|
|
358
|
+
}
|
|
359
|
+
return false
|
|
360
|
+
}
|
|
361
|
+
close_class7(i: number): boolean | undefined {
|
|
362
|
+
if (this.uri == null) { return undefined }
|
|
363
|
+
if (this.#start_class != null && this.#opened_class != null && this.#block_state == 0 && this.close_block.test(this.#lines[i])) {
|
|
364
|
+
add_symb(
|
|
365
|
+
this.#start_class,
|
|
366
|
+
i + 1,
|
|
367
|
+
this.#orig_lines[this.#start_class],
|
|
368
|
+
"Class",
|
|
369
|
+
this.uri,
|
|
370
|
+
this.symbols
|
|
371
|
+
);
|
|
372
|
+
this.block_head.name = "";
|
|
373
|
+
this.#start_class = null;
|
|
374
|
+
this.#opened_class = null;
|
|
375
|
+
this.#opened_class = null
|
|
376
|
+
return true;
|
|
377
|
+
}
|
|
378
|
+
return false
|
|
379
|
+
}
|
|
380
|
+
update_block_state(i: number) {
|
|
381
|
+
// this.#no_comments = this.#lines[i].replaceAll(this.exclude_comments, "");
|
|
382
|
+
// this.block_head.try_set_info(this.#no_comments, i);
|
|
383
|
+
this.#block_state -= (this.#search_curlies = this.#no_comments.match(this.open_block)) != null ? this.#search_curlies.length : 0;
|
|
384
|
+
if (!this.#opened_class && this.#start_class != null && this.#sav_block_state != this.#block_state) {
|
|
385
|
+
this.#block_state += 1;
|
|
386
|
+
this.#opened_class = i;
|
|
387
|
+
}
|
|
388
|
+
this.#block_state += (this.#search_curlies = this.#no_comments.match(this.close_block)) != null ? this.#search_curlies.length : 0;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
export function c_fn_body(doc: string, uri: vscode.Uri, symbols: & vscode.SymbolInformation[]) {
|
|
392
|
+
let lines: string[] = doc.split("\n");
|
|
393
|
+
for (let i = 0; i < lines.length; i++) {
|
|
394
|
+
lines[i] = lines[i].trim();
|
|
395
|
+
}
|
|
396
|
+
const exclude_comments: RegExp = /(\/\/.*)|(\/\*.*(\/)?)/g;//|([\"\'\`].*[\"\'\`])/g;
|
|
397
|
+
const one_line_comment: RegExp = /^[/]{2}/;
|
|
398
|
+
const one_line_block: RegExp = /.*\{.*\}.*/;
|
|
399
|
+
const open_comment: RegExp = /^\/\*/;
|
|
400
|
+
const count_quotes: RegExp = /[\"\'\`]+/g;
|
|
401
|
+
let quote_state: number = 0;
|
|
402
|
+
let tmp_quote_state: number = 0;
|
|
403
|
+
const close_comment: RegExp = /\*\/$/;
|
|
404
|
+
const open_block: RegExp = /\{/;//(^\{([/]{2})?(\/\*)?)|(\{([/]{2})?(\/[\*]*)?$)/;
|
|
405
|
+
const close_block: RegExp = /\}/;//(^\}([/]{2})?(\/\*)?)|(\}([/]{2})?(\/[\*]*)?$)/;
|
|
406
|
+
const tst_class: RegExp = /.*(\sclass|\sstruct)\s/i;
|
|
407
|
+
let opened_class = false;
|
|
408
|
+
let within_comment: boolean = false;
|
|
409
|
+
let within_quotes = false
|
|
410
|
+
let start_class: number | null = null;
|
|
411
|
+
let start_block: number | null = null;
|
|
412
|
+
let block_state: number = 0;
|
|
413
|
+
let sav_block_state = 0;
|
|
414
|
+
let fn_head: string = "";
|
|
415
|
+
let search_curlies: RegExpExecArray | null = null;
|
|
416
|
+
let ln: string;
|
|
417
|
+
let no_comments = "";
|
|
418
|
+
let block_head = new _block_head;
|
|
419
|
+
for (let i = 0; i < lines.length; i++) {
|
|
420
|
+
ln = lines[i];
|
|
421
|
+
if (one_line_comment.test(ln)) {
|
|
422
|
+
continue;
|
|
423
|
+
}
|
|
424
|
+
if (!within_comment) { within_comment = open_comment.test(lines[i]); }
|
|
425
|
+
if (within_comment) {
|
|
426
|
+
if (close_comment.test(ln)) {
|
|
427
|
+
within_comment = false;
|
|
428
|
+
}
|
|
429
|
+
continue;
|
|
430
|
+
}
|
|
431
|
+
if (quote_state == 0) { quote_state = count_quotes.exec(lines[i])?.length ?? 0; } // not complete covering
|
|
432
|
+
if (quote_state > 0) {
|
|
433
|
+
if ((tmp_quote_state = count_quotes.exec(lines[i])?.length ?? 0) > 0) {
|
|
434
|
+
quote_state -= tmp_quote_state;
|
|
435
|
+
}
|
|
436
|
+
continue;
|
|
437
|
+
}
|
|
438
|
+
if (one_line_block.test(ln) && block_state == 0) {
|
|
439
|
+
add_symb(
|
|
440
|
+
i,
|
|
441
|
+
i,
|
|
442
|
+
ln,
|
|
443
|
+
"Function",
|
|
444
|
+
uri,
|
|
445
|
+
symbols
|
|
446
|
+
);
|
|
447
|
+
continue;
|
|
448
|
+
}
|
|
449
|
+
if (one_line_block.test(ln) && block_state != 0) { continue; }
|
|
450
|
+
if (start_class == null && block_state == 0) {
|
|
451
|
+
if (tst_class.test(lines[i])) {
|
|
452
|
+
if (open_block.test(lines[i])) { opened_class = true; }
|
|
453
|
+
start_class = i;
|
|
454
|
+
sav_block_state = block_state;
|
|
455
|
+
continue;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
if (start_class != null && block_state == 0 && close_block.test(lines[i])) {
|
|
459
|
+
add_symb(
|
|
460
|
+
start_class,
|
|
461
|
+
i,
|
|
462
|
+
lines[start_class],
|
|
463
|
+
"Class",
|
|
464
|
+
uri,
|
|
465
|
+
symbols
|
|
466
|
+
);
|
|
467
|
+
start_class = null;
|
|
468
|
+
opened_class = false;
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
471
|
+
no_comments = lines[i].replaceAll(exclude_comments, "");
|
|
472
|
+
block_state -= (search_curlies = open_block.exec(no_comments)) != null ? search_curlies.length : 0;
|
|
473
|
+
if (!opened_class && start_class != null && sav_block_state != block_state) {
|
|
474
|
+
block_state += 1;
|
|
475
|
+
opened_class = true;
|
|
476
|
+
}
|
|
477
|
+
block_state += (search_curlies = close_block.exec(no_comments)) != null ? search_curlies.length : 0;
|
|
478
|
+
block_head.set_info(lines[i], i);
|
|
479
|
+
if (start_block == null && block_state == -1) {
|
|
480
|
+
fn_head = get_c_fn_head(lines, i);
|
|
481
|
+
start_block = i;
|
|
482
|
+
}
|
|
483
|
+
if (start_block != null && block_state == 0) {
|
|
484
|
+
add_symb(
|
|
485
|
+
start_block,
|
|
486
|
+
i,
|
|
487
|
+
fn_head,
|
|
488
|
+
"Function",
|
|
489
|
+
uri,
|
|
490
|
+
symbols
|
|
491
|
+
);
|
|
492
|
+
start_block = null;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
export function get_c_fn_head(doc: string[], lnum: number): string {
|
|
497
|
+
for (let i = lnum; i > -1; i--) {
|
|
498
|
+
if (doc[i].includes("(")) { return doc[i]; }
|
|
499
|
+
}
|
|
500
|
+
return doc[0];
|
|
501
|
+
}
|
|
502
|
+
export class mode {
|
|
503
|
+
static dbg: boolean = false;
|
|
504
|
+
}
|
package/src/goto_impl.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as vscode from 'vscode';
|
|
2
|
+
import { langsName, restrict_search } from './faav'
|
|
3
|
+
import { handleExtraCMDs, pressF12, EL } from './fancy_f12';
|
|
4
|
+
import { prnt } from './basic_funx';
|
|
5
|
+
export class langDefinitionProvider implements vscode.DefinitionProvider {
|
|
6
|
+
async provideDefinition(
|
|
7
|
+
document: vscode.TextDocument,
|
|
8
|
+
position: vscode.Position,
|
|
9
|
+
token: vscode.CancellationToken
|
|
10
|
+
): Promise<vscode.Location[]> {
|
|
11
|
+
const wordRange = document.getWordRangeAtPosition(position, /[\w$@_]+/);
|
|
12
|
+
//if (!wordRange) return [];
|
|
13
|
+
let word = document.getText(wordRange);
|
|
14
|
+
const extra_locations = word != undefined && word != "" ? await handleExtraCMDs(word) : await handleExtraCMDs();
|
|
15
|
+
const results: vscode.Location[] = [];
|
|
16
|
+
prnt(extra_locations.kind);
|
|
17
|
+
if (extra_locations.kind == "extra_locations") {
|
|
18
|
+
results.push(...extra_locations.v);
|
|
19
|
+
}
|
|
20
|
+
let file_ext: vscode.GlobPattern = "**/*." + langsName().file_exts[0];
|
|
21
|
+
let uris = await vscode.workspace.findFiles(
|
|
22
|
+
//"**/*.d",
|
|
23
|
+
file_ext,
|
|
24
|
+
restrict_search.exclude_paths,
|
|
25
|
+
restrict_search.max_num_of_res);
|
|
26
|
+
if (langsName().file_exts.length > 1) {
|
|
27
|
+
for (let i = 1; i < langsName().file_exts.length; i++) {
|
|
28
|
+
file_ext = "**/*." + langsName().file_exts[i];
|
|
29
|
+
let uri = await vscode.workspace.findFiles(
|
|
30
|
+
// '**/*.{langsName.file_exts}',
|
|
31
|
+
file_ext,
|
|
32
|
+
restrict_search.exclude_paths,
|
|
33
|
+
restrict_search.max_num_of_res);
|
|
34
|
+
uris.push(...uri);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
for (const uri of uris) {
|
|
38
|
+
if (token.isCancellationRequested) break;
|
|
39
|
+
try {
|
|
40
|
+
const doc = await vscode.workspace.openTextDocument(uri);
|
|
41
|
+
const text = doc.getText();
|
|
42
|
+
let idx = text.indexOf(word);
|
|
43
|
+
// vscode.window.showInformationMessage(idx.toString());
|
|
44
|
+
while (idx !== -1) {
|
|
45
|
+
if (token.isCancellationRequested) break;
|
|
46
|
+
// crude heuristic: treat occurrences followed by '(' or ':' or '=' as possible definitions
|
|
47
|
+
const after = text.substr(idx + word.length, 3);
|
|
48
|
+
const isDef = /[\s\(=:\{]/.test(after);
|
|
49
|
+
if (isDef) {
|
|
50
|
+
const start = doc.positionAt(idx);
|
|
51
|
+
const end = doc.positionAt(idx + word.length);
|
|
52
|
+
results.push(new vscode.Location(uri, new vscode.Range(start, end)));
|
|
53
|
+
}
|
|
54
|
+
idx = text.indexOf(word, idx + 1);
|
|
55
|
+
}
|
|
56
|
+
} catch {
|
|
57
|
+
// ignore files that can't be opened
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return results;
|
|
61
|
+
}
|
|
62
|
+
}
|
package/src/init.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import * as vscode from 'vscode';
|
|
2
|
+
import { i_c_fn_head_opts, langsName } from './faav';
|
|
3
|
+
import { langDefinitionProvider } from './goto_impl';
|
|
4
|
+
import { activate0 as colors } from './colorful';
|
|
5
|
+
import { ShowDocumentSymbols } from './show_doc_symbs'
|
|
6
|
+
import { getCMD, prnt } from './basic_funx';
|
|
7
|
+
export async function uri_to_file_of_opts(): Promise <vscode.Uri[]> {
|
|
8
|
+
return vscode.workspace.findFiles(
|
|
9
|
+
'**/i_c_fn_head.opts',
|
|
10
|
+
"", /* exclude none path */
|
|
11
|
+
1 /* only one result */
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
export async function init(context: & vscode.ExtensionContext) {
|
|
15
|
+
// if (!i_c_fn_head_opts.been_set) { return; }
|
|
16
|
+
try {
|
|
17
|
+
const uri = await uri_to_file_of_opts();
|
|
18
|
+
const doc = await vscode.workspace.openTextDocument(uri[0]);
|
|
19
|
+
txt._0 = doc.getText();
|
|
20
|
+
set_lang("D", context);
|
|
21
|
+
set_lang("Rust", context);
|
|
22
|
+
set_lang("C", context);
|
|
23
|
+
set_lang("CPP", context);
|
|
24
|
+
i_c_fn_head_opts.been_set = true;
|
|
25
|
+
i_c_fn_head_opts.path_to_conf = uri[0].fsPath;
|
|
26
|
+
|
|
27
|
+
//vscode.window.showInformationMessage(msg);
|
|
28
|
+
// vscode.window.showInformationMessage(txt._0);
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
prnt("Sorry, Dear Dev.. it was failed to init i_c_fn_head (" + String(err) + " )");
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
regDefProvider(context);
|
|
35
|
+
colors(context);
|
|
36
|
+
}
|
|
37
|
+
function run_opt(key: string): RegExp {
|
|
38
|
+
return new RegExp(`\\/\\/\\s*run\\s+${key}\\s*\\/\\/`);
|
|
39
|
+
}
|
|
40
|
+
function set_lang(name: string, context?: vscode.ExtensionContext) {
|
|
41
|
+
//vscode.window.showInformationMessage(txt._0);
|
|
42
|
+
if (run_opt(name).test(txt._0) && name == "D") {
|
|
43
|
+
i_c_fn_head_opts.provide_lang_D = true;
|
|
44
|
+
context?.subscriptions.push(
|
|
45
|
+
vscode.languages.registerDocumentSymbolProvider({ language: 'D' }, new ShowDocumentSymbols())
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
if (run_opt(name).test(txt._0) && name == "CPP") {
|
|
49
|
+
i_c_fn_head_opts.provide_lang_CPP = true;
|
|
50
|
+
context?.subscriptions.push(
|
|
51
|
+
vscode.languages.registerDocumentSymbolProvider({ language: 'cpp' }, new ShowDocumentSymbols())
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
if (run_opt(name).test(txt._0) && name == "C") {
|
|
55
|
+
i_c_fn_head_opts.provide_lang_C = true;
|
|
56
|
+
context?.subscriptions.push(
|
|
57
|
+
vscode.languages.registerDocumentSymbolProvider({ language: 'c' }, new ShowDocumentSymbols())
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
if (run_opt(name).test(txt._0) && name == "Rust") {
|
|
61
|
+
i_c_fn_head_opts.provide_lang_Rust = true;
|
|
62
|
+
context?.subscriptions.push(
|
|
63
|
+
vscode.languages.registerDocumentSymbolProvider({ language: 'rust' }, new ShowDocumentSymbols())
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
class txt {
|
|
68
|
+
static _0: string = "";
|
|
69
|
+
}
|
|
70
|
+
export function regDefProvider(context: & vscode.ExtensionContext) {
|
|
71
|
+
const selector: vscode.DocumentSelector = mkDocSel ();
|
|
72
|
+
context.subscriptions.push(
|
|
73
|
+
vscode.languages.registerDefinitionProvider(selector, new langDefinitionProvider())
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
function mkDocSel(): vscode.DocumentSelector {
|
|
77
|
+
let sel = [] as (vscode.DocumentFilter | string)[];
|
|
78
|
+
let sel_strn: string = "";
|
|
79
|
+
if (i_c_fn_head_opts.provide_lang_C) { sel.push({ scheme: 'file', language: 'c' }); }
|
|
80
|
+
if (i_c_fn_head_opts.provide_lang_Rust) { sel.push({ scheme: 'file', language: 'rust' }); }
|
|
81
|
+
if (i_c_fn_head_opts.provide_lang_CPP) { sel.push({ scheme: 'file', language: 'cpp' }); }
|
|
82
|
+
if (i_c_fn_head_opts.provide_lang_D) { sel.push({ scheme: 'file', language: 'D' }); }
|
|
83
|
+
return sel
|
|
84
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as vscode from 'vscode';
|
|
2
|
+
export function menu() {
|
|
3
|
+
|
|
4
|
+
async function showQuickPickExample() {
|
|
5
|
+
const items: vscode.QuickPickItem[] = [
|
|
6
|
+
{ label: '$(file-text) Open file', description: 'Open a file from workspace', detail: 'Opens the file picker' },
|
|
7
|
+
{ label: '$(gear) Settings', description: 'Open settings', detail: 'Show configuration' },
|
|
8
|
+
{ label: '$(repo) Clone repo', description: 'Clone a repository', detail: 'Clone from URL' },
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
// Single-select QuickPick (simple)
|
|
12
|
+
const single = await vscode.window.showQuickPick(items, {
|
|
13
|
+
placeHolder: 'Choose an action',
|
|
14
|
+
matchOnDescription: true,
|
|
15
|
+
matchOnDetail: true,
|
|
16
|
+
canPickMany: false,
|
|
17
|
+
});
|
|
18
|
+
if (single) {
|
|
19
|
+
vscode.window.showInformationMessage(`Selected: ${single.label}`);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Multi-select QuickPick (programmatic QuickPick for more control)
|
|
23
|
+
const qp = vscode.window.createQuickPick<vscode.QuickPickItem>();
|
|
24
|
+
qp.items = items;
|
|
25
|
+
qp.canSelectMany = true;
|
|
26
|
+
qp.matchOnDescription = true;
|
|
27
|
+
qp.matchOnDetail = true;
|
|
28
|
+
qp.placeholder = 'Select one or more actions';
|
|
29
|
+
qp.ignoreFocusOut = true;
|
|
30
|
+
|
|
31
|
+
qp.onDidAccept(() => {
|
|
32
|
+
const selected = qp.selectedItems;
|
|
33
|
+
if (selected.length) {
|
|
34
|
+
vscode.window.showInformationMessage(`Selected: ${selected.map(s => s.label).join(', ')}`);
|
|
35
|
+
}
|
|
36
|
+
qp.hide();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
qp.onDidHide(() => qp.dispose());
|
|
40
|
+
qp.show();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
}
|