VSCode color theme methods calls - visual-studio-code

I'm trying to change method calls color in VSCode. I know I can change the Function scope color as follewed:
{
"name": "Function call",
"scope": "meta.function-call.object",
"settings": {
"foreground": "#e26f60"
}
}
Is there an equivalent for method calls. I would like to only highlight the foo_method() in the following code:
class Foo():
def foo_method(self):
print("Called Foo from class")
foo_object = Foo()
foo_object.foo_method()

The scope of the method call to foo_method is:
meta.function-call.generic.python
meta.function-call.python
meta.member.access.python
source.python
So to just target methods, try using a more specific scope selector in your theme. For example, meta.member.access meta.function-call will select all meta.function-call scopes under meta.member.access scopes:
{
"name": "Function call",
"scope": "meta.member.access meta.function-call",
"settings": {
"foreground": "#e26f60"
}
}
(you may need to further tweak the scope selector based on your specific needs)

Related

Do all solidity functions in an imported interface get compiled into the smart contract bytecode, even if they aren't used?

I'm trying to keep a contract as small as possible. I know that if you import a solidity library, only the functions actually utilized in that library get compiled into the contract, increasing it's size.
I'm not sure if that goes for importing interfaces.
For example:
interface IDoThings {
function transfer(address from, address to, uint256 amount) external;
function setValue(uint256 newVal) external;
function owner() external view returns (address);
}
contract DoingThings {
function getOwnerOfAnotherContract(address target) public view returns (address) {
return IDoThings(target).owner();
}
}
When this get's compiled down, will the function selectors for transfer & setValue also be included in the contract's bytecode, or will only the owner function selector be included?
interface is like typescript types, they are used in compilation time and in the javascript bundle you do not see any type definitions.
If you compile your code at https://remix.ethereum.org/
this is what you will get
[
{
"inputs": [
{
"internalType": "address",
"name": "target",
"type": "address"
}
],
"name": "getOwnerOfAnotherContract",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
}
]
there is nothing about interface or its function signatures
They do not.
Solidity v0.8 without bytecode optimizer:
with the unused interface declarations: 554 bytes
without: 554 bytes

VSCode - Make custom user snippets overwriting default suggestion

To match my company's coding standards, I'm making custom snippets like so:
// php.json
{
"If block": {
"prefix": ["if"],
"body": ["if ( ${1:condition} )", "{", "\t$0", "}"],
"description": "if block",
},
// ...
}
Then, when I type if + Tab, I have two suggestions:
I'm forced to press enter to actually select the first one, which is my custom made snippet ; the second being PHP's default snippet.
Is there a way to actually ignore PHP's default snippets in case I have the exact same prefix?

Golang VS Code Snippet: Mimic "built-in" `variable.print!` snippet

Context: The Golang VS Code extension has built-in snippets/macros for creating a fmt.PrintX statement from a given variable:
Note how the variable name is filled in for me.
I frequently write methods, and the Golang extension's meth snippet, in my opinion, is slow, since there are 5 (!) tab stops:
So far, I've written a snippet that mimics the meth snippet:
"Struct Method": {
"prefix": ".meth",
"body": [
"func ($1 $2) $3($4) $5 {",
"\t$6",
"}"
],
"description": "some description"
}
And I would like this snippet to mimic the print! macro/snippet, where it fills in the variable name; for the method snippet, instead of filling a variable, it would automatically fill in the method receiver ($1 and $2) with the first letter of the struct name, and the full struct name in the second.
So, if I have the following struct:
type SomeStruct struct {}
and type:
SomeStruct.meth
then activate the snippet, it should output:
func (s SomeStruct) .(.) . {
.
}
where each . is a tab stop.
Is this sort of snippet possible? If so, how can I write it so it does this?
One thing you can do is to make a snippet in a keybinding that can parse the current line. Put this into your keybindings.json:
{
"key": "alt+w",
"command": "editor.action.insertSnippet",
"args": {
"snippet": "\n\nfunc (${TM_CURRENT_LINE/\\s*type\\s*(.)(.*)\\s* struct\\s*{}/${1:/downcase} $1$2)/} $1($2) $3 {\n\t$4\n}"
},
// "when": "langId == golang"
}
The workflow is different than what you mentioned but is also easier - you don't have to type SomeStruct.meth. Just trigger the keybinding at the end of the type SomeStruct struct {} line as in the demo.
If you want to be anywhere in the document and trigger a snippet completion, then the HyperSnips extension may be the way to go.

Add tasks to tasks.json for users of a vscode extension

I am writing a vscode extention for a specification language. I would like to provide the users of the plugin with a specific task. The task could be made available using tasks.json.
Is there a way to add tasks to the tasks.json of a user that uses that extension?
The documentation didn't help me here either. When you provide tasks through the extension there is the TaskProvider API. The example doesn't go into much detail about how these tasks are created though, compared to the classical tasks.json approach.
In your package.json you need to define the types of tasks this extension contributes. This has nothing to do with the type in tasks.json. It's rather a freeform string. If you need custom problem matchers you also need to define theme here.
"contributes": {
"taskDefinitions": [
{
"type": "mytask"
}
],
"problemMatchers": [
{
"name": "mywarnings",
"base": "$gcc",
"fileLocation": [
"relative",
"/"
]
}
]
},
In extension.ts you need to provide the tasks. Say we have an array of vscode.Task in tasks you can do:
vscode.tasks.registerTaskProvider('mytask', {
provideTasks: () => {
return tasks;
},
resolveTask(_task: vscode.Task): vscode.Task | undefined {
// as far as I can see from the documentation this just needs to return undefined.
return undefined;
}
});
If you want to create a shell task you need the following:
new vscode.Task (
{type: 'shell'}, // this is the same type as in tasks.json
ws, // The workspace folder
'name', // how you name the task
'MyTask', // Shows up as MyTask: name
new vscode.ShellExecution(command),
["mywarnings"] // list of problem matchers (can use $gcc or other pre-built matchers, or the ones defined in package.json)
);
I hope this helps. The bigges issue I see is the overloading of various names (like type), and that the format in tasks.json is completely different to the way tasks are built with TaskProvider API.

What is the difference between sap.ui.core.routing.Router.navTo() and sap.m.routing.Targets.display()?

Let’s say we I have one route and one target:
"routes": [{
"pattern": "modify",
"name": "modify",
"target": [
"master",
"modify"
]
}],
"targets": {
"modify": {
"viewName": "Modify",
"viewId": "modify",
"viewLevel": 2
}
}
So I can access the route by this.getRouter().navTo("modify"), meanwhile I can access the target by this.getRouter().getTargets().display("modify"). Both API can carry parameter by the second argument. It seems to achieve the same effect.
I can access target without defining a route for it. So I did not quite understand why I need a route?
Ref: sap.m.routing.Targets and
sap.ui.core.routing.Router
display displays the target view without changing the hash value in contrast to navTo.
You can find more information in the tutorial "Display a Target Without Changing the Hash".
Both API can carry parameter by the second argument. It seems to achieve the same effect.
The data in display method is for the display event handler. When the event is fired, the handler carries the data we passed earlier.
The parameter map we can pass to navTo is mandatory if the pattern actually awaits a parameter, e.g. if we've defined the pattern like this initially: "pattern": "modify/{id}". Check out "Navigate to Routes with Mandatory Parameters".
Just complement Boghyon's answer:
Route pattern is defined in Router, and hash is set in Router. That's the main difference.BTW, UI5 uses crossroads and hasher to help implementing router.
navTo() in sap.m.routing.Router is borrowed from sap.ui.core.routing.Router
display() in sap.m.routing.Targets is borrowed from sap.ui.core.routing.Targets
in _routeMatched of Route, oRouter._oTargets._display is called. So _display is called in both Router and Targets.
The parameter they use are different.navTo use Route name, and display use Target name. Sometimes they are defined the same.
onToPage2 : function () {
// this.getOwnerComponent().getRouter().navTo("pageRoute2");
this.getOwnerComponent().getRouter().getTargets().display("pageTarget2");
},
onToPage1 : function () {
this.getOwnerComponent().getRouter().navTo("pageRoute1");
// this.getOwnerComponent().getRouter().getTargets().display("pageTarget1");
}