/
TextDocument.cs
130 lines (111 loc) · 4.71 KB
/
TextDocument.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis
{
public class TextDocument
{
internal TextDocumentState State { get; }
internal TextDocumentKind Kind { get; }
/// <summary>
/// The project this document belongs to.
/// </summary>
public Project Project { get; protected set; }
protected TextDocument()
{
}
internal TextDocument(Project project, TextDocumentState state, TextDocumentKind kind)
{
Contract.ThrowIfNull(project);
Contract.ThrowIfNull(state);
this.Project = project;
State = state;
Kind = kind;
}
/// <summary>
/// The document's identifier. Many document instances may share the same ID, but only one
/// document in a solution may have that ID.
/// </summary>
public DocumentId Id => State.Id;
/// <summary>
/// The path to the document file or null if there is no document file.
/// </summary>
public string FilePath => State.FilePath;
/// <summary>
/// The name of the document.
/// </summary>
public string Name => State.Name;
/// <summary>
/// The sequence of logical folders the document is contained in.
/// </summary>
public IReadOnlyList<string> Folders => State.Folders;
/// <summary>
/// A <see cref="IDocumentServiceProvider"/> associated with this document
/// </summary>
internal IDocumentServiceProvider Services => State.Services;
/// <summary>
/// Get the current text for the document if it is already loaded and available.
/// </summary>
public bool TryGetText(out SourceText text)
{
return State.TryGetText(out text);
}
/// <summary>
/// Gets the version of the document's text if it is already loaded and available.
/// </summary>
public bool TryGetTextVersion(out VersionStamp version)
{
return State.TryGetTextVersion(out version);
}
/// <summary>
/// Gets the current text for the document asynchronously.
/// </summary>
public Task<SourceText> GetTextAsync(CancellationToken cancellationToken = default)
{
return State.GetTextAsync(cancellationToken);
}
/// <summary>
/// Fetches the current text for the document synchronously.
/// </summary>
/// <remarks>This is internal for the same reason <see cref="Document.GetSyntaxTreeSynchronously(CancellationToken)"/> is internal:
/// we have specialized cases where we need it, but we worry that making it public will do more harm than good.</remarks>
internal SourceText GetTextSynchronously(CancellationToken cancellationToken)
{
return State.GetTextSynchronously(cancellationToken);
}
/// <summary>
/// Gets the version of the document's text.
/// </summary>
public Task<VersionStamp> GetTextVersionAsync(CancellationToken cancellationToken = default)
{
return State.GetTextVersionAsync(cancellationToken);
}
/// <summary>
/// Fetches the current version for the document synchronously.
/// </summary>
/// <remarks>This is internal for the same reason <see cref="Document.GetSyntaxTreeSynchronously(CancellationToken)"/> is internal:
/// we have specialized cases where we need it, but we worry that making it public will do more harm than good.</remarks>
internal VersionStamp GetTextVersionSynchronously(CancellationToken cancellationToken)
{
return State.GetTextVersionSynchronously(cancellationToken);
}
/// <summary>
/// Gets the version of the document's top level signature.
/// </summary>
internal Task<VersionStamp> GetTopLevelChangeTextVersionAsync(CancellationToken cancellationToken = default)
{
return State.GetTopLevelChangeTextVersionAsync(cancellationToken);
}
/// <summary>
/// True if the info of the document change (name, folders, file path; not the content)
/// </summary>
internal virtual bool HasInfoChanged(TextDocument otherTextDocument)
{
return State.Attributes != otherTextDocument.State.Attributes;
}
}
}