コード例 #1
0
        public static TextEditor CreateNewEditor(TextBufferFileModel textBufferFileModel, TextEditorType textEditorType = TextEditorType.Default)
        {
            var result = new TextEditor(currentFactory.CreateNewEditor(textBufferFileModel), textEditorType);

            InitializeTextEditor(result);
            return(result);
        }
コード例 #2
0
        public async Task DowngradeInstance()
        {
            FilePath filePath       = "test.txt";
            var      textBufferFile = new TextBufferFileModel();

            textBufferFile.CreateNew();
            textBufferFile.SetText("Foo");
            await textBufferFile.LinkToFile(filePath);

            await registry.ShareModel(textBufferFile);

            var textFile = await registry.GetSharedModel <TextFileModel> (filePath);

            Assert.IsFalse(textFile.IsLoaded);
            await textFile.Load();

            Assert.AreEqual("Foo", textFile.GetText());

            var file = await registry.GetSharedModel <FileModel> (filePath);

            Assert.IsFalse(file.IsLoaded);
            await file.Load();

            Assert.AreEqual("Foo", TestHelper.FromStream(file.GetContent()));
        }
コード例 #3
0
        public async Task EditorConfigFile_ModifiedInTextEditor()
        {
            FilePath solFile = Util.GetSampleProject("additional-files", "additional-files.sln");

            using (var sol = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile))
                using (var ws = await TypeSystemServiceTestExtensions.LoadSolution(sol)) {
                    try {
                        var project = sol.GetAllProjects().Single();

                        FilePath editorConfigFileName = solFile.ParentDirectory.Combine(".editorconfig");
                        var      textFileModel        = new TextBufferFileModel();
                        var      mimeType             = MimeTypeCatalog.Instance.FindMimeTypeForFile(editorConfigFileName);
                        textFileModel.CreateNew(editorConfigFileName, mimeType?.Id);

                        var projectInfo = ws.CurrentSolution.Projects.Single();
                        Microsoft.CodeAnalysis.AnalyzerConfigDocument editorConfigDoc =
                            projectInfo.AnalyzerConfigDocuments.Single(d => d.FilePath == editorConfigFileName);

                        int analyzerConfigDocumentChangedCount = 0;
                        ws.WorkspaceChanged += (sender, e) => {
                            if (e.DocumentId == editorConfigDoc.Id &&
                                e.Kind == Microsoft.CodeAnalysis.WorkspaceChangeKind.AnalyzerConfigDocumentChanged)
                            {
                                analyzerConfigDocumentChangedCount++;
                            }
                        };

                        using (var fileRegistration = IdeApp.TypeSystemService.RegisterOpenDocument(
                                   null,              // No owner.
                                   editorConfigFileName,
                                   textFileModel.TextBuffer)) {
                            Assert.IsTrue(ws.IsDocumentOpen(editorConfigDoc.Id));

                            Func <bool> action = () => analyzerConfigDocumentChangedCount == 1;
                            await AssertIsTrueWithTimeout(action, "Timed out waiting for analyzer config file changed event on opening file", 100000);

                            // Add error style to .editorconfig
                            string contents =
                                "root = true\r\n" +
                                "\r\n" +
                                "[*.cs]\r\n" +
                                "csharp_style_var_for_built_in_types = true:error\r\n";
                            textFileModel.SetText(contents);
                            await textFileModel.Save();

                            action = () => analyzerConfigDocumentChangedCount == 2;
                            await AssertIsTrueWithTimeout(action, "Timed out waiting for analyzer config file changed event", 100000);
                        }
                        // After the file registration is disposed the document should be closed.
                        Assert.IsFalse(ws.IsDocumentOpen(editorConfigDoc.Id));
                    } finally {
                        TypeSystemServiceTestExtensions.UnloadSolution(sol);
                    }
                }
        }