public void Create() { var loader = new FileTextLoader(Path.GetTempPath(), defaultEncoding: null); var id = DocumentId.CreateNewId(ProjectId.CreateNewId()); var info = DocumentInfo.Create( id, name: "doc", sourceCodeKind: SourceCodeKind.Script, loader: loader, isGenerated: true); Assert.Equal(id, info.Id); Assert.Equal("doc", info.Name); Assert.Equal(SourceCodeKind.Script, info.SourceCodeKind); Assert.Same(loader, info.TextLoader); Assert.True(info.IsGenerated); }
public DocumentId AddFile(string fullPath, SourceCodeKind sourceCodeKind, ImmutableArray <string> folders) { if (string.IsNullOrEmpty(fullPath)) { throw new ArgumentException($"{nameof(fullPath)} isn't a valid path.", nameof(fullPath)); } var documentId = DocumentId.CreateNewId(_project.Id, fullPath); var textLoader = new FileTextLoader(fullPath, defaultEncoding: null); var documentInfo = DocumentInfo.Create( documentId, FileNameUtilities.GetFileName(fullPath), folders: folders.IsDefault ? null : (IEnumerable <string>)folders, sourceCodeKind: sourceCodeKind, loader: textLoader, filePath: fullPath); lock (_project._gate) { if (_documentPathsToDocumentIds.ContainsKey(fullPath)) { throw new ArgumentException($"'{fullPath}' has already been added to this project.", nameof(fullPath)); } _documentPathsToDocumentIds.Add(fullPath, documentId); _project._fileWatchingTokens.Add(documentId, _project._documentFileChangeContext.EnqueueWatchingFile(fullPath)); if (_project._activeBatchScopes > 0) { _documentsAddedInBatch.Add(documentInfo); } else { _project._workspace.ApplyChangeToWorkspace(w => _documentAddAction(w, documentInfo)); _project._workspace.CheckForOpenDocuments(ImmutableArray.Create(fullPath)); } } return(documentId); }