in vscode default formatter for JavaScript, how to avoid space before brace? - visual-studio-code

here is my code
function foo(){
}
after passing it through the default formatter(alt+shift+f) I get:
function foo() {
}
(note the added space in the first line)
My question is: how do I set up the formatter so it does not add the space?

Related

Have breakpoint print the name of the calling function

I'd like to have my breakpoint print the name of the test it's being called from in the console. Is this possible?
Relatedly, can I have a breakpoint condition be dependent on which function got us to the breakpoint?
While not exactly the "function" name you can use lldb's command to print the call stack as far back as you want.
In Xcode create a breakpoint with a "Debugger Command" action of bt 2 (the 2 limits the depth of the call stack to print). If you don't want the breakpoint to actually stop processing also tick the option "Automatically continue…" checkbox at the bottom.
When the breakpoint is hit you'll see output similar to this in the "Debugger Output" pane in the "Debug Area" at the bottom of your Xcode window.
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
* frame #0: 0x0000000104982fa8 SharingTest`DataManager.loadFromDisk(self=0x000060800005e3f0) at DataManager.swift:66
frame #1: 0x0000000104998dbe SharingTest`AppDelegate.applicationDidBecomeActive(application=0x00007fe6b9600220, self=0x000060400005b2d0) at AppDelegate.swift:56
If you add a string parameter with a default value of #function, it gets filled in with the calling function name:
func bar(_ funcName:String = #function) {
print("called from function", funcName)
}
func foo() {
bar()
}
foo()
That prints "called from function foo()"
The only problem with that is if you pass it an actual string value, that overrides the default value so:
func foo() {
bar("snort")
}
That prints "called from function snort"

Prevent VS Code from changing indentation on Enter

Let's assume I have a JavaScript file with the following content and the cursor placed at the pipe symbol (|):
class ItemCtrl {
getPropertiesByItemId(id) {
return this.fetchItem(id)
.then(item => {
return this.getPropertiesOfItem(item);
});
}|
}
If I now hit enter, the code changes in the following way:
class ItemCtrl {
getPropertiesByItemId(id) {
return this.fetchItem(id)
.then(item => {
return this.getPropertiesOfItem(item);
});
}
|
}
It wrongly aligns the closing curly brace with the return statement, when it should be aligned with the method definition. I know that the formatting inside the function is not the best but I still would rather disable that feature to prevent weird things like that from happening.
I already set editor.autoIndent to false but it still keeps happening. Is there any other way, how I can turn this feature off entirely? (or make it work in a smarter way)
In VS Code 1.17, this bug caused "editor.autoIndent": false to not work
This should be fixed in VS Code 1.18

Eclipse CDT Code Formatter

Is there a way to force the Eclipse CDT Codestyle Formatter to ignore the blank lines?
As an example we would like to have 2 blank lines between functions in C like the pep8 for python uses
// 2 lines between function
void foo()
{
}
void bar()
{
}
But the Formatter removes this blank lines to 1 line for each. So how can i change that behavior.
// 1 lines between function
void foo()
{
}
void bar()
{
}
Thanks for your help

Set selection to a string in codemirror

I'm trying to set a text selection in CodeMirror based on a predefined string, similar to a find without prompt (i.e. http://perso.jojaba.fr/codemirror-test/codemirror/demo/search-element.html) except not marking the value, but actually putting a selection on the range (which might be multi line, depending on the predefined string). I can't seem to figure out how to set a selection in this way. Any idea.
well, as it turns out the findNext() offered by searchwithoutdialog.js actually does what I need. effectively it's:
instance.on("change", function (cm, change) {
// other code snipped! //
var str = "my replacement";
var token = cm.getTokenAt(change.from, false);
cm.replaceRange(str, { ch: token.start, line: line }, { ch: token.end, line: line });
CodeMirror.commands.findNext(cm, str);
}

Eclipse custom formatting

I'm trying to create a JAVA code formatter such that it doesn't wrap any lines. BUT for any lines in my code that I have manually wrapped I want the formatter to respect them and not format them in to one line.
For example:
public Class {
public Class(String a,
String b,
String c,
String d) {
// The constructor arguments should stay as they are
}
public void aMethod() {
// This statement should not be wrapped
get().doSomething().getAnohterMethodThatHasAReeeeeeeaalllyyLongName();
}
}
I have made the line width 9999 (the max), and I have turned off line wrapping for everything. What have I missed?
Thanks.
I opened the preference page for
"Java - Code Style - Formatter"
and activated "never join lines"
and selected "Do not wrap" in the combo box "line wrapping policy"
After this change i was able to write code, which was not wrapped.