Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"/v:Minimal",
// "/p:Configuration=Release",
"/p:VSVersion=2022",
"/p:DeployExtension=true",
"${workspaceFolder}/src/Eto.DevExtension.VisualStudio.Windows/Eto.DevExtension.VisualStudio.Windows.csproj",
],
},
Expand Down
50 changes: 27 additions & 23 deletions src/Eto.DevExtension.VisualStudio.Windows/Editor/EditorFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.VisualStudio.OLE.Interop;
using Eto.Designer;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Editor;
using Microsoft.VisualStudio.Utilities;
using Eto.DevExtension.VisualStudio.Windows.Wizards;
using IOleServiceProvider = Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
Expand Down Expand Up @@ -269,7 +270,7 @@ public static IEnumerable<string> GetReferences(EnvDTE.Project project)
foreach (VSLangProj.Reference reference in vsproject.References)
{
if (reference.SourceProject == null)
{
{
//skip framework assemblies
//if (((dynamic)reference).AutoReferenced)
// continue;
Expand Down Expand Up @@ -319,15 +320,21 @@ IVsTextLines GetTextBuffer(IntPtr punkDocDataExisting, string fileName, IVsProje
, dwFlags: (uint)_EDITORREGFLAGS.RIEF_ENABLECACHING
, pFactory: null
, ppEditor: out invisibleEditor);
if (invisibleEditor == null) // sometimes when closing files this will be null?
return null;
IntPtr docDataPointer;
var guidIVsTextLines = typeof(IVsTextLines).GUID;
result = invisibleEditor.GetDocData(
fEnsureWritable: 1
, riid: ref guidIVsTextLines
, ppDocData: out docDataPointer);
textBuffer = (IVsTextLines)Marshal.GetObjectForIUnknown(docDataPointer);
if (invisibleEditor == null)
{
// on solution reload the RDT holds a deferred placeholder for this file, so load our own buffer
textBuffer = CreateTextBuffer(fileName);
}
else
{
IntPtr docDataPointer;
var guidIVsTextLines = typeof(IVsTextLines).GUID;
result = invisibleEditor.GetDocData(
fEnsureWritable: 1
, riid: ref guidIVsTextLines
, ppDocData: out docDataPointer);
textBuffer = (IVsTextLines)Marshal.GetObjectForIUnknown(docDataPointer);
}

/* set site for the doc data?
var objWSite = docData as IObjectWithSite;
Expand Down Expand Up @@ -367,6 +374,15 @@ IVsTextLines GetTextBuffer(IntPtr punkDocDataExisting, string fileName, IVsProje
return textBuffer;
}

static IVsTextLines CreateTextBuffer(string fileName)
{
ThreadHelper.ThrowIfNotOnUIThread();
var editorSvc = Services.GetComponentService<IVsEditorAdaptersFactoryService>();
var textBuffer = (IVsTextLines)editorSvc.CreateVsTextBufferAdapter(Services.ServiceProvider);
ErrorHandler.ThrowOnFailure(((IVsPersistDocData)textBuffer).LoadDocData(fileName));
return textBuffer;
}

private static void MapLanguage(IVsTextLines textBuffer, string languageSid)
{
var textManagerSvc = Services.GetService<SVsTextManager, IVsTextManager>();
Expand All @@ -384,20 +400,8 @@ public int ChooseEditorFactory(string pszMkDocument, IVsHierarchy pHier, uint it
return VSConstants.VS_E_UNSUPPORTEDFORMAT;
}

// don't touch punkDocDataExisting here; on solution reload it's a deferred doc data that throws E_PENDING
rguidLogicalView = VSConstants.LOGVIEWID.Designer_guid;
object prjItemObject;
var projectItemId = VSConstants.VSITEMID_ROOT;
pHier.GetProperty(projectItemId, (int)__VSHPROPID.VSHPROPID_ExtObject, out prjItemObject);
var proj = prjItemObject as EnvDTE.Project;

// Get or open text buffer
var textBuffer = GetTextBuffer(punkDocDataExisting, pszMkDocument, ToVsProject(proj));

if (textBuffer == null)
return VSConstants.VS_E_INCOMPATIBLEDOCDATA;



return VSConstants.S_OK;
}

Expand Down
3 changes: 3 additions & 0 deletions src/Eto.DevExtension.VisualStudio.Windows/EtoAddinPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ protected override async System.Threading.Tasks.Task InitializeAsync(Cancellatio
Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
await base.InitializeAsync(cancellationToken, progress);

// EditorFactory's static ctor initializes Eto/WPF, which must happen on the UI thread
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

//Create Editor Factory.
base.RegisterEditorFactory(new EditorFactory(this));
}
Expand Down
Loading