@@ -16,15 +16,13 @@ export class Document {
1616 private cachedParsedContent : unknown ;
1717
1818 constructor (
19- private readonly textDocument : TextDocument ,
19+ public readonly uri : DocumentUri ,
20+ private readonly textDocument : ( uri : string ) => TextDocument ,
2021 detectIndentation : boolean = true ,
2122 fallbackTabSize : number = DefaultSettings . editor . tabSize ,
22- public readonly uri : DocumentUri = textDocument . uri ,
23- public readonly languageId : string = textDocument . languageId ,
24- public readonly version : number = textDocument . version ,
25- public readonly lineCount : number = textDocument . lineCount ,
2623 ) {
27- const { extension, type } = detectDocumentType ( textDocument . uri , textDocument . getText ( ) ) ;
24+ const doc = this . textDocument ( uri ) ;
25+ const { extension, type } = detectDocumentType ( doc . uri , doc . getText ( ) ) ;
2826
2927 this . extension = extension ;
3028 this . documentType = type ;
@@ -36,12 +34,24 @@ export class Document {
3634 this . processIndentation ( detectIndentation , fallbackTabSize ) ;
3735 }
3836
37+ public get languageId ( ) : string {
38+ return this . textDocument ( this . uri ) . languageId ;
39+ }
40+
41+ public get version ( ) : number {
42+ return this . textDocument ( this . uri ) . version ;
43+ }
44+
45+ public get lineCount ( ) : number {
46+ return this . textDocument ( this . uri ) . lineCount ;
47+ }
48+
3949 public get cfnFileType ( ) : CloudFormationFileType {
4050 return this . _cfnFileType ;
4151 }
4252
4353 public updateCfnFileType ( ) : void {
44- const content = this . textDocument . getText ( ) ;
54+ const content = this . textDocument ( this . uri ) . getText ( ) ;
4555 if ( ! content . trim ( ) ) {
4656 this . _cfnFileType = CloudFormationFileType . Empty ;
4757 this . cachedParsedContent = undefined ;
@@ -54,14 +64,12 @@ export class Document {
5464 } catch {
5565 // If parsing fails, leave cfnFileType unchanged and clear cache
5666 this . cachedParsedContent = undefined ;
57- this . log . debug (
58- `Failed to parse document ${ this . textDocument . uri } , keeping cfnFileType as ${ this . _cfnFileType } ` ,
59- ) ;
67+ this . log . debug ( `Failed to parse document ${ this . uri } , keeping cfnFileType as ${ this . _cfnFileType } ` ) ;
6068 }
6169 }
6270
6371 private parseContent ( ) : unknown {
64- const content = this . textDocument . getText ( ) ;
72+ const content = this . textDocument ( this . uri ) . getText ( ) ;
6573 if ( this . documentType === DocumentType . JSON ) {
6674 return JSON . parse ( content ) ;
6775 }
@@ -124,27 +132,27 @@ export class Document {
124132 }
125133
126134 public getText ( range ?: Range ) {
127- return this . textDocument . getText ( range ) ;
135+ return this . textDocument ( this . uri ) . getText ( range ) ;
128136 }
129137
130138 public getLines ( ) : string [ ] {
131139 return this . getText ( ) . split ( '\n' ) ;
132140 }
133141
134142 public positionAt ( offset : number ) {
135- return this . textDocument . positionAt ( offset ) ;
143+ return this . textDocument ( this . uri ) . positionAt ( offset ) ;
136144 }
137145
138146 public offsetAt ( position : Position ) {
139- return this . textDocument . offsetAt ( position ) ;
147+ return this . textDocument ( this . uri ) . offsetAt ( position ) ;
140148 }
141149
142150 public isTemplate ( ) {
143151 return this . cfnFileType === CloudFormationFileType . Template ;
144152 }
145153
146154 public contents ( ) {
147- return this . textDocument . getText ( ) ;
155+ return this . textDocument ( this . uri ) . getText ( ) ;
148156 }
149157
150158 public metadata ( ) : DocumentMetadata {
0 commit comments