allowing to insert breakpoint in visual studio editor extension - c#

Add Syntax Highlighting to IElisonBuffer
I follow this question and implement my visual studio editor extension.
I got everything working fine: syntax highlight, completion...but I cannot add breakpoint even thought the options was there in the right context menu (disabled)
Is there anything else I need to do to enable this feature for my editor?

Well, for the breakpoint to actually do anything, you'll need to implement a debugger (via the AD7 interfaces, etc.).
But to just get the actual breakpoint toggling working, all you need to do is implement the IVsLanguageDebugInfo interface (and optionally IVsLanguageDebugInfo2 and IVsLanguageDebugInfo3 too for more control). (I suggest you do so on the your language info object that's already implementing IVsLanguageInfo.) Don't forget to register your implementation so that VS knows about it.
ValidateBreakpointLocation() will be called when the user presses F9, etc., and in it you should set the breakpoint span to the appropriate bounds of the line (or portion of the line depending on your language, e.g. you might be in a lambda or want to highlight a statement except for any trailing comments on the line), then return VSConstants.S_OK.

Related

Is there a "Go To Variable Type Declaration" function for C# in Visual Studio 2015 or a free plugin which does it?

void MagicalFunction(MagicalType magic)
{
...
magic.Poof("something");
...
var foo = magic.GetFoo();
...
}
Pressing the hotkey on variable magic would navigate to definition of type MagicalType.
Pressing the hotkey on foo would go to definition of type Foo which is not directly visible here because of type-inference.
Resharper plugin has this functionality (called Go To Type of Symbol) , but is there a built-in alternative or a free-extension that does this?
Right click on the "var" keyword, select "Go to definition" from context menu, and it will take you to the type definition of the inferred type of the variable. I have some tools installed, like Productivity Power Tools which were mentioned, so not sure if this option is available through clean VS2015.
Edit:
You can also with cursor on the "var" keyword press Ctrl-F12 (Go to Implementation), if you prefer to use keyboard. Ref: https://www.youtube.com/watch?v=xWcQhF-1hxA
Sort of.
You could press F12 on "magic" to get to its definition, and then F12 again to get to its class.
Also, while you can't get anything meaningful by F12 on "foo" since it would just highlight the line you're already on, if you F12 from the "var" immediately prior to foo, it will jump you to the Foo class, even though that type is being inferred.
The function you are looking for is "Navigate To".
For some weird reason, the keyboard shortcut was removed from VS 2015. You can see this by going into the Edit menu. The option will be there but has no shortcut assigned to it.
You can fix this manually. The default was:
CTRL + ,
Go to Tools > Options > Environment > Keyboard, search for "Edit.NavigateTo" and reassign the shortcut. You can then place the cursor on the variable and hit the shortcut and a tiny window will overlay on the top right hand corner with possible candidates, one of them being the type definition.
Productivity Power Tools has a feature "Ctrl + Click Go To Definition
This extension gives the editor a web browser by adding clickable hyperlinks to symbols in your code as you hold down the Ctrl key."
https://visualstudiogallery.msdn.microsoft.com/d0d33361-18e2-46c0-8ff2-4adea1e34fef
it deosn't work in the first case but it works very well when you ctrl click "var" in the second case

Resharper - Disable 'help' when using "prop" shortcut in C#

I'm getting quite annoyed with a feature of Resharper that I just cannot find how to disable independently.
With Resharper turned off, whenever I type prop in VS2015 and press TAB, I get the following auto-generated code:
public int MyProperty { get; set; }
and I'm then able to switch between int and MyProperty repeatedly by pressing TAB again.
I'm also able to use autocomplete to fill in the variable type as I type.
For example, lets say I wanted to create a property called "test" of type "string", I would do the following:
type prop
press TAB to generate the property code template
type stri
press TAB to autocomplete the variable type with string
press TAB to move to the variable name placeholder
type test
press Return to finish
perfect.
However, with Resharper enabled, whilst steps 1,2 and 3 still work, it all goes to pot after that!
If I press TAB to try and autocomplete the variable type, the cursor simply moves over to the variable name, leaving the variable type as stri.
If I then press TAB (or even SHIFT+TAB) again to try and get back to it, it simply finishes the line.
To make things clearer, I've included two gifs demonstrating my problem.
This first one shows what happens with Resharper disabled:
Whilst this one illustrates the frustration I'm currently experiencing with Resharper enabled:
I understand this is an old(er) question and already has an answer; however, I wanted to provide a solution for future SO readers that would allow one to continue using Visual Studio's IntelliSense as opposed to Resharper's.
I had the same issue as the OP (original poster) and found the issue to be caused by a conflict with Resharper's Live Templates. With Resharper enabled, the resolution of prop after Tab + Tab, resolves Resharper's prop Live Template and not Visual Studio's prop snippet. You might have notice that in OP's 2nd screen cap (the one with Resharper enabled) that the resolution of prop has a datatype shown as TYPE instead of int. This is because Resharper's Live Template has set this parameter name to TYPE, while Visual Studio's snippet has the same parameter set to int by default. This is what lead me to look at Resharper's Live Templates for a resolution; lo and behold turning off the prop Live Template fixes the issue.
Go to Resharper's Template Explorer (Resharper -> Tools -> Templates Explorer) you will see there is a Live Template named prop. Simply clear the check box for the prop Live Template and Visual Studio's prop snippet resolution, and datatype resolution for that matter, will start working again.
It looks like you have an intellisense setting conflict.
Re-Enable Resharper and then change this setting:
Resharper->Options->IntelliSense->General
Change the selection from "Visual Studio" to "Resharper", hit Save and the desired behaviour should be yours.
I find those shortcuts still work without disabling anything however sometimes this functionality stops working.
Currently using R# 2018.2 with the default keyboard mappings set to IntelliJ IDEA scheme (as I also use java) and the shortcuts are all available, but when they stop working closing all tabs and reopening the tab you are working on normally fixes it.
No restart or reset is needed.

Change name of winform components of C# in code with visual studio

When I create a win-form project and add some components to the form by drag them from the tool box, everything works nice, binding codes are generated but components' names are given by default, like button1, button2... I think they are not appropriate for code maintenance.
So I want to name them like button_add, button_del and some name like that, more meaningful, so I change the name in the attribute box of the component, but I don't see any change in the code.
Can some one show me how to do this?
Usually such changes should be performed automatically by Visual Studio when you change the control's name. The only thing not being renamed are event handlers.
For example: If you add a Click handler to a button named button1 the method will be named button1_Click by Visual Studio. The method name will not change if you rename the button to button_add. This is probably because you can name the method yourself, for example ItWasPressed - how should Visual Studio handle this? If it renamed the method, you'd complain that Visual Studio turned your nicely named method into button_add_Click automatically :-)
You can simplify this refactoring-step by modifying the method name, then pressing Shift+Alt+F10 and selecting the respective option to rename all occurrances.
However, all other references in code will be changed, like for example button1.Enabled = false; will be changed to button_add.Enabled = false;.

C# Form Application: How to avoid deleting the unwanted events "manually" from InitializeComponent()?

This is a simple scenario:
I add an event to a control on the form by double clicking on its field (in Events part). But, then I decide that it was unnecessary and delete the automatically generated method. I'll run the program and it gives an error telling me that the event still exists in the InitializeComponent() and I must delete it from there.
So, is there anyway to avoid deleting the event "manually"? Is there anyway to fully delete it without leaving any trace (specially in InitializeComponent())?
Update: Also, another question arose:
When I delete the method from the code, the method name in the event field will disappear. So, if the InitializeComponent() is linked to these events, why isn't it updated with the empty event field?
You should use again the events grid and right click on the event you have inserted.
Select the Reset Menu option. This will remove the event handler assigned in the InitializeComponent and the code of the emtpy event in the code designer.
Note, that if you add code at the event, Visual Studio doesn't remove the new code.
The best way to do this is through the Properties grid in the Designer. You can click the Reset button or just delete the text and it will remove the event hook-up in the InitializeComponent() method. If your method is empty in your code behind, it will also delete it there:
It makes sense that you would have to manually delete the method body if it contains code in case it accidentally got Reset in the designer or if your method is referenced from some other part of your code. Visual Studio is gong to err on the side of caution.
If you delete the method body first, the reason it is not deleting the references to it probably in part has to do with cutting-and-pasting code. If you wanted to move the method to a different place in your code, the acting of cutting it would sever the references to it. After you pasted it, then you would wonder why your event was no longer be called. Again, error on the side of caution since it's not that difficult for the developer to track down extraneous code.
This pertains to C# 2017. So hopefully it would help others.
I'm new to C# (or at least back to code it) and ran with the same issue.
I commented out the event that I did by mistake. Then in the Error list, you will find an error there because that event is missing. Double click on it. It'll take you to the Designer code that "wires" the event. Once there, find the unwanted event and comment it out/delete it. Take care!
Look at the properties window when you select the Control. Click on the little flash and you'll see the Events listed, along with your event (Click or whatever), and your event will have the name of the assigned method behind it. Just delete that method.
That deletes the method, only if it's empty and otherwise unused though, which is quite reasonable. After all you might have put a lot of work into that event handler. (note: Just tried it again and apparently it doesn't always delete empty methods even though it did a few minutes ago. weird.)
In the designer you go to the events tab for the control in question, select the event that has the unwanted handler; and delete the name of the handler. Then save the form again.
This doesn't delete the method itself I think, (possibly unless it's empty or just been added).
Update
I dare say the reason for why it nearly always doesn't delete the method is because it could be used as a handler on another control's event. After all, in the UI you only asked to remove one event's handler; not every handler bound to that method. Then there's the question of whether the back-end code is dirty (i.e. unsaved) - checking whether the method is empty or not isn't reliable in that case. Yes, all of these could be worked around, but having to delete the method manually isn't exactly a hardship :) and at least this way VS doesn't end up deleting methods you actually want to keep.
Go back to the form and hit CTRL+Z.

Visual Studio: How to show Overloads in IntelliSense?

Once code has been written, the only way I know of to view the overloads for a method is to actually edit the method by deleting the Parenthesis () and reopening them.
Is there a shortcut key that I could press to activate this instead of having to edit my files?
For an example, please reference the ShowDialog Overload screen shot below:
With your cursor inside the parentheses, use the keyboard shortcut Ctrl-Shift-Space. If you changed the default, this corresponds to Edit.ParameterInfo.
Example:
Ctrl+Shift+Space shows the Edit.ParameterInfo for the selected method, and by selected method I mean the caret must be within the method parentheses.
Here is the Visual Studio 2010 Keybinding Poster.
And for those still using 2008.
Tested only on Visual Studio 2010.
Place your cursor within the (), press Ctrl+K, then P.
Now navigate by pressing the ↑ / ↓ arrow keys.
The default key binding for this is Ctrl+Shift+Space.
The underlying Visual Studio command is Edit.ParameterInfo.
If the standard keybinding doesn't work for you (possible in some profiles) then you can change it via the keyboard options page
Tools -> Options
Keyboard
Type in Edit.ParameterInfo
Change the shortcut key
Hit Assign
It happens that none of the above methods work. Key binding is proper, but tool tip simply doesn't show in any case, neither as completion help or on demand.
To fix it just go to Tools\Text Editor\C# (or all languages) and check the 'Parameter Information'. Now it should work
Great question; I had the same issue. Turns out that there is indeed a keyboard shortcut to bring up this list: Ctrl+Shift+Space (a variation of the basic IntelliSense shortcut of Ctrl+Space).
The command Edit.ParameterInfo (mapped to Ctrl+Shift+Space by default) will show the overload tooltip if it's invoked when the cursor is inside the parameter brackets of a method call.
The command Edit.QuickInfo (mapped to Ctrl+KCtrl+I by default) will show the tooltip that you'd see if you moused over the cursor location.
I know this is an old post, but for the newbies like myself who still hit this page this might be useful.
when you hover on a method you get a non clickable info-box whereas if you just write a comma in the method parenthesis the IntelliSense will offer you the beloved info-box with the clickable arrows.
Every once and a while the suggestions above stop working, if I restart Visual Studio they start working again though.
you mean's change overload.
just Press Shift + ↑ / ↓
Mine showed up in VS2010 after writing the first parenthesis..
so, prams.Add(
After doings something like that, the box with the up and down arrows appeared.

Categories

Resources