Notepad++ SourceCookifier plugin very slow on large C++ headers - c++

I like to browse through my C++ projects in Notepad++. I use the SourceCookifier Plugin in order to easily jump in between definitions on large files. However, if I load a large C++ header file (around 30.000 lines), with a lot of #define and typedef declarations inside, it seems to hang and takes a long of time to load.
Does anyone know if there is any option one can set to make it faster or can this plugin generally not load so many definitions?

You can accelerate everything by throwing your project folder into the SourceCookifier panel while (and this is the important but badly documented part) pressing a modifier key (shift, ctrl or alt).
.. for importing INCLUDE files. But you have to additionally either
press the CTRL, SHIFT or ALT key while dropping a file or folder into
the treeview.
Or even smarter... separately only add your large define/typedef sources like described. It will result in a performance boost, since their symbols won't be listed in the tree view anymore, but SourceCookifier will still navigate you there, when hitting "Go To Definition" on one of their symbols somewhere else in the project.
I also sometimes use to add header files with several thousand defines to a SourceCookifier session. Without pressing ctrl-key it takes up to 5 mins per file, but with pressing ctrl-key it only takes 1 second!
EDIT/
Adding source files without pressing ctrl-key:
"Go To Definition" functionality? Yes.
Symbols shown in tree view as subnodes of source file node? Yes.
==> Not recommended for laaaarge source files.
Adding source files with pressing ctrl-key:
"Go To Definition" functionality? Yes.
Symbols shown in tree view as subnodes of source file node? NO.
==> Recommended for laaaarge source files.

Related

Eclipse freeze on opening declaration in long file

I am using Eclipse CDT on linux. I have a long header file with 5k lines of code. When I try to open declaration of some variable in this file by pressing F3, Eclipse freezes for about 20 seconds and then opens declaration. This issue makes code navigation unusable in a long file. In shorter files declaration opens almost instantly.
I tried to restart Eclipse and rebuild the index but this did not help.
My Eclipse version is:
Version: Neon.1 (4.6.1)
Build id: Z20161111-1340
How can I workaround this issue ?
Due to the way CDT is architected, operations on larger files will be slower than operations on smaller files.
CDT obtains semantic information about the code for operations like Open Declaration from two places:
For the currently open file: from the AST (abstract syntax tree) it builds for that file.
For included header files and other files in the project: from the index, which is a searchable database of semantic information about the project.
The index is initially built by creating an AST for every file in the project, and storing information from them into a database. This is a time-consuming process, but it only has to be done once (and then it's incrementally updated every time you save a file), and once it's built, querying the index is fast (querying is about O(log n) in the size of the index).
On the other hand, since the AST represents code that is (potentially) being currently edited, it is constantly being rebuilt "as you type". Since building an AST is at least O(n) in the length of the file (possibly worse; I haven't done a careful analysis), operations that depend on the AST get slower as the length of the file you're editing increases.
Now, for workarounds:
Enabling some of the scalability settings in Preferences | C/C++ | Editor | Scalability may help, by restricting the kinds of operations that require building an AST for large files (notice you get to define the threshold for "large"). It's not immediately clear to me whether it will make Open Declaration faster; try it and see.
Your best bet, however, is to break your header up into smaller headers. This has the added advantage of reducing compile times (since not all translation units may need to include all parts of the header), and organizing your code better (this last one is a matter of taste; feel free to disagree).
Looks like this is Eclipse bug 455467.
The reason of freeze is high cpu usage when opening declaration.
I applied workaround from Comment 5 and freeze dropped to 1-5 seconds:
Changing all settings in
.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.cdt.codan.core.prefs
from RUN_AS_YOU_TYPE\=>true to RUN_AS_YOU_TYPE\=>false seems to help
us out of this but this is not really what we want.
As I understand this workaround partially disables Codan - CDT static analysis framework.

Comparing the contents of two files in Sublime Text

I have two cloned repositories of two very similar open-source projects, which I have been working on in different instances in Sublime Text 2 to arrive at my desired result. Code from both of these projects was used. I have been using Git as version control for my project, but have not included the original projects. Thus, I would like to be able to quickly compare the contents of two files of the original project and compare the differences between them and my project.
I was hoping that Sublime Text 2 would have a "Compare File" feature, but I can't seem to find anything related to it in the settings or online. A third-party ST2 package to accomplish this task would also work well. Is such a task possible to do within the ST2 text editor?
You can actually compare files natively right in Sublime Text.
Navigate to the folder containing them through Open Folder... or
in a project
Select the two files (ie, by holding Ctrl on
Windows or ⌘ on macOS) you want to compare in the sidebar
Right click and select the Diff files... option.
Compare Side-By-Side looks like the most convenient to me though it's not the most popular:
UPD: I need to add that this plugin can freeze ST while comparing big files. It is certainly not the best decision if you are going to compare large texts.
There are a number of diff plugins available via Package Control. I've used Sublimerge Pro, which worked well enough, but it's a commercial product (with an unlimited trial period) and closed-source, so you can't tweak it if you want to change something, or just look at its internals. FileDiffs is quite popular, judging by the number of installs, so you might want to try that one out.
UPDATE (Given the upvotes, I feel there is a need for a complete step-by-step explanation...)
In the Menu bar click on File->Open Folder...
Select a folder (the actual folder does not really matter, this step is just to make the FOLDERS sidebar available)
If there is no Side Bar shown yet, make it appear via View -> Side Bar -> Show Side Bar
Use this FOLDERS-titled Side Bar to navigate to the first file you want to compare.
Select it (click on it), hold down ctrl and select the second file.
Having two files selected, right click on one of the two and select Diff Files...
There should be a new Tab now showing the comparison.
Original short answer:
Note that:
The "Diff files" only appears with the "folders" sidebar (to open a folder: File->Open Folder) , not with "open files" sidebar.
UPDATE JAN 2018 - especially for Sublime/Mac
(This is very similar to Marty F's reply, but addresses some issues from previous responses, combines several different suggestions and discusses the critical distinction that gave me problems at first.)
I'm using Sublime Text 3 (build 3143) on Mac and have been trying for about 30 minutes to find this File Compare feature. I had used it before on Sublime/Mac without any problems, but this time, it was trickier. But, I finally figured it out.
The file format does not need to be UTF-8. I have successfully compared files that are UTF-8, ISO-8559-1, and Windows-1252.
There is no File > Open Folders on Sublime/Mac. Many instructions above start with "Select File > Open Folders," but that doesn't exist on Sublime/Mac.
File compare works on a Project basis. If you want to compare two files, they must be saved to disk and part of the current project.
Ways to open a project
If Sublime/Mac is not running or if it's running but no windows are open, drag a folder onto the Sublime app.
If Sublime/Mac is running, select "File > Open", navigate to the desired folder, don't select a file or folder and click "Open".
Add a folder to a project. If the files you want to compare are not part of the same hierarchy, first open the folder containing one of the files. Then, select "Project > Add Folder to Project", navigate to the folder you want and click "Open". You will now see two root-level folders in your sidebar.
The Sidebar must be visible. You can either "View > Side Bar > Show Side Bar" or use the shortcut, Command-K, Command-B.
Files must be closed (ie, saved) to compare. Single-clicking a file in the Side Bar does not open the file, but it does display it. You can tell if a file is open if it's listed in the "Open Files" section at the top of the Side Bar. Double-clicking a file or making a modification to a file will automatically change a file's status to "Open". In this case, be sure to close it before trying to compare.
Select files from the folder hierarchy. Standard Mac shorcut here, (single) click the first file, then Command-click the second file. When you select the first file, you'll see its contents, but it's not open. Then, when you Command-click the second file, you'll see its contents, but again, neither are open. You'll notice only one tab in the editing panel.
Control-click is not the same as right-click. This was the one that got me. I use my trackpad and often resort to Control-click as a right-click or secondary-click. This does not work for me. However, since I configured my trackpad in System Preferences to use the bottom-right corner of my trackpad as a right-click, that worked, displaying the contextual menu, with "Delete", "Reveal in Finder", and.... "Diff Files..."
Voilà!
UPDATE OCTOBER 2017
I never knew this feature existed in Sublime Text, but the interface appears to have changed slightly from the previous answer - at least on OS X. Here are the detailed steps I followed:
In the Menu Bar click File -> Open...
Navigate to the FOLDER that contains the files to be compared and with the FOLDER selected, click the Open button, this makes the FOLDERS sidebar appear
In the FOLDERS sidebar, click on the first file to be compared
Hold the Ctrl on Windows or ⌘ on OS X, and click the second file
With both files selected, right click on one and select Diff Files...
This opens a new tab showing the comparison. The first file in red, the second in green.
View - Layout and View - Groups will do in latest Sublime 3
eg:
Shift+Alt+2 --> creates 2 columns
Ctrl+2 --> move selected file to column 2
This is for side by side comparison.
For actual diff, there is the diff function other already mentioned.
Unfortunately, I can't find a way to make columns scroll at the same time, which would be a nice feature.
The Diff Option only appears if the files are in a folder that is part of a Project.
Than you can actually compare files natively right in Sublime Text.
Navigate to the folder containing them through Open Folder... or in a project
Select the two files (ie, by holding Ctrl on Windows or ⌘ on macOS) you want to compare in the sidebar
Right click and select the Diff files... option.
No one is talking about Linux but all above answers will work. Just use Ctrl to select more than one file. If you are looking to compare side by side, Meld is lovely.
There's a BeyondCompare plugin as well. It opens the 2 files in a BeyondCompare window. Pretty convenient to open files from the sublime window.
You will need BC3 installation present in the system.
After installing the plugin, you will have to provide the path to the installation.
Example:
{
//Define a custom path to beyond compare
"beyond_compare_path": "G:/Softwares/Beyond Compare 3/BCompare.exe"
}

Sublime Find and Replace without having to click save

When I do a global search/replace in a project, Sublime will automatically open all the files involved, and not save them. I then have to manually save every single file.
Is there a way to have Sublime automatically save all the changes that have been done, and not open the files that where not previously open?
Thanks in advance for anyone who can help me with this.
http://www.sublimetext.com/forum/viewtopic.php?f=3&p=40348
I think it's Option + Command + S(Mac) or Command + Alt + S(Win).
Just performed a similar task with the free Visual Studio Code. Replace in Files without opening files and fast. Just made 60k changes in just a few minutes.
Robust if awkward.
While it doesn't change the fact that Sublime Text doesn't seem to be the best tool for this job, here's a practical workaround procedure I've come to rely on. It's reasonably slow but painless if done correctly. Memory consumption impact seems negligible, if you're wondering. The ballpark of my use cases is up to about 10k files in up to a handful of minutes on a mediocre memory-cramped machine using Sublime Text 3.2.2 (3211) on Windows 10 Pro x64.
Requirements
You'll need the package SideBarEnhancements to be installed.
…which in turn relies on Sublime Text 3 or newer as of writing this.
Procedure
(Could probably be deferred until step 3.) You add the directory A that you're going to operate on to the project sidebar.
You initiate your batch replacement operation over numerous files inside directory A.
Sublime Text takes its time to open numerous tabs belonging to directory A recursively and perform replacement in each.
You right-click on the directory A in the project sidebar to bring up its context menu and choose "Save Views".
Sublime Text takes its time to save each tab belonging to directory A recursively.
You right-click on the directory A in the project sidebar to bring up its context menu and choose "Close Views".
Sublime Text takes its time to close all tabs belonging to directory A recursively.
Disclaimers
Warning
Do not make the mistake of skipping step 3 or you'll effectively become stuck in a GUI loop of writing confirmation dialogs defaulting to "Yes" for however many thousands of files you're operating on.
If you decide to abort operation between steps 2 and 3 — your best course of action, is to back the files up on disk, proceed with the outlined procedure and then restore the backup.
Caution
All of the tabs belonging to the directory you'll operate on will be closed by the end of this procedure. If you need a substantial portion of them to remain open throughout replacement — consider organizing the files contained into a sub-directory structure conducive to cherry-picking.
General advice
As a rule of thumb, before proceeding with this procedure, it would be wise to check if the required context menu entries are in fact present (greyed out or not) in your combination of editor+package versions. And to be on the safe side, you might want to back up your data and Sublime Text session before massive operations.

C++ IDE feature: Synchronized viewing columns for headers and implementation files?

Modern screens have large resolutions, fitting two or three columns of 80-column code easily. C++ basically requires that you separate your code into .hpp and .cpp files.
So, to utilize this space, why not automatically open the .cpp file in a second column when you open a .hpp file (and vice versa)? This obviously wouldn't work for extreme cases, although for a lot of projects there is a direct correspondence between the filenames that would be easy to determine. To me, this seems like a very reasonable use of this space, and it's hard to imagine it hasn't been done.
Is there an IDE that does this? A plugin? Or, why do you think it can't be done?
If you're in Visual Studio, a plugin (Visual Assist X), which is already very nice to have for C++ projects has a similar feature. It's not completely automatic, but all you have to do is press Alt+o and it will open the other file in the set. That is, if you're .hpp pressing the key will open the .cpp, and vice versa.
Their website demonstrates how this works in a video. It also works for things like XAML/Code Behind files, Windows Forms/Code files, etc. (Basically anywhere files operate in pairs, that key combo switches to the other file in the pair)

Adding header & implementation file at the same time

I'm sure I'm not the only one with this issue, but I couldn't manage to find a question for it. So I want to add a new unit to my project, the process goes like right click project -> Add -> New Item -> Type in name -> Select .h as type -> Hit Ok. Then repeat the whole process again for the cpp file. The logical choice would be to have a multi select support for the file type selection, but this isn't the case at least in VS 2008. I can see one reason for not having multi select, and that is because the dialog would have to be slightly smarter / different, as the location path often wouldn't be identical.
My question naturally becomes: "Is there a better / quicker way to add a cpp file & corresponding header file in VS?"
Hi you can add class witch create cpp and h files.. if it helps to you
Doing things the way your'e doing them, I think the answer is no. You have to create one file at a time. This makes sense to me since you will often not create CPP and H files on a one-to-one basis.
Otherwise, you can use VS's class wizard, which will create the files and write some skeleton code for you.