Custom ColorableItems in Visual Studio Extension - visual-studio-2013

I am working on a LanguageService for Visual Studio and am having issues with custom colors in Visual Studio 2013. I recently moved from Visual Studio 2010 to 2013, and now whenever I set RequestStockColors to false, I lose all syntax highlighting.
My LanguageService implements GetColorableItem and GetItemCount. I am using 9 custom colors. When I debug my language service, I have noticed that GetColorableItem is called a handful of times, but GetItemCount never gets hit.
I am using the following command-line arguments when I debug through Visual Studio:
/ranu /rootsuffix Exp
Update: I changed the name of the first 5 colors (the ones that overlap with the standard token colors) to match the standard names (e.g. "Keyword", "Identifier", etc.) and those colors now show, but none of my extra color types show up. In addition, I never see any of them appear in the Fonts and Colors configuration in Visual Studio. How do I get them to be installed there?

I recently ran into a similar issue where my custom ColorableItems weren't showing up in my syntax highlighting. I was able fix this by clearing the font and color cache.
I temporarily included the following in my Initialize method of my vs package:
IVsFontAndColorCacheManager mgr = this.GetService(typeof(SVsFontAndColorCacheManager)) as IVsFontAndColorCacheManager;
mgr.ClearAllCaches();
This fixed things for me. This fix shouldn't require including the 6 default values or require any additional ClassificationFormatDefinition classes.
NOTE: Worth mentioning that I also never see GetItemCount() called, but clearing the cache fixed the primary issue.
Credit: Also some credit to a comment by Ed Dore on this thread http://www.databaseforum.info/8/1217583.aspx that helped me find my fix.

It turns out I needed to create an instance of ClassificationFormatDefinition for each of my custom colors and export them as a EditorFormatDefinition type. Once I did this, they showed up in the Fonts and Colors page and also showed up in syntax highlighting.
For each color beyond the default 6, I added a class definition as follows:
[Export(typeof(EditorFormatDefinition))]
[ClassificationType(ClassificationTypeNames = "<name of color>")]
[Name("<name of color>")]
[UserVisible(true)]
[Order(Before = Priority.Default)]
internal sealed class ExampleColor: ClassificationFormatDefinition
{
public ExampleColor()
{
this.DisplayName = "<name of color>";
this.ForegroundColor = System.Windows.Media.Color.FromArgb(0, 0, 128, 128);
}
}
I am still seeing no hits on my GetItemCount() method, however.

Related

Visual Studio Intellisense describing the property/method not working

I was using Visual Studio 2012 and it used to give the description of a property/method, which doesn't seem to work in VS2019. Is there an option that I will have to enable for this to work?
Below screesnhot is an example of File Input/Output operation:
When I scroll/hover over ios::app, it should give a description "Append to the end of the file" which it does not.
Second concern is that it is giving me a lot of other options as well (marked as * in VS). Is there an option to disable that permanently?
Final concern is that, when I hover over a function, it will display the parameters that the function is expecting (Or list of suggestions if the function is overloaded). But for some reason, in the below case, it is displaying along with namespace. Is there an option to disable that?
public static constexpr std::_losb::_Openmode std::_losb::app = (std::_losb::_Openmode)8

Is there a keyboard shortcut to enable/disable "Common Language Runtime Exceptions" in Visual Studio exception settings?

I find myself enabling and disabling the "Common Language Runtime Exceptions" checkbox in Exception Settings with considerable regularity. I'm tired of having to open the window every time. Is there a keyboard shortcut?
EDIT: as the answer as of June 2020 appears to be "no", I've requested a feature here: https://developercommunity.visualstudio.com/idea/1073035/keyboard-shortcut-to-enabledisable-the-common-runt.html
Is there a keyboard shortcut to enable/disable “Common Language
Runtime Exceptions” in Visual Studio exception settings?
I think there is no such quick shortcut to do that.
Actually, the shortcut for the Exception window is Ctrl+Alt+E, you can call such window by that.
However, VS only has a shortcut key to open a window, and there is no shortcut key to enable or disable an exception, and there are many different types of exceptions in the exception window. So it can be a bit difficult.
So you should use shortcut Ctrl+Alt+E to open Exception and then set the exception manually.
Besides, if you still want that feature to have a keyboard shortcut to enable/disable Common Language Runtime Exceptions, you can suggest this feature on our User Voice Forum.
After that, you can share the link with us here and anyone who is interested in this feature will vote it so that it will get more attention from Microsoft.
It is managed by the DebuggerServiceHelper class in VSDebugCoreUI.dll:
ExceptionSettingsBatchOperation{_operationDepth=3} DebuggerServiceHelper.BeginExceptionBatchOperation()
DebuggerServiceHelper.UpdateException(EXCEPTION_INFO150{bstrProgramName=null, bstrExceptionName="Common Language Runtime Exceptions", dwCode=0, dwState=16418})
ExceptionSettingsBatchOperation.EndBatchOperation()
But these are all internal classes and not easily accessible from external code.
Another approach is to find this WPF CheckBox on screen (by the TextBlock following it with the given Text property) and click it programmatically.
I really wish Exception Breaker worked for later versions of Visual Studio.
In combination with this answer to a similar question, I was able to get something to work. It is not ideal, but you might give this a try.
Note: I am using Visual Studio 2019
Tool required
The free version of the Visual Commander extension that allows Visual Studio macros in later versions.
Note: I tried (a little) to use the Macros for Visual Studio extension, but with no luck
Steps
Using Visual Commander, add a new command with the code below, save and compile.
Run with one of:
Run directly from the Visual Commander UI
Modify a toolbar and add the Extensions/Command01 command to it
Add a Keyboard shortcut via Options and select VCmd.Command01
Code
Notes:
I tried toggling the <All Common Language Runtime Exceptions not in this list> item, but did not have luck with it.
I tried looping through all of the Exceptions in the group but it was really slow (i.e. 15 seconds :-( ) so I picked the most important exceptions for my project.
I was unsuccessful finding a away to toggle the parent Common Language Runtime Exceptions, but if you find it, please leave a comment.
using EnvDTE;
using EnvDTE80; // DTE2 type
using EnvDTE90; // Debugger3
public class M : VisualCommanderExt.ICommand
{
public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package)
{
var lDebugger = DTE.Debugger as Debugger3;
var lExceptionSettings = lDebugger.ExceptionGroups.Item("Common Language Runtime Exceptions");
// Use this Exception as the master toggle
bool lExceptionsEnabledToSet = !lExceptionSettings.Item("System.ArgumentException").BreakWhenThrown;
// 2 examples
lExceptionSettings.SetBreakWhenThrown(lExceptionsEnabledToSet, lExceptionSettings.Item("System.ArgumentException"));
lExceptionSettings.SetBreakWhenThrown(lExceptionsEnabledToSet, lExceptionSettings.Item("System.OutOfMemoryException"));
// This does not work to set the whole group on/off:
//lExceptionSettings.SetBreakWhenThrown(true, lExceptionSettings.Item("<All Common Language Runtime Exceptions not in this list>"));
// This is really slow
//foreach (var lExceptionSetting in lExceptionSettings)
//{
// lExceptionSettings.SetBreakWhenThrown(lExceptionsEnabledToSet, lExceptionSetting as ExceptionSetting);
//}
}
}

Options Pages are only showing after disabling and enabling my Visual Studio extension

I'm the author of a small os vs2015 extension (AsmDude) and my users complain that the options pages are only visible after disabling the extension, restarting vs, enabling the extension and restarting vs again.
I have sifted through many tutorials, examples and manuals on how to use the ProvideOptionPage attribute properly, but nothing helped.
I have run devenv.exe with /LOG, but nothing strange comes up.
I have cleaned all registry entries that this plugin makes, but no fix.
The problem exists on clean installs of visual studio 2015 (sp2)
Next are some relevant c# code snippets:
[PackageRegistration(UseManagedResourcesOnly = true)]
[InstalledProductRegistration("AsmDude", Vsix.Description, Vsix.Version)]
[ProvideAutoLoad(UIContextGuids.NoSolution)]
[Guid(Guids.GuidPackage_str)]
[ComVisible(true)]
[ProvideMenuResource("Menus.ctmenu", 1)]
[ProvideOptionPage(typeof(OptionsPageSyntaxHighlighting), "AsmDude", "Syntax Highlighting", 0, 0, true)]
public sealed class AsmDudePackage : Package {
//snip
}
[Export(typeof(DialogPage))]
[Guid(Guids.GuidOptionsPageSyntaxHighlighting)]
public class OptionsPageSyntaxHighlighting : DialogPage {
// snip
}
Question: how to debug such a vague problem? There must be a warning or error message logged somewhere that could help me pinpoint the problem.
Regards!
Edit: this question can also be found here on MSDN.

Visual Studio Extension for Custom Memory Window

My custom tool window in a Visual Studio Extension package is supposed to evaluate custom expressions during debug sessions for VS2012 and VS2013. The final goal is to build a graphical watch window. Therefore, I must fetch the value of the expression result from the debug engine.
The evaluation works fine via
IDebugStackFrame2 -> IDebugExpressionContext2 -> ParseText
IDebugExpression2 -> EvaluateSync -> IDebugProperty2
The first problem here: On Visual Studio 2013 ParseText() does not correctly report errors. But the IDebugProperty2 retrieved is valid (for valid expressions). On VS2012 I get proper errors for invalid expressions.
This is where the real problem starts. The result Property2 represents a complex custom object. In order to visualize it, a specific property from one of its base classes needs to get retrieved. In my current attempt, I am using IDebugProperty2.EnumChildren() to walk along its members up to the right place in the class hierarchy, similar as one would do in the Locals window in Visual Studio:
[result] -> base -> Raw -> base -> Non-public Members -> [private field] ... a.s.o.
This is somehow working but introduces the following problems:
Problem 1: Get an internal member of some complex object
The members and their order received from EnumChildren() seem to depend on some factors, which are not obvious to me:
* Does the object has a Debug Visualizer attached? (VS2013 ignores enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE_RAW in EnumChildren and gives back the beautified version + a "Raw View" node, VS2012 works as expected)
* Is a 'Non-public Members' node shown? Sometimes it is, sometimes not - dunno from what it depends on
* Setting of 'Just my code' (? I read about it in several posts but couldn't really figure out a reliable rule)
* ... there must be other dependencies ?
This turns out to be a really hacky way of aquiring an internal member of some complex expression result object. What could be a better way? Using IDebugProperty3 and some Debugger Visualizer tricks? Any pointer would be great.
Problem 2: VS2012 fails to give memory bytes
Once I have the private member of the result object, I use IDebugProperty2.GetMemoryBytes() in order to 'serialize' its value (a plain System.Array) and transfer it to my Custom Tool Window. While this is working in VS2013, in VS2012 IDebugProperty2.GetMemoryBytes() always returns VS_Constants.S_FALSE. I am really out of ideas here. Since there is a Memory Window in VS2012, there ought to be some way to get this working here also? What am I missing?
The code used to query the memory API:
IDebugMemoryContext2 memCtx = null;
IDebugMemoryBytes2 memBytes = null;
// getting the memory context is working ok
if (tmpProperty2.GetMemoryContext(out memCtx) == VSConstants.S_OK
// VS2012 fails here, always returns S_FALSE, memBytes remains null:
&& (tmpProperty2.GetMemoryBytes(out memBytes) == VSConstants.S_OK)) {
...
Some more context:
OS: Windows 8 and 8.1
Visual Studio: 2012 / 2013
Tool Window built with MPF (C#) in VS2013, (removed all vers. 12 references from the package before deploying to VS2012)
Debug engines: C# and Visual Basic

Track issue-related comments like "// fixes #123" in Visual Studio, similar to task list

We use an issue tracker (Redmine) for our software tasks/bugs and often mark the fixes/implementations with a comment like this:
// fixes #1234: changed this and that
Or we also mark code locations which cause a certain bug like this:
// causes #2345
Now, I am looking for a tool which can automatically track those issue-related comments in all files in the current solution and present them in a list or tree. This is similar to the task list which scans the files for comments with // TODO or // HACK. Unfortunately, it is not possible to define a new task category with just # as identifier because this character is not allowed.
Does anyone know of such a functionality, addon, or tool for VS2010 or VS2008?
This is generally a feature provided by whatever issue tracking software you use rather than a function of Visual Studio. Codebase HQ for example scans code (on commit) for speciially formatted comments that it is configured to recognise and groups the code change/commit to the record of the issue. It's web-based.
Axosoft OnTime provide a plugin for Visual Studio which allow you to work with your issues directly within the IDE.
See: http://www.axosoft.com/ontime/visual_studio_plugin
Failing that, if you only want to track bug causes between commits while you're working, then the inbuild tracker might be of use after all...
Add a tag to track with to Visual Studios configuration (I've added the CausesBug token)...
Then add the token in amongst your code:
public override bool IsApproved {
get
{
// CausesBug: 1234
return this.IsEnabled;
}
set { this.IsEnabled = value; }
}
Then each item gets listed in the Task List, displaying location in source, until you can ammend, and then say you fixed the issue in your commit, in turn getting picked up by your issue tracker.

Resources