Search files by name - Is it possible to define the ignored characters? - visual-studio-code

In VS-Code you can use cmd + p to quickly open a file.
Very often I copy a ruby class name from a stacktrace or from the code, which usually is something like MonduleName::ClassName (for example Admin::User), which by convention is located under module_name/class_name (in the example, would be admin/user.rb).
The problem is that the separator :: is not in the file path and VS-Code does not find it, so I have to
to delete those :: every time, which turns pretty annoying very quickly.
So the question here is pretty obvious, is there a way to tell VS-Code to ignore the : when performing the file search?

No, it is not possible.
I have added an issue in the VS Code project, which sounded reasonable to some maintainer, but it did not get enough upvotes from the community to be implemented and got closed/discarded.
I still miss this feature, so if somebody decides to reopen it, I would be glad to get a comment here.

Related

Which algorithm is used to implement search for files in Visual Studio Code / Google Chrome Developer / Sublime (Ctrl+p or Cmd+p)?

I am very impressed with the powerful search feature of Sublime which we later found in Visual Studio Code and Google Chrome Developer.
A very basic algorithm for searching may use Trie, I guess but this search for files of Sublime etc seems like some sort of a multi-direction Trie (if there is such a thing!) i.e. if you have a file name like:
"I-am-a-very-big-beautifully-created-file-and-something-else.js"
and you search for "created file", "file created", "something-beautifully", "else big", "big else" or any other combination of strings from that file's name, Sublime and Visual Studio code will find it and other files with similar names, in no time. (Google Chrome Developer version isn't very powerful though but that's not the point here).
So, I dug through the source code of Visual Studio for a little bit but still couldn't figure out how the search is implemented and which algorithm is used. I am not looking for its code. Just need to understand a high level theory of how this powerful feature, that saves us developers a lot of time, is implemented.
The VS Code functionality you're looking for can be tracked by looking into what happens when this function is called:
https://github.com/microsoft/vscode/blob/master/src/vs/workbench/contrib/search/browser/anythingQuickAccess.ts#L365
an interesting part here (filter on the first term only , then on the whole filter):
https://github.com/microsoft/vscode/blob/d1220da07267242e9b58193da0ded43bbe7f2aa5/src/vs/workbench/contrib/search/browser/anythingQuickAccess.ts#L570
If you dig from there you will find that most of the useful stuff is regrouped in this file:
https://github.com/microsoft/vscode/blob/master/src/vs/base/common/fuzzyScorer.ts
Some notes:
The fuzzy search is pretty strict, the filter will not match if a single letter is not found or if the letters are not found in the right order. A key advantage is that you can highlight the matching part in the results and it makes pretty clear what's happening to your users.
The fuzzy scorer scores results based on a matching label/description[/path] (for a file, label = filename, description = path without name).
This looks like the code that DevTools uses for its fuzzy search in the Command Menu.
https://cs.chromium.org/chromium/src/third_party/WebKit/Source/devtools/front_end/quick_open/CommandMenu.js?l=174
And the underlying diff algorithm is:
https://cs.chromium.org/chromium/src/third_party/WebKit/Source/devtools/front_end/diff/Diff.js?q=Diff.Diff&dr=CSs&l=4
I think the name is "fuzzy search" lol. Here's a nice github repo where some kind person released an open source JS version that is a lot easier to include in your code than the VS Code version because it's on npm and it's just one file:
https://github.com/farzher/fuzzysort

Is there a quick way to show the code of a method declared in the Scala Console?

I frequently use the Scala console to evaluate and test code before I actually write it down in my project. If I want to know the contents of a variable, I can just enter it and scala evaluates it. But is there also a way to show the code of methods I entered?
I know there's the UP-key to show single lines, but what I was searching for is to show the whole code at once.
There's a file in your home directory named .scala_history that contains all of your recent REPL history. I regularly copy and paste code from this file into project source files. It's not exactly the same as showing the code for individual methods in the REPL, but it might help you accomplish the same goals.
See the comments by Paul Phillips in this issue for a discussion of some related functionality in the REPL (grouping statements in the history):
At some point I implemented the logic for this, but the real obstacle
is jline. It has enough trouble figuring out where the cursor is under
the simplest conditions. Start throwing big multiline blocks into the
history and it breaks down in tears. Would love to see this and
SI-2547 addressed by the community.
...
I expect to fix this soon too, but it depends on how well the recent
jline work goes. I implemented it long ago, and display issues are the
impediment.
Both of these comments are over two years old, so I wouldn't hold your breath.
I dont know a command to load all the code from command line.
What you can do is to :load path/to/my/file.scala to load some complex code and re- :load it when you changed the code in the file.

emacs Semantic/senator : autocomplete for external lib's

It seems this forum is more alive than mailing list : http://sourceforge.net/mailarchive/forum.php?forum_name=cedet-semantic.
I would like repost my quest from a week ago from there:
First hi to all who contribute to this great package as CEDET :D .
Without much hussle I am able to get working most of the CEDET futures, but when it comes to senator / semantic things get more tought :\ .
Parsing local files are fine.
I don't use EDE not to get things more complicated.
I use the 1.0.6 git trunk version, for compability with ECB.
First is the rumble about the emacs core / cedet git-trunk hussle. How do I check that current installation is running the latter ? ( I have done some .emacs modificaitons see below) .
I generally cannot get the proper autocomplete working for external libs - in this case the OGRE3D project, which all are in the /usr/include/OGRE. I suppose I have added to 'search path' include properly, semantic-describe-c-env. sees them added properly.
2.a What are the basic commands to the semantic parser ? , that is I need to force it to parse the desired includes.
Once I saw semantic parsing the OGRE files in the 'idle time'. Still the autocomplete does not work ( OGRE:RAY is not recongized as a type).
senator-completition-menu-pop gives some non-matching 'c**p'
2.b I know there are customize-group options for semantic, tough their description say little to me.
From the other post:
"Yes, there is a setup cost. You can use semanticdb.sh to pre-parse your
code, but if you never open every file, you might end up with Emacs
having such a huge data structure it gets larger that your machine can
handle. If your project is small, this shouldn't be a problem."
Well this might be, if that would parse OGRE.
here's my .emacs:
.emacs at pastebin.com
Here's what I got on the mailing list, hope that it would help someone , thaks to Eric Ludlam :D :
======================
1. First is the rumble about the emacs core / cedet git-trunk hussle. How do I check that current installation is running the latter ? ( I have done some .emacs modificaitons see below) .
After emacs start, use:
M-x cedet-version RET
and look for the 1.1 version from CEDET/bzr.
I just tried this and noticed not everything has the right version
number. Interesting. I'll have to look into that.
Anyway, the next thing to try is:
M-x locate-library RET cedet RET
and make sure it points where you think it should.
2. I generally cannot get the proper autocomplete working for external libs - in this case the OGRE3D project, which all are in the /usr/include/OGRE. I suppose I have added to 'search path' include properly, semantic-describe-c-env. sees them added properly.
If you enable global-semantic-decoration-mode you can right-click on
header files, and it will give you some options, such as showing where
it things the header is, and showing if it has been parsed yet or not.
2.a What are the basic commands to the semantic parser ? , that is I need to force it to parse the desired includes.
You can use the include menu to force a header to be parsed, or visit
said include. If it can't find it, you can add OGRE to your path from
there too.
If you vist your header, you can use the senator menu to force a file to
reparse, or use:
C-u M-x bovinate RET
to do it.
Once I saw semantic parsing the OGRE files in the 'idle time'. Still the autocomplete does not work ( OGRE:RAY is not recongized as a type). senator-completition-menu-pop gives some non-matching 'c**p'
Autocomplete can fail for many reasons. The best way to find out why is:
M-x semantic-analyze-debug-assist RET
at a place you want to do completion. It will tell you about your
header files, symbols, and the like. It could be your preprocessor
symbols need some setup.
For large complex library headers, sometimes it is just a matter of
having the right pre-processor symbols setup in Semantic so that the
right bits of the headers get parsed for symbols. You'd have to visit a
header where a symbol you want to complete is, and see if it was parsed.
Using:
M-x boviante RET
will dump the symbol table.
2.b I know there are customize-group options for semantic, tough their description say little to me.
From the other post:
"Yes, there is a setup cost. You can use semanticdb.sh to pre-parse your code, but if you never open *every* file, you might end up with Emacs having such a huge data structure it gets larger that your machine can handle. If your project is small, this shouldn't be a problem." Well this might be, if that would parse OGRE.
I doubt parsing the includes is the problem here. I think there is just
something new in the ogre headers we'll have to deal with.
Eric
===================================

How to get around Eclipse swallowing double quotes for ${selected_text}

I am using Eclipse 3.6.1 Build id: M20100909-0800 and Aptana Studio 2.0.5 which is based on Eclipse 3.5.2 (both on OS X) and in both programs the external tools feature seems to swallow double quotes and whitespace for the ${selected_text} variable.
Isn't the ${selected_text} variable essentially useless with the mentioned behaviour?
Is there a way around that or maybe a hidden setting somewhere?
Thanks for reading.
This could easily be considered a safety/security feature.
I suggest "${selected_text}".
...but if it's eating ALL whitespace, that won't really help. Huh. Maybe it's clever enough to detect the quotes and preserve the whitespace... but probably not.
Okay, I did a little poking around. Quotes within the argument list itself are preserved, as per my initial suggestion above. I found the following auto-generated argument list that was working Just Fine:
-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog
-debug "${workspace_loc:/com.cardiff.bpm.ide.webforms.ui/debug.options}"
But if your text selection contains quotes, I'd expect it to be handled as per the underlying OS. Windows "cmd" does some... creative things with them for example. My *nix-fu is Not Mighty, so I couldn't tell you what OS X will do under the covers, but I suspect that's where you'll find your solution.
You may have to do something goofy like URL-encode your selection, and use some command line tool to un-encode it before passing it to your desired external tool once the text is out of Eclipse's clutches.
A (very) quick look around my 3.6.1 UI didn't turn up that would do this automagically for you, but there's probably a plugin out there somewhere that'll add that feature to an editor's context (right click) menu.
I'd expect the HTML editor to have this ability already... but I don't see anything other than "smart insert mode" that sounds promising, and I don't see that working either.
That doth bloweth goats, most heartily, yay for weeks on end. E'en till yon goat hath a rash, most unpleasant in both severity and locality. Verily.
I don't think you're getting my proposed solution:
Set up your tool so it'll de-url-encode-ificate the incoming string with some proposed command line tool.
In your editor (in eclipse), URL-encode the text you wish to select and pass to the tool. Manually.
Run the tool on the selected (url-encoded) text.
Revert the selected text. Also manually. Probably just "undo".
"1" is why I was looking for some eclipse UI way of url-encoding a selection. The HTML Editor won't even do it when you paste into an attribute string. Sheesh.
Two Other Options:
Fix the bug yourself. Open Source and all that.
Write a plugin that exposes it's own version of ${selected_text} that doesn't strip out all the strings.
Hey! SED! Replace the quotes with some random (unused in any selection you might make) high-ascii character and sed it back to a double quote instead of the proposed de-url-encode-ificationizer. You'd still have to manually edit/undo the text, but at least you won't have to """ Actually search/replace over a given selection makes that less painful than one might think.
I'm not sure what the scope of #2 is, but I'd image if you don't have any eclipse plugin experience the thought might be rather daunting. There might even be a sample plugin that exposes such a variable, though I haven't checked.
I don't think we're communicating.
You don't select text with quotes in it. You select mangled text, and sed demangles it back into quotes for you.
For example, you have the string print("hello world"); in your editor and want to send that to your tool.
change it to print(~hello world~); in your editor. Manually or via a script or whatever.
select it
run your tool, maybe wrapped in a script that'll sed the ~s back to "s.
change it back to print("hello world");.
This is a manual process. It's not pretty. Bug workarounds are like that. You can probably come up with a monkey script to convert quotes to Something Else, and "undo" is easy. You might even be able to get your script attached to a keyboard short cut... dunno. And ~ is a lousy choice for a replacement character, it's just the first thing I could think of that was rare enough to be a decent example.
Are we communicating yet?
For the record, I put together a patch using some guidance from a gentleman in the bug comments.
I don't know if it will be accepted, but it fixes things for me so maybe someone else may find it useful.
Again, this is only for Mac OS X Eclipse.
Start Eclipse.
Go to Import > Plug-ins and Fragments.
Import From: Active Platform
Fragments to import: Select from all plug-ins
Import As: Projects from a repository
Next >
Pick org.eclipse.debug.ui and org.eclipse.debug.core
Once the projects are in your workspace, apply the two patches that compose proposed patch v1, found at the bug tracker page for bug 255619
Go to Export > Deployable plug-ins and fragments and make a jar out of your changed packages.
Hope it helps.

How can I compare 2 files and ignore any changes in comments?

I'm using C# and VB.NET.
I often (every days...) add comments to existing source files. When I check-in these files, I would like to have my merge tool to ignore any changes made to comments - I just want to be sure that I did not change the code.
I use WinMerge and Team Foundation Control Server (yes, no chance : Subversion was not an option when I accepted this job :o). Both of them can ignore white spaces but cannot ignore comments. Result : I have to carefully look at all the changes that I have made to each file before checking them in. And this is pretty cumbersome.
(Well, since most of my co-workers do not comment at all -- hey, they use pretty long namespace/class/methods/property/type/constant names that tell it all, guys ! -- it's a lot of work.)
Any suggestions ?
All the best,
Sylvain.
BeyondCompare has a filter for ignoring "unimportant" changes and comments belong to that category by default.
Compare++ has an option "Ignore comment changes" and "Ignore pure formatted changes" which should honor your request.
You said you used WinMerge - well it has the ability to filter out comments.
However it only works for comments that are on a separate line, so for example:
int i; // comment
will be detected as different from
int i;
It sounds like you're using commenting as a tool to understand the code as you work with it. That's an interesting idea, the equivalent of highlighting a book or taking notes. But you need to make sure you strip out all these transient comments before working with others.
Before comparing or promoting, run your source files through a filter program that strips the comment. This could be a one-liner perl script.
To make it easier, use a distinctive pattern for your non-permanent comments, to make them easier to filter out (and to distinguish between these transient comments, and comments you really want to leave in the source). E.g. if you were writing in C++, always comment using
//Sylvain: this is my comment here.
or some other pattern that is even easier to grep for.
If the content of the comments are not something you care about, and do not matter, why not delete them?
If well documented code that is readable and understandable is part of what you create, why not review changes to that meta-data?
Adding comment to your code is smell that your code is hard to read, code should be self describing, like someone has said that , good code is like good joke, it does not need to be explained. It is better to change your variable name, put section of your code into a subroutine. Re factoring is better than commenting. Even you find a tool to solve you commenting problem, it does not solve the real problem that is make you code easy to understand.