Find completely commented files which are commented by /* */ - visual-studio

Similar to this question. I would like to find all commented files. But in my case /* */ is a possibility.
Apparently when you write changes to a database project, dropped objects are only commented out instead of deleting the file. I would like to remove all of these commented out files from the project.
Is is possible to find all files which start with /* and end with */?

Using Visual studio
Your regex is:
/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/
Use the following options in "find in files" (Ctrl-Shift-F)
This reference has even more options ostermiller.com/findcomments.html
I'm sure you could mod this to find the /// comment as well

Studio allows you to search with regular expressions so you could write a regular expression to find /* at the beginning and */ at the end of any file. I'm no regex wizard so I'm not sure of the exact syntax. Maybe something like /*.*/ would work?
Any regex gurus know the proper expression here?

Related

wrap multi-line comments in vs code

VS Code seems to understand what it means to wrap multi-line comments differently from what other IDEs understand. For instance if I set Intellij to wrap multi-line comments at column 100, it breaks the line for me. But if I ask VS Code to do the same, it visually wraps the line but if I later open the same file in a simple text editor, I get one long line.
How do I get VS Code to auto break long comment lines?
Intellij:
/**
* Intellij will break this line
* at the correct location
* because I asked it to break
*/
VS Code
/**
* VS Code will wrap this line
at the correct location
but it's really one very
long line.
*/
I don't think VS Code provides native support for this.
There is an extension in the marketplace for this though: https://marketplace.visualstudio.com/items?itemName=stkb.rewrap.

Batch with comments in OrientDB Studio

I want to run a batch of queries, mostly creating and dropping indexes. In the batch call I also have a bunch of comments but the query parser keeps failing because of the comments. How do I write a comment?
I basically want to do this:
DROP INDEX oldIndex
/*
Comments
*/
CREATE INDEX newIndex ON Class (field) NOTUNIQUE
I have tried to comment with //, -- and #.
I also tried placing everything inside a transaction with begin and end but I can't drop an index inside a transaction.
Note that I'm using the studio. I made short test in the console but I still got problem with comments and lacked the overview to see any problems with my queries.
I am guessing the problem has to do with each row is seen as its own command. I suppose a command with only a comment doesn't make sense but is there any way around it?
In the meantime, use # comment-lines, that is, lines in which the first character (or the first non-blank character) is #.
I have used this in console.sh scripts in Version 2.1.x, e.g. 2.1.9, 2.1.10, and 2.1.11.
I have tried from Studio
I have found this issue https://github.com/orientechnologies/orientdb/issues/4651 about your problem with comments.
If the problem persists, you can reopen the issue.
Hope it helps.

Visual Studio : Search Uncommented Code only

Is there any way to restrict the Find/Search to uncommented lines only ?
(Maybe using regex would be a good lead)
Lets say, if you need to search all occurrences of an uncommented text "VPEntity" then try using the following regular expression in Find in files after selecting the Use RegEx option
^((?!//|/\*).)*VPEntity
Hope it works for you

How can I search in Visual Studio and get it to ignore what is commented out?

I am refactoring a C++ codebase in Visual Studio 2005. I'm about half way through this process now and I've commented out a lot of old code and replaced or moved it. Now I'm searching to see that I have to change next but the search function keeps bringing me the old commented out stuff I no longer care about. I don't really want to delete that old code yet, just in case.
Is there any way I can search all files in the solution and get results ignoring what is commented out? I don't see a way in visual studio itself, is the perhaps a plug-in that would do it?
As the other provided solutions didn't work for me, I finally discovered the following solution:
^~(:b*//).*your_search_term
Short explanation:
^ from beginning of line
~( NOT the following
:b* any number of white spaces, followed by
// the comment start
) end of NOT
.* any character may appear before
your_search_term your search term :-)
Obviouly this will only work for // and ///-style comments.
You must click "Use Regular Expressions " Button (dot and asterisk) on your find window to apply regex search
In newer versions of visual studio .net regex is used which has a slightly different syntax:
^(?![ \t]*//).*your_search_term
My take:
yes you can use regular expressions, those tend to be too slow and thinking about them distracts from focusing on real stuff - your software.
I prefer non-obtrusive semi-inteligent methods:
Poor man's method:
Find references if you happen to use intelisense on
Or even better:
Visual assist and it's colored "Find all References" and "Go To" mapped to handy shortcuts. This speeds up navigation tremendously.
If you comment your old code with // you can use regular expressions while searching for something in your codebase. Something like this for example: ^[^/][^/].*your_function_name.*.
Previous answer gave a false-positive on cases where otherwise matching lines were placed on lines containing other source:
++i; // your_search_term gets found, don't want it found
So replaced the :b* with .* and added the <> so only entire words are found, and then went after some of the older C-style comments where there's a /* on the line:
^~(.*//)~(.*/\*).*<your_search_term>
In my case I was hunting for all instances of new, not amenable to refactor assistance, and boatloads of false-positives. I also haven't figured out how to avoid matches in quoted strings.
Just to add on, as I was doing a "find all" for division operator used in the code, used the below to exclude comments as well as </ and /> from aspx files:
^~(.*//)~(.*/\*)~(.*\<\/)~(.*/\>).*/
In Visual Basic within Visual Studio 2015, I was able to search for text outside of comments by adapting glassiko's comment from the most upvoted answer
^(?![ \t]*[']).*mysearchterm
And in C# you would use glassiko's comment exactly as it was
^(?![ \t]*//).*mysearchterm
Better use \s I think. ^(?![\s]*//).*your_search_term
delete the commented out code, it is in source control right? there is no need to keep it in the file as well.

Global Find and Replace in Visual Studio

I have a solution with multiple projects and we need to do some serious global replacements.
Is there a way to do a wildcard replacement where some values remain in after the replace?
So, for instance if I want every HttpContext.Current.Session[“whatevervalue”] to become HttpContext.Current.Session[“whatevervalue”].ToString() the string value being passed in will be respected? I don’t want to replace “whatevervalue” I just want to append a .ToString() where the pattern matches.
Is this possible in Visual Studio?
First, Backup your Projects, just in case... Always a good idea before mass replacements.
Then, in the Find/Replace Dialog, select the Use Regular Expressions checkbox:
In the Find box, use the pattern:
HttpContext\.Current\.Session\["{.#}"\]
and in the Replace box, use:
HttpContext.Current.Session["\1"].ToString()
Easy...use regular expressions and grouping.
Find what:
(HttpContext.Current.Session[“whatevervalue”])
Replace with:
\0.ToString();
Remember to check the Use: and select Regular expressions
You want to open the "Find Options" expander and select the "Use Regular Expressions" option. After you've done that, you want these as your find/replace entries:
Find:
HttpContext\.Current\.Session\[{("([^"]|\")*")}\]
Replace:
HttpContext.Current.Session[\1].ToString()
Additional Note:
Once you've enabled regular expressions option, you'll be able to use the right-pointing triangle buttons to access snippets of Visual Studio's Regex syntax.
Also note that Visual Studio's Regex syntax is pretty ghetto, as it hasn't changed since the days of Visual Studio 6 (or earlier?)--so don't take any syntax elements for granted.
For example, one might expect that my find regex above is broken because the backslash before the double-quote is not properly escaped, but in reality, putting a double-backslash there will break the expression, not fix it.
None of these answers seem to work in Visual Studio 2013, as that version seems to have finally made the switch to standard RegEx. However, those who are non-RegEx Experts or those who are used to the old VS Find/Replace RegEx syntax will find the RegEx Shortcut buttons very useful.
Please see this answer for more information, including Find/Replace/Surround With examples:
Visual Studio 'Find and Surround With' instead of 'Find and Replace'
You can use Visual Assist for tasks like this. It's a powerful tool for different kinds of refactoring.
You could also consider using the free download tool Refactor available at http://www.devexpress.com/Products/NET/IDETools/RefactorASP/
It does a whole lot more than just find & replace, which they call renaming members with more understandable names. Its various features will easily help you to improve your code.

Resources