public void RegisterCallbacks( AstManager astManager, ISolution solution, ProjectModelViewHost host, DteProtocolModel model ) { model.Solution_FileName.SetWithReadLock(() => solution.SolutionFilePath.FullPath); model.Solution_Count.SetWithReadLock(() => solution.GetAllProjects().Count); model.Solution_Item.SetWithReadLock(index => { var projects = solution.GetAllProjects(); if (projects.Count < index) { return(new Rider.Model.ProjectModel(-1)); } var project = projects.ElementAt(index - 1); int id = host.GetIdByItem(project); return(new Rider.Model.ProjectModel(id)); }); model.Solution_get_Projects.SetWithReadLock(() => solution .GetAllProjects() .Select(host.GetIdByItem) .Where(id => id != 0) .Select(id => new Rider.Model.ProjectModel(id)) .AsList()); }
public void RegisterCallbacks( AstManager astManager, ISolution solution, ProjectModelViewHost host, DteProtocolModel model ) { model.ProjectItem_get_Name.SetWithReadLock(projectItemModel => host.GetItemById <IProjectItem>(projectItemModel.Id)?.Name ?? ""); model.ProjectItem_set_Name.SetWithReadLock(request => { var item = host.GetItemById <IProjectItem>(request.Model.Id); if (item == null) { return(Unit.Instance); } solution.InvokeUnderTransaction(cookie => cookie.Rename(item, request.NewName)); return(Unit.Instance); }); model.ProjectItem_get_Kind.SetWithReadLock(projectItemModel => host.GetItemById <IProjectItem>(projectItemModel.Id)?.Kind switch { ProjectItemKind.PHYSICAL_FILE => ProjectItemKindModel.PhysicalFile, ProjectItemKind.PHYSICAL_DIRECTORY => ProjectItemKindModel.PhysicalFolder, ProjectItemKind.PROJECT => ProjectItemKindModel.Project, ProjectItemKind.VIRTUAL_DIRECTORY => ProjectItemKindModel.VirtualDirectory, _ => ProjectItemKindModel.Unknown, });
public void RegisterCallbacks( AstManager astManager, ISolution solution, ProjectModelViewHost host, DteProtocolModel model ) { model.Project_get_Name.SetWithReadLock(projectModel => host.GetItemById <IProject>(projectModel.Id)?.Name ?? ""); model.Project_set_Name.SetWithReadLock(request => { string name = request.NewName; var project = host.GetItemById <IProject>(request.Model.Id); if (project == null) { return(Unit.Instance); } solution.InvokeUnderTransaction(cookie => cookie.Rename(project, name)); return(Unit.Instance); }); model.Project_get_FileName.SetWithReadLock(projectModel => host.GetItemById <IProject>(projectModel.Id)?.ProjectFile?.Name ?? ""); model.Project_Delete.SetWithReadLock(projectModel => { var project = host.GetItemById <IProject>(projectModel.Id); if (project == null) { return(Unit.Instance); } solution.InvokeUnderTransaction(cookie => cookie.Remove(project)); return(Unit.Instance); }); }
protected override void DoRegisterCallbacks( ProjectModelViewHost host, DteProtocolModel model ) { MapWithAstManager <ITypeDeclaration, ITypeElement, List <CodeElementModel> >( model.CodeElement_get_Bases, node => GetSuperTypes(node.DeclaredElement).AsList(), element => GetSuperTypes(element).AsList(), type => new List <CodeElementModel> { ToModel(TypeFactory.CreateTypeByCLRName("System.Array", type.Module)) } ); MapWithAstManager <ICSharpTypeDeclaration, ITypeElement, CodeElementModel>( model.CodeElement_get_Namespace, CreateNamespaceModel, element => ToModel(element.GetContainingNamespace()), type => throw new NotImplementedException() ); IEnumerable <CodeElementModel> GetSuperTypes(ITypeElement declaredType) => from typeElement in declaredType.NotNull().GetSuperTypeElements() where typeElement != null let child = ToModel(typeElement) where child != null select child; }
protected override void DoRegisterCallbacks( ProjectModelViewHost host, DteProtocolModel model ) { MapWithAstManager( model.CodeElement_get_Children, node => node.GetEnvDTEModelChildren().Select(CreateCodeElementModel).ToList(), element => throw new NotImplementedException(), type => throw new InvalidOperationException() ); MapWithAstManager( model.CodeElement_get_Access, GetAccessRights, GetAccessRights, type => throw new NotImplementedException()); MapWithAstManager( model.CodeElement_get_Name, ElementNameProvider.FindName, element => element.ShortName, type => type.GetPresentableName(CSharpLanguage.Instance.NotNull()) ); MapWithAstManager( model.CodeElement_get_FullName, node => { if (!(node is ICSharpDeclaration declaration)) { return(null); } return(CSharpSharedImplUtil.GetQualifiedName(declaration)); },
public void RegisterCallbacks( AstManager astManager, ISolution solution, ProjectModelViewHost host, DteProtocolModel model ) { model.FileCodeModel_get_CodeElements.SetWithReadLock(projectItemModel => { var projectFile = host.GetItemById <IProjectFile>(projectItemModel.Id); var psiFile = projectFile ?.ToSourceFile() ?.GetPrimaryPsiFile(); if (psiFile == null) { return(new List <CodeElementModel>()); } var query = from child in psiFile.GetEnvDTEModelChildren() let childId = astManager.GetOrCreateId(child) let childTypeId = PsiElementRegistrar.GetTypeId(child) select new CodeElementModel(childTypeId, childId); return(query.ToList()); }); }
protected override void DoRegisterCallbacks(ProjectModelViewHost host, DteProtocolModel model) { MapWithAstManager <IParameterDeclaration, IParameter, CodeElementModel>( model.CodeParameter_get_Type, node => ToModel(node.DeclaredElement.NotNull().Type), parameter => ToModel(parameter.Type), type => throw new InvalidOperationException() ); }
protected override void DoRegisterCallbacks(ProjectModelViewHost host, DteProtocolModel model) { MapWithAstManager <IFunctionDeclaration, IFunction, CodeElementModel>( model.CodeFunction_get_Type, node => ToModel(node.DeclaredElement.NotNull().ReturnType), function => ToModel(function.ReturnType), type => throw new InvalidOperationException() ); }
public void RegisterCallbacks( AstManager astManager, ISolution solution, ProjectModelViewHost host, DteProtocolModel model ) { AstManager = astManager; DoRegisterCallbacks(host, model); }
public void RegisterCallbacks( AstManager astManager, ISolution solution, ProjectModelViewHost host, DteProtocolModel model ) { model.DTE_Name.SetWithReadLock(() => "JetBrains Rider"); model.DTE_FileName.SetWithReadLock(() => FileSystemPath .Parse(AppDomain.CurrentDomain.BaseDirectory) .Combine(AppDomain.CurrentDomain.FriendlyName) .FullPath ); model.DTE_CommandLineArgs.SetWithReadLock(() => Environment.GetCommandLineArgs().AggregateString(" ")); }
private void RegisterCallbacks( [NotNull] DteProtocolModel model, [NotNull] ISolution solution ) { var host = solution.GetComponent <ProjectModelViewHost>(); // This manager will be stored in closures of callbacks. // Since the entire protocol will be deleted on file execution end, // this shouldn't cause memory leaks var astManager = new AstManager(); foreach (var provider in solution.GetComponents <IEnvDteCallbackProvider>()) { provider.RegisterCallbacks(astManager, solution, host, model); } }
private void SetupModel(Lifetime lifetime, ISolution solution) { var scheduler = SingleThreadScheduler.RunOnSeparateThread(lifetime, Host); var server = new SocketWire.Server(lifetime, scheduler); Port = server.Port; var serializers = new Serializers(); var identities = new Identities(IdKind.Server); scheduler.Queue(() => { var protocol = new Protocol(Protocol, serializers, identities, scheduler, server, lifetime); var model = new DteProtocolModel(lifetime, protocol); RegisterCallbacks(model, solution); }); }
public DteImplementation([NotNull] DteProtocolModel dteProtocolModel) { DteProtocolModel = dteProtocolModel; Solution = new SolutionImplementation(this); }
protected abstract void DoRegisterCallbacks( [NotNull] ProjectModelViewHost host, [NotNull] DteProtocolModel model );