Пример #1
0
        public ProjectState WithChangedHostDocument(HostDocument hostDocument, Func <Task <TextAndVersion> > loader)
        {
            if (hostDocument == null)
            {
                throw new ArgumentNullException(nameof(hostDocument));
            }

            if (!Documents.TryGetValue(hostDocument.FilePath, out var document))
            {
                return(this);
            }

            var documents = Documents.SetItem(hostDocument.FilePath, document.WithTextLoader(loader));

            if (ImportsToRelatedDocuments.TryGetValue(hostDocument.TargetPath, out var relatedDocuments))
            {
                foreach (var relatedDocument in relatedDocuments)
                {
                    documents = documents.SetItem(relatedDocument, documents[relatedDocument].WithImportsChange());
                }
            }

            var state = new ProjectState(this, ProjectDifference.DocumentChanged, HostProject, ProjectWorkspaceState, documents, ImportsToRelatedDocuments);

            return(state);
        }
        public List <string> GetImportDocumentTargetPaths(HostDocument hostDocument)
        {
            var projectEngine  = ProjectEngine;
            var importFeatures = projectEngine.ProjectFeatures.OfType <IImportProjectFeature>();
            var projectItem    = projectEngine.FileSystem.GetItem(hostDocument.TargetPath, hostDocument.FileKind);
            var importItems    = importFeatures.SelectMany(f => f.GetImports(projectItem)).Where(i => i.FilePath != null);

            // Target path looks like `Foo\\Bar.cshtml`
            var targetPaths = new List <string>();

            foreach (var importItem in importItems)
            {
                var itemTargetPath = importItem.FilePath.Replace('/', '\\').TrimStart('\\');

                if (FilePathComparer.Instance.Equals(itemTargetPath, hostDocument.TargetPath))
                {
                    // We've normalized the original importItem.FilePath into the HostDocument.TargetPath. For instance, if the HostDocument.TargetPath
                    // was '/_Imports.razor' it'd be normalized down into '_Imports.razor'. The purpose of this method is to get the associated document
                    // paths for a given import file (_Imports.razor / _ViewImports.cshtml); therefore, an import importing itself doesn't make sense.
                    continue;
                }

                targetPaths.Add(itemTargetPath);
            }

            return(targetPaths);
        }
Пример #3
0
        public DefaultProjectSnapshotTest()
        {
            TagHelperResolver = new TestTagHelperResolver();

            HostProject = new HostProject(TestProjectData.SomeProject.FilePath, FallbackRazorConfiguration.MVC_2_0, TestProjectData.SomeProject.RootNamespace);
            HostProjectWithConfigurationChange = new HostProject(TestProjectData.SomeProject.FilePath, FallbackRazorConfiguration.MVC_1_0, TestProjectData.SomeProject.RootNamespace);
            ProjectWorkspaceState = new ProjectWorkspaceState(new[]
            {
                TagHelperDescriptorBuilder.Create("TestTagHelper", "TestAssembly").Build(),
            });

            SomeTagHelpers = new List <TagHelperDescriptor>
            {
                TagHelperDescriptorBuilder.Create("Test1", "TestAssembly").Build()
            };

            Documents = new HostDocument[]
            {
                TestProjectData.SomeProjectFile1,
                TestProjectData.SomeProjectFile2,

                // linked file
                TestProjectData.AnotherProjectNestedFile3,
            };
        }
Пример #4
0
        public DefaultProjectSnapshotTest()
        {
            TagHelperResolver = new TestTagHelperResolver();

            HostProject = new HostProject(TestProjectData.SomeProject.FilePath, FallbackRazorConfiguration.MVC_2_0);
            HostProjectWithConfigurationChange = new HostProject(TestProjectData.SomeProject.FilePath, FallbackRazorConfiguration.MVC_1_0);

            var projectId = ProjectId.CreateNewId("Test");
            var solution  = Workspace.CurrentSolution.AddProject(ProjectInfo.Create(
                                                                     projectId,
                                                                     VersionStamp.Default,
                                                                     "Test",
                                                                     "Test",
                                                                     LanguageNames.CSharp,
                                                                     TestProjectData.SomeProject.FilePath));

            WorkspaceProject = solution.GetProject(projectId);

            SomeTagHelpers = new List <TagHelperDescriptor>
            {
                TagHelperDescriptorBuilder.Create("Test1", "TestAssembly").Build()
            };

            Documents = new HostDocument[]
            {
                TestProjectData.SomeProjectFile1,
                TestProjectData.SomeProjectFile2,

                // linked file
                TestProjectData.AnotherProjectNestedFile3,
            };
        }
Пример #5
0
        public DefaultProjectSnapshotManagerTest()
        {
            var someTagHelpers = new List <TagHelperDescriptor>();

            someTagHelpers.Add(TagHelperDescriptorBuilder.Create("Test1", "TestAssembly").Build());
            TagHelperResolver = new TestTagHelperResolver()
            {
                TagHelpers = someTagHelpers,
            };

            Documents = new HostDocument[]
            {
                TestProjectData.SomeProjectFile1,
                TestProjectData.SomeProjectFile2,

                // linked file
                TestProjectData.AnotherProjectNestedFile3,

                TestProjectData.SomeProjectComponentFile1,
                TestProjectData.SomeProjectComponentFile2,
            };

            HostProject = new HostProject(TestProjectData.SomeProject.FilePath, FallbackRazorConfiguration.MVC_2_0, TestProjectData.SomeProject.RootNamespace);
            HostProjectWithConfigurationChange = new HostProject(TestProjectData.SomeProject.FilePath, FallbackRazorConfiguration.MVC_1_0, TestProjectData.SomeProject.RootNamespace);

            ProjectManager = new TestProjectSnapshotManager(Dispatcher, Enumerable.Empty <ProjectSnapshotChangeTrigger>(), Workspace);

            ProjectWorkspaceStateWithTagHelpers = new ProjectWorkspaceState(TagHelperResolver.TagHelpers, default);

            SourceText = SourceText.From("Hello world");
        }
Пример #6
0
        public override void DocumentAdded(HostProject hostProject, HostDocument document, TextLoader textLoader)
        {
            if (hostProject == null)
            {
                throw new ArgumentNullException(nameof(hostProject));
            }

            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            _foregroundDispatcher.AssertForegroundThread();

            if (_projects.TryGetValue(hostProject.FilePath, out var entry))
            {
                var loader = textLoader == null ? DocumentState.EmptyLoader : (Func <Task <TextAndVersion> >)(() =>
                {
                    return(textLoader.LoadTextAndVersionAsync(Workspace, null, CancellationToken.None));
                });
                var state = entry.State.WithAddedHostDocument(document, loader);

                // Document updates can no-op.
                if (!object.ReferenceEquals(state, entry.State))
                {
                    var oldSnapshot = entry.GetSnapshot();
                    entry = new Entry(state);
                    _projects[hostProject.FilePath] = entry;
                    NotifyListeners(new ProjectChangeEventArgs(oldSnapshot, entry.GetSnapshot(), document.FilePath, ProjectChangeKind.DocumentAdded));
                }
            }
        }
Пример #7
0
        public override void DocumentRemoved(HostProject hostProject, HostDocument document)
        {
            if (hostProject == null)
            {
                throw new ArgumentNullException(nameof(hostProject));
            }

            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }

            _foregroundDispatcher.AssertForegroundThread();
            if (_projects.TryGetValue(hostProject.FilePath, out var entry))
            {
                var state = entry.State.WithRemovedHostDocument(document);

                // Document updates can no-op.
                if (!object.ReferenceEquals(state, entry.State))
                {
                    var oldSnapshot = entry.GetSnapshot();
                    entry = new Entry(state);
                    _projects[hostProject.FilePath] = entry;
                    NotifyListeners(new ProjectChangeEventArgs(oldSnapshot, entry.GetSnapshot(), document.FilePath, ProjectChangeKind.DocumentRemoved));
                }
            }
        }
Пример #8
0
        protected void RemoveDocumentUnsafe(HostDocument document)
        {
            var projectManager = GetProjectManager();

            projectManager.DocumentRemoved(_current, document);
            _currentDocuments.Remove(document.FilePath);
        }
Пример #9
0
        public DefaultDocumentSnapshotTest()
        {
            SourceText = SourceText.From("<p>Hello World</p>");
            Version    = VersionStamp.Create();

            // Create a new HostDocument to avoid mutating the code container
            ComponentCshtmlHostDocument = new HostDocument(TestProjectData.SomeProjectCshtmlComponentFile5);
            ComponentHostDocument       = new HostDocument(TestProjectData.SomeProjectComponentFile1);
            LegacyHostDocument          = new HostDocument(TestProjectData.SomeProjectFile1);
            NestedComponentHostDocument = new HostDocument(TestProjectData.SomeProjectNestedComponentFile3);

            var projectState = ProjectState.Create(Workspace.Services, TestProjectData.SomeProject);
            var project      = new DefaultProjectSnapshot(projectState);

            var textAndVersion = TextAndVersion.Create(SourceText, Version);

            var documentState = DocumentState.Create(Workspace.Services, LegacyHostDocument, () => Task.FromResult(textAndVersion));

            LegacyDocument = new DefaultDocumentSnapshot(project, documentState);

            documentState     = DocumentState.Create(Workspace.Services, ComponentHostDocument, () => Task.FromResult(textAndVersion));
            ComponentDocument = new DefaultDocumentSnapshot(project, documentState);

            documentState           = DocumentState.Create(Workspace.Services, ComponentCshtmlHostDocument, () => Task.FromResult(textAndVersion));
            ComponentCshtmlDocument = new DefaultDocumentSnapshot(project, documentState);

            documentState           = DocumentState.Create(Workspace.Services, NestedComponentHostDocument, () => Task.FromResult(textAndVersion));
            NestedComponentDocument = new DefaultDocumentSnapshot(project, documentState);
        }
        public void SetOutput_AcceptsSameVersionedDocuments()
        {
            // Arrange
            var services     = TestWorkspace.Create().Services;
            var hostProject  = new HostProject("C:/project.csproj", RazorConfiguration.Default);
            var projectState = ProjectState.Create(services, hostProject);
            var project      = new DefaultProjectSnapshot(projectState);

            var text           = SourceText.From("...");
            var textAndVersion = TextAndVersion.Create(text, VersionStamp.Default);
            var hostDocument   = new HostDocument("C:/file.cshtml", "C:/file.cshtml");
            var documentState  = new DocumentState(services, hostDocument, text, VersionStamp.Default, () => Task.FromResult(textAndVersion));
            var document       = new DefaultDocumentSnapshot(project, documentState);
            var newDocument    = new DefaultDocumentSnapshot(project, documentState);

            var csharpDocument = RazorCSharpDocument.Create("...", RazorCodeGenerationOptions.CreateDefault(), Enumerable.Empty <RazorDiagnostic>());

            var version   = VersionStamp.Create();
            var container = new GeneratedCodeContainer();

            container.SetOutput(document, csharpDocument, version, version);

            // Act
            container.SetOutput(newDocument, csharpDocument, version, version);

            // Assert
            Assert.Same(newDocument, container.LatestDocument);
        }
Пример #11
0
        public BackgroundDocumentGeneratorTest()
        {
            Documents = new HostDocument[]
            {
                new HostDocument("c:\\Test1\\Index.cshtml", "Index.cshtml"),
                new HostDocument("c:\\Test1\\Components\\Counter.cshtml", "Components\\Counter.cshtml"),
            };

            HostProject1 = new HostProject("c:\\Test1\\Test1.csproj", FallbackRazorConfiguration.MVC_1_0);
            HostProject2 = new HostProject("c:\\Test2\\Test2.csproj", FallbackRazorConfiguration.MVC_1_0);

            Workspace = TestWorkspace.Create();

            var projectId1 = ProjectId.CreateNewId("Test1");
            var projectId2 = ProjectId.CreateNewId("Test2");

            var solution = Workspace.CurrentSolution
                           .AddProject(ProjectInfo.Create(
                                           projectId1,
                                           VersionStamp.Default,
                                           "Test1",
                                           "Test1",
                                           LanguageNames.CSharp,
                                           "c:\\Test1\\Test1.csproj"))
                           .AddProject(ProjectInfo.Create(
                                           projectId2,
                                           VersionStamp.Default,
                                           "Test2",
                                           "Test2",
                                           LanguageNames.CSharp,
                                           "c:\\Test2\\Test2.csproj"));;

            WorkspaceProject1 = solution.GetProject(projectId1);
            WorkspaceProject2 = solution.GetProject(projectId2);
        }
        public BackgroundDocumentGeneratorTest()
        {
            Documents = new HostDocument[]
            {
                TestProjectData.SomeProjectFile1,
                TestProjectData.AnotherProjectFile1,
            };

            HostProject1 = new HostProject(TestProjectData.SomeProject.FilePath, FallbackRazorConfiguration.MVC_1_0);
            HostProject2 = new HostProject(TestProjectData.AnotherProject.FilePath, FallbackRazorConfiguration.MVC_1_0);

            var projectId1 = ProjectId.CreateNewId("Test1");
            var projectId2 = ProjectId.CreateNewId("Test2");

            var solution = Workspace.CurrentSolution
                           .AddProject(ProjectInfo.Create(
                                           projectId1,
                                           VersionStamp.Default,
                                           "Test1",
                                           "Test1",
                                           LanguageNames.CSharp,
                                           TestProjectData.SomeProject.FilePath))
                           .AddProject(ProjectInfo.Create(
                                           projectId2,
                                           VersionStamp.Default,
                                           "Test2",
                                           "Test2",
                                           LanguageNames.CSharp,
                                           TestProjectData.AnotherProject.FilePath));;

            WorkspaceProject1 = solution.GetProject(projectId1);
            WorkspaceProject2 = solution.GetProject(projectId2);

            DynamicFileInfoProvider = new RazorDynamicFileInfoProvider(new DefaultDocumentServiceProviderFactory());
        }
Пример #13
0
        public ProjectState WithRemovedHostDocument(HostDocument hostDocument)
        {
            if (hostDocument == null)
            {
                throw new ArgumentNullException(nameof(hostDocument));
            }

            if (!Documents.ContainsKey(hostDocument.FilePath))
            {
                return(this);
            }

            var documents = Documents.Remove(hostDocument.FilePath);

            // First check if the updated document is an import - it's important that this happens
            // before updating the imports map.
            if (ImportsToRelatedDocuments.TryGetValue(hostDocument.TargetPath, out var relatedDocuments))
            {
                foreach (var relatedDocument in relatedDocuments)
                {
                    documents = documents.SetItem(relatedDocument, documents[relatedDocument].WithImportsChange());
                }
            }

            // Compute the effect on the import map
            var importTargetPaths         = GetImportDocumentTargetPaths(hostDocument.TargetPath);
            var importsToRelatedDocuments = RemoveFromImportsToRelatedDocuments(ImportsToRelatedDocuments, hostDocument, importTargetPaths);

            var state = new ProjectState(this, ProjectDifference.DocumentRemoved, HostProject, ProjectWorkspaceState, documents, importsToRelatedDocuments);

            return(state);
        }
        public DefaultRazorDocumentInfoProviderTest()
        {
            ProjectSnapshotManager = new TestProjectSnapshotManager(Workspace);

            var hostProject = new HostProject("C:/path/to/project.csproj", RazorConfiguration.Default, "RootNamespace");

            ProjectSnapshotManager.ProjectAdded(hostProject);

            var hostDocument   = new HostDocument("C:/path/to/document.cshtml", "/C:/path/to/document.cshtml");
            var sourceText     = SourceText.From("Hello World");
            var textAndVersion = TextAndVersion.Create(sourceText, VersionStamp.Default, hostDocument.FilePath);

            ProjectSnapshotManager.DocumentAdded(hostProject, hostDocument, TextLoader.From(textAndVersion));

            ProjectSnapshot  = ProjectSnapshotManager.Projects[0];
            DocumentSnapshot = ProjectSnapshot.GetDocument(hostDocument.FilePath);
            var factory = new Mock <VisualStudioMacDocumentInfoFactory>();

            factory.Setup(f => f.CreateEmpty(It.IsAny <string>(), It.IsAny <ProjectId>()))
            .Returns <string, ProjectId>((razorFilePath, projectId) =>
            {
                var documentId   = DocumentId.CreateNewId(projectId);
                var documentInfo = DocumentInfo.Create(documentId, "testDoc", filePath: razorFilePath);
                return(documentInfo);
            });
            Factory = factory.Object;
        }
Пример #15
0
 public static TestDocumentState Create(
     HostWorkspaceServices services,
     HostDocument hostDocument,
     Func <Task <TextAndVersion> > loader = null,
     Action onTextChange             = null,
     Action onTextLoaderChange       = null,
     Action onConfigurationChange    = null,
     Action onWorkspaceProjectChange = null)
 {
     return(new TestDocumentState(services, hostDocument, null, null, loader, onTextChange, onTextLoaderChange, onConfigurationChange, onWorkspaceProjectChange));
 }
Пример #16
0
        public HostDocument(HostDocument other)
        {
            if (other == null)
            {
                throw new ArgumentNullException(nameof(other));
            }

            FileKind   = other.FileKind;
            FilePath   = other.FilePath;
            TargetPath = other.TargetPath;

            GeneratedDocumentContainer = new GeneratedDocumentContainer();
        }
Пример #17
0
        protected void AddDocumentUnsafe(HostDocument document)
        {
            var projectManager = GetProjectManager();

            if (_currentDocuments.ContainsKey(document.FilePath))
            {
                // Ignore duplicates
                return;
            }

            projectManager.DocumentAdded(Current, document, new FileTextLoader(document.FilePath, null));
            _currentDocuments.Add(document.FilePath, document);
        }
        public BackgroundDocumentGeneratorTest()
        {
            Documents = new HostDocument[]
            {
                TestProjectData.SomeProjectFile1,
                TestProjectData.AnotherProjectFile1,
            };

            HostProject1 = new HostProject(TestProjectData.SomeProject.FilePath, FallbackRazorConfiguration.MVC_1_0, TestProjectData.SomeProject.RootNamespace);
            HostProject2 = new HostProject(TestProjectData.AnotherProject.FilePath, FallbackRazorConfiguration.MVC_1_0, TestProjectData.AnotherProject.RootNamespace);

            DynamicFileInfoProvider = new RazorDynamicFileInfoProvider(new DefaultDocumentServiceProviderFactory());
        }
        public DefaultDocumentSnapshotTest()
        {
            var projectState = ProjectState.Create(Workspace.Services, TestProjectData.SomeProject);
            var project      = new DefaultProjectSnapshot(projectState);

            HostDocument = new HostDocument(TestProjectData.SomeProjectFile1.FilePath, TestProjectData.SomeProjectFile1.TargetPath);
            SourceText   = SourceText.From("<p>Hello World</p>");
            Version      = VersionStamp.Create();
            var textAndVersion = TextAndVersion.Create(SourceText, Version);
            var documentState  = DocumentState.Create(Workspace.Services, HostDocument, () => Task.FromResult(textAndVersion));

            Document = new DefaultDocumentSnapshot(project, documentState);
        }
Пример #20
0
 // Internal for testing
 internal DocumentState(
     HostWorkspaceServices services,
     HostDocument hostDocument,
     SourceText text,
     VersionStamp?version,
     Func <Task <TextAndVersion> > loader)
 {
     Services     = services;
     HostDocument = hostDocument;
     _sourceText  = text;
     _version     = version;
     _loader      = loader;
     _lock        = new object();
 }
Пример #21
0
        protected void AddDocumentUnsafe(HostDocument document)
        {
            var projectManager = GetProjectManager();

            if (_currentDocuments.ContainsKey(document.FilePath))
            {
                // Ignore duplicates
                return;
            }

            projectManager.DocumentAdded(_current, document, new FileTextLoader(document.FilePath, null));
            _projectContext?.AddSourceFile(document.FilePath, document.GeneratedCodeContainer.SourceTextContainer, true, GetFolders(document), SourceCodeKind.Regular, document.GeneratedCodeContainer);
            _currentDocuments.Add(document.FilePath, document);
        }
        public BackgroundDocumentGeneratorTest()
        {
            Documents = new HostDocument[]
            {
                TestProjectData.SomeProjectFile1,
                TestProjectData.AnotherProjectFile1,
            };

            HostProject1 = new HostProject(TestProjectData.SomeProject.FilePath, FallbackRazorConfiguration.MVC_1_0, TestProjectData.SomeProject.RootNamespace);
            HostProject2 = new HostProject(TestProjectData.AnotherProject.FilePath, FallbackRazorConfiguration.MVC_1_0, TestProjectData.AnotherProject.RootNamespace);

            DynamicFileInfoProvider = new DefaultRazorDynamicFileInfoProvider(new DefaultRazorDocumentServiceProviderFactory());

            DivergenceChecker = Mock.Of <DocumentDivergenceChecker>(checker => checker.PossibleDivergence(It.IsAny <DocumentSnapshot>(), It.IsAny <DocumentSnapshot>()) == true);
        }
Пример #23
0
        public BackgroundDocumentGeneratorTest()
        {
            Documents = new HostDocument[]
            {
                TestProjectData.SomeProjectFile1,
                TestProjectData.AnotherProjectFile1,
            };

            HostProject1 = new HostProject(TestProjectData.SomeProject.FilePath, FallbackRazorConfiguration.MVC_1_0, TestProjectData.SomeProject.RootNamespace);
            HostProject2 = new HostProject(TestProjectData.AnotherProject.FilePath, FallbackRazorConfiguration.MVC_1_0, TestProjectData.AnotherProject.RootNamespace);

            var razorDocumentServiceProviderFactory = new DefaultRazorDocumentServiceProviderFactory();
            var testLSPEnabledEditorFeatureDetector = Mock.Of <LSPEditorFeatureDetector>(detector => detector.IsLSPEditorFeatureEnabled() == true, MockBehavior.Strict);

            DynamicFileInfoProvider = new DefaultRazorDynamicFileInfoProvider(razorDocumentServiceProviderFactory, testLSPEnabledEditorFeatureDetector);
        }
Пример #24
0
 private TestDocumentState(
     HostWorkspaceServices services,
     HostDocument hostDocument,
     SourceText text,
     VersionStamp?version,
     Func <Task <TextAndVersion> > loader,
     Action onTextChange,
     Action onTextLoaderChange,
     Action onConfigurationChange,
     Action onWorkspaceProjectChange)
     : base(services, hostDocument, text, version, loader)
 {
     _onTextChange             = onTextChange;
     _onTextLoaderChange       = onTextLoaderChange;
     _onConfigurationChange    = onConfigurationChange;
     _onWorkspaceProjectChange = onWorkspaceProjectChange;
 }
Пример #25
0
        public ProjectStateTest()
        {
            TagHelperResolver = new TestTagHelperResolver();

            HostServices = TestServices.Create(
                new IWorkspaceService[]
            {
                new TestProjectSnapshotProjectEngineFactory(),
            },
                new ILanguageService[]
            {
                TagHelperResolver,
            });

            HostProject = new HostProject("c:\\MyProject\\Test.csproj", FallbackRazorConfiguration.MVC_2_0);
            HostProjectWithConfigurationChange = new HostProject("c:\\MyProject\\Test.csproj", FallbackRazorConfiguration.MVC_1_0);

            Workspace = TestWorkspace.Create(HostServices);

            var projectId = ProjectId.CreateNewId("Test");
            var solution  = Workspace.CurrentSolution.AddProject(ProjectInfo.Create(
                                                                     projectId,
                                                                     VersionStamp.Default,
                                                                     "Test",
                                                                     "Test",
                                                                     LanguageNames.CSharp,
                                                                     "c:\\MyProject\\Test.csproj"));

            WorkspaceProject = solution.GetProject(projectId);

            SomeTagHelpers = new List <TagHelperDescriptor>();
            SomeTagHelpers.Add(TagHelperDescriptorBuilder.Create("Test1", "TestAssembly").Build());

            Documents = new HostDocument[]
            {
                new HostDocument("c:\\MyProject\\File.cshtml", "File.cshtml"),
                new HostDocument("c:\\MyProject\\Index.cshtml", "Index.cshtml"),

                // linked file
                new HostDocument("c:\\SomeOtherProject\\Index.cshtml", "Pages\\Index.cshtml"),
            };

            Text       = SourceText.From("Hello, world!");
            TextLoader = () => Task.FromResult(TextAndVersion.Create(Text, VersionStamp.Create()));
        }
Пример #26
0
        public static DocumentState Create(
            HostWorkspaceServices services,
            HostDocument hostDocument,
            Func <Task <TextAndVersion> > loader)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (hostDocument == null)
            {
                throw new ArgumentNullException(nameof(hostDocument));
            }

            loader = loader ?? EmptyLoader;
            return(new DocumentState(services, hostDocument, null, null, loader));
        }
Пример #27
0
        public DocumentState(HostWorkspaceServices services, HostDocument hostDocument)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (hostDocument == null)
            {
                throw new ArgumentNullException(nameof(hostDocument));
            }

            Services     = services;
            HostDocument = hostDocument;
            Version      = VersionStamp.Create();

            _lock = new object();
        }
Пример #28
0
        private static ImmutableDictionary <string, ImmutableArray <string> > RemoveFromImportsToRelatedDocuments(
            ImmutableDictionary <string, ImmutableArray <string> > importsToRelatedDocuments,
            HostDocument hostDocument,
            List <string> importTargetPaths)
        {
            foreach (var importTargetPath in importTargetPaths)
            {
                if (importsToRelatedDocuments.TryGetValue(importTargetPath, out var relatedDocuments))
                {
                    relatedDocuments          = relatedDocuments.Remove(hostDocument.FilePath);
                    importsToRelatedDocuments = relatedDocuments.Length > 0
                        ? importsToRelatedDocuments.SetItem(importTargetPath, relatedDocuments)
                        : importsToRelatedDocuments.Remove(importTargetPath);
                }
            }

            return(importsToRelatedDocuments);
        }
Пример #29
0
        private static ImmutableDictionary <string, ImmutableArray <string> > AddToImportsToRelatedDocuments(
            ImmutableDictionary <string, ImmutableArray <string> > importsToRelatedDocuments,
            HostDocument hostDocument,
            List <string> importTargetPaths)
        {
            foreach (var importTargetPath in importTargetPaths)
            {
                if (!importsToRelatedDocuments.TryGetValue(importTargetPath, out var relatedDocuments))
                {
                    relatedDocuments = ImmutableArray.Create <string>();
                }

                relatedDocuments          = relatedDocuments.Add(hostDocument.FilePath);
                importsToRelatedDocuments = importsToRelatedDocuments.SetItem(importTargetPath, relatedDocuments);
            }

            return(importsToRelatedDocuments);
        }
Пример #30
0
        public List <string> GetImportDocumentTargetPaths(HostDocument hostDocument)
        {
            var projectEngine  = ProjectEngine;
            var importFeatures = projectEngine.ProjectFeatures.OfType <IImportProjectFeature>();
            var projectItem    = projectEngine.FileSystem.GetItem(hostDocument.TargetPath, hostDocument.FileKind);
            var importItems    = importFeatures.SelectMany(f => f.GetImports(projectItem)).Where(i => i.FilePath != null);

            // Target path looks like `Foo\\Bar.cshtml`
            var targetPaths = new List <string>();

            foreach (var importItem in importItems)
            {
                var itemTargetPath = importItem.FilePath.Replace('/', '\\').TrimStart('\\');
                targetPaths.Add(itemTargetPath);
            }

            return(targetPaths);
        }