I would like to convert the first uppercased letter in a VSCode Dart snippet to a lowercased one.
Example:
MyClassIWroteInMySnippet -> myClassIWroteInMySnippet
During my search, I found this which demonstrate how to convert a camelCase String to UPPER_CASED_STRING but I don't achieve to pick the first character (in uppercase) and then transform it to lowercase...
Any help would be very appreciated !
Thanks :)
EDIT:
Here is my current snippet
"Mock a service using Mockito": {
"prefix": "testMockitoService",
"body": [
"class _${1}Mock extends Mock implements ${1} {}",
"",
"final ${1} = _${1}Mock();", // Here I want to "${1}" be camelCased when I finish to write my class
],
"description": "Mock a service using Mockito"
},
So If I insert my snippet, and write "MyClass", I want to display in my code
class _MyClassMock extends Mock implements MyClass {}
final myClass = _MyClassMock();
After your clarification in the question, try this:
"Mock a service using Mockito": {
"prefix": "testMockitoService",
"body": [
"class _${1}Mock extends Mock implements ${1} {}",
"",
"final ${1/(.)(.*)/${1:/downcase}$2/} = _${1}Mock();",
],
"description": "Mock a service using Mockito"
},
${1/(.)(.*)/${1:/downcase}$2/} puts the first letter into capture group 1 and the rest into capture group 2. Then that first letter is down-cased and the second group appended to that.
Related
I am attempting to use the frida swift bridge functionality built into Frida to hook the constructor of a Swift class. I am running my code with the command:
frida --no-pause -U -l swift_cooperia.js -f com.example.myapp
with the contents of swift_cooperia.js being:
Swift.Interceptor.attach(Swift.classes.hooked_class.init, {
onEnter: function (args) {
console.log("obj instantiated");
}
});
I am trying to use the Swift.Interceptor.Attach function, but I'm not quite sure what to use for the first argument (the function I'm trying to hook). In all of the examples I've seen of the interceptor, I should be using something like Swift.classes.hooked_class.init (what I'm doing right now in my swift_cooperia.js file) for my first argument, but this throws the following error:
Error: missing argument
at T (frida/node_modules/frida-swift-bridge/dist/lib/macho.js:144)
at F (frida/node_modules/frida-swift-bridge/dist/lib/macho.js:155)
at <anonymous> (frida/node_modules/frida-swift-bridge/dist/lib/interceptor.js:23)
at <eval> (/swift_cooperia.js:5)
I have also tried using Swift.classes.hooked_class.init() but this errors with:
TypeError: not a function
at <eval> (/swift_cooperia.js:1)
I have also tried Swift.classes.hooked_class.init.implementation which errors with:
TypeError: cannot read property 'implementation' of undefined
at <eval> (/swift_cooperia.js:1)
When I look at the $methods properties of the class using Swift.class.hooked_class during a frida session (not in this script execution), I get the following:
"$methods": [
{
"address": "0x1008e37b8",
"type": "Method"
},
{
"address": "0x1008e3b90",
"type": "Method"
},
{
"address": "0x1008e5998",
"type": "Method"
},
{
"address": "0x1008e5e30",
"type": "Method"
},
{
"address": "0x1008e5e50",
"type": "Method"
}
]
Which shows no easy constructor or init method. One of these might be the init method, but I have no clue how to sniff out which one is, if any, and after that how to use it as the first parameter for the Swift Interceptor.
I'm very new to using Frida, so any help would be appreciated.
Frida Swift bridge author here. The method you're trying to hook isn't symbolicated which is why the bridge can't intercept it, from the docs:
A major caveat is that the function at target has to have a Swift symbol or either we bail. The symbol is required for the parsing of argument and return types.
The API should be returning a more useful error though, so I'll fix that.
(Also feel free to open an issue on GitHub as it'll get much better coverage there, I came across this by chance!)
I am continually typing string instead of String in dart. it's very annoying, and it seems some others are bothered by it too: https://github.com/dart-lang/sdk/issues/1410
I'm hoping to have a solution of it being autocorrected in VS code or to have a stable way of simply using "string".
Still think that the best solution is "get used to it" but there are at least one plugin for VS Code which can auto-correct you: https://marketplace.visualstudio.com/items?itemName=sygene.auto-correct
I made the following configuration which seems to work (after restarting VS Code):
{
"auto-correct.dictionary": [
{
"languages": [
"dart"
],
"words": {
"string": "String"
}
}
]
}
The solution is not perfect since the plugin does not understand the context of your code so it will auto-correct every time you write "string" and replace it with "String". So it can be really annoying if you write code like String string = "". You can then manually scroll back and fix the auto-correction. But yeah, that is a little annoying if you often use string as a variable name.
I tried out https://marketplace.visualstudio.com/items?itemName=sygene.auto-correct, but it wasn't working half the time when I would open up VS Code and try it.
For now, I have installed https://marketplace.visualstudio.com/items?itemName=DomiR.regreplace and using:
"regreplace.commands": [
{
"on-save": false,
"name": "string to String",
"match": "\\.dart?$",
"regexp": "string ",
"global": true,
"replace": "String "
}
]
With the autosave feature on for VS Code, this is the closest I could achieve for an automatic solution.
while this is a generic solution above, for this actual data type name, Dart has typedef ability now. Typedefs are alias for functions which are object. So, Typedefs are object with an alias.
here's the documentation: https://dart.dev/guides/language/language-tour#typedefs
below should work to alias String as string:
typedef string = String;
I'm trying to create set of rules in Bazel for a tool my company works with.
Is there any way to create a rule attribute which is a dict of lists of labels, where the key for the dict is a string?
For example, a target should look like this:
some_rule (
name = "target_name",
files = {
"foo" : [
"file1",
"file2",
],
"bar" : [
"file3",
"file4",
"file5"
]
}
)
Note: I know i could distinguish between foo and bar by having them in separate targets and then having a third one to depend on both, but would rather that they all be in the same target.
Short answer, no. This feature request is tracked here.
I am attempting to create a relationship in my Neo4j database with a GraphQL mutation. I have a number of other mutations already working except this one causing problems. It looks like this:
mutation(
$id: String!,
$recipe: String!,
$date: String!
) {
CreateUserRecipeRelation(id:$id, recipe:$recipe, date:$date) {
id
recipe {
name
}
}
}
I am passing in the following set of parameters:
{"id": "google-oauth2|yyyyremovedauthstuffyyyy", "recipe": "baked spaghetti", "date": "10/10/2018"}
But the GraphQL playground throws the following error:
"Variable \"$id\" of required type \"String!\" was not provided."
In my schema.graphql file I have the following defined:
CreateUserRecipeRelation (
id: String
recipe: String
date: String
): User #cypher(statement:
"MATCH (r:Recipe{name:$recipe}), (u:User{id:$id}) CREATE (r)-[c:Created_By{date:$date}]->(u) RETURN r,c,u")
And if I run that cypher query directly in Neo4j it works just fine. In this same project I have 5 or 6 other relationship-creating mutations currently working but this one is giving me pause.
UPDATE:
This is a mutation I currently have that is working, so you can see the similarity in structure:
CreateIngredientRelation (
name: String
recipe: String
quantity: String
): Ingredient #cypher(statement:
"MATCH (r:Recipe{name:$recipe}), (i:Ingredient{name:$name}) CREATE (r)-[c:Contains{quantity:$quantity}]->(i) RETURN r,c,i")
This one works great and creates tons of relationships with the quantity attached to them. This is why I am puzzled. If they both didn't work it would be easier to try and come up with a solution I think.
#BehemothDan, how are you calling this mutation? Are you using react-apollo? If yes, Let me provide you an example of how you should be handling this.
For example, if you have a form to create this UserRecipeRelation. You have your Mutation component from react-apollo. On this Mutation you have on renderProps CreateUserRecipeRelation, that you could pass to a function on onSubmit. In this function you pass your variables:
UserRecipeRelation({ variables: { id: 'your id', recipe: 'bla bla', date: '12/12/18' } });
Hope it helps! :)
I have a problem with cross-referencing terminals that are only locally unique (in their block/scope), but not globally. I found tutorials that describe, how I can use fully qualified names or package declarations, but my case is syntactically a little bit different from the example and I cannot change the DSL to support something like explicit fully qualified names or package declarations.
In my DSL I have two types of structured JSON resources:
The instance that contains my data.
A meta model, containing type information etc. for my data.
I can easily parse those two, and get an EMF model with the following Java snippet:
new MyDSLStandaloneSetup().createInjectorAndDoEMFRegistration();
ResourceSet rs = new ResourceSetImpl();
rs.getResource(URI.createPlatformResourceURI("/Foo/meta.json", true), true);
Resource instanceResource= rs.getResource(URI.createPlatformResourceURI("/Bar/instance.json", true), true);
EObject eobject = instanceResource.getContents().get(0);
Simplyfied example:
meta.json
{
"toplevel_1": {
"sublevels": {
"sublevel_1": {
"type": "int"
},
"sublevel_2": {
"type": "long"
}
}
},
"toplevel_2": {
"sublevels": {
"sublevel_1": {
"type": "float"
},
"sublevel_2": {
"type": "double"
}
}
}
}
instance.json
{
"toplevel_1": {
"sublevel_1": "1",
"sublevel_2": "2"
},
"toplevel_2": {
"sublevel_1": "3",
"sublevel_2": "4"
}
}
From this I want to infer that:
toplevel_1:sublevel_1 has type int and value 1
toplevel_1:sublevel_2 has type long and value 2
toplevel_2:sublevel_1 has type float and value 3
toplevel_2:sublevel_2 has type double and value 4
I was able to cross-reference the unique toplevel-elements and iterate over all sublevels until I found the ones that I was looking for, but for my use case that is quite inefficient and complicated. Also, I don't get the generated editor to link between the sublevels this way.
I played around with linking and scoping, but I'm unsure as to what I really need, and if I have to extend the providers-classes AbstractDeclarativeScopeProvider and/or DefaultDeclarativeQualifiedNameProvider.
What's the best way to go?
See also:
Xtext cross reference using custom terminal rule
http://www.eclipse.org/Xtext/documentation.html#scoping
http://www.eclipse.org/Xtext/documentation.html#linking
After some trial and error I solved my problem with a ScopeProvider.
The main issue was that I didn't really understand what a scope is in Xtext-terms, and what I have to provide it to.
Looking at the signature from the documentation:
IScope scope_<RefDeclaringEClass>_<Reference>(<ContextType> ctx, EReference ref)
In my example language:
RefDeclaringEClass would refer to the Sublevel from instance.json,
Reference to the cross-reference to the Sublevel from meta.json, and
ContextType would match the RefDeclaringEClass.
Using the eContainer of ctx I can get the Toplevel from instance.json.
This Toplevel already has a cross-reference to the matching Toplevel from meta.json, which I can use to get the Sublevels from meta.json. This collection of Sublevels is basically the scope within which the current Sublevel should be unique.
To get the IScope I used Scopes#scopeFor(Iterable).
I didn't post any code here because the actual grammar is bigger/different, and therefore doesn't really help the explanation.