Reputation: 41
From an add-in, we can obtain the solution path using following way.
_applicationObject = (DTE2)application; // retrieved from OnConnection method
string solutionDir = System.IO.Path.GetDirectoryName(_applicationObject.Solution.FullName);
How would you do this via a Editor Classifier Project (Visual C# --> Extensibility--> Editor Classifier)?
I am unable to get the DTE object either from application or using the getService method.
Could someone help me please? Thanks in advance.
internal class TestQuickInfoSource : IQuickInfoSource
{
private TestQuickInfoSourceProvider m_provider;
private ITextBuffer m_subjectBuffer;
private Dictionary<string, string> m_dictionary;
private bool m_isDisposed;
private DTE2 _applicationObject;
[Import]
internal SVsServiceProvider ServiceProvider = null;
//constructor that initializes the dictionary
public TestQuickInfoSource(TestQuickInfoSourceProvider provider, ITextBuffer subjectBuffer)
{
m_provider = provider;
m_subjectBuffer = subjectBuffer;
**// HERE the dictionary with the tool-tip info is created. I would need the solution path here ideally so that I can dynamically create the dictionary from a file there. Following commented statements.**
// Get an instance of the currently running Visual Studio IDE
//DTE dte = (DTE)ServiceProvider.GetService(typeof(DTE));
//string solutionDir = System.IO.Path.GetDirectoryName(dte.Solution.FullName);
//DTE dte = (DTE)ServiceProvider.GetService(typeof(EnvDTE.DTE));
//string solutionPath = Path.GetDirectoryName(dte.Solution.FullName);
//_applicationObject = (DTE2)provider;
//string solutionPath = Path.GetDirectoryName(_applicationObject.Solution.FullName);
//string gg = System.Reflection.Assembly.GetExecutingAssembly().ToString();
//string solutionDirectory = ((EnvDTE.DTE)System.Runtime
// .InteropServices
// .Marshal
// .GetActiveObject("VisualStudio.DTE.10.0"))
// .Solution
// .FullName;
//EnvDTE.DTE dte = (EnvDTE.DTE)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE");
//string solutionDir = System.IO.Path.GetDirectoryName(dte.Solution.FullName);
//_applicationObject = (DTE2)dte;
//string solutionDir1 = System.IO.Path.GetDirectoryName(_applicationObject.Solution.FullName);
string startupPath = System.IO.Directory.GetCurrentDirectory();
//EnvDTE.DTE dte = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE));
//System.IO.Path.GetDirectoryName(dte.Solution.FullName);
//Reading Resource File
//string path = "";
//EnvDTE80.DTE2 dte2;
//dte2 = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.10.0");
//_applicationObject = (DTE2)dte2;
//if (_applicationObject.ActiveDocument != null)
//{
// string y = _applicationObject.ActiveDocument.ToString();
// string solutionPat = Path.GetDirectoryName(dte2.Solution.FullName);
//}
//Connect objConnect = new Connect();
//Array objArray = null;
//objConnect.OnConnection(dte2, ext_ConnectMode.ext_cm_AfterStartup, null, ref objArray);
//these are the method names and their descriptions
m_dictionary = new Dictionary<string, string>();
m_dictionary.Add("add", "int add(int firstInt, int secondInt)\nAdds one integer to another.");
m_dictionary.Add("subtract", "int subtract(int firstInt, int secondInt)\nSubtracts one integer from another.");
m_dictionary.Add("multiply", "int multiply(int firstInt, int secondInt)\nMultiplies one integer by another.");
m_dictionary.Add("divide", "int divide(int firstInt, int secondInt)\nDivides one integer by another.");
m_dictionary.Add("#include", "Custom Tool-Tip !");
}
Please check the comments in bold to understand the problem
Upvotes: 4
Views: 3763
Reputation: 26268
You could use GetGlobalService
, as such:
var dte2 = (DTE2)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SDTE));
but the way you usually do it, is given by @Srikanth Venugopalan. If you get "NULL", there's something wrong, and without knowing more, it's hard to help.
Upvotes: 3
Reputation: 9049
You can try importing SVsServiceProvider and get instance using the GetService
method
This walkthrough gives you an illustration on how to obtain a reference to the DTE
object.
Once you have the DTE
reference, the rest should be similar to what you would do in the add-n.
Upvotes: 0