Open mprinc opened 8 years ago
I don't know much of typescript, but I don't think that it would be hard to make some basic symbols. If you want, you can check lib/symbols-list-regex.coffee, tweak some JS regexes and share it as a pull request :)
Hello @mprinc ,
do you maybe have some examples / explanations of how such symbols should look like? Maybe i can help adding them to the regexes.
Regards Marco
Hi @7ute and everyone else,
I quickly checked your package and from what I understand you can easily add a new language by adding the definitions like the other languages in lib/symbols-list-regex.coffee, correct?
I've created a definition for TypeScript based on JS which works pretty well, except for methods. Somehow I can't figure the regex out, but I can't find the error.
Here's the regex:
method: /^[^\S\n]*(?:final|static|abstract|private|protected|public|[^\S\n])*[\s]([\w]+\((\w:[ ]\w[,])*\)\s?:\s?\w)[\s\n]*{/gmi
A typical method in TS would be:
public myMethod(arg1: any, arg2: number): void {}
Everything works, up to the last : void
which, when added, gets the method unrecognized.
Thanks for your help!
As soon as it works I'll create a pull request.
D
Hello @danyright ,
i've tried to simplify/shorten your regex a bit, please try this:
method: /^[ ](?:final|static|abstract|private|protected|public)[ ]([^)]+:[ ]*[^ ]+)[^\n]+{/gmi
It should work in the all situations and will support unicode characters, what was not possible before.
Regards Marco
Hey @mbuc82 ,
Thanks for your help!
However it does still not recognize a typed method properly. As soon as you add any character after the method's )
, it disappears from the list.
Cheers, D
Hey @danyright ,
could you maybe provide some sample method strings, that needs to work with this regex? In that case, i could specify it better.
Thanks in advance!
Regards Marco
Hi, Here's a complete class example:
`export default class myClass extends myAbstractClass {
private property1: string;
constructor(arg1: string, arg2: number) {
}
public myMethod1(arg1: string): void {
console.log("myMethod1");
}
public myMethod2(arg1: string): number {
return 1;
}
public set property1(arg1: string): void {
this.property1 = arg1;
}
public get property1(): string {
return this.property1;
}
}`
As mentioned, the class declaration, the constructor, the setter and getter are recognized, but not the method.
Thanks for your help. D
Hey @danyright ,
thank you for your feedback and that example. I'll follow up on this as soon as possible.
Have a nice day!
Cheers Marco
Hey there,
Actually, I just gave it another try based on your regex, and here's a solution that isn't perfect but works pretty well in my files:
/^[^\S\n]*(?:final|static|abstract|private|protected|public)[ ](.*[^)]*):[ ]*[^ ]+[^\n]+{/gmi
D
Correction:
method: /^[^\S\n]*(?:final|static|abstract|private|protected|public)*[ ](.*[^)]*):[ ]*[^ ]+[^\n]+{/gmi
Had to add a '*' after final|static|...
Please also find hereby a test file (I had to change the file's extension from .ts to .txt in order to upload it. Just change it back for your tests). Hmm actually I realise that non-method lines are also added to the symbol list...
Thanks for your help :-) D example_TS_class.txt
Hmm getting closer, but now symbols-list can't seem to figure out the method's name anymore... Otherwise the detection is correct.
method: /^[^\S\n]*(?:final|static|abstract|private|protected|public)*(?!(get|set|for|foreach|while|if))*[ ]([^ (]+\(.*\)):[ ]*[^ ]+[^\n]+{/gmi
Hey @danyright ,
thanks a lot for your testfile, it was of great help so far. I just played around a bit, to just detect the methods. If i understand your pattern correctly, all methods (with and without prefixed private, public etc.) should be matched, but you want to avoid getters and setters (since i guess, you have single patterns for them) because of the negative lookahead. Please try this one:
^[ ]*(?:final|static|abstract|private|protected|public)?[ ]*([^ (]+\(.*\)(?::[ ]+[^ ]+)?)[^\n]+
From your file, it matches the constructor and all methods, but without getters and setters (and without commented out methods) correctly. I like to use space-matches like [ ]* because they also captures tabulators and other types of whitespace (not just spaces).
Please let me know, if it works for you.
Cheers Marco
Hi Marco, Thanks for your help. Sorry, I realize that I didn't tell you that my symbols-list-regex.coffee can be found here: https://github.com/danyright/symbols-list/blob/master/lib/symbols-list-regex.coffee
We're getting closer, but with your suggestion, method/function calls are recognized as methods (for instance this.MyMethod3(); ) - see corrected version of my example file. It looks like if this can be resolved it should work alright.
D
Hello @danyright ,
sorry for my delayed response, i was off for 2 weeks. Thanks for your regex-definitions and the updated example file (which indeed should be used as a testfile in the final version).
I've tweaked the regex a bit again and now the method recognition seems to work good on my side, even with function / method calls in the code:
^[ ]*(?:final|static|abstract|private|protected|public)?[ ]*([^ (]+\(.*\)(?::[ ]+[^ ]+)?)[^\r\n;]+[\r\n]+
Please take a look and let me know, how it works for you.
link to regex101:
https://regex101.com/r/s8FaOT/1
Best regards Marco
Hey Marco, Thank you for this latest code! As far as I can see this seems to work pretty well :-) I will test it thoroughly and let you know.
Thanks for your help, D
Hey Marco,
Sorry for the delay. It was working well except for a few issues. I was away for 10 days and wanted to check these at my return, but apparently, the latest symbols-list update (or atom update, I'm not sure) broke something?
Because I now only have : Classes, Constructor, Getters & Setters
.
The rest of the methods is not recognized anymore.
Any idea why?
Regards D
hello, any news about this?
What about typescript?
Or how difficult is to describe it by ourselves?