How to tell eclipse to not format parts of a codefile (pressing Strg + Shift + F) - eclipse

I really love the autofromat feature. I makes your code more readable and in case of JavaScript tells you, when there are synatcs errors (missing brackets etc.).
However sometimes the formatting makes the code harder to read. e.g. when it puts a long array inizalisation into a single line. In that case I don't want him to format it, but rather leave it ofer multiple lines.
E.g.
define([
'jquery',
'aloha',
'aloha/plugin',
'ui/ui',
'ui/scopes',
'ui/button',
'ui/toggleButton',
'ui/port-helper-attribute-field',
'ui/text'
// 'css!youtube/css/youtube.css'
],
function(
$,
Aloha,
Plugin,
Ui,
Scopes,
Button,
ToggleButton,
AttributeField)
{
this array should stay like this and don't become this:
define(['jquery', 'aloha', 'aloha/plugin', 'ui/ui', 'ui/scopes', 'ui/button', 'ui/toggleButton', 'ui/port-helper-attribute-field', 'ui/text' ], function($, Aloha, Plugin, Ui, Scopes, Button, ToggleButton, AttributeField) {
Is there a special tag, to tell eclipse not to format the code?

OK, it took me some time to find the right setting so I will post a toturial here.
Go to Window Preferences and Search the Formatter you are using. In my case it was under 'Aptana Studia' -> 'Formatter'. (Depending on your Package this differs, e.g. the Java Formatter is under 'Java' -> 'Code Style' -> 'Formater').
Noww create a new Build profile since you can't override the old one.
Now enable the Formatter tags.
Now you can use the
- #formatter:on
- #formatter:off
tags to disable code formatting.
Example:
this code:
function hello() { return 'hello';
}
//#formatter:off
/*
|\ _,,,---,,_
/,`.-'`' -. ;-;;,_
|,4- ) )-,_..;\ ( `'-'
'---''(_/--' `-'\_) fL
*/
//#formatter:on
function
world() {
return 'world';
}
Will get formatted to like this
function hello() {
return 'hello';
}
//#formatter:off
/*
|\ _,,,---,,_
/,`.-'`' -. ;-;;,_
|,4- ) )-,_..;\ ( `'-'
'---''(_/--' `-'\_) fL
*/
//#formatter:on
function world() {
return 'world';
}
Note how the function definition is formatted correct, while the ascii art isn't
Credits:
Katja Christiansen for his comment
https://stackoverflow.com/a/3353765/639035 : for a similar answer

Try to make an empty comment after each line:
define([ //
'jquery', //
'aloha', //
'aloha/plugin', //
'ui/ui', //
'ui/scopes', //
'ui/button', //
'ui/toggleButton', //
...
Not nice, but I think it will work.

Related

Neovim - How to filter out text snippets from nvim-lspconfig + nvim-cmp

I'm using NeoVim with autocomplete using nvim-lspconfig and nvim-cmp. I would like to know if there's a way of filtering out text feeds from the autocompletion menu, so that they don't appear in the contextual menu:
In your setup you can exclude any kind if suggestions thanks to this merged PR.
What is happening is the function "entry_filter" is getting called whenever a suggestion for nvim_lsp is being made. in it we return false if the entry is of the kind "text".
local cmp = require "cmp"
cmp.setup {
...
sources = cmp.config.sources({
-- Dont suggest Text from nvm_lsp
{ name = "nvim_lsp",
entry_filter = function(entry, ctx)
return require("cmp").lsp.CompletionItemKind.Text ~= entry:get_kind()
end },
})
}
Check out nvim-cmp sources list and remove whatever source you don't want to use. Text is quite probably coming from buffer:
cmp.setup({
...
sources = cmp.config.sources({
{ name = 'buffer' }, -- <- remove
{ name = 'nvim_lsp' },
...
})
})

How to select symbols onWorkspaceSymbol

I am developing an extension for visual studio code using language server protocol, and I am including the support for "Go to symbol in workspace". My problem is that I don't know how to select the matches...
Actually I use this function I wrote:
function IsInside(word1, word2)
{
var ret = "";
var i1 = 0;
var lenMatch =0, maxLenMatch = 0, minLenMatch = word1.length;
for(var i2=0;i2<word2.length;i2++)
{
if(word1[i1]==word2[i2])
{
lenMatch++;
if(lenMatch>maxLenMatch) maxLenMatch = lenMatch;
ret+=word1[i1];
i1++;
if(i1==word1.length)
{
if(lenMatch<minLenMatch) minLenMatch = lenMatch;
// Trying to filter like VSCode does.
return maxLenMatch>=word1.length/2 && minLenMatch>=2? ret : undefined;
}
} else
{
ret+="Z";
if(lenMatch>0 && lenMatch<minLenMatch)
minLenMatch = lenMatch;
lenMatch=0;
}
}
return undefined;
}
That return the sortText if the word1 is inside the word2, undefined otherwise. My problem are cases like this:
My algorithm see that 'aller' is inside CallServer, but the interface does not mark it like expected.
There is a library or something that I must use for this? the code of VSCode is big and complex and I don't know where start looking for this information...
VSCode's API docs for provideWorkspaceSymbols() provide the following guidance (which I don't think your example violates):
The query-parameter should be interpreted in a relaxed way as the editor will apply its own highlighting and scoring on the results. A good rule of thumb is to match case-insensitive and to simply check that the characters of query appear in their order in a candidate symbol. Don't use prefix, substring, or similar strict matching.
These docs were added in response to this discussion, where somebody had very much the same issue as you.
Having a brief look at VSCode sources, internally it seems to use filters.matchFuzzy2() for the highlighting (see here and here). I don't think it's exposed in the API, so you would probably have to copy it if you wanted the behavior to match exactly.

VS Code, Prettier and Flow not working nicely together - what am I missing?

I'm using the prettier-vscode extension to format my js code, but flow annotations are formatted in a weird way with lots of extra space:
const handleResponse = async function < T > ( // <-- should be function<T>(
response,
url: string,
options: responseOptions = {}
): Promise < T | null > { // <-- should be Promise<T|null> {
or Promise<T | null> {
I've looked around in all the places I could think of to see what config I need to change to get this working, but I can't find anywhere that seems to affect the spacing in te above case.
There's also some weirdness going on with multi-line ternary statements, but I don't think that's related to flow:
const WORKORDERS_BASE_URL =
WORKORDERS_PORT === '80' ? // <-- I'd prefer if ? and : were on the next line
`http://${WORKORDERS_HOST}` : // <-- on same indentation level as above - I want one more
`http://${WORKORDERS_HOST}:${WORKORDERS_PORT}` // <-- same here, I want more indentation
The worst case of them all is this change, which happens when I format the document:
Promise<?T>
// becomes
Promise<<?T>
i.e. it actually breaks my code!
Where should I look for config that controls these things?

preg_replace add ; to javascript function

I have a javascript which contains something like this
var f = function(){
if(){
}else{
}
}
and I need to add ; at the end, like this
var f = function(){
if(){
}else{
}
};
I need some help to get the closing function } tag and not the } tags from inside the function.
Thanks
You can't, if all you can use is regex. It'd be very much like parsing HTML with regex.
Instead, see if you can find an AST parser for javascript in PHP - that's what you'll need to be able to find the appropriate closing bracket.

Wordpress TinyMCE: Switch Views

In order to complete my Wordpress Plugin I want to make tinyMCE to switch between a custom Tag (Some|data|here) and a corresponding Image Display in the WYSIWYG-View.
The event should be triggered on load, safe, autosave, switch view etc. Threre are 4 different events defined, but none of them works as expected.
onBeforeSetContent
onGetContent
onPostProcess
onLoadContent
.
ed.onPostProcess.add(function(ed, o) {
if (o.set){
o.content = t._htmlToWysiwyg(o.content, url);
}
if (o.get){
o.content = t._wysiwygToHtml(o.content, t);
}
});
Anyon know the right way?
I do not know what you expect the 4 different events will do (?), but i can see some problems in your code.
1. The object o does not contain fields get and set - so o.get and o.set will never be true! Thus your code will never be called.
2. You are using the variable url, but this one is not defined here.
Working example: You may try to paste a string containing "a" into the editor. Use the following:
ed.onPostProcess.add(function(ed, o) {
//console.log('o:', o);
o.content = o.content.replace(/a/g, "A");
});
You should see that all lower 'a's get replaced by 'A's.