Daniel --
Getting from the editor to the project is a multiple step process. First, you get the filename of the file in the editor, and from there you can find the containing project.
Assuming you've got an IWPFTextView, you can get the filename like this:
public static string GetFilePath(Microsoft.VisualStudio.Text.Editor.IWpfTextView wpfTextView)
{
Microsoft.VisualStudio.Text.ITextDocument document;
if ((wpfTextView == null) ||
(!wpfTextView.TextDataModel.DocumentBuffer.Properties.TryGetProperty(typeof(Microsoft.VisualStudio.Text.ITextDocument), out document)))
return String.Empty;
// If we have no document, just ignore it.
if ((document == null) || (document.TextBuffer == null))
return String.Empty;
return document.FilePath;
}
Once you've got a filename, you can get it's parent project like this:
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Interop;
public static Project GetContainingProject(string fileName)
{
if (!String.IsNullOrEmpty(fileName))
{
var dte2 = (DTE2)Package.GetGlobalService(typeof(SDTE));
if (dte2 != null)
{
var prjItem = dte2.Solution.FindProjectItem(fileName);
if (prjItem != null)
return prjItem.ContainingProject;
}
}
return null;
}
From the project you can get to the codemodel, and I assume the references, but I haven't needed to do that yet.
Hope this helps...
~ Cameron