|
4 | 4 | *--------------------------------------------------------------------------------------------*/ |
5 | 5 |
|
6 | 6 | import * as serverUtils from '../omnisharp/utils'; |
7 | | -import { Event, EventEmitter, TextDocument, TextDocumentContentProvider, TextEditor, Uri, window, workspace } from 'vscode'; |
| 7 | +import { CancellationToken, Event, EventEmitter, TextDocument, TextDocumentContentProvider, TextEditor, Uri, window, workspace } from 'vscode'; |
8 | 8 | import { IDisposable } from '../Disposable'; |
9 | 9 | import { SourceGeneratedFileInfo, SourceGeneratedFileResponse, UpdateType } from '../omnisharp/protocol'; |
10 | 10 | import { OmniSharpServer } from '../omnisharp/server'; |
@@ -89,6 +89,27 @@ export default class SourceGeneratedDocumentProvider implements TextDocumentCont |
89 | 89 | return undefined; |
90 | 90 | } |
91 | 91 |
|
| 92 | + public addSourceGeneratedFileWithoutInitialContent(fileInfo: SourceGeneratedFileInfo, fileName: string): Uri { |
| 93 | + if (this._documents.has(fileInfo)) { |
| 94 | + // Raced with something, return the existing one |
| 95 | + return this.tryGetExistingSourceGeneratedFile(fileInfo); |
| 96 | + } |
| 97 | + |
| 98 | + const uri = this.getUriForName(fileName); |
| 99 | + const uriString = uri.toString(); |
| 100 | + |
| 101 | + if (this._uriToDocumentInfo.has(uriString)) { |
| 102 | + this._documents.delete(fileInfo); |
| 103 | + this._uriToDocumentInfo.delete(uriString); |
| 104 | + } |
| 105 | + |
| 106 | + // Provide will see the null and retrieve the file when asked. |
| 107 | + this._documents.set(fileInfo, null); |
| 108 | + this._uriToDocumentInfo.set(uriString, fileInfo); |
| 109 | + |
| 110 | + return uri; |
| 111 | + } |
| 112 | + |
92 | 113 | public addSourceGeneratedFile(fileInfo: SourceGeneratedFileInfo, response: SourceGeneratedFileResponse): Uri { |
93 | 114 | if (this._documents.has(fileInfo)) { |
94 | 115 | // Raced with something, return the existing one |
@@ -117,8 +138,17 @@ export default class SourceGeneratedDocumentProvider implements TextDocumentCont |
117 | 138 | return uri; |
118 | 139 | } |
119 | 140 |
|
120 | | - public provideTextDocumentContent(uri: Uri): string { |
121 | | - return this._documents.get(this._uriToDocumentInfo.get(uri.toString())).Source; |
| 141 | + public async provideTextDocumentContent(uri: Uri, token: CancellationToken): Promise<string> { |
| 142 | + const fileInfo = this._uriToDocumentInfo.get(uri.toString()); |
| 143 | + let response = this._documents.get(fileInfo); |
| 144 | + |
| 145 | + if (response === null) { |
| 146 | + // No content yet, get it |
| 147 | + response = await serverUtils.getSourceGeneratedFile(this.server, fileInfo, token); |
| 148 | + this._documents.set(fileInfo, response); |
| 149 | + } |
| 150 | + |
| 151 | + return response.Source; |
122 | 152 | } |
123 | 153 |
|
124 | 154 | private getUriForName(sourceName: string): Uri { |
|
0 commit comments