/// <summary> /// Gets the FileCodeModel associated with current ProjectItem. /// </summary> /// <returns>LuaFileCodeModel</returns> public LuaFileCodeModel GetFileCodeModel() { LuaFileCodeModel codeModel = null; //Retrieve FileCodeModel from ProjectItem if (DTE != null) { String sFileName = DTE.ActiveDocument.ProjectItem.get_FileNames(1); codeModel = DTE.ActiveDocument.ProjectItem.FileCodeModel as LuaFileCodeModel; // LiXizhi: codeModel is always null, need to register a code model somewhere. // we will dynamically create code model based on file extension even no File Code Model is found. if (codeModel == null) { LuaCodeDomProvider domProvider = new LuaCodeDomProvider(DTE.ActiveDocument.ProjectItem); codeModel = LuaCodeModelFactory.CreateFileCodeModel(DTE.ActiveDocument.ProjectItem, domProvider, sFileName) as LuaFileCodeModel; } if (codeModel != null && !codeModel.ModelInitialized) { string text = null; try { //Retrieve TextDocument from ProjectItem var td = ((TextDocument)DTE.ActiveDocument.ProjectItem.Document.Object("TextDocument")); EditPoint ep = td.CreateEditPoint(td.StartPoint); text = ep.GetText(td.EndPoint); } catch(Exception) { // open external file if file does not belong to project. System.IO.StreamReader fileReader = new System.IO.StreamReader(sFileName); text = fileReader.ReadToEnd(); fileReader.Close(); } //Initialize FileCodeModel with parsed source code codeModel.Initialize(ParseSource(text)); } } return codeModel; }
/// <summary> /// Initializes a new instance of the <see cref="VSMDLuaCodeDomProvider"/> class. /// </summary> /// <param name="projectItem">ProjectItem instance.</param> public VSMDLuaCodeDomProvider(ProjectItem projectItem) { codeDomProvider = new LuaCodeDomProvider(projectItem); }
/// <summary> /// Initializes a new instance of the <see cref="VSMDLuaCodeDomProvider"/> class. /// </summary> /// <param name="provider">LuaCodeDomProvider instance.</param> public VSMDLuaCodeDomProvider(LuaCodeDomProvider provider) { codeDomProvider = provider; }