diff --git a/Nodejs/Product/Nodejs/Guids.cs b/Nodejs/Product/Nodejs/Guids.cs index 7772f7d75..b548d38d8 100644 --- a/Nodejs/Product/Nodejs/Guids.cs +++ b/Nodejs/Product/Nodejs/Guids.cs @@ -24,8 +24,6 @@ static class Guids { public const string NodejsPackageString = "FE8A8C3D-328A-476D-99F9-2A24B75F8C7F"; public const string NodejsCmdSetString = "695e37e2-c6df-4e0a-8833-f688e4c65f1f"; public const string NodejsDebugLanguageString = "{65791609-BA29-49CF-A214-DBFF8AEC3BC2}"; - public const string NodejsEditorFactoryString = "88941496-93F4-4E37-83AF-AFE087415334"; - public const string NodejsEditorFactoryPromptEncodingString = "C8576E92-EFB6-4414-8F63-C84D474A539E"; //do not remove the curly braces. Without curly braces, in certain cases some language service features (e.g. snippets) will fail to load because //some comparisons in native code surround the guid string with curlies, and they'll fail to match unless we also surround the guid string with curlies. public const string NodejsLanguageInfoGuidString = "ABD5E8A5-5A35-4BE9-BCAF-E10C1212CB40"; @@ -58,7 +56,6 @@ static class Guids { public static readonly Guid NodejsBaseProjectFactory = new Guid(NodejsBaseProjectFactoryString); public static readonly Guid NodejsCmdSet = new Guid(NodejsCmdSetString); - public static readonly Guid NodejsEditorFactory = new Guid(NodejsEditorFactoryString); public static readonly Guid NodejsDebugLanguage = new Guid(NodejsDebugLanguageString); public static readonly Guid NodejsNpmCmdSet = new Guid(NodejsNpmCmdSetString); public static readonly Guid TypeScriptLanguageInfo = new Guid(TypeScriptLanguageInfoString); diff --git a/Nodejs/Product/Nodejs/Nodejs.csproj b/Nodejs/Product/Nodejs/Nodejs.csproj index 882778381..d70324fef 100644 --- a/Nodejs/Product/Nodejs/Nodejs.csproj +++ b/Nodejs/Product/Nodejs/Nodejs.csproj @@ -638,7 +638,6 @@ - diff --git a/Nodejs/Product/Nodejs/NodejsEditorFactory.cs b/Nodejs/Product/Nodejs/NodejsEditorFactory.cs deleted file mode 100644 index 6368c6f54..000000000 --- a/Nodejs/Product/Nodejs/NodejsEditorFactory.cs +++ /dev/null @@ -1,340 +0,0 @@ -//*********************************************************// -// Copyright (c) Microsoft. All rights reserved. -// -// Apache 2.0 License -// -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -// implied. See the License for the specific language governing -// permissions and limitations under the License. -// -//*********************************************************// - -using System; -using System.ComponentModel.Composition; -using System.Runtime.InteropServices; -using Microsoft.VisualStudio; -using Microsoft.VisualStudio.ComponentModelHost; -using Microsoft.VisualStudio.Editor; -using Microsoft.VisualStudio.OLE.Interop; -using Microsoft.VisualStudio.Shell; -using Microsoft.VisualStudio.Shell.Interop; -using Microsoft.VisualStudio.TextManager.Interop; -using Microsoft.VisualStudio.Utilities; -using IOleServiceProvider = Microsoft.VisualStudio.OLE.Interop.IServiceProvider; - -namespace Microsoft.NodejsTools { - /// - /// Common factory for creating our editor - /// - [Guid(Guids.NodejsEditorFactoryString)] - class NodejsEditorFactory : IVsEditorFactory { - - [Export, Name(NodejsConstants.Nodejs), BaseDefinition("text")] - internal static ContentTypeDefinition ContentTypeDefinition = null; - - private NodejsPackage _package; - private ServiceProvider _serviceProvider; - private readonly bool _promptEncodingOnLoad; - - public NodejsEditorFactory(NodejsPackage package) { - _package = package; - } - - public NodejsEditorFactory(NodejsPackage package, bool promptEncodingOnLoad) { - _package = package; - _promptEncodingOnLoad = promptEncodingOnLoad; - } - - #region IVsEditorFactory Members - - public virtual int SetSite(Microsoft.VisualStudio.OLE.Interop.IServiceProvider psp) { - _serviceProvider = new ServiceProvider(psp); - return VSConstants.S_OK; - } - - public virtual object GetService(Type serviceType) { - return _serviceProvider.GetService(serviceType); - } - - // This method is called by the Environment (inside IVsUIShellOpenDocument:: - // OpenStandardEditor and OpenSpecificEditor) to map a LOGICAL view to a - // PHYSICAL view. A LOGICAL view identifies the purpose of the view that is - // desired (e.g. a view appropriate for Debugging [LOGVIEWID_Debugging], or a - // view appropriate for text view manipulation as by navigating to a find - // result [LOGVIEWID_TextView]). A PHYSICAL view identifies an actual type - // of view implementation that an IVsEditorFactory can create. - // - // NOTE: Physical views are identified by a string of your choice with the - // one constraint that the default/primary physical view for an editor - // *MUST* use a NULL string as its physical view name (*pbstrPhysicalView = NULL). - // - // NOTE: It is essential that the implementation of MapLogicalView properly - // validates that the LogicalView desired is actually supported by the editor. - // If an unsupported LogicalView is requested then E_NOTIMPL must be returned. - // - // NOTE: The special Logical Views supported by an Editor Factory must also - // be registered in the local registry hive. LOGVIEWID_Primary is implicitly - // supported by all editor types and does not need to be registered. - // For example, an editor that supports a ViewCode/ViewDesigner scenario - // might register something like the following: - // HKLM\Software\Microsoft\VisualStudio\9.0\Editors\ - // {...guidEditor...}\ - // LogicalViews\ - // {...LOGVIEWID_TextView...} = s '' - // {...LOGVIEWID_Code...} = s '' - // {...LOGVIEWID_Debugging...} = s '' - // {...LOGVIEWID_Designer...} = s 'Form' - // - public virtual int MapLogicalView(ref Guid logicalView, out string physicalView) { - // initialize out parameter - physicalView = null; - - bool isSupportedView = false; - // Determine the physical view - if (VSConstants.LOGVIEWID_Primary == logicalView || - VSConstants.LOGVIEWID_Debugging == logicalView || - VSConstants.LOGVIEWID_Code == logicalView || - VSConstants.LOGVIEWID_TextView == logicalView) { - // primary view uses NULL as pbstrPhysicalView - isSupportedView = true; - } else if (VSConstants.LOGVIEWID_Designer == logicalView) { - physicalView = "Design"; - isSupportedView = true; - } - - if (isSupportedView) - return VSConstants.S_OK; - else { - // E_NOTIMPL must be returned for any unrecognized rguidLogicalView values - return VSConstants.E_NOTIMPL; - } - } - - public virtual int Close() { - _serviceProvider?.Dispose(); - return VSConstants.S_OK; - } - - public virtual int CreateEditorInstance( - uint createEditorFlags, - string documentMoniker, - string physicalView, - IVsHierarchy hierarchy, - uint itemid, - System.IntPtr docDataExisting, - out System.IntPtr docView, - out System.IntPtr docData, - out string editorCaption, - out Guid commandUIGuid, - out int createDocumentWindowFlags) { - // Initialize output parameters - docView = IntPtr.Zero; - docData = IntPtr.Zero; - commandUIGuid = this.GetType().GUID; - createDocumentWindowFlags = 0; - editorCaption = null; - - // Validate inputs - if ((createEditorFlags & (VSConstants.CEF_OPENFILE | VSConstants.CEF_SILENT)) == 0) { - return VSConstants.E_INVALIDARG; - } - - // Get a text buffer - IVsTextLines textLines = GetTextBuffer(docDataExisting, documentMoniker); - - // Assign docData IntPtr to either existing docData or the new text buffer - if (docDataExisting != IntPtr.Zero) { - docData = docDataExisting; - Marshal.AddRef(docData); - } else { - docData = Marshal.GetIUnknownForObject(textLines); - } - - try { - docView = CreateDocumentView(documentMoniker, physicalView, hierarchy, itemid, textLines, docDataExisting == IntPtr.Zero, out editorCaption, out commandUIGuid); - } finally { - if (docView == IntPtr.Zero) { - if (docDataExisting != docData && docData != IntPtr.Zero) { - // Cleanup the instance of the docData that we have addref'ed - Marshal.Release(docData); - docData = IntPtr.Zero; - } - } - } - return VSConstants.S_OK; - } - - - #endregion - - #region Helper methods - - private IVsTextLines GetTextBuffer(System.IntPtr docDataExisting, string filename) { - IVsTextLines textLines; - if (docDataExisting == IntPtr.Zero) { - // Create a new IVsTextLines buffer. - Type textLinesType = typeof(IVsTextLines); - Guid riid = textLinesType.GUID; - Guid clsid = typeof(VsTextBufferClass).GUID; - textLines = _package.CreateInstance(ref clsid, ref riid, textLinesType) as IVsTextLines; - - // set the buffer's site - ((IObjectWithSite)textLines).SetSite(_serviceProvider.GetService(typeof(IOleServiceProvider))); - } else { - // Use the existing text buffer - Object dataObject = Marshal.GetObjectForIUnknown(docDataExisting); - textLines = dataObject as IVsTextLines; - if (textLines == null) { - // Try get the text buffer from textbuffer provider - IVsTextBufferProvider textBufferProvider = dataObject as IVsTextBufferProvider; - if (textBufferProvider != null) { - textBufferProvider.GetTextBuffer(out textLines); - } - } - if (textLines == null) { - // Unknown docData type then, so we have to force VS to close the other editor. - ErrorHandler.ThrowOnFailure((int)VSConstants.VS_E_INCOMPATIBLEDOCDATA); - } - - } - return textLines; - } - - protected void InitializeLanguageService(IVsTextLines textLines, Guid langSid) { - IVsUserData userData = textLines as IVsUserData; - if (userData != null) { - if (langSid != Guid.Empty) { - Guid vsCoreSid = Guids.DefaultLanguageService; - Guid currentSid; - ErrorHandler.ThrowOnFailure(textLines.GetLanguageServiceID(out currentSid)); - // If the language service is set to the default SID, then - // set it to our language - if (currentSid == vsCoreSid) { - ErrorHandler.ThrowOnFailure(textLines.SetLanguageServiceID(ref langSid)); - } else if (currentSid != langSid) { - // Some other language service has it, so return VS_E_INCOMPATIBLEDOCDATA - throw new COMException("Incompatible doc data", VSConstants.VS_E_INCOMPATIBLEDOCDATA); - } - - Guid bufferDetectLang = VSConstants.VsTextBufferUserDataGuid.VsBufferDetectLangSID_guid; - ErrorHandler.ThrowOnFailure(userData.SetData(ref bufferDetectLang, false)); - } - } - } - - private void InitializeLanguageService(IVsTextLines textLines) { - InitializeLanguageService(textLines, typeof(NodejsLanguageInfo).GUID); - } - - private IntPtr CreateDocumentView(string documentMoniker, string physicalView, IVsHierarchy hierarchy, uint itemid, IVsTextLines textLines, bool createdDocData, out string editorCaption, out Guid cmdUI) { - //Init out params - editorCaption = string.Empty; - cmdUI = Guid.Empty; - - if (string.IsNullOrEmpty(physicalView)) { - // create code window as default physical view - return CreateCodeView(documentMoniker, textLines, hierarchy, itemid, createdDocData, ref editorCaption, ref cmdUI); - } - - // We couldn't create the view - // Return special error code so VS can try another editor factory. - ErrorHandler.ThrowOnFailure((int)VSConstants.VS_E_UNSUPPORTEDFORMAT); - - return IntPtr.Zero; - } - - private IntPtr CreateCodeView(string documentMoniker, IVsTextLines textLines, IVsHierarchy hierarchy, uint itemid, bool createdDocData, ref string editorCaption, ref Guid cmdUI) { - Type codeWindowType = typeof(IVsCodeWindow); - Guid riid = codeWindowType.GUID; - Guid clsid = typeof(VsCodeWindowClass).GUID; - var compModel = (IComponentModel)_package.GetService(typeof(SComponentModel)); - var adapterService = compModel.GetService(); - - var window = adapterService.CreateVsCodeWindowAdapter((IOleServiceProvider)_serviceProvider.GetService(typeof(IOleServiceProvider))); - ErrorHandler.ThrowOnFailure(window.SetBuffer(textLines)); - ErrorHandler.ThrowOnFailure(window.SetBaseEditorCaption(null)); - ErrorHandler.ThrowOnFailure(window.GetEditorCaption(READONLYSTATUS.ROSTATUS_Unknown, out editorCaption)); - - IVsUserData userData = textLines as IVsUserData; - if (userData != null) { - if (_promptEncodingOnLoad) { - var guid = VSConstants.VsTextBufferUserDataGuid.VsBufferEncodingPromptOnLoad_guid; - userData.SetData(ref guid, (uint)1); - } - } - var textMgr = (IVsTextManager)_package.GetService(typeof(SVsTextManager)); - - var bufferEventListener = new TextBufferEventListener(textLines); - if (!createdDocData) { - // we have a pre-created buffer, go ahead and initialize now as the buffer already - // exists and is initialized. - bufferEventListener.OnLoadCompleted(0); - } - - InitializeLanguageService(textLines); - - cmdUI = VSConstants.GUID_TextEditorFactory; - - return Marshal.GetIUnknownForObject(window); - } - - #endregion - - /// - /// Listens for the text buffer to finish loading and then sets up our projection - /// buffer. - /// - internal sealed class TextBufferEventListener : IVsTextBufferDataEvents { - private readonly IVsTextLines _textLines; - private readonly uint _cookie; - private readonly IConnectionPoint _cp; - - public TextBufferEventListener(IVsTextLines textLines) { - _textLines = textLines; - - var cpc = textLines as IConnectionPointContainer; - var bufferEventsGuid = typeof(IVsTextBufferDataEvents).GUID; - cpc.FindConnectionPoint(ref bufferEventsGuid, out _cp); - _cp.Advise(this, out _cookie); - } - - #region IVsTextBufferDataEvents - - public void OnFileChanged(uint grfChange, uint dwFileAttrs) { - } - - public int OnLoadCompleted(int fReload) { - _cp.Unadvise(_cookie); - - Guid langSvcGuid = typeof(NodejsLanguageInfo).GUID; - _textLines.SetLanguageServiceID(ref langSvcGuid); - - return VSConstants.S_OK; - } - - #endregion - } - } - - [Guid(Guids.NodejsEditorFactoryPromptEncodingString)] - class NodejsEditorFactoryPromptForEncoding : NodejsEditorFactory { - public NodejsEditorFactoryPromptForEncoding(NodejsPackage package) : base(package, true) { } - public override int CreateEditorInstance(uint createEditorFlags, string documentMoniker, string physicalView, VisualStudio.Shell.Interop.IVsHierarchy hierarchy, uint itemid, IntPtr docDataExisting, out IntPtr docView, out IntPtr docData, out string editorCaption, out Guid commandUIGuid, out int createDocumentWindowFlags) { - if (docDataExisting != IntPtr.Zero) { - docView = IntPtr.Zero; - docData = IntPtr.Zero; - editorCaption = null; - commandUIGuid = Guid.Empty; - createDocumentWindowFlags = 0; - return VSConstants.VS_E_INCOMPATIBLEDOCDATA; - } - - return base.CreateEditorInstance(createEditorFlags, documentMoniker, physicalView, hierarchy, itemid, docDataExisting, out docView, out docData, out editorCaption, out commandUIGuid, out createDocumentWindowFlags); - } - } -} diff --git a/Nodejs/Product/Nodejs/NodejsPackage.cs b/Nodejs/Product/Nodejs/NodejsPackage.cs index 40a75e3c5..afbb786fa 100644 --- a/Nodejs/Product/Nodejs/NodejsPackage.cs +++ b/Nodejs/Product/Nodejs/NodejsPackage.cs @@ -76,10 +76,6 @@ namespace Microsoft.NodejsTools { [ProvideDebugPortSupplier("Node remote debugging", typeof(NodeRemoteDebugPortSupplier), NodeRemoteDebugPortSupplier.PortSupplierId)] [ProvideMenuResource(1000, 1)] // This attribute is needed to let the shell know that this package exposes some menus. [ProvideBraceCompletion(NodejsConstants.Nodejs)] - [ProvideEditorExtension2(typeof(NodejsEditorFactory), NodeJsFileType, 50, "*:1", ProjectGuid = "{78D985FC-2CA0-4D08-9B6B-35ACD5E5294A}", NameResourceID = 102, DefaultName = "server", TemplateDir = ".\\NullPath")] - [ProvideEditorExtension2(typeof(NodejsEditorFactoryPromptForEncoding), NodeJsFileType, 50, "*:1", ProjectGuid = "{78D985FC-2CA0-4D08-9B6B-35ACD5E5294A}", NameResourceID = 113, DefaultName = "server")] - [ProvideEditorLogicalView(typeof(NodejsEditorFactory), VSConstants.LOGVIEWID.TextView_string)] - [ProvideEditorLogicalView(typeof(NodejsEditorFactoryPromptForEncoding), VSConstants.LOGVIEWID.TextView_string)] [ProvideProjectItem(typeof(BaseNodeProjectFactory), NodejsConstants.Nodejs, "FileTemplates\\NewItem", 0)] [ProvideLanguageTemplates("{349C5851-65DF-11DA-9384-00065B846F21}", NodejsConstants.JavaScript, Guids.NodejsPackageString, "Web", "Node.js Project Templates", "{" + Guids.NodejsBaseProjectFactoryString + "}", ".js", NodejsConstants.Nodejs, "{" + Guids.NodejsBaseProjectFactoryString + "}")] [ProvideTextEditorAutomation(NodejsConstants.Nodejs, 106, 102, ProfileMigrationType.PassThrough)] @@ -206,8 +202,6 @@ protected override void Initialize() { ((IServiceContainer)this).AddService(typeof(ClipboardServiceBase), new ClipboardService(), true); RegisterProjectFactory(new NodejsProjectFactory(this)); - RegisterEditorFactory(new NodejsEditorFactory(this)); - RegisterEditorFactory(new NodejsEditorFactoryPromptForEncoding(this)); RegisterEditorFactory(new JadeEditorFactory(this)); // Add our command handlers for menu (commands must exist in the .vsct file) @@ -579,11 +573,11 @@ private bool ShouldQuerySurveryNewsServer() { } internal static void NavigateTo(string filename, int line, int col) { - VsUtilities.NavigateTo(Instance, filename, NodejsProjectNode.IsNodejsFile(filename) ? typeof(NodejsEditorFactory).GUID : Guid.Empty, line, col); + VsUtilities.NavigateTo(Instance, filename, Guid.Empty, line, col); } internal static void NavigateTo(string filename, int pos) { - VsUtilities.NavigateTo(Instance, filename, NodejsProjectNode.IsNodejsFile(filename) ? typeof(NodejsEditorFactory).GUID : Guid.Empty, pos); + VsUtilities.NavigateTo(Instance, filename, Guid.Empty, pos); } /// diff --git a/Nodejs/Product/Nodejs/NodejsProject.cs b/Nodejs/Product/Nodejs/NodejsProject.cs index 3f3b6d9dd..07c0e2137 100644 --- a/Nodejs/Product/Nodejs/NodejsProject.cs +++ b/Nodejs/Product/Nodejs/NodejsProject.cs @@ -540,15 +540,8 @@ out project private int OpenWithNodejsEditor(uint selectionItemId) { // If the item type of this file is not compile, we don't actually want to open with Nodejs and should instead use the default. - Guid ourEditor; + Guid ourEditor = Guid.Empty; var properties = GetExtensionObject(_innerVsHierarchy, selectionItemId).Properties; - try { - var itemType = properties.Item("ItemType").Value; - ourEditor = Guid.Empty; - } catch (ArgumentException) { - // no item type, file is excluded from project. - ourEditor = Guids.NodejsEditorFactory; - } Guid view = Guid.Empty; IVsWindowFrame frame;